code cleanup
This commit is contained in:
parent
9e429e2a5b
commit
45127be73a
395
heavy_script.sh
395
heavy_script.sh
@ -4,108 +4,37 @@
|
|||||||
[[ -z "$*" || "-" == "$*" || "--" == "$*" ]] && echo "This script requires an argument, use --help for help" && exit
|
[[ -z "$*" || "-" == "$*" || "--" == "$*" ]] && echo "This script requires an argument, use --help for help" && exit
|
||||||
|
|
||||||
|
|
||||||
while getopts ":si:rb:t:uUpSRv-:" opt
|
help(){
|
||||||
do
|
[[ $help == "true" ]] && clear -x
|
||||||
case $opt in
|
echo "Basic Utilities"
|
||||||
-)
|
echo "--mount | Initiates mounting feature, choose between unmounting and mounting PVC data"
|
||||||
case "${OPTARG}" in
|
echo "--restore | Opens a menu to restore a \"heavy_script\" backup that was taken on your \"ix-applications\" dataset"
|
||||||
help)
|
echo "--delete backup | Opens a menu to delete backups on your system"
|
||||||
clear -x
|
echo "--dns | list all of your applications DNS names and their web ports"
|
||||||
echo "Basic Utilities"
|
echo
|
||||||
echo "--mount | Initiates mounting feature, choose between unmounting and mounting PVC data"
|
echo "Update Options"
|
||||||
echo "--restore | Opens a menu to restore a \"heavy_script\" backup that was taken on your \"ix-applications\" dataset"
|
echo "-U | Update all applications, ignores versions"
|
||||||
echo "--delete backup | Opens a menu to delete backups on your system"
|
echo "-u | Update all applications, does not update Major releases"
|
||||||
echo "--dns | list all of your applications DNS names and their web ports"
|
echo "-b | Back-up your ix-applications dataset, specify a number after -b"
|
||||||
echo
|
echo "-i | Add application to ignore list, one by one, see example below."
|
||||||
echo "Update Options"
|
echo "-R | THIS OPTION WILL DEPRICATE SOON, USE \"-r\" instead. Roll-back applications if they fail to update"
|
||||||
echo "-U | Update all applications, ignores versions"
|
echo "-r | Roll-back applications if they fail to update"
|
||||||
echo "-u | Update all applications, does not update Major releases"
|
echo "-S | Shutdown applications prior to updating"
|
||||||
echo "-b | Back-up your ix-applications dataset, specify a number after -b"
|
echo "-v | verbose output"
|
||||||
echo "-i | Add application to ignore list, one by one, see example below."
|
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 "-R | THIS OPTION WILL DEPRICATE SOON, USE \"-r\" instead. Roll-back applications if they fail to update"
|
echo "-s | sync catalog"
|
||||||
echo "-r | Roll-back applications if they fail to update"
|
echo "-p | Prune unused/old docker images"
|
||||||
echo "-S | Shutdown applications prior to updating"
|
echo
|
||||||
echo "-v | verbose output"
|
echo "Examples"
|
||||||
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 "bash heavy_script.sh -b 14 -i portainer -i arch -i sonarr -i radarr -t 600 -vrsUp"
|
||||||
echo "-s | sync catalog"
|
echo "bash /mnt/tank/scripts/heavy_script.sh -t 150 --mount"
|
||||||
echo "-p | Prune unused/old docker images"
|
echo "bash /mnt/tank/scripts/heavy_script.sh --dns"
|
||||||
echo
|
echo "bash /mnt/tank/scripts/heavy_script.sh --restore"
|
||||||
echo "Examples"
|
echo "bash /mnt/tank/scripts/heavy_script.sh --delete-backup"
|
||||||
echo "bash heavy_script.sh -b 14 -i portainer -i arch -i sonarr -i radarr -t 600 -vrsUp"
|
echo
|
||||||
echo "bash /mnt/tank/scripts/heavy_script.sh -t 150 --mount"
|
exit
|
||||||
echo "bash /mnt/tank/scripts/heavy_script.sh --dns"
|
}
|
||||||
echo "bash /mnt/tank/scripts/heavy_script.sh --restore"
|
export -f help
|
||||||
echo "bash /mnt/tank/scripts/heavy_script.sh --delete-backup"
|
|
||||||
echo
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
dns)
|
|
||||||
dns="true"
|
|
||||||
;;
|
|
||||||
restore)
|
|
||||||
restore="true"
|
|
||||||
;;
|
|
||||||
mount)
|
|
||||||
mount="true"
|
|
||||||
;;
|
|
||||||
delete-backup)
|
|
||||||
deleteBackup="true"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Invalid Option --$OPTARG, type --help for help"
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
\?)
|
|
||||||
echo "Invalid Option -$OPTARG, type --help for help"
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
:)
|
|
||||||
echo "Option: -$OPTARG requires an argument" >&2
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
b)
|
|
||||||
re='^[0-9]+$'
|
|
||||||
number_of_backups=$OPTARG
|
|
||||||
! [[ $OPTARG =~ $re ]] && echo -e "Error: -b needs to be assigned an interger\n\"""$number_of_backups""\" is not an interger" >&2 && exit
|
|
||||||
[[ "$number_of_backups" -le 0 ]] && echo "Error: Number of backups is required to be at least 1" && exit
|
|
||||||
;;
|
|
||||||
r)
|
|
||||||
rollback="true"
|
|
||||||
;;
|
|
||||||
i)
|
|
||||||
ignore+=("$OPTARG")
|
|
||||||
;;
|
|
||||||
t)
|
|
||||||
re='^[0-9]+$'
|
|
||||||
timeout=$OPTARG
|
|
||||||
! [[ $timeout =~ $re ]] && echo -e "Error: -t needs to be assigned an interger\n\"""$timeout""\" is not an interger" >&2 && exit
|
|
||||||
;;
|
|
||||||
s)
|
|
||||||
sync="true"
|
|
||||||
;;
|
|
||||||
U)
|
|
||||||
update_all_apps="true"
|
|
||||||
;;
|
|
||||||
u)
|
|
||||||
update_apps="true"
|
|
||||||
;;
|
|
||||||
S)
|
|
||||||
stop_before_update="true"
|
|
||||||
;;
|
|
||||||
p)
|
|
||||||
prune="true"
|
|
||||||
;;
|
|
||||||
R)
|
|
||||||
rollback="true"
|
|
||||||
echo "WARNING: -R is being transisitioned to -r, this is due to a refactor in the script. Please Make the change ASAP!"
|
|
||||||
;;
|
|
||||||
v)
|
|
||||||
verbose="true"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
deleteBackup(){
|
deleteBackup(){
|
||||||
@ -119,13 +48,14 @@ echo "$list_backups" && read -t 600 -p "Please type a number: " selection && res
|
|||||||
echo -e "\nWARNING:\nYou CANNOT go back after deleting your restore point" || { echo "FAILED"; exit; }
|
echo -e "\nWARNING:\nYou CANNOT go back after deleting your restore point" || { echo "FAILED"; exit; }
|
||||||
echo -e "\n\nYou have chosen:\n$restore_point\n\nWould you like to continue?" && echo -e "1 Yes\n2 No" && read -t 120 -p "Please type a number: " yesno || { echo "FAILED"; exit; }
|
echo -e "\n\nYou have chosen:\n$restore_point\n\nWould you like to continue?" && echo -e "1 Yes\n2 No" && read -t 120 -p "Please type a number: " yesno || { echo "FAILED"; exit; }
|
||||||
if [[ $yesno == "1" ]]; then
|
if [[ $yesno == "1" ]]; then
|
||||||
echo -e "\nDeleting $restore_point" && cli -c 'app kubernetes delete_backup backup_name=''"'"$restore_point"'"' &>/dev/null && echo "Sucessfully deleted" || echo "Deletion Failed"
|
echo -e "\nDeleting $restore_point" && cli -c 'app kubernetes delete_backup backup_name=''"'"$restore_point"'"' &>/dev/null && echo "Sucessfully deleted" || echo "Deletion Failed"
|
||||||
elif [[ $yesno == "2" ]]; then
|
elif [[ $yesno == "2" ]]; then
|
||||||
echo "You've chosen NO, killing script."
|
echo "You've chosen NO, killing script."
|
||||||
else
|
else
|
||||||
echo "Invalid Selection"
|
echo "Invalid Selection"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
export -f deleteBackup
|
||||||
|
|
||||||
|
|
||||||
backup(){
|
backup(){
|
||||||
@ -135,14 +65,14 @@ date=$(date '+%Y_%m_%d_%H_%M_%S')
|
|||||||
[[ -z "$verbose" ]] && echo -e "\nNew Backup Name:" && cli -c 'app kubernetes backup_chart_releases backup_name=''"'HeavyScript_"$date"'"' | tail -n 1
|
[[ -z "$verbose" ]] && echo -e "\nNew Backup Name:" && cli -c 'app kubernetes backup_chart_releases backup_name=''"'HeavyScript_"$date"'"' | tail -n 1
|
||||||
mapfile -t list_backups < <(cli -c 'app kubernetes list_backups' | grep "HeavyScript_" | sort -t '_' -Vr -k2,7 | awk -F '|' '{print $2}'| tr -d " \t\r")
|
mapfile -t list_backups < <(cli -c 'app kubernetes list_backups' | grep "HeavyScript_" | sort -t '_' -Vr -k2,7 | awk -F '|' '{print $2}'| tr -d " \t\r")
|
||||||
if [[ ${#list_backups[@]} -gt "number_of_backups" ]]; then
|
if [[ ${#list_backups[@]} -gt "number_of_backups" ]]; then
|
||||||
echo -e "\nDeleting the oldest backup(s) for exceeding limit:"
|
echo -e "\nDeleting the oldest backup(s) for exceeding limit:"
|
||||||
overflow=$(( ${#list_backups[@]} - "$number_of_backups" ))
|
overflow=$(( ${#list_backups[@]} - "$number_of_backups" ))
|
||||||
mapfile -t list_overflow < <(cli -c 'app kubernetes list_backups' | grep "HeavyScript_" | sort -t '_' -V -k2,7 | awk -F '|' '{print $2}'| tr -d " \t\r" | head -n "$overflow")
|
mapfile -t list_overflow < <(cli -c 'app kubernetes list_backups' | grep "HeavyScript_" | sort -t '_' -V -k2,7 | awk -F '|' '{print $2}'| tr -d " \t\r" | head -n "$overflow")
|
||||||
for i in "${list_overflow[@]}"
|
for i in "${list_overflow[@]}"
|
||||||
do
|
do
|
||||||
cli -c 'app kubernetes delete_backup backup_name=''"'"$i"'"' &> /dev/null || echo "Failed to delete $i"
|
cli -c 'app kubernetes delete_backup backup_name=''"'"$i"'"' &> /dev/null || echo "Failed to delete $i"
|
||||||
echo "$i"
|
echo "$i"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
export -f backup
|
export -f backup
|
||||||
@ -159,11 +89,11 @@ echo "$list_backups" && read -t 600 -p "Please type a number: " selection && res
|
|||||||
echo -e "\nWARNING:\nThis is NOT guranteed to work\nThis is ONLY supposed to be used as a LAST RESORT\nConsider rolling back your applications instead if possible" || { echo "FAILED"; exit; }
|
echo -e "\nWARNING:\nThis is NOT guranteed to work\nThis is ONLY supposed to be used as a LAST RESORT\nConsider rolling back your applications instead if possible" || { echo "FAILED"; exit; }
|
||||||
echo -e "\n\nYou have chosen:\n$restore_point\n\nWould you like to continue?" && echo -e "1 Yes\n2 No" && read -t 120 -p "Please type a number: " yesno || { echo "FAILED"; exit; }
|
echo -e "\n\nYou have chosen:\n$restore_point\n\nWould you like to continue?" && echo -e "1 Yes\n2 No" && read -t 120 -p "Please type a number: " yesno || { echo "FAILED"; exit; }
|
||||||
if [[ $yesno == "1" ]]; then
|
if [[ $yesno == "1" ]]; then
|
||||||
echo -e "\nStarting Backup, this will take a LONG time." && cli -c 'app kubernetes restore_backup backup_name=''"'"$restore_point"'"' || echo "Restore FAILED"
|
echo -e "\nStarting Backup, this will take a LONG time." && cli -c 'app kubernetes restore_backup backup_name=''"'"$restore_point"'"' || echo "Restore FAILED"
|
||||||
elif [[ $yesno == "2" ]]; then
|
elif [[ $yesno == "2" ]]; then
|
||||||
echo "You've chosen NO, killing script. Good luck."
|
echo "You've chosen NO, killing script. Good luck."
|
||||||
else
|
else
|
||||||
echo "Invalid Selection"
|
echo "Invalid Selection"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
export -f restore
|
export -f restore
|
||||||
@ -201,51 +131,51 @@ title
|
|||||||
echo -e "1 Mount\n2 Unmount All" && read -t 600 -p "Please type a number: " selection
|
echo -e "1 Mount\n2 Unmount All" && read -t 600 -p "Please type a number: " selection
|
||||||
[[ -z "$selection" ]] && echo "Your selection cannot be empty" && exit #Check for valid selection. If none, kill script
|
[[ -z "$selection" ]] && echo "Your selection cannot be empty" && exit #Check for valid selection. If none, kill script
|
||||||
if [[ $selection == "1" ]]; then
|
if [[ $selection == "1" ]]; then
|
||||||
list=$(k3s kubectl get pvc -A | sort -u | awk '{print NR-1, "\t" $1 "\t" $2 "\t" $4}' | column -t | sed "s/^0/ /")
|
list=$(k3s kubectl get pvc -A | sort -u | awk '{print NR-1, "\t" $1 "\t" $2 "\t" $4}' | column -t | sed "s/^0/ /")
|
||||||
echo "$list" && read -t 120 -p "Please type a number: " selection
|
echo "$list" && read -t 120 -p "Please type a number: " selection
|
||||||
[[ -z "$selection" ]] && echo "Your selection cannot be empty" && exit #Check for valid selection. If none, kill script
|
[[ -z "$selection" ]] && echo "Your selection cannot be empty" && exit #Check for valid selection. If none, kill script
|
||||||
app=$(echo -e "$list" | grep ^"$selection " | awk '{print $2}' | cut -c 4- )
|
app=$(echo -e "$list" | grep ^"$selection " | awk '{print $2}' | cut -c 4- )
|
||||||
[[ -z "$app" ]] && echo "Invalid Selection: $selection, was not an option" && exit #Check for valid selection. If none, kill script
|
[[ -z "$app" ]] && echo "Invalid Selection: $selection, was not an option" && exit #Check for valid selection. If none, kill script
|
||||||
pvc=$(echo -e "$list" | grep ^"$selection ")
|
pvc=$(echo -e "$list" | grep ^"$selection ")
|
||||||
status=$(cli -m csv -c 'app chart_release query name,status' | grep -E "^$app\b" | awk -F ',' '{print $2}'| tr -d " \t\n\r")
|
status=$(cli -m csv -c 'app chart_release query name,status' | grep -E "^$app\b" | awk -F ',' '{print $2}'| tr -d " \t\n\r")
|
||||||
if [[ "$status" != "STOPPED" ]]; then
|
if [[ "$status" != "STOPPED" ]]; then
|
||||||
[[ -z $timeout ]] && echo -e "\nDefault Timeout: 500" && timeout=500 || echo -e "\nCustom Timeout: $timeout"
|
[[ -z $timeout ]] && echo -e "\nDefault Timeout: 500" && timeout=500 || echo -e "\nCustom Timeout: $timeout"
|
||||||
SECONDS=0 && echo -e "\nScaling down $app" && midclt call chart.release.scale "$app" '{"replica_count": 0}' &> /dev/null
|
SECONDS=0 && echo -e "\nScaling down $app" && midclt call chart.release.scale "$app" '{"replica_count": 0}' &> /dev/null
|
||||||
else
|
else
|
||||||
echo -e "\n$app is already stopped"
|
echo -e "\n$app is already stopped"
|
||||||
fi
|
fi
|
||||||
while [[ "$SECONDS" -le "$timeout" && "$status" != "STOPPED" ]]
|
while [[ "$SECONDS" -le "$timeout" && "$status" != "STOPPED" ]]
|
||||||
do
|
do
|
||||||
status=$(cli -m csv -c 'app chart_release query name,status' | grep -E "^$app\b" | awk -F ',' '{print $2}'| tr -d " \t\n\r")
|
status=$(cli -m csv -c 'app chart_release query name,status' | grep -E "^$app\b" | awk -F ',' '{print $2}'| tr -d " \t\n\r")
|
||||||
echo -e "Waiting $((timeout-SECONDS)) more seconds for $app to be STOPPED" && sleep 5
|
echo -e "Waiting $((timeout-SECONDS)) more seconds for $app to be STOPPED" && sleep 5
|
||||||
done
|
done
|
||||||
data_name=$(echo "$pvc" | awk '{print $3}')
|
data_name=$(echo "$pvc" | awk '{print $3}')
|
||||||
mount=$(echo "$pvc" | awk '{print $4}')
|
mount=$(echo "$pvc" | awk '{print $4}')
|
||||||
volume_name=$(echo "$pvc" | awk '{print $4}')
|
volume_name=$(echo "$pvc" | awk '{print $4}')
|
||||||
full_path=$(zfs list | grep "$volume_name" | awk '{print $1}')
|
full_path=$(zfs list | grep "$volume_name" | awk '{print $1}')
|
||||||
echo -e "\nMounting\n$full_path\nTo\n/mnt/heavyscript/$data_name" && zfs set mountpoint=/heavyscript/"$data_name" "$full_path" && echo -e "Mounted\n\nUnmount with:\nzfs set mountpoint=legacy "$full_path" && rmdir /mnt/heavyscript/"$data_name"\n\nOr use the Unmount All option\n"
|
echo -e "\nMounting\n$full_path\nTo\n/mnt/heavyscript/$data_name" && zfs set mountpoint=/heavyscript/"$data_name" "$full_path" && echo -e "Mounted\n\nUnmount with:\nzfs set mountpoint=legacy "$full_path" && rmdir /mnt/heavyscript/"$data_name"\n\nOr use the Unmount All option\n"
|
||||||
exit
|
exit
|
||||||
elif [[ $selection == "2" ]]; then
|
elif [[ $selection == "2" ]]; then
|
||||||
mapfile -t unmount_array < <(basename -a /mnt/heavyscript/* | sed "s/*//")
|
mapfile -t unmount_array < <(basename -a /mnt/heavyscript/* | sed "s/*//")
|
||||||
[[ -z $unmount_array ]] && echo "Theres nothing to unmount" && exit
|
[[ -z $unmount_array ]] && echo "Theres nothing to unmount" && exit
|
||||||
for i in "${unmount_array[@]}"
|
for i in "${unmount_array[@]}"
|
||||||
do
|
do
|
||||||
main=$(k3s kubectl get pvc -A | grep -E "\s$i\s" | awk '{print $1, $2, $4}')
|
main=$(k3s kubectl get pvc -A | grep -E "\s$i\s" | awk '{print $1, $2, $4}')
|
||||||
app=$(echo "$main" | awk '{print $1}' | cut -c 4-)
|
app=$(echo "$main" | awk '{print $1}' | cut -c 4-)
|
||||||
pvc=$(echo "$main" | awk '{print $3}')
|
pvc=$(echo "$main" | awk '{print $3}')
|
||||||
mapfile -t path < <(find /mnt/*/ix-applications/releases/"$app"/volumes/ -maxdepth 0 | cut -c 6-)
|
mapfile -t path < <(find /mnt/*/ix-applications/releases/"$app"/volumes/ -maxdepth 0 | cut -c 6-)
|
||||||
if [[ "${#path[@]}" -gt 1 ]]; then #if there is another app with the same name on another pool, use the current pools application, since the other instance is probably old, or unused.
|
if [[ "${#path[@]}" -gt 1 ]]; then #if there is another app with the same name on another pool, use the current pools application, since the other instance is probably old, or unused.
|
||||||
echo "$i is a name used on more than one pool.. attempting to use your current kubernetes apps pool"
|
echo "$i is a name used on more than one pool.. attempting to use your current kubernetes apps pool"
|
||||||
pool=$(cli -c 'app kubernetes config' | grep -E "dataset\s\|" | awk -F '|' '{print $3}' | awk -F '/' '{print $1}' | tr -d " \t\n\r")
|
pool=$(cli -c 'app kubernetes config' | grep -E "dataset\s\|" | awk -F '|' '{print $3}' | awk -F '/' '{print $1}' | tr -d " \t\n\r")
|
||||||
full_path=$(find /mnt/"$pool"/ix-applications/releases/"$app"/volumes/ -maxdepth 0 | cut -c 6-)
|
full_path=$(find /mnt/"$pool"/ix-applications/releases/"$app"/volumes/ -maxdepth 0 | cut -c 6-)
|
||||||
zfs set mountpoint=legacy "$full_path""$pvc" && echo "$i unmounted" && rmdir /mnt/heavyscript/"$i" || echo "failed to unmount $i"
|
zfs set mountpoint=legacy "$full_path""$pvc" && echo "$i unmounted" && rmdir /mnt/heavyscript/"$i" || echo "failed to unmount $i"
|
||||||
else
|
else
|
||||||
zfs set mountpoint=legacy "$path""$pvc" && echo "$i unmounted" && rmdir /mnt/heavyscript/"$i" || echo "failed to unmount $i"
|
zfs set mountpoint=legacy "$path""$pvc" && echo "$i unmounted" && rmdir /mnt/heavyscript/"$i" || echo "failed to unmount $i"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
rmdir /mnt/heavyscript
|
rmdir /mnt/heavyscript
|
||||||
else
|
else
|
||||||
echo "Invalid selection, type -h for help"
|
echo "Invalid selection, \"$selection\" was not an option"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
export -f mount
|
export -f mount
|
||||||
@ -258,33 +188,33 @@ export -f sync
|
|||||||
|
|
||||||
|
|
||||||
update_apps(){
|
update_apps(){
|
||||||
mapfile -t array < <(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,container_images_update_available,status' | grep -E ",true(,|$)" | sort)
|
mapfile -t array < <(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,container_images_update_available,status' | grep -E ",true(,|$)" | sort)
|
||||||
[[ -z $array ]] && echo -e "\nThere are no updates available" && return 0 || echo -e "\n${#array[@]} update(s) available"
|
[[ -z $array ]] && echo -e "\nThere are no updates available" && return 0 || echo -e "\n${#array[@]} update(s) available"
|
||||||
[[ -z $timeout ]] && echo -e "\nDefault Timeout: 500" && timeout=500 || echo -e "\nCustom Timeout: $timeout"
|
[[ -z $timeout ]] && echo -e "\nDefault Timeout: 500" && timeout=500 || echo -e "\nCustom Timeout: $timeout"
|
||||||
[[ "$timeout" -le 120 ]] && echo "Warning: Your timeout is set low and may lead to premature rollbacks or skips"
|
[[ "$timeout" -le 120 ]] && echo "Warning: Your timeout is set low and may lead to premature rollbacks or skips"
|
||||||
for i in "${array[@]}"
|
for i in "${array[@]}"
|
||||||
do
|
do
|
||||||
app_name=$(echo "$i" | awk -F ',' '{print $1}') #print out first catagory, name.
|
app_name=$(echo "$i" | awk -F ',' '{print $1}') #print out first catagory, name.
|
||||||
old_app_ver=$(echo "$i" | awk -F ',' '{print $4}' | awk -F '_' '{print $1}' | awk -F '.' '{print $1}') #previous/current Application MAJOR Version
|
old_app_ver=$(echo "$i" | awk -F ',' '{print $4}' | awk -F '_' '{print $1}' | awk -F '.' '{print $1}') #previous/current Application MAJOR Version
|
||||||
new_app_ver=$(echo "$i" | awk -F ',' '{print $5}' | awk -F '_' '{print $1}' | awk -F '.' '{print $1}') #new Application MAJOR Version
|
new_app_ver=$(echo "$i" | awk -F ',' '{print $5}' | awk -F '_' '{print $1}' | awk -F '.' '{print $1}') #new Application MAJOR Version
|
||||||
old_chart_ver=$(echo "$i" | awk -F ',' '{print $4}' | awk -F '_' '{print $2}' | awk -F '.' '{print $1}') # Old Chart MAJOR version
|
old_chart_ver=$(echo "$i" | awk -F ',' '{print $4}' | awk -F '_' '{print $2}' | awk -F '.' '{print $1}') # Old Chart MAJOR version
|
||||||
new_chart_ver=$(echo "$i" | awk -F ',' '{print $5}' | awk -F '_' '{print $2}' | awk -F '.' '{print $1}') # New Chart MAJOR version
|
new_chart_ver=$(echo "$i" | awk -F ',' '{print $5}' | awk -F '_' '{print $2}' | awk -F '.' '{print $1}') # New Chart MAJOR version
|
||||||
status=$(echo "$i" | awk -F ',' '{print $2}') #status of the app: STOPPED / DEPLOYING / ACTIVE
|
status=$(echo "$i" | awk -F ',' '{print $2}') #status of the app: STOPPED / DEPLOYING / ACTIVE
|
||||||
startstatus=$status
|
startstatus=$status
|
||||||
diff_app=$(diff <(echo "$old_app_ver") <(echo "$new_app_ver")) #caluclating difference in major app versions
|
diff_app=$(diff <(echo "$old_app_ver") <(echo "$new_app_ver")) #caluclating difference in major app versions
|
||||||
diff_chart=$(diff <(echo "$old_chart_ver") <(echo "$new_chart_ver")) #caluclating difference in Chart versions
|
diff_chart=$(diff <(echo "$old_chart_ver") <(echo "$new_chart_ver")) #caluclating difference in Chart versions
|
||||||
old_full_ver=$(echo "$i" | awk -F ',' '{print $4}') #Upgraded From
|
old_full_ver=$(echo "$i" | awk -F ',' '{print $4}') #Upgraded From
|
||||||
new_full_ver=$(echo "$i" | awk -F ',' '{print $5}') #Upraded To
|
new_full_ver=$(echo "$i" | awk -F ',' '{print $5}') #Upraded To
|
||||||
rollback_version=$(echo "$i" | awk -F ',' '{print $4}' | awk -F '_' '{print $2}')
|
rollback_version=$(echo "$i" | awk -F ',' '{print $4}' | awk -F '_' '{print $2}')
|
||||||
printf '%s\0' "${ignore[@]}" | grep -iFxqz "${app_name}" && echo -e "\n$app_name\nIgnored, skipping" && continue #If application is on ignore list, skip
|
printf '%s\0' "${ignore[@]}" | grep -iFxqz "${app_name}" && echo -e "\n$app_name\nIgnored, skipping" && continue #If application is on ignore list, skip
|
||||||
if [[ "$diff_app" == "$diff_chart" || "$update_all_apps" == "true" ]]; then #continue to update
|
if [[ "$diff_app" == "$diff_chart" || "$update_all_apps" == "true" ]]; then #continue to update
|
||||||
if [[ $stop_before_update == "true" ]]; then # Check to see if user is using -S or not
|
if [[ $stop_before_update == "true" ]]; then # Check to see if user is using -S or not
|
||||||
if [[ "$status" == "STOPPED" ]]; then # if status is already stopped, skip while loop
|
if [[ "$status" == "STOPPED" ]]; then # if status is already stopped, skip while loop
|
||||||
echo -e "\n$app_name"
|
echo -e "\n$app_name"
|
||||||
[[ "$verbose" == "true" ]] && echo "Updating.."
|
[[ "$verbose" == "true" ]] && echo "Updating.."
|
||||||
cli -c 'app chart_release upgrade release_name=''"'"$app_name"'"' &> /dev/null && echo -e "Updated\n$old_full_ver\n$new_full_ver" && after_update_actions || echo "FAILED"
|
cli -c 'app chart_release upgrade release_name=''"'"$app_name"'"' &> /dev/null && echo -e "Updated\n$old_full_ver\n$new_full_ver" && after_update_actions || echo "FAILED"
|
||||||
continue
|
continue
|
||||||
else # if status was not STOPPED, stop the app prior to updating
|
else # if status was not STOPPED, stop the app prior to updating
|
||||||
echo -e "\n$app_name"
|
echo -e "\n$app_name"
|
||||||
[[ "$verbose" == "true" ]] && echo "Stopping prior to update.."
|
[[ "$verbose" == "true" ]] && echo "Stopping prior to update.."
|
||||||
midclt call chart.release.scale "$app_name" '{"replica_count": 0}' &> /dev/null && SECONDS=0 || echo -e "FAILED"
|
midclt call chart.release.scale "$app_name" '{"replica_count": 0}' &> /dev/null && SECONDS=0 || echo -e "FAILED"
|
||||||
@ -305,20 +235,21 @@ update_apps(){
|
|||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
else #user must not be using -S, just update
|
else #user must not be using -S, just update
|
||||||
echo -e "\n$app_name"
|
echo -e "\n$app_name"
|
||||||
[[ "$verbose" == "true" ]] && echo "Updating.."
|
[[ "$verbose" == "true" ]] && echo "Updating.."
|
||||||
cli -c 'app chart_release upgrade release_name=''"'"$app_name"'"' &> /dev/null && echo -e "Updated\n$old_full_ver\n$new_full_ver" && after_update_actions || { echo "FAILED"; continue; }
|
cli -c 'app chart_release upgrade release_name=''"'"$app_name"'"' &> /dev/null && echo -e "Updated\n$old_full_ver\n$new_full_ver" && after_update_actions || { echo "FAILED"; continue; }
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo -e "\n$app_name\nMajor Release, update manually"
|
echo -e "\n$app_name\nMajor Release, update manually"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
export -f update_apps
|
export -f update_apps
|
||||||
|
|
||||||
|
|
||||||
after_update_actions(){
|
after_update_actions(){
|
||||||
SECONDS=0
|
SECONDS=0
|
||||||
count=0
|
count=0
|
||||||
@ -384,11 +315,13 @@ fi
|
|||||||
}
|
}
|
||||||
export -f after_update_actions
|
export -f after_update_actions
|
||||||
|
|
||||||
|
|
||||||
prune(){
|
prune(){
|
||||||
echo -e "\nPruning Docker Images" && docker image prune -af | grep "^Total" || echo "Failed to Prune Docker Images"
|
echo -e "\nPruning Docker Images" && docker image prune -af | grep "^Total" || echo "Failed to Prune Docker Images"
|
||||||
}
|
}
|
||||||
export -f prune
|
export -f prune
|
||||||
|
|
||||||
|
|
||||||
title(){
|
title(){
|
||||||
echo ' _ _ _____ _ _ '
|
echo ' _ _ _____ _ _ '
|
||||||
echo '| | | | / ___| (_) | | '
|
echo '| | | | / ___| (_) | | '
|
||||||
@ -402,10 +335,94 @@ echo
|
|||||||
}
|
}
|
||||||
export -f title
|
export -f title
|
||||||
|
|
||||||
|
|
||||||
|
# Parse script options
|
||||||
|
while getopts ":si:rb:t:uUpSRv-:" opt
|
||||||
|
do
|
||||||
|
case $opt in
|
||||||
|
-)
|
||||||
|
case "${OPTARG}" in
|
||||||
|
help)
|
||||||
|
help="true"
|
||||||
|
;;
|
||||||
|
dns)
|
||||||
|
dns="true"
|
||||||
|
;;
|
||||||
|
restore)
|
||||||
|
restore="true"
|
||||||
|
;;
|
||||||
|
mount)
|
||||||
|
mount="true"
|
||||||
|
;;
|
||||||
|
delete-backup)
|
||||||
|
deleteBackup="true"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo -e "Invalid Option \"--$OPTARG\"\n" && help
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
\?)
|
||||||
|
echo -e "Invalid Option \"-$OPTARG\"\n" && help
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
:)
|
||||||
|
echo -e "Option: \"-$OPTARG\" requires an argument\n" && help
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
b)
|
||||||
|
re='^[0-9]+$'
|
||||||
|
number_of_backups=$OPTARG
|
||||||
|
! [[ $OPTARG =~ $re ]] && echo -e "Error: -b needs to be assigned an interger\n\"""$number_of_backups""\" is not an interger" >&2 && exit
|
||||||
|
[[ "$number_of_backups" -le 0 ]] && echo "Error: Number of backups is required to be at least 1" && exit
|
||||||
|
;;
|
||||||
|
r)
|
||||||
|
rollback="true"
|
||||||
|
;;
|
||||||
|
i)
|
||||||
|
ignore+=("$OPTARG")
|
||||||
|
;;
|
||||||
|
t)
|
||||||
|
re='^[0-9]+$'
|
||||||
|
timeout=$OPTARG
|
||||||
|
! [[ $timeout =~ $re ]] && echo -e "Error: -t needs to be assigned an interger\n\"""$timeout""\" is not an interger" >&2 && exit
|
||||||
|
;;
|
||||||
|
s)
|
||||||
|
sync="true"
|
||||||
|
;;
|
||||||
|
U)
|
||||||
|
update_all_apps="true"
|
||||||
|
;;
|
||||||
|
u)
|
||||||
|
update_apps="true"
|
||||||
|
;;
|
||||||
|
S)
|
||||||
|
stop_before_update="true"
|
||||||
|
;;
|
||||||
|
p)
|
||||||
|
prune="true"
|
||||||
|
;;
|
||||||
|
R)
|
||||||
|
rollback="true"
|
||||||
|
echo "WARNING: -R is being transisitioned to -r, this is due to a refactor in the script. Please Make the change ASAP!"
|
||||||
|
;;
|
||||||
|
v)
|
||||||
|
verbose="true"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo -e "Invalid Option \"--$OPTARG\"\n" && help
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
#exit if incompatable functions are called
|
#exit if incompatable functions are called
|
||||||
[[ "$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
|
||||||
|
[[ "$help" == "true" ]] && help
|
||||||
[[ "$deleteBackup" == "true" ]] && deleteBackup && exit
|
[[ "$deleteBackup" == "true" ]] && deleteBackup && exit
|
||||||
[[ "$dns" == "true" ]] && dns && exit
|
[[ "$dns" == "true" ]] && dns && exit
|
||||||
[[ "$restore" == "true" ]] && restore && exit
|
[[ "$restore" == "true" ]] && restore && exit
|
||||||
|
Loading…
Reference in New Issue
Block a user