Files
routine/install-mac.sh

191 lines
8.2 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Routine for macOS: install it, update it (run this again), or remove it (--uninstall).
# UNTESTED ON A REAL MAC so far: if anything goes wrong, please send the output.
#
# curl -fsSL https://git.autonomic.zone/trav/routine/raw/branch/main/install-mac.sh | bash
# curl -fsSL https://git.autonomic.zone/trav/routine/raw/branch/main/install-mac.sh | bash -s -- --uninstall
#
# No admin password, no Xcode, no Homebrew, no git. It downloads into
# ~/Library/Application Support/Routine-app the app, its own Python and Qt (~400 MB)
# and makes Routine.app (in /Applications if you can write there, else ~/Applications) that opens it.
# Your routine and history live apart from it, in ~/Library/Application Support/Routine, and are
# never touched by updating or uninstalling.
#
# How: uv (https://docs.astral.sh/uv/, a single program, kept inside the app folder) fetches a
# standalone Python 3.13 and PySide6 into that folder. Nothing is installed anywhere else.
#
# Optional settings (for testing): ROUTINE_SOURCE=DIR|FILE.tar.gz (a local copy instead of
# downloading), ROUTINE_ARCHIVE=URL, ROUTINE_APPS_DIR=DIR (where Routine.app goes), ROUTINE_UV=PATH
# (a uv already on this machine), ROUTINE_INSTALL_TEST=1 (let it run off a Mac, to test).
set -euo pipefail
REPO_URL="https://git.autonomic.zone/trav/routine"
ARCHIVE="${ROUTINE_ARCHIVE:-$REPO_URL/archive/main.tar.gz}"
UV_VERSION="0.10.4"
PYTHON_VERSION="3.13"
PINS=(PySide6-Essentials==6.11.0) # macOS 13 (Ventura) or newer; Apple silicon and Intel
MIN_MACOS=13
SUPPORT="$HOME/Library/Application Support"
APPDIR="$SUPPORT/Routine-app"
DATA_DIR="$SUPPORT/Routine"
LOGS="$HOME/Library/Logs/Routine"
say() { printf '%s\n' "$*"; }
die() { printf '\nRoutine installer: %s\n' "$*" >&2; exit 1; }
if [ -n "${ROUTINE_APPS_DIR:-}" ]; then
APPS="$ROUTINE_APPS_DIR"
elif [ -w /Applications ]; then
APPS=/Applications
else
APPS="$HOME/Applications"
fi
BUNDLE="$APPS/Routine.app"
uninstall() {
for b in "$BUNDLE" /Applications/Routine.app "$HOME/Applications/Routine.app"; do
if [ -f "$b/Contents/Resources/routine-installer" ]; then # only a Routine.app this script made
rm -rf "$b"
say "Removed $b"
fi
done
rm -rf "$APPDIR"
say "Routine is removed."
say "Your routine, history and settings are still in $DATA_DIR"
say "(or wherever Settings → Data put them), and error logs in $LOGS."
say "Delete those folders yourself if you want them gone."
}
case "${1:-}" in
--uninstall|uninstall) uninstall; exit 0 ;;
-h|--help) say "See the comments at the top of install-mac.sh."; exit 0 ;;
"") ;;
*) die "unknown option $1 (try --uninstall)" ;;
esac
if [ "$(uname -s)" != Darwin ] && [ "${ROUTINE_INSTALL_TEST:-}" != 1 ]; then
die "this is the Mac installer; on Linux use install-linux.sh"
fi
if [ "$(uname -s)" = Darwin ]; then
v="$(sw_vers -productVersion 2>/dev/null || echo 0)"
[ "${v%%.*}" -ge "$MIN_MACOS" ] 2>/dev/null ||
die "Routine needs macOS $MIN_MACOS (Ventura) or newer; this Mac has macOS $v."
fi
for c in curl tar; do command -v "$c" >/dev/null || die "needs $c"; done
say "Installing Routine into $APPDIR"
mkdir -p "$APPDIR" "$LOGS"
# ── 1. The app itself ──
NEW="$APPDIR/src.new"
rm -rf "$NEW"
mkdir -p "$NEW"
SRC="${ROUTINE_SOURCE:-}"
if [ -z "$SRC" ]; then # run from a checkout (not through a pipe)? install that
here="$(dirname "${BASH_SOURCE[0]:-/nonexistent}")"
[ -f "$here/routine/__init__.py" ] && SRC="$(cd "$here" && pwd)"
fi
if [ -n "$SRC" ] && [ -d "$SRC" ]; then
say "Copying Routine from $SRC …"
tar -C "$SRC" --exclude=.git --exclude=__pycache__ --exclude=android -cf - . | tar -C "$NEW" -xf -
elif [ -n "$SRC" ]; then
tar -C "$NEW" --strip-components=1 -xzf "$SRC"
else
say "Downloading Routine …"
curl -fsSL "$ARCHIVE" | tar -C "$NEW" --strip-components=1 -xzf - || die "couldn't download $ARCHIVE"
fi
[ -f "$NEW/routine/__init__.py" ] || die "that doesn't look like Routine (no routine/__init__.py)"
rm -rf "$NEW/android" # the Rabbit R1 app: not used on a Mac (yet)
VERSION="$(sed -n 's/^__version__ = "\(.*\)"/\1/p' "$NEW/routine/__init__.py")"
rm -rf "$APPDIR/src.old"
[ -d "$APPDIR/src" ] && mv "$APPDIR/src" "$APPDIR/src.old"
mv "$NEW" "$APPDIR/src"
rm -rf "$APPDIR/src.old"
# ── 2. uv, then Python and PySide6, all inside APPDIR ──
export UV_PYTHON_INSTALL_DIR="$APPDIR/python"
export UV_CACHE_DIR="$APPDIR/cache"
export UV_PYTHON_PREFERENCE=only-managed # its own Python: never the system's or Homebrew's
export UV_NO_CONFIG=1
UV="${ROUTINE_UV:-$APPDIR/uv/uv}"
if [ ! -x "$UV" ] || ! "$UV" --version 2>/dev/null | grep -q " $UV_VERSION"; then
if [ -z "${ROUTINE_UV:-}" ]; then
say "Downloading uv $UV_VERSION (it fetches Python and Qt) …"
rm -rf "$APPDIR/uv"
curl -LsSf "https://astral.sh/uv/$UV_VERSION/install.sh" |
env UV_UNMANAGED_INSTALL="$APPDIR/uv" INSTALLER_NO_MODIFY_PATH=1 sh >/dev/null ||
die "couldn't download uv from astral.sh"
fi
fi
[ -x "$UV" ] || die "uv isn't at $UV"
if [ ! -x "$APPDIR/venv/bin/python" ]; then
say "Downloading Python $PYTHON_VERSION …"
"$UV" venv --quiet --python "$PYTHON_VERSION" "$APPDIR/venv" || die "couldn't set up Python"
fi
say "Installing ${PINS[*]} (the first time this is a big download) …"
"$UV" pip install --quiet --python "$APPDIR/venv/bin/python" "${PINS[@]}" || die "couldn't install ${PINS[*]}"
rm -rf "$APPDIR/cache"
(cd "$APPDIR/src" && "$APPDIR/venv/bin/python" -c 'import routine.qt.QtWidgets') ||
die "Qt for Python won't start (see the message above)"
# ── 3. Routine.app: a small bundle whose program starts the app above ──
say "Making $BUNDLE …"
mkdir -p "$APPS"
TMPB="$APPS/.Routine.app.new"
rm -rf "$TMPB"
mkdir -p "$TMPB/Contents/MacOS" "$TMPB/Contents/Resources"
cp "$APPDIR/src/shared/icon.icns" "$TMPB/Contents/Resources/Routine.icns"
printf 'Made by install-mac.sh; run it again to update, or with --uninstall to remove.\n' \
>"$TMPB/Contents/Resources/routine-installer"
cat >"$TMPB/Contents/Info.plist" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key><string>Routine</string>
<key>CFBundleDisplayName</key><string>Routine</string>
<key>CFBundleIdentifier</key><string>me.teafry.routine</string>
<key>CFBundleExecutable</key><string>Routine</string>
<key>CFBundleIconFile</key><string>Routine</string>
<key>CFBundlePackageType</key><string>APPL</string>
<key>CFBundleShortVersionString</key><string>$VERSION</string>
<key>CFBundleVersion</key><string>$VERSION</string>
<key>LSMinimumSystemVersion</key><string>$MIN_MACOS.0</string>
<key>LSApplicationCategoryType</key><string>public.app-category.productivity</string>
<key>NSHighResolutionCapable</key><true/>
<key>NSSupportsAutomaticGraphicsSwitching</key><true/>
</dict>
</plist>
EOF
# The program: bash, so no compiler is needed. exec keeps one process, so the Dock shows Routine.
cat >"$TMPB/Contents/MacOS/Routine" <<EOF
#!/bin/bash
# Starts Routine from $APPDIR (made by install-mac.sh).
APP="$APPDIR"
LOGS="$LOGS"
mkdir -p "\$LOGS"
if [ ! -x "\$APP/venv/bin/python" ] || [ ! -d "\$APP/src/routine" ]; then
/usr/bin/osascript -e 'display alert "Routine isn’t fully installed" message "Run the installer again (see the README)."' >/dev/null 2>&1
exit 1
fi
cd "\$APP/src" || exit 1
exec "\$APP/venv/bin/python" -m routine 2>"\$LOGS/launch.log"
EOF
chmod +x "$TMPB/Contents/MacOS/Routine"
rm -rf "$BUNDLE"
mv "$TMPB" "$BUNDLE"
if [ "$(uname -s)" = Darwin ]; then
xattr -dr com.apple.quarantine "$BUNDLE" 2>/dev/null || true
touch "$BUNDLE"
LSREG=/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister
[ -x "$LSREG" ] && "$LSREG" -f "$BUNDLE" >/dev/null 2>&1 || true # the Dock / Launchpad see it now
fi
say ""
say "Routine $VERSION is installed: $BUNDLE"
say "Open it from Launchpad, Spotlight (⌘ Space, type Routine) or the Applications folder;"
say "to keep it in the Dock, right-click its Dock icon → Options → Keep in Dock."
say "Update: run the same command again. Remove: … | bash -s -- --uninstall (your data stays)."
say "Your routine and history will be kept in $DATA_DIR"