#!/bin/sh set -eu FEED="https://console.himoose.com/desktop-updates" APP_NAME="Hi, Moose" DOWNLOADS_PAGE="https://himoose.com/downloads/" TMP_DIR="" MOUNT_DIR="" fail() { printf '\n%s\n\n' "$1" >&2 exit 1 } cleanup() { if [ -n "$MOUNT_DIR" ] && [ -d "$MOUNT_DIR" ]; then hdiutil detach "$MOUNT_DIR" -quiet >/dev/null 2>&1 || hdiutil detach "$MOUNT_DIR" -force -quiet >/dev/null 2>&1 || true fi if [ -n "$TMP_DIR" ] && [ -d "$TMP_DIR" ]; then rm -rf "$TMP_DIR" fi } main() { trap cleanup EXIT trap 'exit 130' INT TERM if [ "$(uname -s)" != "Darwin" ]; then fail "This command is for macOS. On Windows, run this in PowerShell: irm https://himoose.com/install.ps1 | iex" fi major=$(sw_vers -productVersion | cut -d. -f1) if [ "$major" -lt 12 ]; then fail "Hi, Moose needs macOS 12 (Monterey) or later." fi arch=$(uname -m) if [ "$arch" = "x86_64" ] && [ "$(sysctl -n sysctl.proc_translated 2>/dev/null || echo 0)" = "1" ]; then arch="arm64" fi case "$arch" in arm64) arch="arm64"; label="Apple Silicon" ;; x86_64) arch="x64"; label="Intel" ;; *) fail "This Mac reports an unknown chip ($arch). Download from $DOWNLOADS_PAGE instead." ;; esac if pgrep -xq "$APP_NAME"; then fail "Hi, Moose is open. Quit it (Hi, Moose menu > Quit), then run this command again." fi printf '\nLooking up the latest version of Hi, Moose...\n' manifest=$(curl -fsSL "$FEED/latest-mac.yml") || fail "Could not reach the release list. Check your connection and try again, or download from $DOWNLOADS_PAGE" version=$(printf '%s\n' "$manifest" | sed -n 's/^version:[[:space:]]*\([^[:space:]]*\).*$/\1/p' | head -n 1) file_name=$(printf '%s\n' "$manifest" | sed -n "s/^[[:space:]]*-[[:space:]]*url:[[:space:]]*\(.*-$arch\.dmg\)[[:space:]]*$/\1/p" | head -n 1) if [ -z "$version" ] || [ -z "$file_name" ]; then fail "Could not read the release list. Try again in a minute, or download from $DOWNLOADS_PAGE" fi expected=$(printf '%s\n' "$manifest" | awk -v f="$file_name" ' /^[[:space:]]*-[[:space:]]*url:/ { line = $0; sub(/^[[:space:]]*-[[:space:]]*url:[[:space:]]*/, "", line); sub(/[[:space:]]*$/, "", line); found = (line == f); next } found && $1 == "sha512:" { print $2; exit }') size=$(printf '%s\n' "$manifest" | awk -v f="$file_name" ' /^[[:space:]]*-[[:space:]]*url:/ { line = $0; sub(/^[[:space:]]*-[[:space:]]*url:[[:space:]]*/, "", line); sub(/[[:space:]]*$/, "", line); found = (line == f); next } found && $1 == "size:" { printf "%d", $2 / 1048576; exit }') if [ -z "$expected" ]; then fail "Could not read the release list. Try again in a minute, or download from $DOWNLOADS_PAGE" fi TMP_DIR=$(mktemp -d "${TMPDIR:-/tmp}/himoose.XXXXXX") dmg="$TMP_DIR/HiMoose.dmg" url="$FEED/$(printf '%s' "$file_name" | sed 's/%/%25/g; s/ /%20/g; s/,/%2C/g')" printf 'Downloading Hi, Moose %s for %s Macs (%s MB)...\n' "$version" "$label" "${size:-?}" curl -fL --progress-bar -o "$dmg" "$url" || fail "The download did not finish. Check your connection and run the command again." printf 'Checking the download matches the published file...\n' actual=$(openssl dgst -sha512 -binary "$dmg" | base64 | tr -d '\n') if [ "$actual" != "$expected" ]; then fail "The download does not match the published file, so it was not installed. Try again, or download from $DOWNLOADS_PAGE" fi MOUNT_DIR="$TMP_DIR/mount" mkdir "$MOUNT_DIR" hdiutil attach "$dmg" -nobrowse -readonly -noautoopen -mountpoint "$MOUNT_DIR" -quiet || fail "Could not open the downloaded disk image. Download from $DOWNLOADS_PAGE instead." source_app="$MOUNT_DIR/$APP_NAME.app" if [ ! -d "$source_app" ]; then fail "The disk image does not contain $APP_NAME.app. Download from $DOWNLOADS_PAGE instead." fi printf 'Checking the app is signed and notarized by Apple...\n' if ! codesign --verify --deep --strict "$source_app" >/dev/null 2>&1 || ! spctl --assess --type execute "$source_app" >/dev/null 2>&1; then fail "The app did not pass the Apple signature check, so it was not installed. Download from $DOWNLOADS_PAGE instead." fi if [ -d "/Applications/$APP_NAME.app" ] || [ -w "/Applications" ]; then dest_dir="/Applications" else dest_dir="$HOME/Applications" mkdir -p "$dest_dir" fi dest="$dest_dir/$APP_NAME.app" printf 'Installing into %s...\n' "$dest_dir" if [ -e "$dest" ]; then rm -rf "$dest" 2>/dev/null || fail "Could not replace the existing $dest. Drag it to the Trash, then run this command again." fi ditto "$source_app" "$dest" || fail "Could not copy Hi, Moose into $dest_dir. Download from $DOWNLOADS_PAGE instead." hdiutil detach "$MOUNT_DIR" -quiet >/dev/null 2>&1 || true MOUNT_DIR="" open "$dest" >/dev/null 2>&1 || true printf '\nHi, Moose %s is installed in %s and opening now.\n\n' "$version" "$dest_dir" } main "$@"