Skip to content

awk device ID parsing fails for iPads with spaces in model name #4

Description

@huangt04

Prerequisites

  • I have searched for similar issues and confirmed this is not a duplicate

Game Version

  • Command & Conquer Generals
  • Command & Conquer Generals: Zero Hour
  • Other (please specify below)

Operating System

  • macOS
  • Linux
  • Windows
  • Other (please specify below)

Bug Description

Description
When running the iOS deployment script to install an app to a connected physical device, the script fails to extract the correct Device ID (UDID) if the device's hardware model contains spaces (e.g., iPad Pro 13-inch).

Instead of extracting the UDID, the script extracts a fragment of the model name (like "13-inch"), which causes the deployment command to fail unless the user manually renames their actual iPad to "13-inch" to bypass the error.

Reproduction Steps

Steps to Reproduce
Connect a physical iPad with a multi-word hardware model name (e.g., iPad Pro 13-inch Wi-Fi Cellular).

Ensure the device name also contains spaces (e.g., Joe's ipad).

Run the deployment script
GX_TEAM_ID= GX_BUNDLE_ID=com.you.generalszh
./scripts/build/ios/package-ios-zh.sh --install

Or run the logic
Bash
DEVICE_ID=$(xcrun devicectl list devices 2>/dev/null | awk '/connected/{print $(NF-2); exit}')
Observe the devicectl device install output.

Expected Behavior
The script should reliably extract the 25-character or 40-character physical device UDID (e.g., 00008020-001234567890ABCD) and deploy the app to that specific device.

Actual Behavior
The script attempts to deploy the app to a device literally named "13-inch".

Additional Context

Root Cause
There are two distinct points of failure in the current script:

Flawed awk parsing: The command awk '{print $(NF-2)}' attempts to grab the 3rd-to-last column by counting spaces from the end of the line. Because the hardware model (iPad Pro 13-inch (M4)) contains varying amounts of spaces, the 3rd-to-last word ends up being "13-inch" instead of the actual identifier. Since this string is not empty, the script proceeds with "13-inch" as the DEVICE_ID.

Broken Regex Fallback: If the awk command were to fail and return an empty string, the fallback regex is hardcoded to look for exactly 36 characters: grep -oE '[0-9A-F-]{36}'. This only matches iOS Simulator UUIDs, entirely missing modern physical device UDIDs (25 characters) and older physical device UDIDs (40 characters).

Proposed Solution
Remove the brittle space-counting awk logic entirely. Instead, use a strict regex pattern as the primary method to extract the UDID. This ensures we only capture valid 25-character (modern physical), 40-character (older physical), or 36-character (simulator) IDs, completely ignoring device names and model strings.

DEVICE_ID=$(xcrun devicectl list devices 2>/dev/null | grep -i connected | grep -ioE '([0-9a-f]{40}|[0-9a-f]{8}-[0-9a-f]{16}|[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})' | head -1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions