hex/scripts/smoke-service-app.sh
Dax 3434eb5f35
Rename voice-control to hex everywhere, without migrations (#293)
* Rename voice-control to hex everywhere, without migrations

The Cargo package and binary are now hex, every OS keeps its data in a
hex folder, and VOICE_CONTROL_* variables are HEX_*. Hex is a fresh
app: the macOS voice-control rename, its symlink, and the Windows and
Linux beta settings imports are gone. The Windows installer gets a new
AppId so it never takes over an old voice-control install's entry.

* Format

* Drop the Windows paste-last default only the beta import used
2026-10-28 13:08:44 -04:00

113 lines
3.3 KiB
Shell
Executable file

#!/bin/sh
set -eu
root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
. "$root/scripts/macos-signing.sh"
version=$(hex_version "$root")
arch=$(uname -m)
artifact=${HEX_SERVICE_ARTIFACT:-$root/dist/service/HEX-Service-$version-$arch.zip}
digest="$artifact.sha256"
install_root="$HOME/Library/Application Support/HEX Service Proof"
version_dir="$install_root/versions/$version"
installed="$version_dir/HEX Service.app"
runtime="$install_root/runtime"
staging="$install_root/.staging-$version-$$"
expected_team=${HEX_TEAM_ID:?Set HEX_TEAM_ID to the Apple Developer signing team}
expected_identifier=anomaly.hex.service
pid=
cleanup() {
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
kill -INT "$pid" 2>/dev/null || true
shutdown_attempts=100
while kill -0 "$pid" 2>/dev/null && [ "$shutdown_attempts" -gt 0 ]; do
shutdown_attempts=$((shutdown_attempts - 1))
sleep 0.05
done
if kill -0 "$pid" 2>/dev/null; then
kill -TERM "$pid" 2>/dev/null || true
sleep 0.1
fi
if kill -0 "$pid" 2>/dev/null; then
kill -KILL "$pid" 2>/dev/null || true
fi
fi
rm -rf "$staging"
}
trap cleanup EXIT INT TERM
if [ "$#" -ne 0 ]; then
echo "Usage: $0" >&2
exit 1
fi
if [ ! -f "$artifact" ] || [ ! -f "$digest" ]; then
echo "Prepare the service artifact first with ./scripts/prepare-service-app.sh." >&2
exit 1
fi
(cd "$(dirname -- "$artifact")" && shasum -a 256 -c "$(basename -- "$digest")")
rm -rf "$staging"
mkdir -p "$staging" "$install_root/versions" "$runtime"
/usr/bin/ditto -x -k "$artifact" "$staging"
bundle="$staging/HEX Service.app"
codesign --verify --deep --strict --verbose=2 "$bundle"
xcrun stapler validate "$bundle"
spctl --assess --type execute --verbose=2 "$bundle"
team=$(codesign -dvv "$bundle" 2>&1 | sed -n 's/^TeamIdentifier=//p')
identifier=$(codesign -dvv "$bundle" 2>&1 | sed -n 's/^Identifier=//p')
if [ "$team" != "$expected_team" ] || [ "$identifier" != "$expected_identifier" ]; then
echo "Unexpected service identity: $team / $identifier" >&2
exit 1
fi
rm -rf "$version_dir"
mkdir -p "$version_dir"
/usr/bin/ditto "$bundle" "$installed"
rm -rf "$staging"
'/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister' \
-f "$installed"
rm -f "$runtime/local-api.json"
/usr/bin/open -gj -n \
--env "HEX_APPLICATION_SUPPORT_DIR=$runtime" \
"$installed" --args service
discovery="$runtime/local-api.json"
attempts=100
while [ ! -f "$discovery" ]; do
attempts=$((attempts - 1))
if [ "$attempts" -eq 0 ]; then
echo "Timed out waiting for service discovery." >&2
exit 1
fi
sleep 0.05
done
port=$(jq -r .port "$discovery")
token=$(jq -r .token "$discovery")
pid=$(jq -r .pid "$discovery")
health=$(curl --fail --silent --show-error \
-H "Authorization: Bearer $token" \
"http://127.0.0.1:$port/health")
models=$(curl --fail --silent --show-error \
-H "Authorization: Bearer $token" \
"http://127.0.0.1:$port/models")
jq -e '.apiVersion == "2" and .version != null' >/dev/null <<EOF
$health
EOF
jq -e 'length > 0 and .[0].id == "parakeet_unified_en"' >/dev/null <<EOF
$models
EOF
kill -INT "$pid"
attempts=100
while [ -f "$discovery" ]; do
attempts=$((attempts - 1))
if [ "$attempts" -eq 0 ]; then
echo "Timed out waiting for service shutdown." >&2
exit 1
fi
sleep 0.05
done
pid=
echo "Service bootstrap smoke test passed: $installed"