84 lines
2.7 KiB
Bash
Executable File
84 lines
2.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
cd "$ROOT"
|
|
|
|
[ -f "$ROOT/.yrxtls-ios-target" ] && . "$ROOT/.yrxtls-ios-target"
|
|
|
|
TARGET="${1:-${YRXTALS_IOS_KIND:-}}"
|
|
if [ -z "$TARGET" ]; then
|
|
if xcrun devicectl list devices 2>/dev/null | grep -q "available (paired)"; then
|
|
TARGET="device"
|
|
else
|
|
TARGET="sim"
|
|
fi
|
|
fi
|
|
|
|
case "$TARGET" in
|
|
device) export YRXTALS_IOS_DEVICE="${YRXTALS_IOS_DEVICE:-${YRXTALS_IOS_UDID:-}}" ;;
|
|
sim) export YRXTALS_IOS_SIM="${YRXTALS_IOS_SIM:-${YRXTALS_IOS_UDID:-}}" ;;
|
|
esac
|
|
|
|
case "$TARGET" in
|
|
sim)
|
|
bash "$ROOT/scripts/ios/build.sh" sim
|
|
APP="$ROOT/build/ios/YrXtals.app"
|
|
BUNDLE_ID="org.else-if.yrxtals"
|
|
|
|
DEV="${YRXTALS_IOS_SIM:-}"
|
|
if [ -z "$DEV" ]; then
|
|
DEV="$(xcrun simctl list devices booted | awk '/Booted/ {print $NF}' | tr -d '()' | head -1 || true)"
|
|
fi
|
|
if [ -z "$DEV" ]; then
|
|
DEV="$(xcrun simctl list devices available | awk '/iPad/ && /\([A-F0-9\-]+\)/ {gsub(/[\(\)]/,"",$NF); print $NF; exit}')"
|
|
if [ -z "$DEV" ]; then
|
|
echo "no iPad simulator available, open Xcode > Window > Devices and Simulators to add one" >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
xcrun simctl boot "$DEV" 2>/dev/null || true
|
|
open -a Simulator
|
|
|
|
echo "Installing to simulator $DEV..."
|
|
xcrun simctl install "$DEV" "$APP"
|
|
echo "Launching..."
|
|
xcrun simctl launch "$DEV" "$BUNDLE_ID"
|
|
;;
|
|
|
|
device)
|
|
bash "$ROOT/scripts/ios/build.sh" device
|
|
APP="$ROOT/build/ios/YrXtals.app"
|
|
|
|
AVAILABLE_LINES="$(xcrun devicectl list devices 2>/dev/null \
|
|
| grep 'available (paired)' \
|
|
| grep -E 'iPad|iPhone' || true)"
|
|
|
|
DEVICE_ID="${YRXTALS_IOS_DEVICE:-}"
|
|
if [ -n "$DEVICE_ID" ] && ! echo "$AVAILABLE_LINES" | grep -q "$DEVICE_ID"; then
|
|
echo "saved device $DEVICE_ID not currently available, falling back to first paired device" >&2
|
|
DEVICE_ID=""
|
|
fi
|
|
if [ -z "$DEVICE_ID" ]; then
|
|
DEVICE_ID="$(echo "$AVAILABLE_LINES" \
|
|
| awk '{for(i=1;i<=NF;i++) if($i ~ /^[A-F0-9-]{36}$/) {print $i; exit}}')"
|
|
fi
|
|
|
|
if [ -z "$DEVICE_ID" ]; then
|
|
echo "no paired iPad/iPhone found, connect via cable and trust the host on the device" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "Installing to device $DEVICE_ID..."
|
|
xcrun devicectl device install app --device "$DEVICE_ID" "$APP"
|
|
|
|
echo "Launching..."
|
|
xcrun devicectl device process launch --device "$DEVICE_ID" org.else-if.yrxtals || true
|
|
;;
|
|
|
|
*)
|
|
echo "usage: $0 [sim|device]" >&2
|
|
exit 2
|
|
;;
|
|
esac
|