Files
connector-macos/configure.d/lib/nextcloud.sh
T
davidandClaude Opus 5.5 08e6b2ee4f 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>
2026-11-11 08:34:42 -07:00

71 lines
2.6 KiB
Bash

#!/bin/bash
#
# Purpose : Nextcloud app passwords for configure.d items, and keeping them in
# your login keychain. Source this file after lib/json.sh
# and lib/keychain.sh.
KEYCHAIN_SERVICE="Federated Connector"
# Basic auth header for curl, read from stdin (-H @-) so the password isn't
# in the process list (printf is a shell builtin)
auth_header() {
printf 'Authorization: Basic %s\n' "$(printf '%s:%s' "$1" "$2" | base64 | tr -d '\n')"
}
# Create a Nextcloud app password, so this Mac doesn't keep your Core
# password for Calendar and Contacts. It shows in Nextcloud under Settings >
# Security with the name given, where it can be revoked. Uses CORE_USER,
# PASSWORD and NEXTCLOUD; sets APP_PASSWORD. Returns 2 if Nextcloud says the
# password is wrong.
nextcloud_app_password() {
local name="$1" response code
response="$(auth_header "$CORE_USER" "$PASSWORD" | curl -s --max-time 30 -w '\n%{http_code}' -H @- \
-H 'OCS-APIRequest: true' -A "$name" \
"$NEXTCLOUD/ocs/v2.php/core/getapppassword?format=json")"
code="${response##*$'\n'}"
case "$code" in
200) APP_PASSWORD="$(json_get 'd.ocs.data.apppassword' <<< "${response%$'\n'*}")"
[ -n "$APP_PASSWORD" ] ;;
401) return 2 ;;
*) return 1 ;;
esac
}
# Revoke an app password, signing in with it. Uses CORE_USER and NEXTCLOUD.
nextcloud_revoke_app_password() {
auth_header "$CORE_USER" "$1" | curl -sf --max-time 30 -o /dev/null -X DELETE -H @- \
-H 'OCS-APIRequest: true' "$NEXTCLOUD/ocs/v2.php/core/apppassword"
}
# Sign in to Nextcloud as CORE_USER with a password ($1), or PASSWORD if not
# given. Signing in with your Core password (not an app password) also turns
# back on the app passwords Nextcloud turned off when the Core password
# changed. Uses NEXTCLOUD. Returns 2 if Nextcloud says the password is wrong.
nextcloud_sign_in() {
local code
code="$(auth_header "$CORE_USER" "${1:-$PASSWORD}" | curl -s --max-time 30 -o /dev/null -w '%{http_code}' -H @- \
-H 'OCS-APIRequest: true' "$NEXTCLOUD/ocs/v2.php/cloud/user?format=json")"
case "$code" in
200) return 0 ;;
401) return 2 ;;
*) return 1 ;;
esac
}
# The app password this Mac gave Calendar and Contacts is kept in your login
# keychain too, so it can be put in the profile again (e.g. when your Core
# password changes) without making another, and revoked when you remove the
# Core. Uses KEYCHAIN_ACCOUNT.
app_password_load() {
keychain_load "$KEYCHAIN_SERVICE" "$KEYCHAIN_ACCOUNT"
}
app_password_save() {
keychain_save "$KEYCHAIN_SERVICE" "$KEYCHAIN_ACCOUNT" "$1"
}
app_password_delete() {
keychain_delete "$KEYCHAIN_SERVICE" "$KEYCHAIN_ACCOUNT"
}