forked from dchang0/torrentwatch-xa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_twxa.sh
executable file
·127 lines (115 loc) · 3.93 KB
/
install_twxa.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
#!/bin/bash
# simple install script for torrentwatch-xa
# Most of this script requires sudo power.
# WARNING: This wipes out the old install, copying old config file to your home directory.
# It uses rm -fr, which can be quite dangerous. USE THIS SCRIPT AT YOUR OWN RISK!
# DOES NOT INSTALL PREREQUISITES
# REMEMBER TO RESTART APACHE2 AFTER INSTALLING PRE-REQUISITES
while [[ $# -gt 0 ]]; do
key="$1"
case "$key" in
-k|--keep-config)
KEEPCONFIG=1
;;
-h|--help)
HELP=1
;;
*)
# extra, unknown options
echo "Unknown option '$key'"
;;
esac
# Shift after checking all the cases to get the next option
shift
done
if [[ $HELP == 1 ]]
then
echo "install_twxa.sh {--keep-config}"
exit
fi
# make sure new torrentwatch-xa package is accessible
if [ ! -e var/lib/torrentwatch-xa/lib/twxa_tools.php ]
then
echo "Cannot find new torrentwatch-xa lib tree to install; exiting."
exit
fi
if [ ! -e var/www/html/torrentwatch-xa/torrentwatch-xa.php ]
then
echo "Cannot find new torrentwatch-xa www tree to install; exiting."
exit
fi
if [ ! -e etc/cron.d/torrentwatch-xa-cron ]
then
echo "Cannot find new torrentwatch-xa cron job to install; exiting."
exit
fi
# back up the old config file
# requires sudo power
if [ -f /var/lib/torrentwatch-xa/config_cache/torrentwatch-xa.config ]
then
sudo cp /var/lib/torrentwatch-xa/config_cache/torrentwatch-xa.config ~/torrentwatch-xa.config.bak
if [ ! -e ~/torrentwatch-xa.config.bak ]
then
echo "Backup of config file to ~/torrentwatch-xa.config.bak failed; exiting."
exit
else
echo "Backed up config file to ~/torrentwatch-xa.config.bak"
fi
fi
# DOES NOT BACK UP THE DOWNLOAD CACHE!
# destroy the old installation
echo "Destroying the old installation..."
if [ -f /etc/cron.d/torrentwatch-xa-cron ]
then
sudo rm /etc/cron.d/torrentwatch-xa-cron
fi
if [ -e /var/lib/torrentwatch-xa ]
then
sudo rm -fr /var/lib/torrentwatch-xa
fi
if [ -e /var/www/html/torrentwatch-xa ]
then
sudo rm -fr /var/www/html/torrentwatch-xa
fi
# copy in the new installation
echo "Copying in the new installation..."
sudo cp -R var/lib/torrentwatch-xa /var/lib
# try to chown the cache directories using Debian/Ubuntu default Apache user and group www-data
sudo chown -R www-data:www-data /var/lib/torrentwatch-xa/*_cache
if [ $? -ne 0 ]
then
# try to chown the cache directories using Fedora default Apache user and group apache
sudo chown -R apache:apache /var/lib/torrentwatch-xa/*_cache
fi
sudo cp -R var/www/html/torrentwatch-xa /var/www/html
sudo cp etc/cron.d/torrentwatch-xa-cron /etc/cron.d
sudo chown root:root /etc/cron.d/torrentwatch-xa-cron
# create the log file
echo "Creating log file..."
sudo touch /var/log/twxalog
sudo chown www-data:www-data /var/log/twxalog
if [ $? -ne 0 ]
then
# try to chown the cache directories using Fedora default Apache user and group apache
sudo chown apache:apache /var/log/twxalog
fi
# copy in the old config file
echo "Copying the old config file back into the new installation..."
if [[ $KEEPCONFIG == 1 ]]
then
sudo cp ~/torrentwatch-xa.config.bak /var/lib/torrentwatch-xa/config_cache/torrentwatch-xa.config
sudo chown www-data:www-data /var/lib/torrentwatch-xa/config_cache/torrentwatch-xa.config
if [ $? -ne 0 ]
then
# try to chown the config file using Fedora default Apache user and group apache
sudo chown apache:apache /var/lib/torrentwatch-xa/config_cache/torrentwatch-xa.config
fi
sudo chmod 644 /var/lib/torrentwatch-xa/config_cache/torrentwatch-xa.config
fi
# RedHat/Fedora/CentOS warning
if [ -e /etc/redhat-release ]
then
echo "SELINUX and firewalld changes must be made manually for Fedora Server and other RedHat-derived distributions. Refer to the Manual Install instructions for those steps."
fi
# DEFAULT CONFIG IS AUTOMATICALLY GENERATED ON FIRST RUN OF NEW INSTALL IF CONFIG FILE NOT FOUND
echo "Done."