Files
boss/scripts/bootstrap-server.sh
2026-03-26 23:16:56 +08:00

50 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
if [[ "${EUID}" -ne 0 ]]; then
echo "Please run with sudo."
exit 1
fi
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y ca-certificates curl gnupg rsync
if ! command -v node >/dev/null 2>&1; then
mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key \
| gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" \
>/etc/apt/sources.list.d/nodesource.list
apt-get update
apt-get install -y nodejs
fi
if ! command -v caddy >/dev/null 2>&1; then
apt-get install -y debian-keyring debian-archive-keyring apt-transport-https
curl -fsSL https://dl.cloudsmith.io/public/caddy/stable/gpg.key \
| gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -fsSL https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt \
>/etc/apt/sources.list.d/caddy-stable.list
apt-get update
apt-get install -y caddy
fi
mkdir -p /opt/boss
chown -R ubuntu:ubuntu /opt/boss
if [[ -f /opt/boss/deployment/systemd/boss-web.service ]]; then
cp /opt/boss/deployment/systemd/boss-web.service /etc/systemd/system/boss-web.service
fi
if [[ -f /opt/boss/deployment/Caddyfile ]]; then
cp /opt/boss/deployment/Caddyfile /etc/caddy/Caddyfile
fi
systemctl daemon-reload
systemctl enable boss-web || true
systemctl enable caddy || true
echo "bootstrap-server.sh completed"