29 lines
1.1 KiB
Bash
Executable File
29 lines
1.1 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
cd "$(dirname "$0")/.."
|
|
host=${1:-stage.slumpxland-official.com}
|
|
port=${2:-8093}
|
|
if [ "$#" -gt 2 ] || ! printf '%s\n' "$host" | grep -Eq '^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,63}$' || ! printf '%s\n' "$port" | grep -Eq '^[1-9][0-9]{0,4}$' || [ "$port" -gt 65535 ] || [ "$port" -lt 1024 ]; then
|
|
printf 'Usage: sh scripts/setup.sh [hostname] [port 1024-65535]\n' >&2
|
|
exit 2
|
|
fi
|
|
if [ -e .env ] || [ -e secrets ]; then
|
|
printf 'Setup already exists. Edit .env to change hostname or port; keep the existing secrets.\n' >&2
|
|
exit 1
|
|
fi
|
|
umask 077
|
|
db_password=$(openssl rand -hex 32)
|
|
django_secret=$(openssl rand -hex 48)
|
|
mkdir -m 0700 secrets
|
|
printf '%s\n' "$db_password" > secrets/db_password
|
|
printf '%s\n' "$django_secret" > secrets/django_secret
|
|
chmod 0644 secrets/db_password secrets/django_secret
|
|
cat > .env <<CONFIG
|
|
SLX_ALLOWED_HOSTS=$host,localhost
|
|
SLX_CSRF_ORIGINS=https://$host
|
|
SLX_PORT=$port
|
|
SLX_BEHIND_CADDY=1
|
|
SLX_HTTPS=1
|
|
CONFIG
|
|
printf 'Configured %s on local port %s. Next: docker compose up -d --build\n' "$host" "$port"
|