sirius-press/install.sh
Silent Mode 05d77a0187 fix(sirius-press): stop writing dead build args into the installer's .env
install.sh was still sourcing tools/wordpress.lock and copying WP_VERSION,
WP_URL and WP_SHA256 into the generated .env. Nothing reads them any more —
core is vendored and baked into the image — and a config file full of
settings that do nothing invites someone to edit one and wonder why it had
no effect.
2026-09-21 03:24:24 +02:00

157 lines
5.2 KiB
Bash

#!/usr/bin/env bash
# Sirius Press installer.
#
# curl -fsSL https://silentmode.st/sirius-press/install.sh | bash
#
# Brings up a working instance on a fresh Ubuntu 22.04 or 24.04 VPS: Docker if
# it is missing, the repository, generated passwords, and the stack running
# behind nginx.
#
# Two things this script will not do, both on purpose:
#
# It does not pipe anything else into a shell. Docker is installed from the
# distribution's own packages, not from get.docker.com — you are already
# trusting one curl-to-bash by running this, and chaining a second is how a
# supply chain gets long.
#
# It does not ask for, generate or store a wallet phrase. The site's
# publishing key is entered later in wp-admin, by a person, over whatever
# TLS they have arranged — not typed into a terminal session that scrolls
# into a log.
set -euo pipefail
REPO="${SIRIUS_PRESS_REPO:-https://code.silentmode.st/silentmode/sirius-press.git}"
DIR="${SIRIUS_PRESS_DIR:-/opt/sirius-press}"
PORT="${SIRIUS_PRESS_PORT:-80}"
BRANCH="${SIRIUS_PRESS_BRANCH:-master}"
bold() { printf '\033[1m%s\033[0m\n' "$*"; }
say() { printf '\033[1m→\033[0m %s\n' "$*"; }
warn() { printf '\033[33mwarning:\033[0m %s\n' "$*" >&2; }
die() { printf '\033[31merror:\033[0m %s\n' "$*" >&2; exit 1; }
[ "$(id -u)" -eq 0 ] || die "run this as root, or with sudo."
# --------------------------------------------------------------- prerequisites
say "checking prerequisites"
if ! command -v docker >/dev/null 2>&1; then
say "installing Docker from the distribution repositories"
export DEBIAN_FRONTEND=noninteractive
apt-get update -qq
apt-get install -y -qq docker.io docker-compose-v2 git curl \
|| die "could not install Docker. Install it yourself and run this again."
systemctl enable --now docker
else
command -v git >/dev/null 2>&1 || apt-get install -y -qq git
fi
if docker compose version >/dev/null 2>&1; then
COMPOSE="docker compose"
elif command -v docker-compose >/dev/null 2>&1; then
COMPOSE="docker-compose"
else
die "Docker is installed but Compose is not. Install docker-compose-v2."
fi
# ------------------------------------------------------------------ the code
if [ -d "$DIR/.git" ]; then
say "updating $DIR"
git -C "$DIR" fetch --quiet origin "$BRANCH"
git -C "$DIR" checkout --quiet "$BRANCH"
git -C "$DIR" pull --quiet --ff-only origin "$BRANCH" \
|| warn "could not fast-forward; leaving the checkout as it is."
else
say "cloning into $DIR"
mkdir -p "$(dirname "$DIR")"
git clone --quiet --branch "$BRANCH" --depth 1 "$REPO" "$DIR" \
|| die "could not clone $REPO"
fi
cd "$DIR/docker"
# ---------------------------------------------------------------- the config
random() { head -c 32 /dev/urandom | od -An -tx1 | tr -d ' \n'; }
if [ -f .env ]; then
say "keeping the existing .env"
else
say "writing .env with generated passwords"
# No WordPress version or checksum here: core is vendored in the
# repository and baked into the image, so there is nothing to pin at
# deploy time.
{
echo "# Written by install.sh on $(date -u +%Y-%m-%dT%H:%M:%SZ)."
echo "DB_NAME=wordpress"
echo "DB_USER=wordpress"
echo "DB_PASSWORD=$(random)"
echo "DB_ROOT_PASSWORD=$(random)"
echo "SITE_URL="
echo "HTTP_PORT=$PORT"
echo "WP_DEBUG=false"
echo "SIRIUS_PRESS_KEY=$(random)"
} > .env
chmod 600 .env
fi
# ------------------------------------------------------------------- run it
say "building the image (this is the slow part — a few minutes on a small VPS)"
$COMPOSE build --quiet 2>&1 | tail -5 || die "the image did not build."
say "starting"
$COMPOSE up -d || die "the stack did not start. Try: cd $DIR/docker && $COMPOSE logs"
# Give the app a moment, then check that something answers. A silent failure
# here is the difference between "installed" and "installed and working".
say "waiting for the site to answer"
url="http://127.0.0.1:${PORT}/wp-admin/install.php"
ok=0
for _ in $(seq 1 60); do
code="$(curl -fsS -o /dev/null -w '%{http_code}' --max-time 5 "$url" 2>/dev/null || true)"
case "$code" in
200|30[0-9]) ok=1; break ;;
esac
sleep 2
done
ip="$(curl -fsS --max-time 5 https://api.ipify.org 2>/dev/null || hostname -I 2>/dev/null | awk '{print $1}')"
suffix=""
[ "$PORT" = "80" ] || suffix=":$PORT"
echo
if [ "$ok" -eq 1 ]; then
bold "Sirius Press is running."
else
bold "Sirius Press started, but nothing answered on port $PORT yet."
warn "Check with: cd $DIR/docker && $COMPOSE logs -f app"
fi
cat <<EOF
Finish setup: http://${ip:-your-server}${suffix}/wp-admin/install.php
The setup screen asks for a wallet address instead of an email address.
You can leave it blank and attach one later from your profile.
Next:
1. Point your BCNR name's p or ip record at ${ip:-this server}.
See ${DIR}/docs/bcnr-records.md
2. In wp-admin, open Sirius Press and set the name this site publishes under.
3. Decide whether this server may hold your publishing key, or whether you
would rather sign exports from your browser. Manual is the default and
the safer answer. See ${DIR}/docs/publishing.md
Managing it:
cd ${DIR}/docker
${COMPOSE} logs -f app # what the site is doing
${COMPOSE} restart # after changing .env
git -C ${DIR} pull && ${COMPOSE} build && ${COMPOSE} up -d # upgrade
EOF