52 lines
1.0 KiB
Bash
Executable File
52 lines
1.0 KiB
Bash
Executable File
#!/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
|
|
|