#!/bin/sh # Installs Onset: `curl -fsSL https://downloads.coline.dev/onset/install.sh | sh` # # Picks the build for this OS and CPU from the channel's manifest, checks its # SHA-256 before trusting it, keeps each version in its own folder and links # ~/.local/bin/on to it. Running it again updates in place. set -eu CHANNEL="${ONSET_INSTALL_CHANNEL:-${VCS_INSTALL_CHANNEL:-stable}}" BASE="${ONSET_DOWNLOADS:-${VCS_DOWNLOADS:-https://downloads.coline.dev/onset}}" INSTALL_DIR="${ONSET_INSTALL_DIR:-${VCS_INSTALL_DIR:-$HOME/.local/share/coline/onset}}" BIN_DIR="${ONSET_BIN_DIR:-${VCS_BIN_DIR:-$HOME/.local/bin}}" fail() { echo "Onset install: $1" >&2; exit 1; } case "$CHANNEL" in stable | latest) ;; *) fail "unknown channel '$CHANNEL' (stable or latest)" ;; esac command -v curl >/dev/null 2>&1 || fail "curl is required" command -v tar >/dev/null 2>&1 || fail "tar is required" case "$(uname -s)-$(uname -m)" in Darwin-arm64) platform=darwin-arm64 ;; Darwin-x86_64) platform=darwin-x64 ;; Linux-x86_64) platform=linux-x64 ;; Linux-aarch64 | Linux-arm64) platform=linux-arm64 ;; *) fail "no build for $(uname -s) on $(uname -m) yet" ;; esac manifest="$(curl -fsSL "$BASE/$CHANNEL.json")" || fail "couldn't fetch $BASE/$CHANNEL.json" # The manifest has one platform per line, so a line holds a build's URL and checksum. version="$(printf '%s\n' "$manifest" | sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' | head -1)" printf '%s' "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+([-+][A-Za-z0-9.-]+)?$' || fail "the manifest has no valid version" line="$(printf '%s\n' "$manifest" | grep "\"$platform\"" || true)" url="$(printf '%s' "$line" | sed -n 's/.*"url": *"\([^"]*\)".*/\1/p')" sha="$(printf '%s' "$line" | sed -n 's/.*"sha256": *"\([0-9a-f]*\)".*/\1/p')" [ -n "$url" ] && [ -n "$sha" ] || fail "release $version has no build for $platform" tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT echo "Downloading Onset $version ($platform)..." curl -fsSL "$url" -o "$tmp/onset.tar.gz" || fail "download failed" if command -v sha256sum >/dev/null 2>&1; then got="$(sha256sum "$tmp/onset.tar.gz" | cut -d' ' -f1)"; else got="$(shasum -a 256 "$tmp/onset.tar.gz" | cut -d' ' -f1)"; fi [ "$got" = "$sha" ] || fail "checksum mismatch: the download isn't the published build" mkdir -p "$tmp/x" "$INSTALL_DIR/$version" "$BIN_DIR" tar -xzf "$tmp/onset.tar.gz" -C "$tmp/x" [ -f "$tmp/x/on" ] && [ ! -L "$tmp/x/on" ] || fail "the archive is missing the on executable" chmod +x "$tmp/x/on" "$tmp/x/on" --version >/dev/null 2>&1 || fail "the downloaded on doesn't run on this machine" mv -f "$tmp/x/on" "$INSTALL_DIR/$version/on" ln -sfn "$INSTALL_DIR/$version/on" "$BIN_DIR/on" # Onset was called vcs before it had its name: that command goes, and on # picks up where it left off (sign-ins, projects, workspaces). if [ -L "$BIN_DIR/vcs" ] && readlink "$BIN_DIR/vcs" | grep -q "/coline/vcs/"; then rm -f "$BIN_DIR/vcs" echo "vcs is now Onset: its command is on, with your sign-ins, projects and workspaces as they were" fi echo "Installed Onset $version at $BIN_DIR/on" case ":$PATH:" in *":$BIN_DIR:"*) ;; *) echo "Add $BIN_DIR to your PATH, for example: echo 'export PATH=\"$BIN_DIR:\$PATH\"' >> ~/.profile" ;; esac echo "Next: on login, then on get upstream.codes//"