mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-11-22 03:19:53 -08:00
add file_history table and update setup script
This commit is contained in:
parent
090f0e84e7
commit
21597fc1bc
79
db.sh
79
db.sh
@ -1,79 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
[ -z "$XDG_CONFIG_HOME" ] && XDG_CONFIG_HOME="$HOME/.config"
|
|
||||||
|
|
||||||
DIR="$XDG_CONFIG_HOME/aniwrapper"
|
|
||||||
DB='history.sqlite3'
|
|
||||||
|
|
||||||
log() {
|
|
||||||
printf "%s\n" "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
while getopts 'cdrqCs' OPT; do
|
|
||||||
case "$OPT" in
|
|
||||||
c)
|
|
||||||
log "Creating database..."
|
|
||||||
sqlite3 "$DIR"/"$DB" < sql/search_history_tbl.sql
|
|
||||||
sqlite3 "$DIR"/"$DB" < sql/watch_history_tbl.sql
|
|
||||||
log "Created database..."
|
|
||||||
;;
|
|
||||||
d)
|
|
||||||
log "Deleting database..."
|
|
||||||
echo "$DIR/$DB"
|
|
||||||
rm "$DIR/$DB"
|
|
||||||
log "Database deleted..."
|
|
||||||
;;
|
|
||||||
|
|
||||||
r)
|
|
||||||
log "Deleting database..."
|
|
||||||
rm -rf "$DIR"/"$DB"
|
|
||||||
mkdir -p "$DIR"
|
|
||||||
log "Database deleted..."
|
|
||||||
log "Creating database..."
|
|
||||||
sqlite3 "$DIR"/"$DB" < sql/search_history_tbl.sql
|
|
||||||
sqlite3 "$DIR"/"$DB" < sql/watch_history_tbl.sql
|
|
||||||
log "Created database..."
|
|
||||||
;;
|
|
||||||
q)
|
|
||||||
log "Connecting to database..."
|
|
||||||
sqlite3 "$DIR/$DB"
|
|
||||||
log "Ending connection to databse..."
|
|
||||||
;;
|
|
||||||
C)
|
|
||||||
log "Cleaning up database..."
|
|
||||||
stmt="DELETE FROM search_history WHERE anime_name IS NULL OR anime_name = ''"
|
|
||||||
log "Cleaning up search history..."
|
|
||||||
sqlite3 "$DIR/$DB" <<< "$stmt"
|
|
||||||
stmt="DELETE FROM watch_history WHERE anime_name IS NULL OR anime_name = '' OR episode_number = 0"
|
|
||||||
log "Cleaning up watch history..."
|
|
||||||
sqlite3 "$DIR/$DB" <<< "$stmt"
|
|
||||||
;;
|
|
||||||
s)
|
|
||||||
printf "%s" "Enter connection string for remote user in the form user@host: "
|
|
||||||
read -r connection_str
|
|
||||||
printf "%s" "Enter port to connect to remote host with or leave blank for default (22): "
|
|
||||||
read -r port
|
|
||||||
if [[ ! "${port/ //}" == "" ]]; then
|
|
||||||
PORT="$port"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! "@" != *"$connection_str" ]]; then
|
|
||||||
log "Enter in full connection string to remote user in the form: user@host"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
log "Syncing database with: $connection_str on port $PORT"
|
|
||||||
|
|
||||||
scp -P "$PORT" "$connection_str:$DIR/$DB" "$temp_db"
|
|
||||||
if [[ "$?" -ne 0 ]]; then
|
|
||||||
printf "%s\n" "Error getting database file from remote host"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
sync_search_history && sync_watch_history
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
log "Does not exist or not implemented yet..."
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
14
setup.sh
14
setup.sh
@ -48,21 +48,19 @@ run_setup() {
|
|||||||
log "Creating history database..."
|
log "Creating history database..."
|
||||||
sqlite3 "$DIR/$DB" < sql/watch_history_tbl.sql
|
sqlite3 "$DIR/$DB" < sql/watch_history_tbl.sql
|
||||||
sqlite3 "$DIR/$DB" < sql/search_history_tbl.sql
|
sqlite3 "$DIR/$DB" < sql/search_history_tbl.sql
|
||||||
|
sqlite3 "$DIR/$DB" < sql/file_history.sql
|
||||||
log "History database created..."
|
log "History database created..."
|
||||||
|
elif ! sqlite3 -noheader -batch "$DIR/$DB" ".tables" | grep 'file_history'; then
|
||||||
|
log "file_history table not found in database... creating table"
|
||||||
|
sqlite3 "$DIR/$DB" < sql/file_history.sql
|
||||||
|
log "file_history table created"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Move theme files and skip-intro script to correct locations
|
||||||
if [[ ! -f "$DIR/aniwrapper.rasi" ]]; then
|
if [[ ! -f "$DIR/aniwrapper.rasi" ]]; then
|
||||||
# Move theme files and skip-intro script to correct locations
|
|
||||||
log "aniwrapper.rasi does not exist in filesystem... Moving theme files"
|
log "aniwrapper.rasi does not exist in filesystem... Moving theme files"
|
||||||
cp themes/* "$DIR"/
|
cp themes/* "$DIR"/
|
||||||
log "Theme files moved..."
|
log "Theme files moved..."
|
||||||
elif diff -q "themes/aniwrapper.rasi" "$DIR/aniwrapper.rasi" &> /dev/null; then
|
|
||||||
log "Theme file has not changed... skipping"
|
|
||||||
else
|
|
||||||
log "Theme has changed... backing up old theme"
|
|
||||||
mv "$DIR/aniwrapper.rasi" "$DIR/aniwrapper.rasi.bak"
|
|
||||||
log "Renamed $DIR/aniwrapper.rasi -> $DIR/aniwrapper.rasi.bak"
|
|
||||||
cp themes/aniwrapper.rasi "$DIR/"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log "Creating mpv/scripts/ directory if it doesn't exist..."
|
log "Creating mpv/scripts/ directory if it doesn't exist..."
|
||||||
|
5
sql/file_history.sql
Normal file
5
sql/file_history.sql
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
CREATE TABLE file_history (
|
||||||
|
id integer PRIMARY KEY AUTOINCREMENT,
|
||||||
|
directory varchar(200) NOT NULL,
|
||||||
|
filename varchar(200) NOT NULL
|
||||||
|
);
|
Loading…
Reference in New Issue
Block a user