-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
126 lines (110 loc) · 4.51 KB
/
Copy pathjustfile
File metadata and controls
126 lines (110 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
ios_app := "target/dx/ook-reader/debug/ios/OokReader.app"
ios_device_app := "target/dx/ook-reader/release/ios/OokReader.app"
bundle_id := "com.dimaportenko.ook-reader"
default:
@just --list
test:
RUST_BACKTRACE=1 cargo test
validate:
cargo test && cargo clippy --all-targets
serve-desktop:
dx serve --platform desktop
boot-ios:
#!/usr/bin/env bash
set -euo pipefail
DEVICE="${DEVICE:-$(xcrun simctl list devices available | awk '
/iPhone/ && match($0, /[0-9A-F]+-[0-9A-F]+-[0-9A-F]+-[0-9A-F]+-[0-9A-F]+/) {
udid = substr($0, RSTART, RLENGTH)
if ($0 ~ /\(Booted\)/) booted = udid
latest = udid
}
END { print (booted != "" ? booted : latest) }
')}"
if [ -z "$DEVICE" ]; then
echo "No available iPhone simulator found. Install one via Xcode > Settings > Components." >&2
exit 1
fi
echo "Using simulator: $(xcrun simctl list devices | grep -i "$DEVICE" | head -1 | sed 's/^ *//')"
xcrun simctl boot "$DEVICE" 2>/dev/null || true
open -a Simulator
xcrun simctl bootstatus "$DEVICE" -b
serve-ios: boot-ios
dx serve --platform ios
install-ios: boot-ios
dx build --platform ios
cp assets/icons/ios/*.png {{ios_app}}/
xcrun simctl install booted {{ios_app}}
release-macos:
dx bundle --bundle macos --release
open target/dx/ook-reader/bundle/macos/macos
devices-ios:
xcrun devicectl list devices
pick-device query="":
#!/usr/bin/env bash
set -euo pipefail
json=$(mktemp)
script=$(mktemp)
trap 'rm -f "$json" "$script"' EXIT
xcrun devicectl list devices --json-output "$json" > /dev/null
cat > "$script" <<'PY'
import json, os, sys
devices = json.load(open(sys.argv[1]))["result"]["devices"]
rows = [
(
d["hardwareProperties"]["udid"],
d["deviceProperties"].get("name", "?"),
d["hardwareProperties"].get("marketingName", "?"),
d["connectionProperties"].get("tunnelState", "?"),
)
for d in devices
]
query = os.environ.get("QUERY", "").strip().lower()
if query:
rows = [r for r in rows if any(query in f.lower() for f in r[:3])]
if not rows:
sys.exit("No paired device matches %r. Try `just devices-ios`." % query)
if not rows:
sys.exit("No paired devices. Connect one and trust this Mac.")
if len(rows) > 1:
for i, (_, name, model, state) in enumerate(rows, 1):
print(" %d) %s - %s (%s)" % (i, name, model, state), file=sys.stderr)
try:
prompt = open("/dev/tty")
except OSError:
prompt = sys.stdin
print("Device [1-%d]: " % len(rows), end="", file=sys.stderr, flush=True)
answer = prompt.readline().strip()
if not answer.isdigit() or not 1 <= int(answer) <= len(rows):
sys.exit("Not a choice: %r" % answer)
rows = [rows[int(answer) - 1]]
udid, name, model, _ = rows[0]
print("Installing to %s - %s" % (name, model), file=sys.stderr)
print(udid)
PY
QUERY="{{query}}" python3 "$script" "$json"
release-ios query="":
#!/usr/bin/env bash
set -euo pipefail
udid=$(just pick-device "{{query}}")
dx build --platform ios --release --device "$udid"
cp assets/icons/ios/*.png "{{ios_device_app}}/"
profile=$(security cms -D -i "{{ios_device_app}}/embedded.mobileprovision")
team=$(echo "$profile" | plutil -extract ApplicationIdentifierPrefix.0 raw -)
valid=$(security find-identity -v -p codesigning)
identity=""
for i in $(seq 0 $(($(echo "$profile" | plutil -extract DeveloperCertificates raw -) - 1))); do
sha=$(echo "$profile" | plutil -extract DeveloperCertificates.$i raw - | base64 -d \
| openssl x509 -inform DER -noout -fingerprint -sha1 | cut -d= -f2 | tr -d :)
if echo "$valid" | grep -q "$sha"; then identity=$sha; break; fi
done
if [ -z "$identity" ]; then
echo "No valid keychain identity matches the profile dx embedded." >&2
echo "Its certificates have all expired or been revoked - refresh the profile in Xcode." >&2
exit 1
fi
entitlements=$(mktemp)
codesign -d --entitlements - --xml "{{ios_device_app}}" > "$entitlements"
plutil -replace application-identifier -string "$team.{{bundle_id}}" "$entitlements"
plutil -replace keychain-access-groups -json "[\"$team.{{bundle_id}}\"]" "$entitlements"
codesign --force --entitlements "$entitlements" --sign "$identity" "{{ios_device_app}}"
xcrun devicectl device install app --device "$udid" "{{ios_device_app}}"