Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Major breaking update (#103)
Browse files Browse the repository at this point in the history
[Breaking Changes]
- Command line was changed, meaning all cron jobs will need to be changed.
- - I understand the inconvenience of breaking changes, but this was necessary to break apart the large script.
- Checkout the Github README for the new command line
- Alternatively, type heavyscript --help to see the new sub functions, you can also type --help on any sub-function
- - heavyscript update -h
- - This will show the help page specific to the update sub function

[Features]
- New config file for storing defaults of the script.
- CNPG apps databases are backed up
- Enable apt, kube API, helm, have all been added
- Start, Stop, Restart have been updated to accept app names as an argument E.g.
- - heavyscript app --start authelia
- All Flags now have long and short options
- Show app/chart versions when an application has a pending major update

[Bugfixes]
- pod shell and logs now can handle multi-replica applications
- Stop app function can now handle CNPG applications
- - CNPG applications deployments will be scaled down, but still show ACTIVE in the GUI.
  • Loading branch information
Heavybullets8 authored May 11, 2023
1 parent 7f60f93 commit 0bf1321
Show file tree
Hide file tree
Showing 77 changed files with 3,748 additions and 2,499 deletions.
67 changes: 67 additions & 0 deletions .default.config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[DNS]
## true/false options ##
# Show all pods within a namespace instead of just the main pod
verbose=false


[SELFUPDATE]
## true/false options ##
# Automatically update HeavyScript every time it runs
always=false

# Automatically update HeavyScript every time an application update is performed
when_updating=false

# Allow HeavyScript updates to include major version changes
include_major=false


[UPDATE]
## Integer options ##
# Number of applications to update concurrently
concurrent=1

# Timeout duration (in seconds) for requests
timeout=500

# Maximum number of HeavyScript/Truetool backups to retain
# Setting a value here will also enable backups to run
# automatically when updating applications
backup=

## true/false options ##
# Allow updates for major version changes of applications
include_major=false

# Update applications even if no new version is available
ignore_img=false

# Always prune images after updating
prune=false

# Automatically roll back applications if their update fails
rollback=false

# Sync the catalog before updating applications
sync=false

# Stop applications before updating
stop_before_update=false

# Enable verbose output for the update command
verbose=false

## String options ##
# Comma-separated list of applications to exclude from updates
# Example: ignore=plex,sonarr,radarr
ignore=


[databases]
## true/false options ##
# Enable or disable database dumps
enabled=true

## String options ##
# File path for database dump folder
dump_folder="./database_dumps"
233 changes: 147 additions & 86 deletions README.md

Large diffs are not rendered by default.

73 changes: 0 additions & 73 deletions functions/allowed.sh

This file was deleted.

57 changes: 57 additions & 0 deletions functions/app/app_select.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash


apps=()


prompt_app_selection() {
local action="$2"

clear -x
echo -e "${blue}Fetching applications..${reset}"

case "$1" in
"ALL")
mapfile -t apps < <(cli -m csv -c 'app chart_release query name,status' | tail -n +2 | sort | tr -d " \t\r" | awk 'NF')
search_type="Any"
;;
"STOPPED")
mapfile -t apps < <(cli -m csv -c 'app chart_release query name,status' | tail -n +2 | sort | tr -d " \t\r" | awk 'NF' | grep "STOPPED")
search_type="STOPPED"
;;
"ACTIVE")
mapfile -t apps < <(cli -m csv -c 'app chart_release query name,status' | tail -n +2 | sort | tr -d " \t\r" | awk 'NF' | grep "ACTIVE")
search_type="ACTIVE"
;;
esac

if [ "${#apps[@]}" -eq 0 ]; then
echo -e "${yellow}Application type: ${blue}$search_type${reset}"
echo -e "${yellow}Not found..${reset}"
exit 1
fi

clear -x
title

while true; do
echo -e "${bold}Choose an application to: $action${reset}"
echo
for i in "${!apps[@]}"; do
echo "$((i+1))) ${apps[i]}" | awk -F ',' '{print $1}'
done
echo
echo "0) Exit"
read -rt 120 -p "Choose an application by number: " app_index || { echo -e "\n${red}Failed to make a selection in time${reset}" ; exit; }
if [ "$app_index" -eq 0 ]; then
exit 0
elif [ "$app_index" -gt 0 ] && [ "$app_index" -le "${#apps[@]}" ]; then
app_name=$(echo "${apps[app_index-1]}" | awk -F ',' '{print $1}')
return "$app_index"
else
echo -e "${red}Invalid selection. Please choose a number from the list.${reset}"
sleep 3
fi
done
}

62 changes: 62 additions & 0 deletions functions/app/delete_app_prompt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash


