-
Notifications
You must be signed in to change notification settings - Fork 19
/
autoconf
executable file
·168 lines (125 loc) · 4.81 KB
/
autoconf
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
#!/bin/sh
# this is file sets all peoplesopen network settings
# it takes a desired MESH IP as its only input,
# this is can _carefully_ be chosen manually
# or retrieved automatically by /opt/mesh/retrieve_ip
EXIT_NODE_MESH_IPv4_ADDR='100.64.0.42'
ADHOC_SUBNET_IPv4_MASK='255.255.255.255'
ADHOC_SUBNET_IPv4_BITMASK='32'
OPEN_SUBNET_IPv4_MASK='255.255.255.192'
OPEN_SUBNET_IPv4_BITMASK='26'
MESH_SUBNET_IPv4='100.64.0.0'
MESH_SUBNET_IPv4_BITMASK='10'
CHANNEL_2_4='6'
CHANNEL_5='157'
TX_POWER='23'
STREAMS_2G='2'
STREAMS_5G='2'
PRIVATE_WIFI_KEY='meshtheworld'
PRIVATE_WIFI_SSID='pplsopen-admin'
RPCD_USER_NAME='admin'
UUID=$(cat /proc/sys/kernel/random/uuid)
DOWNSTREAM_BW=4096
UPSTREAM_BW=4096
MESHIP=$1
# create some other MESH IP dependent info
LAST_3_OF_IP=${MESHIP#*.} # removes everything before first dot
previp(){
IP=$1
IP_HEX=$(printf '%.2X%.2X%.2X%.2X\n' `echo $IP | sed -e 's/\./ /g'`)
PREV_IP_HEX=$(printf %.8X `echo $(( 0x$IP_HEX - 1 ))`)
PREV_IP=$(printf '%d.%d.%d.%d\n' `echo $PREV_IP_HEX | sed -r 's/(..)/0x\1 /g'`)
echo $PREV_IP
}
nextip(){
IP=$1
IP_HEX=$(printf '%.2X%.2X%.2X%.2X\n' `echo $IP | sed -e 's/\./ /g'`)
NEXT_IP_HEX=$(printf %.8X `echo $(( 0x$IP_HEX + 1 ))`)
NEXT_IP=$(printf '%d.%d.%d.%d\n' `echo $NEXT_IP_HEX | sed -r 's/(..)/0x\1 /g'`)
echo $NEXT_IP
}
MESHBLOCK=$(previp $MESHIP)
EXTENDER_NODE_IP_1=$(nextip $MESHIP)
EXTENDER_NODE_IP_2=$(nextip $EXTENDER_NODE_IP_1)
# copy template configs
cp -r -f /opt/mesh/templates/etc/* /etc/.
cp -r -f /opt/mesh/templates/opt/* /opt/.
# config babeld
uci set babeld.@filter[0].ip=$MESHIP'/32'
uci commit babeld
# config dhcp
uci delete dhcp.openpool.dhcp_option
uci add_list dhcp.openpool.dhcp_option='1,255.255.255.192'
uci add_list dhcp.openpool.dhcp_option='3,'$MESHIP
uci add_list dhcp.openpool.dhcp_option='6,'$MESHIP
uci commit dhcp
# config network settings
uci set network.ext1mesh.ipaddr=$MESHIP
uci set network.ext1mesh.dns=$EXIT_NODE_MESH_IPv4
uci set network.ext1mesh.netmask=$ADHOC_SUBNET_IPv4_BITMASK
uci set network.ext2mesh.ipaddr=$MESHIP
uci set network.ext2mesh.dns=$EXIT_NODE_MESH_IPv4
uci set network.ext2mesh.netmask=$ADHOC_SUBNET_IPv4_BITMASK
uci set network.mesh2.ipaddr=$MESHIP
uci set network.mesh2.dns=$EXIT_NODE_MESH_IPv4
uci set network.mesh2.netmask=$ADHOC_SUBNET_IPv4_MASK
uci set network.mesh5.ipaddr=$MESHIP
uci set network.mesh5.dns=$EXIT_NODE_MESH_IPv4
uci set network.mesh5.netmask=$ADHOC_SUBNET_IPv4_MASK
uci set network.open.ipaddr=$MESHIP
uci set network.open.dns=$EXIT_NODE_MESH_IPv4
uci set network.open.netmask=$OPEN_SUBNET_IPv4_MASK
uci commit network
# config notdhcp
uci delete notdhcpserver.@server[0].addresses
uci add_list notdhcpserver.@server[0].addresses='eth0.1='$EXTENDER_NODE_IP_1'/32'
uci add_list notdhcpserver.@server[0].addresses='eth0.2='$EXTENDER_NODE_IP_2'/32'
uci commit notdhcpserver
# config rpcd
uci set rpcd.@login[0].username=$RPCD_USER_NAME
uci set rpcd.@login[0].password='$p$'$RPCD_USER_NAME
uci commit rpcd
# config tunneldigger
uci set tunneldigger.main.uuid=$UUID
uci set tunneldigger.main.limit_bw_down=$DOWNSTREAM_BW'kbit'
uci set tunneldigger.main.limit_bw_up=$UPSTREAM_BW'kbit'
uci commit tunneldigger
# config wirless
uci set wireless.radio0.channel=$CHANNEL_2_4
uci set wireless.radio0.txpower=$TX_POWER
uci delete wireless.radio0.ht_capab
uci add_list wireless.radio0.ht_capab='TX-STBC'
uci add_list wireless.radio0.ht_capab='TX-STBC-2BY1'
uci add_list wireless.radio0.ht_capab='RX-STBC'$STREAMS_2G
uci set wireless.@wifi-iface[0].ssid='peoplesopen.net '$LAST_3_OF_IP
uci set wireless.@wifi-iface[1].key=$PRIVATE_WIFI_KEY
uci set wireless.@wifi-iface[1].ssid=$PRIVATE_WIFI_SSID
uci set wireless.radio1.channel=$CHANNEL_5
uci set wireless.radio1.txpower=$TX_POWER
uci delete wireless.radio1.ht_capab
uci add_list wireless.radio1.ht_capab='GF'
uci add_list wireless.radio1.ht_capab='TX-STBC'
uci add_list wireless.radio1.ht_capab='RX-STBC'$STREAMS_5G
uci set wireless.@wifi-iface[3].ssid='peoplesopen.net fast '$LAST_3_OF_IP
uci set wireless.@wifi-iface[4].key=$PRIVATE_WIFI_KEY
uci set wireless.@wifi-iface[4].ssid=$PRIVATE_WIFI_SSID
uci commit wireless
# deal with old shell config file
# TODO move this to a uci config
HOME_NODE=/etc/sudomesh/home_node
echo "LANNET="$MESHBLOCK"/26" >>$HOME_NODE
echo "NODEIP="$MESHIP >>$HOME_NODE
# deal with tunnel_hook related to bug #31
sed -i -e "s/<%= mesh_addr_ipv4 %>/$MESHIP/g" /opt/mesh/tunnel_hook
sed -i -e "s/<%= tun_subnet_ipv4_bitmask %>/32/g" /opt/mesh/tunnel_hook
# config complete
cp /opt/mesh/config_succeeded /root/.
sed -i -e "s/<ins.ert.mes.hip>/$MESHIP/g" /root/config_succeeded
# enable some services
/etc/init.d/meshrouting enable
/etc/init.d/babeld enable
# kill cron job
sed -i '/retrieve_ip/d' /etc/crontabs/root
echo "node reconfigured with mesh IP "$MESHIP
echo "if running manually, please reboot to apply changes"
exit 0