-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.sh
146 lines (100 loc) · 4.73 KB
/
setup.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<< 'COMMENT'
Manual Setup Instructions:
Ensure system.file.allocate.set = 0. This is the default setting in rtorrent so it's not necessary to include it in your rtorrent.rc file.
1. Add the following code to your ~/.rtorrent.rc file !! making sure to update the paths to client.py & server.py !!
method.set_key = event.download.erased, checker_erase, "execute.throw.bg=python3,/path/to/client.py,delete,$d.hash=,$d.name=,$d.directory="
method.set_key = event.download.inserted_new, checker, "branch=((and,((not,((d.is_meta)))),((d.state)))),((dcheck))"
method.insert = dcheck, simple, d.stop=, "execute.throw.bg=python3,/path/to/client.py,$d.name=,$d.hash=,$d.directory=,$d.size_bytes="
execute.throw.bg = python3, "/path/to/server.py"
2. SCGI Addition
2a. Enter the following command in your terminal to obtain your SCGI address/port or unix socket file path:
grep -oP "^[^#]*scgi.* = \K.*" ~/.rtorrent.rc
2b. Update the scgi variable in line 9 of config.py with your own SCGI address/port or unix socket file path.
3. Optional: As an extra layer of protection you may add the close_low_diskspace command to your rtorrent.rc file. This command will make rtorrent periodically
check your disk space and stop all downloading torrents if your disk space falls below a threshold.
schedule2 = low_diskspace,0,55,close_low_diskspace=1G
55 = the time in seconds the check is ran
1G = the threshold in Gigabytes
4. Run setup.py. If you opted to include close_low_diskspace, run setup.py with two arguments; interval and threshold. So for the above example,
setup.py would be ran as: python setup.py 55 1
If setup.py fails, you will need to restart rtorrent for your changes to the rtorrent.rc file to take effect.
COMMENT
low_diskspace=false
rtorrent="$HOME/.rtorrent.rc"
if [[ ! -f $rtorrent ]]; then
echo ".rtorrent.rc file not found in $HOME. Terminating script."
exit
fi
allocation=$(grep -oP "system.file.allocate.* = \K.*" $rtorrent)
if [[ $allocation == 1 ]]; then
printf '\nThe script has detected that system.file.allocate is set to 1. This can cause the script to delete more files than necessary.'
printf '\n\nEnter [Y] to permit the script to set system.file.allocate to 0 or Enter [Q] to exit: '
while true; do
read answer
case $answer in
[yY] )
sed -i '/system.file.allocate/d' $rtorrent
sed -i '1isystem.file.allocate.set = 0' $rtorrent
break ;;
[qQ] )
exit ;;
* )
printf '\nEnter [Y] or [Q]: ' ;;
esac
done
fi
printf '\nDo you want rtorrent to stop all downloading torrents when your available space falls below a threshold? [Y]/[N]: '
while true; do
read answer
case $answer in
[yY] )
low_diskspace=true
printf '\nPlease enter a number representing the time in seconds the check will run per cycle: '
while true; do
read interval
case $interval in
''|*[!0-9]* ) printf '\nPlease enter a number: ' ;;
* ) break ;;
esac
done
printf '\nPlease enter a number representing the threshold in Gigabytes: '
while true; do
read amount
case $amount in
''|*[!0-9]* ) printf '\nPlease enter a number: ' ;;
* ) break ;;
esac
done
sed -i '/schedule2 = low_diskspace/d' $rtorrent
sed -i "1ischedule2 = low_diskspace,0,$interval,close_low_diskspace="$amount"G" $rtorrent
break ;;
[nN] )
break ;;
* )
printf '\nEnter [Y] or [N]: ' ;;
esac
done
# Delete existing entries
sed -i "\|execute.throw.bg = python.*, \"$PWD/server.py|d" $rtorrent
sed -i '/method.insert = dcheck, simple, d.stop=/d' $rtorrent
sed -i '/method.set_key = event.download.inserted_new, checker/d' $rtorrent
sed -i '/method.set_key = event.download.erased, checker_erase/d' $rtorrent
# Add to file
sed -i "1iexecute.throw.bg = python3, \"$PWD/server.py\"" $rtorrent
sed -i '1imethod.insert = dcheck, simple, d.stop=, "execute.throw.bg=python3,'"$PWD"'/client.py,$d.name=,$d.hash=,$d.directory=,$d.size_bytes="' $rtorrent
sed -i '1imethod.set_key = event.download.inserted_new, checker, "branch=((and,((not,((d.is_meta)))),((d.state)))),((dcheck))"' $rtorrent
sed -i '1imethod.set_key = event.download.erased, checker_erase, "execute.throw.bg=python3,'"$PWD"'/client.py,delete,$d.hash=,$d.name=,$d.directory="' $rtorrent
scgi=$(grep -oP "^[^#]*scgi.* = \K.*" $rtorrent)
if [[ -z $scgi ]]; then
printf '\n\033[0;36mUnable to locate a SCGI address or unix socket file path. Check your rtorrent.rc file and update the SCGI variable in config.py.\033[0m\n'
printf '\nRtorrent has to be restarted in order for the changes to take effect.'
else
sed -i "s|scgi.*=.*|scgi = "\'${scgi}\'"|" config.py
printf '\nSCGI has been updated in your config.py file.\n'
if [ "$low_diskspace" = true ]; then
python3 "$PWD/setup.py" $interval $amount
else
python3 "$PWD/setup.py"
fi
fi
printf '\nSetup has completed.\n'