Skip to content

Commit c04a936

Browse files
installation fixed, cpu frequency card fixed, cpu core card imporve
1 parent 8a65c55 commit c04a936

5 files changed

Lines changed: 90 additions & 51 deletions

File tree

setup.sh

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ USER_HOME=/home/$USER_NAME
4545
# Define directories and file paths
4646
DOWNLOAD_DIR="/tmp"
4747
APP_NAME="SystemGuard"
48+
INSATLLER_VERSION="v1.0.0"
4849
APP_NAME_LOWER=$(echo "$APP_NAME" | tr '[:upper:]' '[:lower:]')
4950
EXTRACT_DIR="$USER_HOME/.$APP_NAME_LOWER"
5051
GIT_INSTALL_DIR="$EXTRACT_DIR/${APP_NAME}-git"
@@ -67,11 +68,11 @@ GITHUB_USER="codeperfectplus"
6768
GITHUB_REPO="$APP_NAME"
6869
GITHUB_URL="https://github.com/$GITHUB_USER/$GITHUB_REPO"
6970
ISSUE_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
7778
ENV_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() {
170171
display_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
473474
backup_configs() {
474475
rotate_backups $NUM_OF_BACKUP
@@ -630,7 +631,6 @@ setup_cron_job() {
630631

631632
# Function to install from Git repository
632633
install_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

826826
start_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
835855
install() {
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
9991026
fix() {
10001027
log "Fixing $APP_NAME server..."

src/scripts/dashboard.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fetch_env_variable() {
101101

102102
auto_update=$(fetch_env_variable "sg_auto_update")
103103
# Fetch from bashrc for auto-update
104-
echo "Auto update for $APP_NAME is set to $auto_update"
104+
log_message "Auto update for $APP_NAME is set to $auto_update"
105105

106106
# Ensure log directory exists
107107
LOG_DIR="$(dirname "$LOG_FILE")"

src/static/css/style.css

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -209,32 +209,41 @@ body {
209209
transition: width 0.3s ease;
210210
}
211211

212-
.cpu-core-visualization {
213-
display: flex;
214-
justify-content: center;
215-
align-items: center;
216-
gap: 10px;
217-
margin-top: 10px;
212+
213+
.cpu-core-card {
214+
height: 190px;
215+
border: 1px solid #e0e0e0;
216+
border-radius: 10px;
217+
background-color: #f8f9fa;
218+
padding: 20px;
219+
color: #333;
218220
}
219221

220222
.cpu-core-bar {
221-
width: 15px;
222-
height: 55px;
223+
width: 20px; /* Increased width for better visibility */
224+
height: 40px; /* Increased height for better visibility */
223225
background-color: var(--color-primary);
224-
border-radius: 5px;
225-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
226-
transition: background-color 0.3s ease;
226+
border-radius: 10px;
227+
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
228+
transition: background-color 0.3s ease, transform 0.3s ease;
229+
}
230+
231+
.cpu-core-bar:hover {
232+
background-color: var(--color-primary-dark);
233+
transform: translateY(-5px);
234+
}
235+
236+
.cpu-core-visualization {
237+
display: flex;
238+
justify-content: center;
239+
flex-wrap: wrap;
240+
gap: 8px; /* Spacing between bars */
227241
}
228242

229243
.cpu-core-bar:nth-child(even) {
230244
background-color: #d7b25c;
231245
}
232246

233-
.cpu-core-bar:hover {
234-
background-color: var(--color-light);
235-
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
236-
filter: brightness(1.2);
237-
}
238247

239248
/* Card Content Alignment */
240249
.site-home {

src/static/js/refreshCardData.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,13 @@ function updateCard(cardSelector, dataKey, data, unit = '', barSelector = null,
123123

124124
let percentage = parseFloat(dataValue);
125125

126-
127-
// Ensure the percentage doesn't exceed 100%
128-
percentage = Math.min(percentage, 100);
126+
// check if maxDataKey is provided
127+
if (maxDataKey) {
128+
let maxDataValue = data?.[maxDataKey];
129+
percentage = dataValue / maxDataValue * 100;
130+
} else {
131+
percentage = Math.min(percentage, 100);
132+
}
129133

130134
// Set the bar width based on the percentage
131135
barElement.style.width = `${percentage}%`;
@@ -156,7 +160,7 @@ async function refreshData() {
156160
updateCard('.bg-disk', 'disk_percent', data, '%', '.disk-bar');
157161
updateCard('.cpu-temp-card', 'current_temp', data, ' °C', '.temp-bar');
158162
updateCard('.bg-memory', 'memory_percent', data, '%', '.memory-usage-bar');
159-
updateCard('.cpu-frequency-card', 'cpu_frequency', data, ' MHz', '.frequency-bar');
163+
updateCard('.cpu-frequency-card', 'cpu_frequency', data, ' MHz', '.frequency-bar', 'cpu_max_frequency');
160164
updateCard('.cpu-usage-card', 'cpu_percent', data, '%', '.cpu-usage-bar');
161165
updateCard('.network-received', 'network_received', data, 'MB');
162166
updateCard('.network-sent', 'network_sent', data, 'MB');
@@ -186,7 +190,6 @@ function updateColorBars() {
186190
if (isNaN(card_value)) return;
187191

188192
bar.classList.remove('low', 'medium', 'high');
189-
console.log("dataAttr", dataAttr, card_value, limits)
190193
// Apply the appropriate class based on the limits
191194
if (card_value <= limits[0]) {
192195
bar.classList.add('low');

src/templates/card_comp/cpu/core.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{% if card_settings.is_cpu_core_card_enabled %}
22
<div class="col-md-6 col-lg-4 mb-4">
33
<div class="card cpu-core-card bg-cpu shadow-sm">
4-
<div class="card-body d-flex flex-column align-items-center">
4+
<div class="card-body d-flex flex-column align-items-center text-center">
55
<h5 class="card-title mb-3">CPU Cores <i class="fas fa-microchip"></i></h5>
6-
<!-- <p class="card-text fs-4 mb-3">{{ system_info['cpu_core'] }} Cores</p> -->
7-
<div class="cpu-core-visualization">
6+
<p class="card-text fs-4 mb-3">{{ system_info['cpu_core'] }} Cores</p>
7+
<div class="cpu-core-visualization d-flex justify-content-center flex-wrap">
88
{% for i in range(system_info['cpu_core']) %}
9-
<div class="cpu-core-bar"></div>
9+
<div class="cpu-core-bar mx-1"></div>
1010
{% endfor %}
1111
</div>
1212
</div>

0 commit comments

Comments
 (0)