#!/usr/bin/env bash # Installs Pit Wall, the dashboard for the Assetto Corsa server, and the server itself if there isn't one yet. # Anywhere (Ubuntu or Debian, 64-bit): curl -fsSL https://api.mintmotive.com.au/pitwall/install.sh | sudo bash # From the mint-cloud folder: sudo ./apps/pitwall/install.sh # Run through curl it gets Node.js 22 if the machine hasn't got it, downloads the newest Pit Wall and checks it # against its published fingerprint, puts AssettoServer in ~/acserver (with a service that starts with the machine) # if there's no server there yet, and keeps Pit Wall up to date from the same site. Running it again updates it. # Optional (before bash: curl … | sudo PITWALL_PORT=9000 bash): # PITWALL_AC_DIR=/home/you/acserver PITWALL_SERVICE=acserver PITWALL_PORT=8700 PITWALL_USER=you # PITWALL_HOST=0.0.0.0 (open it on your home network too; the default when installed through curl) # PITWALL_DATA=/srv/mint-data/assetto PITWALL_INBOX=/srv/mint-data/assetto-drop PITWALL_VERSION=1.74.0 set -euo pipefail [ "$(id -u)" = 0 ] || { echo "Run it with sudo: curl -fsSL https://api.mintmotive.com.au/pitwall/install.sh | sudo bash"; exit 1; } SITE=${PITWALL_SITE:-https://api.mintmotive.com.au/pitwall} die() { echo "✕ $*" >&2; exit 1; } # ---- run through curl: get Node.js and the newest release first, then carry on from the release's own copy ---- SRC=$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd || echo /) if [ ! -f "$SRC/lib/app.js" ] || [ ! -f "$SRC/server.js" ]; then command -v apt-get >/dev/null || die "Pit Wall installs on Ubuntu or Debian (64-bit). This machine has no apt-get." echo "Getting what Pit Wall needs…" apt-get update -qq >/dev/null 2>&1 || true apt-get install -y -qq curl ca-certificates tar xz-utils >/dev/null case "$(uname -m)" in x86_64|amd64) ARCH=x64 ;; aarch64|arm64) ARCH=arm64 ;; *) die "Pit Wall needs a 64-bit machine (this one is $(uname -m))." ;; esac NODE="" if command -v node >/dev/null && [ "$(node -p 'process.versions.node.split(".")[0]' 2>/dev/null || echo 0)" -ge 22 ]; then NODE=$(command -v node) elif [ -x /opt/pitwall-node/bin/node ] && [ "$(/opt/pitwall-node/bin/node -p 'process.versions.node.split(".")[0]')" -ge 22 ]; then NODE=/opt/pitwall-node/bin/node else echo "Getting Node.js 22 (Pit Wall's own copy, in /opt/pitwall-node)…" TMPN=$(mktemp -d) curl -fsSL https://nodejs.org/dist/latest-v22.x/SHASUMS256.txt -o "$TMPN/SUMS" FILE=$(grep -oE "node-v22\.[0-9]+\.[0-9]+-linux-$ARCH\.tar\.xz" "$TMPN/SUMS" | head -1) [ -n "$FILE" ] || die "Couldn't find Node.js 22 for $ARCH." curl -fsSL "https://nodejs.org/dist/latest-v22.x/$FILE" -o "$TMPN/$FILE" (cd "$TMPN" && grep " $FILE\$" SUMS | sha256sum -c --quiet -) || die "Node.js didn't match its published fingerprint, so it wasn't installed." rm -rf /opt/pitwall-node && mkdir -p /opt/pitwall-node && tar -xJf "$TMPN/$FILE" -C /opt/pitwall-node --strip-components=1 --no-same-owner rm -rf "$TMPN"; NODE=/opt/pitwall-node/bin/node fi T=$(mktemp -d); trap 'rm -rf "$T"' EXIT curl -fsSL "$SITE/latest.json" -o "$T/latest.json" || die "Couldn't reach $SITE. Is this machine online?" PICK=$("$NODE" -e 'const l=require(process.argv[1]), want=process.argv[2]; const r=want ? [l, ...(l.releases||[])].find((x)=>x.version===want) : l; if(!r) process.exit(3); console.log(r.version, r.tarball, r.sha256);' "$T/latest.json" "${PITWALL_VERSION:-}") || die "Pit Wall ${PITWALL_VERSION:-} isn't on $SITE." read -r VER TARBALL SHA <<<"$PICK" echo "Downloading Pit Wall $VER…" curl -fsSL "$SITE/$TARBALL" -o "$T/$TARBALL" || die "Couldn't download Pit Wall." echo "$SHA $T/$TARBALL" | sha256sum -c --quiet - || die "The download didn't match Pit Wall's published fingerprint, so nothing was changed." mkdir -p /opt/pitwall-releases && rm -rf "/opt/pitwall-releases/pitwall-$VER" tar -xzf "$T/$TARBALL" -C /opt/pitwall-releases --no-same-owner PITWALL_NODE=$NODE PITWALL_SITE=$SITE exec bash "/opt/pitwall-releases/pitwall-$VER/install.sh" fi # From the mint-cloud repository (your own machines), or from a downloaded release (everyone else). REPO=$(cd "$SRC/../.." && pwd) if [ -d "$REPO/.git" ] && [ -x "$REPO/scripts/repo-pull.sh" ]; then MODE=repo; else MODE=release; fi # Who Pit Wall (and the game servers) run as: you, if you ran sudo from your account; else a "pitwall" account. RUN_AS=${PITWALL_USER:-${SUDO_USER:-}} if [ -z "$RUN_AS" ] || [ "$RUN_AS" = root ]; then [ "$MODE" = release ] || die "Run it with sudo from your own account (not as root), so Pit Wall runs as you." RUN_AS=pitwall id pitwall >/dev/null 2>&1 || useradd --create-home --shell /bin/bash pitwall fi HOME_DIR=$(getent passwd "$RUN_AS" | cut -d: -f6) # Run again by hand, it keeps the settings it was installed with (say, folders moved to another drive); a setting # given on the command line still wins. if [ -f /etc/pitwall.env ]; then while IFS='=' read -r k v; do case "$k" in PITWALL_*) [ -n "${!k:-}" ] || export "$k=$v" ;; esac; done < /etc/pitwall.env fi APP=/opt/pitwall AC_DIR=${PITWALL_AC_DIR:-$HOME_DIR/acserver} SERVICE=${PITWALL_SERVICE:-acserver} PORT=${PITWALL_PORT:-8700} if [ -d /srv/mint-data ]; then DEF_DATA=/srv/mint-data/assetto; DEF_INBOX=/srv/mint-data/assetto-drop; else DEF_DATA=$HOME_DIR/pitwall-data; DEF_INBOX=$HOME_DIR/assetto-drop; fi DATA=${PITWALL_DATA:-$DEF_DATA} if [ -d /srv/mint-data ]; then DEF_SERVERS=/srv/mint-data/acservers; else DEF_SERVERS=$HOME_DIR/acservers; fi SERVERS=${PITWALL_SERVERS_DIR:-$DEF_SERVERS} INBOX=${PITWALL_INBOX:-$DEF_INBOX} SYSTEMCTL=$(command -v systemctl) NODE=${PITWALL_NODE:-$(command -v node || true)} [ -n "$NODE" ] && [ "$("$NODE" -p 'process.versions.node.split(".")[0]' 2>/dev/null || echo 0)" -ge 22 ] || die "Pit Wall needs Node.js 22 or newer. Run the one-line install (it brings its own): curl -fsSL $SITE/install.sh | sudo bash" echo "Installing the unpackers (zip, 7z and rar)…" apt-get install -y -qq libarchive-tools unzip >/dev/null # No game server yet: AssettoServer's own release goes in the folder, with a service that starts with the machine. if [ ! -x "$AC_DIR/AssettoServer" ]; then case "$(uname -m)" in x86_64|amd64) AS_ARCH=linux-x64 ;; aarch64|arm64) AS_ARCH=linux-arm64 ;; *) AS_ARCH="" ;; esac if [ -n "$AS_ARCH" ]; then echo "Getting AssettoServer (the game server program) for $AC_DIR…" TAS=$(mktemp -d) if curl -fsSL "https://github.com/compujuckel/AssettoServer/releases/download/v0.0.54/assetto-server-$AS_ARCH.tar.gz" -o "$TAS/as.tar.gz" && mkdir -p "$AC_DIR" && tar -xzf "$TAS/as.tar.gz" -C "$AC_DIR" --no-same-owner; then chmod +x "$AC_DIR/AssettoServer" 2>/dev/null || true else echo "!! Couldn't download AssettoServer. Put its files in $AC_DIR and run this again." fi rm -rf "$TAS" fi fi mkdir -p "$AC_DIR/content/cars" "$AC_DIR/content/tracks" "$AC_DIR/cfg" "$DATA" "$INBOX" "$SERVERS" chown -R "$RUN_AS:$RUN_AS" "$AC_DIR" "$DATA" "$INBOX" "$SERVERS" if [ -x "$AC_DIR/AssettoServer" ] && ! systemctl list-unit-files "$SERVICE.service" 2>/dev/null | grep -q "^$SERVICE.service"; then cat > "/etc/systemd/system/$SERVICE.service" </dev/null 2>&1 || true echo "Made the $SERVICE service: it starts with the machine (start it from Pit Wall once you've picked a track)." fi mkdir -p "$APP" cp -r "$SRC/lib" "$SRC/public" "$SRC/server.js" "$SRC/package.json" "$APP/" # the Pit Wall Hub plugin (built, in dist/): Pit Wall puts it on the game servers from here mkdir -p "$APP/assettoserver/PitWallHub" rm -rf "$APP/assettoserver/PitWallHub/dist" cp -r "$SRC/assettoserver/PitWallHub/dist" "$APP/assettoserver/PitWallHub/" chown -R root:root "$APP" HOSTV=${PITWALL_HOST:-$([ "$MODE" = release ] && echo 0.0.0.0 || echo 127.0.0.1)} cat > /etc/pitwall.env <> /etc/pitwall.env; fi # More servers made from the panel each run from their own folder as acserver@. cat > /etc/systemd/system/acserver@.service < /usr/local/sbin/pitwall-svc <&2; exit 2 ;; esac case "\$2" in $SERVICE) ;; acserver@*) echo "\$2" | grep -Eq '^acserver@[a-z0-9-]{1,40}\$' || { echo "pitwall-svc: bad service name" >&2; exit 2; } ;; *) echo "pitwall-svc: service not allowed" >&2; exit 2 ;; esac exec $SYSTEMCTL "\$1" "\$2" HELPER chown root:root /usr/local/sbin/pitwall-svc chmod 755 /usr/local/sbin/pitwall-svc cat > /etc/sudoers.d/pitwall </dev/null || { rm -f /etc/sudoers.d/pitwall; echo "Couldn't add the sudo rule."; exit 1; } # …and read the game server's log. usermod -aG systemd-journal "$RUN_AS" cat > /etc/systemd/system/pitwall.service </dev/null 2>&1 && systemctl is-enabled acserver-deploy.path >/dev/null 2>&1; then systemctl disable --now acserver-deploy.path || true echo "Turned off the old drop-folder job: Pit Wall watches $INBOX now." fi # Automatic updates: every 15 minutes (and whenever Mint Cloud's own updater brings something new), bring the # mint-cloud clone up to date (as you, in this folder) and, when Pit Wall's files changed since it was installed, # run this install again with the same settings. Only Pit Wall restarts; the game servers keep running. if [ "$MODE" = repo ]; then cat > /usr/local/sbin/pitwall-update.new <<'UPD' #!/bin/sh # Pit Wall's updater (written by install.sh). Run by pitwall-update.service: every 15 minutes, when Mint Cloud's # updater brings something new, or Settings → Update now. "pitwall-update force" installs again even with nothing new. REPO="__REPO__"; RUN_AS="__RUN_AS__"; STATUS="__DATA__/update.json"; DONE="__DATA__/pitwall-installed-rev" # What happened goes to Pit Wall's Settings and, when it went wrong, to the journal (journalctl -u pitwall-update). say() { msg=$(printf '%s' "$2" | grep -v '^hint:' | tail -n 3 | tr -d '"\\' | tr '\n\r\t' ' ' | cut -c1-300); printf '{"at":%s,"ok":%s,"message":"%s"}\n' "$(date +%s)" "$1" "$msg" > "$STATUS"; [ "$1" = true ] || printf '%s\n' "$2" >&2; } err=$(mktemp); trap 'rm -f "$err"' EXIT if ! head=$("$REPO/scripts/repo-pull.sh" "$REPO" "$RUN_AS" 2>"$err"); then say false "Couldn't download it: $(cat "$err")"; exit 1; fi # Against what's installed, not what was there a moment ago: Mint Cloud's updater may have brought it in already. was=$(cat "$DONE" 2>/dev/null) if [ "$1" != force ] && [ -n "$was" ] && { [ "$was" = "$head" ] || sudo -u "$RUN_AS" git -C "$REPO" diff --quiet "$was" "$head" -- apps/pitwall 2>/dev/null; }; then echo "$head" > "$DONE"; say true "Up to date."; exit 0 fi [ -f /etc/pitwall.env ] || { say false "Pit Wall's settings (/etc/pitwall.env) are missing. Run its install once by hand: sudo $REPO/apps/pitwall/install.sh"; exit 1; } set -a; . /etc/pitwall.env; set +a [ ! -x /usr/local/sbin/dyno-keep ] || /usr/local/sbin/dyno-keep before-update pitwall || true if out=$(SUDO_USER="$RUN_AS" "$REPO/apps/pitwall/install.sh" 2>&1); then say true "Updated to the newest version."; else say false "The install stopped: $out"; exit 1; fi UPD else # A downloaded release: the updater asks the download site for a newer one, checks it, and installs it the same way. cat > /usr/local/sbin/pitwall-update.new <<'UPD' #!/bin/sh # Pit Wall's updater (written by install.sh). Run by pitwall-update.service: every 15 minutes, or Settings → Update now. SITE="__SITE__"; RUN_AS="__RUN_AS__"; NODE="__NODE__"; STATUS="__DATA__/update.json" say() { msg=$(printf '%s' "$2" | tail -n 3 | tr -d '"\\' | tr '\n\r\t' ' ' | cut -c1-300); printf '{"at":%s,"ok":%s,"message":"%s"}\n' "$(date +%s)" "$1" "$msg" > "$STATUS"; [ "$1" = true ] || printf '%s\n' "$2" >&2; } T=$(mktemp -d); trap 'rm -rf "$T"' EXIT curl -fsSL "$SITE/latest.json" -o "$T/latest.json" 2>"$T/err" || { say false "Couldn't reach the download site: $(cat "$T/err")"; exit 1; } NEW=$("$NODE" -p "require('$T/latest.json').version"); HAVE=$("$NODE" -p "require('/opt/pitwall/package.json').version" 2>/dev/null || echo 0) if [ "$1" != force ] && [ "$NEW" = "$HAVE" ]; then say true "Up to date ($HAVE)."; exit 0; fi TB=$("$NODE" -p "require('$T/latest.json').tarball"); SHA=$("$NODE" -p "require('$T/latest.json').sha256") curl -fsSL "$SITE/$TB" -o "$T/$TB" || { say false "Couldn't download Pit Wall $NEW."; exit 1; } echo "$SHA $T/$TB" | sha256sum -c --quiet - || { say false "Pit Wall $NEW didn't match its published fingerprint, so it wasn't installed."; exit 1; } mkdir -p /opt/pitwall-releases && rm -rf "/opt/pitwall-releases/pitwall-$NEW" && tar -xzf "$T/$TB" -C /opt/pitwall-releases --no-same-owner if out=$(PITWALL_NODE="$NODE" PITWALL_USER="$RUN_AS" SUDO_USER="$RUN_AS" bash "/opt/pitwall-releases/pitwall-$NEW/install.sh" 2>&1); then say true "Updated to $NEW."; else say false "The install stopped: $out"; exit 1; fi ls -1d /opt/pitwall-releases/pitwall-* 2>/dev/null | sort -V | head -n -3 | xargs -r rm -rf UPD fi sed -i "s|__REPO__|$REPO|g; s|__RUN_AS__|$RUN_AS|g; s|__DATA__|$DATA|g; s|__SITE__|$SITE|g; s|__NODE__|$NODE|g" /usr/local/sbin/pitwall-update.new chmod 755 /usr/local/sbin/pitwall-update.new mv /usr/local/sbin/pitwall-update.new /usr/local/sbin/pitwall-update # a new file, so a running update isn't cut short cat > /etc/systemd/system/pitwall-update.service < /etc/systemd/system/pitwall-update.timer < "$DATA/pitwall-installed-rev" 2>/dev/null || rm -f "$DATA/pitwall-installed-rev"; fi systemctl daemon-reload systemctl enable pitwall >/dev/null systemctl enable --now pitwall-update.timer >/dev/null 2>&1 || true systemctl restart pitwall if ! systemctl list-unit-files "$SERVICE.service" | grep -q "$SERVICE"; then echo "!! There's no $SERVICE service yet. Start/Stop/Restart work once it exists (see the README)." fi echo if command -v tailscale >/dev/null && tailscale status >/dev/null 2>&1; then tailscale serve --bg --https=10000 "http://127.0.0.1:$PORT" >/dev/null 2>&1 || true NAME=$(tailscale status --json 2>/dev/null | grep -m1 '"DNSName"' | sed -E 's/.*"DNSName": *"([^"]+)\.".*/\1/') echo "Pit Wall is ready. Open it from any of your Tailscale devices:" echo " https://${NAME:-..ts.net}:10000" else echo "Pit Wall is running on http://127.0.0.1:$PORT (on this machine)." echo "To open it from your phone and PC, sign this machine in to Tailscale, then run:" echo " sudo tailscale serve --bg --https=10000 http://127.0.0.1:$PORT" fi if [ "$HOSTV" = "0.0.0.0" ]; then LAN=$(hostname -I 2>/dev/null | tr ' ' '\n' | grep -E '^(192\.168|10\.|172\.(1[6-9]|2[0-9]|3[01]))' | head -1 || true) echo "On your home network (any PC or phone on the same Wi-Fi): http://${LAN:-SERVER-IP}:$PORT" fi echo "The first visit asks you to pick its password." echo "Drop mods in: $INBOX (or upload them in the dashboard)"