feat(scripts): added --source and --binary flags for install method control

- Added --source and --binary flags to control installation method in install scripts.
- Enabled automatic bun detection with fallback to prebuilt binary for default installation.
- Added bun-based installation option that installs bun automatically if needed.
- Documented new installer options in README with usage examples.
This commit is contained in:
can1357
2026-01-03 14:37:17 +01:00
parent 937646d0e1
commit d969b0d565
3 changed files with 188 additions and 64 deletions
+11
View File
@@ -43,6 +43,17 @@ curl -fsSL https://raw.githubusercontent.com/can1357/oh-my-pi/main/scripts/insta
irm https://raw.githubusercontent.com/can1357/oh-my-pi/main/scripts/install.ps1 | iex
```
By default, the installer uses bun if available, otherwise downloads the prebuilt binary.
Options:
- `--source` / `-Source`: Install via bun (installs bun first if needed)
- `--binary` / `-Binary`: Always use prebuilt binary
```bash
# Force bun installation
curl -fsSL .../install.sh | sh -s -- --source
```
### Manual download
Download binaries directly from [GitHub Releases](https://github.com/can1357/oh-my-pi/releases/latest).
+76 -23
View File
@@ -1,35 +1,88 @@
# Pi Coding Agent Installer for Windows
# Usage: irm https://raw.githubusercontent.com/can1357/oh-my-pi/main/scripts/install.ps1 | iex
#
# Or with options:
# & ([scriptblock]::Create((irm https://raw.githubusercontent.com/can1357/oh-my-pi/main/scripts/install.ps1))) -Source
# & ([scriptblock]::Create((irm https://raw.githubusercontent.com/can1357/oh-my-pi/main/scripts/install.ps1))) -Binary
param(
[switch]$Source,
[switch]$Binary
)
$ErrorActionPreference = "Stop"
$Repo = "can1357/oh-my-pi"
$Package = "@oh-my-pi/pi-coding-agent"
$InstallDir = if ($env:PI_INSTALL_DIR) { $env:PI_INSTALL_DIR } else { "$env:LOCALAPPDATA\pi" }
$Binary = "pi-windows-x64.exe"
$BinaryName = "pi-windows-x64.exe"
# Get latest release
Write-Host "Fetching latest release..."
$Release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
$Latest = $Release.tag_name
Write-Host "Latest version: $Latest"
function Test-BunInstalled {
try {
$null = Get-Command bun -ErrorAction Stop
return $true
} catch {
return $false
}
}
# Download binary
$Url = "https://github.com/$Repo/releases/download/$Latest/$Binary"
Write-Host "Downloading $Binary..."
function Install-Bun {
Write-Host "Installing bun..."
irm bun.sh/install.ps1 | iex
# Refresh PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "User") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "Machine")
}
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
$OutPath = Join-Path $InstallDir "pi.exe"
Invoke-WebRequest -Uri $Url -OutFile $OutPath
Write-Host ""
Write-Host "Installed pi to $OutPath"
# Add to PATH if not already there
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($UserPath -notlike "*$InstallDir*") {
Write-Host "Adding $InstallDir to PATH..."
[Environment]::SetEnvironmentVariable("Path", "$UserPath;$InstallDir", "User")
Write-Host "Restart your terminal, then run 'pi' to get started!"
} else {
function Install-ViaBun {
Write-Host "Installing via bun..."
bun install -g $Package
Write-Host ""
Write-Host "✓ Installed pi via bun" -ForegroundColor Green
Write-Host "Run 'pi' to get started!"
}
function Install-Binary {
# Get latest release
Write-Host "Fetching latest release..."
$Release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
$Latest = $Release.tag_name
Write-Host "Latest version: $Latest"
# Download binary
$Url = "https://github.com/$Repo/releases/download/$Latest/$BinaryName"
Write-Host "Downloading $BinaryName..."
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
$OutPath = Join-Path $InstallDir "pi.exe"
Invoke-WebRequest -Uri $Url -OutFile $OutPath
Write-Host ""
Write-Host "✓ Installed pi to $OutPath" -ForegroundColor Green
# Add to PATH if not already there
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($UserPath -notlike "*$InstallDir*") {
Write-Host "Adding $InstallDir to PATH..."
[Environment]::SetEnvironmentVariable("Path", "$UserPath;$InstallDir", "User")
Write-Host "Restart your terminal, then run 'pi' to get started!"
} else {
Write-Host "Run 'pi' to get started!"
}
}
# Main logic
if ($Source) {
if (-not (Test-BunInstalled)) {
Install-Bun
}
Install-ViaBun
} elseif ($Binary) {
Install-Binary
} else {
# Default: use bun if available, otherwise binary
if (Test-BunInstalled) {
Install-ViaBun
} else {
Install-Binary
}
}
+101 -41
View File
@@ -3,50 +3,110 @@ set -e
# Pi Coding Agent Installer
# Usage: curl -fsSL https://raw.githubusercontent.com/can1357/oh-my-pi/main/scripts/install.sh | sh
#
# Options:
# --source Install via bun (installs bun if needed)
# --binary Always install prebuilt binary
REPO="can1357/oh-my-pi"
PACKAGE="@oh-my-pi/pi-coding-agent"
INSTALL_DIR="${PI_INSTALL_DIR:-$HOME/.local/bin}"
# Detect platform
OS="$(uname -s)"
ARCH="$(uname -m)"
# Parse arguments
MODE=""
for arg in "$@"; do
case "$arg" in
--source) MODE="source" ;;
--binary) MODE="binary" ;;
esac
done
case "$OS" in
Linux) PLATFORM="linux" ;;
Darwin) PLATFORM="darwin" ;;
*) echo "Unsupported OS: $OS"; exit 1 ;;
esac
case "$ARCH" in
x86_64|amd64) ARCH="x64" ;;
arm64|aarch64) ARCH="arm64" ;;
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac
BINARY="pi-${PLATFORM}-${ARCH}"
# Get latest release tag
echo "Fetching latest release..."
LATEST=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$LATEST" ]; then
echo "Failed to fetch latest release"
exit 1
fi
echo "Latest version: $LATEST"
# Download binary
URL="https://github.com/${REPO}/releases/download/${LATEST}/${BINARY}"
echo "Downloading ${BINARY}..."
mkdir -p "$INSTALL_DIR"
curl -fsSL "$URL" -o "${INSTALL_DIR}/pi"
chmod +x "${INSTALL_DIR}/pi"
echo ""
echo "Installed pi to ${INSTALL_DIR}/pi"
# Check if in PATH
case ":$PATH:" in
*":$INSTALL_DIR:"*) echo "Run 'pi' to get started!" ;;
*) echo "Add ${INSTALL_DIR} to your PATH, then run 'pi'" ;;
# Check if bun is available
has_bun() {
command -v bun >/dev/null 2>&1
}
# Install bun
install_bun() {
echo "Installing bun..."
curl -fsSL https://bun.sh/install | bash
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
}
# Install via bun
install_via_bun() {
echo "Installing via bun..."
bun install -g "$PACKAGE"
echo ""
echo "✓ Installed pi via bun"
echo "Run 'pi' to get started!"
}
# Install binary from GitHub releases
install_binary() {
# Detect platform
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux) PLATFORM="linux" ;;
Darwin) PLATFORM="darwin" ;;
*) echo "Unsupported OS: $OS"; exit 1 ;;
esac
case "$ARCH" in
x86_64|amd64) ARCH="x64" ;;
arm64|aarch64) ARCH="arm64" ;;
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac
BINARY="pi-${PLATFORM}-${ARCH}"
# Get latest release tag
echo "Fetching latest release..."
LATEST=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$LATEST" ]; then
echo "Failed to fetch latest release"
exit 1
fi
echo "Latest version: $LATEST"
# Download binary
URL="https://github.com/${REPO}/releases/download/${LATEST}/${BINARY}"
echo "Downloading ${BINARY}..."
mkdir -p "$INSTALL_DIR"
curl -fsSL "$URL" -o "${INSTALL_DIR}/pi"
chmod +x "${INSTALL_DIR}/pi"
echo ""
echo "✓ Installed pi to ${INSTALL_DIR}/pi"
# Check if in PATH
case ":$PATH:" in
*":$INSTALL_DIR:"*) echo "Run 'pi' to get started!" ;;
*) echo "Add ${INSTALL_DIR} to your PATH, then run 'pi'" ;;
esac
}
# Main logic
case "$MODE" in
source)
if ! has_bun; then
install_bun
fi
install_via_bun
;;
binary)
install_binary
;;
*)
# Default: use bun if available, otherwise binary
if has_bun; then
install_via_bun
else
install_binary
fi
;;
esac