-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·192 lines (162 loc) · 6.37 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
#!/bin/bash
#######################################################
# -------------------- mx_router -------------------- #
# Copyright (C) Torsten Amshove <torsten@amshove.net> #
# See: http://www.amshove.net #
#######################################################
echo "###################################"
echo "# Bereite den Server als Router vor"
echo "###################################"
grep dhcp /etc/network/interfaces > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "# In /etc/network/interfaces steht noch ein Interface auf dhcp ..."
echo "# Das interne Interface muss fest auf die LAN-IP eingestellt sein"
echo "# alle anderen Interfaces duerfen keine Konfiguration haben"
echo "# Breche ab .. bitte erst /etc/network/interfaces bearbeiten"
exit 1
fi
echo "# Deinstalliere resolvconf & appamor (mit funktioniert das ip_forwarding nicht)"
apt-get -y remove apparmor apparmor-utils resolvconf
echo "# Installiere fehlende Pakete"
PACKAGES="dnsmasq apache2 libapache2-mod-php php-mysql php php-cli mysql-server ntp ethtool conntrack"
apt-get -y install $PACKAGES
dpkg -s $PACKAGES > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "###########################################"
echo "# ERROR: Die folgenden Pakete konnten nicht installiert werden"
echo "# $PACKAGES"
echo "# Bitte das System so konfigurieren, dass diese mit apt-get installiert werden koennen"
echo "###########################################"
exit 1
fi
echo "# Erstelle /etc/sysctl.d/99-mx_router.conf"
cp source/99-mx_router.conf /etc/sysctl.d/99-mx_router.conf
chown root:root /etc/sysctl.d/99-mx_router.conf
chmod 644 /etc/sysctl.d/99-mx_router.conf
# service procps start bzw sysctl -p nicht noetig, weil spaeter reboot
echo "# Lege SUDO fuer www-data an (/etc/sudoers.d/mx_router)"
echo "www-data ALL= NOPASSWD: /sbin/iptables" > /etc/sudoers.d/mx_router
chown root:root /etc/sudoers.d/mx_router
chmod 0440 /etc/sudoers.d/mx_router
echo "# Ueberschreibe /etc/ntp.conf"
mv /etc/ntp.conf /etc/ntp.conf.orig
cp source/ntp.conf /etc/ntp.conf
chown root:root /etc/ntp.conf
chmod 644 /etc/ntp.conf
echo "# Richte /etc/resolv.conf ein"
DNS1=""
DNS2="8.8.8.8"
DOMAIN=""
echo "####################################"
read -p "Bitte den DNS-Server fuer das lokale Netz eingeben: " DNS1
read -p "Domain fuer das lokale Netz: " DOMAIN
mv /etc/resolv.conf /etc/resolv.conf.orig
if [ "$DOMAIN" != "" ]; then
echo "domain $DOMAIN" >> /etc/resolv.conf
fi
if [ "$DNS1" != "" ]; then
echo "nameserver $DNS1" >> /etc/resolv.conf
fi
echo "nameserver $DNS2" >> /etc/resolv.conf
chown root:root /etc/resolv.conf
chmod 644 /etc/resolv.conf
echo "###################################"
echo "# Richte MySQL-Server ein"
echo "###################################"
read -s -p "Bitte Passwort fuer MySQL-User 'root' eingeben: " MY_PW
mysql -u root --password=$MY_PW -e "SHOW DATABASES" > /dev/null 2>&1
RC=$?
while [ $RC -ne 0 ]; do
echo ""
echo "ERROR: Passwort falsch .."
read -s -p "Bitte Passwort fuer MySQL-User 'root' eingeben: " MY_PW
mysql -u root --password=$MY_PW -e "SHOW DATABASES" > /dev/null 2>&1
RC=$?
done
echo ""
echo "# Generiere Passwort fuer mx_router User"
MX_PW=`date | md5sum | base64`
echo "# Lege MySQL-User und DB an"
sed s/\\*\\*\\*/$MX_PW/g source/create_mysql_user.sql | mysql -u root --password=$MY_PW
mysql -u mx_router --password=$MX_PW mx_router < source/create_mysql_db.sql
echo "###################################"
echo "# Richte Webinterface ein"
echo "###################################"
if [ ! -d "/var/www" ]; then
echo "# Lege /var/www an"
mkdir /var/www
chmod 755 /var/www
fi
if [ `ls -1 /var/www/ | wc -l` -ne 0 ]; then
DIR="/var/www_`date +%s`"
echo "# /var/www ist nicht leer - verschiebe es nach $DIR"
mv /var/www $DIR
mkdir /var/www
chmod 755 /var/www
fi
echo "# Kopiere Webinterface nach /var/www"
cp -r webinterface/* /var/www/
chown -R root:root /var/www/
sed -i.bak -e "s/DocumentRoot\ \/var\/www\/html/DocumentRoot\ \/var\/www/" /etc/apache2/sites-enabled/000-default.conf
echo "# Trage MySQL-PW in config.inc.php ein"
sed -i s/--MYSQL_PW--/$MX_PW/ /var/www/config.inc.php
echo "# Generiere PW fuer API und trage es in config.inc.php ein"
API_PW=`date | sha1sum | md5sum | base64`
sed -i s/--API_PW--/$API_PW/ /var/www/config.inc.php
echo "# Lege crontab-Eintrag an"
echo "" >> /etc/crontab
echo "# mx_router: Loeschen der zeitlich begrenzten Regeln" >> /etc/crontab
echo "*/1 * * * * root /usr/bin/php /var/www/scripte/del_rules.php > /dev/null 2>&1" >> /etc/crontab
echo "" >> /etc/crontab
echo "# mx_router: Fuellen der statischen ARP-Tabelle" >> /etc/crontab
echo "*/1 * * * * root /usr/bin/php /var/www/scripte/arp_table.php > /dev/null 2>&1" >> /etc/crontab
echo "###################################"
echo "# Richte Scripte ein"
echo "###################################"
echo "# Kopiere Scripte nach /opt/mx_router"
mkdir /opt/mx_router
cp -r source/opt/* /opt/mx_router
chown root:root -R /opt/mx_router
chmod 744 /opt/mx_router/*.sh
echo "# Richte Status-motd ein"
rm /etc/update-motd.d/*
ln -s /opt/mx_router/show_status.sh /etc/update-motd.d/99-mx_router-status
dpkg -s upstart > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "# Lege Upstart-Config an (/etc/init/mx_router.conf)"
cp source/mx_router.conf /etc/init/mx_router.conf
chown root:root /etc/init/mx_router.conf
chmod 644 /etc/init/mx_router.conf
initctl reload-configuration
else
echo "# Lege systemd-Config an (/etc/init/mx_router.conf)"
cp source/mx_router.service /etc/systemd/system/
chown root:root /etc/systemd/system/mx_router.service
chmod 644 /etc/systemd/system/mx_router.service
systemctl enable mx_router.service
fi
echo ""
echo ""
echo "###################################"
echo "# Installation durchgefuehrt #"
echo "###################################"
echo "# Die Internet-Leitungen muessen in"
echo "# /opt/mx_router/etc/leitungen.d/"
echo "# eingerichtet werden."
echo "#"
echo "# Danach werden die Aenderungen aktiv mit"
echo "# /opt/mx_router/configure.sh"
echo "#"
echo "# Danach kann die Webseite benutzt werden"
echo "# User: admin PW: mx_router"
echo "###################################"
echo "# Alle Infos auch in: /opt/mx_router/README.txt"
echo "###################################"
echo ""
echo ""
echo "###################################"
echo "# Der Server wird jetzt neu gestartet .."
echo "# .. wenn du Enter drueckst"
echo "###################################"
read
reboot