longopts + dns + refactor
This commit is contained in:
parent
5d872c952f
commit
6d1a9fc77b
@ -1,12 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
#If no argument is passed, kill the script.
|
||||
[[ -z "$*" || "-" == "$*" || "--" == "$*" ]] && echo "This script requires an argument, use --help for help" && exit
|
||||
|
||||
[[ -z "$*" ]] && echo "This script requires an argument, use -h for help" && exit
|
||||
|
||||
while getopts ":hsi:mrb:t:uUpSRv" opt
|
||||
while getopts ":si:rb:t:uUpSRv-:" opt
|
||||
do
|
||||
case $opt in
|
||||
h)
|
||||
-)
|
||||
case "${OPTARG}" in
|
||||
dns)
|
||||
dns="true"
|
||||
;;
|
||||
restore)
|
||||
restore="true"
|
||||
;;
|
||||
mount)
|
||||
mount="true"
|
||||
;;
|
||||
help)
|
||||
echo "-m | Initiates mounting feature, choose between unmounting and mounting PVC data"
|
||||
echo "-r | Opens a menu to restore a heavy_script backup that was taken on you ix-applications pool"
|
||||
echo "-b | Back-up your ix-applications dataset, specify a number after -b"
|
||||
@ -23,8 +35,15 @@ do
|
||||
echo "EX | bash /mnt/tank/scripts/heavy_script.sh -t 8812 -m"
|
||||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Invalid Option -$OPTARG, type --help for help"
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
\?)
|
||||
echo "Invalid Option -$OPTARG, type -h for help"
|
||||
echo "Invalid Option -$OPTARG, type --help for help"
|
||||
exit
|
||||
;;
|
||||
:)
|
||||
@ -38,7 +57,7 @@ do
|
||||
[[ "$number_of_backups" -le 0 ]] && echo "Error: Number of backups is required to be at least 1" && exit
|
||||
;;
|
||||
r)
|
||||
restore="true"
|
||||
rollback="true"
|
||||
;;
|
||||
i)
|
||||
ignore+=("$OPTARG")
|
||||
@ -48,9 +67,6 @@ do
|
||||
timeout=$OPTARG
|
||||
! [[ $timeout =~ $re ]] && echo -e "Error: -t needs to be assigned an interger\n\"""$timeout""\" is not an interger" >&2 && exit
|
||||
;;
|
||||
m)
|
||||
mount="true"
|
||||
;;
|
||||
s)
|
||||
sync="true"
|
||||
;;
|
||||
@ -318,10 +334,38 @@ echo ' |___/ |_| '
|
||||
echo
|
||||
}
|
||||
export -f title
|
||||
|
||||
dns(){
|
||||
clear -x
|
||||
echo "Generating DNS Names.."
|
||||
#ignored dependency pods, No change required
|
||||
ignore="cron|kube-system|nvidia|svclb|NAME|memcached"
|
||||
|
||||
# Pulling pod names
|
||||
|
||||
mapfile -t main < <(k3s kubectl get pods -A | grep -Ev "$ignore" | sort)
|
||||
|
||||
# Pulling all ports
|
||||
all_ports=$(k3s kubectl get service -A)
|
||||
|
||||
clear -x
|
||||
count=0
|
||||
for i in "${main[@]}"
|
||||
do
|
||||
[[ count -le 0 ]] && echo -e "\n" && ((count++))
|
||||
appName=$(echo "$i" | awk '{print $2}' | sed 's/-[^-]*-[^-]*$//' | sed 's/-0//')
|
||||
ixName=$(echo "$i" | awk '{print $1}')
|
||||
port=$(echo "$all_ports" | grep -E "\s$appName\s" | awk '{print $6}' | grep -Eo "^[[:digit:]]+{1}")
|
||||
echo -e "$appName.$ixName.svc.cluster.local $port"
|
||||
done | uniq | nl -b t | sed 's/\s\s\s$/- -------- ----/' | column -t -R 1 -N "#,DNS_Name,Port" -L
|
||||
}
|
||||
export -f dns
|
||||
|
||||
#exit if incompatable functions are called
|
||||
[[ "$restore" == "true" && "$mount" == "true" ]] && echo -e "The Restore Function(-r)\nand\nMount Function(-m)\nCannot both be called at the same time." && exit
|
||||
[[ "$update_all_apps" == "true" && "$update_apps" == "true" ]] && echo -e "-U and -u cannot BOTH be called" && exit
|
||||
#Continue to call functions in specific order
|
||||
[[ "$dns" == "true" ]] && dns && exit
|
||||
[[ "$restore" == "true" ]] && restore && exit
|
||||
[[ "$mount" == "true" ]] && mount && exit
|
||||
[[ "$number_of_backups" -ge 1 ]] && backup
|
||||
|
Loading…
Reference in New Issue
Block a user