Skip to content

Commit fe41d67

Browse files
authored
fix(installer): install release formula from Homebrew tap (#1222)
1 parent d45c1a7 commit fe41d67

4 files changed

Lines changed: 53 additions & 10 deletions

File tree

crates/openshell-driver-vm/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,11 @@ On Linux amd64 and arm64, `install-dev.sh` installs the Debian package from the
182182
selected `OPENSHELL_VERSION` release tag. That package includes
183183
`openshell-gateway` and `openshell-driver-vm`.
184184
185-
On Apple Silicon macOS, `install-dev.sh` installs the generated `openshell.rb`
186-
formula from the selected release. Homebrew installs `openshell`,
187-
`openshell-gateway`, and `openshell-driver-vm`, ad-hoc signs the driver with
188-
the Hypervisor entitlement in `post_install`, and owns the `brew services`
189-
gateway lifecycle.
185+
On Apple Silicon macOS, `install-dev.sh` stages the generated `openshell.rb`
186+
formula from the selected release in the `nvidia/openshell` Homebrew tap.
187+
Homebrew installs `openshell`, `openshell-gateway`, and
188+
`openshell-driver-vm`, ad-hoc signs the driver with the Hypervisor entitlement
189+
in `post_install`, and owns the `brew services` gateway lifecycle.
190190
191191
## Relationship to `openshell-vm`
192192

install-dev.sh

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ GITHUB_URL="https://github.com/${REPO}"
1616
RELEASE_TAG="${OPENSHELL_VERSION:-dev}"
1717
CHECKSUMS_NAME="openshell-checksums-sha256.txt"
1818
LOCAL_GATEWAY_PORT="17670"
19+
HOMEBREW_TAP="nvidia/openshell"
20+
HOMEBREW_FORMULA_NAME="openshell"
1921

2022
info() {
2123
printf '%s: %s\n' "$APP_NAME" "$*" >&2
@@ -269,6 +271,34 @@ install_deb_package() {
269271
fi
270272
}
271273

274+
homebrew_formula_path() {
275+
_tap="$1"
276+
_formula="$2"
277+
278+
if ! as_target_user brew tap-info "$_tap" >/dev/null 2>&1; then
279+
info "creating local Homebrew tap ${_tap}..."
280+
as_target_user brew tap-new --no-git "$_tap" >/dev/null
281+
fi
282+
283+
_tap_dir="$(as_target_user brew --repository "$_tap" 2>/dev/null || true)"
284+
[ -n "$_tap_dir" ] || error "could not locate Homebrew tap ${_tap}"
285+
286+
_formula_dir="${_tap_dir}/Formula"
287+
as_target_user mkdir -p "$_formula_dir"
288+
printf '%s/%s.rb\n' "$_formula_dir" "$_formula"
289+
}
290+
291+
patch_homebrew_formula() {
292+
_formula_file="$1"
293+
_patched_file="${_formula_file}.patched"
294+
295+
if grep -q 'entitlements.write <<~XML' "$_formula_file"; then
296+
info "patching Homebrew formula for idempotent postinstall..."
297+
sed 's/entitlements\.write <<~XML/entitlements.atomic_write <<~XML/' "$_formula_file" >"$_patched_file"
298+
mv "$_patched_file" "$_formula_file"
299+
fi
300+
}
301+
272302
start_user_gateway() {
273303
info "restarting openshell-gateway user service as ${TARGET_USER}..."
274304

@@ -386,19 +416,31 @@ install_macos_homebrew() {
386416
download_release_asset "$RELEASE_TAG" "openshell.rb" "$_formula_file" || {
387417
error "failed to download ${_formula_url}; the selected release may not include a Homebrew formula"
388418
}
419+
chmod 0644 "$_formula_file"
420+
patch_homebrew_formula "$_formula_file"
421+
422+
_tap_formula_file="$(homebrew_formula_path "$HOMEBREW_TAP" "$HOMEBREW_FORMULA_NAME")"
423+
info "staging Homebrew formula in tap ${HOMEBREW_TAP}..."
424+
cp "$_formula_file" "$_tap_formula_file"
425+
chmod 0644 "$_tap_formula_file"
426+
if [ "$(id -u)" -eq 0 ]; then
427+
chown "$TARGET_USER" "$_tap_formula_file" 2>/dev/null || true
428+
fi
429+
430+
_formula_ref="${HOMEBREW_TAP}/${HOMEBREW_FORMULA_NAME}"
389431

390432
if as_target_user brew list --formula openshell >/dev/null 2>&1; then
391433
info "reinstalling OpenShell with Homebrew..."
392-
as_target_user brew reinstall --formula "$_formula_file"
434+
as_target_user brew reinstall --formula "$_formula_ref"
393435
else
394436
info "installing OpenShell with Homebrew..."
395-
as_target_user brew install --formula "$_formula_file"
437+
as_target_user brew install --formula "$_formula_ref"
396438
fi
397439

398440
info "restarting OpenShell Homebrew service..."
399-
if ! as_target_user brew services restart openshell; then
441+
if ! as_target_user brew services restart "$_formula_ref"; then
400442
warn "could not restart the OpenShell Homebrew service"
401-
info "restart it later with: brew services restart openshell"
443+
info "restart it later with: brew services restart ${_formula_ref}"
402444
info "then register it with: openshell gateway add http://127.0.0.1:${LOCAL_GATEWAY_PORT} --local --name local"
403445
return 0
404446
fi

python/openshell/release_formula_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@ def test_generate_homebrew_formula_uses_tagged_macos_driver_asset(
5252
) in formula
5353
assert 'sha256 "' + "b" * 64 + '"' in formula
5454
assert 'OPENSHELL_DRIVER_DIR: "#{opt_libexec}"' in formula
55+
assert "entitlements.atomic_write" in formula
5556
assert "brew services restart openshell" in formula

tasks/scripts/release.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def post_install
271271
(var/"log/openshell").mkpath
272272
273273
entitlements = var/"openshell/openshell-driver-vm.entitlements.plist"
274-
entitlements.write <<~XML
274+
entitlements.atomic_write <<~XML
275275
<?xml version="1.0" encoding="UTF-8"?>
276276
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
277277
<plist version="1.0">

0 commit comments

Comments
 (0)