#!/usr/bin/env bash set -euo pipefail umask 077 [ "$(id -u)" = 0 ] || { echo 'Run as root on a clean Debian 12/13 or Ubuntu 24.04 VPS'; exit 1; } BASE=$(cd -- "$(dirname -- "$0")" && pwd) [ ! -e /etc/log-atlas/runtime.env ] && [ ! -e /opt/log-atlas ] || { echo 'Existing installation found. No files changed. See README for upgrades.'; exit 1; } [ ! -e /etc/caddy/Caddyfile ] || { echo 'Existing Caddy configuration found. Use the manual coexistence instructions; no overwrite.'; exit 1; } if command -v ss >/dev/null && ss -ltnH | awk '{print $4}' | grep -Eq ':(80|443|8787)$'; then echo 'A required port is busy. Use a clean VPS or the manual instructions.'; exit 1; fi command -v python3 >/dev/null || { echo 'Install python3 first'; exit 1; } echo 'Log Atlas: no nodes are contacted. Existing firewall rules will not be changed.' python3 "$BASE/configure.py" apt-get update apt-get install -y python3-venv python3-pip caddy curl id log-atlas >/dev/null 2>&1 || useradd --system --home-dir /var/lib/log-atlas --shell /usr/sbin/nologin log-atlas install -d -m 755 /opt/log-atlas install -d -o log-atlas -g log-atlas -m 700 /var/lib/log-atlas install -m 644 "$BASE/app.py" "$BASE/requirements.txt" "$BASE/install-agent.sh" "$BASE/agent.py" /opt/log-atlas/ cp -R "$BASE/static" /opt/log-atlas/ chmod -R a+rX /opt/log-atlas/static python3 -m venv /opt/log-atlas/venv /opt/log-atlas/venv/bin/pip install --disable-pip-version-check -r /opt/log-atlas/requirements.txt chmod -R a+rX /opt/log-atlas # Verify private S3 credentials before starting the service. A tiny test object remains under _setup/. /opt/log-atlas/venv/bin/python - <<'PY' import json,os,secrets,sys from pathlib import Path for line in Path('/etc/log-atlas/runtime.env').read_text().splitlines(): k,v=line.split('=',1);os.environ[k]=json.loads(v) sys.path.insert(0,'/opt/log-atlas');import app key='_setup/'+secrets.token_hex(16)+'.txt';payload=b'log-atlas-install-check\n' app.s3.put_object(Bucket=app.BUCKET,Key=key,Body=payload) r=app.s3.get_object(Bucket=app.BUCKET,Key=key);body=r['Body'] try:assert body.read()==payload finally:body.close() print('S3 upload/readback passed') PY chown -R log-atlas:log-atlas /var/lib/log-atlas cat > /etc/systemd/system/log-atlas.service <<'EOF' [Unit] Description=Log Atlas private log catalogue After=network-online.target Wants=network-online.target [Service] User=log-atlas Group=log-atlas WorkingDirectory=/opt/log-atlas EnvironmentFile=/etc/log-atlas/runtime.env ExecStart=/opt/log-atlas/venv/bin/uvicorn app:app --host 127.0.0.1 --port 8787 --workers 1 --no-proxy-headers Restart=on-failure RestartSec=5 UMask=0077 NoNewPrivileges=true PrivateTmp=true ProtectSystem=strict ProtectHome=true ReadWritePaths=/var/lib/log-atlas MemoryMax=512M [Install] WantedBy=multi-user.target EOF python3 - <<'PY' import json from pathlib import Path v=json.loads(Path('/etc/log-atlas/site.json').read_text()) Path('/etc/caddy/Caddyfile').write_text(v['address']+' {\n request_body {\n max_size 536870912\n }\n reverse_proxy 127.0.0.1:8787\n}\n') PY caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile systemctl daemon-reload systemctl enable --now log-atlas.service systemctl enable caddy systemctl restart caddy for attempt in 1 2 3 4 5; do if curl -fsS http://127.0.0.1:8787/healthz; then break; fi; sleep 1; done curl -fsS http://127.0.0.1:8787/healthz >/dev/null python3 - <<'PY' import json from pathlib import Path print('\nOpen '+json.loads(Path('/etc/log-atlas/site.json').read_text())['origin']) print('DNS must point to this VPS. Allow inbound TCP 80 and the HTTPS port in your provider firewall. Certificate issuance may take time.') PY