#!/bin/bash # Below Boil installer. Usage: # curl -fsSL https://belowboil.com/install.sh | bash # Installs the newest Below Boil into /Applications (or ~/Applications when /Applications is not writable). # No sudo. A zip fetched by curl carries no quarantine flag, so macOS does not ask for Open Anyway. # Test overrides (not for normal use): BELOWBOIL_URL (zip), BELOWBOIL_DEST (install folder), # BELOWBOIL_NO_OPEN=1 (do not launch). set -euo pipefail main() { # These stay global so the EXIT trap can still read them after main returns. app_name="Below Boil"; tmp=""; dest=""; old="" local bundle_id="dev.sedgelabs.belowboil" local url="${BELOWBOIL_URL:-https://belowboil.com/download}" say() { printf '%s\n' "$*"; } die() { printf 'Below Boil installer: %s\n' "$*" >&2; exit 1; } [ "$(uname -s)" = "Darwin" ] || die "this is a Mac app. It cannot be installed on $(uname -s)." # Apple Silicon only. uname can say x86_64 inside a Rosetta shell, so ask the kernel as well. local arm=0 [ "$(uname -m)" = "arm64" ] && arm=1 [ "$(sysctl -n hw.optional.arm64 2>/dev/null || echo 0)" = "1" ] && arm=1 [ "$arm" = 1 ] || die "Below Boil needs a Mac with Apple Silicon (M1 or later). This Mac is $(uname -m)." cleanup() { # Put the old copy back if the new one never landed. if [ -n "$old" ] && [ -d "$old" ] && [ -n "$dest" ] && [ ! -d "$dest/$app_name.app" ]; then mv "$old" "$dest/$app_name.app" 2>/dev/null || true fi [ -n "$tmp" ] && rm -rf "$tmp" return 0 } trap cleanup EXIT # Where it goes. if [ -n "${BELOWBOIL_DEST:-}" ]; then dest="$BELOWBOIL_DEST" mkdir -p "$dest" elif [ -w /Applications ]; then dest="/Applications" else dest="$HOME/Applications" mkdir -p "$dest" fi [ -w "$dest" ] || die "$dest is not writable." tmp="$(mktemp -d "${TMPDIR:-/tmp}/belowboil.XXXXXX")" say "Downloading Below Boil..." if [ -n "${BELOWBOIL_URL:-}" ]; then curl -fL --silent --show-error -o "$tmp/BelowBoil.zip" "$url" || die "the download failed." else curl -fL --silent --show-error --proto '=https' --tlsv1.2 -o "$tmp/BelowBoil.zip" "$url" \ || die "the download failed. Check your connection and try again." fi mkdir "$tmp/unpacked" ditto -x -k "$tmp/BelowBoil.zip" "$tmp/unpacked" || die "could not unpack the download." local new="$tmp/unpacked/$app_name.app" [ -d "$new" ] || die "the download does not contain $app_name.app." local plist="$new/Contents/Info.plist" local got_id got_id="$(/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' "$plist" 2>/dev/null || true)" [ "$got_id" = "$bundle_id" ] || die "the download is not Below Boil (bundle id '$got_id')." codesign --verify --strict --deep "$new" 2>/dev/null || die "the download's signature does not verify. Nothing was installed." # Architecture and macOS version, from the app itself. # lipo is an xcode-select shim without developer tools, so read the architectures with file(1). local exe archs min cur exe="$new/Contents/MacOS/$(/usr/libexec/PlistBuddy -c 'Print CFBundleExecutable' "$plist")" archs="$(/usr/bin/file -b "$exe" 2>/dev/null || true)" case "$archs" in *arm64*) ;; *) die "this Below Boil build has no Apple Silicon version (${archs:-unreadable binary})." ;; esac min="$(/usr/libexec/PlistBuddy -c 'Print LSMinimumSystemVersion' "$plist" 2>/dev/null || echo 0)" cur="$(sw_vers -productVersion)" version_ge "$cur" "$min" || die "Below Boil needs macOS $min or later. This Mac has macOS $cur." # Quit a running copy: politely first, then by force. if pgrep -f "/$app_name.app/Contents/MacOS/" >/dev/null 2>&1; then say "Quitting the running Below Boil..." osascript -e "tell application id \"$bundle_id\" to quit" >/dev/null 2>&1 || true local i=0 while [ $i -lt 10 ] && pgrep -f "/$app_name.app/Contents/MacOS/" >/dev/null 2>&1; do sleep 0.5; i=$((i + 1)); done if pgrep -f "/$app_name.app/Contents/MacOS/" >/dev/null 2>&1; then pkill -f "$dest/$app_name.app/Contents/MacOS/" >/dev/null 2>&1 || true sleep 1 fi fi # Replace any existing copy. The old one waits in the temp folder until the new one is in place. local replaced=0 if [ -e "$dest/$app_name.app" ]; then old="$tmp/previous.app" mv "$dest/$app_name.app" "$old" || die "could not move the existing copy aside." replaced=1 fi if ! ditto "$new" "$dest/$app_name.app"; then rm -rf "$dest/$app_name.app" die "copying into $dest failed.${old:+ The previous copy was restored.}" fi xattr -dr com.apple.quarantine "$dest/$app_name.app" 2>/dev/null || true old="" # installed: nothing to restore if [ "${BELOWBOIL_NO_OPEN:-}" != "1" ]; then open "$dest/$app_name.app" || say "Installed, but could not open it. Open it from $dest." fi if [ "$replaced" = 1 ]; then say "Replaced the old copy."; fi say "Installed $app_name to $dest/$app_name.app" [ "${BELOWBOIL_NO_OPEN:-}" = "1" ] || say "It is running in your menu bar." say "To uninstall, quit it and move it to the Trash." } # True when dotted version $1 >= $2 (numeric parts, missing parts count as 0). bash 3.2 safe. version_ge() { local a="$1" b="$2" x y while [ -n "$a$b" ]; do x="${a%%.*}"; y="${b%%.*}" [ "${x:-0}" -gt "${y:-0}" ] && return 0 [ "${x:-0}" -lt "${y:-0}" ] && return 1 case "$a" in *.*) a="${a#*.}" ;; *) a="" ;; esac case "$b" in *.*) b="${b#*.}" ;; *) b="" ;; esac done return 0 } main "$@"