update setup to not overwrite
This commit is contained in:
48
setup.sh
48
setup.sh
@@ -1,6 +1,22 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
# CLI: parse flags
|
||||||
|
PROMPT_DELETE=1
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
--no-prompt|-n)
|
||||||
|
PROMPT_DELETE=0
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--prompt|-p)
|
||||||
|
PROMPT_DELETE=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*) break
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
echo ">>> Bootstrapping new Debian-like machine..."
|
echo ">>> Bootstrapping new Debian-like machine..."
|
||||||
|
|
||||||
# 1. Update package list and install essentials
|
# 1. Update package list and install essentials
|
||||||
@@ -23,10 +39,32 @@ dotfiles() {
|
|||||||
}
|
}
|
||||||
echo ">>> Checking out dotfiles..."
|
echo ">>> Checking out dotfiles..."
|
||||||
if ! dotfiles checkout; then
|
if ! dotfiles checkout; then
|
||||||
echo ">>> Conflicts detected! Backing up existing dotfiles..."
|
echo ">>> Conflicts detected! Handling conflicting dotfiles..."
|
||||||
mkdir -p $HOME/.dotfiles-backup
|
mkdir -p "$HOME/.dotfiles-backup"
|
||||||
dotfiles checkout 2>&1 | grep -E "\s+\." | awk '{print $1}' | \
|
|
||||||
xargs -I{} mv {} $HOME/.dotfiles-backup/{}
|
# Gather conflicts (paths with spaces supported)
|
||||||
|
conflicts=$(dotfiles checkout 2>&1 | grep -E "\s+\." | awk '{print $1}')
|
||||||
|
if [ -n "$conflicts" ]; then
|
||||||
|
if [ "$PROMPT_DELETE" = "0" ]; then
|
||||||
|
while IFS= read -r f; do
|
||||||
|
[ -z "$f" ] && continue
|
||||||
|
mv "$f" "$HOME/.dotfiles-backup/$f"
|
||||||
|
done <<< "$conflicts"
|
||||||
|
else
|
||||||
|
while IFS= read -r f; do
|
||||||
|
[ -z "$f" ] && continue
|
||||||
|
if [ -t 1 ]; then
|
||||||
|
read -r -p "Move '$f' to backup? (y/N): " resp
|
||||||
|
case "$resp" in
|
||||||
|
[Yy]* ) mv "$f" "$HOME/.dotfiles-backup/$f" ;;
|
||||||
|
* ) echo "Skipping '$f'." ;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
echo "Non-interactive environment detected; skipping '$f'."
|
||||||
|
fi
|
||||||
|
done <<< "$conflicts"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
dotfiles checkout
|
dotfiles checkout
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -40,6 +78,4 @@ if [ ! -d ~/.tmux/plugins/tpm ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
echo ">>> Done! Bash, tmux, vim, and dotfiles are ready."
|
echo ">>> Done! Bash, tmux, vim, and dotfiles are ready."
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user