← All repositories

crossmate

A collaborative crossword app for iPhone and iPad

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


Scripts/screenshots-ipad.sh (3486B)

1#!/bin/bash
2set -euo pipefail
3
4SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
5REPO_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
6
7DO_COMPOSE=false
8while getopts "c" opt; do
9  case $opt in
10    c) DO_COMPOSE=true ;;
11    *) ;;
12  esac
13done
14shift $((OPTIND - 1))
15
16MAJOR="${1:-27}"
17RUNTIME=$(xcrun simctl list runtimes available \
18  | grep "iOS ${MAJOR}\." \
19  | sed 's/.*iOS \([0-9.]*\).*/\1/' \
20  | sort -t. -k1,1n -k2,2n \
21  | tail -1 || true)
22DESTINATION_OS=$(xcrun simctl list runtimes available \
23  | grep "iOS ${MAJOR}\." \
24  | sed 's/.*(\([0-9.]*\) -.*/\1/' \
25  | sort -t. -k1,1n -k2,2n -k3,3n \
26  | tail -1 || true)
27
28if [ -z "$RUNTIME" ] || [ -z "$DESTINATION_OS" ]; then
29  echo "No available iOS ${MAJOR}.x simulator runtime found." >&2
30  exit 1
31fi
32
33DEVICE=$(xcrun simctl list devices available "iOS ${RUNTIME}" \
34  | grep "iPad Pro 13" \
35  | head -1 \
36  | sed 's/^ *\(.*\) ([A-F0-9-]*).*/\1/' || true)
37if [ -z "$DEVICE" ]; then
38  DEVICE=$(xcrun simctl list devices available "iOS ${RUNTIME}" \
39    | grep "iPad" \
40    | head -1 \
41    | sed 's/^ *\(.*\) ([A-F0-9-]*).*/\1/' || true)
42fi
43
44if [ -z "$DEVICE" ]; then
45  echo "No available iPad simulator found for iOS ${RUNTIME}." >&2
46  exit 1
47fi
48
49echo "Using ${DEVICE}, iOS ${RUNTIME}"
50
51UDID=$(xcrun simctl list devices available "iOS ${RUNTIME}" \
52  | grep "$DEVICE" \
53  | head -1 \
54  | sed 's/.*(\([A-F0-9-]*\)).*/\1/')
55
56xcrun simctl boot "$UDID" 2>/dev/null || true
57xcrun simctl bootstatus "$UDID" -b
58
59xcrun simctl status_bar "$UDID" override \
60  --time "9:41" \
61  --batteryState discharging \
62  --batteryLevel 100 \
63  --wifiBars 3 \
64  --cellularBars 4 \
65  --cellularMode active \
66  --dataNetwork wifi
67
68echo "Status bar overridden"
69
70DERIVED_DATA="/tmp/crossmate-screenshots-derived"
71SCREENSHOT_TMP="/tmp/crossmate-ipad-screenshot.png"
72FRAMED_TMP="/tmp/crossmate-ipad-framed"
73RAW_OUTPUT_PATH="${REPO_DIR}/ipad_0.png"
74MARKETING_DIR="${REPO_DIR}/Marketing"
75BUNDLE_ID="net.inqk.crossmate"
76CAPTION="Built for iPad too"
77CANVAS_WIDTH=2064
78CANVAS_HEIGHT=2752
79
80rm -rf "$DERIVED_DATA" "$SCREENSHOT_TMP" "$FRAMED_TMP"
81
82xcodebuild build \
83  -scheme "Crossmate" \
84  -project "${REPO_DIR}/Crossmate.xcodeproj" \
85  -destination "platform=iOS Simulator,name=${DEVICE},OS=${DESTINATION_OS}" \
86  -derivedDataPath "$DERIVED_DATA" \
87  2>&1
88
89APP_PATH="${DERIVED_DATA}/Build/Products/Debug-iphonesimulator/Crossmate.app"
90if [ ! -d "$APP_PATH" ]; then
91  echo "Built app not found at ${APP_PATH}" >&2
92  exit 1
93fi
94
95xcrun simctl install "$UDID" "$APP_PATH"
96xcrun simctl launch --terminate-running-process "$UDID" "$BUNDLE_ID" \
97  --crossmate-marketing-screenshot
98
99sleep 3
100
101xcrun simctl io "$UDID" screenshot --mask ignored "$SCREENSHOT_TMP"
102xcrun simctl status_bar "$UDID" clear 2>/dev/null || true
103
104if [ ! -f "$SCREENSHOT_TMP" ]; then
105  echo "Screenshot capture failed." >&2
106  exit 1
107fi
108
109echo ""
110if [ "$DO_COMPOSE" = true ]; then
111  mkdir -p "$FRAMED_TMP" "$MARKETING_DIR"
112
113  echo "Framing screenshot..."
114  shortcuts run "Frame Screenshots" -i "$SCREENSHOT_TMP" -o "${FRAMED_TMP}/framed.png"
115
116  echo "Composing final image..."
117  swift "${SCRIPT_DIR}/screenshots-ios-compose.swift" \
118    "${FRAMED_TMP}/framed.png" \
119    "${MARKETING_DIR}/ipad_0.png" \
120    "$CAPTION" \
121    "$CANVAS_WIDTH" \
122    "$CANVAS_HEIGHT"
123
124  rm -rf "$FRAMED_TMP"
125
126  echo ""
127  echo "Screenshot saved to ${MARKETING_DIR}/ipad_0.png"
128  ls -la "${MARKETING_DIR}/ipad_0.png"
129else
130  cp "$SCREENSHOT_TMP" "$RAW_OUTPUT_PATH"
131
132  echo "Screenshot saved to ${RAW_OUTPUT_PATH}"
133  ls -la "$RAW_OUTPUT_PATH"
134fi