Add an installer and update command

curl -fsSL https://federated.sh/mac | bash

install.sh checks the Mac (macOS 13+, not root, internet; warns if the
account isn't an administrator), then downloads the latest commit as an
archive from Gitea, as macOS has no git without the Command Line Tools.
It installs into ~/.local/share/federated-connector/connector, links
configure and update into ~/.local/bin and puts that on PATH at the top
of ~/.zprofile and ~/.bash_profile, then offers to run configure. Piped
into bash, it runs only once read in full, and asks from /dev/tty.

The folder never moves, so the backup and storage jobs and the Federated
Backup app (with its Full Disk Access) keep pointing at it. update shows
the commits since the installed one and swaps the new files in with two
renames.

If configure ran from another folder before, the installer says what
still runs from there; backup and storage now show as to do until
they're set up again from the installed copy.

smoketest: 05-install pipes install.sh into bash with the working copy,
runs update, then installs the published version from Gitea.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 09:21:17 -07:00
co-authored by Claude Opus 5.5
parent 8e2a886215
commit f92dbcb3bd
8 changed files with 398 additions and 13 deletions
+39 -8
View File
@@ -7,15 +7,45 @@ Sets up a Mac for your Federated Core, using the apps macOS comes with: Mail, Ca
- macOS 13 (Ventura) or later, on Apple silicon or Intel.
- Nothing else. It runs with the bash macOS comes with and only uses tools that are part of macOS. It doesn't need Homebrew, jq, python or the Command Line Tools.
## Installing
In Terminal:
```
curl -fsSL https://federated.sh/mac | bash
```
federated.sh/mac sends curl to [install.sh](install.sh) here on Gitea, so you can read what it runs first. In a browser, it opens this page.
It checks the Mac first: macOS 13 or later, not run as root, and an internet connection. It also warns if your account isn't an administrator, as some apps need your Mac password to install. Then it:
- downloads the latest version into `~/.local/share/federated-connector/connector`
- adds the `configure` and `update` commands to `~/.local/bin`
- adds `~/.local/bin` to your PATH, at the top of `~/.zprofile` and `~/.bash_profile`
- offers to run `configure`
It doesn't need git, which macOS doesn't have without the Command Line Tools. Running it again reinstalls the latest version. The log is in `~/Library/Logs/Federated Connector/`.
The install's folder never moves. That matters because the backup and network storage jobs, and the Federated Backup app you give Full Disk Access, point into it.
## Running it
```
./configure # show what's set up and choose what to set up
./configure core # set up one item
./configure --list # show what's set up, and the item names
configure # show what's set up and choose what to set up
configure core # set up one item
configure --list # show what's set up, and the item names
```
To run it as just `configure`, link it into a directory on your PATH, e.g. `ln -s "$PWD/configure" /usr/local/bin/configure`.
## Updating
```
update # get the latest version, showing what changed
update --version # the version installed
```
`update` downloads the latest version and swaps it in at once, so it's safe while backups run. Your settings, the profiles, keychain items and downloaded tools stay as they are, and the Federated Backup app keeps its Full Disk Access.
If you ran `configure` from a downloaded folder before installing, the installer tells you what still runs from there. Run `configure` again: backup, storage and agents show as to do until they've moved. Backups then need Full Disk Access again, as the app is made anew.
## What it sets up
@@ -67,7 +97,7 @@ To allow more, put a file in the same format as `sandbox/config/base.json` in `~
To see the backups and get files back:
```
source system/backup-env.sh
source ~/.local/share/federated-connector/connector/system/backup-env.sh
restic snapshots
restic restore latest --target ~/restored --include ~/Documents
```
@@ -75,7 +105,7 @@ restic restore latest --target ~/restored --include ~/Documents
On a new Mac, run `configure core` and `configure backup` first. Then name the old Mac's folder, and restic asks for the passphrase you saved:
```
source system/backup-env.sh .backup-{old Mac's name}
source ~/.local/share/federated-connector/connector/system/backup-env.sh .backup-{old Mac's name}
restic snapshots
```
@@ -109,7 +139,8 @@ The agents are installed with their makers' own installers: claude.ai/install.sh
- Your answers: `~/Library/Application Support/Federated Connector/` (`cores/<domain>.conf`, `core.conf` for the main Core, `tailscale.conf`, `backup.conf`, `storage`, `ai-servers`, and your own `sandbox/` config)
- App passwords and the backup passphrase: login keychain, services "Federated Connector" and "federated-connector-backup"
- Background jobs: `~/Library/LaunchAgents/computer.federated.connector.{backup,storage}.plist`
- Downloaded tools: `~/.local/share/federated-connector`
- Federated Connector itself: `~/.local/share/federated-connector/connector`, with `configure` and `update` linked in `~/.local/bin`
- Downloaded tools: `~/.local/share/federated-connector` (`bin`, `node`, `srt`)
- The accounts: System Settings > Privacy & Security > Profiles (General > Device Management on some versions)
## Adding an item
@@ -132,7 +163,7 @@ Keep to bash 3.2: no `mapfile`, `read -i`, associative arrays or `${var,,}`.
## Testing
`smoketest/run` runs the scenarios in `smoketest/`, each in a fresh macOS VM, with Tart on an Apple silicon Mac. See [smoketest/README.md](smoketest/README.md).
`smoketest/run` (with `05-install` for the installer) runs the scenarios in `smoketest/`, each in a fresh macOS VM, with Tart on an Apple silicon Mac. See [smoketest/README.md](smoketest/README.md).
## Differences from CoreDesktop
+4 -2
View File
@@ -33,9 +33,11 @@ backups_on() {
[ -n "$RESTIC_PASSWORD_COMMAND" ] && job_loaded
}
# Done when backing up to the main Core
# Done when backing up to the main Core, with the app running this copy's
# script (not one in a folder configure ran from before it was installed)
is_configured() {
backups_on && [ "$BACKUP_WEBDAV" = "https://nextcloud.$CORE_DOMAIN/remote.php/dav/files/${CORE_EMAIL%@*}" ]
backups_on && [ "$BACKUP_WEBDAV" = "https://nextcloud.$CORE_DOMAIN/remote.php/dav/files/${CORE_EMAIL%@*}" ] \
&& backup_app_current
}
save_secret() {
+10 -1
View File
@@ -20,8 +20,14 @@ source "$CONNECTOR/configure.d/lib/mdns.sh"
source "$CONNECTOR/configure.d/lib/smb.sh"
source "$CONNECTOR/configure.d/lib/sftp.sh"
# The job runs this copy's storage-mount, not one in a folder configure ran
# from before it was installed
job_current() {
[ ! -f "$PLIST" ] || grep -qF "<string>$(xml_escape "$STORAGE_MOUNT")</string>" "$PLIST"
}
is_configured() {
[ -f "$STORAGE_CONF" ]
[ -f "$STORAGE_CONF" ] && job_current
}
# launchd runs system/storage-mount at login and whenever the network changes
@@ -287,6 +293,9 @@ choose_and_remove() {
run_configure() {
local choice url point
mkdir -p "$(dirname "$STORAGE_CONF")" && touch "$STORAGE_CONF" || return 1
if ! job_current; then
install_job && echo "Shared folders are now mounted again at login by this copy ($CONNECTOR)."
fi
echo "This mounts shared folders from other machines on your network and mounts them"
echo "again each time you log in: SMB shares (Windows PCs, NAS boxes, Macs with File"
echo "Sharing on) and, over SSH, any machine you can ssh to."
Executable
+241
View File
@@ -0,0 +1,241 @@
#!/bin/bash
#
# Purpose : Install Federated Connector for macOS, or update it (`update`
# runs this with --update).
#
# curl -fsSL https://federated.sh/mac | bash
#
# macOS has no git (its git asks to install the Command Line Tools), so this
# downloads an archive of the latest commit from Gitea, puts it in
# ~/.local/share/federated-connector/connector, and records the commit. The
# place never changes, which matters: the backup and network storage jobs,
# and the Federated Backup app you give Full Disk Access, point into it. An
# update swaps the new files in at once.
#
# It also puts `configure` and `update` in ~/.local/bin, and that on your
# PATH, then offers to run configure.
#
# Usage: install.sh [--update]
#
# FEDERATED_CONNECTOR_SOURCE=<folder> installs from that folder instead of
# Gitea (the smoketest uses it to install the working copy).
# Piped into bash, the script is read as it runs; main at the end runs it
# only once bash has read it all. Questions are read from the terminal, as
# stdin is the script.
set -o pipefail
REPO_URL="https://gitea.federated.computer/Federated_Computer/connector-macos"
API_URL="https://gitea.federated.computer/api/v1/repos/Federated_Computer/connector-macos"
BRANCH=main
BASE="$HOME/.local/share/federated-connector"
CONNECTOR="$BASE/connector"
VERSION_FILE="$CONNECTOR/.version"
BIN="$HOME/.local/bin"
LOG_DIR="$HOME/Library/Logs/Federated Connector"
CONF_DIR="$HOME/Library/Application Support/Federated Connector"
BLOCK_START="# >>> Federated Connector commands >>>"
BLOCK_END="# <<< Federated Connector commands <<<"
RED=$'\033[31m' GREEN=$'\033[32m' YELLOW=$'\033[33m' BOLD=$'\033[1m' RESET=$'\033[0m'
say() {
echo "$BOLD$*$RESET"
}
fail() {
echo "$RED$*$RESET"
exit 1
}
# Questions come from the terminal; without one (e.g. in a script), the
# answer is no
has_tty() {
{ : < /dev/tty; } 2> /dev/null
}
confirm_yes() {
local answer
has_tty || return 1
read -rp "$1 [Y/n] " answer < /dev/tty
[[ "$answer" != [nN]* ]]
}
# What can't be fixed from here, checked before anything changes
preflight() {
local major
[ "$(uname -s)" = Darwin ] || fail "This is for macOS. On Linux, use CoreDesktop: https://federated.sh"
major="$(sw_vers -productVersion | cut -d. -f1)"
[ "$major" -ge 13 ] 2> /dev/null || fail "This needs macOS 13 (Ventura) or later; this Mac has $(sw_vers -productVersion)."
[ "$(id -u)" -ne 0 ] || fail "Run this as yourself, not as root. It asks for your password when it needs it."
if ! id -Gn | tr ' ' '\n' | grep -qx admin; then
echo "${YELLOW}Your account isn't an administrator, so apps that need installing with your"
echo "Mac password (Nextcloud, Tailscale, macFUSE) can't be installed. The rest works.$RESET"
fi
if [ -z "$FEDERATED_CONNECTOR_SOURCE" ] && ! curl -fsS --max-time 15 -o /dev/null "$API_URL"; then
fail "Couldn't reach Gitea ($REPO_URL). Connect to the internet and run this again."
fi
}
installed_version() {
cat "$VERSION_FILE" 2> /dev/null
}
# The commit main is at now
latest_version() {
if [ -n "$FEDERATED_CONNECTOR_SOURCE" ]; then
echo local
else
curl -fsS --max-time 30 "$API_URL/branches/$BRANCH" | plutil -extract commit.id raw -o - - 2> /dev/null
fi
}
# The commits between the installed version and the new one: "short subject"
changes_since() {
[ -n "$1" ] && [ "$1" != local ] && [ "$2" != local ] || return 0
curl -fsS --max-time 30 "$API_URL/commits?sha=$2&limit=50&stat=false&verification=false&files=false" \
| osascript -l JavaScript -e '
function run(argv) {
ObjC.import("Foundation");
var data = $.NSFileHandle.fileHandleWithStandardInput.readDataToEndOfFile;
var commits = JSON.parse($.NSString.alloc.initWithDataEncoding(data, $.NSUTF8StringEncoding).js);
var out = [];
for (var i = 0; i < commits.length && commits[i].sha !== argv[0]; i++) {
out.push(commits[i].sha.slice(0, 7) + " " + commits[i].commit.message.split("\n")[0]);
}
return out.join("\n");
}' "$1" 2> /dev/null
}
# Put version $1 in a new folder next to CONNECTOR, then swap it in. A folder
# next to it is on the same disk, so the swap is two renames.
fetch_and_swap() {
local version="$1" staging="$BASE/.connector-new-$$" old="$BASE/.connector-old-$$"
mkdir -p "$BASE" || return 1
rm -rf "$staging"
mkdir "$staging" || return 1
if [ -n "$FEDERATED_CONNECTOR_SOURCE" ]; then
(cd "$FEDERATED_CONNECTOR_SOURCE" && COPYFILE_DISABLE=1 tar --exclude ./.git --exclude ./.claude \
--exclude ./smoketest/results -cf - .) | tar -xf - -C "$staging" || { rm -rf "$staging"; return 1; }
else
echo "Downloading ${version:0:7} from $REPO_URL"
curl -fsSL --max-time 300 "$REPO_URL/archive/$version.tar.gz" \
| tar -xzf - -C "$staging" --strip-components 1 || { rm -rf "$staging"; return 1; }
fi
[ -x "$staging/configure" ] || { echo "The download doesn't look right (no configure in it)."; rm -rf "$staging"; return 1; }
echo "$version" > "$staging/.version"
if [ -d "$CONNECTOR" ]; then
mv "$CONNECTOR" "$old" || { rm -rf "$staging"; return 1; }
fi
if ! mv "$staging" "$CONNECTOR"; then
[ -d "$old" ] && mv "$old" "$CONNECTOR"
rm -rf "$staging"
return 1
fi
rm -rf "$old"
}
# configure and update in ~/.local/bin, linked so they follow updates
link_commands() {
local name
mkdir -p "$BIN" || return 1
for name in configure update; do
ln -sfn "$CONNECTOR/$name" "$BIN/$name" || return 1
done
}
path_block() {
cat << EOF
$BLOCK_START
# configure and update: see $REPO_URL
export PATH="\$HOME/.local/bin:\$PATH"
$BLOCK_END
EOF
}
# ~/.local/bin on PATH, at the top of ~/.zprofile (zsh, macOS' shell) and
# ~/.bash_profile (bash), so what comes later in them, e.g. the agent
# sandbox's line that configure agents adds, still comes first on PATH
put_on_path() {
local file tmp changed=0
for file in "$HOME/.zprofile" "$HOME/.bash_profile"; do
grep -qxF "$BLOCK_START" "$file" 2> /dev/null && continue
tmp="$(mktemp)" || return 1
{ path_block; echo; cat "$file" 2> /dev/null || true; } > "$tmp" && cat "$tmp" > "$file"
rm -f "$tmp"
changed=1
done
[ $changed -eq 0 ] || echo "Added ~/.local/bin to your PATH (in ~/.zprofile and ~/.bash_profile)."
}
# Jobs and the sandbox set up by running configure from another folder (before
# there was an installer) still point there
point_elsewhere() {
local file found=0
for file in "$HOME/Library/LaunchAgents/computer.federated.connector."*.plist; do
[ -f "$file" ] || continue
if ! grep -qF "$CONNECTOR/" "$file" && ! grep -qF "Federated Backup.app" "$file"; then
found=1
fi
done
if [ -d "$HOME/Applications/Federated Backup.app" ] \
&& [ "$(plutil -extract FederatedBackupScript raw -o - "$HOME/Applications/Federated Backup.app/Contents/Info.plist" 2> /dev/null)" \
!= "$CONNECTOR/system/backup" ]; then
found=1
fi
grep -qs 'Federated Connector >>>' "$HOME/.zshrc" && ! grep -qsF "$CONNECTOR/sandbox/bin" "$HOME/.zshrc" && found=1
if [ $found -eq 1 ]; then
echo
echo "${YELLOW}Some of what configure set up runs from the folder you used before. To move it"
echo "here, run configure again and choose backup, storage and agents (it shows them as"
echo "to do). Backups then need Full Disk Access again.$RESET"
fi
}
main() {
local update=0 installed latest log
[ "$1" = --update ] && update=1
mkdir -p "$LOG_DIR" && log="$LOG_DIR/$([ $update -eq 1 ] && echo update || echo install)-$(date +%Y-%m-%d-%H%M%S).log"
[ -n "$log" ] && exec > >(tee -a "$log") 2>&1
if [ $update -eq 0 ]; then
echo
say "Federated Connector for macOS"
echo "Sets up this Mac for your Federated Core: Mail, Calendar, Contacts, files,"
echo "backups, shared folders and AI agents."
echo
fi
preflight
installed="$(installed_version)"
latest="$(latest_version)" || fail "Couldn't find the latest version on Gitea."
[ -n "$latest" ] || fail "Couldn't find the latest version on Gitea."
if [ $update -eq 1 ] && [ "$installed" = "$latest" ] && [ "$latest" != local ]; then
echo "Federated Connector is up to date (${latest:0:7})."
return 0
fi
if [ $update -eq 1 ] && [ -n "$installed" ]; then
say "Updating Federated Connector from ${installed:0:7} to ${latest:0:7}"
changes_since "$installed" "$latest" | sed 's/^/ /'
fi
fetch_and_swap "$latest" || fail "Couldn't install Federated Connector."
link_commands || fail "Couldn't put configure and update in $BIN."
put_on_path
point_elsewhere
echo
if [ $update -eq 1 ]; then
echo "${GREEN}Federated Connector is up to date (${latest:0:7}).$RESET"
return 0
fi
echo "${GREEN}Federated Connector is installed in $CONNECTOR.$RESET"
echo "In a new Terminal window, run: configure (and later, to get new versions: update)"
if confirm_yes "Run configure now?"; then
"$CONNECTOR/configure" < /dev/tty
fi
}
main "$@"
exit
+1
View File
@@ -49,6 +49,7 @@ Each scenario runs on a fresh clone of Cirrus Labs' **vanilla** macOS image (def
| Scenario | Checks |
|----------|--------|
| `00-environment` | Every script parses with `/bin/bash` 3.2. None uses a tool macOS lacks: no python3, which would start installing the Command Line Tools, and no jq, timeout or mapfile. The macOS tools used are all there. |
| `05-install` | `install.sh` piped into bash, as `curl \| bash` runs it, with the working copy. The commands are in `~/.local/bin` and a login zsh finds them, and `update` swaps in a fresh copy without leaving staging folders behind. Then the published version installs from Gitea, records its commit, and `update` says it is up to date. |
| `10-configure` | `configure --help`, `--list` (nothing on stderr; agent sign-ins hidden until installed), the menu, and an item's questions |
| `20-json-keychain` | `json_get` and `json_edit` through real `osascript`; saving, replacing and deleting keychain secrets |
| `30-core-local` | The profile: valid, passwords and names survive escaping, stable payload UUIDs, and the format of `profiles show -output stdout-xml`. Superpanel's app: built, re-signed after the icon changes, and it opens. Element's config, and `nextcloud.cfg` matching |
+2 -2
View File
@@ -3,14 +3,14 @@ DESCRIPTION="The scripts parse with macOS' bash 3.2, and the macOS tools they us
TIER=quick
# Patterns, expanded in CONNECTOR
SCRIPTS=("configure" "configure.d/*.sh" "configure.d/lib/*.sh" "system/backup" "system/backup-env.sh"
SCRIPTS=("configure" "install.sh" "update" "configure.d/*.sh" "configure.d/lib/*.sh" "system/backup" "system/backup-env.sh"
"system/storage-mount" "sandbox/agent" "smoketest/run" "smoketest/lib/runner.sh")
# Commands that macOS doesn't have, or that would start installing the
# Command Line Tools if called (python3), outside comments
uses_missing_tools() {
(cd "$CONNECTOR" && grep -nE '(^|[^#[:alnum:]_-])(python3|jq|gsed|gawk|timeout|realpath|mapfile|readarray|declare -A)([^[:alnum:]_-]|$)' \
configure configure.d/*.sh configure.d/lib/*.sh system/backup system/storage-mount sandbox/agent \
configure install.sh update configure.d/*.sh configure.d/lib/*.sh system/backup system/storage-mount sandbox/agent \
| grep -vE ':[[:space:]]*#')
}
+51
View File
@@ -0,0 +1,51 @@
# shellcheck shell=bash
DESCRIPTION="install.sh piped into bash, then update: the working copy, then the real one from Gitea"
TIER=quick
INSTALLED="$HOME/.local/share/federated-connector/connector"
RAW="https://gitea.federated.computer/Federated_Computer/connector-macos/raw/branch/main/install.sh"
# As `curl ... | bash` runs it: the script on stdin, no terminal to answer
# questions (so it doesn't offer to run configure)
install_piped() {
cat "$1" | /bin/bash
}
login_zsh_finds() {
[ "$(zsh -lc "command -v $1" 2> /dev/null)" = "$HOME/.local/bin/$1" ]
}
lists_from_installed() {
zsh -lc 'configure --list' < /dev/null | grep -qE '^(to do|done) +core '
}
swaps() {
touch "$INSTALLED/marker-from-before"
"$HOME/.local/bin/update" < /dev/null && [ ! -e "$INSTALLED/marker-from-before" ] || return 1
# No staging folders left over from the swap
set -- "$(dirname "$INSTALLED")"/.connector-*
[ ! -e "$1" ]
}
up_to_date() {
"$HOME/.local/bin/update" < /dev/null | grep -q 'is up to date'
}
scenario() {
step "The working copy, through install.sh"
check "install.sh, piped into bash" env FEDERATED_CONNECTOR_SOURCE="$CONNECTOR" bash -c \
"cat '$CONNECTOR/install.sh' | /bin/bash"
check "it's in ~/.local/share/federated-connector/connector" test -x "$INSTALLED/configure"
check "a login zsh finds configure in ~/.local/bin" login_zsh_finds configure
check "...and update" login_zsh_finds update
check "configure --list runs from there" lists_from_installed
check_eq "update --version" "Federated Connector local" "$("$HOME/.local/bin/update" --version)"
check "update swaps in a fresh copy and leaves nothing behind" env FEDERATED_CONNECTOR_SOURCE="$CONNECTOR" bash -c \
"$(declare -f swaps); INSTALLED='$INSTALLED'; swaps"
check_eq "the PATH lines are in ~/.zprofile once" 1 "$(grep -c 'Federated Connector commands >>>' "$HOME/.zprofile")"
step "The published version, from Gitea"
check "curl -fsSL <install.sh on Gitea> | bash" bash -c "curl -fsSL '$RAW' | /bin/bash"
check "it records the commit" grep -qE '^[0-9a-f]{40}$' "$INSTALLED/.version"
check "update says it's up to date" up_to_date
}
Executable
+50
View File
@@ -0,0 +1,50 @@
#!/bin/bash
#
# Purpose : Update Federated Connector to the latest version on Gitea.
#
# Usage: update Update, showing what changed
# update --version Show the version installed
#
# The installer does the work (install.sh --update): it downloads the new
# version and swaps it in, so the jobs and the Federated Backup app keep
# pointing at the same place. Your settings, the profiles, keychain items and
# downloaded tools are left as they are.
# Wrapped in { ...; exit; } so bash reads the whole script up front; the
# update replaces this file while it runs.
{
# This script, through the link in ~/.local/bin
self="$0"
while [ -L "$self" ]; do
link="$(readlink "$self")"
case "$link" in
/*) self="$link" ;;
*) self="$(dirname "$self")/$link" ;;
esac
done
CONNECTOR="$(cd "$(dirname "$self")" && pwd -P)"
case "$1" in
--version|-v)
echo "Federated Connector $(cut -c1-7 "$CONNECTOR/.version" 2> /dev/null || echo "(not installed with install.sh)")"
exit 0 ;;
-h|--help)
sed -n '4,6p' "$self" | sed 's/^# \{0,1\}//'
exit 0 ;;
esac
if [ ! -f "$CONNECTOR/.version" ]; then
echo "This copy wasn't installed with install.sh, so update can't replace it. Install with:"
echo " curl -fsSL https://federated.sh/mac | bash"
exit 1
fi
# Run from a copy: the update replaces install.sh along with everything else
copy="$(mktemp)" || exit 1
cp "$CONNECTOR/install.sh" "$copy" || exit 1
bash "$copy" --update
status=$?
rm -f "$copy"
exit $status
}