From 12b752892bfe9e9a8eedd50aeb09c3e4f7ab8298 Mon Sep 17 00:00:00 2001 From: MangoPig Date: Mon, 1 Jun 2026 00:34:54 +0100 Subject: [PATCH] MacOS fixes --- Scripts/base.sh | 4 ++++ Scripts/bin/install.sh | 10 ++++++++-- Scripts/setup.sh | 16 ++++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Scripts/base.sh b/Scripts/base.sh index 2586e8b..4f1ca7f 100644 --- a/Scripts/base.sh +++ b/Scripts/base.sh @@ -297,6 +297,10 @@ touch "$REPO_ROOT/Zsh/.zsh_secrets" TARGET_SHELL="$(command -v zsh)" CURRENT_LOGIN_SHELL="" +if is_macos && [ -x /bin/zsh ]; then + TARGET_SHELL="/bin/zsh" +fi + if command -v getent >/dev/null 2>&1; then CURRENT_LOGIN_SHELL="$(getent passwd "$(whoami)" | cut -d: -f7)" elif is_macos && command -v dscl >/dev/null 2>&1; then diff --git a/Scripts/bin/install.sh b/Scripts/bin/install.sh index 095d804..becc1ef 100644 --- a/Scripts/bin/install.sh +++ b/Scripts/bin/install.sh @@ -46,7 +46,7 @@ detect_arch() { install_tool() { local tool="$1" - local platform arch version owner repo asset binary_rel formula url tmp_dir archive_path extracted_path target_path installed_path + local platform arch version owner repo asset binary_rel formula url tmp_dir archive_path extracted_path target_path installed_path formula_prefix platform="$(detect_platform)" arch="$(detect_arch)" @@ -74,7 +74,13 @@ install_tool() { printf '%s already installed via Homebrew\n' "$tool" fi - installed_path="$(command -v "$tool" || true)" + formula_prefix="$(brew --prefix "$formula" 2>/dev/null || true)" + if [ -n "$formula_prefix" ] && [ -x "$formula_prefix/bin/$tool" ]; then + installed_path="$formula_prefix/bin/$tool" + else + installed_path="$(command -v "$tool" || true)" + fi + if [ -z "$installed_path" ]; then printf 'Installed formula %s but %s is not on PATH\n' "$formula" "$tool" >&2 exit 1 diff --git a/Scripts/setup.sh b/Scripts/setup.sh index d1eb19f..0de8632 100644 --- a/Scripts/setup.sh +++ b/Scripts/setup.sh @@ -44,7 +44,7 @@ sync_repo_managed_secret_file() { } backup_conflicting_home_files() { - local backup_dir backed_up_any=0 source_file filename target_file + local backup_dir backed_up_any=0 source_file filename target_file target_resolved source_resolved backup_dir="$BACKUP_ROOT/$(date +%Y%m%d-%H%M%S)" @@ -52,7 +52,19 @@ backup_conflicting_home_files() { filename="$(basename "$source_file")" target_file="$HOME/$filename" - if [ -e "$target_file" ] && [ ! -L "$target_file" ]; then + if [ -L "$target_file" ]; then + target_resolved="$(python3 -c 'import os,sys; print(os.path.realpath(sys.argv[1]))' "$target_file")" + source_resolved="$(python3 -c 'import os,sys; print(os.path.realpath(sys.argv[1]))' "$source_file")" + + if [ "$target_resolved" = "$source_resolved" ]; then + continue + fi + + mkdir -p "$backup_dir" + mv "$target_file" "$backup_dir/$filename" + echo "Backed up existing linked $target_file -> $backup_dir/$filename" + backed_up_any=1 + elif [ -e "$target_file" ]; then mkdir -p "$backup_dir" mv "$target_file" "$backup_dir/$filename" echo "Backed up existing $target_file -> $backup_dir/$filename"