#!/bin/bash

mkdir authentik
cd authentik

git init
git pull https://github.com/goauthentik/authentik

cp /home/authentik/authentik/lib/default.yml /etc/authentik/config.yml
cat << EOF > /etc/authentik/config.yml
secret_key: "$(openssl rand -base64 60 | tr -d '\n')"
EOF

curl -LsSf https://astral.sh/uv/install.sh | sh

uv sync
uv run ak build_schema

bun i --cwd web --no-save
NODE_RUN_SCRIPT_NAME=build bun run --cwd web wireit

uv run python -m lifecycle.migrate

uv run ak server