This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
heavy_script.sh
149 lines (134 loc) · 3.69 KB
/
heavy_script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
declare -x no_config=false
declare -x no_self_update=false
declare -x self_update=false
declare -x major_self_update=false
declare -x script
declare -x script_path
declare -x script_name
declare -x current_tag
declare -x current_version
declare -x hs_version
# colors
declare -x reset='\033[0m'
declare -x red='\033[0;31m'
declare -x yellow='\033[1;33m'
declare -x green='\033[0;32m'
declare -x blue='\033[0;34m'
declare -x bold='\033[1m'
declare -x gray='\033[38;5;7m'
# cd to script, this ensures the script can find the source scripts below, even when ran from a separate directory
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; }
# Get the name of the latest tag
current_tag=$(git describe --tags --abbrev=0)
# Check if the current version is a branch or a tag
current_version=$(git rev-parse --abbrev-ref HEAD)
if [[ "$current_version" == "HEAD" ]]; then
# The current version is a tag, assign the name of the current tag to the hs_version variable
hs_version=${current_tag}
else
# The current version is a branch, assign the name of the current branch to the hs_version variable
hs_version=${current_version}
fi
# Source all functions and utilities
while IFS= read -r script_file; do
if [[ "$script_file" == "functions/deploy.sh" ]]; then
# Ignore the deploy.sh file, it is meant to install the script
continue
fi
# shellcheck source=/dev/null
source "$script_file"
done < <(find functions utils -name "*.sh" -exec printf '%s\n' {} \;)
# Ensure sudoers file contains the necessary configuration
if [[ $EUID -eq 0 ]]; then
ensure_sudoers
fi
# generate the config.ini file if it does not exist
generate_config_ini
# Separate bundled short options
args=()
for arg in "$@"; do
if [[ $arg =~ ^-[aIprsxUv]+$ ]]; then
for opt in $(echo "$arg" | grep -o .); do
if [[ $opt == "-" ]]; then
# Ignore the leading dash
continue
fi
args+=("-$opt")
done
else
args+=("$arg")
fi
done
if remove_self_update_args; then
self_update=true
fi
if remove_force_update_args; then
major_self_update=true
fi
if remove_no_self_update_args; then
no_self_update=true
fi
if remove_no_config_args; then
no_config=true
fi
# Run the self update function if the script has not already been updated
if [[ $no_self_update == false ]]; then
self_update_handler "${args[@]}"
fi
# If no arguments are passed, the first argument is an empty string, '-', or '--', open the menu function.
if [[ "${#args[@]}" -eq 0 || "${args[0]}" =~ ^(-{1,2})?$ ]]; then
menu
exit
fi
case "${args[0]}" in
app)
check_root "${args[@]}"
app_handler "${args[@]:1}"
;;
backup)
check_root "${args[@]}"
backup_handler "${args[@]:1}"
;;
dns)
check_root "${args[@]}"
dns_handler "${args[@]:1}"
;;
enable)
check_root "${args[@]}"
enable_handler "${args[@]:1}"
;;
git)
git_handler "${args[@]:1}"
;;
pod)
check_root "${args[@]}"
pod_handler "${args[@]:1}"
;;
pvc)
check_root "${args[@]}"
pvc_handler "${args[@]:1}"
;;
update)
check_root "${args[@]}"
update_handler "${args[@]:1}"
;;
sync)
check_root "${args[@]}"
sync_handler "${args[@]:1}"
;;
prune)
check_root "${args[@]}"
prune_handler "${args[@]:1}"
;;
-h|--help|help)
main_help
;;
*)
echo "Unknown command: $1"
exit 1
;;
esac