← All repositories

reportage

A life-logging app for iPhone

git clone https://code.inqk.net/reportage.git


Scripts/deploy-ota.sh (6615B)

1#!/bin/bash
2# Builds a development-signed Reportage IPA and serves it over Tailscale so an
3# iPhone on the tailnet can install it from Safari, wherever it is.
4#
5# Usage: bash Scripts/deploy-ota.sh [--skip-build]
6#
7# The iPhone must be registered with the team (it is if the app has been run
8# on it from Xcode). Serving stops when the script is interrupted.
9set -euo pipefail
10
11cd "$(dirname "${BASH_SOURCE[0]}")/.."
12
13SKIP_BUILD=false
14if [[ "${1:-}" == "--skip-build" ]]; then
15  SKIP_BUILD=true
16fi
17
18TEAM_ID="7TD7PZBNXP"
19BUNDLE_ID="net.inqk.reportage"
20PORT="${OTA_PORT:-8787}"
21OTA_DIR="$(pwd)/.cache/ota"
22ARCHIVE="${OTA_DIR}/Reportage.xcarchive"
23SITE="${OTA_DIR}/site"
24
25if command -v tailscale &>/dev/null; then
26  TAILSCALE="tailscale"
27else
28  TAILSCALE="/Applications/Tailscale.app/Contents/MacOS/Tailscale"
29fi
30
31HOST="$("$TAILSCALE" status --json | plutil -extract Self.DNSName raw -o - -)"
32HOST="${HOST%.}"
33BASE_URL="https://${HOST}"
34
35if [[ "$SKIP_BUILD" == false ]]; then
36  rm -rf "$OTA_DIR"
37  mkdir -p "$SITE"
38
39  echo "==> Archiving"
40  xcodebuild archive \
41    -scheme "Reportage" \
42    -project "Reportage.xcodeproj" \
43    -configuration Release \
44    -destination "generic/platform=iOS" \
45    -archivePath "$ARCHIVE" \
46    -allowProvisioningUpdates \
47    -quiet
48
49  # Development signing keeps the build on the CloudKit Development
50  # environment, the same one builds run from Xcode use.
51  cat > "${OTA_DIR}/ExportOptions.plist" <<EOF
52<?xml version="1.0" encoding="UTF-8"?>
53<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
54<plist version="1.0">
55<dict>
56  <key>method</key>
57  <string>debugging</string>
58  <key>teamID</key>
59  <string>${TEAM_ID}</string>
60  <key>signingStyle</key>
61  <string>automatic</string>
62  <key>iCloudContainerEnvironment</key>
63  <string>Development</string>
64  <key>compileBitcode</key>
65  <false/>
66  <key>thinning</key>
67  <string>&lt;none&gt;</string>
68</dict>
69</plist>
70EOF
71
72  echo "==> Exporting IPA"
73  xcodebuild -exportArchive \
74    -archivePath "$ARCHIVE" \
75    -exportPath "${OTA_DIR}/export" \
76    -exportOptionsPlist "${OTA_DIR}/ExportOptions.plist" \
77    -allowProvisioningUpdates \
78    -quiet
79
80  mv "${OTA_DIR}/export/Reportage.ipa" "${SITE}/Reportage.ipa"
81fi
82
83if [[ ! -f "${SITE}/Reportage.ipa" ]]; then
84  echo "No IPA at ${SITE}/Reportage.ipa; run without --skip-build first." >&2
85  exit 1
86fi
87
88APP_INFO="${ARCHIVE}/Products/Applications/Reportage.app/Info.plist"
89VERSION="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$APP_INFO")"
90BUILD="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleVersion' "$APP_INFO")"
91
92cat > "${SITE}/manifest.plist" <<EOF
93<?xml version="1.0" encoding="UTF-8"?>
94<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
95<plist version="1.0">
96<dict>
97  <key>items</key>
98  <array>
99    <dict>
100      <key>assets</key>
101      <array>
102        <dict>
103          <key>kind</key>
104          <string>software-package</string>
105          <key>url</key>
106          <string>${BASE_URL}/Reportage.ipa</string>
107        </dict>
108      </array>
109      <key>metadata</key>
110      <dict>
111        <key>bundle-identifier</key>
112        <string>${BUNDLE_ID}</string>
113        <key>bundle-version</key>
114        <string>${VERSION}</string>
115        <key>kind</key>
116        <string>software</string>
117        <key>title</key>
118        <string>Reportage</string>
119      </dict>
120    </dict>
121  </array>
122</dict>
123</plist>
124EOF
125
126INSTALL_URL="itms-services://?action=download-manifest&url=${BASE_URL}/manifest.plist"
127
128cat > "${SITE}/index.html" <<EOF
129<!doctype html>
130<html lang="en">
131<head>
132<meta charset="utf-8">
133<meta name="viewport" content="width=device-width, initial-scale=1">
134<title>Install Reportage</title>
135<style>
136  body { font: -apple-system-body; font-family: -apple-system, sans-serif; margin: 3em 1.5em; text-align: center; }
137  a { display: inline-block; padding: 0.8em 1.6em; border-radius: 0.6em; background: #007aff; color: #fff; text-decoration: none; font-weight: 600; }
138  p { color: #888; }
139  [hidden] { display: none !important; }
140  #progress { display: flex; align-items: center; justify-content: center; gap: 0.6em; margin-top: 1.5em; color: #888; }
141  .spinner { width: 1em; height: 1em; border: 2px solid #ccc; border-top-color: #007aff; border-radius: 50%; animation: spin 0.8s linear infinite; }
142  @keyframes spin { to { transform: rotate(360deg); } }
143</style>
144</head>
145<body>
146<h1>Reportage</h1>
147<p>${VERSION} (${BUILD})</p>
148<a id="install" href="${INSTALL_URL}">Install</a>
149<div id="progress" hidden><span class="spinner"></span><span id="message"></span></div>
150<a id="open" href="reportage://" hidden>Open Reportage</a>
151<p id="note" hidden>If Reportage doesn't open, wait for its Home Screen icon to finish installing.</p>
152<script>
153  // ota-server.swift reports how far the install has got; iOS doesn't say
154  // when installing finishes, so the Open link appears after a delay.
155  const messages = {
156    confirming: "Confirm the install in the alert",
157    downloading: "Downloading…",
158    installing: "Installing…",
159  };
160  const element = (id) => document.getElementById(id);
161  let tapped = false;
162
163  function show(stage) {
164    // The alert might have been cancelled, so Install stays until the
165    // download starts.
166    element("install").hidden = stage !== "confirming";
167    element("progress").hidden = false;
168    element("message").textContent = messages[stage];
169  }
170
171  function reveal() {
172    element("progress").hidden = true;
173    element("open").hidden = false;
174    element("note").hidden = false;
175  }
176
177  element("install").addEventListener("click", () => {
178    tapped = true;
179    show("confirming");
180  });
181
182  async function poll() {
183    try {
184      const response = await fetch("/status", { cache: "no-store" });
185      const { stage } = await response.json();
186      if (stage === "installing") {
187        // The server shuts down soon after this, so polling stops here.
188        show(stage);
189        setTimeout(reveal, 8000);
190        return;
191      }
192      if (stage !== "waiting") show(stage);
193      else if (tapped) show("confirming");
194    } catch {}
195    setTimeout(poll, 1000);
196  }
197  poll();
198</script>
199</body>
200</html>
201EOF
202
203cleanup() {
204  "$TAILSCALE" serve --https=443 off >/dev/null 2>&1 || true
205}
206trap cleanup EXIT
207
208"$TAILSCALE" serve --bg --https=443 "http://127.0.0.1:${PORT}" >/dev/null
209
210echo
211echo "==> Reportage ${VERSION} (${BUILD})"
212echo "    Open ${BASE_URL}/ in Safari on the iPhone and tap Install."
213echo "    Serving stops shortly after the IPA has been downloaded (or on Ctrl-C)."
214echo
215
216xcrun swift Scripts/ota-server.swift "$SITE" "$PORT"