Fixes the tsc-not-found build error when NODE_ENV=production omits build tooling. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
84 lines
2.5 KiB
Bash
84 lines
2.5 KiB
Bash
#!/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" <<EOF
|
|
[Unit]
|
|
Description=Shelfless (Audiobookshelf frontend)
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
WorkingDirectory=$INSTALL_DIR
|
|
ExecStart=$NODE_BIN server/index.mjs
|
|
Restart=on-failure
|
|
RestartSec=3
|
|
Environment=NODE_ENV=production
|
|
Environment=PORT=$PORT
|
|
Environment=ABS_URL=$ABS_URL
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
echo "==> 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:-<container-ip>}:$PORT"
|
|
echo " ABS: $ABS_URL"
|
|
echo " Logs: journalctl -u $SERVICE -f"
|