diff options
| author | Danilo M. <danix@danix.xyz> | 2026-05-06 10:01:45 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-05-06 10:01:45 +0200 |
| commit | 4b2ffd1003531ef54396d1eb14a8b699d20073fc (patch) | |
| tree | d841e388b0eba0859565d337a055cd9287f5e39d | |
| parent | fdde3a49d44e7e1404d7665880158a5b84c3dcad (diff) | |
| download | dots-backup-4b2ffd1003531ef54396d1eb14a8b699d20073fc.tar.gz dots-backup-4b2ffd1003531ef54396d1eb14a8b699d20073fc.zip | |
Fix review findings: quoting, set -e trap, system path, push guard
- Quote all $DEFAULT_OUTPUT_DIR references to handle paths with spaces
- Replace git rev-parse $(...) with exit-code check to avoid set -e trap
- Fix system file dst using $i instead of ${i#/} (double-slash bug)
- Quote $i in beginswith call
- Simplify push guard to check remote existence directly
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| -rwxr-xr-x | dot-backup.sh | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/dot-backup.sh b/dot-backup.sh index 82b6053..4cee3fa 100755 --- a/dot-backup.sh +++ b/dot-backup.sh @@ -182,8 +182,8 @@ beginswith() { lastupdate() { D=$(date) - [ ! -f ${DEFAULT_OUTPUT_DIR}/lastupdate ] && touch ${DEFAULT_OUTPUT_DIR}/lastupdate - echo "Last update: $D" > ${DEFAULT_OUTPUT_DIR}/lastupdate + [ ! -f "${DEFAULT_OUTPUT_DIR}/lastupdate" ] && touch "${DEFAULT_OUTPUT_DIR}/lastupdate" + echo "Last update: $D" > "${DEFAULT_OUTPUT_DIR}/lastupdate" } log_verbose() { @@ -295,12 +295,12 @@ if [[ "$RESTORE" == true ]]; then fi echo -e "${YELLOW}Local Git Repository: ${NC}" -if [[ -d $DEFAULT_OUTPUT_DIR ]]; then +if [[ -d "$DEFAULT_OUTPUT_DIR" ]]; then echo -e "\t${BLUE}$DEFAULT_OUTPUT_DIR ${GREEN} ${NC}" - [ -d $DEFAULT_OUTPUT_DIR/home ] || mkdir -p $DEFAULT_OUTPUT_DIR/home - [ -d $DEFAULT_OUTPUT_DIR/system ] || mkdir -p $DEFAULT_OUTPUT_DIR/system - cd $DEFAULT_OUTPUT_DIR - if [[ $(git rev-parse --is-inside-work-tree) == "true" ]]; then + [ -d "$DEFAULT_OUTPUT_DIR/home" ] || mkdir -p "$DEFAULT_OUTPUT_DIR/home" + [ -d "$DEFAULT_OUTPUT_DIR/system" ] || mkdir -p "$DEFAULT_OUTPUT_DIR/system" + cd "$DEFAULT_OUTPUT_DIR" + if git rev-parse --is-inside-work-tree &>/dev/null; then echo -e "${GREEN}Git Repository already initialized.${NC}" else echo -e "${YELLOW}Initializing Git Repository.${NC}" @@ -311,9 +311,9 @@ else echo -e "\t${BLUE}$DEFAULT_OUTPUT_DIR ${RED} ${NC}" if [[ "$DRY_RUN" == false ]]; then echo -e "${YELLOW}creating our backup directories${NC}" - mkdir -p $DEFAULT_OUTPUT_DIR/{home,system} + mkdir -p "$DEFAULT_OUTPUT_DIR"/{home,system} echo -e "${YELLOW}Initializing Git Repository.${NC}" - cd $DEFAULT_OUTPUT_DIR + cd "$DEFAULT_OUTPUT_DIR" git init git add . fi @@ -321,7 +321,7 @@ fi # Ensure remote is registered if GIT_REMOTE is configured if [[ -n "$GIT_REMOTE" && "$DRY_RUN" == false ]]; then - cd $DEFAULT_OUTPUT_DIR + cd "$DEFAULT_OUTPUT_DIR" if git remote get-url origin &>/dev/null; then current=$(git remote get-url origin) if [[ "$current" != "$GIT_REMOTE" ]]; then @@ -352,10 +352,10 @@ for i in "${DOTFILES[@]}"; do echo -e "${BLUE}${HOME}/$i${NC}" do_rsync "${HOME}/$i" "${DEFAULT_OUTPUT_DIR}/home/$i" true # if it begins with a / it's a system file/directory - elif beginswith "/" $i; then + elif beginswith "/" "$i"; then if [[ -f $i ]]; then echo -e "${GREEN}$i${NC}" - do_rsync "$i" "${DEFAULT_OUTPUT_DIR}/system/$i" + do_rsync "$i" "${DEFAULT_OUTPUT_DIR}/system/${i#/}" elif [[ -d $i ]]; then echo -e "${BLUE}$i${NC}" do_rsync "$i" "${DEFAULT_OUTPUT_DIR}/system/${i#/}" true @@ -371,7 +371,7 @@ if [[ "$DRY_RUN" == true ]]; then fi echo -e "\n${GREEN}Adding all copied files to git.${NC}" -cd $DEFAULT_OUTPUT_DIR +cd "$DEFAULT_OUTPUT_DIR" git add . if git diff --cached --quiet; then @@ -382,7 +382,7 @@ else fi if [[ "$PUSH" == true ]]; then - if [[ -z "$GIT_REMOTE" ]] && ! git remote get-url origin &>/dev/null; then + if ! git remote get-url origin &>/dev/null; then echo -e "${RED}--push requested but no remote configured. Set GIT_REMOTE in config.${NC}" exit 1 fi |
