booksql/bin/booksql

18 lines
676 B
Bash
Executable File

#!/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" "$@"