#!/bin/sh # sc — the someones.computer deploy agent. # # curl -fsSL https://app.someones.computer/install.sh | sh # # Installs a single static binary. Nothing else is written, no daemon is # started, and uninstalling is `rm` on the path it prints. set -eu CHANNEL='stable' VERSION='0.1.0' ENDPOINT="${SC_INSTALL_ENDPOINT:-https://app.someones.computer}" # Where the binary lands. Resolved below: /usr/local/bin when that is writable, # ~/.local/bin otherwise. $SC_INSTALL_DIR overrides both. PREFIX="${SC_INSTALL_DIR:-}" say() { printf '%s\n' "$*"; } die() { printf 'sc: %s\n' "$*" >&2; exit 1; } # ---------------------------------------------------------------- platform -- os=$(uname -s | tr '[:upper:]' '[:lower:]') arch=$(uname -m) case "$os" in linux|darwin) ;; msys*|mingw*|cygwin*) die "this script is for Linux and macOS — take the Windows zip from $ENDPOINT/install" ;; *) die "unsupported operating system: $os" ;; esac case "$arch" in x86_64|amd64) arch=amd64 ;; aarch64|arm64) arch=arm64 ;; *) die "unsupported architecture: $arch" ;; esac # The archive and its checksum, one branch per published build. Written out # rather than derived so a platform this release does not cover is a clear # message instead of a 404 halfway through a download. case "$os/$arch" in 'darwin/amd64') archive='sc_0.1.0_darwin_amd64.tar.gz'; checksum='c1788f789b0965f837aea9c080986992a9c0dd870f886c651a59e304ca77bea8' ;; 'darwin/arm64') archive='sc_0.1.0_darwin_arm64.tar.gz'; checksum='61535572007eec2d5657c02190e865596a10aa565c567e4bde0177907ab56022' ;; 'linux/amd64') archive='sc_0.1.0_linux_amd64.tar.gz'; checksum='c12bfdb7993e59d2e288e611482558f0e3cab1c54d54a2bb20a450abd66df661' ;; 'linux/arm64') archive='sc_0.1.0_linux_arm64.tar.gz'; checksum='97b124de2eaac672fc1e72a726179c059d7daae1ebc42ba45d57cc94f1c47b91' ;; *) die "no sc 0.1.0 build for $os/$arch — see $ENDPOINT/install" ;; esac # ------------------------------------------------------------------- fetch -- if command -v curl >/dev/null 2>&1; then fetch() { curl -fsSL "$1" -o "$2"; } elif command -v wget >/dev/null 2>&1; then fetch() { wget -qO "$2" "$1"; } else die 'neither curl nor wget is installed' fi tmp=$(mktemp -d "${TMPDIR:-/tmp}/sc-install.XXXXXX") # Covers the error paths too, which is most of them: every `die` past this point # exits through the trap. trap 'rm -rf "$tmp"' EXIT INT TERM say "Downloading sc $VERSION ($CHANNEL) for $os/$arch…" fetch "$ENDPOINT/install/$CHANNEL/$os/$arch" "$tmp/$archive" \ || die "download failed: $ENDPOINT/install/$CHANNEL/$os/$arch" # ------------------------------------------------------------------ verify -- # sha256sum on Linux, shasum -a 256 on macOS. A machine with neither is not # waved through: shipping an unverified binary is the one thing this will not do. if command -v sha256sum >/dev/null 2>&1; then actual=$(sha256sum "$tmp/$archive" | cut -d' ' -f1) elif command -v shasum >/dev/null 2>&1; then actual=$(shasum -a 256 "$tmp/$archive" | cut -d' ' -f1) else die 'no sha256sum or shasum available to verify the download' fi [ "$actual" = "$checksum" ] || die "checksum mismatch for $archive expected $checksum got $actual" tar -xzf "$tmp/$archive" -C "$tmp" || die "could not unpack $archive" [ -f "$tmp/sc" ] || die "$archive did not contain an sc binary" # ----------------------------------------------------------------- install -- if [ -z "$PREFIX" ]; then if [ -w /usr/local/bin ]; then PREFIX=/usr/local/bin else # No silent `sudo`: a machine where /usr/local/bin needs root gets a # per-user install, which needs no privilege and is trivial to undo. PREFIX="$HOME/.local/bin" fi fi mkdir -p "$PREFIX" || die "cannot create $PREFIX" install -m 0755 "$tmp/sc" "$PREFIX/sc" || die "cannot write $PREFIX/sc" say "Installed sc $VERSION to $PREFIX/sc" # `command -v` rather than a $PATH substring test: what matters is whether the # shell would find *this* sc, and a stale copy earlier in PATH is worth saying. found=$(command -v sc 2>/dev/null || true) if [ "$found" != "$PREFIX/sc" ]; then say '' if [ -n "$found" ]; then say "Note: \`sc\` still resolves to $found, not the copy just installed." else say "Note: $PREFIX is not on your PATH. Add it:" say '' say " export PATH=\"$PREFIX:\$PATH\"" fi fi say '' say 'Next: sign in, then deploy from your project directory.' say '' say ' sc login --endpoint https://app.someones.computer' say ' sc deploy'