run pre-commit

This commit is contained in:
Kjeld Schouten-Lebbing 2022-12-27 12:02:56 +01:00
parent a58d53ac4e
commit 407ebddbca
10 changed files with 59 additions and 60 deletions

View File

@ -19,7 +19,7 @@ if [[ ${#list_backups[@]} -gt "$number_of_backups" ]]; then
done done
fi 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[@]}" for i in "${echo_backup[@]}"
do do
echo -e "$i" 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; } 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}') restore_point=$(echo "$list_backups" | grep ^"$selection)" | awk '{print $2}')
if [[ $selection == 0 ]]; then if [[ $selection == 0 ]]; then
echo "Exiting.." echo "Exiting.."
exit exit
elif [[ -z "$selection" ]]; then elif [[ -z "$selection" ]]; then
echo "Your selection cannot be empty" echo "Your selection cannot be empty"
sleep 3 sleep 3
continue continue
@ -70,7 +70,7 @@ done
while true while true
do do
clear -x 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" 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; } 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 case $yesno in
@ -104,7 +104,7 @@ do
exit exit
;; ;;
*) *)
echo "$yesno was not an option, try again" echo "$yesno was not an option, try again"
sleep 2 sleep 2
continue 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; } 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}') restore_point=$(echo "$list_backups" | grep ^"$selection)" | awk '{print $2}')
if [[ $selection == 0 ]]; then if [[ $selection == 0 ]]; then
echo "Exiting.." echo "Exiting.."
exit exit
elif [[ -z "$selection" ]]; then elif [[ -z "$selection" ]]; then
echo "Your selection cannot be empty" echo "Your selection cannot be empty"
sleep 3 sleep 3
continue continue

View File

@ -6,7 +6,7 @@ app_name=$(k3s crictl pods -s ready --namespace ix | sed -E 's/[[:space:]]([0-9]
while true while true
do do
clear -x clear -x
title title
echo "Command to Container Menu" echo "Command to Container Menu"
echo "-------------------------" echo "-------------------------"
echo "$app_name" echo "$app_name"
@ -92,7 +92,7 @@ do
exit exit
;; ;;
1) 1)
clear -x clear -x
title title
read -rt 500 -p "What command do you want to run?: " command || { echo -e "\nFailed to make a selection in time" ; exit; } 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 # shellcheck disable=SC2086
@ -116,4 +116,4 @@ do
done done
rm cont_file 2> /dev/null rm cont_file 2> /dev/null
} }
export -f cmd_to_container export -f cmd_to_container

View File

@ -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" done | nl -s ") " -b t | sed '0,/\s\s\s/{s/\s\s\s/- ---- -------- ----/}'| column -t -N "#,Name,DNS_Name,Port"
rm dns_file rm dns_file
} }
export -f dns export -f dns

View File

@ -28,7 +28,7 @@ case $selection in
help help
;; ;;
2) 2)
dns dns
;; ;;
3) 3)
mount mount
@ -71,7 +71,7 @@ case $selection in
esac esac
done done
;; ;;
5) 5)
self_update self_update
;; ;;
@ -84,7 +84,7 @@ case $selection in
8) 8)
patch_2212_backups patch_2212_backups
;; ;;
9) 9)
patch_2212_backups2 patch_2212_backups2
;; ;;
*) *)
@ -93,4 +93,4 @@ case $selection in
esac esac
echo echo
} }
export -f menu export -f menu

View File

@ -2,10 +2,10 @@
sync(){ sync(){
echo_sync+=("🅂 🅈 🄽 🄲") echo_sync+=("🅂 🅈 🄽 🄲")
cli -c 'app catalog sync_all' &> /dev/null && echo_sync+=("Catalog sync complete") 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[@]}" for i in "${echo_sync[@]}"
do do
echo -e "$i" echo -e "$i"
@ -17,7 +17,7 @@ export -f sync
prune(){ prune(){
echo -e "🄿 🅁 🅄 🄽 🄴" echo -e "🄿 🅁 🅄 🄽 🄴"
version="$(cli -c 'system version' | awk -F '-' '{print $3}' | awk -F '.' '{print $1 $2}' | tr -d " \t\r\.")" version="$(cli -c 'system version' | awk -F '-' '{print $3}' | awk -F '.' '{print $1 $2}' | tr -d " \t\r\.")"
if (( "$version" >= 2212 )); then 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 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 continue
;; ;;
esac esac
done done
} }
@ -228,6 +228,5 @@ do
continue continue
;; ;;
esac esac
done done
} }

View File

