forked from getsentry/XcodeBuildMCP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify-portable-install.sh
More file actions
executable file
·132 lines (118 loc) · 3.26 KB
/
verify-portable-install.sh
File metadata and controls
executable file
·132 lines (118 loc) · 3.26 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
127
128
129
130
131
132
#!/usr/bin/env bash
set -euo pipefail
ARCHIVE_PATH=""
PORTABLE_ROOT=""
TEMP_DIR=""
usage() {
cat <<'EOF'
Usage:
scripts/verify-portable-install.sh --archive <path/to/tar.gz>
scripts/verify-portable-install.sh --root <path/to/portable-root>
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
--archive)
ARCHIVE_PATH="${2:-}"
shift 2
;;
--root)
PORTABLE_ROOT="${2:-}"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown argument: $1"
usage
exit 1
;;
esac
done
cleanup() {
if [[ -n "$TEMP_DIR" && -d "$TEMP_DIR" ]]; then
rm -r "$TEMP_DIR"
fi
}
if [[ -z "$ARCHIVE_PATH" && -z "$PORTABLE_ROOT" ]]; then
usage
exit 1
fi
if [[ -n "$ARCHIVE_PATH" ]]; then
TEMP_DIR="$(mktemp -d)"
trap cleanup EXIT
tar -xzf "$ARCHIVE_PATH" -C "$TEMP_DIR"
extracted_count="$(find "$TEMP_DIR" -mindepth 1 -maxdepth 1 -type d | wc -l | tr -d ' ')"
if [[ "$extracted_count" -ne 1 ]]; then
echo "Expected archive to contain exactly one top-level directory"
exit 1
fi
PORTABLE_ROOT="$(find "$TEMP_DIR" -mindepth 1 -maxdepth 1 -type d | head -1)"
fi
if [[ ! -d "$PORTABLE_ROOT/bin" || ! -d "$PORTABLE_ROOT/libexec" ]]; then
echo "Portable layout missing bin/ or libexec/: $PORTABLE_ROOT"
exit 1
fi
if [[ ! -x "$PORTABLE_ROOT/bin/xcodebuildmcp" ]]; then
echo "Missing executable wrapper: $PORTABLE_ROOT/bin/xcodebuildmcp"
exit 1
fi
if [[ ! -x "$PORTABLE_ROOT/bin/xcodebuildmcp-doctor" ]]; then
echo "Missing executable wrapper: $PORTABLE_ROOT/bin/xcodebuildmcp-doctor"
exit 1
fi
if [[ ! -x "$PORTABLE_ROOT/libexec/xcodebuildmcp" ]]; then
echo "Missing executable binary: $PORTABLE_ROOT/libexec/xcodebuildmcp"
exit 1
fi
if [[ ! -d "$PORTABLE_ROOT/libexec/manifests" ]]; then
echo "Missing manifests directory under libexec"
exit 1
fi
if [[ ! -x "$PORTABLE_ROOT/libexec/bundled/axe" ]]; then
echo "Missing bundled axe binary under libexec"
exit 1
fi
if [[ ! -d "$PORTABLE_ROOT/libexec/bundled/Frameworks" ]]; then
echo "Missing bundled Frameworks under libexec"
exit 1
fi
if [[ ! -d "$PORTABLE_ROOT/libexec/skills" ]]; then
echo "Missing skills directory under libexec"
exit 1
fi
HOST_ARCH="$(uname -m)"
NODE_RUNTIME="$PORTABLE_ROOT/libexec/node-runtime"
if [[ ! -x "$NODE_RUNTIME" ]]; then
echo "Missing executable Node runtime under libexec"
exit 1
fi
RUNTIME_ARCHS="$(lipo -archs "$NODE_RUNTIME" 2>/dev/null || true)"
if [[ -z "$RUNTIME_ARCHS" ]]; then
if file "$NODE_RUNTIME" | grep -q "x86_64"; then
RUNTIME_ARCHS="x86_64"
elif file "$NODE_RUNTIME" | grep -q "arm64"; then
RUNTIME_ARCHS="arm64"
fi
fi
NORMALIZED_HOST_ARCH="$HOST_ARCH"
if [[ "$HOST_ARCH" == "aarch64" ]]; then
NORMALIZED_HOST_ARCH="arm64"
fi
CAN_EXECUTE="false"
for runtime_arch in $RUNTIME_ARCHS; do
if [[ "$runtime_arch" == "$NORMALIZED_HOST_ARCH" ]]; then
CAN_EXECUTE="true"
break
fi
done
if [[ "$CAN_EXECUTE" == "true" ]]; then
"$PORTABLE_ROOT/bin/xcodebuildmcp" --help >/dev/null
"$PORTABLE_ROOT/bin/xcodebuildmcp-doctor" --help >/dev/null
"$PORTABLE_ROOT/bin/xcodebuildmcp" init --print >/dev/null
else
echo "Skipping binary execution checks: host arch ($HOST_ARCH) not in runtime archs ($RUNTIME_ARCHS)"
fi
echo "Portable install verification passed for: $PORTABLE_ROOT"