Set up a Mac for a Federated Core, like CoreDesktop's configure

A macOS counterpart of CoreDesktop's configure, with the same drop-in
items in configure.d/:

- core: Mail, Calendar and Contacts through a configuration profile,
  Superpanel as an app, Nextcloud files through the Nextcloud app, and
  Element; with test-and-fix, password change and removal
- tailscale: join the Core's network through headscale
- backup: restic to Nextcloud through rclone, run by launchd through an
  app that can be given Full Disk Access
- storage: SMB shares mounted the way Finder does, again at login and
  on network changes
- agents, claude, opencode, hermes, sandbox: install the agents and run
  them in Anthropic's sandbox runtime (Seatbelt on macOS)
- ai-servers: LLM servers on this Mac or the network, for the agents

Apps and tools macOS lacks are offered for download, checked against
their makers' Team IDs and notarization, or published SHA-256 sums.
Everything runs on macOS' bash 3.2 with only built-in tools.

smoketest/ runs scenarios in fresh macOS VMs with Tart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 08:34:42 -07:00
co-authored by Claude Opus 5.5
commit 08e6b2ee4f
45 changed files with 4517 additions and 0 deletions
+140
View File
@@ -0,0 +1,140 @@
#!/bin/bash
#
# Purpose : Find the apps the Core's services need that macOS doesn't come
# with, and offer to download and install them. Source this file
# after lib/json.sh; it uses confirm_yes from configure.
#
# Each app is downloaded from its maker, and installed only if it's signed
# with the maker's Developer ID (the Team ID below) and Gatekeeper accepts it
# (it's notarized by Apple). The apps update themselves after that.
#
# To check an app's Team ID on a Mac where it's installed:
# codesign -dv /Applications/<App>.app 2>&1 | grep TeamIdentifier
# app_info <name>: sets APP_TITLE, APP_BUNDLE, APP_TEAM, APP_KIND (dmg or
# pkg) and APP_URL. Nextcloud's URL changes with each release, so app_url
# looks it up.
app_info() {
case "$1" in
element)
APP_TITLE="Element" APP_BUNDLE="Element.app" APP_TEAM="7J4U792NQT" APP_KIND=dmg
APP_URL="https://packages.element.io/desktop/install/macos/Element.dmg" ;;
nextcloud)
APP_TITLE="Nextcloud" APP_BUNDLE="Nextcloud.app" APP_TEAM="NKUJUXUJ3B" APP_KIND=pkg
APP_URL="https://api.github.com/repos/nextcloud-releases/desktop/releases/latest" ;;
tailscale)
APP_TITLE="Tailscale" APP_BUNDLE="Tailscale.app" APP_TEAM="W5364U7YZB" APP_KIND=pkg
APP_URL="https://pkgs.tailscale.com/stable/Tailscale-latest-macos.pkg" ;;
*) return 1 ;;
esac
}
# Where the app is installed, if it is
app_path() {
app_info "$1" || return 1
if [ -d "/Applications/$APP_BUNDLE" ]; then
echo "/Applications/$APP_BUNDLE"
elif [ -d "$HOME/Applications/$APP_BUNDLE" ]; then
echo "$HOME/Applications/$APP_BUNDLE"
else
return 1
fi
}
app_installed() {
app_path "$1" > /dev/null
}
# The download URL for app_info's app
app_url() {
case "$APP_URL" in
https://api.github.com/*)
curl -sf --max-time 30 "$APP_URL" \
| json_get 'd.assets.map(function (x) { return x.browser_download_url; })
.filter(function (u) { return /\.pkg$/.test(u); })[0]' ;;
*) echo "$APP_URL" ;;
esac
}
# The Team ID a signed installer package or app is signed with
pkg_team() {
pkgutil --check-signature "$1" 2> /dev/null \
| sed -nE 's/^ *1\. Developer ID Installer: .*\(([A-Z0-9]{10})\)$/\1/p'
}
app_team() {
codesign -dv "$1" 2>&1 | sed -n 's/^TeamIdentifier=//p'
}
verify_team() {
local what="$1" team="$2"
if [ "$team" != "$APP_TEAM" ]; then
echo "$RED$what isn't signed by $APP_TITLE's maker (Team ID ${team:-none}, not $APP_TEAM). Not installing it.$RESET"
return 1
fi
}
# Install a downloaded .pkg, once it's checked. The installer needs admin.
install_pkg() {
local pkg="$1"
verify_team "The download" "$(pkg_team "$pkg")" || return 1
if ! spctl --assess --type install "$pkg" 2> /dev/null; then
echo "${RED}Gatekeeper doesn't accept the download (it isn't notarized). Not installing it.$RESET"
return 1
fi
echo "Installing $APP_TITLE needs your Mac password."
sudo installer -pkg "$pkg" -target / > /dev/null
}
# Copy the app out of a downloaded .dmg into /Applications, once it's checked
install_dmg() {
local dmg="$1" mount="$2/mount" app status=0
hdiutil attach -nobrowse -readonly -noautoopen -mountpoint "$mount" "$dmg" > /dev/null || return 1
app="$mount/$APP_BUNDLE"
if [ ! -d "$app" ]; then
echo "The download doesn't have $APP_BUNDLE in it."
status=1
elif ! codesign --verify --deep --strict "$app" 2> /dev/null; then
echo "$RED$APP_BUNDLE's signature doesn't check out. Not installing it.$RESET"
status=1
elif ! verify_team "$APP_BUNDLE" "$(app_team "$app")"; then
status=1
elif ! spctl --assess --type execute "$app" 2> /dev/null; then
echo "${RED}Gatekeeper doesn't accept $APP_BUNDLE (it isn't notarized). Not installing it.$RESET"
status=1
elif ! ditto "$app" "/Applications/$APP_BUNDLE" 2> /dev/null; then
echo "Copying $APP_TITLE to Applications needs your Mac password."
sudo ditto "$app" "/Applications/$APP_BUNDLE" || status=1
fi
hdiutil detach -quiet "$mount" || hdiutil detach -quiet -force "$mount"
return $status
}
# Download and install an app
app_install() {
local name="$1" url tmp status
app_info "$name" || return 1
url="$(app_url)"
[ -n "$url" ] || { echo "Couldn't find where to download $APP_TITLE."; return 1; }
tmp="$(mktemp -d)" || return 1
echo "Downloading $APP_TITLE from $url"
if curl -fL --progress-bar --max-time 1800 -o "$tmp/download.$APP_KIND" "$url"; then
"install_$APP_KIND" "$tmp/download.$APP_KIND" "$tmp"
status=$?
else
echo "Couldn't download $APP_TITLE."
status=1
fi
rm -rf "$tmp"
[ $status -eq 0 ] && app_installed "$name" || return 1
echo "Installed $APP_TITLE."
}
# app_ensure <name> <why it's needed>: offer to install the app if it's
# missing. Fails if it's still missing.
app_ensure() {
app_installed "$1" && return 0
echo "$APP_TITLE isn't on this Mac. $2"
confirm_yes "Download and install $APP_TITLE?" || return 1
app_install "$1"
}