Files
stanp-opencode/install.sh
T
StanPonomarev f527778b29
CI / verify (pull_request) Failing after 8s
feat: split plugins and cleanup
2026-10-04 12:49:41 +02:00

51 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
selection=()
if (($#)); then
if [[ "$#" -ne 2 || "$1" != "--plugins" || ! "$2" =~ ^(agents|multi-work|quota)(,(agents|multi-work|quota))*$ ]]; then
printf 'Usage: %s [--plugins agents,multi-work,quota]\n' "$0" >&2
exit 2
fi
if [[ ",$2," == *,multi-work,* && ",$2," != *,agents,* ]]; then
printf 'Multi-work requires Agents\n' >&2
exit 2
fi
selection=("$2")
fi
for command in bun curl jq sha256sum tar; do
command -v "$command" >/dev/null || { printf 'Required command not found: %s\n' "$command" >&2; exit 1; }
done
config="${OPENCODE_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/opencode}"
mkdir -p "$config"
config=$(cd "$config" && pwd -P)
mkdir -p "$config/plugins"
install=$(mktemp -d "$config/install.stanp-opencode.XXXXXXXX")
cleanup() {
if [[ -n "$install" ]]; then rm -rf "$install"; fi
}
trap cleanup EXIT
api='https://git.krtss.de/api/v1/repos/StanPonomarev/stanp-opencode/releases/latest'
curl --fail-with-body --silent --show-error --location --proto '=https' --proto-redir '=https' "$api" -o "$install/release.json"
for asset in stanp-opencode.tgz stanp-opencode.tgz.sha256; do
url=$(jq -er --arg name "$asset" '[.assets[] | select(.name == $name)] | if length == 1 then .[0] | select((.id | type) == "number" and (.browser_download_url | type) == "string" and (.browser_download_url | startswith("https://"))) | "\(.browser_download_url)?asset_id=\(.id)" else error("Missing or duplicate release asset: " + $name) end' "$install/release.json")
curl --fail-with-body --silent --show-error --location --proto '=https' --proto-redir '=https' "$url" -o "$install/$asset"
done
read -r checksum _ < "$install/stanp-opencode.tgz.sha256"
if [[ ! "$checksum" =~ ^[a-fA-F0-9]{64}$ ]]; then
printf 'Invalid release checksum\n' >&2
exit 1
fi
hash_output=$(sha256sum "$install/stanp-opencode.tgz")
read -r actual _ <<< "$hash_output"
if [[ ! "$actual" =~ ^[a-fA-F0-9]{64}$ || "$actual" != "$checksum" ]]; then
printf 'Release checksum mismatch; installation unchanged\n' >&2
exit 1
fi
tar -xzf "$install/stanp-opencode.tgz" -C "$install"
bun "$install/package/dist/install.js" "$install/package" "$config" "${selection[@]}"