#!/usr/bin/env bash set -euo pipefail # ============================================================================= # Canectic BBS - bootstrap installer # ============================================================================= # # The only thing a new sysop touches. It resolves a release, downloads it, # verifies its checksum, extracts it, and hands off to that release's own # installer. # # No git clone, and no second tree afterwards. The old shape had the sysop # keeping a source directory whose only purpose was to install the thing beside # it, which could be stale, on the wrong branch, or at an untagged commit, with # nothing checking. # # This script is deliberately small and deliberately dumb. Everything version # specific happens in the installer inside the release, so a release can ship a # fixed installer and it takes effect for THAT install rather than the next one. # The same split as the updater's handoff, for the same reason. # # Verify before you run. This audience cares about provenance and it costs one # line: # # curl -fsSLO https://canectic.tranqsoft.com/releases/bootstrap.sh # curl -fsSLO https://canectic.tranqsoft.com/releases/bootstrap.sh.sha256 # sha256sum -c bootstrap.sh.sha256 && bash bootstrap.sh # # Piping straight into a shell works and is not recommended. # # Usage: # ./bootstrap.sh newest stable into /opt/canectic # ./bootstrap.sh --target ~/bbs somewhere else # ./bootstrap.sh --channel development track development builds # ./bootstrap.sh --version 0.9.6a a specific release # ./bootstrap.sh --from ./dist/releases artifacts already on disk # ./bootstrap.sh --download-only fetch and verify, do not install # ./bootstrap.sh --extract-only ./canectic unpack it and stop, so you can # read the docs and run the setup # scripts before installing # ./bootstrap.sh --from DIR DIR may hold only the release # archive, as a file echo delivers # it: its signed MANIFEST is checked # ./bootstrap.sh --no-keyserver do not look the release keys up # on keys.openpgp.org (only after # checking the fingerprint yourself) # ./bootstrap.sh --keyserver URL another keyserver # # A first install needs gpg and, unless --no-keyserver, the internet: the # release keys are looked up on a keyserver, so a key revoked since this script # was written is refused. npm install needs the npm registry anyway, or a # mirror set in .npmrc. # ============================================================================= BASE_URL="${CANECTIC_RELEASES:-https://canectic.tranqsoft.com/releases}" CHANNEL="stable" VERSION="" TARGET="" FROM="" DOWNLOAD_ONLY=false EXTRACT_TO= INSTALL_ARGS=() KEYSERVER="${CANECTIC_KEYSERVER:-https://keys.openpgp.org}" USE_KEYSERVER=true RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; BOLD='\033[1m'; NC='\033[0m' info() { echo -e "${CYAN}->${NC} $1"; } ok() { echo -e "${GREEN}+${NC} $1"; } warn() { echo -e "${YELLOW}!${NC} $1"; } die() { echo -e "${RED}x${NC} $1" >&2; exit 1; } while [[ $# -gt 0 ]]; do case "$1" in --target) TARGET="$2"; shift 2 ;; --channel) CHANNEL="$2"; shift 2 ;; --version) VERSION="$2"; shift 2 ;; --url) BASE_URL="${2%/}"; shift 2 ;; --from) FROM="$2"; shift 2 ;; --download-only) DOWNLOAD_ONLY=true; shift ;; --extract-only) EXTRACT_TO="$2"; shift 2 ;; --keyserver) KEYSERVER="${2%/}"; shift 2 ;; --no-keyserver) USE_KEYSERVER=false; shift ;; --help|-h) sed -n '6,53p' "$0"; exit 0 ;; # Anything else is for the installer inside the release, so a flag it # gains does not need this script changed. *) INSTALL_ARGS+=("$1"); shift ;; esac done # ----------------------------------------------------------------------------- # What we need, checked up front rather than failing partway through a download # ----------------------------------------------------------------------------- need() { command -v "$1" >/dev/null 2>&1 || die "$1 is needed and was not found"; } need unzip need sha256sum command -v gpg >/dev/null 2>&1 || die "gpg is needed to check that the release is ours, and was not found: sudo apt install gnupg" if [[ -z "$FROM" ]] || $USE_KEYSERVER; then if command -v curl >/dev/null 2>&1; then FETCH="curl -fsSL" FETCH_OUT="curl -fsSL -o" elif command -v wget >/dev/null 2>&1; then FETCH="wget -qO-" FETCH_OUT="wget -qO" else die "neither curl nor wget is installed$([[ -n "$FROM" ]] && printf '%s' ' (needed for the keyserver; --no-keyserver after checking the fingerprint yourself)')" fi fi command -v node >/dev/null 2>&1 || die "Node is needed and was not found. Install Node 22 or later; nvm is recommended. See docs/sysop/INSTALL.md" NODE_MAJOR="$(node -p 'process.versions.node.split(".")[0]')" if [[ "$NODE_MAJOR" -lt 22 ]]; then die "Node $(node -p 'process.versions.node') is too old; 22 or later is needed" fi # ----------------------------------------------------------------------------- # Fetch a published file, from a URL or a directory. Both paths land in the same # place so verification and extraction do not care which was used, and a sysop # who fetched an artifact down a file echo uses the identical code. # ----------------------------------------------------------------------------- WORK="$(mktemp -d)" GPGHOME="$WORK/gnupg" mkdir -m 700 "$GPGHOME" # gpg 2.4 can start an agent for a new home; removing the directory does not # stop it. trap 'gpgconf --homedir "$GPGHOME" --kill all >/dev/null 2>&1 || true; rm -rf "$WORK"' EXIT fetch() { local name="$1" dest="$2" if [[ -n "$FROM" ]]; then [[ -f "$FROM/$name" ]] || die "not found in $FROM: $name" cp "$FROM/$name" "$dest" else $FETCH_OUT "$dest" "$BASE_URL/$name" || die "could not fetch $BASE_URL/$name" fi } fetch_text() { local name="$1" if [[ -n "$FROM" ]]; then [[ -f "$FROM/$name" ]] || die "not found in $FROM: $name" cat "$FROM/$name" else $FETCH "$BASE_URL/$name" || die "could not fetch $BASE_URL/$name" fi } # ----------------------------------------------------------------------------- # Resolve # ----------------------------------------------------------------------------- echo "" echo -e "${BOLD}Canectic BBS${NC}" echo "" # A directory holding releases and no index is what a file echo delivers: the # newest stable archive in it is the one, picked by its name here and confirmed # by the CANECTIC.ID inside it before anything is trusted. if [[ -z "$VERSION" && -n "$FROM" && ! -f "$FROM/index-${CHANNEL}.json" ]]; then info "no index in $FROM; looking at the release archives there" VERSION="$(ls -1 "$FROM" | node -e ' var s = ""; process.stdin.on("data", d => s += d).on("end", () => { var num = function (x) { var m = /^(\d+)\.(\d+)\.(\d+)([a-z]?)$/.exec(x || ""); return m ? [+m[1], +m[2], +m[3], m[4] ? m[4].charCodeAt(0) : 999] : null; }; var newer = function (a, b) { for (var k = 0; k < a.length; k++) if (a[k] !== b[k]) return a[k] > b[k]; return false; }; var best = null, bestN = null; for (var name of s.split("\n")) { var m = /^canectic-(.+)\.zip$/i.exec(name.trim()); if (!m) continue; var v = m[1].toLowerCase(), n = num(v); if (!n) continue; if (!bestN || newer(n, bestN)) { best = v; bestN = n; } } if (!best) process.exit(3); process.stdout.write(best); }); ')" || die "no index and no stable release archive in $FROM" elif [[ -z "$VERSION" ]]; then info "looking at the $CHANNEL channel" INDEX="$(fetch_text "index-${CHANNEL}.json")" # The index is newest first, so the first version is the one we want. Parsed # with node rather than with sed: this is a JSON document and the release # tooling that writes it is entitled to add fields. A withdrawn release is # not listed at all; the skip is for the first withdrawal format, which # left the entry in place and marked it. VERSION="$(printf '%s' "$INDEX" | node -e ' var s = ""; process.stdin.on("data", d => s += d).on("end", () => { var i = JSON.parse(s); var r = (i.releases || []).filter(function (x) { return x && !x.superseded_by; }); if (!r.length) { process.exit(3); } process.stdout.write(r[0].version); }); ')" || die "the $CHANNEL channel has no releases published" else # A version asked for by name is still looked up, so a withdrawn release is # refused rather than installed. No index (an artifact directory copied by # hand) is not a reason to refuse anything. NAMED_CHANNEL="$CHANNEL" [[ "$VERSION" =~ \.[0-9]{8}(\.[0-9]+)?$ ]] && NAMED_CHANNEL="development" INDEX="$(fetch_text "index-${NAMED_CHANNEL}.json" 2>/dev/null)" || INDEX="" if [[ -n "$INDEX" ]]; then WITHDRAWN="$(printf '%s' "$INDEX" | NAMED="$VERSION" node -e ' var s = ""; process.stdin.on("data", d => s += d).on("end", () => { var i; try { i = JSON.parse(s); } catch (e) { return; } var v = process.env.NAMED; var w = (i.withdrawn || []).filter(function (x) { return x && x.version === v; })[0] || (i.releases || []).filter(function (x) { return x && x.version === v && x.superseded_by; })[0]; if (!w) return; var why = w.withdrawn_reason || w.superseded_reason; // The named replacement may have been withdrawn since, so the // chain is followed to something listed, and the newest listed // release is named once it is: the same rule as replacementFor // in src/release/releaseIndex.js, which this cannot import. var num = function (x) { var m = /^(\d+)\.(\d+)\.(\d+)([a-z]?)(?:\.(\d{8}))?(?:\.(\d+))?$/.exec(x || ""); return m ? [+m[1], +m[2], +m[3], m[4] ? m[4].charCodeAt(0) : 999, +(m[5] || 0), +(m[6] || 0)] : null; }; var newer = function (a, b) { var x = num(a), y = num(b); if (!x || !y) return false; for (var k = 0; k < x.length; k++) if (x[k] !== y[k]) return x[k] > y[k]; return false; }; var listed = (i.releases || []).filter(function (x) { return x && !x.superseded_by; }); var newest = listed.reduce(function (a, x) { return !a || newer(x.version, a) ? x.version : a; }, null); var gone = function (n) { return (i.withdrawn || []).filter(function (x) { return x && x.version === n; })[0] || (i.releases || []).filter(function (x) { return x && x.version === n && x.superseded_by; })[0]; }; var by = w.superseded_by || null, seen = {}; seen[v] = true; while (by) { if (listed.some(function (x) { return x.version === by; })) { by = newest; break; } var g = gone(by); if (!g) break; seen[by] = true; if (!g.superseded_by || seen[g.superseded_by]) { by = newer(newest, by) ? newest : null; break; } by = g.superseded_by; } process.stdout.write(v + " has been withdrawn" + (why ? " (" + why + ")" : "") + (by ? "; install " + by + " instead" : "")); }); ')" [[ -n "$WITHDRAWN" ]] && die "$WITHDRAWN" fi fi ok "release $VERSION" # ----------------------------------------------------------------------------- # Trust. # # Every key is checked in a private gpg home, so nothing depends on, or changes, # your own keyring. A signature counts only when gpg says a Canectic release # key (RELEASE_KEY_FPRS, below) made it, and one by a key that has been revoked # or has expired is refused. # # Two ways to establish that the release is ours, depending on what is there: # # A signed SHA256SUMS beside the release (the release site, or a copy of it): # signature -> SHA256SUMS -> metadata -> archive, every link checked. The # metadata used to be trusted on its own say-so while the sysop was told # "signature verified"; anyone able to write to the host swapped the archive # and the metadata together and both checks passed. # # The archive alone (a file echo delivers nothing else): the MANIFEST signed # inside it, read out WITHOUT unpacking, then every file it lists checked # against it, and anything it does not list refused, before anything from the # archive runs. # # Either way the release keys are first looked up on a keyserver (unless # --no-keyserver), so a key revoked since this script was written is refused. # ----------------------------------------------------------------------------- gpg_q() { gpg --homedir "$GPGHOME" --batch --no-tty "$@"; } # The Canectic release keys' MASTER fingerprints, the numbers # docs/sysop/INSTALL.md tells you to compare: the active key, and the reserve # kept offline for the day the active one has to be retired (#109). Kept equal to signing.RELEASE_MASTER_KEYS and # setup/canectic-release.asc by tests. The override (space separated) exists to # test this script itself. RELEASE_KEY_FPRS=("F3F16D3659AF25FBF9474C6DB5D8AB143016761F" "DE1A1F1FE233514664DE71138ABB2D2EC0D13127") if [[ -n "${CANECTIC_RELEASE_KEY_FPR:-}" ]]; then read -r -a RELEASE_KEY_FPRS <<< "$(printf '%s' "$CANECTIC_RELEASE_KEY_FPR" | tr 'abcdef' 'ABCDEF')" warn "using the release key fingerprints from CANECTIC_RELEASE_KEY_FPR, not the ones built into this script" fi spaced_fpr() { printf '%s' "$1" | sed 's/.\{4\}/& /g; s/ $//'; } is_release_key() { local k; for k in "${RELEASE_KEY_FPRS[@]}"; do [[ "$1" == "$k" ]] && return 0; done; return 1; } release_keys_spaced() { local k out=""; for k in "${RELEASE_KEY_FPRS[@]}"; do out+="${out:+, }$(spaced_fpr "$k")"; done; printf '%s' "$out"; } # Master fingerprints in a key file, one per line. masters_in() { gpg --homedir "$GPGHOME" --batch --with-colons --show-keys "$1" 2>/dev/null \ | awk -F: '$1=="pub"{want=1; next} $1=="fpr" && want{print $10; want=0}' } # Take a key file into the private home, refusing one that names no release key. take_keys() { local file="$1" label="$2" found=false k for k in $(masters_in "$file"); do is_release_key "$k" && found=true; done $found || die "the key that came with $label is not a Canectic release key. expected $(release_keys_spaced) got $(spaced_fpr "$(masters_in "$file" | head -1)") Nothing has been unpacked." gpg_q --import "$file" >/dev/null 2>&1 || die "gpg could not read the key that came with $label" } # The keyserver, by fingerprint. Unreachable is a refusal: the point of asking # is to hear about a revocation, and silence is not news. A keyserver that has # no copy of a key is only noted. KEYSERVER_CHECKED=false keyserver_keys() { if ! $USE_KEYSERVER; then warn "not asking a keyserver about the release keys (--no-keyserver). Compare the fingerprint" warn "printed below with docs/sysop/INSTALL.md yourself." return fi info "looking the release keys up on $KEYSERVER" local k f status for k in "${RELEASE_KEY_FPRS[@]}"; do f="$WORK/keyserver-$k.asc" status=0 if command -v curl >/dev/null 2>&1; then code="$(curl -sS -o "$f" -w '%{http_code}' "$KEYSERVER/vks/v1/by-fingerprint/$k" 2>/dev/null)" || status=$? if [[ $status -ne 0 || "$code" == "000" ]]; then status=network elif [[ "$code" == "404" ]]; then status=missing elif [[ "$code" != 2* ]]; then status="HTTP $code" else status=ok; fi else wget -qO "$f" "$KEYSERVER/vks/v1/by-fingerprint/$k" || status=$? if [[ "$status" == 0 ]]; then status=ok elif [[ "$status" == 8 ]]; then status=missing else status=network; fi fi case "$status" in ok) gpg_q --import "$f" >/dev/null 2>&1 || warn "the keyserver's copy of $(spaced_fpr "$k") could not be read" ;; missing) warn "$KEYSERVER holds no copy of $(spaced_fpr "$k")" ;; *) die "could not ask $KEYSERVER about the release keys ($status). A first install looks them up there, so a key revoked since this script was written is refused. If you have compared the fingerprint with docs/sysop/INSTALL.md yourself, run again with --no-keyserver." ;; esac done KEYSERVER_CHECKED=true } # Check a detached signature against the release keys in the private home. verify_signed() { local file="$1" sig="$2" label="$3" status primary status="$(gpg_q --status-fd 1 --verify "$sig" "$file" 2>/dev/null || true)" grep -q '^\[GNUPG:\] BADSIG ' <<<"$status" && die "$label does not match its own signature. Something is wrong with this release; nothing has been unpacked." grep -q '^\[GNUPG:\] REVKEYSIG ' <<<"$status" && die "$label is signed with a release key that has been REVOKED. Nothing has been unpacked." grep -q '^\[GNUPG:\] EXPKEYSIG ' <<<"$status" && die "$label is signed with a release key that has expired. Nothing has been unpacked." primary="$(awk '/^\[GNUPG:\] VALIDSIG /{print $NF; exit}' <<<"$status")" [[ -n "$primary" ]] || die "$label is not signed by a Canectic release key. Nothing has been unpacked." is_release_key "$primary" || die "$label is signed by a key that is not a Canectic release key ($(spaced_fpr "$primary")). Nothing has been unpacked." ok "signature verified (Canectic release key $(spaced_fpr "$primary"))" } fetch_optional() { local name="$1" dest="$2" if [[ -n "$FROM" ]]; then [[ -f "$FROM/$name" ]] && cp "$FROM/$name" "$dest" && return 0 return 1 fi $FETCH_OUT "$dest" "$BASE_URL/$name" 2>/dev/null } # The file in --from called this, whatever case a file echo gave it. find_in_from() { local want f want="$(printf '%s' "$1" | tr 'A-Z' 'a-z')" for f in "$FROM"/*; do [[ "$(basename "$f" | tr 'A-Z' 'a-z')" == "$want" ]] && { printf '%s' "$f"; return 0; } done return 1 } keyserver_keys SUMS="$WORK/SHA256SUMS" TREE="" SIGNED_BY="" if fetch_optional "SHA256SUMS" "$SUMS" && fetch_optional "SHA256SUMS.asc" "$WORK/SHA256SUMS.asc"; then # ---- A signed checksum list --------------------------------------------- if fetch_optional "canectic-release.asc" "$WORK/canectic-release.asc"; then take_keys "$WORK/canectic-release.asc" "the release directory" elif ! $KEYSERVER_CHECKED; then die "the release directory has no copy of the release key (canectic-release.asc), and no keyserver was asked. Nothing has been unpacked." fi verify_signed "$SUMS" "$WORK/SHA256SUMS.asc" "the published checksum list" SIGNED_BY=sums # What SHA256SUMS says a file should hash to. A file it does not mention is # a refusal and not a pass: a published release lists everything it # publishes. check_against_sums() { local name="$1" file="$2" expected actual expected="$(awk -v n="$name" '$2 == n { print $1; exit }' "$SUMS")" [[ -n "$expected" ]] || die "SHA256SUMS does not mention $name. Either the checksum list or $name is not from this release. Nothing has been unpacked." actual="$(sha256sum "$file" | cut -d' ' -f1)" [[ "$actual" == "$expected" ]] || die "$name does not match the published checksum list. expected $expected got $actual Nothing has been unpacked." } META="$WORK/meta.json" fetch "canectic-${VERSION}.json" "$META" check_against_sums "canectic-${VERSION}.json" "$META" ARTIFACT="$(node -p "require('$META').artifact")" EXPECTED="$(node -p "require('$META').sha256")" IS_DELTA="$(node -p "require('$META').delta === true")" if [[ "$IS_DELTA" == "true" ]]; then die "$VERSION is a development build, which is a delta against a stable release and cannot be installed from nothing. Install the stable it names first, then update to this." fi info "downloading $ARTIFACT" fetch "$ARTIFACT" "$WORK/$ARTIFACT" check_against_sums "$ARTIFACT" "$WORK/$ARTIFACT" ACTUAL="$(sha256sum "$WORK/$ARTIFACT" | cut -d' ' -f1)" [[ "$ACTUAL" == "$EXPECTED" ]] || die "$ARTIFACT does not match its published checksum. expected $EXPECTED got $ACTUAL It has NOT been unpacked." ok "checksum verified" else # ---- The archive alone ---------------------------------------------------- [[ -n "$FROM" ]] || die "the release site publishes no signed checksum list for this release, so there is nothing to check it against. Nothing has been downloaded." ARCHIVE_PATH="$(find_in_from "canectic-${VERSION}.zip")" || die "not found in $FROM: canectic-${VERSION}.zip" ARTIFACT="canectic-${VERSION}.zip" cp "$ARCHIVE_PATH" "$WORK/$ARTIFACT" info "no signed checksum list beside it; checking the MANIFEST signed inside $(basename "$ARCHIVE_PATH")" # Identity, read without unpacking. The name is a hint; this settles it. ID_VERSION="$( (unzip -p "$WORK/$ARTIFACT" CANECTIC.ID 2>/dev/null || true) | awk '$1=="Version"{print tolower($2); exit}')" ID_DELTA="$( (unzip -p "$WORK/$ARTIFACT" CANECTIC.ID 2>/dev/null || true) | awk '$1=="Delta"{print $2; exit}')" [[ -n "$ID_VERSION" ]] || die "$(basename "$ARCHIVE_PATH") carries no CANECTIC.ID, so it cannot say what it is. Nothing has been unpacked." [[ "$ID_VERSION" == "$VERSION" ]] || die "$(basename "$ARCHIVE_PATH") says it is $ID_VERSION, not $VERSION. Nothing has been unpacked." [[ "$ID_DELTA" == "yes" ]] && die "$VERSION is a development build, which is a delta against a stable release and cannot be installed from nothing. Install the stable it names first, then update to this." WRAP="canectic-${VERSION}" mkdir -p "$WORK/signed" unzip -p "$WORK/$ARTIFACT" "$WRAP/MANIFEST" > "$WORK/signed/MANIFEST" 2>/dev/null || true unzip -p "$WORK/$ARTIFACT" "$WRAP/MANIFEST.asc" > "$WORK/signed/MANIFEST.asc" 2>/dev/null || true unzip -p "$WORK/$ARTIFACT" "$WRAP/setup/canectic-release.asc" > "$WORK/signed/canectic-release.asc" 2>/dev/null || true [[ -s "$WORK/signed/MANIFEST" ]] || die "$(basename "$ARCHIVE_PATH") has no MANIFEST. Nothing has been unpacked." [[ -s "$WORK/signed/MANIFEST.asc" ]] || die "$(basename "$ARCHIVE_PATH") is not signed (no MANIFEST.asc), and there is no signed checksum list beside it. Nothing has been unpacked." if [[ -s "$WORK/signed/canectic-release.asc" ]]; then take_keys "$WORK/signed/canectic-release.asc" "$(basename "$ARCHIVE_PATH")" elif ! $KEYSERVER_CHECKED; then die "$(basename "$ARCHIVE_PATH") carries no release key and no keyserver was asked. Nothing has been unpacked." fi verify_signed "$WORK/signed/MANIFEST" "$WORK/signed/MANIFEST.asc" "the release's MANIFEST" SIGNED_BY=manifest # Unpacked into the work directory only, then every file checked against # the signed MANIFEST, and anything it does not list refused, before a # single file of it is run. info "checking every file against the signed MANIFEST" unzip -q -o "$WORK/$ARTIFACT" -d "$WORK" || die "$(basename "$ARCHIVE_PATH") could not be unpacked" TREE="$WORK/$WRAP" cmp -s "$WORK/signed/MANIFEST" "$TREE/MANIFEST" || die "the MANIFEST unpacked is not the one that was checked. Nothing has been run." node -e ' var fs = require("fs"), path = require("path"), crypto = require("crypto"); var root = process.argv[1], version = process.argv[2]; function fail(m) { process.stderr.write(m + "\n"); process.exit(2); } var m; try { m = JSON.parse(fs.readFileSync(path.join(root, "MANIFEST"), "utf8")); } catch (e) { fail("the MANIFEST does not parse"); } if (!m || !Array.isArray(m.files) || !m.files.length) fail("the MANIFEST lists no files"); if (String(m.version || "").toLowerCase() !== version) fail("the signed MANIFEST describes " + (m.version || "no version") + ", not " + version); var listed = new Set(["MANIFEST", "MANIFEST.asc"]); for (var f of m.files) { listed.add(f.path); var p = path.join(root, f.path), st; try { st = fs.lstatSync(p); } catch (e) { fail(f.path + " is missing"); } if (!st.isFile()) fail(f.path + " is not a plain file"); var h = crypto.createHash("sha256").update(fs.readFileSync(p)).digest("hex"); if (h !== f.sha256) fail(f.path + " does not match the signed MANIFEST"); } (function walk(rel) { for (var e of fs.readdirSync(path.join(root, rel), { withFileTypes: true })) { var r = rel ? rel + "/" + e.name : e.name; if (e.isDirectory()) { walk(r); continue; } if (e.isSymbolicLink() || !listed.has(r)) fail(r + " is in the archive and not in its signed MANIFEST"); } })(""); process.stdout.write(String(m.files.length)); ' "$TREE" "$VERSION" > "$WORK/checked" 2> "$WORK/check-error" \ || die "$(cat "$WORK/check-error"). Nothing has been run." ok "$(cat "$WORK/checked") files match the signed MANIFEST" fi # Unpack and stop. The docs and the setup scripts live inside the release, so # without this there is no moment at which a sysop can read INSTALL.md or run # create_pg_db_user.sh before committing to an install: the bootstrap unpacks # into a temporary directory and deletes it on the way out. if [[ -n "$EXTRACT_TO" ]]; then info "extracting to $EXTRACT_TO" mkdir -p "$EXTRACT_TO" [[ -n "$TREE" ]] || unzip -q -o "$WORK/$ARTIFACT" -d "$WORK" cp -a "$WORK/canectic-${VERSION}/." "$EXTRACT_TO/" ok "Canectic $VERSION unpacked into $EXTRACT_TO" echo "" echo " Read first: $EXTRACT_TO/docs/sysop/INSTALL.md" echo " Database: cd $EXTRACT_TO && bash setup/create_pg_db_user.sh" echo " Then install: cd $EXTRACT_TO && node src/tools/install.js --target /opt/canectic" echo "" exit 0 fi if [[ "$DOWNLOAD_ONLY" == "true" ]]; then DEST="${TARGET:-$PWD}" cp "$WORK/$ARTIFACT" "$DEST/" [[ "$SIGNED_BY" == "sums" ]] && cp "$META" "$DEST/canectic-${VERSION}.json" ok "downloaded and verified into $DEST" echo "" echo " To install it yourself:" echo " unzip $ARTIFACT && cd canectic-$VERSION" echo " less docs/sysop/INSTALL.md" echo " bash setup/create_pg_db_user.sh" echo " node src/tools/install.js --target /opt/canectic" echo "" exit 0 fi # ----------------------------------------------------------------------------- # Extract and hand off # ----------------------------------------------------------------------------- if [[ -z "$TREE" ]]; then info "extracting" unzip -q -o "$WORK/$ARTIFACT" -d "$WORK" TREE="$WORK/canectic-${VERSION}" fi [[ -d "$TREE" ]] || die "the archive did not contain canectic-${VERSION}/" [[ -f "$TREE/src/tools/install.js" ]] || die "this release ships no installer. Extract it and follow docs/sysop/INSTALL.md" echo "" info "handing off to ${VERSION}'s own installer" echo "" # The release installs itself. Installing is version specific, so a release # should do its own rather than be installed by whatever fetched it. ARGS=() [[ -n "$TARGET" ]] && ARGS+=(--target "$TARGET") [[ ${#INSTALL_ARGS[@]} -gt 0 ]] && ARGS+=("${INSTALL_ARGS[@]}") # exec replaces this shell, so the exit trap never runs: stop the private gpg # home's agent now. gpgconf --homedir "$GPGHOME" --kill all >/dev/null 2>&1 || true cd "$TREE" exec node src/tools/install.js "${ARGS[@]}"