#!/bin/sh
set -eu

site=/etc/nginx/sites-available/filyx
env_file=/srv/filyx/.env

if ! grep -q 'filyx-oauth-callback.conf' "$site"; then
  sed -i '/client_max_body_size 32m;/a\
    include /etc/nginx/snippets/filyx-oauth-callback.conf;
' "$site"
fi

if ! grep -q '^FILYX_KICK_REDIRECT_URI=' "$env_file"; then
  printf '\nFILYX_KICK_REDIRECT_URI=https://filyx.hom3r-off.fr/auth/kick/bot/callback\nFILYX_OAUTH_CALLBACK_PORT=47831\n' >> "$env_file"
fi

chown debian:www-data "$env_file"
chmod 640 "$env_file"
nginx -t
systemctl reload nginx
