-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathtorrent_status.sh
91 lines (84 loc) · 3.18 KB
/
torrent_status.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
#!/bin/bash
# Requirements rTorrent, deluge & linux
option(){
answer=$1;
case "$answer" in
1) rtorrent_restart ;;
2) deluge_restart ;;
3) rtorrent_status ;;
4) deluge_status ;;
5) hdd_usage ;;
*) echo "1 or 2" ; exit;
esac;
}
rtorrent_restart(){
#reply=''
if pgrep -U $(whoami) rtorrent &>/dev/null ; then
echo -en "\e[32mrtorrent is running, do you want to restart it? yes/no \e[0m"
read -p ":" reply
if [[ "$reply" = 'yes' ]]; then
echo -e "\e[33mrestarting rtorrent...\e[0m"
screen -X -S rtorrent quit >&/dev/null
# kill -9 $(pgrep -u $(whoami) rtorrent) >&/dev/null
# kill -9 $(pgrep -u $(whoami) screen) >&/dev/null
# kill -9 $(pgrep -u $(whoami) irssi) >&/dev/null
screen -wipe >&/dev/null
# rm -f /var/run/screen/S-$/$(whoami).rtorrent
# rm -f /var/run/screen/S-$(whoami)/$(whoami).irssi >&/dev/null
# rm -f ~/rtorrent/.session/rtorrent.lock
screen -dm -S rtorrent rtorrent >&/dev/null
sleep 1
pgrep -U $(whoami) rtorrent >&/dev/null
[[ $? = 0 ]] && echo -e "\e[31mrtorrent restarted and is running\e[0m" || echo -e "\e[31mcan't start rtorrent, please contact support\e[0m"
else
echo -e "\e[31mexiting...\e[0m"
fi
else
echo -e "\e[33mrestarting rtorrent...\e[0m"
screen -X -S rtorrent quit >&/dev/null
screen -wipe >&/dev/null
screen -dm -S rtorrent rtorrent >&/dev/null
sleep 1
pgrep -U $(whoami) rtorrent >&/dev/null
[[ $? = 0 ]] && echo -e "\e[31mrtorrent restarted and is running\e[0m" || echo -e "\e[31mcan't start rtorrent, please contact support\e[0m"
fi
}
deluge_restart(){
if [[ -f ~/.config/deluge/core.conf ]]; then
if pgrep -U $(whoami) deluged &>/dev/null ; then
echo -e "\e[32mdeluge is running, do you want to restart it? yes/no \e[0m"
read -p ":" reply
if [[ "$reply" = 'yes' ]]; then
echo -e "\e[33mrestarting deluge...\e[0m"
killall -I -9 deluged deluge-web
sleep 1
deluged && deluge-web -f
sleep 1
pgrep -U $(whoami) deluged &>/dev/null
[[ $? = 0 ]] && echo -e "\e[31mdeluge restarted and is running\e[0m" || echo -e "\e[31mcan't start deluge, please contact support\e[0m"
else
echo -e "\e[31mexiting...\e[0m"
exit
fi
else
killall -I -9 deluged deluge-web
sleep 1
deluged && deluge-web -f
sleep 1
pgrep -U $(whoami) deluged &>/dev/null
[[ $? = 0 ]] && echo -e "\e[31mdeluge restarted and is running\e[0m" || echo -e "\e[31mcan't start deluge, please contact support\e[0m"
fi
else
echo -e "\e[31myou don't have deluge installed, exiting...\e[0m"
fi
}
rtorrent_status(){
pgrep -U $(whoami) rtorrent &>/dev/null && echo -e "\e[33mrtorrent is running\e[0m" || echo -e "\e[31mrtorrent is down\e[0m"
}
deluge_status(){
[[ -f ~/.config/deluge/core.conf ]] && pgrep -U $(whoami) deluge &>/dev/null && echo -e "\e[33mdeluge is running\e[0m" || echo -e "\e[31mdeluge is down\e[0m"
}
hdd_usage(){
echo -e "\e[33mused $(du -sh ~ | awk -F " " '{print $1}')iB\e[0m"
}
option $*