roneoinstall.sh
98ff76d5794bbd1480ad719803187d2c40e42403- #!/bin/sh
- # Install Ronéo from https://code.cleyrop.tech/roneo releases with SHA-256 verification.
- #
- # Usage:
- # curl -fsSL https://code.cleyrop.tech/roneo/raw/main/install.sh | sh
- # RONEO_VERSION=v0.1.0 sh install.sh
- # RONEO_INSTALL_DIR=/usr/local/bin sh install.sh
- set -eu
- FORGE_URL="${RONEO_FORGE_URL:-https://code.cleyrop.tech}"
- REPO="${RONEO_REPO:-roneo}"
- VERSION="${RONEO_VERSION:-latest}"
- INSTALL_DIR="${RONEO_INSTALL_DIR:-${HOME}/.local/bin}"
- need_cmd() {
- if ! command -v "$1" >/dev/null 2>&1; then
- printf 'error: required command not found: %s\n' "$1" >&2
- exit 1
- fi
- }
- detect_os() {
- case "$(uname -s)" in
- Linux*) printf 'linux' ;;
- Darwin*) printf 'darwin' ;;
- *)
- printf 'error: unsupported OS: %s\n' "$(uname -s)" >&2
- exit 1
- ;;
- esac
- }
- detect_arch() {
- case "$(uname -m)" in
- x86_64 | amd64) printf 'amd64' ;;
- aarch64 | arm64) printf 'arm64' ;;
- *)
- printf 'error: unsupported architecture: %s\n' "$(uname -m)" >&2
- exit 1
- ;;
- esac
- }
- sha256_file() {
- if command -v sha256sum >/dev/null 2>&1; then
- sha256sum "$1" | awk '{print $1}'
- elif command -v shasum >/dev/null 2>&1; then
- shasum -a 256 "$1" | awk '{print $1}'
- else
- printf 'error: neither sha256sum nor shasum found\n' >&2
- exit 1
- fi
- }
- main() {
- need_cmd curl
- need_cmd uname
- os="$(detect_os)"
- arch="$(detect_arch)"
- api_url="${FORGE_URL}/api/v1/repos/${REPO}/releases/${VERSION}"
- tmpdir="$(mktemp -d)"
- trap 'rm -rf "$tmpdir"' EXIT INT TERM
- meta_file="${tmpdir}/release.json"
- printf 'Fetching %s release metadata (%s/%s)...\n' "$REPO" "$os" "$arch"
- curl -fsSL -H 'Accept: application/json' "$api_url" -o "$meta_file"
- # Resolve asset url, sha256, and tag from the forge-public JSON schema (lot 7).
- # Uses python3 if available, otherwise jq (no `eval`).
- parsed_file="${tmpdir}/parsed.txt"
- if command -v python3 >/dev/null 2>&1; then
- python3 -c '
- import json, sys
- data = json.load(open(sys.argv[1]))
- os_name, arch_name = sys.argv[2], sys.argv[3]
- tag = data.get("tag") or data.get("version") or ""
- match = None
- for a in data.get("assets", []):
- if a.get("bin", "roneo") == "roneo" and a.get("os") == os_name and a.get("arch") == arch_name:
- match = a
- break
- if not match:
- sys.stderr.write(f"error: no roneo release asset found for {os_name}/{arch_name} in {tag}\n")
- sys.exit(1)
- print(tag)
- print(match["url"])
- print(match.get("sha256", ""))
- ' "$meta_file" "$os" "$arch" > "$parsed_file"
- elif command -v jq >/dev/null 2>&1; then
- jq -r --arg os "$os" --arg arch "$arch" '
- (.tag // .version // ""),
- ([.assets[] | select((.bin // "roneo") == "roneo" and .os == $os and .arch == $arch)][0] | (.url // ""), (.sha256 // ""))
- ' "$meta_file" > "$parsed_file"
- else
- printf 'error: python3 or jq is required to parse release metadata\n' >&2
- exit 1
- fi
- {
- IFS= read -r TAG || true
- IFS= read -r ASSET_URL || true
- IFS= read -r ASSET_SHA256 || true
- } < "$parsed_file"
- if [ -z "$ASSET_URL" ]; then
- printf 'error: no roneo release asset found for %s/%s\n' "$os" "$arch" >&2
- exit 1
- fi
- case "$ASSET_URL" in
- http://*|https://*) download_url="$ASSET_URL" ;;
- /*) download_url="${FORGE_URL}${ASSET_URL}" ;;
- *) download_url="${FORGE_URL}/${ASSET_URL}" ;;
- esac
- dl_path="${tmpdir}/asset"
- printf 'Downloading roneo %s (%s/%s)...\n' "$TAG" "$os" "$arch"
- curl -fsSL "$download_url" -o "$dl_path"
- if [ -n "$ASSET_SHA256" ]; then
- actual="$(sha256_file "$dl_path")"
- if [ "$actual" != "$ASSET_SHA256" ]; then
- printf 'error: SHA-256 mismatch!\n expected: %s\n actual: %s\n' "$ASSET_SHA256" "$actual" >&2
- exit 1
- fi
- printf 'Verified SHA-256: %s\n' "$actual"
- fi
- bin_src="$dl_path"
- case "$download_url" in
- *.tar.gz|*.tgz)
- need_cmd tar
- mkdir -p "${tmpdir}/extract"
- tar -xzf "$dl_path" -C "${tmpdir}/extract"
- bin_src="$(find "${tmpdir}/extract" -type f -name roneo | head -n 1)"
- ;;
- *.zip)
- need_cmd unzip
- mkdir -p "${tmpdir}/extract"
- unzip -q "$dl_path" -d "${tmpdir}/extract"
- bin_src="$(find "${tmpdir}/extract" -type f -name roneo | head -n 1)"
- ;;
- esac
- if [ -z "$bin_src" ] || [ ! -f "$bin_src" ]; then
- printf 'error: downloaded asset did not contain a roneo binary\n' >&2
- exit 1
- fi
- mkdir -p "$INSTALL_DIR"
- chmod 0755 "$bin_src"
- mv -f "$bin_src" "${INSTALL_DIR}/roneo"
- printf 'Installed roneo %s -> %s/roneo\n' "$TAG" "$INSTALL_DIR"
- case ":${PATH}:" in
- *":${INSTALL_DIR}:"*) ;;
- *) printf 'Note: add %s to your PATH to run roneo directly.\n' "$INSTALL_DIR" ;;
- esac
- }
- main "$@"