#!/bin/sh # NodeCE installer (customer-distribution spec ยง3). # # curl -fsSL https://get.nodece.se | bash # # Prefer to read it first? curl -fsSLO https://get.nodece.se/install.sh, then bash install.sh. # # It downloads the nodece CLI for this machine from https://get.nodece.se/latest/, checks it against SHA256SUMS, checks the # signature on SHA256SUMS when cosign is installed (printing the fingerprint of the key that verified it), and # installs /usr/local/bin/nodece plus the Docker credential helper /usr/local/bin/docker-credential-nodece (a link to # the same binary). It changes nothing else. # # To check the signature with a key you got elsewhere (verifying-images.md) instead of the one printed below: # # NODECE_SIGNING_KEY=./nodece.pub bash install.sh # # Environment: NODECE_GET_URL (download origin), NODECE_SIGNING_KEY (a PEM public key file; needs cosign), # HTTPS_PROXY and CURL_CA_BUNDLE (curl reads both itself). set -eu GET_URL="${NODECE_GET_URL:-https://get.nodece.se}" INSTALL_DIR=/usr/local/bin say() { printf '%s\n' "$*"; } die() { printf 'nodece installer: %s\n' "$*" >&2 exit 1 } [ "$(uname -s)" = Linux ] || die "NodeCE runs on Linux, not $(uname -s)." case "$(uname -m)" in x86_64 | amd64) arch=amd64 ;; aarch64 | arm64) arch=arm64 ;; *) die "unsupported CPU $(uname -m); NodeCE needs x86_64 or aarch64." ;; esac command -v curl >/dev/null 2>&1 || die "curl is required." tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT INT TERM fetch() { curl -fsS --retry 3 -o "$tmp/$1" "$GET_URL/latest/$1" || die "could not download $GET_URL/latest/$1" } binary="nodece-linux-$arch" version="$(curl -fsS "$GET_URL/latest/version" 2>/dev/null || true)" say "Downloading nodece ${version:-(latest)} for linux/$arch from $GET_URL" fetch "$binary" fetch SHA256SUMS if command -v sha256sum >/dev/null 2>&1; then sha256() { sha256sum | awk '{ print $1 }'; } elif command -v shasum >/dev/null 2>&1; then sha256() { shasum -a 256 | awk '{ print $1 }'; } else die "sha256sum or shasum is required to check the download." fi # 1. The binary must match its line in SHA256SUMS. expected="$(awk -v f="$binary" '$2 == f || $2 == "*" f { print $1 }' "$tmp/SHA256SUMS")" [ -n "$expected" ] || die "SHA256SUMS has no line for $binary." actual="$(sha256 <"$tmp/$binary")" [ "$expected" = "$actual" ] || die "checksum mismatch for $binary (expected $expected, got $actual)." say "Checksum OK" # 2. SHA256SUMS must be signed with the NodeCE image-signing key (only when cosign is installed). The signature is # not in the public transparency log, so the log lookup is skipped; the key check still applies. The fingerprint # printed is the SHA-256 of the key (DER), as verifying-images.md lists it. if [ -n "${NODECE_SIGNING_KEY:-}" ]; then [ -r "$NODECE_SIGNING_KEY" ] || die "cannot read $NODECE_SIGNING_KEY." command -v cosign >/dev/null 2>&1 || die "install cosign to check the signature with $NODECE_SIGNING_KEY." cat "$NODECE_SIGNING_KEY" >"$tmp/signing-keys.txt" elif command -v cosign >/dev/null 2>&1; then cat >"$tmp/signing-keys.txt" <<'KEYS' -----BEGIN PUBLIC KEY----- MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE4zymguE6Xj2KEGdfMYiavr3ZM1F+ W10EZnoPs04S6n/xKKpjgblm7K+BopWm3gHfz0IlCU0BUaUeCQgRVqWbWw== -----END PUBLIC KEY----- KEYS fi if [ -f "$tmp/signing-keys.txt" ]; then fetch SHA256SUMS.sigstore.json # One file per key: during a key rotation either may have signed. awk -v dir="$tmp" '/BEGIN PUBLIC KEY/ { n++ } { print > (dir "/key" n ".pem") }' "$tmp/signing-keys.txt" verified="" for key in "$tmp"/key*.pem; do if cosign verify-blob --key "$key" --bundle "$tmp/SHA256SUMS.sigstore.json" --insecure-ignore-tlog=true \ "$tmp/SHA256SUMS" >/dev/null 2>&1; then verified="$key" break fi done [ -n "$verified" ] || die "the signature on SHA256SUMS does not verify with ${NODECE_SIGNING_KEY:-the NodeCE image-signing key}." fingerprint="$(sed -n '/BEGIN PUBLIC KEY/,/END PUBLIC KEY/p' "$verified" | sed '/-----/d' | tr -d ' \r\n' | base64 -d | sha256)" say "Signature OK, key fingerprint $fingerprint" else say "cosign is not installed, so the signature on SHA256SUMS was not checked." fi # 3. Install. Replace by rename, so a running nodece is never overwritten in place. sudo="" if [ "$(id -u)" -ne 0 ] && ! [ -w "$INSTALL_DIR" ]; then command -v sudo >/dev/null 2>&1 || die "run as root, or install sudo, to write to $INSTALL_DIR." sudo=sudo fi chmod 0755 "$tmp/$binary" $sudo mkdir -p "$INSTALL_DIR" $sudo cp "$tmp/$binary" "$INSTALL_DIR/.nodece.new" $sudo chmod 0755 "$INSTALL_DIR/.nodece.new" $sudo mv -f "$INSTALL_DIR/.nodece.new" "$INSTALL_DIR/nodece" $sudo ln -sf nodece "$INSTALL_DIR/docker-credential-nodece" say "" say "Installed $INSTALL_DIR/nodece and $INSTALL_DIR/docker-credential-nodece." say "Next, with the invitation file you received from NodeCE:" say "" say " sudo nodece install --credential ./invitation.json --hostname "