-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmode-bridge-script.sh
executable file
·198 lines (177 loc) · 4.6 KB
/
mode-bridge-script.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
#!/bin/bash
# ----------------------------------------------
# valid_ip
# ----------------------------------------------
function valid_ip()
{
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$?
fi
return $stat
}
# ----------------------------------------------
# valid_netmask
# ----------------------------------------------
function valid_netmask()
{
local netmask=$1
local netmask_binary
local octet
local stat
if [[ $netmask =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
stat=0
for ((i=0; i<4; i++))
do
octet=${netmask%%.*}
netmask=${netmask#*.}
[[ $octet -gt 255 ]] && { stat=1; break; }
netmask_binary=$netmask_binary$( echo "obase=2; $octet" | bc )
[[ $netmask_binary =~ 01 ]] && { stat=1; break; }
done
else
stat=1
fi
return $stat
}
# MODE SELECTION
echo "" ;
echo "CommunityCube initial wizard, please select an option: "
echo " [1] Protect privacy"
echo " [2] CommunityCube Services"
echo -n "Enter your selection: "
read -n 1 MODE
echo
while [ "$MODE" != "1" ] && [ "$MODE" != "2" ]; do
echo -n "Option $MODE not available, please choose 1 or 2: "
read -n 1 MODE
echo
done
echo " Selection $MODE"
# -----------------
# ------ WAN ------
# -----------------
# INTERNET SELECTION
echo "" ;
echo "How will you access to Internet: "
echo " [1] Ethernet (wired)"
echo " [2] WiFi (wireless)"
echo -n "Enter your selection: "
read -n 1 ACCESS
echo
while [ "$ACCESS" != "1" ] && [ "$ACCESS" != "2" ]; do
echo -n "Option $ACCESS not available, please choose 1 or 2: "
read -n 1 ACCESS
echo
done
echo "Selection $ACCESS"
# WAN Interface
if [ "$ACCESS" == "1" ]
then
NET_INTERFACE="eth0"
else
NET_INTERFACE="wlan0"
fi
# WIFI SELECTION
if [ "$ACCESS" == "2" ]
then
echo -n "Enter SSID name and press [ENTER]: "
read SSID_NAME
echo -n "Enter SSID password and press [ENTER]: "
read SSID_PASSWORD
echo "Enter SSID encryption method: "
echo " [1] WEP "
echo " [2] WPA-PSK"
echo " [3] WPA2-PSK"
echo -n "Enter your selection: "
read -n 1 SSID_METHOD
echo
while [ "$SSID_METHOD" != "1" ] && [ "$SSID_METHOD" != "2" ] && [ "$SSID_METHOD" != "3" ]; do
echo -n "Option $ACCESS not available, please choose 1, 2 o 3: "
read -n 1 ACCESS
echo
done
echo "Selection $SSID_METHOD"
fi
# FIXED ADDRESS OR DHCP SELECTION
echo "" ;
echo "IP configuration:"
echo " [1] Fixed address"
echo " [2] DHCP"
echo -n "Enter your selection: "
read -n 1 IP_CONF
echo
while [ "$IP_CONF" != "1" ] && [ "$IP_CONF" != "2" ]; do
echo -n "Option $IP_CONF not available, please choose 1 or 2: "
read -n 1 IP_CONF
echo
done
echo "Selection $IP_CONF"
# FIXED ADDRESS SELECTION
if [ "$IP_CONF" == "1" ]
then
echo -n "Enter IP address and press [ENTER]: "
read IP_ADDRESS
while ! valid_ip $IP_ADDRESS; do
echo -n "IP $IP_ADDRESS is not valid, please enter a valid IP address and press [ENTER]: "
read IP_ADDRESS
done
echo -n "Enter net mask and press [ENTER]: "
read IP_NETMASK
while ! valid_netmask $IP_NETMASK; do
echo -n "Netmask $IP_NETMASK is not valid, please enter a valid net mask address and press [ENTER]: "
read IP_NETMASK
done
echo -n "Enter gateway and press [ENTER]: "
read IP_GATEWAY
while ! valid_ip $IP_GATEWAY; do
echo -n "Gateway $IP_GATEWAY is not valid, please enter a gateway address and press [ENTER]: "
read IP_GATEWAY
done
echo -n "Enter DNS and press [ENTER]: "
read IP_DNS
while ! valid_ip $IP_DNS; do
echo -n "DNS $IP_DNS is not valid, please enter a valid IP address and press [ENTER]: "
read IP_DNS
done
# Fix address net file
cat << EOF > /etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto $NET_INTERFACE
iface $NET_INTERFACE inet static
address $IP_ADDRESS
netmask $IP_NETMASK
gateway $IP_GATEWAY
dns-nameservers $IP_DNS
EOF
else
# DHCP net file
cat << EOF > /etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto $NET_INTERFACE
iface $NET_INTERFACE inet dhcp
EOF
fi
echo "Configuring interfaces ..."
ifdown $NET_INTERFACE
sleep 2
ifup $NET_INTERFACE
echo "Checking Internet access ..."
if ping -c1 www.communitycube.net >/dev/null 2>/dev/null; then
echo "You need internet to proceed. Exiting"
exit
fi
exit;