summaryrefslogtreecommitdiff
path: root/sioyek_db_gen.sh
diff options
context:
space:
mode:
Diffstat (limited to 'sioyek_db_gen.sh')
-rwxr-xr-xsioyek_db_gen.sh47
1 files changed, 47 insertions, 0 deletions
diff --git a/sioyek_db_gen.sh b/sioyek_db_gen.sh
new file mode 100755
index 0000000..05a7b69
--- /dev/null
+++ b/sioyek_db_gen.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+
+PDFs="$HOME/PDFs"
+TTRPGs="$HOME/Downloads/TTRPGs"
+SIOYEK="$HOME/.local/share/sioyek"
+LOCALDB="$SIOYEK/local.db"
+SHAREDDB="$SIOYEK/shared.db"
+
+#backup just in case
+[[ -f "$LOCALDB" ]] && cp "$LOCALDB" "$LOCALDB.backup"
+[[ -f "$SHAREDDB" ]] && cp "$SHAREDDB" "$SHAREDDB.backup"
+
+echo "Compiling PDF list..."
+mapfile -t FILES < <( ( find $PDFs -type f -iregex "^.*\.pdf$" -printf "$PDFs/%P\n"; find $TTRPGs -type f -iregex "^.*\.pdf$" -printf "$TTRPGs/%P\n" ) | cat | sort --version-sort )
+
+# save against collision errors
+echo "Calculating file hashes..."
+
+i=0
+mapfile -t HASHES < <( for FILE in "${FILES[@]}"; do md5sum "$FILE" | cut -d' ' -f1 ; done )
+
+
+
+echo "Creating database..."
+sqlite3 "$LOCALDB" "drop table if exists document_hash;"
+sqlite3 "$LOCALDB" "create table if not exists document_hash (id INTEGER PRIMARY KEY AUTOINCREMENT,path TEXT,hash TEXT,UNIQUE(path, hash));"
+
+sqlite3 "$SHAREDDB" "create table if not exists bookmarks (id INTEGER PRIMARY KEY AUTOINCREMENT,document_path TEXT,desc TEXT,creation_time timestamp,modification_time timestamp,uuid TEXT,font_size integer DEFAULT -1,color_red real DEFAULT 0,color_green real DEFAULT 0,color_blue real DEFAULT 0,font_face TEXT,begin_x real DEFAULT -1,begin_y real DEFAULT -1,end_x real DEFAULT -1,end_y real DEFAULT -1,offset_y real);"
+sqlite3 "$SHAREDDB" "create table if not exists highlights (id INTEGER PRIMARY KEY AUTOINCREMENT,document_path TEXT,desc TEXT,text_annot TEXT,type char,creation_time timestamp,modification_time timestamp,uuid TEXT,begin_x real,begin_y real,end_x real,end_y real);"
+sqlite3 "$SHAREDDB" "create table if not exists links (id INTEGER PRIMARY KEY AUTOINCREMENT,creation_time timestamp,modification_time timestamp,uuid TEXT,src_document TEXT,dst_document TEXT,src_offset_y REAL,src_offset_x REAL,dst_offset_x REAL,dst_offset_y REAL,dst_zoom_level REAL);"
+sqlite3 "$SHAREDDB" "create table if not exists marks (id INTEGER PRIMARY KEY AUTOINCREMENT,document_path TEXT,symbol CHAR,offset_x real,offset_y real,zoom_level real,creation_time timestamp,modification_time timestamp,uuid TEXT,UNIQUE(document_path, symbol));"
+
+sqlite3 "$SHAREDDB" "drop table if exists opened_books;"
+sqlite3 "$SHAREDDB" "create table opened_books (id INTEGER PRIMARY KEY AUTOINCREMENT,path TEXT UNIQUE,document_name TEXT,zoom_level REAL,offset_x REAL,offset_y REAL,last_access_time TEXT);"
+
+i=0
+for FILE in "${FILES[@]}"; do
+ FILE=$( sed -r "s|'|''|g" <<< "$FILE" )
+ DATE=$( shuf -n1 -i$(date -d '1987-01-01' '+%s')-$(date '+%s') | xargs -I{} date -d '@{}' '+%Y-%m-%d %H:%M:%S' )
+ echo $FILE
+ sqlite3 "$LOCALDB" "insert into document_hash (path, hash) values ('$FILE', '${HASHES[i]}');"
+ sqlite3 "$SHAREDDB" "insert into opened_books (path, document_name, zoom_level, offset_x, offset_y, last_access_time) values ('${HASHES[i]}', '$FILE', 1.5, 0, 300, '$DATE');"
+ ((i++))
+done
+
+echo "Done."