diff --git a/install.sh b/install.sh index 4e825aefe..57b36af9b 100755 --- a/install.sh +++ b/install.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash cd "$(dirname "$0")" +# TODO: Use REPO_ROOT instead of base +# Also, when scripts are sourced they do not need export to inherit vars export base="$(pwd)" +REPO_ROOT="$(pwd)" source ./sdata/lib/environment-variables.sh source ./sdata/lib/functions.sh source ./sdata/lib/package-installers.sh @@ -13,11 +16,11 @@ set -e # For subcommands case ${SCRIPT_SUBCOMMAND} in exp-uninstall) - source ./sdata/exp/uninstall.sh + source ./sdata/step/exp-uninstall.sh exit ;; exp-update) - source ./sdata/exp/update.sh + source ./sdata/step/exp-update.sh exit ;; esac diff --git a/sdata/lib/options-exp-update.sh b/sdata/lib/options-exp-update.sh index 798b6a776..93cb4c7f0 100644 --- a/sdata/lib/options-exp-update.sh +++ b/sdata/lib/options-exp-update.sh @@ -17,17 +17,6 @@ This script updates your dotfiles by: 5. Updating script permissions " } - 0 - ;; - shift - ;; - *) - log_error "Unknown option: $1" - echo "Use --help for usage information" - exit 1 - ;; - esac -done # `man getopt` to see more para=$(getopt \ -o hfpnv \ @@ -52,6 +41,7 @@ FORCE_CHECK=false CHECK_PACKAGES=false DRY_RUN=false VERBOSE=false +SKIP_NOTICE=false eval set -- "$para" while true ; do diff --git a/sdata/lib/options-install.sh b/sdata/lib/options-install.sh index 5ca4bea7c..c0b9320b4 100644 --- a/sdata/lib/options-install.sh +++ b/sdata/lib/options-install.sh @@ -43,13 +43,6 @@ while true ; do --exp-files) EXPERIMENTAL_FILES_SCRIPT=true;shift;; --via-nix) INSTALL_VIA_NIX=true;shift;; - ## Update script specific options - -u|--update-force) UPDATE_FORCE=true;shift;; - -p|--packages) UPDATE_PACKAGES=true;shift;; - -n|--dry-run) UPDATE_DRY_RUN=true;shift;; - -v|--verbose) UPDATE_VERBOSE=true;shift;; - --skip-notice) SKIP_NOTICE=true;shift;; - ## Ones with parameter --fontset) case $2 in diff --git a/sdata/exp/uninstall.sh b/sdata/step/exp-uninstall.sh similarity index 100% rename from sdata/exp/uninstall.sh rename to sdata/step/exp-uninstall.sh diff --git a/sdata/exp/test_update.sh b/sdata/step/exp-update-tester.sh similarity index 92% rename from sdata/exp/test_update.sh rename to sdata/step/exp-update-tester.sh index cd696c042..d62c04a28 100755 --- a/sdata/exp/test_update.sh +++ b/sdata/step/exp-update-tester.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# test_update.sh - Test suite for update.sh +# exp-update-tester.sh - Test suite for update.sh # set -euo pipefail @@ -140,18 +140,18 @@ test_dots_structure() { cat > test_detection.sh << 'EOF' #!/bin/bash -REPO_DIR="$1" +REPO_ROOT="$1" detect_repo_structure() { local found_dirs=() - if [[ -d "${REPO_DIR}/dots/.config" ]]; then + if [[ -d "${REPO_ROOT}/dots/.config" ]]; then found_dirs+=("dots/.config") - [[ -d "${REPO_DIR}/dots/.local/bin" ]] && found_dirs+=("dots/.local/bin") - elif [[ -d "${REPO_DIR}/.config" ]]; then + [[ -d "${REPO_ROOT}/dots/.local/bin" ]] && found_dirs+=("dots/.local/bin") + elif [[ -d "${REPO_ROOT}/.config" ]]; then found_dirs+=(".config") - [[ -d "${REPO_DIR}/.local/bin" ]] && found_dirs+=(".local/bin") + [[ -d "${REPO_ROOT}/.local/bin" ]] && found_dirs+=(".local/bin") else for candidate in "dots/.config" ".config" "dots/.local/bin" ".local/bin"; do - if [[ -d "${REPO_DIR}/${candidate}" ]]; then + if [[ -d "${REPO_ROOT}/${candidate}" ]]; then if [[ ! " ${found_dirs[*]} " =~ " ${candidate} " ]]; then found_dirs+=("${candidate}") fi @@ -200,18 +200,18 @@ test_flat_structure() { cat > test_detection.sh << 'EOF' #!/bin/bash -REPO_DIR="$1" +REPO_ROOT="$1" detect_repo_structure() { local found_dirs=() - if [[ -d "${REPO_DIR}/dots/.config" ]]; then + if [[ -d "${REPO_ROOT}/dots/.config" ]]; then found_dirs+=("dots/.config") - [[ -d "${REPO_DIR}/dots/.local/bin" ]] && found_dirs+=("dots/.local/bin") - elif [[ -d "${REPO_DIR}/.config" ]]; then + [[ -d "${REPO_ROOT}/dots/.local/bin" ]] && found_dirs+=("dots/.local/bin") + elif [[ -d "${REPO_ROOT}/.config" ]]; then found_dirs+=(".config") - [[ -d "${REPO_DIR}/.local/bin" ]] && found_dirs+=(".local/bin") + [[ -d "${REPO_ROOT}/.local/bin" ]] && found_dirs+=(".local/bin") else for candidate in "dots/.config" ".config" "dots/.local/bin" ".local/bin"; do - if [[ -d "${REPO_DIR}/${candidate}" ]]; then + if [[ -d "${REPO_ROOT}/${candidate}" ]]; then if [[ ! " ${found_dirs[*]} " =~ " ${candidate} " ]]; then found_dirs+=("${candidate}") fi @@ -285,16 +285,16 @@ EOF cat > test_ignore.sh << 'EOF' #!/bin/bash -REPO_DIR="$1" -UPDATE_IGNORE_FILE="${REPO_DIR}/.updateignore" +REPO_ROOT="$1" +UPDATE_IGNORE_FILE="${REPO_ROOT}/.updateignore" HOME_UPDATE_IGNORE_FILE="/dev/null" should_ignore() { local file_path="$1" local relative_path="${file_path#$HOME/}" local repo_relative="" - if [[ "$file_path" == "$REPO_DIR"* ]]; then - repo_relative="${file_path#$REPO_DIR/}" + if [[ "$file_path" == "$REPO_ROOT"* ]]; then + repo_relative="${file_path#$REPO_ROOT/}" fi for ignore_file in "$UPDATE_IGNORE_FILE" "$HOME_UPDATE_IGNORE_FILE"; do @@ -326,11 +326,11 @@ should_ignore() { } test_cases=( - "$REPO_DIR/app.log:0" - "$REPO_DIR/secrets/key.txt:0" - "$REPO_DIR/.config/private-config:0" - "$REPO_DIR/.config/backup-file:0" - "$REPO_DIR/normal-config:1" + "$REPO_ROOT/app.log:0" + "$REPO_ROOT/secrets/key.txt:0" + "$REPO_ROOT/.config/private-config:0" + "$REPO_ROOT/.config/backup-file:0" + "$REPO_ROOT/normal-config:1" ) all_passed=true diff --git a/sdata/exp/update.sh b/sdata/step/exp-update.sh similarity index 94% rename from sdata/exp/update.sh rename to sdata/step/exp-update.sh index 09218cb66..9a681d2ea 100644 --- a/sdata/exp/update.sh +++ b/sdata/step/exp-update.sh @@ -14,22 +14,20 @@ # set -euo pipefail -REPO_DIR="$(pwd)" - # TODO: For Arch(-Linux) specific part please check if pacman exists first, if not it should be skipped. # TODO: Is this really needed? `git pull` should do a full upgrade, not partially, which means this script will be updated along with the folder structure together. # Try to find the packages directory (different names in different versions) -if [[ -d "${REPO_DIR}/dist-arch" ]]; then - ARCH_PACKAGES_DIR="${REPO_DIR}/dist-arch" -elif [[ -d "${REPO_DIR}/arch-packages" ]]; then - ARCH_PACKAGES_DIR="${REPO_DIR}/arch-packages" -elif [[ -d "${REPO_DIR}/sdist/arch" ]]; then - ARCH_PACKAGES_DIR="${REPO_DIR}/sdist/arch" +if [[ -d "${REPO_ROOT}/dist-arch" ]]; then + ARCH_PACKAGES_DIR="${REPO_ROOT}/dist-arch" +elif [[ -d "${REPO_ROOT}/arch-packages" ]]; then + ARCH_PACKAGES_DIR="${REPO_ROOT}/arch-packages" +elif [[ -d "${REPO_ROOT}/sdist/arch" ]]; then + ARCH_PACKAGES_DIR="${REPO_ROOT}/sdist/arch" else - ARCH_PACKAGES_DIR="${REPO_DIR}/dist-arch" # Default fallback + ARCH_PACKAGES_DIR="${REPO_ROOT}/dist-arch" # Default fallback fi -UPDATE_IGNORE_FILE="${REPO_DIR}/.updateignore" +UPDATE_IGNORE_FILE="${REPO_ROOT}/.updateignore" HOME_UPDATE_IGNORE_FILE="${HOME}/.updateignore" # TODO: Is this really needed? `git pull` should do a full upgrade, not partially, which means this script will be updated along with the folder structure together. @@ -38,19 +36,19 @@ detect_repo_structure() { local found_dirs=() # Check for dots/ prefixed structure - if [[ -d "${REPO_DIR}/dots/.config" ]]; then + if [[ -d "${REPO_ROOT}/dots/.config" ]]; then found_dirs+=("dots/.config") - [[ -d "${REPO_DIR}/dots/.local/bin" ]] && found_dirs+=("dots/.local/bin") - [[ -d "${REPO_DIR}/dots/.local/share" ]] && found_dirs+=("dots/.local/share") + [[ -d "${REPO_ROOT}/dots/.local/bin" ]] && found_dirs+=("dots/.local/bin") + [[ -d "${REPO_ROOT}/dots/.local/share" ]] && found_dirs+=("dots/.local/share") # Check for flat structure - elif [[ -d "${REPO_DIR}/.config" ]]; then + elif [[ -d "${REPO_ROOT}/.config" ]]; then found_dirs+=(".config") - [[ -d "${REPO_DIR}/.local/bin" ]] && found_dirs+=(".local/bin") - [[ -d "${REPO_DIR}/.local/share" ]] && found_dirs+=(".local/share") + [[ -d "${REPO_ROOT}/.local/bin" ]] && found_dirs+=(".local/bin") + [[ -d "${REPO_ROOT}/.local/share" ]] && found_dirs+=(".local/share") else # Manual detection of common directories for candidate in "dots/.config" ".config" "config" "dots/.local/bin" ".local/bin" "dots/.local/share" ".local/share"; do - if [[ -d "${REPO_DIR}/${candidate}" ]]; then + if [[ -d "${REPO_ROOT}/${candidate}" ]]; then # Avoid duplicates if [[ ! " ${found_dirs[*]} " =~ " ${candidate} " ]]; then found_dirs+=("${candidate}") @@ -104,8 +102,8 @@ should_ignore() { # Also get path relative to repo for repo-level ignores local repo_relative="" - if [[ "$file_path" == "$REPO_DIR"* ]]; then - repo_relative="${file_path#$REPO_DIR/}" + if [[ "$file_path" == "$REPO_ROOT"* ]]; then + repo_relative="${file_path#$REPO_ROOT/}" fi # Check both repo and home ignore files @@ -354,7 +352,7 @@ check_pkgbuild_changed() { [[ ! -f "$pkgbuild_path" ]] && return 1 - local relative_path="${pkgbuild_path#$REPO_DIR/}" + local relative_path="${pkgbuild_path#$REPO_ROOT/}" if [[ "$FORCE_CHECK" == true ]]; then return 0 @@ -501,7 +499,7 @@ build_packages() { log_error "Failed to build package $pkg_name" fi - cd "$REPO_DIR" || log_die "Failed to return to repository directory" + cd "$REPO_ROOT" || log_die "Failed to return to repository directory" done if [[ $rebuilt_packages -eq 0 ]]; then @@ -523,7 +521,7 @@ get_changed_files() { # Get files that changed in the last pull local has_changes=false while IFS= read -r file; do - local full_path="${REPO_DIR}/${file}" + local full_path="${REPO_ROOT}/${file}" if [[ "$full_path" == "$dir_path"/* ]] && [[ -f "$full_path" ]]; then printf '%s\0' "$full_path" has_changes=true @@ -554,7 +552,7 @@ has_new_commits() { # Main script starts here log_header "Dotfiles Update Script" -if [[ "$SKIP_NOTICE" != true ]]; then +if [[ "$SKIP_NOTICE" == false ]]; then log_warning "THIS SCRIPT IS NOT FULLY TESTED AND MAY CAUSE ISSUES!" log_warning "It might be safer if you want to preserve your modifications and not delete added files," log_warning " but this can cause partial updates and therefore unexpected behavior like in #1856." @@ -566,9 +564,10 @@ if [[ "$SKIP_NOTICE" != true ]]; then exit 1 fi fi +exit # Check if we're in a git repository -cd "$REPO_DIR" || log_die "Failed to change to repository directory" +cd "$REPO_ROOT" || log_die "Failed to change to repository directory" if git rev-parse --is-inside-work-tree &>/dev/null; then log_info "Running in git repository: $(git rev-parse --show-toplevel)" @@ -583,10 +582,10 @@ if detected_dirs=$(detect_repo_structure); then read -ra MONITOR_DIRS <<<"$detected_dirs" log_success "Detected repository structure:" for dir in "${MONITOR_DIRS[@]}"; do - if [[ -d "${REPO_DIR}/${dir}" ]]; then - log_info " ✓ ${REPO_DIR}/${dir}" + if [[ -d "${REPO_ROOT}/${dir}" ]]; then + log_info " ✓ ${REPO_ROOT}/${dir}" else - log_warning " ✗ ${REPO_DIR}/${dir} (not found, will skip)" + log_warning " ✗ ${REPO_ROOT}/${dir} (not found, will skip)" fi done else @@ -763,7 +762,7 @@ if [[ "$process_files" == true ]]; then files_created=0 for dir_name in "${MONITOR_DIRS[@]}"; do - repo_dir_path="${REPO_DIR}/${dir_name}" + repo_dir_path="${REPO_ROOT}/${dir_name}" if [[ ! -d "$repo_dir_path" ]]; then if [[ "$VERBOSE" == true ]]; then @@ -882,7 +881,7 @@ fi if [[ ! -f "$HOME_UPDATE_IGNORE_FILE" && ! -f "$UPDATE_IGNORE_FILE" ]]; then echo log_info "Tip: Create ignore files to exclude files from updates:" - echo " - Repository ignore: ${REPO_DIR}/.updateignore" + echo " - Repository ignore: ${REPO_ROOT}/.updateignore" echo " - User ignore: ~/.updateignore" echo echo "Example patterns:"