diff --git a/install.sh b/install.sh index 1b2626a..ec2abf2 100755 --- a/install.sh +++ b/install.sh @@ -46,7 +46,15 @@ echo "Welcome to the colorshell installation script!" # Warn user of possible issues Send_log warn "!! By running this script, you assume total responsability for any issues that may occur with your filesystem" -Send_log warn "Your current Hyprland and kitty configuration will be overwritten, please do a backup if you still want them" + +[[ -z $skip_prompts ]] && \ + Send_log warn "Your current Hyprland and kitty configuration will be overwritten, accept the backup prompt if you still want them" + +[[ -z $skip_prompts ]] && \ + Ask "Do you want to backup what is going to be modified/overwritten?" + +[[ $answer == y ]] || [[ $skip_prompts ]] && \ + Backup_config $repo_directory [[ -z "$skip_prompts" ]] && \ Ask "Do you want to start the shell installation?" diff --git a/scripts/utils.sh b/scripts/utils.sh index 5f980ac..834d08e 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -92,6 +92,45 @@ function Is_installed() { return 1 } +# ------------- +# Interactively backup user dotfiles that ovewritten by colorshell +# param $1: colorshell repository directory +# ------------- +function Backup_config() { + bkp_dir="$HOME/config.bkp" + repo_dir=${1:-"."} + + Send_log "Creating backup in $bkp_dir" + + if [[ -d $bkp_dir ]]; then + Send_log "Found existing backup in $bkp_dir!" + Ask "Would you like to move it to trash/override it?" + + if [[ $answer == "y" ]]; then + echo "Moving previous backup is goning to be moved to trash" + trash-put $bkp_dir || (mkdir -p "$XDG_DATA_HOME/Trash" && \ + mv $bkp_dir "$XDG_DATA_HOME/Trash/$(basename $bkp_dir)") + else + echo "Ok, quitting backup because it already exists" + return 1 + fi + fi + + # Make backup of existing configurations + mkdir -p $bkp_dir + for dir in $(basename `ls -A $repo_directory/config`); do + if [[ -d "$CONFIG_DIR/$dir" ]]; then + echo "-> backuping $dir" + cp -r "$CONFIG_DIR/$dir" $DOTFILES_BACKUP_DIR + else + Send_log "$dir not found, skipped" + fi + done + + Send_log "backup has been finished" +} + + # ------------- # Ask the user to choose a number from the provided list # Input answer is exported as $answer diff --git a/update.sh b/update.sh index a5a17ce..61aed3d 100755 --- a/update.sh +++ b/update.sh @@ -55,14 +55,17 @@ echo "This is colorshell's update script" if Is_installed; then Send_log "colorshell installation found" else - Send_log "no colorshell installation found, please install it before updating" + Send_log err "no colorshell installation found, please install it before updating" exit 1 fi # Warn user of possible issues -Send_log warn "!! By running this, you assume total responsability for issues that can occur to your filesystem" +Send_log warn "!! By running this, you assume total responsability for \ +issues that can occur to your filesystem" +Send_log "The updater will only change shell configs, like hypr/shell \ +and kitty/kitty.conf, not user ones(hypr/user, kitty/user.conf)" -[[ -z "$skip_prompts" ]] && \ +[[ -z $skip_prompts ]] && \ Ask "Do you want to update colorshell?" if [[ "$answer" == y ]] || [[ "$skip_prompts" ]]; then