Compare commits

..

No commits in common. "221782a25584bf38a4d9000fc4df989b8588cb07" and "a85aa9e3a13406ba6b38921fffc493125c8d153c" have entirely different histories.

3 changed files with 28 additions and 15 deletions

Binary file not shown.

View File

@ -6,7 +6,7 @@
DEFAULT_LOGFILE="./jvb.log" DEFAULT_LOGFILE="./jvb.log"
DEFAULT_ROTATED_LOGFILE="./jvb.log.1" DEFAULT_ROTATED_LOGFILE="./jvb.log.1"
# Default SQLite database file # Default SQLite database file
DEFAULT_DB="./jilo.db" DEFAULT_DB="./jitsi-stats.db"
# Configuration file # Configuration file
CONFIG_FILE="./jilo.conf" CONFIG_FILE="./jilo.conf"
@ -27,16 +27,16 @@ DB=${DB:-$DEFAULT_DB}
db_get_state="SELECT filename, filetime, filesize, position, inode FROM state WHERE jitsi_component = 'JVB';" db_get_state="SELECT filename, filetime, filesize, position, inode FROM state WHERE jitsi_component = 'JVB';"
db_set_state_template="UPDATE state SET time=datetime('now'), filename='%s', filetime='%s', filesize='%s', position='%s', inode='%s' WHERE jitsi_component = 'JVB';" db_set_state_template="UPDATE state SET time=datetime('now'), filename='%s', filetime='%s', filesize='%s', position='%s', inode='%s' WHERE jitsi_component = 'JVB';"
db_insert_template="INSERT INTO conferences (conference_name, conference_id, start, end) VALUES ('%s', '%s', '%s', '%s');" db_insert_template="INSERT INTO conferences (conference_name, conference_id, start, end) VALUES ('%s', '%s', '%s', '%s');"
db_drop=" db_create="
DROP TABLE IF EXISTS conferences; DROP TABLE IF EXISTS conferences;
DROP TABLE IF EXISTS state;" CREATE TABLE conferences (
db_create="CREATE TABLE conferences (
id INTEGER PRIMARY_KEY, id INTEGER PRIMARY_KEY,
conference_name TEXT, conference_name TEXT,
conference_id TEXT, conference_id TEXT,
start TEXT, start TEXT,
end TEXT end TEXT
); );
DROP TABLE IF EXISTS state;
CREATE TABLE state ( CREATE TABLE state (
id INTEGER PRIMARY_KEY, id INTEGER PRIMARY_KEY,
jitsi_component TEXT, jitsi_component TEXT,
@ -46,11 +46,12 @@ CREATE TABLE state (
filesize INTEGER, filesize INTEGER,
position INTEGER CHECK(typeof(position)='integer'), position INTEGER CHECK(typeof(position)='integer'),
inode INTEGER inode INTEGER
);" );
db_init="INSERT OR REPLACE INTO state (id, jitsi_component, time, filename, filetime, filesize, position, inode) VALUES (1, 'JVB', '1970-01-01 00:00:00.000', '', 0, 0, 0, 0);" INSERT OR REPLACE INTO state (id, jitsi_component, time, filename, filetime, filesize, position, inode) VALUES (1, 'JVB', '1970-01-01 00:00:00.000', '', 0, 0, 0, 0);"
db_flush=" db_flush="
DELETE FROM conferences; DELETE FROM conferences;
DELETE FROM state;" DELETE FROM state;
INSERT OR REPLACE INTO state (id, jitsi_component, time, filename, filetime, filesize, position, inode) VALUES (1, 'JVB', '1970-01-01 00:00:00.000', '', 0, 0, 0, 0);"
help="Usage:\n\t$0 [OPTION]\nOptions:\n\t--create-db|-d - create the database\n\t--flush|-f - flush the tables\n\t--check|-c - check for new data\n\t--parse|-p [-v] - parse the logs [verbosely]" help="Usage:\n\t$0 [OPTION]\nOptions:\n\t--create-db|-d - create the database\n\t--flush|-f - flush the tables\n\t--check|-c - check for new data\n\t--parse|-p [-v] - parse the logs [verbosely]"
@ -186,16 +187,13 @@ shift $((OPTIND -1))
case "$cmd" in case "$cmd" in
--create-db) --create-db)
sqlite3 "$DB" "$db_drop"
sqlite3 "$DB" "$db_create" sqlite3 "$DB" "$db_create"
sqlite3 "$DB" "$db_init"
echo "Database created." echo "Database created."
exit 0 exit 0
;; ;;
--flush) --flush)
sqlite3 "$DB" "$db_flush" sqlite3 "$DB" "$db_flush"
sqlite3 "$DB" "$db_init"
echo "Tables flushed." echo "Tables flushed."
exit 0 exit 0
;; ;;
@ -203,15 +201,14 @@ case "$cmd" in
--check) --check)
# First check if database exists # First check if database exists
if [[ ! -f "$DB" ]]; then if [[ ! -f $"DB" ]]; then
echo "Database not found. If it's a fresh install, please install the database first." echo "Database not found. If it's a fresh install, please install the database first."
exit 1 exit 1
fi fi
# compare the DB schema to the expected one # Check the state table
current_db_schema=$(sqlite3 "$DB" .schema) if ! sqlite3 "$DB" ".schema state" &>/dev/null; then
if [[ "$current_db_schema" != "$db_create" ]]; then echo "The database doesn't contain the required table \"state\". Please check it, and if needed, reinstall it."
echo "The database doesn't match the expected schema. Please check it, and if needed, reinstall it."
exit 1 exit 1
fi fi

View File

@ -0,0 +1,16 @@
CREATE TABLE IF NOT EXISTS conferences (
id INTEGER PRIMARY_KEY,
conference_name TEXT,
conference_id TEXT,
start TEXT,
end TEXT
);
CREATE TABLE IF NOT EXISTS state (
id INTEGER PRIMARY_KEY,
time TEXT,
filename TEXT,
filetime INTEGER,
position INTEGER CHECK(typeof(position)='integer'),
inode INTEGER
);
INSERT OR IGNORE INTO state (id, time, filename, filetime, position, inode) VALUES (1, '1970-01-01 00:00:00.000', '', 0, 0, 0);