-
Notifications
You must be signed in to change notification settings - Fork 2
/
install-eden-apache-mysql.sh
362 lines (329 loc) · 10.7 KB
/
install-eden-apache-mysql.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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#!/bin/bash
# Script to turn a generic Debian Wheezy, Jessie, Stretch, Buster or Bullseye box into an Eden server
# with Apache & MySQL
# Which OS are we running?
read -d . DEBIAN < /etc/debian_version
if [ $DEBIAN == '10' ]; then
DEBIAN_NAME='bullseye'
PYVERSION='3'
# Apache 2.4
extension='.conf'
elif [ $DEBIAN == '10' ]; then
DEBIAN_NAME='buster'
PYVERSION='3'
# Apache 2.4
extension='.conf'
elif [ $DEBIAN == '9' ]; then
DEBIAN_NAME='stretch'
PYVERSION='2'
# Apache 2.4
extension='.conf'
elif [ $DEBIAN == '8' ]; then
DEBIAN_NAME='jessie'
PYVERSION='2'
# Apache 2.4
extension='.conf'
else
DEBIAN_NAME='wheezy'
PYVERSION='2'
# Apache 2.2
extension=''
fi
# Update system
apt-get update
apt-get upgrade -y
# Install Admin Tools
apt-get install -y "at" "curl" "dos2unix" "htop" "lrzsz" "mlocate" "p7zip" "psmisc" "pwgen" "rcconf" "sudo" "telnet" "unzip" "vim"
if [ $DEBIAN == '11' ]; then
echo 'elinks-lite not available in Debian 11'
elif [ $DEBIAN == '10' ]; then
echo 'elinks-lite not available in Debian 10'
elif [ $DEBIAN == '9' ]; then
echo 'elinks-lite not available in Debian 9'
else
# Debian 7 or 8
apt-get install -y elinks-lite
fi
# Install Git
apt-get install -y git-core
# Email
apt-get -y install exim4-config exim4-daemon-light
########
# MySQL
########
if [ $DEBIAN == '11' ]; then
apt-get -y install mariadb-server mariadb-client
apt-get -y install phpmyadmin
elif [ $DEBIAN == '10' ]; then
apt-get -y install mariadb-server mariadb-client
# Not working as have held broken packages:
apt-get -y install phpmyadmin
elif [ $DEBIAN == '9' ]; then
apt-get -y install mysql-server python-mysqldb phpmyadmin mariadb-client
else
# Debian 7 or 8
apt-get -y install mysql-server python-mysqldb phpmyadmin mytop
fi
# Tune for smaller RAM setups
if [ $DEBIAN == '11' ]; then
echo 'MariaDB tuning needs configuring in Debian 11'
elif [ $DEBIAN == '10' ]; then
echo 'MariaDB tuning needs configuring in Debian 10'
elif [ $DEBIAN == '9' ]; then
echo 'MariaDB tuning needs configuring in Debian 9'
else
# Debian 7 or 8
sed -i 's|query_cache_size = 16M|query_cache_size = 1M|' /etc/mysql/my.cnf
sed -i 's|key_buffer = 16M|key_buffer = 1M|' /etc/mysql/my.cnf
sed -i 's|max_allowed_packet = 16M|max_allowed_packet = 1M|' /etc/mysql/my.cnf
/etc/init.d/mysql restart
fi
#########
# Apache
#########
apt-get -y install apache2
if [ $PYVERSION == '2' ]; then
apt-get -y install libapache2-mod-wsgi
else
apt-get -y install libapache2-mod-wsgi-py3
fi
a2enmod rewrite
a2enmod deflate
a2enmod headers
a2enmod expires
# Enable Basic Authentication for WebServices
sed -i 's|</IfModule>|WSGIPassAuthorization On|' /etc/apache2/mods-enabled/wsgi.conf
echo "</IfModule>" >> /etc/apache2/mods-enabled/wsgi.conf
# Prevent Memory leaks from killing servers
sed -i 's|MaxRequestsPerChild 0|MaxRequestsPerChild 300|' /etc/apache2/apache2.conf
# Tune for smaller RAM setups
sed -i 's|MinSpareServers 5|MinSpareServers 3|' /etc/apache2/apache2.conf
sed -i 's|MaxSpareServers 10|MaxSpareServers 6|' /etc/apache2/apache2.conf
apache2ctl restart
# Holding Page for Maintenance windows
cat << EOF > "/var/www/maintenance.html"
<html><body><h1>Site Maintenance</h1>Please try again later...</body></html>
EOF
#########
# Python
#########
# Install Libraries
if [ $DEBIAN == '11' ]; then
apt-get -y install libgeos-c1v5
elif [ $DEBIAN == '10' ]; then
apt-get -y install libgeos-c1v5
elif [ $DEBIAN == '9' ]; then
apt-get -y install libgeos-c1v5
else
# Debian 7 or 8
apt-get -y install libgeos-c1
fi
# Install Python
if [ $PYVERSION == '2' ]; then
apt-get -y install "python-dev" "python-pip" "python-setuptools" "python-mysqldb"
PIP=pip
#apt-get -y install "python-lxml" "python-dateutil"
apt-get -y install "python-serial"
#apt-get -y install "python-imaging"
#apt-get -y install "python-matplotlib"
#apt-get -y install "python-requests"
#apt-get -y install "python-xlwt"
else
apt-get -y install "python3-dev" "python3-pip" "python3-setuptools" "python3-mysqldb"
PIP=pip3
#apt-get -y install "python3-lxml" "python3-dateutil"
apt-get -y install "python3-serial"
#apt-get -y install "python3-pil"
#apt-get -y install "python3-matplotlib"
#apt-get -y install "python3-requests"
#apt-get -y install "python3-xlwt"
update-alternatives --install /usr/bin/python python /usr/bin/python2 1
update-alternatives --install /usr/bin/python python /usr/bin/python3 2
fi
apt-get clean
$PIP install lxml
$PIP install python-dateutil
$PIP install pillow
$PIP install requests
$PIP install xlwt
$PIP install geopy
# Upgrade ReportLab for Percentage support
#apt-get remove -y python-reportlab
#wget --no-check-certificate http://pypi.python.org/packages/source/r/reportlab/reportlab-3.3.0.tar.gz
#tar zxvf reportlab-3.3.0.tar.gz
#cd reportlab-3.3.0
#python setup.py install
#cd ..
$PIP install reportlab
# Upgrade Shapely for Simplify enhancements
#apt-get remove -y python-shapely
apt-get -y install libgeos-dev
#wget --no-check-certificate https://pypi.python.org/packages/e6/23/03ea2c965fe5ded97c0dd97c2cd659f1afb5c21f388ec68012d6d981cb7c/Shapely-1.5.17.tar.gz
#tar zxvf Shapely-1.5.17.tar.gz
#cd Shapely-1.5.17
#python setup.py install
#cd ..
$PIP install shapely
# Upgrade XLRD for XLS import support
#apt-get remove -y python-xlrd
#wget --no-check-certificate http://pypi.python.org/packages/source/x/xlrd/xlrd-0.9.4.tar.gz
#tar zxvf xlrd-0.9.4.tar.gz
#cd xlrd-0.9.4
#python setup.py install
#cd ..
$PIP install xlrd
#########
# Web2Py
#########
apt-get -y install libodbc1
# Install Web2Py
adduser --system --disabled-password web2py
addgroup web2py
cd /home
env GIT_SSL_NO_VERIFY=true git clone --recursive git://github.com/web2py/web2py.git
cd web2py
# 2.21.2
git reset --hard 31905858b
git submodule update --init --recursive
ln -s /home/web2py ~
cp -f /home/web2py/handlers/wsgihandler.py /home/web2py
cat << EOF > "/home/web2py/routes.py"
#!/usr/bin/python
default_application = 'eden'
default_controller = 'default'
default_function = 'index'
routes_onerror = [
('eden/400', '!'),
('eden/401', '!'),
('eden/509', '!'),
('eden/*', '/eden/errors/index'),
('*/*', '/eden/errors/index'),
]
EOF
# Configure Matplotlib
#mkdir /home/web2py/.matplotlib
#chown web2py /home/web2py/.matplotlib
#echo "os.environ['MPLCONFIGDIR'] = '/home/web2py/.matplotlib'" >> /home/web2py/wsgihandler.py
#sed -i 's|TkAgg|Agg|' /etc/matplotlibrc
##############
# Sahana Eden
##############
# Install Sahana Eden
cd ~web2py/applications
# @ToDo: Stable branch
git clone git://github.com/sahana/eden-stable.git eden
# Fix permissions
chown web2py ~web2py
chown web2py ~web2py/applications/admin/cache
chown web2py ~web2py/applications/admin/cron
chown web2py ~web2py/applications/admin/databases
chown web2py ~web2py/applications/admin/errors
chown web2py ~web2py/applications/admin/sessions
chown web2py ~web2py/applications/eden
chown web2py ~web2py/applications/eden/cache
chown web2py ~web2py/applications/eden/cron
mkdir -p ~web2py/applications/eden/databases
chown web2py ~web2py/applications/eden/databases
chown web2py ~web2py/applications/eden/errors
chown web2py ~web2py/applications/eden/models
mkdir -p ~web2py/applications/eden/sessions
chown web2py ~web2py/applications/eden/sessions
chown web2py ~web2py/applications/eden/static/fonts
chown web2py ~web2py/applications/eden/static/img/markers
mkdir -p ~web2py/applications/eden/static/cache/chart
chown web2py -R ~web2py/applications/eden/static/cache
chown web2py ~web2py/applications/eden/uploads
mkdir -p ~web2py/applications/eden/uploads/gis_cache
mkdir -p ~web2py/applications/eden/uploads/images
mkdir -p ~web2py/applications/eden/uploads/tracks
chown web2py ~web2py/applications/eden/uploads/gis_cache
chown web2py ~web2py/applications/eden/uploads/images
chown web2py ~web2py/applications/eden/uploads/tracks
ln -s /home/web2py/applications/eden ~
#####################
# Management scripts
#####################
cat << EOF > "/usr/local/bin/backup"
#!/bin/sh
NOW=\$(date +"%Y-%m-%d")
mysqldump sahana > /root/backup-\$NOW.sql
gzip -9 /root/backup-\$NOW.sql
OLD=\$(date --date='7 day ago' +"%Y-%m-%d")
rm -f /root/backup-\$OLD.sql.gz
EOF
chmod +x /usr/local/bin/backup
cat << EOF > "/usr/local/bin/compile"
#!/bin/sh
cd ~web2py
python web2py.py -S eden -M -R applications/eden/static/scripts/tools/compile.py
apache2ctl restart
EOF
chmod +x /usr/local/bin/compile
cat << EOF > "/usr/local/bin/maintenance"
#!/bin/sh
# Script to activate/deactivate the maintenance site
# Can provide the option 'off' to disable the maintenance site
if [ "\$1" != "off" ]; then
# Stop the Scheduler
killall python
# Deactivate the Production Site
a2dissite production$extension
# Activate the Maintenance Site
a2ensite maintenance$extension
else
# Deactivate the Maintenance Site
a2dissite maintenance$extension
# Activate the Production Site
a2ensite production$extension
# Start the Scheduler
cd ~web2py && sudo -H -u web2py nohup python web2py.py -K eden -Q >/dev/null 2>&1 &
fi
apache2ctl restart
EOF
chmod +x /usr/local/bin/maintenance
cat << EOF > "/usr/local/bin/pull"
#!/bin/sh
cd ~web2py/applications/eden
sed -i 's/settings.base.migrate = False/settings.base.migrate = True/g' models/000_config.py
git pull
git submodule update --recursive
/usr/local/bin/maintenance
rm -rf compiled
cd ~web2py
sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
cd ~web2py/applications/eden
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/g' models/000_config.py
/usr/local/bin/compile
/usr/local/bin/maintenance off
EOF
chmod +x /usr/local/bin/pull
# Change the value of prepopulate, if-necessary
cat << EOF > "/usr/local/bin/clean"
#!/bin/sh
/usr/local/bin/maintenance
cd ~web2py/applications/eden
rm -rf databases/*
rm -f errors/*
rm -rf sessions/*
rm -rf uploads/*
sed -i 's/settings.base.migrate = False/settings.base.migrate = True/g' models/000_config.py
sed -i 's/settings.base.prepopulate = 0/#settings.base.prepopulate = 0/g' models/000_config.py
rm -rf compiled
mysqladmin -f drop sahana
mysqladmin create sahana
cd ~web2py
sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
cd ~web2py/applications/eden
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/g' models/000_config.py
sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/g' models/000_config.py
/usr/local/bin/maintenance off
/usr/local/bin/compile
EOF
chmod +x /usr/local/bin/clean
cat << EOF > "/usr/local/bin/w2p"
#!/bin/sh
cd ~web2py
python web2py.py -S eden -M
EOF
chmod +x /usr/local/bin/w2p
# END