moved config to a json, which makes adding more variables easier, but perhaps otherwise adds complexity
This commit is contained in:
51
forum/init_forum.sh
Executable file
51
forum/init_forum.sh
Executable 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
|
||||
|
||||
Reference in New Issue
Block a user