Skip to content

Commit 175bc75

Browse files
Install scripts (#16)
1 parent 4d396f2 commit 175bc75

7 files changed

Lines changed: 203 additions & 5 deletions

File tree

.github/workflows/release.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ jobs:
2020
go-version-file: go.mod
2121

2222
- name: Build and package all targets
23+
env:
24+
TAG: ${{ github.event.release.tag_name }}
2325
run: |
2426
mkdir -p dist build
27+
ver="${TAG#v}" # strip a leading "v" if present
28+
ldflags="-s -w -X github.com/php-debugger/installer/internal/version.Version=${ver}"
2529
# Windows-on-ARM runs x64 under emulation, so one Windows build suffices.
2630
for target in linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64; do
2731
goos="${target%/*}"; arch="${target#*/}"
@@ -31,7 +35,7 @@ jobs:
3135
3236
echo "building $osname/$arch"
3337
CGO_ENABLED=0 GOOS="$goos" GOARCH="$arch" \
34-
go build -trimpath -ldflags "-s -w" -o "build/$bin" .
38+
go build -trimpath -ldflags "$ldflags" -o "build/$bin" .
3539
chmod +x "build/$bin"
3640
3741
# Package into an archive so the executable bit survives download
@@ -44,6 +48,9 @@ jobs:
4448
fi
4549
rm -f "build/$bin"
4650
done
51+
# Attach the install scripts too, so releases/latest/download/install.sh
52+
# is a stable URL that serves the released version of the script.
53+
cp scripts/install.sh scripts/install.ps1 dist/
4754
ls -la dist
4855
4956
- name: Attach binaries to the release

README.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,28 @@ pulls the **latest release** and auto-detects your OS and architecture.
77

88
## Installation
99

10+
### Install script (recommended)
11+
12+
macOS / Linux:
13+
14+
```bash
15+
curl -fsSL https://github.com/php-debugger/installer/releases/latest/download/install.sh | sh
16+
```
17+
18+
Windows (PowerShell):
19+
20+
```powershell
21+
powershell -c "irm https://github.com/php-debugger/installer/releases/latest/download/install.ps1 | iex"
22+
```
23+
24+
The script detects your OS/arch, downloads the right archive, and installs the
25+
binary (into the current directory by default; set `INSTALL_DIR` to change it, or
26+
`VERSION` to pin a release). Because it fetches with `curl`/`wget` rather than a
27+
browser, the binary is **not quarantined**, so macOS Gatekeeper doesn't block it.
28+
1029
### Download a prebuilt binary
1130

12-
Grab the archive for your platform from the
31+
Alternatively, grab the archive for your platform from the
1332
[Releases page](https://github.com/php-debugger/installer/releases):
1433

1534
| Platform | Asset |
@@ -20,16 +39,22 @@ Grab the archive for your platform from the
2039
| Linux (arm64) | `php-debugger-linux-arm64.tar.gz` |
2140
| Windows (x64) | `php-debugger-windows-amd64.zip` |
2241

23-
On macOS/Linux, extract **in the terminal** (not by double-clicking in Finder).
24-
Command-line `tar` keeps the executable bit and avoids macOS Gatekeeper flagging
25-
the binary — no `chmod` or "allow anyway" needed:
42+
Extract it (command-line `tar` keeps the executable bit) and put it on your PATH:
2643

2744
```bash
2845
tar -xzf php-debugger-macos-arm64.tar.gz
2946
mv php-debugger /usr/local/bin/ # or ~/.local/bin
3047
php-debugger --help
3148
```
3249

50+
On macOS, a binary downloaded through a **browser** is quarantined, so Gatekeeper
51+
shows "Apple could not verify…". These builds are ad-hoc signed but not notarized,
52+
so clear the quarantine flag once (the install script above avoids this entirely):
53+
54+
```bash
55+
xattr -d com.apple.quarantine ./php-debugger
56+
```
57+
3358
On Windows, unzip the archive and put `php-debugger.exe` somewhere on your PATH.
3459

3560
### Build from source

internal/cli/root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"os"
66

7+
"github.com/php-debugger/installer/internal/version"
78
"github.com/spf13/cobra"
89
)
910

@@ -27,6 +28,7 @@ func newRootCmd() *cobra.Command {
2728
Long: "php-debugger installs the PHP debugger from the php-debugger/php-debugger\n" +
2829
"GitHub releases: either a self-contained PHP interpreter with the debugger\n" +
2930
"compiled in (default), or the debugger extension for an existing PHP.",
31+
Version: version.Version,
3032
SilenceUsage: true,
3133
SilenceErrors: true,
3234
}
@@ -45,6 +47,7 @@ func newRootCmd() *cobra.Command {
4547
newUninstallCmd(),
4648
newSwitchCmd(),
4749
newResolveCmd(),
50+
newVersionCmd(),
4851
)
4952

5053
return rootCmd

internal/cli/version.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
"runtime"
6+
7+
"github.com/php-debugger/installer/internal/platform"
8+
"github.com/php-debugger/installer/internal/version"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
func newVersionCmd() *cobra.Command {
13+
return &cobra.Command{
14+
Use: "version",
15+
Short: "Print the installer version",
16+
Args: cobra.NoArgs,
17+
RunE: func(cmd *cobra.Command, args []string) error {
18+
plat := runtime.GOOS + "/" + runtime.GOARCH
19+
if p, err := platform.Detect(); err == nil {
20+
plat = p.String()
21+
}
22+
fmt.Fprintf(cmd.OutOrStdout(), "php-debugger %s (%s)\n", version.Version, plat)
23+
return nil
24+
},
25+
}
26+
}

internal/version/version.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Package version holds the installer's build version.
2+
package version
3+
4+
// Version is the installer version. It is "dev" for local builds; release builds
5+
// override it with the release tag via:
6+
//
7+
// -ldflags "-X github.com/php-debugger/installer/internal/version.Version=<tag>"
8+
var Version = "dev"

scripts/install.ps1

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<#
2+
.SYNOPSIS
3+
php-debugger installer bootstrap (Windows).
4+
5+
.DESCRIPTION
6+
Downloads the latest php-debugger release for Windows and installs the binary.
7+
8+
Usage:
9+
powershell -c "irm https://github.com/php-debugger/installer/releases/latest/download/install.ps1 | iex"
10+
11+
Environment overrides:
12+
$env:INSTALL_DIR where to place the binary (default: current directory)
13+
#>
14+
15+
$ErrorActionPreference = "Stop"
16+
17+
$Repo = "php-debugger/installer"
18+
$Bin = "php-debugger.exe"
19+
$InstallDir = if ($env:INSTALL_DIR) { $env:INSTALL_DIR } else { (Get-Location).Path }
20+
21+
# Only one Windows build is published (x64); Windows-on-ARM runs it via emulation.
22+
$Asset = "php-debugger-windows-amd64.zip"
23+
24+
# The releases/latest/download URL always resolves to the newest release.
25+
$Url = "https://github.com/$Repo/releases/latest/download/$Asset"
26+
Write-Host "Installing $Bin (latest, windows/amd64)"
27+
28+
$tmp = Join-Path $env:TEMP ("php-debugger-" + [System.Guid]::NewGuid().ToString())
29+
New-Item -ItemType Directory -Path $tmp | Out-Null
30+
try {
31+
$zip = Join-Path $tmp $Asset
32+
Invoke-WebRequest -UseBasicParsing -Uri $Url -OutFile $zip
33+
Expand-Archive -Path $zip -DestinationPath $tmp -Force
34+
35+
$src = Join-Path $tmp $Bin
36+
if (-not (Test-Path $src)) { throw "archive did not contain $Bin" }
37+
38+
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
39+
Move-Item -Force $src (Join-Path $InstallDir $Bin)
40+
} finally {
41+
Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue
42+
}
43+
44+
Write-Host ""
45+
Write-Host "Installed to $InstallDir\$Bin"
46+
$onPath = ($env:PATH -split ';') -contains $InstallDir
47+
if ($onPath) {
48+
Write-Host "Run: php-debugger install"
49+
} else {
50+
Write-Host "Add $InstallDir to your PATH, then run 'php-debugger install'."
51+
}

scripts/install.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

Comments
 (0)