Add admin account when running init_sqlite.sh

This commit is contained in:
David Hoppenbrouwers
2022-10-09 17:34:47 +02:00
parent 869270733d
commit b6b66049d6
4 changed files with 61 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
#!/usr/bin/env bash
SQLITE=sqlite3
PYTHON=python3
set -e
@@ -10,7 +11,19 @@ then
exit 1
fi
$SQLITE $1 -init schema.txt "insert into config (
if [ -e "$1" ]
then
echo "Database '$1' already exists" >&2
exit 1
fi
read -p 'Admin username: ' username
read -sp 'Admin password: ' password
password=$($PYTHON tool.py password "$password")
time=$($PYTHON -c 'import time; print(time.time_ns())')
$SQLITE "$1" -init schema.txt "insert into config (
version,
name,
description,
@@ -25,4 +38,10 @@ values (
'$(head -c 30 /dev/urandom | base64)',
'$(head -c 30 /dev/urandom | base64)',
0
);"
);
insert into users (name, password, role, join_time)
values (lower('$username'), '$password', 2, $time);
"
echo "Database '$1' created" >&2