-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuSpot-configure
executable file
·108 lines (77 loc) · 2.69 KB
/
uSpot-configure
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
#!/bin/bash
########################################################################
. /usr/local/uSpot/uSpot-functions
########################################################################
#ifaces=$(for a in $(netstat -npl |egrep '^udp .*/ntpd' |egrep -v " (127.0.0.1|0.0.0.0|${PORTAL}):123 " |awk '{print $4}' |cut -d: -f1) ; do ifconfig |grep -B1 " inet addr:${a} " |head -1 ; done |awk '{print $1}')
ifaces=$(ip addr ls |grep "inet " |egrep -v " (127.0.0.1|0.0.0.0|${PORTAL})/" |grep " scope global " |sed 's/^.* scope global //g')
echo "Shutting down services ..."
for service in uSpot apache2 ntp isc-dhcp-server ; do
echo " ${service}"
service ${service} stop 2>/dev/null >/dev/null
done
echo "Shutting down WLAN interfaces ..."
for iface in ${ifaces} ; do
echo " ${iface}"
ifdown ${iface} 2>/dev/null >/dev/null
rm /etc/munin/plugins/if_${iface}
done
echo "Configuring files ..."
for f in dhcpd interfaces ; do
echo " ${CONF}/${f}"
cat<<EOF>${CONF}/${f}
# This file is generated by 'uSpot-configure'
# Do not edit it manualy
EOF
done
########################################################################
echo "Configuring networks ..."
i=0
while [ "${WLAN_IF[$i]}" != "" ] ; do
[ "${WLAN_ID[${i}]}" = "" ] && iface="${WLAN_IF[${i}]}" || iface="${WLAN_IF[${i}]}.${WLAN_ID[${i}]}"
echo " ${IF_WLAN} " |grep -q " ${iface} "
if [ $? -eq 0 ] ; then
r=$(sipcalc ${WLAN_ADDR[${i}]} ${WLAN_MASK[${i}]})
range=$(echo "${r}" |grep "^Network range" |awk '{print $4" "$6}')
range=(${range})
first=${range[0]}
last=${range[1]}
IFS=. read -r f1 f2 f3 f4 <<< "${first}"
IFS=. read -r l1 l2 l3 l4 <<< "${last}"
case ${DHCP_GW_ADDR} in
first)
gateway="${f1}.${f2}.${f3}.$(( ${f4} + 1 ))"
;;
last)
gateway="${l1}.${l2}.${l3}.$(( ${l4} - 1 ))"
;;
esac
first_usable="${f1}.${f2}.${f3}.$(( ${f4} + ${DHCP_RANGE_FIRST} ))"
last_usable="${l1}.${l2}.${l3}.$(( ${l4} - ${DHCP_RANGE_LAST} ))"
echo " ${WLAN_IF[$i]} ${WLAN_ID[${i}]} ${WLAN_ADDR[${i}]}/${WLAN_MASK[${i}]} ${gateway} ${first_usable}-${last_usable}"
cat<<EOF>>${CONF}/interfaces
# ${WLAN_DESC[${i}]}
auto ${iface}
iface ${iface} inet static
address ${gateway}
netmask ${WLAN_MASK[${i}]}
EOF
cat<<EOF>>${CONF}/dhcpd
# ${WLAN_DESC[${i}]}
subnet ${first} netmask ${WLAN_MASK[${i}]} {
option routers ${gateway};
option broadcast-address ${last};
range ${first_usable} ${last_usable};
}
EOF
ifup ${iface} 2>/dev/null >/dev/null
ln -fs /usr/share/munin/plugins/if_ /etc/munin/plugins/if_${iface}
fi
(( i++ ))
done
echo
sed -i "s/^INTERFACES=.*/INTERFACES=\"${IF_WLAN}\"/g" /etc/default/isc-dhcp-server
echo "Starting services ..."
for service in isc-dhcp-server ntp apache2 uSpot ; do
echo " ${service}"
service ${service} start 2>/dev/null >/dev/null
done