-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathstart.sh
More file actions
478 lines (447 loc) · 13.3 KB
/
start.sh
File metadata and controls
478 lines (447 loc) · 13.3 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
#!/bin/sh
. scripts/banner.sh
. scripts/shared-component.sh
sh scripts/init.sh
. scripts/editor.sh
. scripts/runtime/container-config.sh
. scripts/sub-menu/app-manager.sh
. scripts/arch-image-tag.sh
. scripts/arch-platform-runtime.sh
. scripts/runtime/runtime-manager.sh
get_stats() {
current_limit=$($SET_LIMIT | awk '{print $NF}')
if [ "$current_limit" != "$__CACHED_LIMIT" ] || [ -z "$STATS" ]; then
STATS="$(sh scripts/limits.sh "$current_limit")"
__CACHED_LIMIT="$current_limit"
fi
}
SYS_INFO=$($SYS_INFO)
__CACHED_LIMIT="" # Cache to avoid redundant limit calculations
get_stats # Initialize at startup (cached on subsequent calls)
stats() {
printf "%s\n\n" "$SYS_INFO"
printf "%s\n" "$STATS"
printf "${GREEN}------------------------------------------${NC}\n\n"
}
option_2() {
options="(1-5)"
while true; do
display_banner
echo "1. Set up configuration"
echo "2. View config file"
echo "3. Edit config file"
echo "4. Enable or disable applications"
echo "5. Backup & restore config"
echo "0. Return to Main Menu"
echo
printf "Select an option $options: "; read -r option
case $option in
1)
display_banner
printf "Setting up application configuration...\n\n"
$APP_CONFIG
;;
2)
display_banner
$VIEW_CONFIG
;;
3)
display_banner
get_editor_description
printf "\nPress Enter to continue..."; read -r input
run_editor $ENV_FILE
;;
4)
$APP_SELECTION
;;
5)
$BACKUP_RESTORE
;;
0)
break # Return to the main menu
;;
*)
printf "\nInvalid option. Please select a valid option $options.\n"
printf "\nPress Enter to continue..."; read -r input
;;
esac
done
}
option_8() {
if [ "$1" = "quick_menu" ]; then
return_option="0. Exit"
else
return_option="0. Return to Main Menu"
fi
options="(1-5)"
while true; do
display_banner
printf "Pick a new resource limit utilization based\non the current hardware limits.\n\n"
printf "%s\n\n" "$STATS"
echo "1. BASE --> 350MB RAM"
echo "2. MIN --> 12.5% Total RAM"
echo "3. LOW --> 18.75% Total RAM"
echo "4. MID --> 25% Total RAM"
echo "5. MAX --> 50% Total RAM"
echo "$return_option"
printf "\nSelect an option $options: "; read -r option
case $option in
1|2|3|4|5)
limit_type=""
case $option in
1) limit_type="base" ;;
2) limit_type="min" ;;
3) limit_type="low" ;;
4) limit_type="mid" ;;
5) limit_type="max" ;;
esac
echo
$SET_LIMIT "$limit_type"
get_stats
printf "\nRedeploy applications for new limits to take effect.\n"
;;
0)
break ;; # Return to the main menu
*)
printf "\nInvalid option. Please select a valid option $options.\n" ;;
esac
printf "\nPress Enter to continue..."; read -r _
done
}
run_updater() {
display_banner
case "$1" in
--cli)
$UPDATE_CHECKER --update
;;
--force)
$UPDATE_CHECKER --force
;;
*)
$UPDATE_CHECKER --update
unset NEW_UPDATE
;;
esac
$APP_SELECTION --import
printf "\nPress Enter to continue..."; read -r _
}
manage_tool() {
options="(1-6)"
while true; do
display_banner
echo "1. Backup & restore config"
echo "2. Manage application state"
echo "3. Reset resource limit"
echo "4. Reset all back to default"
echo "5. Check and get update"
echo "6. Change editor tool"
echo "0. Return to Main Menu"
printf "\nSelect an option $options: "; read -r option
case $option in
1)
$BACKUP_RESTORE
;;
2)
options="(1-2)"
while true; do
display_banner
printf "Re-enable, restore saved application state.\n\n"
echo "1. Re-enable all applications"
echo "2. Restore from saved application state"
echo "0. Return to Main Menu"
printf "\nSelect an option $options: "; read -r choice
case $choice in
1)
$APP_SELECTION --default
printf "\nAll applications have been re-enabled.\n"
printf "\nPress Enter to continue..."; read -r input
;;
2)
$APP_SELECTION --restore
printf "\nPress Enter to continue..."; read -r input
;;
0)
break
;;
*)
printf "\nInvalid option. Please select a valid option $options.\n"
printf "\nPress Enter to continue..."; read -r input
;;
esac
done
;;
3)
echo
$SET_LIMIT low
get_stats
printf "\nPress Enter to continue..."; read -r input
;;
4)
while true; do
display_banner
printf "${RED}WARNING!${NC}\n\nAbout to reset everything back to default.\n"
printf "This will remove all configured credentials as well.\n"
printf "Disabled apps will be re-enabled for deployment again.\n"
printf "\nDo you want to backup credentials first? (Y/N): "; read -r yn
case $yn in
[Yy]*)
$BACKUP_RESTORE
$APP_SELECTION --backup
break
;;
[Nn]*)
break
;;
*)
printf "\nPlease input yes (Y/y) or no (N/n).\n"
;;
esac
printf "\nPress Enter to continue..."; read -r input
done
display_banner
rm -rf "$ENV_FILE" "$ENV_SYSTEM_FILE" "${ENV_DEPLOY_FILE}.save" "$ENV_DEPLOY_PROXY_FILE" "$ENV_IMAGE_TAG_FILE" "$ENV_PLATFORM_OVERRIDE_FILE"
# Re-init some default setups
sh scripts/init.sh > /dev/null 2>&1
get_stats
$APP_SELECTION --default
run_arch_image_tag
run_platform_override
printf "All settings have been reset. Please run ${PINK}Setup Configuration${NC} again.\n"
printf "Resource limits will need to be re-applied if previously set.\n"
printf "Settings for Income Generator Proxy are left alone.\n"
printf "\nWhat settings can be restored?\n"
printf " - Application credentials if previously backed up.\n"
printf " - State of applications that's been ${GREEN}enabled${NC}/${RED}disabled${NC} for use.\n"
printf "\nPress Enter to continue..."; read -r _
;;
5)
run_updater
;;
6)
display_banner
set_editor
;;
0)
break # Return to the main menu
;;
*)
printf "\nInvalid option. Please select a valid option $options.\n"
printf "\nPress Enter to continue..."; read -r input
;;
esac
done
}
tool_reset() {
while true; do
display_banner
printf "Do you want to reset IGM system settings? (Y/N): "; read -r yn
case $yn in
[Yy]*)
display_banner
rm -rf .env.system
echo "IGM system setting has been reset."
printf "\nPress Enter to continue..."; read -r input
break
;;
''|[Nn]*)
break
;;
*)
printf "\nPlease input yes (Y/y) or no (N/n).\n"
printf "\nPress Enter to continue..."; read -r input
;;
esac
done
}
main_menu() {
NEW_UPDATE=$($UPDATE_CHECKER)
options="(1-9)"
while true; do
display_banner --noline
stats
[ -n "$NEW_UPDATE" ] && printf "$NEW_UPDATE\n"
echo "1. Install & Run Applications"
echo "2. Setup Configuration"
echo "3. Start Applications"
echo "4. Stop Applications"
echo "5. Remove Applications"
echo "6. Show Installed Applications"
echo "7. Manage Runtime"
echo "8. Change Resource Limits"
echo "9. Manage Tool"
echo "0. Quit"
printf "\nSelect an option $options: "; read -r choice
case $choice in
0) display_banner; echo "Quitting..."; sleep 0.62; clear; break ;;
1) install_applications ;;
2) option_2 ;;
3) start_applications ;;
4) stop_applications ;;
5) remove_applications ;;
6) show_applications group ;;
7) runtime_menu ;;
8) option_8 ;;
9) manage_tool ;;
*)
printf "\nInvalid option. Please select a valid option $options.\n"
printf "\nPress Enter to continue..."; read -r input
;;
esac
done
}
# Main script
trap '$POST_OPS; clear; exit 0' INT TERM HUP
$DECRYPT_CRED
case "$1" in
-h|--help|help)
display_banner
. scripts/help.sh
;;
-v|--version|version)
ver=$(git describe --tags --abbrev=0 2>/dev/null || echo "unknown")
printf "version: $ver\n"
;;
"")
$APP_SELECTION --import
main_menu
;;
tool)
if [ "$2" = "reset" ]; then
tool_reset
clear
fi
;;
proxy)
set -- "$2"
. scripts/proxy/proxy-menu.sh
clear
;;
start)
shift
if [ "$#" -gt 0 ]; then
for app in "$@"; do
start_application "$app"
done
else
start_applications
clear
fi
;;
stop)
shift
if [ "$#" -gt 0 ]; then
for app in "$@"; do
stop_application "$app"
done
else
stop_applications
clear
fi
;;
restart)
if [ -n "$2" ]; then
restart_application "$2"
fi
;;
remove)
shift
if [ "$#" -gt 0 ]; then
for app in "$@"; do
remove_application "$app"
done
else
remove_applications
clear
fi
;;
logs)
show_application_log "$2"
clear
;;
show)
show_applications "$2" "$3"
clear
;;
deploy)
$APP_SELECTION --import
install_applications quick_menu
clear
;;
install)
install_single_application
clear
;;
redeploy)
$APP_SELECTION --import
reinstall_applications
clear
;;
clean)
display_banner
igm_cleanup "$2" --cli
clear
;;
app|service)
$APP_SELECTION --import
$APP_SELECTION "$1"
clear
;;
setup)
display_banner
$APP_SELECTION --import
$APP_CONFIG
clear
;;
view)
display_banner
$VIEW_CONFIG
clear
;;
edit)
run_editor $ENV_FILE
clear
;;
limit)
option_8 quick_menu
clear
;;
editor)
display_banner
set_editor
clear
;;
update)
case "$2" in
--force) run_updater --force ;;
*) run_updater --cli ;;
esac
clear
;;
runtime)
runtime_menu --cli
clear
;;
ip)
. scripts/ip/ip-score.sh
clear
;;
wsl)
case "${OS_IS_WSL}:$2" in
true:mirror)
sh scripts/runtime/wsl/wsl-networking.sh "$3"
;;
true:*)
display_banner
. scripts/help/wsl-help.sh
;;
*)
echo "igm: '$1' is not a valid command. See 'igm help'."
;;
esac
;;
*)
echo "igm: '$1' is not a valid command. See 'igm help'."
;;
esac
$POST_OPS
exit 0