-
Notifications
You must be signed in to change notification settings - Fork 259
/
rutupgrade
executable file
·172 lines (148 loc) · 4.72 KB
/
rutupgrade
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
######################################################################
#
# Copyright (c) 2015 arakasi72 (https://github.com/arakasi72)
#
# --> Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
#
######################################################################
PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/bin:/sbin
newvers=$(curl -s https://raw.githubusercontent.com/Novik/ruTorrent/master/js/webui.js | grep -m 1 version: | cut -d \" -f2)
oldvers=$(grep -m 1 version: /var/www/rutorrent/js/webui.js | cut -d \" -f2)
ruflag=0
rurelease=$(curl -s "https://api.github.com/repos/Novik/ruTorrent/releases/latest" | awk -F '"' '/tag_name/{print $4}')
force_yes=1
restore_old=1
install_master=1
ask_restore() {
if [ $force_yes = 0 ]; then
return $restore_old
else
while true
do
echo "1. Restore rutorrent_old"
echo "2. Upgrade to latest version"
read -p "Select 1 or 2: " answer
case $answer in [1]* ) return 0 ;;
[2]* ) return 1 ;;
esac
done
fi
}
ask_version() {
if [ $force_yes = 0 ]; then
return $install_master
else
echo "Choose which build to install, (if you are not sure select 1)"
while true
do
echo "1. Use the latest stable release"
echo "2. Use the most recent master build"
read -p "Select 1 or 2: " answer
case $answer in [1]* ) return 1 ;;
[2]* ) return 0 ;;
esac
done
fi
}
check_user() {
while true
do
read -p "Do you wish to continue? " answer
case $answer in [Yy]* ) return 0 ;;
[Nn]* ) return 1 ;;
* ) echo "Enter y or n";;
esac
done
}
#check user is root or sudo
if [ "$(id -u)" != "0" ]; then
echo "Must be run from root or using sudo" && exit 1
fi
# get options
OPTS=$(getopt -n "$0" -o myo --long "rutorrent-master,force-yes,restore-old" -- "$@")
eval set -- "$OPTS"
while true; do
case "$1" in
-m | --rutorrent-master ) install_master=0; shift;;
-y | --force-yes ) force_yes=0; shift;;
-o | --restore-old ) restore_old=0; shift;;
-- ) shift; break ;;
* ) break ;;
esac
done
#check rutorrent folder exists
if ! [ -d '/var/www/rutorrent' ]; then
echo 'Could not find /var/www/rutorrent, exiting script'
exit
fi
#check versions
echo "Installed version: "$oldvers
echo " Latest version: "$newvers
if [ -d $HOME'/rutorrent_old' ]; then
echo
echo "A previous backup is available to restore"
echo
fi
if [ $restore_old = 0 ] && ! [ -d $HOME'/rutorrent_old' ]; then
echo "No backup available to do a restore"
exit
fi
#check to see if rutorrent_old exists, offer restore or upgrade options
if [ -d $HOME'/rutorrent_old' ];then
echo 'Detected '$HOME'/rutorrent_old'
if ( ask_restore ); then
echo "Restoring Old version of rutorrent"
echo "WARNING: The current rutorrent will be overwitten by older backup"
ruflag=1
if [ $force_yes = 0 ] || ( check_user ); then
echo "Restoring"
rm -r /var/www/rutorrent
mv -f $HOME/rutorrent_old /var/www/rutorrent
echo "Setting permissions, Starting services"
chown -R www-data:www-data /var/www
echo "Done"
else
exit
fi
else
echo "Rutorrent will be upgraded"
echo "WARNING: rutorrent_old will be deleted"
echo "If you wish to retain this older version you should exit this script, and rename or move it"
if [ $force_yes = 0 ] || ( check_user ); then
ruflag=0
else
exit
fi
fi
fi
if [ $ruflag = 0 ]; then
if ( ask_version ); then
rurelease=master
fi
if [ -d $HOME'/rutorrent_old' ]; then
rm -r $HOME/rutorrent_old
echo "rutorrent_old has been deleted"
fi
echo
echo 'Installing version '$newvers' of rutorrent'
echo 'Your existing rutorrent folder will be moved to '$HOME'/rutorrent_old'
echo
echo 'If you are not happy with the upgrade you can restore the old version, by rerunning this script'
echo
mv -f /var/www/rutorrent $HOME/rutorrent_old
echo "Installing Rutorrent ($rurelease)"
wget -q https://github.com/Novik/ruTorrent/archive/$rurelease.tar.gz
tar -xzf $rurelease.tar.gz
mv -f $(tar -tzf $rurelease.tar.gz | head -1) /var/www/rutorrent
rm $rurelease.tar.gz
git clone -q https://github.com/autodl-community/autodl-rutorrent.git /var/www/rutorrent/plugins/autodl-irssi
rm -r /var/www/rutorrent/conf >> /dev/null 2>&1
cp -r $HOME/rutorrent_old/conf /var/www/rutorrent/conf >> /dev/null 2>&1
rm -r /var/www/rutorrent/share >> /dev/null 2>&1
cp -r $HOME/rutorrent_old/share /var/www/rutorrent/share >> /dev/null 2>&1
echo "Setting permissions, Starting services"
chown -R www-data:www-data /var/www
echo
echo "Installation of RuTorrent complete"
fi