Skip to content

Commit 983a504

Browse files
chore: Improve setup script and model defaults
- Update setup.sh script to include completion message and instructions for server restart - Update default value for enable_cache in ApplicationGeneralSettings model - Update default value for speedtest_cooldown in UserDashboardSettings model
1 parent dade600 commit 983a504

1 file changed

Lines changed: 108 additions & 63 deletions

File tree

setup.sh

Lines changed: 108 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -171,84 +171,129 @@ install_executable() {
171171
# Install function
172172
install() {
173173
log "Starting installation of SystemGuard..."
174-
echo "Enter the version of SystemGuard to install (e.g., v1.0.0 or 'latest' for the latest version):"
175-
read VERSION
176-
echo "Warning: This script will remove any existing installation of SystemGuard. Continue? (y/n)"
177-
read CONFIRM
174+
echo "Do you want to install from a Git repository or a specific release? (git/release):"
175+
read INSTALL_METHOD
176+
177+
if [ "$INSTALL_METHOD" == "git" ]; then
178+
log "Installing SystemGuard from Git repository..."
179+
180+
log "Removing any existing installation in the directory $EXTRACT_DIR..."
181+
if [ -d "$EXTRACT_DIR/SystemGuard-*" ]; then
182+
rm -rf "$EXTRACT_DIR/SystemGuard-*"
183+
log "Old installation removed."
184+
fi
185+
186+
log "Cloning the SystemGuard repository from GitHub..."
187+
if ! git clone https://github.com/codeperfectplus/SystemGuard.git "$EXTRACT_DIR/SystemGuard-dev"; then
188+
log "Error: Failed to clone the repository. Please check your internet connection and try again."
189+
exit 1
190+
fi
191+
log "Repository cloned successfully."
192+
193+
cd "$EXTRACT_DIR/SystemGuard-dev"
194+
log "Setting up SystemGuard from Git repository..."
195+
196+
# Install the executable
197+
install_executable
198+
log "SystemGuard installed successfully from Git!"
199+
200+
# Set up cron job if needed
201+
log "Preparing cron job script..."
202+
add_cron_job
203+
204+
if $crontab_cmd -l | grep -q "$CRON_PATTERN"; then
205+
log "Cron job added successfully."
206+
else
207+
log "Error: Failed to add the cron job."
208+
exit 1
209+
fi
178210

179-
if [ "$CONFIRM" != "y" ]; then
180-
log "Installation aborted by user."
181211
exit 0
182-
fi
212+
elif [ "$INSTALL_METHOD" == "release" ]; then
213+
echo "Enter the version of SystemGuard to install (e.g., v1.0.0 or 'latest' for the latest version):"
214+
read VERSION
215+
echo "Warning: This script will remove any existing installation of SystemGuard. Continue? (y/n)"
216+
read CONFIRM
217+
218+
if [ "$CONFIRM" != "y" ]; then
219+
log "Installation aborted by user."
220+
exit 0
221+
fi
222+
223+
# Fetch latest version if specified
224+
if [ "$VERSION" == "latest" ]; then
225+
log "Fetching the latest version of SystemGuard from GitHub..."
226+
VERSION=$(curl -s https://api.github.com/repos/codeperfectplus/SystemGuard/releases/latest | grep -Po '"tag_name": "\K.*?(?=")')
227+
if [ -z "$VERSION" ]; then
228+
log "Error: Unable to fetch the latest version. Please try again or specify a version manually."
229+
exit 1
230+
fi
231+
log "Latest version found: $VERSION"
232+
fi
183233

184-
# Fetch latest version if specified
185-
if [ "$VERSION" == "latest" ]; then
186-
log "Fetching the latest version of SystemGuard from GitHub..."
187-
VERSION=$(curl -s https://api.github.com/repos/codeperfectplus/SystemGuard/releases/latest | grep -Po '"tag_name": "\K.*?(?=")')
188-
if [ -z "$VERSION" ]; then
189-
log "Error: Unable to fetch the latest version. Please try again or specify a version manually."
234+
# Define URL after determining the version
235+
ZIP_URL="https://github.com/codeperfectplus/SystemGuard/archive/refs/tags/$VERSION.zip"
236+
log "Installing SystemGuard version $VERSION..."
237+
238+
# Download the SystemGuard zip file
239+
log "Downloading SystemGuard version $VERSION from $ZIP_URL..."
240+
if ! wget -q "$ZIP_URL" -O "$DOWNLOAD_DIR/systemguard.zip"; then
241+
log "Error: Failed to download SystemGuard version $VERSION. Please check the version number and try again."
190242
exit 1
191243
fi
192-
log "Latest version found: $VERSION"
193-
fi
244+
log "Download completed successfully."
194245

195-
# Define URL after determining the version
196-
ZIP_URL="https://github.com/codeperfectplus/SystemGuard/archive/refs/tags/$VERSION.zip"
197-
log "Installing SystemGuard version $VERSION..."
198-
199-
# Download the SystemGuard zip file
200-
log "Downloading SystemGuard version $VERSION from $ZIP_URL..."
201-
if ! wget -q "$ZIP_URL" -O "$DOWNLOAD_DIR/systemguard.zip"; then
202-
log "Error: Failed to download SystemGuard version $VERSION. Please check the version number and try again."
203-
exit 1
204-
fi
205-
log "Download completed successfully."
246+
# Backup existing configurations
247+
backup_configs
206248

207-
# Backup existing configurations
208-
backup_configs
249+
# Remove any existing installation of SystemGuard
250+
log "Removing previous installation of SystemGuard, if any..."
251+
if [ -d "$EXTRACT_DIR" ]; then
252+
rm -rf "$EXTRACT_DIR"
253+
log "Old installation removed."
254+
fi
209255

210-
# Remove any existing installation of SystemGuard
211-
log "Removing previous installation of SystemGuard, if any..."
212-
if [ -d "$EXTRACT_DIR" ]; then
213-
rm -rf "$EXTRACT_DIR"
214-
log "Old installation removed."
215-
fi
256+
# Clean up previous cron jobs related to SystemGuard
257+
log "Cleaning up previous cron jobs related to SystemGuard..."
258+
if $crontab_cmd -l | grep -q "$CRON_PATTERN"; then
259+
$crontab_cmd -l | grep -v "$CRON_PATTERN" | $crontab_cmd -
260+
log "Old cron jobs removed."
261+
else
262+
log "No previous cron jobs found."
263+
fi
216264

217-
# Clean up previous cron jobs related to SystemGuard
218-
log "Cleaning up previous cron jobs related to SystemGuard..."
219-
if $crontab_cmd -l | grep -q "$CRON_PATTERN"; then
220-
$crontab_cmd -l | grep -v "$CRON_PATTERN" | $crontab_cmd -
221-
log "Old cron jobs removed."
222-
else
223-
log "No previous cron jobs found."
224-
fi
265+
# Create the extraction directory
266+
log "Setting up installation directory..."
267+
mkdir -p $EXTRACT_DIR
268+
269+
# Extract the downloaded zip file
270+
log "Extracting SystemGuard package..."
271+
unzip -q $DOWNLOAD_DIR/systemguard.zip -d $EXTRACT_DIR
272+
rm $DOWNLOAD_DIR/systemguard.zip
273+
log "Extraction completed."
274+
log "Preparing cron job script..."
275+
add_cron_job
276+
277+
# Check if the cron job is added successfully
278+
if $crontab_cmd -l | grep -q "$CRON_PATTERN"; then
279+
log "Cron job added successfully."
280+
else
281+
log "Error: Failed to add the cron job."
282+
exit 1
283+
fi
284+
285+
# Install the executable
286+
install_executable
287+
log "SystemGuard version $VERSION installed successfully!"
288+
log "Server may take a few minutes to start, if you face any try to restart the server."
225289

226-
# Create the extraction directory
227-
log "Setting up installation directory..."
228-
mkdir -p $EXTRACT_DIR
229-
230-
# Extract the downloaded zip file
231-
log "Extracting SystemGuard package..."
232-
unzip -q $DOWNLOAD_DIR/systemguard.zip -d $EXTRACT_DIR
233-
rm $DOWNLOAD_DIR/systemguard.zip
234-
log "Extraction completed."
235-
log "Preparing cronjob script..."
236-
add_cron_job
237-
238-
# check if the cron job is added successfully
239-
if $crontab_cmd -l | grep -q "$CRON_PATTERN"; then
240-
log "Cron job added successfully."
241290
else
242-
log "Error: Failed to add the cron job."
291+
log "Invalid installation method. Please choose 'git' or 'release'."
243292
exit 1
244293
fi
245-
246-
# Install the executable
247-
install_executable
248-
log "SystemGuard version $VERSION installed successfully!"
249-
log "Server may take a few minutes to start, if you face any try to restart the server."
250294
}
251295

296+
252297
# Uninstall function
253298
uninstall() {
254299
log "Uninstalling SystemGuard..."

0 commit comments

Comments
 (0)