update-system.sh now runs sync-dotfiles.sh first, which pulls the repo (fast-forward only) and re-stows it so both machines pick up config changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
1.7 KiB
Bash
Executable File
51 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# Run by update-system.sh inside the update terminal, before the system
|
|
# update — pulls the dotfiles repo and re-stows it so both machines pick up
|
|
# config changes on every update.
|
|
#
|
|
# Never fails the update: a pull that can't fast-forward (local commits or
|
|
# uncommitted changes in the way) or a stow conflict just prints a warning
|
|
# and leaves things as they were, then the system update carries on.
|
|
|
|
DOTFILES="$HOME/Projects/dotfiles"
|
|
|
|
warn() { printf '\033[1;33m%s\033[0m\n' "$*"; }
|
|
info() { printf '\033[1;36m%s\033[0m\n' "$*"; }
|
|
|
|
if [ ! -d "$DOTFILES/.git" ]; then
|
|
warn "Dotfiles repo not found at $DOTFILES — skipping."
|
|
exit 0
|
|
fi
|
|
|
|
info "Pulling dotfiles..."
|
|
# Fetch and merge separately so the warning says which one went wrong — the
|
|
# remote is SSH via Bitwarden's agent, so a failed fetch is almost always
|
|
# Bitwarden being closed or locked.
|
|
if ! git -C "$DOTFILES" fetch; then
|
|
warn "Couldn't reach the dotfiles remote — is Bitwarden open and unlocked? Skipping stow."
|
|
echo
|
|
exit 0
|
|
fi
|
|
# --ff-only so a diverged branch never produces a surprise merge commit;
|
|
# sort that out by hand instead.
|
|
if ! git -C "$DOTFILES" merge --ff-only; then
|
|
warn "Couldn't fast-forward dotfiles (local changes or diverged branch) — skipping stow."
|
|
echo
|
|
exit 0
|
|
fi
|
|
|
|
if ! command -v stow &> /dev/null; then
|
|
warn "stow not installed — skipping."
|
|
exit 0
|
|
fi
|
|
|
|
info "Applying dotfiles with stow..."
|
|
# -R restows: drops links for files removed from the repo and adds new ones.
|
|
if stow -R -d "$DOTFILES" -t "$HOME" dotfiles; then
|
|
info "Dotfiles applied."
|
|
else
|
|
warn "stow hit a conflict — nothing was changed. Fix it and re-run:"
|
|
warn " stow -R -d $DOTFILES -t ~ dotfiles"
|
|
fi
|
|
echo
|