#!/bin/sh # Installs vcs: `curl -fsSL https://downloads.coline.dev/vcs/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/vcs to it. Running it again updates in place. set -eu CHANNEL="${VCS_INSTALL_CHANNEL:-stable}" BASE="${VCS_DOWNLOADS:-https://downloads.coline.dev/vcs}" INSTALL_DIR="${VCS_INSTALL_DIR:-$HOME/.local/share/coline/vcs}" BIN_DIR="${VCS_BIN_DIR:-$HOME/.local/bin}" fail() { echo "vcs 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 vcs $version ($platform)..." curl -fsSL "$url" -o "$tmp/vcs.tar.gz" || fail "download failed" if command -v sha256sum >/dev/null 2>&1; then got="$(sha256sum "$tmp/vcs.tar.gz" | cut -d' ' -f1)"; else got="$(shasum -a 256 "$tmp/vcs.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/vcs.tar.gz" -C "$tmp/x" [ -f "$tmp/x/vcs" ] && [ ! -L "$tmp/x/vcs" ] || fail "the archive has no vcs executable" chmod +x "$tmp/x/vcs" "$tmp/x/vcs" --version >/dev/null 2>&1 || fail "the downloaded vcs doesn't run on this machine" mv -f "$tmp/x/vcs" "$INSTALL_DIR/$version/vcs" ln -sfn "$INSTALL_DIR/$version/vcs" "$BIN_DIR/vcs" echo "Installed vcs $version at $BIN_DIR/vcs" case ":$PATH:" in *":$BIN_DIR:"*) ;; *) echo "Add $BIN_DIR to your PATH, for example: echo 'export PATH=\"$BIN_DIR:\$PATH\"' >> ~/.profile" ;; esac echo "Next: vcs login, then vcs get upstream.codes//"