@ -28,15 +28,15 @@ do
do do
clear -x clear -x
title title
echo "$list" echo "$list"
echo echo
echo "0) Exit" echo "0) Exit"
read -rt 120 -p "Please type a number: " selection || { echo -e "\nFailed to make a selection in time" ; 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 #Check for valid selection. If no issues, continue
[[ $selection == 0 ]] && echo "Exiting.." && exit [[ $selection == 0 ]] && echo "Exiting.." && exit
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" && sleep 3 && continue [[ -z "$app" ]] && echo "Invalid Selection: $selection, was not an option" && sleep 3 && continue
pvc=$(echo -e "$list" | grep ^"$selection)") pvc=$(echo -e "$list" | grep ^"$selection)")
#Stop applicaiton if not stopped #Stop applicaiton if not stopped
@ -64,7 +64,7 @@ do
echo -e "\nMounted\n$data_name" echo -e "\nMounted\n$data_name"
fi fi
echo -e "\nUnmount with:\nzfs set mountpoint=legacy $full_path && rmdir /mnt/heavyscript/$data_name\n\nOr use the Unmount All option\n" 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 #Ask if user would like to mount something else
while true while true
do do
@ -80,7 +80,7 @@ do
exit exit
;; ;;
*) *)
echo "Invalid selection \"$yesno\" was not an option" echo "Invalid selection \"$yesno\" was not an option"
sleep 3 sleep 3
continue continue
;; ;;
@ -97,7 +97,7 @@ do
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}')
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" zfs set mountpoint=legacy "$full_path""$pvc"
echo "$i unmounted" && rmdir /mnt/heavyscript/"$i" || echo "failed to unmount $i" echo "$i unmounted" && rmdir /mnt/heavyscript/"$i" || echo "failed to unmount $i"
done done
rmdir /mnt/heavyscript rmdir /mnt/heavyscript
@ -111,4 +111,4 @@ do
esac esac
done done
} }
export -f mount export -f mount

View File

@ -2,7 +2,7 @@
script_create(){ script_create(){
while true while true
do do
clear -x clear -x
title title
@ -19,7 +19,7 @@ do
echo "Exiting.." echo "Exiting.."
exit exit
;; ;;
1 | -U) 1 | -U)
while true while true
do do
echo -e "\nHow many applications do you want updating at the same time?" echo -e "\nHow many applications do you want updating at the same time?"
@ -69,7 +69,7 @@ do
;; ;;
esac esac
done done
while true while true
do do
clear -x clear -x
title title
@ -91,9 +91,9 @@ do
echo echo
echo "99) Remove Update Options, Restart" echo "99) Remove Update Options, Restart"
echo "00) Done making selections, proceed with update" echo "00) Done making selections, proceed with update"
echo echo
echo "0) Exit" echo "0) Exit"
echo echo
echo "Current Choices" echo "Current Choices"
echo "---------------" echo "---------------"
echo "bash heavy_script.sh ${update_selection[*]}" echo "bash heavy_script.sh ${update_selection[*]}"
@ -153,11 +153,11 @@ do
;; ;;
9 | --ignore-img ) 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 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 ) 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 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) 99)
count=2 count=2
@ -172,9 +172,9 @@ do
continue 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 esac
done done
} }
export -f script_create export -f script_create

View File

@ -11,7 +11,7 @@ echo "🅂 🄴 🄻 🄵"
echo "🅄 🄿 🄳 🄰 🅃 🄴" echo "🅄 🄿 🄳 🄰 🅃 🄴"
if [[ "$hs_version" != "$latest_ver" ]] ; then if [[ "$hs_version" != "$latest_ver" ]] ; then
echo "Found a new version of HeavyScript, updating myself..." echo "Found a new version of HeavyScript, updating myself..."
git checkout "$latest_ver" &>/dev/null git checkout "$latest_ver" &>/dev/null
count=0 count=0
for i in "${args[@]}" for i in "${args[@]}"
do do
@ -22,16 +22,16 @@ if [[ "$hs_version" != "$latest_ver" ]] ; then
echo "Updating To: $latest_ver" echo "Updating To: $latest_ver"
echo "Changelog:" echo "Changelog:"
curl --silent "https://api.github.com/repos/HeavyBullets8/heavy_script/releases/latest" | jq -r .body 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 [[ -z ${args[*]} ]] && echo -e "No more arguments, exiting..\n\n" && exit
echo -e "Running the new version...\n\n" echo -e "Running the new version...\n\n"
sleep 5 sleep 5
exec bash "$script_name" "${args[@]}" exec bash "$script_name" "${args[@]}"
# Now exit this old instance # Now exit this old instance
exit exit
else else
echo "HeavyScript is already the latest version:" echo "HeavyScript is already the latest version:"
echo -e "$hs_version\n\n" echo -e "$hs_version\n\n"
fi fi
} }
export -f self_update export -f self_update

View File

