Onset: version control where nobody waits and nothing gets lost. The on command, its core and onset-server.
| 6 | # ~/.local/bin/on to it. Running it again updates in place. |
| 7 |
| 8 | set -eu |
| 9 |
| 10 | CHANNEL="${ONSET_INSTALL_CHANNEL:-${VCS_INSTALL_CHANNEL:-stable}}" |
| 11 | BASE="${ONSET_DOWNLOADS:-${VCS_DOWNLOADS:-https://downloads.coline.dev/onset}}" |
| 12 | INSTALL_DIR="${ONSET_INSTALL_DIR:-${VCS_INSTALL_DIR:-$HOME/.local/share/coline/onset}}" |
| 13 | BIN_DIR="${ONSET_BIN_DIR:-${VCS_BIN_DIR:-$HOME/.local/bin}}" |
| 14 |
| 15 | fail() { echo "Onset install: $1" >&2; exit 1; } |
| 16 |
| 17 | case "$CHANNEL" in stable | latest) ;; *) fail "unknown channel '$CHANNEL' (stable or latest)" ;; esac |
| 18 | command -v curl >/dev/null 2>&1 || fail "curl is required" |
| 19 | command -v tar >/dev/null 2>&1 || fail "tar is required" |
| 20 |
| 21 | case "$(uname -s)-$(uname -m)" in |
| 22 | Darwin-arm64) platform=darwin-arm64 ;; |
| 23 | Darwin-x86_64) platform=darwin-x64 ;; |
| 24 | Linux-x86_64) platform=linux-x64 ;; |
| 25 | Linux-aarch64 | Linux-arm64) platform=linux-arm64 ;; |
| 26 | *) fail "no build for $(uname -s) on $(uname -m) yet" ;; |
| 27 | esac |
| 28 |
| 29 | manifest="$(curl -fsSL "$BASE/$CHANNEL.json")" || fail "couldn't fetch $BASE/$CHANNEL.json" |
| 30 | # The manifest has one platform per line, so a line holds a build's URL and checksum. |
| 31 | version="$(printf '%s\n' "$manifest" | sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' | head -1)" |
| 32 | printf '%s' "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+([-+][A-Za-z0-9.-]+)?$' || fail "the manifest has no valid version" |
| 33 | line="$(printf '%s\n' "$manifest" | grep "\"$platform\"" || true)" |
| 34 | url="$(printf '%s' "$line" | sed -n 's/.*"url": *"\([^"]*\)".*/\1/p')" |
| 35 | sha="$(printf '%s' "$line" | sed -n 's/.*"sha256": *"\([0-9a-f]*\)".*/\1/p')" |
| 36 | [ -n "$url" ] && [ -n "$sha" ] || fail "release $version has no build for $platform" |
| 37 |
| 38 | tmp="$(mktemp -d)" |
| 39 | trap 'rm -rf "$tmp"' EXIT |
| 40 | echo "Downloading Onset $version ($platform)..." |
| 41 | curl -fsSL "$url" -o "$tmp/onset.tar.gz" || fail "download failed" |
| 42 | 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 |
| 43 | [ "$got" = "$sha" ] || fail "checksum mismatch: the download isn't the published build" |
| 44 |
| 45 | mkdir -p "$tmp/x" "$INSTALL_DIR/$version" "$BIN_DIR" |
| 46 | tar -xzf "$tmp/onset.tar.gz" -C "$tmp/x" |
| 47 | [ -f "$tmp/x/on" ] && [ ! -L "$tmp/x/on" ] || fail "the archive is missing the on executable" |
| 48 | chmod +x "$tmp/x/on" |
| 49 | "$tmp/x/on" --version >/dev/null 2>&1 || fail "the downloaded on doesn't run on this machine" |
| 50 | mv -f "$tmp/x/on" "$INSTALL_DIR/$version/on" |
| 51 | ln -sfn "$INSTALL_DIR/$version/on" "$BIN_DIR/on" |
| 52 |
| 53 | # Onset was called vcs before it had its name: that command goes, and on |
| 54 | # picks up where it left off (sign-ins, projects, workspaces). |
| 55 | if [ -L "$BIN_DIR/vcs" ] && readlink "$BIN_DIR/vcs" | grep -q "/coline/vcs/"; then |
| 56 | rm -f "$BIN_DIR/vcs" |
| 57 | echo "vcs is now Onset: its command is on, with your sign-ins, projects and workspaces as they were" |
| 58 | fi |
| 59 |
| 60 | echo "Installed Onset $version at $BIN_DIR/on" |
| 61 | case ":$PATH:" in |
| 62 | *":$BIN_DIR:"*) ;; |
| 63 | *) echo "Add $BIN_DIR to your PATH, for example: echo 'export PATH=\"$BIN_DIR:\$PATH\"' >> ~/.profile" ;; |
| 64 | esac |
| 65 | echo "Next: on login, then on get upstream.codes/<owner>/<project>" |
| 66 |