From 407ebddbca345bf311b4159b17002427e6c95541 Mon Sep 17 00:00:00 2001 From: Kjeld Schouten-Lebbing Date: Tue, 27 Dec 2022 12:02:56 +0100 Subject: [PATCH] run pre-commit --- functions/backup.sh | 14 +++++++------- functions/cmd_to_container.sh | 6 +++--- functions/dns.sh | 2 +- functions/menu.sh | 8 ++++---- functions/misc.sh | 11 +++++------ functions/mount.sh | 16 ++++++++-------- functions/script_create.sh | 18 +++++++++--------- functions/self_update.sh | 8 ++++---- functions/update_apps.sh | 28 ++++++++++++++-------------- heavy_script.sh | 8 ++++---- 10 files changed, 59 insertions(+), 60 deletions(-) diff --git a/functions/backup.sh b/functions/backup.sh index 3a2e9b71..f0c2baf6 100644 --- a/functions/backup.sh +++ b/functions/backup.sh @@ -19,7 +19,7 @@ if [[ ${#list_backups[@]} -gt "$number_of_backups" ]]; then done fi -#Dump the echo_array, ensures all output is in a neat order. +#Dump the echo_array, ensures all output is in a neat order. for i in "${echo_backup[@]}" do echo -e "$i" @@ -52,9 +52,9 @@ do read -rt 240 -p "Please type a number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; } restore_point=$(echo "$list_backups" | grep ^"$selection)" | awk '{print $2}') if [[ $selection == 0 ]]; then - echo "Exiting.." + echo "Exiting.." exit - elif [[ -z "$selection" ]]; then + elif [[ -z "$selection" ]]; then echo "Your selection cannot be empty" sleep 3 continue @@ -70,7 +70,7 @@ done while true do clear -x - echo -e "WARNING:\nYou CANNOT go back after deleting your restore point" + echo -e "WARNING:\nYou CANNOT go back after deleting your restore point" echo -e "\n\nYou have chosen:\n$restore_point\n\n" read -rt 120 -p "Would you like to proceed with deletion? (y/N): " yesno || { echo -e "\nFailed to make a selection in time" ; exit; } case $yesno in @@ -104,7 +104,7 @@ do exit ;; *) - echo "$yesno was not an option, try again" + echo "$yesno was not an option, try again" sleep 2 continue ;; @@ -136,9 +136,9 @@ do read -rt 240 -p "Please type a number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; } restore_point=$(echo "$list_backups" | grep ^"$selection)" | awk '{print $2}') if [[ $selection == 0 ]]; then - echo "Exiting.." + echo "Exiting.." exit - elif [[ -z "$selection" ]]; then + elif [[ -z "$selection" ]]; then echo "Your selection cannot be empty" sleep 3 continue diff --git a/functions/cmd_to_container.sh b/functions/cmd_to_container.sh index e6f36f48..a9a4132e 100644 --- a/functions/cmd_to_container.sh +++ b/functions/cmd_to_container.sh @@ -6,7 +6,7 @@ app_name=$(k3s crictl pods -s ready --namespace ix | sed -E 's/[[:space:]]([0-9] while true do clear -x - title + title echo "Command to Container Menu" echo "-------------------------" echo "$app_name" @@ -92,7 +92,7 @@ do exit ;; 1) - clear -x + clear -x title read -rt 500 -p "What command do you want to run?: " command || { echo -e "\nFailed to make a selection in time" ; exit; } # shellcheck disable=SC2086 @@ -116,4 +116,4 @@ do done rm cont_file 2> /dev/null } -export -f cmd_to_container \ No newline at end of file +export -f cmd_to_container diff --git a/functions/dns.sh b/functions/dns.sh index ad6536d3..e628c12a 100644 --- a/functions/dns.sh +++ b/functions/dns.sh @@ -24,4 +24,4 @@ do done | nl -s ") " -b t | sed '0,/\s\s\s/{s/\s\s\s/- ---- -------- ----/}'| column -t -N "#,Name,DNS_Name,Port" rm dns_file } -export -f dns \ No newline at end of file +export -f dns diff --git a/functions/menu.sh b/functions/menu.sh index 82a04e03..8f808c57 100644 --- a/functions/menu.sh +++ b/functions/menu.sh @@ -28,7 +28,7 @@ case $selection in help ;; 2) - dns + dns ;; 3) mount @@ -71,7 +71,7 @@ case $selection in esac done ;; - + 5) self_update ;; @@ -84,7 +84,7 @@ case $selection in 8) patch_2212_backups ;; - 9) + 9) patch_2212_backups2 ;; *) @@ -93,4 +93,4 @@ case $selection in esac echo } -export -f menu \ No newline at end of file +export -f menu diff --git a/functions/misc.sh b/functions/misc.sh index 408fcd58..dd1ae239 100644 --- a/functions/misc.sh +++ b/functions/misc.sh @@ -2,10 +2,10 @@ sync(){ -echo_sync+=("🅂 🅈 🄽 🄲") +echo_sync+=("🅂 🅈 🄽 🄲") cli -c 'app catalog sync_all' &> /dev/null && echo_sync+=("Catalog sync complete") -#Dump the echo_array, ensures all output is in a neat order. +#Dump the echo_array, ensures all output is in a neat order. for i in "${echo_sync[@]}" do echo -e "$i" @@ -17,7 +17,7 @@ export -f sync prune(){ -echo -e "🄿 🅁 🅄 🄽 🄴" +echo -e "🄿 🅁 🅄 🄽 🄴" version="$(cli -c 'system version' | awk -F '-' '{print $3}' | awk -F '.' '{print $1 $2}' | tr -d " \t\r\.")" if (( "$version" >= 2212 )); then if ! cli -c 'app container config prune prune_options={"remove_unused_images": true, "remove_stopped_containers": true}' | head -n -4; then @@ -170,7 +170,7 @@ do continue ;; esac -done +done } @@ -228,6 +228,5 @@ do continue ;; esac -done +done } - diff --git a/functions/mount.sh b/functions/mount.sh index 7badfc58..371c98d7 100644 --- a/functions/mount.sh +++ b/functions/mount.sh @@ -28,15 +28,15 @@ do do clear -x title - echo "$list" - echo + echo "$list" + echo echo "0) Exit" read -rt 120 -p "Please type a number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; } - + #Check for valid selection. If no issues, continue [[ $selection == 0 ]] && echo "Exiting.." && exit app=$(echo -e "$list" | grep ^"$selection)" | awk '{print $2}' | cut -c 4- ) - [[ -z "$app" ]] && echo "Invalid Selection: $selection, was not an option" && sleep 3 && continue + [[ -z "$app" ]] && echo "Invalid Selection: $selection, was not an option" && sleep 3 && continue pvc=$(echo -e "$list" | grep ^"$selection)") #Stop applicaiton if not stopped @@ -64,7 +64,7 @@ do echo -e "\nMounted\n$data_name" fi echo -e "\nUnmount with:\nzfs set mountpoint=legacy $full_path && rmdir /mnt/heavyscript/$data_name\n\nOr use the Unmount All option\n" - + #Ask if user would like to mount something else while true do @@ -80,7 +80,7 @@ do exit ;; *) - echo "Invalid selection \"$yesno\" was not an option" + echo "Invalid selection \"$yesno\" was not an option" sleep 3 continue ;; @@ -97,7 +97,7 @@ do app=$(echo "$main" | awk '{print $1}' | cut -c 4-) pvc=$(echo "$main" | awk '{print $3}') full_path=$(find /mnt/"$pool"/ix-applications/releases/"$app"/volumes/ -maxdepth 0 | cut -c 6-) - zfs set mountpoint=legacy "$full_path""$pvc" + zfs set mountpoint=legacy "$full_path""$pvc" echo "$i unmounted" && rmdir /mnt/heavyscript/"$i" || echo "failed to unmount $i" done rmdir /mnt/heavyscript @@ -111,4 +111,4 @@ do esac done } -export -f mount \ No newline at end of file +export -f mount diff --git a/functions/script_create.sh b/functions/script_create.sh index 63802e63..3f1c26e4 100644 --- a/functions/script_create.sh +++ b/functions/script_create.sh @@ -2,7 +2,7 @@ script_create(){ -while true +while true do clear -x title @@ -19,7 +19,7 @@ do echo "Exiting.." exit ;; - 1 | -U) + 1 | -U) while true do echo -e "\nHow many applications do you want updating at the same time?" @@ -69,7 +69,7 @@ do ;; esac done -while true +while true do clear -x title @@ -91,9 +91,9 @@ do echo echo "99) Remove Update Options, Restart" echo "00) Done making selections, proceed with update" - echo + echo echo "0) Exit" - echo + echo echo "Current Choices" echo "---------------" echo "bash heavy_script.sh ${update_selection[*]}" @@ -153,11 +153,11 @@ do ;; 9 | --ignore-img ) printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "--ignore-img" && echo -e "\"--ignore-img\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it - update_selection+=("--ignore-img") + update_selection+=("--ignore-img") ;; 10 | --self-update ) printf '%s\0' "${update_selection[@]}" | grep -Fxqz -- "--self-update" && echo -e "\"--self-update\" is already on here, skipping" && sleep 3 && continue #If option is already on there, skip it - update_selection+=("--self-update") + update_selection+=("--self-update") ;; 99) count=2 @@ -172,9 +172,9 @@ do continue ;; *) - echo "\"$current_selection\" was not an option, try again" && sleep 3 && continue + echo "\"$current_selection\" was not an option, try again" && sleep 3 && continue ;; esac done } -export -f script_create \ No newline at end of file +export -f script_create diff --git a/functions/self_update.sh b/functions/self_update.sh index e06b2dc9..32795d01 100644 --- a/functions/self_update.sh +++ b/functions/self_update.sh @@ -11,7 +11,7 @@ echo "🅂 🄴 🄻 🄵" echo "🅄 🄿 🄳 🄰 🅃 🄴" if [[ "$hs_version" != "$latest_ver" ]] ; then echo "Found a new version of HeavyScript, updating myself..." - git checkout "$latest_ver" &>/dev/null + git checkout "$latest_ver" &>/dev/null count=0 for i in "${args[@]}" do @@ -22,16 +22,16 @@ if [[ "$hs_version" != "$latest_ver" ]] ; then echo "Updating To: $latest_ver" echo "Changelog:" curl --silent "https://api.github.com/repos/HeavyBullets8/heavy_script/releases/latest" | jq -r .body - echo + echo [[ -z ${args[*]} ]] && echo -e "No more arguments, exiting..\n\n" && exit echo -e "Running the new version...\n\n" sleep 5 exec bash "$script_name" "${args[@]}" # Now exit this old instance exit -else +else echo "HeavyScript is already the latest version:" echo -e "$hs_version\n\n" fi } -export -f self_update \ No newline at end of file +export -f self_update diff --git a/functions/update_apps.sh b/functions/update_apps.sh index 9f54bb33..6ad0d59f 100644 --- a/functions/update_apps.sh +++ b/functions/update_apps.sh @@ -38,7 +38,7 @@ do if [[ "$failed_ver" == "$new_full_ver" ]] ; then echo -e "\n$app_name\nSkipping previously failed version:\n$new_full_ver" unset "array[$index]" - else + else sed -i /"$app_name",/d failed fi #Skip Image updates if ignore image updates is set to true @@ -59,7 +59,7 @@ rm finished 2>/dev/null while [[ ${#processes[@]} != 0 || $(wc -l finished 2>/dev/null | awk '{ print $1 }') -lt "${#array[@]}" ]] do if while_status=$(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,container_images_update_available,status' 2>/dev/null) ; then - ((while_count++)) + ((while_count++)) [[ -z $while_status ]] && continue || echo -e "$while_count\n$while_status" > all_app_status mapfile -t deploying_check < <(grep ",DEPLOYING," all_app_status) for i in "${deploying_check[@]}" @@ -78,14 +78,14 @@ do for proc in "${processes[@]}" do kill -0 "$proc" &> /dev/null || unset "processes[$count]" - ((count++)) + ((count++)) done processes=("${processes[@]}") if [[ $index -lt ${#array[@]} && "${#processes[@]}" -lt "$update_limit" ]]; then pre_process "${array[$index]}" & processes+=($!) ((index++)) - else + else sleep 3 fi done @@ -107,7 +107,7 @@ rollback_version=$(echo "${array[$index]}" | awk -F ',' '{print $4}' | awk -F '_ # Check if app is external services, append outcome to external_services file [[ ! -e external_services ]] && touch external_services -if ! grep -qs "^$app_name," external_services ; then +if ! grep -qs "^$app_name," external_services ; then if ! grep -qs "/external-service" /mnt/"$pool"/ix-applications/releases/"$app_name"/charts/"$(find /mnt/"$pool"/ix-applications/releases/"$app_name"/charts/ -maxdepth 1 -type d -printf '%P\n' | sort -r | head -n 1)"/Chart.yaml; then echo "$app_name,false" >> external_services else @@ -178,7 +178,7 @@ count=0 if [[ $rollback == "true" || "$startstatus" == "STOPPED" ]]; then while true do - + # If app reports ACTIVE right away, assume its a false positive and wait for it to change, or trust it after 5 updates to all_app_status status=$(grep "^$app_name," all_app_status | awk -F ',' '{print $2}') if [[ $count -lt 1 && $status == "ACTIVE" && "$(grep "^$app_name," deploying 2>/dev/null | awk -F ',' '{print $2}')" != "DEPLOYING" ]]; then # If status shows up as Active or Stopped on the first check, verify that. Otherwise it may be a false report.. @@ -210,7 +210,7 @@ if [[ $rollback == "true" || "$startstatus" == "STOPPED" ]]; then break else echo_array+=("Active") - break + break fi elif [[ "$SECONDS" -ge "$timeout" ]]; then if [[ $rollback == "true" ]]; then @@ -219,14 +219,14 @@ if [[ $rollback == "true" || "$startstatus" == "STOPPED" ]]; then echo_array+=("Error: Run Time($SECONDS) for $app_name has exceeded Timeout($timeout)") echo_array+=("If this is a slow starting application, set a higher timeout with -t") echo_array+=("If this applicaion is always DEPLOYING, you can disable all probes under the Healthcheck Probes Liveness section in the edit configuration") - echo_array+=("Reverting update..") + echo_array+=("Reverting update..") if rollback_app ; then echo_array+=("Rolled Back") else echo_array+=("Error: Failed to rollback $app_name\nAbandoning") echo_array return 1 - fi + fi failed="true" SECONDS=0 count=0 @@ -286,7 +286,7 @@ do do sleep 1 done - else + else break fi done @@ -316,7 +316,7 @@ do break elif [[ ! $update_avail =~ "true" ]]; then break - else + else sleep 3 fi done @@ -338,7 +338,7 @@ do do sleep 1 done - else + else break fi done @@ -347,7 +347,7 @@ export -f stop_app echo_array(){ -#Dump the echo_array, ensures all output is in a neat order. +#Dump the echo_array, ensures all output is in a neat order. for i in "${echo_array[@]}" do echo -e "$i" @@ -360,4 +360,4 @@ export -f echo_array final_check(){ [[ ! -e finished ]] && touch finished echo "$app_name,finished" >> finished -} \ No newline at end of file +} diff --git a/heavy_script.sh b/heavy_script.sh index 91c0bc36..065a4c76 100644 --- a/heavy_script.sh +++ b/heavy_script.sh @@ -5,7 +5,7 @@ script=$(readlink -f "$0") script_path=$(dirname "$script") script_name="heavy_script.sh" -cd "$script_path" || { echo "Error: Failed to change to script directory" ; exit ; } +cd "$script_path" || { echo "Error: Failed to change to script directory" ; exit ; } #Version hs_version=$(git describe --tags) @@ -98,7 +98,7 @@ do update_limit="$nextopt" else update_limit=1 - fi + fi ;; u) update_apps="true" @@ -129,7 +129,7 @@ do 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 #Continue to call functions in specific order @@ -157,5 +157,5 @@ elif [[ "$sync" == "true" && -z "$number_of_backups" ]]; then # If only sync is sync fi [[ "$update_all_apps" == "true" || "$update_apps" == "true" ]] && commander -[[ "$prune" == "true" ]] && prune +[[ "$prune" == "true" ]] && prune exit 0