@@ -111,7 +111,7 @@ set_auto_update() {
111111 # Prompt user for input
112112 echo " Do you want to enable systemguard_auto_update? (true/false)"
113113 echo " This will enable automatic updates for SystemGuard."
114- read -p " Enter your choice: " auto_update
114+ read -p " Enter your choice: true/false: " auto_update
115115
116116 # Validate input
117117 if [[ " $auto_update " != " true" && " $auto_update " != " false" ]]; then
@@ -187,18 +187,17 @@ SYSTEMGUARD_USERNAME="admin"
187187SYSTEMGUARD_PASSWORD=" admin"
188188
189189# Function to create a directory if it does not exist
190- create_dir_if_not_exists () {
190+ create_and_own_dir () {
191191 local dir=" $1 "
192192 if [ ! -d " $dir " ]; then
193193 mkdir -p " $dir " || { log " ERROR" " Failed to create directory: $dir " ; exit 1; }
194194 chown " $USER_NAME :$USER_NAME " " $dir " || { log " ERROR" " Failed to change ownership of directory: $dir " ; exit 1; }
195195 fi
196196}
197197
198- create_dir_if_not_exists " $LOG_DIR "
199- create_dir_if_not_exists " $BACKUP_DIR "
200-
201-
198+ create_and_own_dir " $LOG_DIR "
199+ create_and_own_dir " $BACKUP_DIR "
200+ create_and_own_dir " $EXTRACT_DIR "
202201
203202# Check if running with sudo
204203if [ " $EUID " -eq 0 ]; then
@@ -231,8 +230,6 @@ add_cron_job() {
231230 local script_path=$( find " $EXTRACT_DIR " -name dashboard.sh)
232231 local cron_job=" * * * * * /bin/bash $script_path >> $log_dir /systemguard_cron.log 2>&1"
233232
234- # Create log directory with error handling
235- mkdir -p " $log_dir "
236233 if [ $? -ne 0 ]; then
237234 log " CRITICAL" " Failed to create log directory: $log_dir "
238235 exit 1
@@ -317,7 +314,6 @@ backup_configs() {
317314 rotate_backups $NUM_OF_BACKUP
318315 log " Backing up existing configurations..."
319316 if [ -d " $EXTRACT_DIR " ]; then
320- mkdir -p " $BACKUP_DIR "
321317 cp -r " $EXTRACT_DIR " " $BACKUP_DIR /$( date ' +%Y%m%d_%H%M%S' ) "
322318 log " Backup completed: $BACKUP_DIR "
323319 else
@@ -445,11 +441,12 @@ install_from_git() {
445441
446442 echo " "
447443 echo " Select the version of $APP_NAME to install:"
448- echo " |---------------------------------------------------------------------------|"
449- echo " |1. Production (stable) - Recommended for most users |"
450- echo " |2. Development (dev) - Latest features, may be unstable |"
451- echo " |3. Specify a branch or tag name - Enter the branch/tag name when prompted |"
452- echo " |---------------------------------------------------------------------------|"
444+ echo " |-----------------------------------------------------------------------------|"
445+ echo " | 1. Production (stable) - Recommended for most users |"
446+ echo " | 2. Development (dev) - Latest features, may be unstable |"
447+ echo " | 3. Specify a branch - Enter the branch/tag name when prompted |"
448+ echo " |-----------------------------------------------------------------------------|"
449+ echo " Enter the number of your choice:"
453450 read -r VERSION
454451
455452 # Set Git URL based on user choice
@@ -524,7 +521,6 @@ install_from_release() {
524521 remove_previous_installation
525522
526523 log " Setting up installation directory..."
527- mkdir -p " $EXTRACT_DIR "
528524
529525 log " Extracting $APP_NAME package..."
530526 unzip -q " $DOWNLOAD_DIR /systemguard.zip" -d " $EXTRACT_DIR "
@@ -539,17 +535,32 @@ install_from_release() {
539535 log " Server may take a few minutes to start. If you face any issues, try restarting the server."
540536}
541537
542- # Install function
543- install () {
544- log " Starting installation of $APP_NAME ..."
545- echo " "
538+ # Function to select the installation method
539+ select_install_method () {
546540 echo " Do you want to install from a Git repository or a specific release?"
547541 echo " |----------------------------------------------------|"
548542 echo " | 1. Git repository |"
549543 echo " | 2. Release |"
550544 echo " |----------------------------------------------------|"
545+ echo " Enter the number of your choice:"
551546 read -r INSTALL_METHOD
552547
548+ case $INSTALL_METHOD in
549+ 1) install_from_git ;;
550+ 2) install_from_release ;;
551+ * ) log " Invalid installation method. Please choose '1' for Git repository or '2' for Release." ; exit 1 ;;
552+ esac
553+ }
554+
555+ display_credentials () {
556+ log " INFO" " You can now login to the server using the following credentials:"
557+ log " INFO" " Username: $SYSTEMGUARD_USERNAME "
558+ log " INFO" " Password: $SYSTEMGUARD_PASSWORD "
559+ }
560+
561+ # Install function
562+ install () {
563+ select_install_method
553564 case $INSTALL_METHOD in
554565 1)
555566 install_from_git
@@ -564,10 +575,7 @@ install() {
564575 esac
565576 stop_server
566577 generate_ascii_art " SystemGuard Installed" " green"
567-
568- log " INFO" " You can now login to the server using the following credentials:"
569- log " INFO" " Username: $SYSTEMGUARD_USERNAME "
570- log " INFO" " Password: $SYSTEMGUARD_PASSWORD "
578+ display_credentials
571579
572580}
573581# Uninstall function
@@ -669,6 +677,7 @@ show_server_logs() {
669677 echo " "
670678
671679 cd $EXTRACT_DIR /$APP_NAME -* /
680+ echo $EXTRACT_DIR /$APP_NAME -* /
672681 log_file=$( find . -name " app_debug.log" | head -n 1)
673682 echo " log file: $log_file "
674683 if [ -f " $log_file " ]; then
0 commit comments