Skip to content

Commit b4a24a1

Browse files
Update page titles to use dynamic {{title}} variable
1 parent cf73330 commit b4a24a1

24 files changed

+357
-200
lines changed

setup.sh

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
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

77
USER_NAME=$(logname)
88
USER_HOME=/home/$USER_NAME
99

1010
# Define directories and file paths
1111
DOWNLOAD_DIR="/tmp"
1212
APP_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"
1415
GIT_INSTALL_DIR="$EXTRACT_DIR/${APP_NAME}-git"
1516
LOG_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
2122
HOST_URL="http://localhost:5050"
2223
INSTALLER_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
2627
NUM_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
3233
GITHUB_USER="codeperfectplus"
@@ -35,12 +36,12 @@ GITHUB_URL="https://github.com/$GITHUB_USER/$GITHUB_REPO"
3536
ISSUE_TRACKER_URL="$GITHUB_URL/issues"
3637

3738
# Environment variables
38-
CONDA_ENV_NAME="systemguard"
39+
CONDA_ENV_NAME="$APP_NAME_LOWER"
3940
ENV_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

4546
set -e
4647
trap '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"
128129
generate_ascii_art "Installer" "yellow"
129130
generate_ascii_art "By" "yellow"
130131
generate_ascii_art "CodePerfectPlus" "yellow"
@@ -221,7 +222,7 @@ update_env_variable() {
221222
}
222223

223224
prompt_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
455456
remove_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
461462
fetch_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
506507
setup_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
518519
install_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
598599
install_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

628629
display_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

634635
timer() {
@@ -641,7 +642,7 @@ timer() {
641642
}
642643

643644
open_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
728730
check_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

src/config.py

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,73 +5,94 @@
55

66
app = Flask(__name__)
77

8+
# Application Metadata
9+
APP_NAME = "SystemGuard"
10+
DESCRIPTION = f"{APP_NAME} is a web application that allows you to monitor your system resources."
11+
AUTHOR = "Deepak Raj"
12+
YEAR = "2024"
13+
VERSION = "1.0.4-pre-release"
14+
PROJECT_URL = f"https://github.com/codeperfectplus/{APP_NAME}"
15+
CONTACT_EMAIL = ""
16+
817
# Configure the SQLite database
9-
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///systemguard.db'
18+
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{APP_NAME.lower()}.db'
1019
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
1120
app.config['SECRET_KEY'] = 'secret'
1221

13-
# define a variable to use in the templates
22+
# Define global variables for templates
1423
app.jinja_env.globals.update(
15-
title="SystemGuard",
16-
description="SystemGuard is a web application that allows you to monitor your system resources.",
17-
author="Deepak Raj",
18-
year="2024",
19-
version="1.0.4-pre-release",
20-
project_url="https://github.com/codeperfectplus/SystemGuard",
21-
contact_email="",
24+
title=APP_NAME,
25+
description=DESCRIPTION,
26+
author=AUTHOR,
27+
year=YEAR,
28+
version=VERSION,
29+
project_url=PROJECT_URL,
30+
contact_email=CONTACT_EMAIL,
2231
)
2332

33+
def get_app_info():
34+
"""Retrieve application metadata."""
35+
return {
36+
"title": APP_NAME,
37+
"description": DESCRIPTION,
38+
"author": AUTHOR,
39+
"year": YEAR,
40+
"version": VERSION,
41+
"project_url": PROJECT_URL,
42+
"contact_email": CONTACT_EMAIL,
43+
}
44+
2445
# Initialize the database
2546
db = SQLAlchemy(app)
2647

2748
@app.cli.command("run")
2849
def server_start():
50+
"""Log server start."""
2951
logger.info("Server started")
3052

31-
# 403 forbidden
53+
# Error Handlers
3254
@app.errorhandler(403)
3355
def forbidden(e):
34-
"""
35-
This function is called when a user tries to access a resource that they are not allowed to access.
36-
"""
56+
"""Handle 403 Forbidden error."""
3757
return render_template("error/403.html"), 403
3858

39-
# not found page
4059
@app.errorhandler(404)
4160
def page_not_found(e):
61+
"""Handle 404 Not Found error."""
4262
return render_template("error/404.html"), 404
4363

44-
# 405 method not allowed
4564
@app.errorhandler(405)
4665
def method_not_allowed(e):
66+
"""Handle 405 Method Not Allowed error."""
4767
return "Method not allowed", 405
4868

49-
# internal server error 500
5069
@app.errorhandler(500)
5170
def internal_server_error(e):
71+
"""Handle 500 Internal Server Error."""
5272
return "Internal server error", 500
5373

54-
# 502
5574
@app.errorhandler(502)
5675
def bad_gateway(e):
76+
"""Handle 502 Bad Gateway error."""
5777
return "Bad gateway", 502
5878

59-
# 503
6079
@app.errorhandler(503)
6180
def service_unavailable(e):
81+
"""Handle 503 Service Unavailable error."""
6282
return "Service unavailable", 503
6383

6484
class CustomError(Exception):
85+
"""Custom exception for application-specific errors."""
6586
pass
6687

67-
68-
69-
# Purpose: Run functions before or after each request, useful for tasks like logging, performance monitoring, or pre-processing requests
88+
# Optional: Request hooks
7089
# @app.before_request
7190
# def before_request_func():
91+
# """Function to run before each request."""
7292
# logger.info("This function runs before each request.")
7393

7494
# @app.after_request
7595
# def after_request_func(response):
96+
# """Function to run after each request."""
7697
# logger.info("This function runs after each request.")
7798
# return response

src/docs/installation.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ wget https://raw.githubusercontent.com/codeperfectplus/SystemGuard/production/se
66
chmod +x setup.sh && sudo mv setup.sh /usr/local/bin/systemguard-installer
77
```
88

9+
| version | support | release |
10+
| ------- | ------ | ------ |
11+
| 1.0.4 | not released ||
12+
| 1.0.3 | yes ||
13+
| 1.0.2 | no ||
14+
| 1.0.1 | no ||
15+
| 1.0.0 | no ||
16+
917
### To install the SystemGuard app, run the following command:
1018

1119
```bash

0 commit comments

Comments
 (0)