commit 0106daafc5e6ceb194ecfdd1285edf76bdf9c855
parent 12db7c5de690a7faccffccb17063b3495643c5e0
Author: Michael Camilleri <[email protected]>
Date: Tue, 20 Oct 2026 08:46:14 +0900
Add a script to install builds on the iPhone over Tailscale
Xcode finds a device for wireless debugging over Bonjour, which doesn't
cross a tailnet, so once the iPhone leaves the local network a new build
can't be sent to it. This commit adds Scripts/deploy-ota.sh, which
archives the app, exports a development-signed IPA and serves it for an
over-the-air install. The user opens the Mac's .ts.net address in Safari
on the iPhone and taps 'Install'.
iOS installs over the air only from an HTTPS address with a valid
certificate, which `tailscale serve` provides for the Mac's tailnet
name, so the build is reachable from anywhere on the tailnet and from
nowhere else. The export keeps development signing so the build will
use the same CloudKit environment as builds run from Xcode.
The site is served by Scripts/ota-server.swift, a small server on
127.0.0.1 that answers only for the install page, the manifest and the
IPA. It logs each request and exits shortly after the IPA has been sent
in full, and the script then removes the Tailscale serve config, so
nothing stays exposed. Passing --skip-build serves the last build again.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat
| A | Scripts/deploy-ota.sh | | | 162 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | Scripts/ota-server.swift | | | 106 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 268 insertions(+), 0 deletions(-)
diff --git a/Scripts/deploy-ota.sh b/Scripts/deploy-ota.sh
@@ -0,0 +1,162 @@
+#!/bin/bash
+# Builds a development-signed Reportage IPA and serves it over Tailscale so an
+# iPhone on the tailnet can install it from Safari, wherever it is.
+#
+# Usage: bash Scripts/deploy-ota.sh [--skip-build]
+#
+# The iPhone must be registered with the team (it is if the app has been run
+# on it from Xcode). Serving stops when the script is interrupted.
+set -euo pipefail
+
+cd "$(dirname "${BASH_SOURCE[0]}")/.."
+
+SKIP_BUILD=false
+if [[ "${1:-}" == "--skip-build" ]]; then
+ SKIP_BUILD=true
+fi
+
+TEAM_ID="7TD7PZBNXP"
+BUNDLE_ID="net.inqk.reportage"
+PORT="${OTA_PORT:-8787}"
+OTA_DIR="$(pwd)/.cache/ota"
+ARCHIVE="${OTA_DIR}/Reportage.xcarchive"
+SITE="${OTA_DIR}/site"
+
+if command -v tailscale &>/dev/null; then
+ TAILSCALE="tailscale"
+else
+ TAILSCALE="/Applications/Tailscale.app/Contents/MacOS/Tailscale"
+fi
+
+HOST="$("$TAILSCALE" status --json | plutil -extract Self.DNSName raw -o - -)"
+HOST="${HOST%.}"
+BASE_URL="https://${HOST}"
+
+if [[ "$SKIP_BUILD" == false ]]; then
+ rm -rf "$OTA_DIR"
+ mkdir -p "$SITE"
+
+ echo "==> Archiving"
+ xcodebuild archive \
+ -scheme "Reportage" \
+ -project "Reportage.xcodeproj" \
+ -configuration Release \
+ -destination "generic/platform=iOS" \
+ -archivePath "$ARCHIVE" \
+ -allowProvisioningUpdates \
+ -quiet
+
+ # Development signing keeps the build on the CloudKit Development
+ # environment, the same one builds run from Xcode use.
+ cat > "${OTA_DIR}/ExportOptions.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>method</key>
+ <string>debugging</string>
+ <key>teamID</key>
+ <string>${TEAM_ID}</string>
+ <key>signingStyle</key>
+ <string>automatic</string>
+ <key>iCloudContainerEnvironment</key>
+ <string>Development</string>
+ <key>compileBitcode</key>
+ <false/>
+ <key>thinning</key>
+ <string><none></string>
+</dict>
+</plist>
+EOF
+
+ echo "==> Exporting IPA"
+ xcodebuild -exportArchive \
+ -archivePath "$ARCHIVE" \
+ -exportPath "${OTA_DIR}/export" \
+ -exportOptionsPlist "${OTA_DIR}/ExportOptions.plist" \
+ -allowProvisioningUpdates \
+ -quiet
+
+ mv "${OTA_DIR}/export/Reportage.ipa" "${SITE}/Reportage.ipa"
+fi
+
+if [[ ! -f "${SITE}/Reportage.ipa" ]]; then
+ echo "No IPA at ${SITE}/Reportage.ipa; run without --skip-build first." >&2
+ exit 1
+fi
+
+APP_INFO="${ARCHIVE}/Products/Applications/Reportage.app/Info.plist"
+VERSION="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$APP_INFO")"
+BUILD="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleVersion' "$APP_INFO")"
+
+cat > "${SITE}/manifest.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>items</key>
+ <array>
+ <dict>
+ <key>assets</key>
+ <array>
+ <dict>
+ <key>kind</key>
+ <string>software-package</string>
+ <key>url</key>
+ <string>${BASE_URL}/Reportage.ipa</string>
+ </dict>
+ </array>
+ <key>metadata</key>
+ <dict>
+ <key>bundle-identifier</key>
+ <string>${BUNDLE_ID}</string>
+ <key>bundle-version</key>
+ <string>${VERSION}</string>
+ <key>kind</key>
+ <string>software</string>
+ <key>title</key>
+ <string>Reportage</string>
+ </dict>
+ </dict>
+ </array>
+</dict>
+</plist>
+EOF
+
+INSTALL_URL="itms-services://?action=download-manifest&url=${BASE_URL}/manifest.plist"
+
+cat > "${SITE}/index.html" <<EOF
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Install Reportage</title>
+<style>
+ body { font: -apple-system-body; font-family: -apple-system, sans-serif; margin: 3em 1.5em; text-align: center; }
+ a { display: inline-block; padding: 0.8em 1.6em; border-radius: 0.6em; background: #007aff; color: #fff; text-decoration: none; font-weight: 600; }
+ p { color: #888; }
+</style>
+</head>
+<body>
+<h1>Reportage</h1>
+<p>${VERSION} (${BUILD})</p>
+<a href="${INSTALL_URL}">Install</a>
+</body>
+</html>
+EOF
+
+cleanup() {
+ "$TAILSCALE" serve --https=443 off >/dev/null 2>&1 || true
+}
+trap cleanup EXIT
+
+"$TAILSCALE" serve --bg --https=443 "http://127.0.0.1:${PORT}" >/dev/null
+
+echo
+echo "==> Reportage ${VERSION} (${BUILD})"
+echo " Open ${BASE_URL}/ in Safari on the iPhone and tap Install."
+echo " Serving stops once the IPA has been downloaded (or on Ctrl-C)."
+echo
+
+xcrun swift Scripts/ota-server.swift "$SITE" "$PORT"
diff --git a/Scripts/ota-server.swift b/Scripts/ota-server.swift
@@ -0,0 +1,106 @@
+// Serves the OTA install site on 127.0.0.1 for deploy-ota.sh and exits once
+// the IPA has been sent in full.
+//
+// Usage: swift Scripts/ota-server.swift <site-dir> <port>
+import Foundation
+import Network
+
+let arguments = CommandLine.arguments
+guard arguments.count == 3, let portNumber = UInt16(arguments[2]),
+ let port = NWEndpoint.Port(rawValue: portNumber) else {
+ FileHandle.standardError.write(Data("usage: ota-server.swift <site-dir> <port>\n".utf8))
+ exit(2)
+}
+let site = URL(fileURLWithPath: arguments[1], isDirectory: true)
+
+// Only these files are served; anything else is a 404.
+let contentTypes = [
+ "index.html": "text/html; charset=utf-8",
+ "manifest.plist": "text/xml",
+ "Reportage.ipa": "application/octet-stream",
+]
+
+func log(_ message: String) {
+ let time = Date.now.formatted(.dateTime.hour(.twoDigits(amPM: .omitted)).minute().second())
+ print(" \(time) \(message)")
+ fflush(stdout)
+}
+
+func respond(on connection: NWConnection, to request: String) {
+ let parts = request.split(separator: " ")
+ guard parts.count >= 2 else {
+ connection.cancel()
+ return
+ }
+ let method = String(parts[0])
+ var path = String(parts[1].split(separator: "?", maxSplits: 1).first ?? "/")
+ if path == "/" { path = "/index.html" }
+ let name = String(path.dropFirst())
+
+ var status = "404 Not Found"
+ var contentType = "text/plain"
+ var body = Data("Not found\n".utf8)
+ if method != "GET" && method != "HEAD" {
+ status = "405 Method Not Allowed"
+ body = Data("Method not allowed\n".utf8)
+ } else if let type = contentTypes[name],
+ let data = try? Data(contentsOf: site.appendingPathComponent(name)) {
+ status = "200 OK"
+ contentType = type
+ body = data
+ }
+
+ let head = "HTTP/1.1 \(status)\r\n"
+ + "Content-Type: \(contentType)\r\n"
+ + "Content-Length: \(body.count)\r\n"
+ + "Connection: close\r\n\r\n"
+ var payload = Data(head.utf8)
+ if method != "HEAD" { payload.append(body) }
+
+ log("\(method) \(path) \(status.prefix(3))")
+ connection.send(content: payload, completion: .contentProcessed { error in
+ connection.cancel()
+ guard error == nil, method == "GET", name == "Reportage.ipa", status.hasPrefix("200") else { return }
+ print("==> IPA downloaded; shutting down")
+ fflush(stdout)
+ // Give Tailscale a moment to finish relaying the IPA to the phone.
+ DispatchQueue.main.asyncAfter(deadline: .now() + 5) { exit(0) }
+ })
+}
+
+func receiveRequest(on connection: NWConnection, buffer: Data = Data()) {
+ connection.receive(minimumIncompleteLength: 1, maximumLength: 65_536) { data, _, isComplete, error in
+ var buffer = buffer
+ if let data { buffer.append(data) }
+ if let end = buffer.range(of: Data("\r\n\r\n".utf8)) {
+ let header = String(decoding: buffer[..<end.lowerBound], as: UTF8.self)
+ respond(on: connection, to: String(header.prefix { $0 != "\r" }))
+ } else if isComplete || error != nil || buffer.count > 65_536 {
+ connection.cancel()
+ } else {
+ receiveRequest(on: connection, buffer: buffer)
+ }
+ }
+}
+
+let parameters = NWParameters.tcp
+parameters.requiredLocalEndpoint = .hostPort(host: "127.0.0.1", port: port)
+let listener: NWListener
+do {
+ listener = try NWListener(using: parameters)
+} catch {
+ FileHandle.standardError.write(Data("Could not listen on port \(portNumber): \(error)\n".utf8))
+ exit(1)
+}
+listener.stateUpdateHandler = { state in
+ if case .failed(let error) = state {
+ FileHandle.standardError.write(Data("Listener failed: \(error)\n".utf8))
+ exit(1)
+ }
+}
+listener.newConnectionHandler = { connection in
+ connection.start(queue: .main)
+ receiveRequest(on: connection)
+}
+listener.start(queue: .main)
+dispatchMain()