@@ -45,6 +45,7 @@ USER_HOME=/home/$USER_NAME
4545# Define directories and file paths
4646DOWNLOAD_DIR=" /tmp"
4747APP_NAME=" SystemGuard"
48+ INSATLLER_VERSION=" v1.0.0"
4849APP_NAME_LOWER=$( echo " $APP_NAME " | tr ' [:upper:]' ' [:lower:]' )
4950EXTRACT_DIR=" $USER_HOME /.$APP_NAME_LOWER "
5051GIT_INSTALL_DIR=" $EXTRACT_DIR /${APP_NAME} -git"
@@ -67,11 +68,11 @@ GITHUB_USER="codeperfectplus"
6768GITHUB_REPO=" $APP_NAME "
6869GITHUB_URL=" https://github.com/$GITHUB_USER /$GITHUB_REPO "
6970ISSUE_TRACKER_URL=" $GITHUB_URL /issues"
70- NUM_OF_RELEASES=5
71- NUM_OF_RETRIES=5
7271
7372# Backup settings
74- NUM_BACKUPS=5
73+ NUM_OF_BACKUP=5
74+ NUM_OF_RELEASES=5
75+ NUM_OF_RETRIES=5
7576
7677# Environment variables
7778ENV_FILE=" $USER_HOME /.bashrc" # Default environment file
@@ -149,16 +150,16 @@ message_box() {
149150 total_length=$(( message_length + 2 * padding))
150151
151152 # Print the top border of the message box
152- echo -e " ${color_border} ┌$( printf ' ─%.0s' $( seq 1 $total_length ) ) ┐${color_reset} "
153+ echo -e " ${color_border} ┌$( printf ' ─%.0s' $( seq 1 $total_length ) ) ┐${color_reset} " | tee -a " $LOG_FILE "
153154
154155 # Read the message line by line and print with padding and side borders
155156 while IFS= read -r line; do
156157 printf " %b│%b%*s%b%s%b%*s%b│%b\n" \
157- " $color_border " " $color_reset " $padding " " " $color_message " " $line " " $color_reset " $(( total_length - padding - ${# line} )) " " " $color_border " " $color_reset "
158+ " $color_border " " $color_reset " $padding " " " $color_message " " $line " " $color_reset " $(( total_length - padding - ${# line} )) " " " $color_border " " $color_reset " | tee -a " $LOG_FILE "
158159 done <<< " $(echo -e " $message " )"
159160
160161 # Print the bottom border of the message box
161- echo -e " ${color_border} └$( printf ' ─%.0s' $( seq 1 $total_length ) ) ┘${color_reset} "
162+ echo -e " ${color_border} └$( printf ' ─%.0s' $( seq 1 $total_length ) ) ┘${color_reset} " | tee -a " $LOG_FILE "
162163
163164 # Pause for the specified sleep time if provided
164165 if [ -n " $sleeptime " ]; then
@@ -170,7 +171,7 @@ message_box() {
170171display_credentials () {
171172 local username=" Username: ${ADMIN_LOGIN} "
172173 local password=" Password: ${ADMIN_PASSWORD} "
173- local message=" Here are your login credentials. It will be used to login to the dashboard."
174+ local message=" Here are your login credentials. \nIt will be use to login to the dashboard."
174175
175176 local max_length=$(( ${# username} > ${# password} ? ${# username} : ${# password} ))
176177 local max_length_message=$(( ${# message} > max_length ? ${# message} : max_length))
@@ -242,7 +243,6 @@ check_dependencies() {
242243 # Detect the package manager
243244 local manager
244245 manager=$( detect_package_manager)
245- echo " Package manager found: $manager "
246246
247247 # Array to keep track of missing dependencies
248248 local missing_dependencies=()
@@ -469,6 +469,7 @@ rotate_backups() {
469469 done
470470 fi
471471}
472+
472473# Backup function for existing configurations
473474backup_configs () {
474475 rotate_backups $NUM_OF_BACKUP
@@ -630,7 +631,6 @@ setup_cron_job() {
630631
631632# Function to install from Git repository
632633install_from_git () {
633- log " Starting installation of $APP_NAME from Git repository..."
634634 set_variable " sg_installation_method" " git"
635635 # Backup existing configurations
636636 backup_configs
@@ -824,18 +824,38 @@ open_browser() {
824824}
825825
826826start_server () {
827- log " Starting $APP_NAME server..."
827+ log " Starting ${ APP_NAME} server..."
828828 display_credentials
829- cd $EXTRACT_DIR /$APP_NAME -* /
830- dashboard_script_path=$( find . -name dashboard.sh | head -n 1)
831- sudo -u " $USER_NAME " bash " $dashboard_script_path " & > /dev/null
829+
830+ # Change to the correct directory
831+ if cd ${EXTRACT_DIR} /${APP_NAME} -* /; then
832+ # Find the dashboard script
833+ dashboard_script_path=$( find . -name " dashboard.sh" | head -n 1)
834+
835+ # Check if the script was found
836+ if [[ -n " $dashboard_script_path " ]]; then
837+ # Run the script with the specified user
838+ if sudo -u " ${USER_NAME} " bash " ${dashboard_script_path} " ; then
839+ log " Server started successfully."
840+ else
841+ log " Failed to start the server."
842+ return 1
843+ fi
844+ else
845+ log " dashboard.sh not found."
846+ return 1
847+ fi
848+ else
849+ log " Failed to change directory to ${EXTRACT_DIR} /${APP_NAME} -*/"
850+ return 1
851+ fi
832852}
833853
834854# Install function
835855install () {
836- message_box " Welcome on board: $( echo " $USER_NAME " | sed ' s/.*/\u&/' ) " 0
856+ message_box " $APP_NAME Installer $INSATLLER_VERSION " 0
857+ message_box " Welcome on board: $( echo " $USER_NAME " | sed ' s/.*/\u&/' ) " 3
837858 check_dependencies
838- log " Starting installation of $APP_NAME ..."
839859 create_dir " $EXTRACT_DIR "
840860 message_box " Choose the installation method\nNote: Release is recommended for production use." 0
841861 message_box " 1. Release (More Stable Version)\n2. Git Repository (Pre-Release Version)\n3. Source Code (Current Directory)" 0
@@ -981,20 +1001,27 @@ show_installer_logs() {
9811001}
9821002
9831003# stop flask server
984- stop_server_helper () {
985- if lsof -Pi :5050 -sTCP:LISTEN -t > /dev/null; then
986- kill -9 $( lsof -t -i:5050)
987- log " Server stopped successfully."
1004+ stop_server () {
1005+ local port=5050
1006+ local pid
1007+
1008+ # Check if the server is listening on the specified port
1009+ if pid=$( lsof -ti :" $port " 2> /dev/null) ; then
1010+ if [ -n " $pid " ]; then
1011+ # Terminate the process
1012+ if kill -9 " $pid " > /dev/null 2>&1 ; then
1013+ log " Server on port $port stopped successfully."
1014+ else
1015+ log " Error: Failed to stop the server on port $port ."
1016+ fi
1017+ else
1018+ log " No process found listening on port $port ."
1019+ fi
9881020 else
989- log " Server is not running ."
1021+ log " No process found listening on port $port ."
9901022 fi
9911023}
9921024
993- stop_server () {
994- log " Stopping $APP_NAME server..."
995- stop_server_helper
996- }
997-
9981025# fix the server
9991026fix () {
10001027 log " Fixing $APP_NAME server..."
0 commit comments