|
| 1 | +#!/bin/sh |
| 2 | +# php-debugger installer bootstrap (Linux/macOS). Always installs the latest release. |
| 3 | +# |
| 4 | +# Usage: |
| 5 | +# curl -fsSL https://github.com/php-debugger/installer/releases/latest/download/install.sh | sh |
| 6 | +# wget -qO- https://github.com/php-debugger/installer/releases/latest/download/install.sh | sh |
| 7 | +# |
| 8 | +# Environment overrides: |
| 9 | +# INSTALL_DIR=/path where to place the binary (default: current directory) |
| 10 | +# |
| 11 | +# Because the archive is fetched with curl/wget (not a browser), the binary is |
| 12 | +# not quarantined, so macOS Gatekeeper does not block it. As a safety net the |
| 13 | +# script also clears the quarantine attribute if present. |
| 14 | +set -eu |
| 15 | + |
| 16 | +REPO="php-debugger/installer" |
| 17 | +BIN="php-debugger" |
| 18 | +INSTALL_DIR="${INSTALL_DIR:-$(pwd)}" |
| 19 | + |
| 20 | +info() { printf '%s\n' "$*"; } |
| 21 | +fail() { printf 'error: %s\n' "$*" >&2; exit 1; } |
| 22 | +have() { command -v "$1" >/dev/null 2>&1; } |
| 23 | + |
| 24 | +download() { # download URL FILE |
| 25 | + if have curl; then curl -fsSL "$1" -o "$2" |
| 26 | + elif have wget; then wget -q "$1" -O "$2" |
| 27 | + else fail "need curl or wget to download"; fi |
| 28 | +} |
| 29 | + |
| 30 | +# --- detect OS --- |
| 31 | +kernel="$(uname -s)" |
| 32 | +case "$kernel" in |
| 33 | + Linux) OS="linux" ;; |
| 34 | + Darwin) OS="macos" ;; |
| 35 | + *) fail "unsupported operating system: $kernel (see the build-from-source instructions)" ;; |
| 36 | +esac |
| 37 | + |
| 38 | +# --- detect architecture --- |
| 39 | +machine="$(uname -m)" |
| 40 | +case "$machine" in |
| 41 | + x86_64 | amd64) ARCH="amd64" ;; |
| 42 | + arm64 | aarch64) ARCH="arm64" ;; |
| 43 | + *) fail "unsupported architecture: $machine" ;; |
| 44 | +esac |
| 45 | + |
| 46 | +ASSET="php-debugger-${OS}-${ARCH}.tar.gz" |
| 47 | +# The releases/latest/download URL always resolves to the newest release. |
| 48 | +URL="https://github.com/$REPO/releases/latest/download/$ASSET" |
| 49 | + |
| 50 | +info "Installing $BIN (latest, $OS/$ARCH)" |
| 51 | + |
| 52 | +# --- download + extract --- |
| 53 | +tmp="$(mktemp -d)" |
| 54 | +trap 'rm -rf "$tmp"' EXIT INT TERM |
| 55 | +download "$URL" "$tmp/$ASSET" || fail "failed to download $URL" |
| 56 | +tar -xzf "$tmp/$ASSET" -C "$tmp" || fail "failed to extract $ASSET" |
| 57 | +[ -f "$tmp/$BIN" ] || fail "archive did not contain $BIN" |
| 58 | + |
| 59 | +# --- install --- |
| 60 | +mkdir -p "$INSTALL_DIR" |
| 61 | +mv "$tmp/$BIN" "$INSTALL_DIR/$BIN" |
| 62 | +chmod +x "$INSTALL_DIR/$BIN" |
| 63 | +# Clear any quarantine attribute so macOS Gatekeeper does not block it. |
| 64 | +if [ "$OS" = "macos" ]; then |
| 65 | + xattr -d com.apple.quarantine "$INSTALL_DIR/$BIN" 2>/dev/null || true |
| 66 | +fi |
| 67 | + |
| 68 | +info "" |
| 69 | +info "Installed to $INSTALL_DIR/$BIN" |
| 70 | +case ":$PATH:" in |
| 71 | + *":$INSTALL_DIR:"*) |
| 72 | + info "Run: $BIN install" |
| 73 | + ;; |
| 74 | + *) |
| 75 | + info "Add $INSTALL_DIR to your PATH, then run '$BIN install':" |
| 76 | + info " export PATH=\"$INSTALL_DIR:\$PATH\"" |
| 77 | + ;; |
| 78 | +esac |
0 commit comments