This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
285 lines (245 loc) · 9.07 KB
/
install.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
#!/bin/sh
# Script by Tom Herbers (07.04.2018)
# Can be found on GitHub under https://github.com/herbetom/install-debian-server
beep(){
echo -en "\007"
}
installDocker(){
echo "Docker will now be installed"
apt install apt-transport-https ca-certificates curl gnupg2 software-properties-common -y
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
apt update
apt install docker-ce -y
docker run hello-world
}
beep
read -r -p "Do you really want to start installing Software on the Server? [y/N] " response
case $response in
[yY][eE][sS]|[yY])
echo "OK, first the Existing Software will be updated!"
;;
*)
echo "Script aborted!"
exit 1
;;
esac
# upgrade server
apt update
apt upgrade -y
#install some tools
apt install htop zip unzip locate git -y
updatedb
DockerInstalled=false
#install docker if neccesary
docker -v &> /dev/null
if [ ! $? -eq 0 ]; then
read -r -p "Do you want to install Docker? [y/N] " response
case $response in
[yY][eE][sS]|[yY])
installDocker
DockerInstalled=true
;;
*)
echo ""
;;
esac
else
DockerInstalled=true
echo "Docker is already installed on the system. No need to install"
fi
WebserverInstalled=false
apache2 -v &> /dev/null
if [ ! $? -eq 0 ]; then WebserverInstalled=true; fi
beep
read -r -p "Do you want to install Apache2, PHP7.0, MySQL as well as the certbot? [y/N] " response
case $response in
[yY][eE][sS]|[yY])
echo "Apache2, PHP7.0, MySQL and certbot will now be installed"
#install Apache2 and PHP
apt install apache2 php7.0 php7.0-mysql php7.0-json php7.0-imap php7.0-curl -y
systemctl restart apache2
a2enmod rewrite
a2enmod headers
a2enmod http2
a2enmod ssl
a2enmod proxy
a2enmod proxy_http
a2enmod proxy_http2
apt-get -y install mysql-server
apt install expect -y
DBROOTPASS=$(</dev/urandom tr -dc A-Za-z0-9 | head -c 28)
SECURE_MYSQL=$(expect -c "
set timeout 2
spawn mysql_secure_installation
expect \"Enter current password for root:\"
send \"\r\"
expect \"Set root password?\"
send \"y\r\"
expect \"New password:\"
send \"$DBROOTPASS\r\"
expect \"Re-enter new password:\"
send \"$DBROOTPASS\r\"
expect \"Remove anonymous users?\"
send \"Y\r\"
expect \"Disallow root login remotely?\"
send \"y\r\"
expect \"Remove test database and access to it?\"
send \"y\r\"
expect \"Reload privilege tables now?\"
send \"y\r\"
expect eof
")
echo "$SECURE_MYSQL"
apt -y purge expect
#allow root access with password
mysql -u root -e "update mysql.user set plugin = 'mysql_native_password' where User='root'; FLUSH PRIVILEGES;"
#install certbot
apt install python-certbot-apache -y
#restart Apache2
systemctl restart apache2
WebserverInstalled=true
;;
*)
echo ""
;;
esac
MailcowInstalled=false
if [ ! -d "/opt/mailcow-dockerized/" ]; then
beep
read -r -p "Do you want to install Mailcow (a Mail Server with Web Frontend)? [y/N] " response
case $response in
[yY][eE][sS]|[yY])
echo "Mailcow will now be installed"
# install Docker if not installed
if [ ! $DockerInstalled == "true" ]; then
installDocker
fi
#install docker-compose if not already installed
if [ ! -d "/usr/local/bin/docker-compose" ]; then
echo "Docker Compose is now installed"
curl -L https://github.com/docker/compose/releases/download/$(curl -Ls https://www.servercow.de/docker-compose/latest.php)/docker-compose-$(uname -s)-$(uname -m) > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
fi
#clone mailcow
cd /opt
git clone https://github.com/mailcow/mailcow-dockerized
cd mailcow-dockerized
beep
./generate_config.sh
source /opt/mailcow-dockerized/mailcow.conf
#if WebServer is installed the MailServer Web Frontend will be Used by a Proxy
if [ $WebserverInstalled == true ]; then
sed -i "s/\(HTTP_PORT *= *\).*/\18080/" /opt/mailcow-dockerized/mailcow.conf
sed -i "s/\(HTTP_BIND *= *\).*/\1127.0.0.1/" /opt/mailcow-dockerized/mailcow.conf
sed -i "s/\(HTTPS_PORT *= *\).*/\18443/" /opt/mailcow-dockerized/mailcow.conf
sed -i "s/\(HTTPS_BIND *= *\).*/\1127.0.0.1/" /opt/mailcow-dockerized/mailcow.conf
sed -i "s/\(SKIP_LETS_ENCRYPT *= *\).*/\1y/" /opt/mailcow-dockerized/mailcow.conf
sitesAvailabledomain='/etc/apache2/sites-available/'$MAILCOW_HOSTNAME.conf
echo "Creating a vhost for $MAILCOW_HOSTNAME"
### create virtual host rules file
maindomain=$(expr match "$MAILCOW_HOSTNAME" '.*\.\(.*\..*\)')
echo "<VirtualHost *:80>" > $sitesAvailabledomain
echo "ServerName $MAILCOW_HOSTNAME" >> $sitesAvailabledomain
echo "ServerAlias autodiscover.$maindomain" >> $sitesAvailabledomain
echo "ServerAlias autoconfig.$maindomain" >> $sitesAvailabledomain
echo "DocumentRoot \"/var/www/html\"" >> $sitesAvailabledomain
echo "<Directory \"/var/www/html\">" >> $sitesAvailabledomain
echo " allow from all" >> $sitesAvailabledomain
echo " Options None" >> $sitesAvailabledomain
echo " Require all granted" >> $sitesAvailabledomain
echo "</Directory>" >> $sitesAvailabledomain
echo "Protocols h2 http/1.1" >> $sitesAvailabledomain
echo "ProxyPass / http://127.0.0.1:8080/" >> $sitesAvailabledomain
echo "ProxyPassReverse / http://127.0.0.1:8080/" >> $sitesAvailabledomain
echo "ProxyPreserveHost On" >> $sitesAvailabledomain
echo "ProxyAddHeaders On" >> $sitesAvailabledomain
echo "<If \"%{HTTPS} == 'on'\" >" >> $sitesAvailabledomain
echo " RequestHeader set X-Forwarded-Proto \"https\"" >> $sitesAvailabledomain
echo "</If>" >> $sitesAvailabledomain
echo "</VirtualHost>" >> $sitesAvailabledomain
echo "New Virtual Host Created"
a2ensite $MAILCOW_HOSTNAME
service apache2 reload
#obtain ssl certificate
beep
certbot --authenticator standalone --installer apache --agree-tos --redirect --pre-hook "apachectl -k stop" --post-hook "apachectl -k start" -d $MAILCOW_HOSTNAME -d autodiscover.$maindomain -d autoconfig.$maindomain
fi
beep
read -r -p "Do you want to make changes to the mailcow.conf? [y/N] " response
case $response in
[yY][eE][sS]|[yY])
nano /opt/mailcow-dockerized/mailcow.conf
;;
*)
;;
esac
docker-compose pull
#the following command must be run to start Mailcow 'docker-compose up -d'
MailcowInstalled=true
;;
*)
echo ""
;;
esac
fi
if [ ! -d "/etc/webmin/" ]; then
beep
read -r -p "Do you want to install webmin? [y/N] " response
case $response in
[yY][eE][sS]|[yY])
echo "Webmin will now be installed"
#install webmin
echo 'deb https://download.webmin.com/download/repository sarge contrib' >> /etc/apt/sources.list
curl -fsSL http://www.webmin.com/jcameron-key.asc | apt-key add -
apt update
apt install webmin -y
#only allow localhost for Webmin Access
echo 'allow=127.0.0.1' >> /etc/webmin/miniserv.conf
echo 'trust_real_ip=0' >> /etc/webmin/miniserv.conf
#disable SSL in Webmin
sed -i "s/\(ssl *= *\).*/\10/" /etc/webmin/miniserv.conf
/etc/webmin/restart
;;
*)
echo ""
;;
esac
fi
if [ $MailcowInstalled == true ]; then
echo ""
beep
read -r -p "Do you want to start mailcow now? The default credentials are admin/moohoo. [y/N] " response
case $response in
[yY][eE][sS]|[yY])
cd /opt/mailcow-dockerized
docker-compose up -d
echo "Mailcow is now started!"
;;
*)
echo ""
echo "***************************************************"
echo "* To start Mailcow 'docker-compose up -d' must be *"
echo "* run within the folder /opt/mailcow-dockerized/ *"
echo "* This will allow you to acces it. *"
echo "***************************************************"
;;
esac
fi
if [ $WebserverInstalled == true ]; then
echo ""
echo "***************************************************"
echo "* The MySQL root user has the following password: *"
echo "* $DBROOTPASS *"
echo "* You should note it! *"
echo "***************************************************"
fi
echo ""
echo "Scipt finished! Thanks for using! I hope everything works!"
if [ $MailcowInstalled == true ]; then
echo "The default credentials for mailcow are admin/moohoo."
fi