#!/usr/bin/env bash # Install or update Sniff on macOS: # curl -fsSL https://sniff.barkbrainlab.com/install.sh | bash # # Files fetched with curl carry no quarantine flag, so macOS opens Sniff without # the "unidentified developer" / Open Anyway step a browser download gets. set -euo pipefail BASE="${SNIFF_URL:-https://sniff.barkbrainlab.com}" APP_DIR="${SNIFF_APP_DIR:-/Applications}" say() { printf '\033[1;34m🐾 %s\033[0m\n' "$*"; } die() { printf '\033[1;31m✖ %s\033[0m\n' "$*" >&2; exit 1; } [ "$(uname -s)" = Darwin ] || die "Sniff is a macOS app." TMP=$(mktemp -d) trap 'rm -rf "$TMP"' EXIT feed=$(curl -fsSL "$BASE/latest-mac.yml?t=$(date +%s)") || die "Could not reach ${BASE}" version=$(printf '%s\n' "$feed" | sed -n 's/^version:[[:space:]]*//p' | head -1) zip=$(printf '%s\n' "$feed" | sed -n 's/^[[:space:]]*- url:[[:space:]]*\(.*\.zip\)[[:space:]]*$/\1/p' | head -1) sha=$(printf '%s\n' "$feed" | grep -A1 -F "url: $zip" | sed -n 's/^[[:space:]]*sha512:[[:space:]]*//p' | head -1) [ -n "$version" ] && [ -n "$zip" ] || die "No release found at ${BASE}" say "Downloading Sniff ${version}..." curl -fL --progress-bar "$BASE/$zip" -o "$TMP/sniff.zip" if [ -n "$sha" ]; then got=$(openssl dgst -sha512 -binary "$TMP/sniff.zip" | base64 | tr -d '\n') [ "$got" = "$sha" ] || die "Download is corrupt (sha512 mismatch), try again." fi ditto -x -k "$TMP/sniff.zip" "$TMP/unpacked" [ -d "$TMP/unpacked/Sniff.app" ] || die "Sniff.app not found in the download." if [ ! -w "$APP_DIR" ]; then APP_DIR="$HOME/Applications" mkdir -p "$APP_DIR" fi if pgrep -xq Sniff; then say "Quitting the running Sniff..." osascript -e 'quit app "Sniff"' >/dev/null 2>&1 || true sleep 1 fi rm -rf "$APP_DIR/Sniff.app" ditto "$TMP/unpacked/Sniff.app" "$APP_DIR/Sniff.app" xattr -dr com.apple.quarantine "$APP_DIR/Sniff.app" 2>/dev/null || true say "Installed Sniff ${version} in ${APP_DIR}. It updates itself from now on." [ -n "${SNIFF_NO_OPEN:-}" ] || open "$APP_DIR/Sniff.app"