#!/usr/bin/env bash # Shelfless installer for a Debian/Ubuntu Proxmox LXC. # Installs Node, fetches the repo, builds the frontend, and sets up a systemd service # that serves the app and reverse-proxies to your Audiobookshelf server. # # Usage (as root on the container): # bash deploy/install.sh [ABS_URL] [PORT] # # Examples: # bash deploy/install.sh # ABS at localhost:13378, port 8080 # bash deploy/install.sh http://192.168.1.10:13378 # ABS elsewhere # bash deploy/install.sh http://192.168.1.10:13378 9000 # # All values can also be given as env vars (REPO_URL, ABS_URL, PORT, INSTALL_DIR). # Re-running updates an existing install. set -euo pipefail REPO_URL="${REPO_URL:-https://git.scarriffle.com/Scarriffle/shelfless.git}" ABS_URL="${1:-${ABS_URL:-http://127.0.0.1:13378}}" PORT="${2:-${PORT:-8080}}" INSTALL_DIR="${INSTALL_DIR:-/opt/shelfless}" SERVICE="${SERVICE:-shelfless}" echo "==> Config: ABS_URL=$ABS_URL PORT=$PORT INSTALL_DIR=$INSTALL_DIR" echo "==> Installing system dependencies" apt-get update -y apt-get install -y git curl ca-certificates if ! command -v node >/dev/null 2>&1; then echo "==> Installing Node.js 20.x" curl -fsSL https://deb.nodesource.com/setup_20.x | bash - apt-get install -y nodejs fi echo " node $(node --version), npm $(npm --version)" echo "==> Fetching source into $INSTALL_DIR" if [ -d "$INSTALL_DIR/.git" ]; then git -C "$INSTALL_DIR" pull --ff-only else git clone "$REPO_URL" "$INSTALL_DIR" fi echo "==> Building" cd "$INSTALL_DIR" # Build tooling (TypeScript/Vite) lives in devDependencies, so install those even when # NODE_ENV=production is set in the environment. npm ci --include=dev npm run build echo "==> Writing systemd unit /etc/systemd/system/$SERVICE.service" NODE_BIN="$(command -v node)" cat > "/etc/systemd/system/$SERVICE.service" < Enabling and starting service" systemctl daemon-reload systemctl enable --now "$SERVICE" sleep 1 systemctl --no-pager --full status "$SERVICE" || true IP="$(hostname -I 2>/dev/null | awk '{print $1}')" echo "" echo "Done. Shelfless is running:" echo " URL: http://${IP:-}:$PORT" echo " ABS: $ABS_URL" echo " Logs: journalctl -u $SERVICE -f"