|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# SystemGuard Installer Script |
| 4 | +# ---------------------------- |
| 5 | +# This script installs SystemGuard by downloading the specified version from GitHub, |
| 6 | +# cleaning up any previous installations, and setting up the new version. |
| 7 | + |
| 8 | +# Variables |
| 9 | +DOWNLOAD_DIR="/tmp" |
| 10 | +EXTRACT_DIR="/home/$USER/.systemguard" |
| 11 | + |
| 12 | +# Prompt the user to enter the version of SystemGuard to install |
| 13 | +echo "Enter the version of SystemGuard to install (e.g., v1.0.0 or 'latest' for the latest version):" |
| 14 | +read VERSION |
| 15 | + |
| 16 | +# If the user enters "latest", fetch the latest version number from GitHub |
| 17 | +if [ "$VERSION" == "latest" ]; then |
| 18 | + echo "Fetching the latest version of SystemGuard from GitHub..." |
| 19 | + VERSION=$(curl -s https://api.github.com/repos/codeperfectplus/SystemGuard/releases/latest | grep -Po '"tag_name": "\K.*?(?=")') |
| 20 | + |
| 21 | + # Check if fetching the latest version was successful |
| 22 | + if [ -z "$VERSION" ]; then |
| 23 | + echo "Error: Unable to fetch the latest version. Please try again or specify a version manually." |
| 24 | + exit 1 |
| 25 | + fi |
| 26 | + echo "Latest version found: $VERSION" |
| 27 | +fi |
| 28 | + |
| 29 | +# Define URL after determining the version |
| 30 | +ZIP_URL="https://github.com/codeperfectplus/SystemGuard/archive/refs/tags/$VERSION.zip" |
| 31 | + |
| 32 | +# Inform the user about the installation process |
| 33 | +echo "Installing SystemGuard version $VERSION..." |
| 34 | +echo "Downloading SystemGuard package from GitHub..." |
| 35 | + |
| 36 | +# Download the SystemGuard zip file to the /tmp directory |
| 37 | +wget -q $ZIP_URL -O $DOWNLOAD_DIR/systemguard.zip |
| 38 | + |
| 39 | +# Check if the download was successful |
| 40 | +if [ $? -ne 0 ]; then |
| 41 | + echo "Error: Failed to download SystemGuard version $VERSION. Please check the version number and try again." |
| 42 | + exit 1 |
| 43 | +fi |
| 44 | +echo "Download completed." |
| 45 | + |
| 46 | +# Remove any existing installation of SystemGuard |
| 47 | +echo "Removing previous installation of SystemGuard, if any..." |
| 48 | +if [ -d "$EXTRACT_DIR" ]; then |
| 49 | + rm -rf "$EXTRACT_DIR" |
| 50 | + echo "Old installation removed." |
| 51 | +fi |
| 52 | + |
| 53 | +# Remove specific cron jobs related to previous SystemGuard installations |
| 54 | +echo "Cleaning up previous cron jobs related to SystemGuard..." |
| 55 | +CRON_PATTERN=".systemguard/SystemGuard-.*/dashboard.sh" |
| 56 | +if crontab -l | grep -q "$CRON_PATTERN"; then |
| 57 | + # Remove only the lines that match the specific pattern |
| 58 | + crontab -l | grep -v "$CRON_PATTERN" | crontab - |
| 59 | + echo "Old cron jobs removed." |
| 60 | +else |
| 61 | + echo "No previous cron jobs found." |
| 62 | +fi |
| 63 | + |
| 64 | +# Create the extraction directory |
| 65 | +echo "Setting up installation directory..." |
| 66 | +mkdir -p $EXTRACT_DIR |
| 67 | + |
| 68 | +# Extract the downloaded zip file to the target directory |
| 69 | +echo "Extracting SystemGuard package..." |
| 70 | +unzip -q $DOWNLOAD_DIR/systemguard.zip -d $EXTRACT_DIR |
| 71 | + |
| 72 | +# Remove the downloaded zip file to clean up |
| 73 | +rm $DOWNLOAD_DIR/systemguard.zip |
| 74 | +echo "Extraction completed." |
| 75 | + |
| 76 | +# Navigate to the extracted SystemGuard directory |
| 77 | +echo "Navigating to the SystemGuard setup directory..." |
| 78 | +cd $EXTRACT_DIR/SystemGuard-*/ |
| 79 | + |
| 80 | +# Check if the cronjob.sh script exists in the extracted content |
| 81 | +if [ ! -f "cronjob.sh" ]; then |
| 82 | + echo "Error: cronjob.sh not found in the extracted directory. Please verify the contents." |
| 83 | + exit 1 |
| 84 | +fi |
| 85 | + |
| 86 | +# Make the cronjob.sh script executable |
| 87 | +echo "Preparing cronjob script..." |
| 88 | +chmod +x cronjob.sh |
| 89 | + |
| 90 | +# Execute the cronjob.sh script to set up cron jobs and complete installation |
| 91 | +echo "Executing the cronjob setup..." |
| 92 | +./cronjob.sh |
| 93 | + |
| 94 | +echo "SystemGuard version $VERSION installed successfully!" |
0 commit comments