crossmate

A collaborative crossword app for iOS
Log | Files | Refs | LICENSE

screenshots-ipad.sh (3486B)


      1 #!/bin/bash
      2 set -euo pipefail
      3 
      4 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
      5 REPO_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
      6 
      7 DO_COMPOSE=false
      8 while getopts "c" opt; do
      9   case $opt in
     10     c) DO_COMPOSE=true ;;
     11     *) ;;
     12   esac
     13 done
     14 shift $((OPTIND - 1))
     15 
     16 MAJOR="${1:-26}"
     17 RUNTIME=$(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)
     22 DESTINATION_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 
     28 if [ -z "$RUNTIME" ] || [ -z "$DESTINATION_OS" ]; then
     29   echo "No available iOS ${MAJOR}.x simulator runtime found." >&2
     30   exit 1
     31 fi
     32 
     33 DEVICE=$(xcrun simctl list devices available "iOS ${RUNTIME}" \
     34   | grep "iPad Pro 13" \
     35   | head -1 \
     36   | sed 's/^ *\(.*\) ([A-F0-9-]*).*/\1/' || true)
     37 if [ -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)
     42 fi
     43 
     44 if [ -z "$DEVICE" ]; then
     45   echo "No available iPad simulator found for iOS ${RUNTIME}." >&2
     46   exit 1
     47 fi
     48 
     49 echo "Using ${DEVICE}, iOS ${RUNTIME}"
     50 
     51 UDID=$(xcrun simctl list devices available "iOS ${RUNTIME}" \
     52   | grep "$DEVICE" \
     53   | head -1 \
     54   | sed 's/.*(\([A-F0-9-]*\)).*/\1/')
     55 
     56 xcrun simctl boot "$UDID" 2>/dev/null || true
     57 xcrun simctl bootstatus "$UDID" -b
     58 
     59 xcrun 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 
     68 echo "Status bar overridden"
     69 
     70 DERIVED_DATA="/tmp/crossmate-screenshots-derived"
     71 SCREENSHOT_TMP="/tmp/crossmate-ipad-screenshot.png"
     72 FRAMED_TMP="/tmp/crossmate-ipad-framed"
     73 RAW_OUTPUT_PATH="${REPO_DIR}/ipad_0.png"
     74 MARKETING_DIR="${REPO_DIR}/Marketing"
     75 BUNDLE_ID="net.inqk.crossmate"
     76 CAPTION="Built for iPad too"
     77 CANVAS_WIDTH=2064
     78 CANVAS_HEIGHT=2752
     79 
     80 rm -rf "$DERIVED_DATA" "$SCREENSHOT_TMP" "$FRAMED_TMP"
     81 
     82 xcodebuild 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 
     89 APP_PATH="${DERIVED_DATA}/Build/Products/Debug-iphonesimulator/Crossmate.app"
     90 if [ ! -d "$APP_PATH" ]; then
     91   echo "Built app not found at ${APP_PATH}" >&2
     92   exit 1
     93 fi
     94 
     95 xcrun simctl install "$UDID" "$APP_PATH"
     96 xcrun simctl launch --terminate-running-process "$UDID" "$BUNDLE_ID" \
     97   --crossmate-marketing-screenshot
     98 
     99 sleep 3
    100 
    101 xcrun simctl io "$UDID" screenshot --mask ignored "$SCREENSHOT_TMP"
    102 xcrun simctl status_bar "$UDID" clear 2>/dev/null || true
    103 
    104 if [ ! -f "$SCREENSHOT_TMP" ]; then
    105   echo "Screenshot capture failed." >&2
    106   exit 1
    107 fi
    108 
    109 echo ""
    110 if [ "$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"
    129 else
    130   cp "$SCREENSHOT_TMP" "$RAW_OUTPUT_PATH"
    131 
    132   echo "Screenshot saved to ${RAW_OUTPUT_PATH}"
    133   ls -la "$RAW_OUTPUT_PATH"
    134 fi