-
Notifications
You must be signed in to change notification settings - Fork 2
/
configure-eden-apache-mysql.sh
236 lines (195 loc) · 7.7 KB
/
configure-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
#!/bin/bash
# Script to configure an Eden server
# - assumes that install-eden-apache-mysql.sh has been run
# Which OS are we running?
read -d . DEBIAN < /etc/debian_version
if [ $DEBIAN == '1`' ]; then
DEBIAN_NAME='bullseye'
# Apache 2.4
extension='.conf'
GRANT='Require all granted'
elif [ $DEBIAN == '10' ]; then
DEBIAN_NAME='buster'
# Apache 2.4
extension='.conf'
GRANT='Require all granted'
elif [ $DEBIAN == '9' ]; then
DEBIAN_NAME='stretch'
# Apache 2.4
extension='.conf'
GRANT='Require all granted'
elif [ $DEBIAN == '8' ]; then
DEBIAN_NAME='jessie'
# Apache 2.4
extension='.conf'
GRANT='Require all granted'
else
DEBIAN_NAME='wheezy'
# Apache 2.2
extension=''
GRANT=' Order deny,allow
Allow from all'
fi
echo -e "What domain name should we use? : \c "
read DOMAIN
echo -e "What host name should we use? : \c "
read hostname
sitename=$hostname".$DOMAIN"
echo -e "What template should we use? [default] : \c "
read template
if [[ ! "$template" ]]; then
template="default"
fi
echo -e "What is the current root MySQL password: \c "
read rootpw
# @ToDo: Generate a random password
echo Note that web2py will not work with passwords with an @ in them
echo -e "What should be the MySQL password for user 'sahana'? \c "
read password
echo "Now reconfiguring system"
cd /etc
filename="hosts"
sed -i "s|localdomain localhost|localdomain localhost $hostname|" $filename
cd /etc
filename="hostname"
echo $hostname > $filename
cd /etc
filename="mailname"
echo $sitename > $filename
# -----------------------------------------------------------------------------
# Email
# -----------------------------------------------------------------------------
echo configure for Internet mail delivery
dpkg-reconfigure exim4-config
# -----------------------------------------------------------------------------
# Update system
# in case run at a much later time than the install script
# -----------------------------------------------------------------------------
apt-get update
apt-get upgrade -y
cd ~web2py/applications/eden
git pull
# -----------------------------------------------------------------------------
# Apache Web server
# -----------------------------------------------------------------------------
echo "Setting up Web server"
rm -f /etc/apache2/sites-enabled/000-default$extension
cat << EOF > "/etc/apache2/sites-available/production$extension"
<VirtualHost *:80>
ServerName $hostname.$DOMAIN
ServerAdmin webmaster@$DOMAIN
DocumentRoot /home/web2py/applications
WSGIScriptAlias / /home/web2py/wsgihandler.py
## Edit the process and the maximum-requests to reflect your RAM
WSGIDaemonProcess web2py user=web2py group=web2py home=/home/web2py processes=4 maximum-requests=100
RewriteEngine On
# Stop GoogleBot from slowing us down
RewriteRule .*robots\.txt$ /eden/static/robots.txt [L]
# extract desired cookie value from multiple-cookie HTTP header
#RewriteCond %{HTTP_COOKIE} registered=([^;]+)
# check that cookie value is correct
#RewriteCond %1 ^yes$
#RewriteRule ^/$ /eden/ [R,L]
#RewriteRule ^/$ /eden/static/index.html [R,L]
RewriteCond %{REQUEST_URI} !/phpmyadmin(.*)
RewriteCond %{REQUEST_URI} !/eden/(.*)
RewriteRule /(.*) /eden/$1 [R]
### static files do not need WSGI
<LocationMatch "^(/[\w_]*/static/.*)">
Order Allow,Deny
Allow from all
SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
ExpiresActive On
ExpiresByType text/html "access plus 1 day"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType text/css "access plus 2 weeks"
ExpiresByType image/ico "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
</LocationMatch>
### everything else goes over WSGI
<Location "/">
$GRANT
WSGIProcessGroup web2py
</Location>
ErrorLog /var/log/apache2/$hostname_error.log
LogLevel warn
CustomLog /var/log/apache2/$hostname_access.log combined
</VirtualHost>
EOF
a2ensite production
apache2ctl restart
cat << EOF > "/etc/apache2/sites-available/maintenance$extension"
<VirtualHost *:80>
ServerName $hostname.$DOMAIN
ServerAdmin webmaster@$DOMAIN
DocumentRoot /var/www
RewriteEngine On
RewriteCond %{REQUEST_URI} !/phpmyadmin(.*)
RewriteRule ^/(.*) /maintenance.html
<Location "/">
$GRANT
</Location>
ErrorLog /var/log/apache2/maintenance_error.log
LogLevel warn
CustomLog /var/log/apache2/maintenance_access.log combined
</VirtualHost>
EOF
# -----------------------------------------------------------------------------
# MySQL Database
# -----------------------------------------------------------------------------
echo "Setting up Database"
# Allow root user to access database without entering password
cat << EOF > "/root/.my.cnf"
[client]
user=root
EOF
echo "password='$rootpw'" >> "/root/.my.cnf"
# Create database
mysqladmin create sahana
# Create user for Sahana application
echo "CREATE USER 'sahana'@'localhost' IDENTIFIED BY '$password';" > "/tmp/mypass"
echo "GRANT ALL PRIVILEGES ON sahana.* TO 'sahana'@'localhost' WITH GRANT OPTION;" >> "/tmp/mypass"
mysql < /tmp/mypass
rm -f /tmp/mypass
# Schedule backups for 02:01 daily
echo "1 2 * * * * root /usr/local/bin/backup" >> "/etc/crontab"
# -----------------------------------------------------------------------------
# Sahana Eden
# -----------------------------------------------------------------------------
echo "Setting up Sahana"
# Copy Templates
cp ~web2py/applications/eden/modules/templates/000_config.py ~web2py/applications/eden/models
sed -i "s|settings.base.template = \"default\"|settings.base.template = \"$template\"|" ~web2py/applications/eden/models/000_config.py
sed -i 's|EDITING_CONFIG_FILE = False|EDITING_CONFIG_FILE = True|' ~web2py/applications/eden/models/000_config.py
sed -i "s|akeytochange|$sitename$password|" ~web2py/applications/eden/models/000_config.py
sed -i "s|127.0.0.1:8000|$sitename|" ~web2py/applications/eden/models/000_config.py
sed -i 's|base.cdn = False|base.cdn = True|' ~web2py/applications/eden/models/000_config.py
# Configure Database
sed -i 's|#settings.database.db_type = "mysql"|settings.database.db_type = "mysql"|' ~web2py/applications/eden/models/000_config.py
sed -i "s|#settings.database.password = \"password\"|settings.database.password = \"$password\"|" ~web2py/applications/eden/models/000_config.py
# Create the Tables & Populate with base data
sed -i 's|settings.base.prepopulate = 0|settings.base.prepopulate = 1|' ~web2py/applications/eden/models/000_config.py
sed -i 's|settings.base.migrate = False|settings.base.migrate = True|' ~web2py/applications/eden/models/000_config.py
cd ~web2py
sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
# Configure for Production
sed -i 's|settings.base.prepopulate = 1|settings.base.prepopulate = 0|' ~web2py/applications/eden/models/000_config.py
sed -i 's|settings.base.migrate = True|settings.base.migrate = False|' ~web2py/applications/eden/models/000_config.py
cd ~web2py
sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/compile.py
# Add Scheduler
sed -i 's|exit 0|cd ~web2py \&\& python web2py.py -K eden -Q >/dev/null 2>\&1 \&|' /etc/rc.local
echo "exit 0" >> /etc/rc.local
#read -p "Press any key to Reboot..."
echo "Now rebooting.."
reboot
# END