← All repositories

reportage

A life-logging app for iPhone

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


Scripts/demo-simulator.sh (2648B)

1#!/bin/bash
2# Shared helper for the demo scripts: finds the dedicated demo simulator,
3# creating it on first use, and builds and installs the app on it.
4# Source this file, then call: demo_simulator [major] and demo_install.
5# Sets DEMO_NAME, UDID and APP_PATH.
6
7DEMO_NAME="Reportage Demo"
8BUNDLE_ID="net.inqk.reportage"
9DEMO_DERIVED_DATA="/tmp/reportage-demo-derived"
10DEMO_REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
11source "$(dirname "${BASH_SOURCE[0]}")/select-simulator.sh"
12
13# Looks up the demo device. Empty if it doesn't exist yet; `|| true` keeps the
14# no-match grep from tripping `set -o pipefail`.
15demo_udid() {
16  xcrun simctl list devices \
17    | grep -F "${DEMO_NAME} (" \
18    | head -1 \
19    | sed -E 's/.*\(([0-9A-Fa-f-]{36})\).*/\1/' || true
20}
21
22# Sets UDID to the demo device, creating it on the newest iOS <major> runtime
23# with the iPhone select_simulator picks, and boots it.
24demo_simulator() {
25  UDID=$(demo_udid)
26  if [ -n "$UDID" ]; then
27    echo "Reusing '${DEMO_NAME}' (${UDID})"
28  else
29    select_simulator "${1:-27}" || return 1
30    local type_id runtime_id
31    type_id=$(xcrun simctl list devicetypes \
32      | grep -E "^${DEVICE} \(" \
33      | head -1 \
34      | sed -E 's/.*\((com\.apple[^)]*)\)$/\1/' || true)
35    runtime_id=$(xcrun simctl list runtimes available \
36      | grep "iOS ${RUNTIME} (" \
37      | head -1 \
38      | sed -E 's/.* - (com\.apple[^ ]*).*/\1/' || true)
39    if [ -z "$type_id" ] || [ -z "$runtime_id" ]; then
40      echo "Couldn't resolve a device type and runtime to create '${DEMO_NAME}'." >&2
41      return 1
42    fi
43    echo "Creating '${DEMO_NAME}' (${DEVICE}, iOS ${RUNTIME})"
44    UDID=$(xcrun simctl create "${DEMO_NAME}" "${type_id}" "${runtime_id}")
45  fi
46  xcrun simctl boot "$UDID" 2>/dev/null || true
47  xcrun simctl bootstatus "$UDID" -b
48}
49
50# Builds the Debug app, which has the demo seed, and installs it on UDID.
51demo_install() {
52  xcodebuild build \
53    -scheme "Reportage" \
54    -project "${DEMO_REPO_DIR}/Reportage.xcodeproj" \
55    -destination "id=${UDID}" \
56    -derivedDataPath "$DEMO_DERIVED_DATA" \
57    2>&1
58  APP_PATH="${DEMO_DERIVED_DATA}/Build/Products/Debug-iphonesimulator/Reportage.app"
59  if [ ! -d "$APP_PATH" ]; then
60    echo "Built app not found at ${APP_PATH}" >&2
61    return 1
62  fi
63  xcrun simctl install "$UDID" "$APP_PATH"
64}
65
66# Launches the app with the demo seed, in Australian English so temperatures
67# are in Celsius. Any arguments are passed to the app as extra launch
68# arguments.
69demo_launch() {
70  xcrun simctl launch --terminate-running-process "$UDID" "$BUNDLE_ID" \
71    --reportage-seed-demo -AppleLanguages "(en-AU)" -AppleLocale en_AU "$@"
72}