diff --git a/sdata/step/exp-uninstall.sh b/sdata/subcmd-exp-uninstall/0.run.sh similarity index 100% rename from sdata/step/exp-uninstall.sh rename to sdata/subcmd-exp-uninstall/0.run.sh diff --git a/sdata/options/exp-uninstall.sh b/sdata/subcmd-exp-uninstall/options.sh similarity index 100% rename from sdata/options/exp-uninstall.sh rename to sdata/subcmd-exp-uninstall/options.sh diff --git a/sdata/step/exp-update-old.sh b/sdata/subcmd-exp-update-old/0.run.sh similarity index 100% rename from sdata/step/exp-update-old.sh rename to sdata/subcmd-exp-update-old/0.run.sh diff --git a/sdata/options/exp-update-old.sh b/sdata/subcmd-exp-update-old/options.sh similarity index 100% rename from sdata/options/exp-update-old.sh rename to sdata/subcmd-exp-update-old/options.sh diff --git a/sdata/step/exp-update.sh b/sdata/subcmd-exp-update/0.run.sh similarity index 98% rename from sdata/step/exp-update.sh rename to sdata/subcmd-exp-update/0.run.sh index 32d90ebec..632d63082 100644 --- a/sdata/step/exp-update.sh +++ b/sdata/subcmd-exp-update/0.run.sh @@ -3,6 +3,16 @@ # shellcheck shell=bash +##################################################################################### +# Notes by @clsty: +# +# I'm not the one who developed this script (see issue#2284 which discussed about the history). +# However it contains many unnecessary logics. This is typically what AI will do. +# I don't really care if it's AI-generated or not, it's just an extra option in addition to ./setup install, so as long as the users say it works, it should be fine. +# However, it's not easy to maintain something like this. +# The redundant logic should be cleaned up someday. +# +# This also applies for exp-update.tester.sh, TBH I don't think that file is really needed, and it also looks like AI-generated. Just guessing though. ##################################################################################### # # exp-update.sh - Enhanced dotfiles update script diff --git a/sdata/step/exp-update-tester.sh b/sdata/subcmd-exp-update/exp-update-tester.sh similarity index 96% rename from sdata/step/exp-update-tester.sh rename to sdata/subcmd-exp-update/exp-update-tester.sh index 9b467d7a1..15e93f150 100755 --- a/sdata/step/exp-update-tester.sh +++ b/sdata/subcmd-exp-update/exp-update-tester.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# exp-update-tester.sh - Test suite for exp-update.sh +# exp-update-tester.sh - Test suite for exp-update # set -euo pipefail @@ -129,7 +129,7 @@ log_header() { :; } log_die() { echo "ERROR: \$1"; exit 1; } STY_CYAN="" STY_RST="" STY_YELLOW="" -# Set required environment variables for exp-update.sh +# Set required environment variables for exp-update/0.run.sh SKIP_NOTICE=true REPO_ROOT="\$1" CHECK_PACKAGES=false @@ -139,7 +139,7 @@ VERBOSE=false NON_INTERACTIVE=true SOURCE_ONLY=true -source "$ORIGINAL_DIR/sdata/step/exp-update.sh" +source "$ORIGINAL_DIR/sdata/subcmd-exp-update/0.run.sh" detected_dirs=\$(detect_repo_structure) if [[ -n "\$detected_dirs" ]]; then read -ra MONITOR_DIRS <<<"\$detected_dirs" @@ -190,7 +190,7 @@ log_success() { :; } log_header() { :; } log_die() { echo "ERROR: \$1"; exit 1; } -# Set required environment variables for exp-update.sh +# Set required environment variables for exp-update SKIP_NOTICE=true REPO_ROOT="\$1" CHECK_PACKAGES=false @@ -200,7 +200,7 @@ VERBOSE=false NON_INTERACTIVE=true SOURCE_ONLY=true -source "$ORIGINAL_DIR/sdata/step/exp-update.sh" +source "$ORIGINAL_DIR/sdata/subcmd-exp-update/0.run.sh" detected_dirs=\$(detect_repo_structure) if [[ -n "\$detected_dirs" ]]; then read -ra MONITOR_DIRS <<<"\$detected_dirs" @@ -276,7 +276,7 @@ log_success() { :; } log_header() { :; } log_die() { echo "ERROR: \$1" >&2; exit 1; } -# FIXED: Set REPO_ROOT before sourcing exp-update.sh +# FIXED: Set REPO_ROOT before sourcing exp-update REPO_ROOT="\$1" export REPO_ROOT @@ -293,7 +293,7 @@ HOME_UPDATE_IGNORE_FILE="/dev/null" # Source the production script to use the real should_ignore function # Redirect all unwanted output to stderr, then to /dev/null -source "$ORIGINAL_DIR/sdata/step/exp-update.sh" 2>/dev/null +source "$ORIGINAL_DIR/sdata/subcmd-exp-update/0.run.sh" 2>/dev/null test_cases=( "\$REPO_ROOT/app.log:0" @@ -348,7 +348,7 @@ test_safe_read_security() { log_test "Testing safe_read uses secure assignment (printf -v)" local safe_read_function - safe_read_function=$(awk '/^safe_read\(\) \{/,/^\}/' "$ORIGINAL_DIR/sdata/step/exp-update.sh") + safe_read_function=$(awk '/^safe_read\(\) \{/,/^\}/' "$ORIGINAL_DIR/sdata/subcmd-exp-update/0.run.sh") if [[ -z "$safe_read_function" ]]; then log_fail "Could not find safe_read function" @@ -547,7 +547,7 @@ log_success() { :; } log_header() { :; } log_die() { echo "ERROR: \$1" >&2; exit 1; } -# FIXED: Set REPO_ROOT before sourcing exp-update.sh +# FIXED: Set REPO_ROOT before sourcing exp-update REPO_ROOT="\$1" export REPO_ROOT @@ -563,7 +563,7 @@ UPDATE_IGNORE_FILE="\${REPO_ROOT}/.updateignore" HOME_UPDATE_IGNORE_FILE="/dev/null" # Source the production script to use the real should_ignore function -source "$ORIGINAL_DIR/sdata/step/exp-update.sh" 2>/dev/null +source "$ORIGINAL_DIR/sdata/subcmd-exp-update/0.run.sh" 2>/dev/null # Load patterns into cache load_ignore_patterns @@ -649,7 +649,7 @@ VERBOSE=false NON_INTERACTIVE=true SOURCE_ONLY=true -source "$ORIGINAL_DIR/sdata/step/exp-update.sh" 2>/dev/null +source "$ORIGINAL_DIR/sdata/subcmd-exp-update/0.run.sh" 2>/dev/null test_dir="/tmp/test-ensure-dir-\$\$" diff --git a/sdata/options/exp-update.sh b/sdata/subcmd-exp-update/options.sh similarity index 100% rename from sdata/options/exp-update.sh rename to sdata/subcmd-exp-update/options.sh diff --git a/sdata/step/0.install-greeting.sh b/sdata/subcmd-install/0.greeting.sh similarity index 100% rename from sdata/step/0.install-greeting.sh rename to sdata/subcmd-install/0.greeting.sh diff --git a/sdata/step/1.install-deps-selector.sh b/sdata/subcmd-install/1.deps-selector.sh similarity index 99% rename from sdata/step/1.install-deps-selector.sh rename to sdata/subcmd-install/1.deps-selector.sh index c1f4bea0c..ebed1bb04 100644 --- a/sdata/step/1.install-deps-selector.sh +++ b/sdata/subcmd-install/1.deps-selector.sh @@ -1,5 +1,6 @@ # This script is meant to be sourced. # It's not for directly running. +printf "${STY_CYAN}[$0]: 1. Install dependencies\n${STY_RST}" function outdate_detect(){ # Shallow clone prevent latest_commit_timestamp() from working. diff --git a/sdata/step/2.install-setups-selector.sh b/sdata/subcmd-install/2.setups-selector.sh similarity index 97% rename from sdata/step/2.install-setups-selector.sh rename to sdata/subcmd-install/2.setups-selector.sh index c279d7085..e4c8e612d 100644 --- a/sdata/step/2.install-setups-selector.sh +++ b/sdata/subcmd-install/2.setups-selector.sh @@ -1,5 +1,6 @@ # This script is meant to be sourced. # It's not for directly running. +printf "${STY_CYAN}[$0]: 2. Setup for permissions/services etc\n${STY_RST}" # shellcheck shell=bash diff --git a/sdata/step/3.install-files.sh b/sdata/subcmd-install/3.files.sh similarity index 94% rename from sdata/step/3.install-files.sh rename to sdata/subcmd-install/3.files.sh index eaea5017a..a9dc7c7e0 100644 --- a/sdata/step/3.install-files.sh +++ b/sdata/subcmd-install/3.files.sh @@ -1,5 +1,6 @@ # This script is meant to be sourced. # It's not for directly running. +printf "${STY_CYAN}[$0]: 3. Copying config files\n${STY_RST}" # shellcheck shell=bash @@ -67,6 +68,15 @@ function ask_backup_configs(){ if $backup;then backup_clashing_targets dots/.config $XDG_CONFIG_HOME "${BACKUP_DIR}/.config" backup_clashing_targets dots/.local/share $XDG_DATA_HOME "${BACKUP_DIR}/.local/share" + printf "${STY_BLUE}Backup into \"${BACKUP_DIR}\" finished.${STY_RST}\n" + fi +} +function auto_backup_configs(){ + # Backup when $BACKUP_DIR does not exist + if [[ ! -d "$BACKUP_DIR" ]]; then + backup_clashing_targets dots/.config $XDG_CONFIG_HOME "${BACKUP_DIR}/.config" + backup_clashing_targets dots/.local/share $XDG_DATA_HOME "${BACKUP_DIR}/.local/share" + printf "${STY_BLUE}Backup into \"${BACKUP_DIR}\" finished.${STY_RST}\n" fi } @@ -75,10 +85,12 @@ function ask_backup_configs(){ # In case some dirs does not exists v mkdir -p $XDG_BIN_HOME $XDG_CACHE_HOME $XDG_CONFIG_HOME/quickshell $XDG_DATA_HOME -case $ask in - false) sleep 0 ;; - *) ask_backup_configs ;; -esac +if [[ ! "${SKIP_BACKUP}" == true ]]; then + case $ask in + false) auto_backup_configs ;; + *) ask_backup_configs ;; + esac +fi # TODO: A better method for users to choose their customization, # for example some users may prefer ZSH over FISH, and foot over kitty. diff --git a/sdata/options/install.sh b/sdata/subcmd-install/options.sh similarity index 92% rename from sdata/options/install.sh rename to sdata/subcmd-install/options.sh index fa3f2b4e3..46a31d71f 100644 --- a/sdata/options/install.sh +++ b/sdata/subcmd-install/options.sh @@ -14,6 +14,7 @@ Options for install: --skip-allsetups Skip the whole process setting up permissions/services etc --skip-allfiles Skip the whole process copying configuration files -s, --skip-sysupdate Skip system package upgrade e.g. \"sudo pacman -Syu\" + --skip-backup Skip backup conflicting files --skip-quickshell Skip installing the config for Quickshell --skip-hyprland Skip installing the config for Hyprland --skip-fish Skip installing the config for Fish @@ -33,7 +34,7 @@ cleancache(){ # `man getopt` to see more para=$(getopt \ -o hfk:cs \ - -l help,force,fontset:,clean,skip-allgreeting,skip-alldeps,skip-allsetups,skip-allfiles,skip-sysupdate,skip-quickshell,skip-fish,skip-hyprland,skip-plasmaintg,skip-miscconf,exp-files,via-nix \ + -l help,force,fontset:,clean,skip-allgreeting,skip-alldeps,skip-allsetups,skip-allfiles,skip-sysupdate,skip-backup,skip-quickshell,skip-fish,skip-hyprland,skip-plasmaintg,skip-miscconf,exp-files,via-nix \ -n "$0" -- "$@") [ $? != 0 ] && echo "$0: Error when getopt, please recheck parameters." && exit 1 ##################################################################################### @@ -63,6 +64,7 @@ while true ; do --skip-allsetups) SKIP_ALLSETUPS=true;shift;; --skip-allfiles) SKIP_ALLFILES=true;shift;; -s|--skip-sysupdate) SKIP_SYSUPDATE=true;shift;; + --skip-backup) SKIP_BACKUP=true;shift;; --skip-hyprland) SKIP_HYPRLAND=true;shift;; --skip-fish) SKIP_FISH=true;shift;; --skip-quickshell) SKIP_QUICKSHELL=true;shift;; diff --git a/setup b/setup index 8fe456ff9..8e6b51d6d 100755 --- a/setup +++ b/setup @@ -34,75 +34,67 @@ case $1 in # Global help help|--help|-h)showhelp_global;exit;; # Correct subcommand - install|install-deps|install-setups|install-files|exp-uninstall|exp-update|exp-update-old) - SCRIPT_SUBCOMMAND=$1;shift;; - # No subcommand - -*|"")SCRIPT_SUBCOMMAND=install;; + install|exp-uninstall|exp-update|exp-update-old) + SUBCMD_NAME=$1 + SUBCMD_DIR=./sdata/subcmd-$1 + shift;; + # Correct subcommand but not using ./sdata/subcmd-$1 + install-deps|install-setups|install-files) + SUBCMD_NAME=$1 + SUBCMD_DIR=./sdata/subcmd-install + shift;; + # No subcommand, default to install + -*|"") + SUBCMD_NAME=install + SUBCMD_DIR=./sdata/subcmd-install + ;; # Wrong subcommand *)printf "${STY_RED}Unknown subcommand \"$1\".${STY_RST}\n";showhelp_global;exit 1;; esac ##################################################################################### -case ${SCRIPT_SUBCOMMAND} in +if [[ -f "${SUBCMD_DIR}/options.sh" ]]; + then source "${SUBCMD_DIR}/options.sh" +fi +case ${SUBCMD_NAME} in install) - source ./sdata/options/install.sh if [[ "${SKIP_ALLGREETING}" != true ]]; then - source ./sdata/step/0.install-greeting.sh + source ${SUBCMD_DIR}/0.greeting.sh fi if [[ "${SKIP_ALLDEPS}" != true ]]; then - printf "${STY_CYAN}[$0]: 1. Install dependencies\n${STY_RST}" - source ./sdata/step/1.install-deps-selector.sh + source ${SUBCMD_DIR}/1.deps-selector.sh fi if [[ "${SKIP_ALLSETUPS}" != true ]]; then - printf "${STY_CYAN}[$0]: 2. Setup for permissions/services etc\n${STY_RST}" - source ./sdata/step/2.install-setups-selector.sh + source ${SUBCMD_DIR}/2.setups-selector.sh fi if [[ "${SKIP_ALLFILES}" != true ]]; then - printf "${STY_CYAN}[$0]: 3. Copying config files\n${STY_RST}" if [[ "${EXPERIMENTAL_FILES_SCRIPT}" == true ]]; then - source ./sdata/step/3.install-files.experimental.sh + source ${SUBCMD_DIR}/3.files-exp.sh else - source ./sdata/step/3.install-files.sh + source ${SUBCMD_DIR}/3.files.sh fi fi ;; install-deps) - source ./sdata/options/install.sh if [[ "${SKIP_ALLDEPS}" != true ]]; then - printf "${STY_CYAN}[$0]: 1. Install dependencies\n${STY_RST}" - source ./sdata/step/1.install-deps-selector.sh + source ${SUBCMD_DIR}/1.deps-selector.sh fi ;; install-setups) - source ./sdata/options/install.sh if [[ "${SKIP_ALLSETUPS}" != true ]]; then - printf "${STY_CYAN}[$0]: 2. Setup for permissions/services etc\n${STY_RST}" - source ./sdata/step/2.install-setups-selector.sh + source ${SUBCMD_DIR}/2.setups-selector.sh fi ;; install-files) - source ./sdata/options/install.sh if [[ "${SKIP_ALLFILES}" != true ]]; then - printf "${STY_CYAN}[$0]: 3. Copying config files\n${STY_RST}" if [[ "${EXPERIMENTAL_FILES_SCRIPT}" == true ]]; then - source ./sdata/step/3.install-files.experimental.sh + source ${SUBCMD_DIR}/3.files-exp.sh else - source ./sdata/step/3.install-files.sh + source ${SUBCMD_DIR}/3.files.sh fi fi ;; - exp-uninstall) - source ./sdata/options/exp-uninstall.sh - source ./sdata/step/exp-uninstall.sh - exit - ;; - exp-update) - source ./sdata/options/exp-update.sh - source ./sdata/step/exp-update.sh - exit - ;; - exp-update-old) - source ./sdata/options/exp-update-old.sh - source ./sdata/step/exp-update-old.sh + exp-*) + source ${SUBCMD_DIR}/0.run.sh exit ;; esac