moved config to a json, which makes adding more variables easier, but perhaps otherwise adds complexity

This commit is contained in:
Ville Rantanen
2023-07-28 13:08:54 +03:00
parent 80af9c321c
commit f1c453d3d4
18 changed files with 258 additions and 182 deletions

51
forum/init_forum.sh Executable file
View File

@@ -0,0 +1,51 @@
#!/usr/bin/env bash
SQLITE=sqlite3
PYTHON=python3
set -e
if [ -z "$DB" ]; then
echo set DB env to point the Sqlite database.
exit 1
fi
if [ -z "$CONF" ]; then
echo set CONF env to point the config file.
exit 1
fi
if [ -e "$CONF" ]; then
echo Config exists
else
version=$($PYTHON tool.py version)
cat <<EOF > "$CONF"
{
"version": "$version",
"server_name": "Forum",
"server_description": "",
"secret_key": "$(head -c 30 /dev/urandom | base64)",
"captcha_key": "$(head -c 30 /dev/urandom | base64)",
"registration_enabled": false,
"login_required": true,
"threads_per_page": 50,
"user_css": ""
}
EOF
echo "Config '$CONF' created" >&2
fi
if [ -e "$DB" ]; then
echo Database already exists
else
password=$($PYTHON tool.py password "$ADMINP")
time=$($PYTHON -c 'import time; print(time.time_ns())')
$SQLITE "$DB" -init schema.txt "
insert into users (name, password, role, join_time)
values (lower('$ADMINU'), '$password', 2, $time)
"
echo "Database '$DB' created" >&2
fi