Script to refresh the labels in our database

This commit is contained in:
Jonny007-MKD 2015-03-12 21:20:33 +01:00
parent d1db36e221
commit 082ddfcd94
2 changed files with 56 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
labelsOfTorrents.db
.tmp

54
refreshDb.sh Executable file
View File

@ -0,0 +1,54 @@
#!/bin/bash
# This script refreshes all labels from the torrent clients
delugeLabels="/etc/deluged/label.conf" # Path to label.conf in DelugeD conf dir
deadline="2 months" # `date -d` compatible time interval
PwD=$(readlink -e $0) # Get the path to this script
PwD=$(dirname "$PwD")
db="$PwD/labelsOfTorrents.db"
if [ ! -f "$db" ]; then # db does not exist
echo "DB does not exist!" >&2
exit 1;
fi
if [ -n "$delugeLabels" -a ! -f "$delugeLabels" ]; then
echo "label.conf not found at $delugeLabels" >&2
exit 1;
fi
deadline=$(date +%s -d "-$deadline") # get timestamp of deadline
#echo $deadline
touch $db.tmp
while IFS=' ' read -r time daemon id name label; do # read DB
if [ $time -gt $deadline ]; then # if entry is not too old
case $daemon in
deluge)
labelNew=$(grep -m 1 $id $delugeLabels | grep -o ': ".*"' | grep -o '[a-zA-Z0-9_-]*') # get label from Deluge
;;
*)
echo "Unknown daemon $daemon!" >&2
exit 2
;;
esac
if [ -n "$labelNew" ]; then
label=$labelNew; # set label
fi
#echo $time $daemon $id $name $label
echo $time $daemon $id $name $label >> $db.tmp; # keep in db
#else
#echo skipped $time $daemon $id $name $label
fi
done < $db;
mv $db.tmp $db
chmod 666 $db