|
@@ -41,241 +41,315 @@ WIFI_TYPE='wpa2-psk'
|
41
|
41
|
WIFI_SSID=
|
42
|
42
|
WIFI_PASSPHRASE=
|
43
|
43
|
WIFI_HOTSPOT='no'
|
|
44
|
+WIFI_CONFIG=/etc/wpa_supplicant/wpa_supplicant.conf
|
|
45
|
+WIFI_FILE=/root/${PROJECT_NAME}-wifi.cfg
|
44
|
46
|
|
45
|
47
|
function wifi_get_psk {
|
46
|
|
- ssid=$1
|
47
|
|
- passphrase=$2
|
|
48
|
+ ssid=$1
|
|
49
|
+ passphrase=$2
|
48
|
50
|
|
49
|
|
- psk=$(wpa_passphrase "$ssid" "$passphrase" | grep 'psk=' | sed -n 2p | awk -F '=' '{print $2}')
|
50
|
|
- echo $psk
|
|
51
|
+ psk=$(wpa_passphrase "$ssid" "$passphrase" | grep 'psk=' | sed -n 2p | awk -F '=' '{print $2}')
|
|
52
|
+ echo $psk
|
51
|
53
|
}
|
52
|
54
|
|
53
|
55
|
function hotspot_off {
|
54
|
|
- if [ ! -f /etc/hostapd/hostapd.conf ]; then
|
55
|
|
- return
|
56
|
|
- fi
|
57
|
|
- systemctl stop hostapd
|
58
|
|
-
|
59
|
|
- rm /etc/hostapd/hostapd.conf
|
60
|
|
-
|
61
|
|
- if [ -f /etc/network/interfaces_original ]; then
|
62
|
|
- cp /etc/network/interfaces_original /etc/network/interfaces
|
63
|
|
- else
|
64
|
|
- echo '# interfaces(5) file used by ifup(8) and ifdown(8)' > /etc/network/interfaces
|
65
|
|
- echo '# Include files from /etc/network/interfaces.d:' >> /etc/network/interfaces
|
66
|
|
- echo 'source-directory /etc/network/interfaces.d' >> /etc/network/interfaces
|
67
|
|
- fi
|
68
|
|
-
|
69
|
|
- systemctl restart network-manager
|
|
56
|
+ if [ ! -f /etc/hostapd/hostapd.conf ]; then
|
|
57
|
+ return
|
|
58
|
+ fi
|
|
59
|
+ systemctl stop hostapd
|
|
60
|
+
|
|
61
|
+ rm /etc/hostapd/hostapd.conf
|
|
62
|
+
|
|
63
|
+ if [ -f /etc/network/interfaces_original ]; then
|
|
64
|
+ cp /etc/network/interfaces_original /etc/network/interfaces
|
|
65
|
+ else
|
|
66
|
+ echo '# interfaces(5) file used by ifup(8) and ifdown(8)' > /etc/network/interfaces
|
|
67
|
+ echo '# Include files from /etc/network/interfaces.d:' >> /etc/network/interfaces
|
|
68
|
+ echo 'source-directory /etc/network/interfaces.d' >> /etc/network/interfaces
|
|
69
|
+ fi
|
|
70
|
+
|
|
71
|
+ systemctl restart network-manager
|
70
|
72
|
}
|
71
|
73
|
|
72
|
74
|
function hotspot_on {
|
73
|
|
- if [ ! -f /etc/default/hostapd ]; then
|
74
|
|
- echo $'/etc/default/hostapd was not found'
|
75
|
|
- exit 67241
|
76
|
|
- fi
|
77
|
|
- if [ ${#WIFI_PASSPHRASE} -lt 8 ]; then
|
78
|
|
- echo $'Wifi hotspot passphrase is too short'
|
79
|
|
- exit 25719
|
80
|
|
- fi
|
81
|
|
-
|
82
|
|
- sed -i 's|#DAEMON_CONF=.*|DAEMON_CONF="/etc/hostapd/hostapd.conf"|g' /etc/default/hostapd
|
83
|
|
-
|
84
|
|
- echo '### Wireless network name ###' > /etc/hostapd/hostapd.conf
|
85
|
|
- echo "interface=$WIFI_INTERFACE" >> /etc/hostapd/hostapd.conf
|
86
|
|
- echo '' >> /etc/hostapd/hostapd.conf
|
87
|
|
- echo '### Set your bridge name ###' >> /etc/hostapd/hostapd.conf
|
88
|
|
- echo 'bridge=br0' >> /etc/hostapd/hostapd.conf
|
89
|
|
- echo '' >> /etc/hostapd/hostapd.conf
|
90
|
|
- echo 'driver=nl80211' >> /etc/hostapd/hostapd.conf
|
91
|
|
- echo "country_code=UK" >> /etc/hostapd/hostapd.conf
|
92
|
|
- echo "ssid=$WIFI_SSID" >> /etc/hostapd/hostapd.conf
|
93
|
|
- echo 'hw_mode=g' >> /etc/hostapd/hostapd.conf
|
94
|
|
- echo 'channel=6' >> /etc/hostapd/hostapd.conf
|
95
|
|
- echo 'wpa=2' >> /etc/hostapd/hostapd.conf
|
96
|
|
- echo "wpa_passphrase=$WIFI_PASSPHRASE" >> /etc/hostapd/hostapd.conf
|
97
|
|
- echo '' >> /etc/hostapd/hostapd.conf
|
98
|
|
- echo '## Key management algorithms ##' >> /etc/hostapd/hostapd.conf
|
99
|
|
- echo 'wpa_key_mgmt=WPA-PSK' >> /etc/hostapd/hostapd.conf
|
100
|
|
- echo '' >> /etc/hostapd/hostapd.conf
|
101
|
|
- echo '## Set cipher suites (encryption algorithms) ##' >> /etc/hostapd/hostapd.conf
|
102
|
|
- echo '## TKIP = Temporal Key Integrity Protocol' >> /etc/hostapd/hostapd.conf
|
103
|
|
- echo '## CCMP = AES in Counter mode with CBC-MAC' >> /etc/hostapd/hostapd.conf
|
104
|
|
- echo 'wpa_pairwise=TKIP' >> /etc/hostapd/hostapd.conf
|
105
|
|
- echo 'rsn_pairwise=CCMP' >> /etc/hostapd/hostapd.conf
|
106
|
|
- echo '' >> /etc/hostapd/hostapd.conf
|
107
|
|
- echo '## Shared Key Authentication ##'
|
108
|
|
- echo 'auth_algs=1'
|
109
|
|
- echo '' >> /etc/hostapd/hostapd.conf
|
110
|
|
- echo '## Accept all MAC address ###' >> /etc/hostapd/hostapd.conf
|
111
|
|
- echo 'macaddr_acl=0' >> /etc/hostapd/hostapd.conf
|
112
|
|
-
|
113
|
|
- if [ ! -f /etc/network/interfaces_original ]; then
|
114
|
|
- if ! grep -q "# wifi enabled" /etc/network/interfaces; then
|
115
|
|
- cp /etc/network/interfaces /etc/network/interfaces_original
|
116
|
|
- fi
|
117
|
|
- fi
|
118
|
|
-
|
119
|
|
- echo '# wifi enabled' > /etc/network/interfaces
|
120
|
|
- echo 'auto lo br0' >> /etc/network/interfaces
|
121
|
|
- echo 'iface lo inet loopback' >> /etc/network/interfaces
|
122
|
|
- echo '' >> /etc/network/interfaces
|
123
|
|
- echo "# wireless $WIFI_INTERFACE" >> /etc/network/interfaces
|
124
|
|
- echo "allow-hotplug $WIFI_INTERFACE" >> /etc/network/interfaces
|
125
|
|
- echo "iface $WIFI_INTERFACE inet manual" >> /etc/network/interfaces
|
126
|
|
- echo '' >> /etc/network/interfaces
|
127
|
|
- echo '# eth0 connected to the ISP router' >> /etc/network/interfaces
|
128
|
|
- echo 'allow-hotplug eth0' >> /etc/network/interfaces
|
129
|
|
- echo 'iface eth0 inet manual' >> /etc/network/interfaces
|
130
|
|
- echo '' >> /etc/network/interfaces
|
131
|
|
- echo '# Setup bridge' >> /etc/network/interfaces
|
132
|
|
- echo 'iface br0 inet static' >> /etc/network/interfaces
|
133
|
|
- echo " bridge_ports $WIFI_INTERFACE eth0" >> /etc/network/interfaces
|
134
|
|
-
|
135
|
|
- systemctl restart network-manager
|
136
|
|
- systemctl restart hostapd
|
|
75
|
+ if [ ! -f /etc/default/hostapd ]; then
|
|
76
|
+ echo $'/etc/default/hostapd was not found'
|
|
77
|
+ exit 67241
|
|
78
|
+ fi
|
|
79
|
+ if [ ${#WIFI_PASSPHRASE} -lt 8 ]; then
|
|
80
|
+ echo $'Wifi hotspot passphrase is too short'
|
|
81
|
+ exit 25719
|
|
82
|
+ fi
|
|
83
|
+
|
|
84
|
+ sed -i 's|#DAEMON_CONF=.*|DAEMON_CONF="/etc/hostapd/hostapd.conf"|g' /etc/default/hostapd
|
|
85
|
+
|
|
86
|
+ echo '### Wireless network name ###' > /etc/hostapd/hostapd.conf
|
|
87
|
+ echo "interface=$WIFI_INTERFACE" >> /etc/hostapd/hostapd.conf
|
|
88
|
+ echo '' >> /etc/hostapd/hostapd.conf
|
|
89
|
+ echo '### Set your bridge name ###' >> /etc/hostapd/hostapd.conf
|
|
90
|
+ echo 'bridge=br0' >> /etc/hostapd/hostapd.conf
|
|
91
|
+ echo '' >> /etc/hostapd/hostapd.conf
|
|
92
|
+ echo 'driver=nl80211' >> /etc/hostapd/hostapd.conf
|
|
93
|
+ echo "country_code=UK" >> /etc/hostapd/hostapd.conf
|
|
94
|
+ echo "ssid=$WIFI_SSID" >> /etc/hostapd/hostapd.conf
|
|
95
|
+ echo 'hw_mode=g' >> /etc/hostapd/hostapd.conf
|
|
96
|
+ echo 'channel=6' >> /etc/hostapd/hostapd.conf
|
|
97
|
+ echo 'wpa=2' >> /etc/hostapd/hostapd.conf
|
|
98
|
+ echo "wpa_passphrase=$WIFI_PASSPHRASE" >> /etc/hostapd/hostapd.conf
|
|
99
|
+ echo '' >> /etc/hostapd/hostapd.conf
|
|
100
|
+ echo '## Key management algorithms ##' >> /etc/hostapd/hostapd.conf
|
|
101
|
+ echo 'wpa_key_mgmt=WPA-PSK' >> /etc/hostapd/hostapd.conf
|
|
102
|
+ echo '' >> /etc/hostapd/hostapd.conf
|
|
103
|
+ echo '## Set cipher suites (encryption algorithms) ##' >> /etc/hostapd/hostapd.conf
|
|
104
|
+ echo '## TKIP = Temporal Key Integrity Protocol' >> /etc/hostapd/hostapd.conf
|
|
105
|
+ echo '## CCMP = AES in Counter mode with CBC-MAC' >> /etc/hostapd/hostapd.conf
|
|
106
|
+ echo 'wpa_pairwise=TKIP' >> /etc/hostapd/hostapd.conf
|
|
107
|
+ echo 'rsn_pairwise=CCMP' >> /etc/hostapd/hostapd.conf
|
|
108
|
+ echo '' >> /etc/hostapd/hostapd.conf
|
|
109
|
+ echo '## Shared Key Authentication ##'
|
|
110
|
+ echo 'auth_algs=1'
|
|
111
|
+ echo '' >> /etc/hostapd/hostapd.conf
|
|
112
|
+ echo '## Accept all MAC address ###' >> /etc/hostapd/hostapd.conf
|
|
113
|
+ echo 'macaddr_acl=0' >> /etc/hostapd/hostapd.conf
|
|
114
|
+
|
|
115
|
+ if [ ! -f /etc/network/interfaces_original ]; then
|
|
116
|
+ if ! grep -q "# wifi enabled" /etc/network/interfaces; then
|
|
117
|
+ cp /etc/network/interfaces /etc/network/interfaces_original
|
|
118
|
+ fi
|
|
119
|
+ fi
|
|
120
|
+
|
|
121
|
+ echo '# wifi enabled' > /etc/network/interfaces
|
|
122
|
+ echo 'auto lo br0' >> /etc/network/interfaces
|
|
123
|
+ echo 'iface lo inet loopback' >> /etc/network/interfaces
|
|
124
|
+ echo '' >> /etc/network/interfaces
|
|
125
|
+ echo "# wireless $WIFI_INTERFACE" >> /etc/network/interfaces
|
|
126
|
+ echo "allow-hotplug $WIFI_INTERFACE" >> /etc/network/interfaces
|
|
127
|
+ echo "iface $WIFI_INTERFACE inet manual" >> /etc/network/interfaces
|
|
128
|
+ echo '' >> /etc/network/interfaces
|
|
129
|
+ echo '# eth0 connected to the ISP router' >> /etc/network/interfaces
|
|
130
|
+ echo 'allow-hotplug eth0' >> /etc/network/interfaces
|
|
131
|
+ echo 'iface eth0 inet manual' >> /etc/network/interfaces
|
|
132
|
+ echo '' >> /etc/network/interfaces
|
|
133
|
+ echo '# Setup bridge' >> /etc/network/interfaces
|
|
134
|
+ echo 'iface br0 inet static' >> /etc/network/interfaces
|
|
135
|
+ echo " bridge_ports $WIFI_INTERFACE eth0" >> /etc/network/interfaces
|
|
136
|
+
|
|
137
|
+ systemctl restart network-manager
|
|
138
|
+ systemctl restart hostapd
|
137
|
139
|
}
|
138
|
140
|
|
139
|
141
|
function wifi_wpa2_psk {
|
140
|
|
- ssid=$1
|
141
|
|
- passphrase=$2
|
142
|
|
-
|
143
|
|
- if [ ! -f /etc/network/interfaces_original ]; then
|
144
|
|
- if ! grep -q "# wifi enabled" /etc/network/interfaces; then
|
145
|
|
- cp /etc/network/interfaces /etc/network/interfaces_original
|
146
|
|
- fi
|
147
|
|
- fi
|
148
|
|
-
|
149
|
|
- echo '# wifi enabled' > /etc/network/interfaces
|
150
|
|
- echo 'auto lo' >> /etc/network/interfaces
|
151
|
|
- echo 'iface lo inet loopback' >> /etc/network/interfaces
|
152
|
|
- echo '' >> /etc/network/interfaces
|
153
|
|
- echo 'allow-hotplug eth0' >> /etc/network/interfaces
|
154
|
|
- echo 'iface eth0 inet dhcp' >> /etc/network/interfaces
|
155
|
|
- echo '' >> /etc/network/interfaces
|
156
|
|
- echo 'allow-hotplug wlan0' >> /etc/network/interfaces
|
157
|
|
- echo 'iface wlan0 inet manual' >> /etc/network/interfaces
|
158
|
|
- echo 'wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf' >> /etc/network/interfaces
|
159
|
|
- echo '' >> /etc/network/interfaces
|
160
|
|
- echo 'iface default inet dhcp' >> /etc/network/interfaces
|
161
|
|
-
|
162
|
|
- wpa_passphrase "$ssid" "$passphrase" > /etc/wpa_supplicant/wpa_supplicant.conf
|
163
|
|
-
|
164
|
|
- systemctl restart network-manager
|
|
142
|
+ ssid=$1
|
|
143
|
+ passphrase=$2
|
|
144
|
+
|
|
145
|
+ if [ ! -f /etc/network/interfaces_original ]; then
|
|
146
|
+ if ! grep -q "# wifi enabled" /etc/network/interfaces; then
|
|
147
|
+ cp /etc/network/interfaces /etc/network/interfaces_original
|
|
148
|
+ fi
|
|
149
|
+ fi
|
|
150
|
+
|
|
151
|
+ echo '# wifi enabled' > /etc/network/interfaces
|
|
152
|
+ echo 'auto lo' >> /etc/network/interfaces
|
|
153
|
+ echo 'iface lo inet loopback' >> /etc/network/interfaces
|
|
154
|
+ echo '' >> /etc/network/interfaces
|
|
155
|
+ echo 'allow-hotplug eth0' >> /etc/network/interfaces
|
|
156
|
+ echo 'iface eth0 inet dhcp' >> /etc/network/interfaces
|
|
157
|
+ echo '' >> /etc/network/interfaces
|
|
158
|
+ echo 'allow-hotplug wlan0' >> /etc/network/interfaces
|
|
159
|
+ echo 'iface wlan0 inet manual' >> /etc/network/interfaces
|
|
160
|
+ echo " wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces
|
|
161
|
+ echo '' >> /etc/network/interfaces
|
|
162
|
+ echo 'iface default inet dhcp' >> /etc/network/interfaces
|
|
163
|
+
|
|
164
|
+ wpa_passphrase "$ssid" "$passphrase" > $WIFI_CONFIG
|
|
165
|
+
|
|
166
|
+ systemctl restart network-manager
|
165
|
167
|
}
|
166
|
168
|
|
167
|
169
|
function wifi_none {
|
168
|
|
- ssid=$1
|
169
|
|
-
|
170
|
|
- if [ ! -f /etc/network/interfaces_original ]; then
|
171
|
|
- if ! grep -q "# wifi enabled" /etc/network/interfaces; then
|
172
|
|
- cp /etc/network/interfaces /etc/network/interfaces_original
|
173
|
|
- fi
|
174
|
|
- fi
|
175
|
|
-
|
176
|
|
- echo '# wifi enabled' > /etc/network/interfaces
|
177
|
|
- echo 'auto lo' >> /etc/network/interfaces
|
178
|
|
- echo 'iface lo inet loopback' >> /etc/network/interfaces
|
179
|
|
- echo '' >> /etc/network/interfaces
|
180
|
|
- echo 'allow-hotplug eth0' >> /etc/network/interfaces
|
181
|
|
- echo 'iface eth0 inet dhcp' >> /etc/network/interfaces
|
182
|
|
- echo '' >> /etc/network/interfaces
|
183
|
|
- echo 'allow-hotplug wlan0' >> /etc/network/interfaces
|
184
|
|
- echo 'iface wlan0 inet manual' >> /etc/network/interfaces
|
185
|
|
- echo 'wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf' >> /etc/network/interfaces
|
186
|
|
- echo '' >> /etc/network/interfaces
|
187
|
|
- echo 'iface default inet dhcp' >> /etc/network/interfaces
|
188
|
|
-
|
189
|
|
- echo 'network={' > /etc/wpa_supplicant/wpa_supplicant.conf
|
190
|
|
- echo " ssid=\"${ssid}\"" >> /etc/wpa_supplicant/wpa_supplicant.conf
|
191
|
|
- echo ' key_mgmt=NONE' >> /etc/wpa_supplicant/wpa_supplicant.conf
|
192
|
|
- echo '}' >> /etc/wpa_supplicant/wpa_supplicant.conf
|
193
|
|
-
|
194
|
|
- systemctl restart network-manager
|
|
170
|
+ ssid=$1
|
|
171
|
+
|
|
172
|
+ if [ ! -f /etc/network/interfaces_original ]; then
|
|
173
|
+ if ! grep -q "# wifi enabled" /etc/network/interfaces; then
|
|
174
|
+ cp /etc/network/interfaces /etc/network/interfaces_original
|
|
175
|
+ fi
|
|
176
|
+ fi
|
|
177
|
+
|
|
178
|
+ echo '# wifi enabled' > /etc/network/interfaces
|
|
179
|
+ echo 'auto lo' >> /etc/network/interfaces
|
|
180
|
+ echo 'iface lo inet loopback' >> /etc/network/interfaces
|
|
181
|
+ echo '' >> /etc/network/interfaces
|
|
182
|
+ echo 'allow-hotplug eth0' >> /etc/network/interfaces
|
|
183
|
+ echo 'iface eth0 inet dhcp' >> /etc/network/interfaces
|
|
184
|
+ echo '' >> /etc/network/interfaces
|
|
185
|
+ echo 'allow-hotplug wlan0' >> /etc/network/interfaces
|
|
186
|
+ echo 'iface wlan0 inet manual' >> /etc/network/interfaces
|
|
187
|
+ echo " wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces
|
|
188
|
+ echo '' >> /etc/network/interfaces
|
|
189
|
+ echo 'iface default inet dhcp' >> /etc/network/interfaces
|
|
190
|
+
|
|
191
|
+ echo 'network={' > $WIFI_CONFIG
|
|
192
|
+ echo " ssid=\"${ssid}\"" >> $WIFI_CONFIG
|
|
193
|
+ echo ' key_mgmt=NONE' >> $WIFI_CONFIG
|
|
194
|
+ echo '}' >> $WIFI_CONFIG
|
|
195
|
+
|
|
196
|
+ systemctl restart network-manager
|
|
197
|
+}
|
|
198
|
+
|
|
199
|
+function create_networks_from_file {
|
|
200
|
+ if [ ! -f $WIFI_FILE ]; then
|
|
201
|
+ return
|
|
202
|
+ fi
|
|
203
|
+
|
|
204
|
+ if [ ! -f /etc/network/interfaces_original ]; then
|
|
205
|
+ if ! grep -q "# wifi enabled" /etc/network/interfaces; then
|
|
206
|
+ cp /etc/network/interfaces /etc/network/interfaces_original
|
|
207
|
+ fi
|
|
208
|
+ fi
|
|
209
|
+
|
|
210
|
+ echo '# wifi enabled' > /etc/network/interfaces
|
|
211
|
+ echo 'auto lo' >> /etc/network/interfaces
|
|
212
|
+ echo 'iface lo inet loopback' >> /etc/network/interfaces
|
|
213
|
+ echo '' >> /etc/network/interfaces
|
|
214
|
+ echo 'allow-hotplug eth0' >> /etc/network/interfaces
|
|
215
|
+ echo 'iface eth0 inet dhcp' >> /etc/network/interfaces
|
|
216
|
+ echo '' >> /etc/network/interfaces
|
|
217
|
+ echo 'allow-hotplug wlan0' >> /etc/network/interfaces
|
|
218
|
+ echo 'iface wlan0 inet manual' >> /etc/network/interfaces
|
|
219
|
+ echo " wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces
|
|
220
|
+ echo '' >> /etc/network/interfaces
|
|
221
|
+ echo 'iface default inet dhcp' >> /etc/network/interfaces
|
|
222
|
+
|
|
223
|
+ # remove wpa_supplicant.conf if it exists
|
|
224
|
+ if [ -f $WIFI_CONFIG ]; then
|
|
225
|
+ rm -f $WIFI_CONFIG
|
|
226
|
+ fi
|
|
227
|
+
|
|
228
|
+ ctr=0
|
|
229
|
+ while read -r line
|
|
230
|
+ do
|
|
231
|
+ if [ ${#line} -gt 1 ]; then
|
|
232
|
+ if [[ "$line" != '#'* ]]; then
|
|
233
|
+ if [ $ctr -eq 0 ]; then
|
|
234
|
+ WIFI_SSID="$line"
|
|
235
|
+ fi
|
|
236
|
+ if [ $ctr -eq 1 ]; then
|
|
237
|
+ WIFI_TYPE="$line"
|
|
238
|
+ if [[ $WIFI_TYPE == $'none' || $WIFI_TYPE == $'None' ]]; then
|
|
239
|
+ echo 'network={' >> $WIFI_CONFIG
|
|
240
|
+ echo " ssid=\"${WIFI_SSID}\"" >> $WIFI_CONFIG
|
|
241
|
+ echo ' key_mgmt=NONE' >> $WIFI_CONFIG
|
|
242
|
+ echo '}' >> $WIFI_CONFIG
|
|
243
|
+ ctr=0
|
|
244
|
+ continue
|
|
245
|
+ fi
|
|
246
|
+ fi
|
|
247
|
+ if [ $ctr -eq 2 ]; then
|
|
248
|
+ WIFI_PASSPHRASE="$line"
|
|
249
|
+ wpa_passphrase "$WIFI_SSID" "$WIFI_PASSPHRASE" >> $WIFI_CONFIG
|
|
250
|
+ ctr=0
|
|
251
|
+ continue
|
|
252
|
+ fi
|
|
253
|
+
|
|
254
|
+ ctr=$((ctr + 1))
|
|
255
|
+ fi
|
|
256
|
+ fi
|
|
257
|
+ done < $WIFI_FILE
|
|
258
|
+
|
|
259
|
+ systemctl restart network-manager
|
195
|
260
|
}
|
196
|
261
|
|
197
|
262
|
function show_help {
|
198
|
|
- echo ''
|
199
|
|
- echo $"${PROJECT_NAME}-wifi -i [interface] -t [type] -s [ssid] -p [passphrase]"
|
200
|
|
- echo ''
|
201
|
|
- echo $'Wifi configuration tool'
|
202
|
|
- echo ''
|
203
|
|
- echo $' --help Show help'
|
204
|
|
- echo $' -i --interface [wlan0|wlan1...] Device name'
|
205
|
|
- echo $' -t --type [wpa2-psk|none] Security type'
|
206
|
|
- echo $' -s --ssid [id] Set SSID'
|
207
|
|
- echo $' -p --passphrase [text] Set passphrase'
|
208
|
|
- echo $' --hotspot [yes|no] Create a hotspot'
|
209
|
|
- echo ''
|
210
|
|
- exit 0
|
|
263
|
+ echo ''
|
|
264
|
+ echo $"${PROJECT_NAME}-wifi -i [interface] -t [type] -s [ssid] -p [passphrase]"
|
|
265
|
+ echo ''
|
|
266
|
+ echo $'Wifi configuration tool'
|
|
267
|
+ echo ''
|
|
268
|
+ echo $' --help Show help'
|
|
269
|
+ echo $' -i --interface [wlan0|wlan1...] Device name'
|
|
270
|
+ echo $' -t --type [wpa2-psk|none] Security type'
|
|
271
|
+ echo $' -s --ssid [id] Set SSID'
|
|
272
|
+ echo $' -p --passphrase [text] Set passphrase'
|
|
273
|
+ echo $' --hotspot [yes|no] Create a hotspot'
|
|
274
|
+ echo ''
|
|
275
|
+ exit 0
|
211
|
276
|
}
|
212
|
277
|
|
213
|
278
|
while [[ $# > 1 ]]
|
214
|
279
|
do
|
215
|
|
- key="$1"
|
216
|
|
-
|
217
|
|
- case $key in
|
218
|
|
- --help)
|
219
|
|
- show_help
|
220
|
|
- ;;
|
221
|
|
- -i|--if|--interface)
|
222
|
|
- shift
|
223
|
|
- WIFI_INTERFACE=${1}
|
224
|
|
- ;;
|
225
|
|
- -t|--type)
|
226
|
|
- shift
|
227
|
|
- WIFI_TYPE=${1}
|
228
|
|
- ;;
|
229
|
|
- -s|--ssid)
|
230
|
|
- shift
|
231
|
|
- WIFI_SSID=${1}
|
232
|
|
- ;;
|
233
|
|
- -p|--pass|--passphrase)
|
234
|
|
- shift
|
235
|
|
- WIFI_PASSPHRASE=${1}
|
236
|
|
- ;;
|
237
|
|
- --hostpot)
|
238
|
|
- shift
|
239
|
|
- WIFI_HOTSPOT=${1}
|
240
|
|
- ;;
|
241
|
|
- *)
|
242
|
|
- # unknown option
|
243
|
|
- ;;
|
244
|
|
- esac
|
245
|
|
- shift
|
|
280
|
+ key="$1"
|
|
281
|
+
|
|
282
|
+ case $key in
|
|
283
|
+ --help)
|
|
284
|
+ show_help
|
|
285
|
+ ;;
|
|
286
|
+ -i|--if|--interface)
|
|
287
|
+ shift
|
|
288
|
+ WIFI_INTERFACE=${1}
|
|
289
|
+ ;;
|
|
290
|
+ -t|--type)
|
|
291
|
+ shift
|
|
292
|
+ WIFI_TYPE=${1}
|
|
293
|
+ ;;
|
|
294
|
+ -s|--ssid)
|
|
295
|
+ shift
|
|
296
|
+ WIFI_SSID=${1}
|
|
297
|
+ ;;
|
|
298
|
+ -p|--pass|--passphrase)
|
|
299
|
+ shift
|
|
300
|
+ WIFI_PASSPHRASE=${1}
|
|
301
|
+ ;;
|
|
302
|
+ --hostpot)
|
|
303
|
+ shift
|
|
304
|
+ WIFI_HOTSPOT=${1}
|
|
305
|
+ ;;
|
|
306
|
+ --config)
|
|
307
|
+ shift
|
|
308
|
+ WIFI_FILE=${1}
|
|
309
|
+ ;;
|
|
310
|
+ *)
|
|
311
|
+ # unknown option
|
|
312
|
+ ;;
|
|
313
|
+ esac
|
|
314
|
+ shift
|
246
|
315
|
done
|
247
|
316
|
|
|
317
|
+if [ -f $WIFI_FILE ]; then
|
|
318
|
+ create_networks_from_file
|
|
319
|
+ exit 0
|
|
320
|
+fi
|
|
321
|
+
|
248
|
322
|
if [ ! $WIFI_SSID ]; then
|
249
|
|
- echo $'No SSID given'
|
250
|
|
- exit 1
|
|
323
|
+ echo $'No SSID given'
|
|
324
|
+ exit 1
|
251
|
325
|
fi
|
252
|
326
|
|
253
|
327
|
if [[ $WIFI_HOTSPOT != 'no' ]]; then
|
254
|
|
- hotspot_on
|
255
|
|
- exit 0
|
|
328
|
+ hotspot_on
|
|
329
|
+ exit 0
|
256
|
330
|
else
|
257
|
|
- hotspot_off
|
|
331
|
+ hotspot_off
|
258
|
332
|
fi
|
259
|
333
|
|
260
|
334
|
if [[ $WIFI_TYPE != 'none' ]]; then
|
261
|
|
- if [ ! $WIFI_PASSPHRASE ]; then
|
262
|
|
- echo $'No wifi passphrase was given'
|
263
|
|
- exit 2
|
264
|
|
- fi
|
|
335
|
+ if [ ! $WIFI_PASSPHRASE ]; then
|
|
336
|
+ echo $'No wifi passphrase was given'
|
|
337
|
+ exit 2
|
|
338
|
+ fi
|
265
|
339
|
fi
|
266
|
340
|
|
267
|
341
|
if [[ $WIFI_TYPE == 'wpa2-psk' ]]; then
|
268
|
|
- if [ ! -d /etc/wpa_supplicant ]; then
|
269
|
|
- echo $'wpasupplicant package is not installed'
|
270
|
|
- exit 3
|
271
|
|
- fi
|
272
|
|
- wifi_wpa2_psk "$WIFI_SSID" "$WIFI_PASSPHRASE"
|
273
|
|
- exit 0
|
|
342
|
+ if [ ! -d /etc/wpa_supplicant ]; then
|
|
343
|
+ echo $'wpasupplicant package is not installed'
|
|
344
|
+ exit 3
|
|
345
|
+ fi
|
|
346
|
+ wifi_wpa2_psk "$WIFI_SSID" "$WIFI_PASSPHRASE"
|
|
347
|
+ exit 0
|
274
|
348
|
fi
|
275
|
349
|
|
276
|
350
|
if [[ $WIFI_TYPE == 'none' ]]; then
|
277
|
|
- wifi_none "$WIFI_SSID"
|
278
|
|
- exit 0
|
|
351
|
+ wifi_none "$WIFI_SSID"
|
|
352
|
+ exit 0
|
279
|
353
|
fi
|
280
|
354
|
|
281
|
355
|
exit 0
|