#!/usr/bin/env bash # Installs VorticPanel, or upgrades it, in one command. On a fresh Debian 12 / 13 or Ubuntu 22.04 / 24.04 # server, as root: # # curl -fsSL https://vorticpanel.com/install.sh | sudo bash # asks for a domain # curl -fsSL https://vorticpanel.com/install.sh | sudo bash -s -- --domain panel.example.com # curl -fsSL https://vorticpanel.com/install.sh | sudo bash -s -- --no-domain # http://, for testing # # It downloads the newest release from https://vorticpanel.com, checks its signature against the release # keys below and its SHA-256, unpacks it in /root and runs the release's install.sh with the same # options (--help lists them). --version X.Y.Z installs that version instead of the newest. # It won't install a version older than MINIMUM below, or than a minimum version a signed release # names, unless --allow-downgrade is given. set -euo pipefail SITE="https://vorticpanel.com" # The release keys (Ed25519 public keys, the middle line of each PEM). A release signed with any of them is installed. RELEASE_KEYS=( "MCowBQYDK2VwAyEAnOUmqRdm+z2SwKy1xZ5vSLR1PuCICdivdXNfhv65kNo=" "MCowBQYDK2VwAyEALRhMXU1FwPTKlT/Tyaf/cfyeiv+RNWry5oSGaverNQI=" ) # The oldest version still safe to install (empty for none). A signed release can raise it, never lower it. MINIMUM="0.3.77" DIR=/root bold() { printf '\n\033[1m==> %s\033[0m\n' "$*"; } die() { printf '\033[31m%s\033[0m\n' "$*" >&2; exit 1; } # base64url (as the manifest uses) to bytes. unb64url() { local s s="$(printf '%s' "$1" | tr '_-' '/+')" case $(( ${#s} % 4 )) in 2) s="$s==" ;; 3) s="$s=" ;; esac printf '%s' "$s" | base64 -d } # A manifest field: the manifest is JSON.stringify output, so a string field is "name":"value". field() { sed -n "s/.*\"$1\":\"\([^\"]*\)\".*/\1/p" "$2" | head -n 1; } # The signed manifest in an answer from $SITE/api/releases/... manifest_in() { sed -n 's/.*"manifest":"\([A-Za-z0-9_.-]*\)".*/\1/p' "$1" | head -n 1; } # Succeeds when version $1 is older than version $2 (both X.Y.Z). older_than() { local a b i IFS=. read -r -a a <<< "$1" IFS=. read -r -a b <<< "$2" for i in 0 1 2; do if (( 10#${a[i]} < 10#${b[i]} )); then return 0; fi if (( 10#${a[i]} > 10#${b[i]} )); then return 1; fi done return 1 } # Checks a signed manifest (".", the signature over the payload's base64url # text) against the release keys, and writes its JSON to $2. Fails when no release key signed it. check_manifest() { local signed="$1" out="$2" key [ -n "$signed" ] && [ "${signed#*.}" != "$signed" ] || return 1 printf '%s' "${signed%%.*}" > "$out.b64" unb64url "${signed#*.}" > "$out.sig" 2> /dev/null || return 1 for key in "${RELEASE_KEYS[@]}"; do printf '%s\n' '-----BEGIN PUBLIC KEY-----' "$key" '-----END PUBLIC KEY-----' > "$out.pem" if openssl pkeyutl -verify -pubin -inkey "$out.pem" -rawin -in "$out.b64" -sigfile "$out.sig" > /dev/null 2>&1; then unb64url "${signed%%.*}" > "$out" return 0 fi done return 1 } # Raises MINIMUM to the minimum version a checked manifest names, when that's newer. raise_minimum() { local m m="$(field minimumVersion "$1")" [[ "$m" =~ ^[0-9]{1,4}\.[0-9]{1,4}\.[0-9]{1,6}$ ]] || return 0 if [ -z "$MINIMUM" ] || older_than "$MINIMUM" "$m"; then MINIMUM="$m"; fi } # Everything is in main, so bash has read the whole script before it runs any of it (it may be # arriving through a pipe). main() { local version=latest allow_old=no local args=() while [ $# -gt 0 ]; do case "$1" in --version) [ $# -ge 2 ] || die "--version needs a version, e.g. --version 0.3.4"; version="$2"; shift 2 ;; --version=*) version="${1#*=}"; shift ;; # Passed on too: the release's own installer takes it to install over a newer version. --allow-downgrade) allow_old=yes; args+=("$1"); shift ;; *) args+=("$1"); shift ;; esac done if [ "$version" != latest ] && ! [[ "$version" =~ ^[0-9]{1,4}\.[0-9]{1,4}\.[0-9]{1,6}$ ]]; then die "That isn't a version: $version"; fi [ "$(id -u)" = 0 ] || die "Run it as root: curl -fsSL $SITE/install.sh | sudo bash" [ "$(uname -m)" = x86_64 ] || die "VorticPanel runs on 64-bit Intel and AMD (x86_64) servers; this one is $(uname -m)." # openssl checks the signature; most servers have it, and it needs to be 3.0 or newer. if ! command -v openssl > /dev/null; then bold "Installing openssl" DEBIAN_FRONTEND=noninteractive apt-get install -y -qq openssl > /dev/null || die "Couldn't install openssl. Install it, then run this again." fi openssl pkeyutl -help 2>&1 | grep -q -- -rawin || die "openssl is too old to check the release's signature. Use Debian 12 or 13, or Ubuntu 22.04 / 24.04." TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT local tmp="$TMP" bold "Finding the $([ "$version" = latest ] && echo "newest release" || echo "release $version")" curl -fsS --retry 3 --max-time 60 "$SITE/api/releases/$version" -o "$tmp/release.json" || die "Couldn't get the release from $SITE. Check this server can reach it (curl -I $SITE)." local signed signed="$(manifest_in "$tmp/release.json")" [ -n "$signed" ] && [ "${signed#*.}" != "$signed" ] || die "$SITE didn't answer with a release." check_manifest "$signed" "$tmp/manifest.json" || die "The release's signature doesn't check out, so nothing was installed. Try again later, or tell support@vorticpanel.com." local got file sha256 got="$(field version "$tmp/manifest.json")" file="$(field file "$tmp/manifest.json")" sha256="$(field sha256 "$tmp/manifest.json")" grep -q '"kind":"release"' "$tmp/manifest.json" && [[ "$got" =~ ^[0-9]{1,4}\.[0-9]{1,4}\.[0-9]{1,6}$ ]] && [ "$file" = "vorticpanel-$got.tar.gz" ] && [[ "$sha256" =~ ^[0-9a-f]{64}$ ]] || die "The release's manifest isn't one this installer understands." [ "$version" = latest ] || [ "$got" = "$version" ] || die "Asked for $version but $SITE offered $got." # The minimum this script was built with, raised by this release's manifest and, when a version # was asked for, the newest release's. raise_minimum "$tmp/manifest.json" if [ "$version" != latest ] && curl -fsS --retry 3 --max-time 60 "$SITE/api/releases/latest" -o "$tmp/latest.json" 2> /dev/null; then if check_manifest "$(manifest_in "$tmp/latest.json")" "$tmp/latest-manifest.json"; then raise_minimum "$tmp/latest-manifest.json"; fi fi if [ -n "$MINIMUM" ] && older_than "$got" "$MINIMUM"; then [ "$allow_old" = yes ] || die "VorticPanel $got is older than $MINIMUM, the oldest version still safe to install, so nothing was installed. Install the newest (leave out --version), or run this again with --allow-downgrade to install $got anyway." echo "Installing $got, older than $MINIMUM, because of --allow-downgrade" fi bold "Downloading VorticPanel $got" curl -fL --retry 3 --progress-bar "$SITE/download/$file" -o "$tmp/$file" || die "The download failed. Run this again to retry." [ "$(sha256sum "$tmp/$file" | cut -d ' ' -f 1)" = "$sha256" ] || die "The download's SHA-256 isn't the release's, so nothing was installed. Run this again to retry." echo "Signature and SHA-256 check out" rm -rf "${DIR:?}/vorticpanel-$got" tar --no-same-owner -xzf "$tmp/$file" -C "$DIR" [ -f "$DIR/vorticpanel-$got/install.sh" ] || die "The release has no install.sh." echo "Unpacked in $DIR/vorticpanel-$got" # Its questions come from the terminal (/dev/tty), not from this pipe. bash "$DIR/vorticpanel-$got/install.sh" ${args[@]+"${args[@]}"} < /dev/null } main "$@"