#!/bin/sh # The publisher fills the version and archive hashes from the verified release. # Keep the final invocation last so a truncated pipe cannot launch the installer. usage() { cat <<'USAGE' Install uapkg for the current user. --platform TARGET Override the macOS/Linux platform (e.g. linux-x64-musl) --yes Install unattended --install-dir DIR Choose the directory containing the launcher --cli-version VER Select the initial default CLI version --no-modify-path Leave shell configuration unchanged --adopt Adopt a verified manual launcher at the chosen destination --adopt-version VER Verify an older manual launcher when using --adopt USAGE } detect_platform() { case "$(uname -m)" in x86_64|amd64) arch=x64 ;; arm64|aarch64) arch=arm64 ;; *) return 1 ;; esac case "$(uname -s)" in Darwin) if [ "$arch" = x64 ] && [ "$(sysctl -in hw.optional.arm64 2>/dev/null)" = 1 ]; then arch=arm64; fi echo "darwin-$arch" ;; Linux) echo "linux-$arch" ;; *) return 1 ;; esac } main() ( set -eu version='0.3.11' platform='' remaining=$# while [ "$remaining" -gt 0 ]; do option=$1 shift remaining=$((remaining - 1)) case "$option" in --platform) if [ "$remaining" -eq 0 ]; then echo '--platform requires a target.' >&2; exit 2; fi platform=$1 shift remaining=$((remaining - 1)) [ -n "$platform" ] || { echo 'Empty platform.' >&2; exit 2; } ;; --platform=*) platform=${option#--platform=}; [ -n "$platform" ] || { echo 'Empty platform.' >&2; exit 2; } ;; --help|-h) usage; exit 0 ;; *) set -- "$@" "$option" ;; esac done if [ -z "$platform" ]; then platform=$(detect_platform) || { echo 'Unsupported host. See https://docs.uapkg.dev/install/' >&2; exit 1; } fi case "$platform" in darwin-x64) digest='4f3227d91896cf64ed5ba560ced561a4f86d0a05d702cebfe52b04ac0f263edf' ;; darwin-arm64) digest='33f57cd40aabd11fd9ebc6e55ea4caa9c2ddc3392f33d76d1887317bce4cef54' ;; linux-x64) digest='ea6d5287bd879b23ed967a8353d3d4fa2ad76c429c6b1330fc3c7abe88a03ab0' ;; linux-arm64) digest='d6305a432c4e12a829a7e9ff6955b866f26bb70ccd763b215d1a98bd14448962' ;; linux-x64-musl) digest='58caafd90151b57c179ec24131f18992127a8f6edf5f0be7e3e88ab1364bf0a2' ;; *) echo "Unsupported Unix platform: $platform" >&2; exit 2 ;; esac umask 077 temp=$(mktemp -d "${TMPDIR:-/tmp}/uapkg-init.XXXXXXXX") || exit 1 trap 'rm -rf -- "$temp"' 0 trap 'exit 1' HUP INT TERM file="uapkg-launcher-$version-$platform.tar.gz" curl --proto '=https' --proto-redir '=https' --tlsv1.2 -fsSL \ "https://releases.uapkg.dev/launcher/$version/$file" -o "$temp/archive" if command -v sha256sum >/dev/null 2>&1; then actual=$(sha256sum < "$temp/archive") else actual=$(shasum -a 256 < "$temp/archive") fi [ "${actual%% *}" = "$digest" ] || { echo 'Launcher archive failed SHA-256 verification.' >&2; exit 1; } tar -xOzf "$temp/archive" uapkg > "$temp/uapkg-init" chmod 700 "$temp/uapkg-init" "$temp/uapkg-init" "$@" ) main "$@"