@ -38,7 +38,7 @@ do
if [[ "$failed_ver" == "$new_full_ver" ]] ; then if [[ "$failed_ver" == "$new_full_ver" ]] ; then
echo -e "\n$app_name\nSkipping previously failed version:\n$new_full_ver" echo -e "\n$app_name\nSkipping previously failed version:\n$new_full_ver"
unset "array[$index]" unset "array[$index]"
else else
sed -i /"$app_name",/d failed sed -i /"$app_name",/d failed
fi fi
#Skip Image updates if ignore image updates is set to true #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[@]}" ]] while [[ ${#processes[@]} != 0 || $(wc -l finished 2>/dev/null | awk '{ print $1 }') -lt "${#array[@]}" ]]
do 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 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 [[ -z $while_status ]] && continue || echo -e "$while_count\n$while_status" > all_app_status
mapfile -t deploying_check < <(grep ",DEPLOYING," all_app_status) mapfile -t deploying_check < <(grep ",DEPLOYING," all_app_status)
for i in "${deploying_check[@]}" for i in "${deploying_check[@]}"
@ -78,14 +78,14 @@ do
for proc in "${processes[@]}" for proc in "${processes[@]}"
do do
kill -0 "$proc" &> /dev/null || unset "processes[$count]" kill -0 "$proc" &> /dev/null || unset "processes[$count]"
((count++)) ((count++))
done done
processes=("${processes[@]}") processes=("${processes[@]}")
if [[ $index -lt ${#array[@]} && "${#processes[@]}" -lt "$update_limit" ]]; then if [[ $index -lt ${#array[@]} && "${#processes[@]}" -lt "$update_limit" ]]; then
pre_process "${array[$index]}" & pre_process "${array[$index]}" &
processes+=($!) processes+=($!)
((index++)) ((index++))
else else
sleep 3 sleep 3
fi fi
done 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 # Check if app is external services, append outcome to external_services file
[[ ! -e external_services ]] && touch external_services [[ ! -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 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 echo "$app_name,false" >> external_services
else else
@ -178,7 +178,7 @@ count=0
if [[ $rollback == "true" || "$startstatus" == "STOPPED" ]]; then if [[ $rollback == "true" || "$startstatus" == "STOPPED" ]]; then
while true while true
do 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 # 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}') 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.. 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 break
else else
echo_array+=("Active") echo_array+=("Active")
break break
fi fi
elif [[ "$SECONDS" -ge "$timeout" ]]; then elif [[ "$SECONDS" -ge "$timeout" ]]; then
if [[ $rollback == "true" ]]; 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+=("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 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+=("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 if rollback_app ; then
echo_array+=("Rolled Back") echo_array+=("Rolled Back")
else else
echo_array+=("Error: Failed to rollback $app_name\nAbandoning") echo_array+=("Error: Failed to rollback $app_name\nAbandoning")
echo_array echo_array
return 1 return 1
fi fi
failed="true" failed="true"
SECONDS=0 SECONDS=0
count=0 count=0
@ -286,7 +286,7 @@ do
do do
sleep 1 sleep 1
done done
else else
break break
fi fi
done done
@ -316,7 +316,7 @@ do
break break
elif [[ ! $update_avail =~ "true" ]]; then elif [[ ! $update_avail =~ "true" ]]; then
break break
else else
sleep 3 sleep 3
fi fi
done done
@ -338,7 +338,7 @@ do
do do
sleep 1 sleep 1
done done
else else
break break
fi fi
done done
@ -347,7 +347,7 @@ export -f stop_app
echo_array(){ 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[@]}" for i in "${echo_array[@]}"
do do
echo -e "$i" echo -e "$i"
@ -360,4 +360,4 @@ export -f echo_array
final_check(){ final_check(){
[[ ! -e finished ]] && touch finished [[ ! -e finished ]] && touch finished
echo "$app_name,finished" >> finished echo "$app_name,finished" >> finished
} }

View File

@ -5,7 +5,7 @@
script=$(readlink -f "$0") script=$(readlink -f "$0")
script_path=$(dirname "$script") script_path=$(dirname "$script")
script_name="heavy_script.sh" 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 #Version
hs_version=$(git describe --tags) hs_version=$(git describe --tags)
@ -98,7 +98,7 @@ do
update_limit="$nextopt" update_limit="$nextopt"
else else
update_limit=1 update_limit=1
fi fi
;; ;;
u) u)
update_apps="true" update_apps="true"
@ -129,7 +129,7 @@ do
done 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
@ -157,5 +157,5 @@ elif [[ "$sync" == "true" && -z "$number_of_backups" ]]; then # If only sync is
sync sync
fi fi
[[ "$update_all_apps" == "true" || "$update_apps" == "true" ]] && commander [[ "$update_all_apps" == "true" || "$update_apps" == "true" ]] && commander
[[ "$prune" == "true" ]] && prune [[ "$prune" == "true" ]] && prune
exit 0 exit 0