#!/bin/sh PYTHON=python3 SQLITE=sqlite3 export DB="/app/forum.db" export SERVER=gunicorn export PID="forum.pid" export WORKERS=4 if [[ $( stat -c %u /app ) -ne $( id -u ) ]]; then echo User id and /app folder owner do not match printf 'UID: %s\nFolder: %s\n' $( id -u ) $( stat -c %u /app ) exit 1 fi set -eu . /opt/venv/bin/activate if [[ -e "$DB" ]]; then $SQLITE -header "$DB" "SELECT version,name,description,registration_enabled,login_required FROM config" echo Database already exists else password=$($PYTHON tool.py password "$ADMINP") time=$($PYTHON -c 'import time; print(time.time_ns())') version=$($PYTHON tool.py version) $SQLITE "$DB" -init schema.txt "insert into config ( version, name, description, secret_key, captcha_key, registration_enabled, login_required ) values ( '$version', 'Forum', '', '$(head -c 30 /dev/urandom | base64)', '$(head -c 30 /dev/urandom | base64)', 0, 1 )" $SQLITE "$DB" " insert into users (name, password, role, join_time) values (lower('$ADMINU'), '$password', 2, $time) " fi exec "$SERVER" -w $WORKERS 'main:app' --pid="$PID" -b 0.0.0.0:5000