delete_app_prompt(){
while true; do
# Prompt user to select an application if one was not passed to the function
if [[ -z $1 ]]; then
prompt_app_selection "ALL" "delete"
app_name=$(echo "${apps[app_index-1]}" | awk -F ',' '{print $1}')
clear -x
title
else
app_name="$1"
fi

clear -x
title

echo -e "Stopping ${blue}$app_name${reset}..."

echo -e "${bold}Chosen Application: ${blue}$app_name${reset}"
echo -e "${yellow}WARNING: This will delete the application and all associated data, including snapshots${reset}"
echo
while true; do
read -rt 120 -p "Continue with deletion?(y/n): " confirmation || { echo -e "\n${red}Failed to make a selection in time${reset}" ; exit; }
case "$(echo "$confirmation" | tr '[:upper:]' '[:lower:]')" in
"yes"|"y")
if cli -c "app chart_release delete release_name=\"$app_name\""; then
echo -e "${green}App $app_name deleted${reset}"
else
echo -e "${red}Failed to delete app $app_name${reset}"
fi
break
;;
"no"|"n"|"")
echo -e "Exiting.."
break
;;
*)
echo -e "${red}Invalid option. Please enter 'y' or 'n'.${reset}"
sleep 3
;;
esac
done

if [[ -n $1 ]]; then
break
fi

read -rt 120 -p "Would you like to delete another application? (y/n): " choice || { echo -e "\n${red}Failed to make a selection in time${reset}" ; exit; }
case "$(echo "$choice" | tr '[:upper:]' '[:lower:]')" in
"yes"|"y")
continue
;;
"no"|"n"|"")
break
;;
*)
echo "Invalid choice, please enter 'y' or 'n'"
esac
done
}
29 changes: 29 additions & 0 deletions functions/app/handler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash


app_handler() {
local args=("$@")

case "${args[0]}" in
-s|--start)
start_app_prompt "${args[@]:1}"
;;
-x|--stop)
stop_app_prompt "${args[@]:1}"
;;
-r|--restart)
restart_app_prompt "${args[@]:1}"
;;
-d|--delete)
delete_app_prompt "${args[@]:1}"
;;
-h|--help)
app_help
;;
*)
echo "Unknown app action: ${args[0]}"
app_help
exit 1
;;
esac
}
28 changes: 28 additions & 0 deletions functions/app/help.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash


app_help() {
echo -e "${bold}App Handler${reset}"
echo -e "${bold}-----------${reset}"
echo -e "${blue}heavyscript app [Option] [app_name]${reset}"
echo
echo -e "${bold}Description${reset}"
echo -e "${bold}-----------${reset}"
echo -e "Start, stop, restart and delete applications"
echo
echo -e "${bold}Options${reset}"
echo -e "${bold}-------${reset}"
echo -e "${blue}-s${reset}, ${blue}--start${reset} [app_name]"
echo -e " Start an application. If no app_name is provided, the user will be prompted to select one."
echo -e "${blue}-x${reset}, ${blue}--stop${reset} [app_name]"
echo -e " Stop an application. If no app_name is provided, the user will be prompted to select one."
echo -e "${blue}-r${reset}, ${blue}--restart${reset} [app_name]"
echo -e " Restart an application. If no app_name is provided, the user will be prompted to select one."
echo -e "${blue}-d${reset}, ${blue}--delete${reset} [app_name]"
echo -e " Delete an application. If no app_name is provided, the user will be prompted to select one."
echo -e "${blue}-h${reset}, ${blue}--help${reset}"
echo -e " Display this help message."
echo
}


40 changes: 40 additions & 0 deletions functions/app/restart_app_prompt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash


restart_app_prompt(){
while true; do
# Prompt user to select an application if one was not passed to the function
if [[ -z $1 ]]; then
prompt_app_selection "ALL" "restart"
app_name=$(echo "${apps[app_index-1]}" | awk -F ',' '{print $1}')
clear -x
title
else
app_name="$1"
fi

echo -e "Restarting ${blue}$app_name${reset}..."

if ! restart_app; then
echo -e "${red}Failed to restart ${blue}$app_name${reset}"
else
echo -e "${green}Restarted ${blue}$app_name${reset}"
fi

if [[ -n $1 ]]; then
break
fi

read -rt 120 -p "Would you like to restart another application? (y/N): " choice || { echo -e "\n${red}Failed to make a selection in time${reset}" ; exit; }
case "$(echo "$choice" | tr '[:upper:]' '[:lower:]')" in
"yes"|"y")
continue
;;
"no"|"n"|"")
break
;;
*)
echo -e "${red}Invalid choice, please enter ${blue}'y'${red} or ${blue}'n'${reset}"
esac
done
}
Loading

0 comments on commit 0bf1321

Please sign in to comment.