#!/usr/bin/env bash set -euo pipefail script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" repo_root="$(cd -- "${script_dir}/../.." && pwd)" ts() { date +"%H:%M:%S"; } run_with_heartbeat() { local desc="$1" shift local start now elapsed hb_pid start="$(date +%s)" echo "==> [$(ts)] ${desc}" # Heartbeat: print elapsed time periodically in case the underlying command is quiet ( while true; do sleep 20 now="$(date +%s)" elapsed="$((now - start))" echo " [$(ts)] ... still working (${elapsed}s elapsed) ..." done ) & hb_pid="$!" set +e "$@" local rc=$? set -e kill "$hb_pid" >/dev/null 2>&1 || true wait "$hb_pid" >/dev/null 2>&1 || true now="$(date +%s)" elapsed="$((now - start))" if [[ $rc -ne 0 ]]; then echo "Error: '${desc}' failed after ${elapsed}s (exit $rc)." >&2 return "$rc" fi echo "==> [$(ts)] Done: ${desc} (${elapsed}s)" } if [[ "$(uname -s)" != "Darwin" ]]; then echo "Error: This script is for macOS only." >&2 exit 1 fi if ! command -v brew >/dev/null 2>&1; then echo "Error: Homebrew ('brew') not found in PATH." >&2 echo "Install Homebrew first: https://brew.sh/" >&2 exit 1 fi # Homebrew taps are git clones; local formula changes must be committed to be visible. if command -v git >/dev/null 2>&1 && git -C "$repo_root" rev-parse --is-inside-work-tree >/dev/null 2>&1; then if git -C "$repo_root" status --porcelain Formula/ | grep -q .; then echo "Error: You have uncommitted changes under Formula/." >&2 echo "Homebrew taps are git clones, so uncommitted formulae won't be visible to 'brew tap'." >&2 echo "Commit your changes, then re-run this script." >&2 exit 1 fi fi # Optional: disable auto-update for faster, more predictable runs. export HOMEBREW_NO_AUTO_UPDATE="${HOMEBREW_NO_AUTO_UPDATE:-1}" cd "$repo_root" echo "==> [$(ts)] Using repo: $repo_root" # Strawberry includes local Homebrew formulae under Formula/. # Homebrew requires formulae to be in a tap; we tap this repo via file:// and then # update the tap clone to the latest commit (without untapping, since Homebrew may # refuse to untap when formulae from this tap are installed). run_with_heartbeat "Ensuring local tap exists: strawberry/local" bash -lc \ "brew tap | grep -q '^strawberry/local$' || brew tap strawberry/local 'file://$repo_root' >/dev/null" run_with_heartbeat "Refreshing strawberry/local tap clone" bash -lc ' tap_repo="$(brew --repo strawberry/local)" cd "$tap_repo" # Make sure the remote points at the current local repo path. git remote set-url origin "file://'"$repo_root"'" git fetch -q origin default_ref="$(git symbolic-ref -q --short refs/remotes/origin/HEAD || true)" if [ -z "$default_ref" ]; then default_ref="origin/master" fi git reset --hard -q "$default_ref" ' for f in kdsingleapplication-qt6 qtsparkle-qt6 sparkle-framework libgpod macdeploycheck; do if ! brew info "strawberry/local/${f}" >/dev/null 2>&1; then echo "Error: Missing formula strawberry/local/${f} in the tapped repo." >&2 echo "If you recently added/changed formulae, ensure they are committed, then refresh the tap:" >&2 echo " git -C \"$(brew --repo strawberry/local)\" pull --ff-only" >&2 exit 1 fi done run_with_heartbeat "Installing dependencies from Brewfile" \ brew bundle install --file "$repo_root/Brewfile" --verbose cat <