-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqTorrents.sh
executable file
·69 lines (60 loc) · 1.75 KB
/
qTorrents.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
# qTorrrents.sh by ignaci0
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
# Instructions:
# This scripts needs two arguments, the queue directory,
# i.e. the source directory and the watch directorty.
#
# Also you'll have to add the following line to the .rtorrent.rc:
#
# system.method.set_key=event.download.finished,move_complete,"execute=~/enqueue_rtorrent.sh,~/queue,~/torrents"
#
# Where ~/queue and ~/torrents are their arguments
#
LOGFILE=`dirname $0`"/"`basename $0 .sh`".log"
QUEUE_DIR=$1
WATCH_DIR=$2
function logger()
{
printf "[`date`] $*\n" >> $LOGFILE;
}
function check_directory()
{
dir=$1
desc=$2
if [[ ! -d "$dir" ]]
then
logger "$desc directory not found: $dir";
exit 1;
fi
}
check_directory "$QUEUE_DIR" "Queue";
check_directory "$WATCH_DIR" "Watch";
file=$(ls -tr -w1 $QUEUE_DIR/*.torrent 2>/dev/null | head -n 1 )
if [[ "x$file" != "x" ]]
then
mv "$file" "$WATCH_DIR";
rv=$?
if [[ $rv -eq 0 ]]
then
logger "$file added to the watch directory";
else
logger "Couln't move file $file to the watch directory";
fi
fi
exit $rv;