11#! /bin/bash
22
3- # SystemGuard Installer Script
3+ # App Installer Script
44# ----------------------------
5- # This script installs, uninstalls, backs up, restores SystemGuard , and includes load testing using Locust.
5+ # This script installs, uninstalls, backs up, restores App , and includes load testing using Locust.
66
77USER_NAME=$( logname)
88USER_HOME=/home/$USER_NAME
99
1010# Define directories and file paths
1111DOWNLOAD_DIR=" /tmp"
1212APP_NAME=" SystemGuard"
13- EXTRACT_DIR=" $USER_HOME /.systemguard"
13+ APP_NAME_LOWER=$( echo " $APP_NAME " | tr ' [:upper:]' ' [:lower:]' )
14+ EXTRACT_DIR=" $USER_HOME /.$APP_NAME_LOWER "
1415GIT_INSTALL_DIR=" $EXTRACT_DIR /${APP_NAME} -git"
1516LOG_DIR=" $USER_HOME /logs"
16- LOG_FILE=" $LOG_DIR /systemguard -installer.log"
17- BACKUP_DIR=" $USER_HOME /.systemguard_backup "
18- EXECUTABLE=" /usr/local/bin/systemguard -installer"
17+ LOG_FILE=" $LOG_DIR /$APP_NAME_LOWER -installer.log"
18+ BACKUP_DIR=" $USER_HOME /.$APP_NAME_LOWER -backup "
19+ EXECUTABLE=" /usr/local/bin/$APP_NAME_LOWER -installer"
1920
2021# Application-related file paths
2122HOST_URL=" http://localhost:5050"
2223INSTALLER_SCRIPT=" setup.sh"
23- FLASK_LOG_FILE=" $LOG_DIR /systemguard_flask .log"
24+ FLASK_LOG_FILE=" $LOG_DIR /$APP_NAME_LOWER -flask .log"
2425
2526# Backup settings
2627NUM_BACKUPS=5
2728
28- # Cron job pattern for SystemGuard
29- CRON_PATTERN=" .systemguard /${APP_NAME} -.*/src/scripts/dashboard.sh"
29+ # Cron job pattern
30+ CRON_PATTERN=" .$APP_NAME_LOWER /${APP_NAME} -.*/src/scripts/dashboard.sh"
3031
3132# GitHub repository details
3233GITHUB_USER=" codeperfectplus"
@@ -35,12 +36,12 @@ GITHUB_URL="https://github.com/$GITHUB_USER/$GITHUB_REPO"
3536ISSUE_TRACKER_URL=" $GITHUB_URL /issues"
3637
3738# Environment variables
38- CONDA_ENV_NAME=" systemguard "
39+ CONDA_ENV_NAME=" $APP_NAME_LOWER "
3940ENV_FILE=" $USER_HOME /.bashrc" # Default environment file
4041
41- # SystemGuard authentication
42- SYSTEMGUARD_USER =" admin"
43- SYSTEMGUARD_PASS =" admin"
42+ # authentication
43+ ADMIN_LOGIN =" admin"
44+ ADMIN_PASSWORD =" admin"
4445
4546set -e
4647trap ' echo "An error occurred. Exiting..."; exit 1;' ERR
@@ -124,7 +125,7 @@ log() {
124125}
125126
126127# introductary message
127- generate_ascii_art " SystemGuard " " yellow"
128+ generate_ascii_art " $APP_NAME " " yellow"
128129generate_ascii_art " Installer" " yellow"
129130generate_ascii_art " By" " yellow"
130131generate_ascii_art " CodePerfectPlus" " yellow"
@@ -221,7 +222,7 @@ update_env_variable() {
221222}
222223
223224prompt_user () {
224- echo " Do you want to enable $var_name ? (true/false) This will enable automatic updates for SystemGuard ."
225+ echo " Do you want to enable $var_name ? (true/false) This will enable automatic updates for $APP_NAME ."
225226 read -p " Enter your choice (true/false): " user_choice
226227 echo " $user_choice "
227228}
@@ -284,7 +285,7 @@ add_cron_job() {
284285 # Define log directory and cron job command
285286 local log_dir=" $USER_HOME /logs"
286287 local script_path=$( find " $EXTRACT_DIR " -name dashboard.sh)
287- local cron_job=" * * * * * /bin/bash $script_path >> $log_dir /systemguard_cron .log 2>&1"
288+ local cron_job=" * * * * * /bin/bash $script_path >> $log_dir /$APP_NAME_LOWER -cron .log 2>&1"
288289
289290 # Create log directory with error handling
290291 if [ $? -ne 0 ]; then
@@ -424,7 +425,7 @@ install_executable() {
424425 CURRENT_SCRIPT=$( pwd) /$INSTALLER_SCRIPT
425426 # Verify that the script exists before attempting to copy
426427 if [ -f " $CURRENT_SCRIPT " ]; then
427- log " Installing executable to /usr/local/bin/systemguard -installer..."
428+ log " Installing executable to /usr/local/bin/$APP_NAME_LOWER -installer..."
428429 cp " $CURRENT_SCRIPT " " $EXECUTABLE "
429430 log " Executable installed successfully."
430431 else
@@ -451,13 +452,13 @@ remove_cronjob () {
451452 log " No previous cron jobs found."
452453 fi
453454}
454- # remove previous installation of cron jobs and SystemGuard
455+ # remove previous installation of cron jobs
455456remove_previous_installation () {
456457 remove_extract_dir
457458 remove_cronjob
458459}
459460
460- # Function to fetch the latest version of SystemGuard from GitHub releases
461+ # Function to fetch the latest version from GitHub releases
461462fetch_latest_version () {
462463 log " Fetching the latest version of $APP_NAME from GitHub..."
463464
@@ -502,7 +503,7 @@ download_release() {
502503 log " Download completed successfully."
503504}
504505
505- # Function to setup the cron job for SystemGuard
506+ # Function to setup the cron job
506507setup_cron_job () {
507508 log " Preparing cron job script..."
508509 add_cron_job
@@ -514,7 +515,7 @@ setup_cron_job() {
514515 fi
515516}
516517
517- # Function to install SystemGuard from Git repository
518+ # Function to install from Git repository
518519install_from_git () {
519520 log " Starting installation of $APP_NAME from Git repository..."
520521
@@ -559,7 +560,7 @@ install_from_git() {
559560 # Construct the full Git URL with branch
560561 FULL_GIT_URL=" $GITHUB_URL -b $BRANCH "
561562
562- set_auto_update " systemguard_auto_update "
563+ set_auto_update " $APP_NAME_LOWER -AUTO-UPDATE "
563564
564565 log " Cloning the $APP_NAME repository from GitHub..."
565566 create_and_own_dir " $GIT_INSTALL_DIR "
@@ -594,7 +595,7 @@ install_from_git() {
594595 log " Installation complete. $APP_NAME is ready to use."
595596}
596597
597- # install the latest version of SystemGuard from the release
598+ # install the latest version of APP from the release
598599install_from_release () {
599600 echo " Enter the version of $APP_NAME to install (e.g., v1.0.0 or 'latest' for the latest version):"
600601 read -r VERSION
@@ -604,16 +605,16 @@ install_from_release() {
604605 ZIP_URL=" $GITHUB_URL /archive/refs/tags/$VERSION .zip"
605606 log " Installing $APP_NAME version $VERSION ..."
606607
607- download_release " $ZIP_URL " " $DOWNLOAD_DIR /systemguard .zip"
608+ download_release " $ZIP_URL " " $DOWNLOAD_DIR /$APP_NAME_LOWER .zip"
608609
609610 backup_configs
610611 remove_previous_installation
611612
612613 log " Setting up installation directory..."
613614
614615 log " Extracting $APP_NAME package..."
615- unzip -q " $DOWNLOAD_DIR /systemguard .zip" -d " $EXTRACT_DIR "
616- rm " $DOWNLOAD_DIR /systemguard .zip"
616+ unzip -q " $DOWNLOAD_DIR /$APP_NAME_LOWER .zip" -d " $EXTRACT_DIR "
617+ rm " $DOWNLOAD_DIR /$APP_NAME_LOWER .zip"
617618 log " Extraction completed."
618619
619620 install_conda_env # if conda is installed then install the conda environment
@@ -627,8 +628,8 @@ install_from_release() {
627628
628629display_credentials () {
629630 log " INFO" " You can now login to the server using the following credentials:"
630- log " INFO" " Username: $SYSTEMGUARD_USERNAME "
631- log " INFO" " Password: $SYSTEMGUARD_PASSWORD "
631+ log " INFO" " Username: $ADMIN_LOGIN "
632+ log " INFO" " Password: $ADMIN_PASSWORD "
632633}
633634
634635timer () {
@@ -641,7 +642,7 @@ timer() {
641642}
642643
643644open_browser () {
644- log " If you face server server issues, run 'sudo systemguard -installer --fix' to fix the installation."
645+ log " If you face server server issues, run 'sudo $$ APP_NAME_LOWER -installer --fix' to fix the installation."
645646 log " Server may take 1-2 minutes to start. Opening the browser in 50 seconds..."
646647 # show timer for 50 seconds
647648 timer 50
@@ -667,11 +668,12 @@ install() {
667668 log " Starting installation of $APP_NAME ..."
668669 create_and_own_dir " $EXTRACT_DIR "
669670 echo " "
670- echo " Do you want to install from a Git repository or a specific release?"
671- echo " |----------------------------------------------------|"
672- echo " | 1. Git repository |"
673- echo " | 2. Release |"
674- echo " |----------------------------------------------------|"
671+ echo " Would you like to install from a Git repository or a specific release?"
672+ echo " For production use, it is recommended to install from a release."
673+ echo " |------------------------------------------------------------|"
674+ echo " | 1. Git Repository (Pre-Release Version) |"
675+ echo " | 2. Release (More Stable Version) |"
676+ echo " |------------------------------------------------------------|"
675677 echo " Enter the number of your choice:"
676678 read -r INSTALL_METHOD
677679
@@ -688,7 +690,7 @@ install() {
688690 ;;
689691 esac
690692 stop_server
691- generate_ascii_art " SystemGuard Installed" " green"
693+ generate_ascii_art " $APP_NAME Installed" " green"
692694 display_credentials
693695 open_browser
694696}
@@ -697,7 +699,7 @@ uninstall() {
697699 log " Uninstalling $APP_NAME ..."
698700 remove_previous_installation
699701 stop_server
700- generate_ascii_art " SystemGuard Uninstalled" " red"
702+ generate_ascii_art " $APP_NAME Uninstalled" " red"
701703}
702704
703705# Load test function to start Locust server
@@ -724,7 +726,7 @@ load_test() {
724726 locust -f " $LOCUST_FILE " --host=" $HOST_URL "
725727}
726728
727- # Check if SystemGuard is installed
729+ # Check if APP is installed
728730check_status () {
729731 log " Checking $APP_NAME status..."
730732
@@ -765,7 +767,7 @@ health_check() {
765767 # Check if the response code indicates success
766768 if [[ $response_code -eq 200 || $response_code -eq 302 ]]; then
767769 log " Health check successful: $HOST_URL is up and running."
768- generate_ascii_art " SystemGuard is UP" " green"
770+ generate_ascii_art " $APP_NAME is UP" " green"
769771 exit 0
770772 else
771773 (( retries++ ))
@@ -777,7 +779,7 @@ health_check() {
777779
778780 # If max retries are reached, log the failure and exit with an error
779781 log " ERROR" " Max retries reached. $HOST_URL is still not responding. Exiting with error."
780- generate_ascii_art " SystemGuard is DOWN" " red"
782+ generate_ascii_art " $APP_NAME is DOWN" " red"
781783 exit 1
782784}
783785
@@ -888,7 +890,7 @@ install_latest() {
888890 log " Fetching the server for the latest version..."
889891 # sleep 3 seconds
890892 # some kind of animation of fetching the latest code
891- echo -n " connecting to the SystemGuard server"
893+ echo -n " connecting to the $APP_NAME server"
892894 for i in {1..3}; do
893895 echo -n " ..."
894896 sleep 1
0 commit comments