Add helper script

This commit is contained in:
~lucidiot 2023-02-24 15:37:08 +01:00
parent 42b004c664
commit 73500a0515
1 changed files with 17 additions and 0 deletions

17
bin/booksql Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
set -eu
# Path to the booksql installation, configurable
BOOKSQL_PATH="${BOOKSQL_PATH:-"$(dirname -- "$(dirname -- "$(readlink -f "$0")")")"}"
# Path to the booksql SQLite database, configurable
BOOKSQL_DB_PATH="${BOOKSQL_DB_PATH:-"$BOOKSQL_PATH/db.sqlite"}"
if [ ! -e "$BOOKSQL_PATH" ]; then
echo "booksql installation at $BOOKSQL_PATH not found" >&2
exit 1
fi
if [ ! -e "$BOOKSQL_DB_PATH" ]; then
echo "Creating new database at $BOOKSQL_DB_PATH" >&2
cat "$BOOKSQL_PATH/schema.sql" "$BOOKSQL_PATH/init.sql" | sqlite3 -bail "$BOOKSQL_DB_PATH"
fi
sqlite3 -box -cmd 'PRAGMA foreign_keys = ON' -cmd 'PRAGMA ignore_check_constraints = OFF' "$BOOKSQL_DB_PATH"