Files
oh-my-pi/scripts/install.sh
T
can1357 5ec30e19f4 feat(scripts): added --ref flag for installing specific git refs
- Added --ref flag to install specific tags, branches, or commits from source or binary releases.
- Enabled source installation from git refs by cloning and checking out the specified reference.
- Added git availability check for source installations with --ref flag.
- Updated README with usage examples for --ref flag on both shell and PowerShell installers.
2026-01-06 22:01:24 +00:00

193 lines
4.7 KiB
Bash
Executable File

#!/bin/sh
set -e
# OMP 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
# --ref <ref> Install specific tag/commit/branch
# -r <ref> Shorthand for --ref
REPO="can1357/oh-my-pi"
PACKAGE="@oh-my-pi/omp-coding-agent"
INSTALL_DIR="${OMP_INSTALL_DIR:-$HOME/.local/bin}"
# Parse arguments
MODE=""
REF=""
while [ $# -gt 0 ]; do
case "$1" in
--source)
MODE="source"
shift
;;
--binary)
MODE="binary"
shift
;;
--ref)
shift
if [ -z "$1" ]; then
echo "Missing value for --ref"
exit 1
fi
REF="$1"
shift
;;
--ref=*)
REF="${1#*=}"
shift
;;
-r)
shift
if [ -z "$1" ]; then
echo "Missing value for -r"
exit 1
fi
REF="$1"
shift
;;
*)
shift
;;
esac
done
# If a ref is provided, default to source install
if [ -n "$REF" ] && [ -z "$MODE" ]; then
MODE="source"
fi
# Check if bun is available
has_bun() {
command -v bun >/dev/null 2>&1
}
# Check if git is available
has_git() {
command -v git >/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..."
if [ -n "$REF" ]; then
if ! has_git; then
echo "git is required for --ref when installing from source"
exit 1
fi
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
if git clone --depth 1 --branch "$REF" "https://github.com/${REPO}.git" "$TMP_DIR" >/dev/null 2>&1; then
:
else
git clone "https://github.com/${REPO}.git" "$TMP_DIR"
(cd "$TMP_DIR" && git checkout "$REF")
fi
if [ ! -d "$TMP_DIR/packages/coding-agent" ]; then
echo "Expected package at ${TMP_DIR}/packages/coding-agent"
exit 1
fi
bun install -g "$TMP_DIR/packages/coding-agent"
else
bun install -g "$PACKAGE"
fi
echo ""
echo "✓ Installed omp via bun"
echo "Run 'omp' 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="omp-${PLATFORM}-${ARCH}"
# Get release tag
if [ -n "$REF" ]; then
echo "Fetching release $REF..."
if RELEASE_JSON=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/tags/${REF}"); then
LATEST=$(echo "$RELEASE_JSON" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
else
echo "Release tag not found: $REF"
echo "For branch/commit installs, use --source with --ref."
exit 1
fi
else
echo "Fetching latest release..."
RELEASE_JSON=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest")
LATEST=$(echo "$RELEASE_JSON" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
fi
if [ -z "$LATEST" ]; then
echo "Failed to fetch release tag"
exit 1
fi
echo "Using 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}/omp"
chmod +x "${INSTALL_DIR}/omp"
echo ""
echo "✓ Installed omp to ${INSTALL_DIR}/omp"
# Check if in PATH
case ":$PATH:" in
*":$INSTALL_DIR:"*) echo "Run 'omp' to get started!" ;;
*) echo "Add ${INSTALL_DIR} to your PATH, then run 'omp'" ;;
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