MacOS
This commit is contained in:
@@ -7,6 +7,7 @@ REPO_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
REBOOT_MARKER="$REPO_ROOT/.setup-reboot-required"
|
||||
REPO_SECRET_FILE="$REPO_ROOT/Zsh/.zsh_secrets"
|
||||
HOME_SECRET_FILE="$HOME/.zsh_secrets"
|
||||
BACKUP_ROOT="$HOME/.dotzsh-pre-stow-backup"
|
||||
|
||||
handle_reboot_marker() {
|
||||
if [ -f "$REBOOT_MARKER" ]; then
|
||||
@@ -42,6 +43,28 @@ sync_repo_managed_secret_file() {
|
||||
touch "$REPO_SECRET_FILE"
|
||||
}
|
||||
|
||||
backup_conflicting_home_files() {
|
||||
local backup_dir backed_up_any=0 source_file filename target_file
|
||||
|
||||
backup_dir="$BACKUP_ROOT/$(date +%Y%m%d-%H%M%S)"
|
||||
|
||||
while IFS= read -r source_file; do
|
||||
filename="$(basename "$source_file")"
|
||||
target_file="$HOME/$filename"
|
||||
|
||||
if [ -e "$target_file" ] && [ ! -L "$target_file" ]; then
|
||||
mkdir -p "$backup_dir"
|
||||
mv "$target_file" "$backup_dir/$filename"
|
||||
echo "Backed up existing $target_file -> $backup_dir/$filename"
|
||||
backed_up_any=1
|
||||
fi
|
||||
done < <(find "$REPO_ROOT/Zsh" -mindepth 1 -maxdepth 1 -type f -name '.*' ! -name '.zsh_secrets')
|
||||
|
||||
if [ "$backed_up_any" -eq 1 ]; then
|
||||
echo "Existing unmanaged dotfiles were backed up before stowing."
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
rm -f "$REBOOT_MARKER"
|
||||
|
||||
@@ -58,6 +81,7 @@ main() {
|
||||
handle_reboot_marker
|
||||
|
||||
sync_repo_managed_secret_file
|
||||
backup_conflicting_home_files
|
||||
|
||||
stow --dir="$REPO_ROOT" -D Zsh --target="$HOME" 2>/dev/null || true
|
||||
stow --dir="$REPO_ROOT" Zsh --target="$HOME"
|
||||
|
||||
Reference in New Issue
Block a user