2021-10-29 22:49:52 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-11-10 00:22:24 -08:00
|
|
|
[ -z "$XDG_CONFIG_HOME" ] && XDG_CONFIG_HOME="$HOME/.config"
|
|
|
|
|
2021-11-08 00:37:24 -08:00
|
|
|
DIR="$XDG_CONFIG_HOME/aniwrapper"
|
2021-10-29 22:49:52 -07:00
|
|
|
DB='history.sqlite3'
|
|
|
|
|
2021-10-30 00:53:18 -07:00
|
|
|
log() {
|
|
|
|
printf "%s\n" "$1"
|
|
|
|
}
|
|
|
|
|
2021-11-11 14:13:11 -08:00
|
|
|
while getopts 'cdrqCs' OPT; do
|
2021-10-29 22:49:52 -07:00
|
|
|
case "$OPT" in
|
2021-11-07 22:02:31 -08:00
|
|
|
c)
|
|
|
|
log "Creating database..."
|
2022-01-02 09:53:16 -08:00
|
|
|
sqlite3 "$DIR"/"$DB" < sql/search_history_tbl.sql
|
|
|
|
sqlite3 "$DIR"/"$DB" < sql/watch_history_tbl.sql
|
2021-11-07 22:02:31 -08:00
|
|
|
log "Created database..."
|
|
|
|
;;
|
|
|
|
d)
|
|
|
|
log "Deleting database..."
|
|
|
|
echo "$DIR/$DB"
|
|
|
|
rm "$DIR/$DB"
|
|
|
|
log "Database deleted..."
|
|
|
|
;;
|
2021-10-29 22:49:52 -07:00
|
|
|
|
2021-11-07 22:02:31 -08:00
|
|
|
r)
|
|
|
|
log "Deleting database..."
|
|
|
|
rm -rf "$DIR"/"$DB"
|
|
|
|
mkdir -p "$DIR"
|
|
|
|
log "Database deleted..."
|
|
|
|
log "Creating database..."
|
2022-01-02 09:53:16 -08:00
|
|
|
sqlite3 "$DIR"/"$DB" < sql/search_history_tbl.sql
|
|
|
|
sqlite3 "$DIR"/"$DB" < sql/watch_history_tbl.sql
|
2021-11-07 22:02:31 -08:00
|
|
|
log "Created database..."
|
|
|
|
;;
|
|
|
|
q)
|
|
|
|
log "Connecting to database..."
|
|
|
|
sqlite3 "$DIR/$DB"
|
|
|
|
log "Ending connection to databse..."
|
|
|
|
;;
|
|
|
|
C)
|
|
|
|
log "Cleaning up database..."
|
2021-11-12 17:22:22 -08:00
|
|
|
stmt="DELETE FROM search_history WHERE anime_name IS NULL OR anime_name = ''"
|
2021-11-07 22:02:31 -08:00
|
|
|
log "Cleaning up search history..."
|
2022-01-02 09:53:16 -08:00
|
|
|
sqlite3 "$DIR/$DB" <<< "$stmt"
|
2021-11-12 17:22:22 -08:00
|
|
|
stmt="DELETE FROM watch_history WHERE anime_name IS NULL OR anime_name = '' OR episode_number = 0"
|
2021-11-07 22:02:31 -08:00
|
|
|
log "Cleaning up watch history..."
|
2022-01-02 09:53:16 -08:00
|
|
|
sqlite3 "$DIR/$DB" <<< "$stmt"
|
2021-11-07 22:02:31 -08:00
|
|
|
;;
|
2021-11-11 14:13:11 -08:00
|
|
|
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
|
|
|
|
;;
|
2021-11-07 22:02:31 -08:00
|
|
|
*)
|
|
|
|
log "Does not exist or not implemented yet..."
|
|
|
|
exit 1
|
|
|
|
;;
|
2021-10-29 22:49:52 -07:00
|
|
|
esac
|
|
|
|
done
|