From ea0d8c772d48a437604f01c268ddef90e88fd72d Mon Sep 17 00:00:00 2001 From: garethgeorge Date: Sun, 7 Apr 2024 03:06:36 -0700 Subject: [PATCH] chore: update install / download scripts --- scripts/get.sh | 87 ++++++++++++++++++++++---------------------------- uninstall.sh | 4 +-- 2 files changed, 40 insertions(+), 51 deletions(-) mode change 100644 => 100755 scripts/get.sh diff --git a/scripts/get.sh b/scripts/get.sh old mode 100644 new mode 100755 index 4b65cefd..9eecaab2 --- a/scripts/get.sh +++ b/scripts/get.sh @@ -3,77 +3,77 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH #================================================= -# System Required: Linux # Description: Backrest Helper -# Author: Nebulosa Cat -# WebSite: https://nebulosa-cat.moe +# Contributed-By: https://github.com/Nebulosa-Cat #================================================= -userHomeDir=$( getent passwd "$USER" | cut -d: -f6 ) +OS=$(uname -s) +if [[ "${OS}" != "Linux" ]]; then + echo -e "This script is only for Linux" + exit 1 +fi -#Coler the Bash output -Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m" && Yellow_font_prefix="\033[0;33m" +# Formatting Variables +Green_font_prefix="\033[32m" +Red_font_prefix="\033[31m" +Green_background_prefix="\033[42;37m" +Red_background_prefix="\033[41;37m" +Font_color_suffix="\033[0m" +Yellow_font_prefix="\033[0;33m" Info="${Green_font_prefix}[Info]${Font_color_suffix}" Error="${Red_font_prefix}[Error]${Font_color_suffix}" -Warring="${Yellow_font_prefix}[Warring]${Font_color_suffix}" +Warning="${Yellow_font_prefix}[Warning]${Font_color_suffix}" # Check Kernal Type sysArch() { + echo -e "${Info} Checking OS info..." uname=$(uname -m) + if [[ "$uname" == "x86_64" ]]; then arch="x86_64" - elif [[ "$uname" == *"armv7"* ]] || [[ "$uname" == "armv6l" ]]; then + elif [[ "$uname" == "armv7" ]] || [[ "$uname" == "armv6l" ]]; then arch="armv6" - elif [[ "$uname" == *"armv8"* ]] || [[ "$uname" == "aarch64" ]]; then + elif [[ "$uname" == "armv8" ]] || [[ "$uname" == "aarch64" ]]; then arch="arm64" else - echo "${Error} Not Support Kernal" && exit 1 + echo -e "${Error} Unsupported Architecture ${arch}" && exit 1 fi + + echo -e "${Info} You are running ${arch}." } + Install() { - clear - echo -e "${Info} Checking Kernal Type..." sysArch - echo -e "${Info} Your Kernel Type is ${arch}." - cd "${userHomeDir}" - echo -e "${Info} Downloading Target Version..." - clear + tempdir=$(mktemp -d) + cd "${tempdir}" + echo -e "${Info} Downloading Latest Version..." wget https://github.com/garethgeorge/backrest/releases/latest/download/backrest_Linux_${arch}.tar.gz rm -r ./backrest mkdir ./backrest tar -xzvf backrest_Linux_${arch}.tar.gz -C ./backrest cd backrest - clear echo -e "${Info} Starting Install Script..." ./install.sh - echo -e "${Info} Clear Install file..." - cd "${userHomeDir}" - rm -r ./backrest - rm backrest_Linux_${arch}.tar.gz + echo -e "${Info} Clearing temporary directory for install..." + rm -rf ${tempdir} echo -e "${Info} Install Completed!" } Uninstall(){ - clear - echo -e "${Info} Checking Kernal Type..." sysArch - echo -e "${Info} Your Kernel Type is ${arch}." - cd "${userHomeDir}" - echo -e "${Info} Downloading Target Version..." - clear + tempdir=$(mktemp -d) + cd "${tempdir}" + echo -e "${Info} Downloading Latest Version of uninstaller..." wget https://github.com/garethgeorge/backrest/releases/latest/download/backrest_Linux_${arch}.tar.gz rm -r ./backrest mkdir ./backrest tar -xzvf backrest_Linux_${arch}.tar.gz -C ./backrest cd backrest - clear echo -e "${Info} Starting Uninstall Script..." ./uninstall.sh - echo -e "${Info} Clear Install file..." - cd "${userHomeDir}" - rm -r ./backrest - rm backrest_Linux_${arch}.tar.gz + echo -e "${Info} Clear temporary directory for uninstall script..." + rm -rf ${tempdir} echo -e "${Info} Uninstall Completed!" } @@ -81,7 +81,7 @@ Start(){ sudo systemctl start backrest } -Stoper(){ +Stop(){ sudo systemctl stop backrest } @@ -95,7 +95,7 @@ Start_Menu(){ ============================================= Backrest Install Helper ============================================= - ${Red_font_prefix} Warring: This Script Only Work On Linux !${Font_color_suffix} + ${Red_font_prefix} Warning: This Script Only Work On Linux !${Font_color_suffix} ————————————————————————————————------------- ${Green_font_prefix} 0.${Font_color_suffix} Install / Update Backrest ${Green_font_prefix} 1.${Font_color_suffix} Uninstall Backrest @@ -108,7 +108,7 @@ Start_Menu(){ ${Green_font_prefix} 9.${Font_color_suffix} Exit Script ============================================= " - read -e -p " Please Input [0-9]:" num + read -p " Please Input [0-9]:" num case "$num" in 0) Install @@ -120,28 +120,17 @@ Start_Menu(){ Start ;; 3) - Stoper + Stop ;; 4) Status ;; - 5) - exit 1 - ;; - 6) - exit 1 - ;; - 7) - exit 1 - ;; - 8) - exit 1 - ;; 9) exit 1 ;; *) - echo "Please input correct number ${Yellow_font_prefix}[0-9]${Font_color_suffix}" + echo -e "${Error} Please enter a correct number [0-9]" + exit 1 ;; esac } diff --git a/uninstall.sh b/uninstall.sh index 5a4df4f5..f28452f3 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -35,13 +35,13 @@ if [ "$OS" = "Darwin" ]; then uninstall_unix remove_launchd_plist - echo "Done -- run `launchctl list | grep backrest` to check the service installation." + echo "Done -- run 'launchctl list | grep backrest' to check the service installation." elif [ "$OS" = "Linux" ]; then echo "Unnstalling on Linux" uninstall_unix remove_systemd_service - echo "Done -- run `systemctl status backrest` to check the status of the service." + echo "Done -- run 'systemctl status backrest' to check the status of the service." else echo "Unknown OS: $OS. This script only supports Darwin and Linux." exit 1