infrastructure-ng/id.tjo.space/configure.sh

71 lines
1.7 KiB
Bash
Raw Normal View History

2025-03-07 11:13:53 +00:00
#!/bin/bash
set -euo pipefail
SERVICE_DIR="/root/service"
mkdir -p ${SERVICE_DIR}
cd ${SERVICE_DIR}
echo "== Fetch Source Code (from git)"
# Clone if not yet cloned
if [ ! -d .git ]; then
git clone \
--depth 1 \
--no-checkout \
--filter=tree:0 \
https://github.com/tjo-space/tjo-space-infrastructure.git .
git sparse-checkout set --no-cone /id.tjo.space
git checkout
else
git fetch --depth=1
git reset --hard origin/main
fi
echo "=== Configure Firewall"
ufw default deny incoming
ufw default allow outgoing
2025-03-07 21:08:41 +00:00
ufw default allow forward
2025-03-07 11:13:53 +00:00
ufw allow 22/tcp # SSH
ufw allow 80/tcp # HTTP
ufw allow 443/tcp # HTTPS
ufw --force enable
echo "=== Copy Configuration Files"
rsync -a id.tjo.space/containers/ /etc/containers/systemd/
rsync -a id.tjo.space/configs/ /etc/
systemctl daemon-reload
echo "=== Read Secrets"
age -d -i /etc/age/key.txt id.tjo.space/secrets.env.encrypted >id.tjo.space/secrets.env
set -a && source id.tjo.space/secrets.env && set +a
2025-03-07 11:27:13 +00:00
echo "=== Prepare srv directories"
mkdir -p /srv/authentik/{media,certs,custom-templates}
mkdir -p /srv/postgresql/data
2025-03-07 11:13:53 +00:00
echo "=== Setup Caddy"
2025-03-07 11:51:13 +00:00
systemctl restart caddy
2025-03-07 11:13:53 +00:00
echo "=== Setup Postgresql"
2025-03-07 11:22:24 +00:00
mkdir -p /etc/postgresql
2025-03-07 11:13:53 +00:00
cat <<EOF >/etc/postgresql/secrets.env
POSTGRES_PASSWORD=${POSTGRESQL_PASSWORD}
EOF
2025-03-07 11:51:13 +00:00
systemctl restart postgresql
2025-03-07 11:13:53 +00:00
2025-03-07 11:28:22 +00:00
echo "=== Setup Valkey"
2025-03-07 11:51:13 +00:00
systemctl restart valkey
2025-03-07 11:13:53 +00:00
echo "=== Setup Authentik Server"
2025-03-07 11:22:24 +00:00
mkdir -p /etc/authentik
2025-03-07 11:13:53 +00:00
cat <<EOF >/etc/authentik/secrets.env
AUTHENTIK_SECRET_KEY=${AUTHENTIK_SECRET_KEY}
AUTHENTIK_EMAIL__PASSWORD=${AUTHENTIK_EMAIL__PASSWORD}
AUTHENTIK_POSTGRESQL__PASSWORD=${POSTGRESQL_PASSWORD}
EOF
2025-03-07 11:51:13 +00:00
systemctl restart authentik-server
2025-03-07 11:13:53 +00:00
echo "=== Setup Authentik Worker"
2025-03-07 11:51:13 +00:00
systemctl restart authentik-worker