longopts + dns + refactor
This commit is contained in:
parent
5d872c952f
commit
6d1a9fc77b
@ -1,30 +1,49 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#If no argument is passed, kill the script.
|
#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
|
do
|
||||||
case $opt in
|
case $opt in
|
||||||
h)
|
-)
|
||||||
echo "-m | Initiates mounting feature, choose between unmounting and mounting PVC data"
|
case "${OPTARG}" in
|
||||||
echo "-r | Opens a menu to restore a heavy_script backup that was taken on you ix-applications pool"
|
dns)
|
||||||
echo "-b | Back-up your ix-applications dataset, specify a number after -b"
|
dns="true"
|
||||||
echo "-i | Add application to ignore list, one by one, see example below."
|
;;
|
||||||
echo "-R | Roll-back applications if they fail to update"
|
restore)
|
||||||
echo "-S | Shutdown applications prior to updating"
|
restore="true"
|
||||||
echo "-v | verbose output"
|
;;
|
||||||
echo "-t | Set a custom timeout in seconds when checking if either an App or Mountpoint correctly Started, Stopped or (un)Mounted. Defaults to 500 seconds"
|
mount)
|
||||||
echo "-s | sync catalog"
|
mount="true"
|
||||||
echo "-U | Update all applications, ignores versions"
|
;;
|
||||||
echo "-u | Update all applications, does not update Major releases"
|
help)
|
||||||
echo "-p | Prune unused/old docker images"
|
echo "-m | Initiates mounting feature, choose between unmounting and mounting PVC data"
|
||||||
echo "EX | bash heavy_script.sh -b 14 -i portainer -i arch -i sonarr -i radarr -t 600 -vRsUp"
|
echo "-r | Opens a menu to restore a heavy_script backup that was taken on you ix-applications pool"
|
||||||
echo "EX | bash /mnt/tank/scripts/heavy_script.sh -t 8812 -m"
|
echo "-b | Back-up your ix-applications dataset, specify a number after -b"
|
||||||
exit
|
echo "-i | Add application to ignore list, one by one, see example below."
|
||||||
;;
|
echo "-R | Roll-back applications if they fail to update"
|
||||||
|
echo "-S | Shutdown applications prior to updating"
|
||||||
|
echo "-v | verbose output"
|
||||||
|
echo "-t | Set a custom timeout in seconds when checking if either an App or Mountpoint correctly Started, Stopped or (un)Mounted. Defaults to 500 seconds"
|
||||||
|
echo "-s | sync catalog"
|
||||||
|
echo "-U | Update all applications, ignores versions"
|
||||||
|
echo "-u | Update all applications, does not update Major releases"
|
||||||
|
echo "-p | Prune unused/old docker images"
|
||||||
|
echo "EX | bash heavy_script.sh -b 14 -i portainer -i arch -i sonarr -i radarr -t 600 -vRsUp"
|
||||||
|
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
|
exit
|
||||||
;;
|
;;
|
||||||
:)
|
:)
|
||||||
@ -38,7 +57,7 @@ do
|
|||||||
[[ "$number_of_backups" -le 0 ]] && echo "Error: Number of backups is required to be at least 1" && exit
|
[[ "$number_of_backups" -le 0 ]] && echo "Error: Number of backups is required to be at least 1" && exit
|
||||||
;;
|
;;
|
||||||
r)
|
r)
|
||||||
restore="true"
|
rollback="true"
|
||||||
;;
|
;;
|
||||||
i)
|
i)
|
||||||
ignore+=("$OPTARG")
|
ignore+=("$OPTARG")
|
||||||
@ -48,9 +67,6 @@ do
|
|||||||
timeout=$OPTARG
|
timeout=$OPTARG
|
||||||
! [[ $timeout =~ $re ]] && echo -e "Error: -t needs to be assigned an interger\n\"""$timeout""\" is not an interger" >&2 && exit
|
! [[ $timeout =~ $re ]] && echo -e "Error: -t needs to be assigned an interger\n\"""$timeout""\" is not an interger" >&2 && exit
|
||||||
;;
|
;;
|
||||||
m)
|
|
||||||
mount="true"
|
|
||||||
;;
|
|
||||||
s)
|
s)
|
||||||
sync="true"
|
sync="true"
|
||||||
;;
|
;;
|
||||||
@ -318,10 +334,38 @@ echo ' |___/ |_| '
|
|||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
export -f title
|
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
|
#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
|
[[ "$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
|
[[ "$update_all_apps" == "true" && "$update_apps" == "true" ]] && echo -e "-U and -u cannot BOTH be called" && exit
|
||||||
#Continue to call functions in specific order
|
#Continue to call functions in specific order
|
||||||
|
[[ "$dns" == "true" ]] && dns && exit
|
||||||
[[ "$restore" == "true" ]] && restore && exit
|
[[ "$restore" == "true" ]] && restore && exit
|
||||||
[[ "$mount" == "true" ]] && mount && exit
|
[[ "$mount" == "true" ]] && mount && exit
|
||||||
[[ "$number_of_backups" -ge 1 ]] && backup
|
[[ "$number_of_backups" -ge 1 ]] && backup
|
||||||
|
Loading…
Reference in New Issue
Block a user