From d6fe7227f6e06f22ab627c7613254233b647efac Mon Sep 17 00:00:00 2001 From: "Roza." <71328419+shinyPy@users.noreply.github.com> Date: Tue, 20 Aug 2024 08:26:20 +0800 Subject: [PATCH 1/3] install.sh : Add an option to create a backup --- scriptdata/environment-variables | 1 + scriptdata/functions | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/scriptdata/environment-variables b/scriptdata/environment-variables index b2e752c62..96f37bffd 100644 --- a/scriptdata/environment-variables +++ b/scriptdata/environment-variables @@ -4,4 +4,5 @@ XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache} XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config} XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share} XDG_STATE_HOME=${XDG_STATE_HOME:-$HOME/.local/state} +BACKUP_DIR=${BACKUP_DIR:-$HOME/backup} diff --git a/scriptdata/functions b/scriptdata/functions index 37f17acd2..98e18c977 100644 --- a/scriptdata/functions +++ b/scriptdata/functions @@ -72,3 +72,14 @@ function prevent_sudo_or_root(){ root)echo -e "\e[31m[$0]: This script is NOT to be executed with sudo or as root. Aborting...\e[0m";exit 1;; esac } + + +function backup_configs() { + local backup_dir="$BACKUP_DIR" + mkdir -p "$backup_dir" + echo "Backing up $XDG_CONFIG_HOME to $backup_dir/config_backup" + rsync -av --progress "$XDG_CONFIG_HOME/" "$backup_dir/config_backup/" + + echo "Backing up $HOME/.local to $backup_dir/local_backup" + rsync -av --progress "$HOME/.local/" "$backup_dir/local_backup/" +} \ No newline at end of file From a55aefbe50bb95cd0b7fb1037884902708acfda0 Mon Sep 17 00:00:00 2001 From: "Roza." <71328419+shinyPy@users.noreply.github.com> Date: Tue, 20 Aug 2024 08:26:32 +0800 Subject: [PATCH 2/3] print option --- install.sh | 60 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/install.sh b/install.sh index af0c929d3..b4d5a9d48 100755 --- a/install.sh +++ b/install.sh @@ -7,34 +7,46 @@ source ./scriptdata/installers source ./scriptdata/options ##################################################################################### -if ! command -v pacman >/dev/null 2>&1;then printf "\e[31m[$0]: pacman not found, it seems that the system is not ArchLinux or Arch-based distros. Aborting...\e[0m\n";exit 1;fi +if ! command -v pacman >/dev/null 2>&1; then + printf "\e[31m[$0]: pacman not found, it seems that the system is not ArchLinux or Arch-based distros. Aborting...\e[0m\n" + exit 1 +fi prevent_sudo_or_root -startask (){ -printf "\e[34m[$0]: Hi there! Before we start:\n" -printf 'This script 1. only works for ArchLinux and Arch-based distros.\n' -printf ' 2. does not handle system-level/hardware stuff like Nvidia drivers\n' -printf "\e[31m" -printf "Please CONFIRM that you HAVE ALREADY BACKED UP \"$XDG_CONFIG_HOME\" and \"$HOME/.local/\" folders!\n" -printf "\e[0m" -printf "Enter capital \"YES\" (without quotes) to continue:" -read -p " " p -case $p in "YES")sleep 0;; *)echo "Received \"$p\", aborting...";exit 1;;esac -printf '\n' -printf 'Do you want to confirm every time before a command executes?\n' -printf ' y = Yes, ask me before executing each of them. (DEFAULT)\n' -printf ' n = No, just execute them automatically.\n' -printf ' a = Abort.\n' -read -p "====> " p -case $p in - n)ask=false;; - a)exit 1;; - *)ask=true;; -esac + +startask () { + printf "\e[34m[$0]: Hi there! Before we start:\n" + printf 'This script 1. only works for ArchLinux and Arch-based distros.\n' + printf ' 2. does not handle system-level/hardware stuff like Nvidia drivers\n' + printf "\e[31m" + + printf "Would you like to create a backup now? [y/N]: " + read -p " " backup_confirm + case $backup_confirm in + [yY][eE][sS]|[yY]) + backup_configs + ;; + *) + echo "Skipping backup..." + ;; + esac + + + printf '\n' + printf 'Do you want to confirm every time before a command executes?\n' + printf ' y = Yes, ask me before executing each of them. (DEFAULT)\n' + printf ' n = No, just execute them automatically.\n' + printf ' a = Abort.\n' + read -p "====> " p + case $p in + n) ask=false ;; + a) exit 1 ;; + *) ask=true ;; + esac } case $ask in - false)sleep 0;; - *)startask ;; + false) sleep 0 ;; + *) startask ;; esac set -e From d02633aa34fe664dd886c6a32e4a741ff937efd3 Mon Sep 17 00:00:00 2001 From: "Roza." <71328419+shinyPy@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:47:04 +0800 Subject: [PATCH 3/3] add more information --- install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index b4d5a9d48..4ae0a5d62 100755 --- a/install.sh +++ b/install.sh @@ -19,7 +19,7 @@ startask () { printf ' 2. does not handle system-level/hardware stuff like Nvidia drivers\n' printf "\e[31m" - printf "Would you like to create a backup now? [y/N]: " + printf "Would you like to create a backup for \"$XDG_CONFIG_HOME\" and \"$HOME/.local/\" folders?\n[y/N]: " read -p " " backup_confirm case $backup_confirm in [yY][eE][sS]|[yY]) @@ -45,8 +45,8 @@ startask () { } case $ask in - false) sleep 0 ;; - *) startask ;; + false)sleep 0 ;; + *)startask ;; esac set -e