#!/usr/bin/env bash # NodePilot install, by Chainwise Holdings LLC # # curl -fsSL https://getnodepilot.com/install | sudo bash -s -- # # The install token comes from your NodePilot dashboard (add a node; it shows the whole command). # # What this script does, in order. It is short so that you can read it before you run it. # 1. Reads this node's settings from NodePilot with your install token. Settings are data, such as # the node's name and role; nothing in them is ever run. # 2. Reads the record of NodePilot's current software release and checks its signature against # NodePilot's release keys, which are written into this script below. They are not downloaded. # 3. Downloads the node installer that the record lists, and checks that its size and SHA-256 are # exactly the ones in the signed record. # 4. Runs that installer with the settings. It checks everything it installs (the NodePilot agent # and the node toolkit) against signed records and the same keys, in the same way. # If any check fails, it stops before anything runs and nothing is installed. # # Why it lives here: getnodepilot.com is hosted apart from NodePilot's own servers. Someone who took # over those servers could change the files they serve, but not this script or the keys in it, so # they still could not make your server run software that NodePilot did not sign. # # Copyright (c) 2026 Chainwise Holdings LLC. All rights reserved. set -euo pipefail NP_CENTRAL="https://nodepilot.chainwise.info" NP_MIN_SETUP="0.0.30" # the first release whose installer checks the agent and toolkit itself say(){ printf '\n\033[1;35m[NodePilot]\033[0m %s\n' "$*"; } die(){ say "ERROR: $*"; say "Nothing was installed. Fix the cause and run the command again."; exit 1; } # NodePilot's release keys: the key on NodePilot's signing server, and an offline backup that has # never been on a server. A record names the key it was signed with by its fingerprint, the first 32 # hex characters of the SHA-256 of the key (openssl pkey -pubin -outform DER | sha256sum). np_key_pem(){ local b case "$1" in 840d74dd34870857a962e7c1c18f9868) b="MCowBQYDK2VwAyEACJka8zanR5vi+OEqCqCv8hy4TnCkYK/H1WsQ7YYw3fo=" ;; 4dc248b1353073b5f368447cddffaa4c) b="MCowBQYDK2VwAyEA0H5IJlWj4deu2SYG9kjgpw7pATB1CfoBxzosu8ndzrI=" ;; *) return 1 ;; esac printf -- '-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----\n' "$b" } # PREFIX RECORD SIG: 0 when RECORD names one of the keys above and SIG is that key's signature over # PREFIX, a newline and RECORD exactly as served. The prefix keeps one kind of record from passing as # another. Only after this are the record's fields read. np_verified(){ # PREFIX RECORD SIG: 0 when RECORD names one of the keys above and SIG verifies with it local fp fp="$(sed -n -E 's/^ "key": "([0-9a-f]{32})"$/\1/p' "$2" 2>/dev/null || true)" case "$fp" in *$'\n'*|'') return 1 ;; esac np_key_pem "$fp" > "$NP_TMP/trust.pem" || return 1 { printf '%s\n' "$1"; cat -- "$2"; } > "$NP_TMP/trust.msg" || return 1 openssl pkeyutl -verify -pubin -inkey "$NP_TMP/trust.pem" -rawin -in "$NP_TMP/trust.msg" -sigfile "$3" >/dev/null 2>&1 } np_field(){ # RECORD NAME: a top-level field of a verified record, present exactly once local v v="$(sed -n -E 's/^ "'"$2"'": "?([A-Za-z0-9._:+-]+)"?,?$/\1/p' "$1" 2>/dev/null || true)" case "$v" in *$'\n'*|'') return 1 ;; esac printf '%s' "$v" } np_file_ok(){ # RECORD NAME FILE: FILE is the size and sha256 that the verified RECORD lists for NAME local e n="${2//./[.]}" e="$(sed -n -E 's/^ "'"$n"'": \{"size": ([0-9]+), "sha256": "([0-9a-f]{64})"\},?$/\1 \2/p' "$1" 2>/dev/null || true)" case "$e" in *$'\n'*|'') return 1 ;; esac [ -f "$3" ] && [ "$(stat -c %s "$3")" = "${e%% *}" ] && [ "$(sha256sum "$3" | cut -c1-64)" = "${e##* }" ] } np_vge(){ [ "$(printf '%s\n%s\n' "$1" "$2" | sort -V | head -n1)" = "$2" ]; } # A >= B, as versions np_xyz(){ [[ "$1" =~ ^[0-9]{1,4}\.[0-9]{1,4}\.[0-9]{1,4}$ ]]; } np_setting(){ # VAR NAME PATTERN: VAR = the one value of NAME in the settings, which must match PATTERN local v v="$(sed -n "s/^$2=//p" "$NP_TMP/settings" | tr -d '\r')" case "$v" in *$'\n'*|'') die "this node's settings have no single $2; get a new install command from your dashboard" ;; esac [[ "$v" =~ $3 ]] || die "this node's setting $2 is not valid; get a new install command from your dashboard" printf -v "$1" '%s' "$v" } main(){ local token="${1:-}" code pol_base api_key pol_ver rc [ "$(id -u)" -eq 0 ] || die "run it as root: curl -fsSL https://getnodepilot.com/install | sudo bash -s -- " [[ "$token" =~ ^[A-Za-z0-9_-]{16,128}$ ]] \ || die "add your install token from the NodePilot dashboard: curl -fsSL https://getnodepilot.com/install | sudo bash -s -- " if ! command -v openssl >/dev/null 2>&1; then DEBIAN_FRONTEND=noninteractive apt-get install -y openssl /dev/null 2>&1 || true fi for c in curl openssl sha256sum sed sort stat; do command -v "$c" >/dev/null 2>&1 || die "this server has no $c, which the install needs" done # A private folder that nobody else can create first, removed however this ends. The node key # reaches curl in a header file, never on a command line where other users could see it. NP_TMP="$(mktemp -d /tmp/np-get.XXXXXX)" trap 'rm -rf "$NP_TMP"' EXIT say "Reading this node's settings from NodePilot ..." code="$(curl -sS --max-time 30 -o "$NP_TMP/settings" -w '%{http_code}' "$NP_CENTRAL/install/$token/config" "$NP_TMP/key.hdr" ) say "Checking NodePilot's signed release ..." pol_ver="$(curl -fsSL --max-time 30 "$pol_base/setup/latest"