crossmate

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

select-simulator.sh (1035B)


      1 #!/bin/bash
      2 # Shared helper: resolves a usable iOS Simulator for the given major version.
      3 # Source this file, then call: select_simulator [major]   (default major: 26)
      4 # On success sets RUNTIME, DESTINATION_OS, and DEVICE; on failure prints to stderr and returns 1.
      5 
      6 select_simulator() {
      7   local major="${1:-26}"
      8 
      9   local runtime_line
     10   runtime_line=$(xcrun simctl list runtimes available \
     11     | grep "iOS ${major}\." \
     12     | sort -t. -k1,1n -k2,2n \
     13     | tail -1 || true)
     14 
     15   RUNTIME=$(sed 's/.*iOS \([0-9.]*\).*/\1/' <<<"${runtime_line}")
     16   DESTINATION_OS=$(sed 's/.*(\([0-9.]*\) -.*/\1/' <<<"${runtime_line}")
     17 
     18   if [ -z "$RUNTIME" ] || [ -z "$DESTINATION_OS" ]; then
     19     echo "No available iOS ${major}.x simulator runtime found." >&2
     20     return 1
     21   fi
     22 
     23   DEVICE=$(xcrun simctl list devices available "iOS ${RUNTIME}" \
     24     | grep "iPhone" \
     25     | head -1 \
     26     | sed 's/^ *\(.*\) ([A-F0-9-]*).*/\1/' || true)
     27 
     28   if [ -z "$DEVICE" ]; then
     29     echo "No available iPhone simulator found for iOS ${RUNTIME}." >&2
     30     return 1
     31   fi
     32 }