-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate_sqlite_db.sh
executable file
·53 lines (43 loc) · 1.23 KB
/
create_sqlite_db.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
set -euo pipefail
# Check if the script is being run from the project root
check_run_from_project_root() {
local script_name=$(basename "$0")
if [[ "$0" != "./scripts/$script_name" && "$0" != "scripts/$script_name" ]]; then
echo "Error: This script should be run from the project root as:"
echo " ./scripts/$script_name"
echo ""
echo "Current run path: $0"
exit 1
fi
}
# Check script is run from project root
check_run_from_project_root
DB_PATH="../../db"
DB_FILE="powerdns.db"
SQLITE_BIN=sqlite3
SCHEMA_FILE="../sql/pdns/47/schema.sqlite3.sql"
# Check if schema file exists
if ! command -v $SQLITE_BIN &> /dev/null; then
echo "Error: sqlite3 is not installed"
exit 1
fi
# Check if schema file exists
if [ ! -f "$SCHEMA_FILE" ]; then
echo "Error: Schema file not found: $SCHEMA_FILE"
exit 1
fi
# Check if directory exists
if [ ! -d "$DB_PATH" ]; then
mkdir -p "$DB_PATH"
fi
# Check if db file exists
if [ -e "$DB_PATH/$DB_FILE" ]; then
echo "Error: database file <$DB_PATH/$DB_FILE> already exists!"
exit 1
fi
# Import db schema and data
"$SQLITE_BIN" "$DB_PATH/$DB_FILE" < "$SCHEMA_FILE"
# Change access rights
chmod 777 $DB_PATH
chmod 666 $DB_PATH/$DB_FILE