-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmazi-domain.sh
117 lines (104 loc) · 2.98 KB
/
mazi-domain.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
#!/bin/bash
#The mazi-domain.sh script enables the modification of the MAZI Portal's domain and the change of the splash page.
###### Initialization ######
hosts="/etc/hosts"
portal_conf="/etc/apache2/sites-available/portal.conf"
index_apache="/var/www/html/index.html"
splash_path="/etc/nodogsplash/htdocs/splash.html"
usage() { echo "This script changes the domain of mazi toolkit"
echo ""
echo "Usage: mazi-domain.sh [options]"
echo "[options]"
echo "-d,--domain <new domain> Set a new network domain of the portal"
echo "-s,--splash <application>/<portal> Set a new spalsh page" 1>&2; exit 1; }
while [ $# -gt 0 ]
do
key="$1"
case $key in
-d|--domain)
domain="$2"
shift # past argument=value
;;
-s|--splash)
app="$2"
shift
;;
*)
# unknown option
usage
;;
esac
shift #past argument or value
done
if [ $domain ];then
c_domain=$(grep -o -P '(?<=url=http://).*(?=">)' $index_apache)
sed -i "s/$c_domain/$domain/g" $hosts
sed -i "s/$c_domain/$domain/g" $splash_path
sed -i '/<meta HTTP-EQUIV="REFRESH"/c\ <meta HTTP-EQUIV="REFRESH" content="0; url=http://'$domain'">' $index_apache
sed -i "s/$c_domain/$domain/g" $portal_conf
sudo systemctl daemon-reload
sudo service apache2 restart
sudo service dnsmasq restart
/etc/init.d/nodogsplash stop
sleep 1
/etc/init.d/nodogsplash start
fi
if [ $app ];then
domain=$(grep -o -P '(?<=url=http://).*(?=">)' $index_apache)
case $app in
guestbook | etherpad)
[ "$app" = "guestbook" ] && port="8081" || port="9001"
cat << EOF > $portal_conf
<VirtualHost *:80>
Redirect /admin http://local.mazizone.eu/admin
ServerName $domain
ProxyPreserveHost On
ProxyRequests Off
ProxyPass /admin !
ProxyPass / http://localhost:$port/
ProxyPassReverse / http://localhost:$port/
</VirtualHost>
<VirtualHost *:80>
ServerName local.mazizone.eu
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://localhost:4567/
ProxyPassReverse / http://localhost:4567/
</VirtualHost>
EOF
;;
framadate| nextcloud | wordpress)
cat << EOF > $portal_conf
<VirtualHost *:80>
Redirect /admin http://local.mazizone.eu/admin
DocumentRoot /var/www/html/$app
ServerName $domain
</VirtualHost>
<VirtualHost *:80>
ServerName local.mazizone.eu
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://localhost:4567/
ProxyPassReverse / http://localhost:4567/
</VirtualHost>
EOF
;;
portal)
cat << EOF > $portal_conf
<VirtualHost *:80>
ServerName $domain
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://localhost:4567/
ProxyPassReverse / http://localhost:4567/
</VirtualHost>
EOF
;;
*)
echo "This application is not available "
;;
esac
sudo systemctl daemon-reload
sudo service apache2 restart
fi
exit 0