-
Notifications
You must be signed in to change notification settings - Fork 2
/
install_hotspot8188CUS.sh
executable file
·397 lines (341 loc) · 9.67 KB
/
install_hotspot8188CUS.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
#!/bin/bash
#
# Raspberry Pi install RTL8188CUS nan wifi USB adaptor
#by Paul Miller
#Revisions:
# 0.1 - 25/04/2013 Initial Release
# 0.1 SW 01Aug2014 - change to use as Hotspot and not AP
#
#
###################################################
###################################################
#set default values
###################################################
# General
CURRENT_AUTHOR="[email protected]"
# Network Interface
IP4_CONF_TYPE=STATIC
IP4_ADDRESS=10.0.0.1
IP4_NETMASK=255.255.255.0
IP4_NETWORK=${IP4_ADDRESS%?}0
IP4_BROADCAST=${IP4_ADDRESS%?}255
IP4_GATEWAY=${IP4_ADDRESS}
IP4_DNS1=8.8.8.8.8
IP4_DNS2=4.4.4.4
IP4_STARTADDRESS=${IP4_ADDRESS%?}2
IP4_ENDADDRESS=${IP4_ADDRESS%?}50
# Wifi Access Point
AP_COUNTRY=GB
AP_CHAN=11
AP_SSID=ClassPi
AP_PASSPHRASE=PASSWORD # not used in practice
###################################################
echo " performing a series of prechecks..."
###################################################
#check current user privileges
(( `id -u` )) && echo "This script MUST be ran with root privileges, try prefixing with sudo. i.e sudo $0" && exit 1
#check that USB wifi device is plugged in and seen
if [[ -n $(lsusb | grep RTL8188CUS) ]]; then
echo "The RTL8188CUS device has been successfully located."
else
echo "The RTL8188CUS device has not been located, check it is inserted and run script again when done."
exit 1
fi
#check that internet connection is available
# the hosts below are selected for their high availability,
# if it is more apprioriate to change a host to equal one that is
# required for the script then simply change the FQDN chosen below
# to check the availabilty for the host before the script gets underway
host1=google.com
host2=wikipedia.org
((ping -w5 -c3 $host1 || ping -w5 -c3 $host2) > /dev/null 2>&1) && echo "Internet connectivity - OK" || (echo "Internet connectivity - Down, Internet connectivity is required for this script to complete. exiting..." && exit 1)
#pre-checks complete#####################################################
#clear the screen
clear
# Get Input from User
echo "Capture User Settings:"
echo "====================="
echo "Please answer the following questions."
echo "Hitting return will continue with the default option"
echo
echo
#read -p "IPv4 DHCP or STATIC? [$IP4_CONF_TYPE]: " -e t1
#if [ -n "$t1" ]; then IP4_CONF_TYPE="$t1";fi
if [ "$IP4_CONF_TYPE" = "STATIC" ]; then
read -p "IPv4 Address [$IP4_ADDRESS]: " -e t1
if [ -n "$t1" ]; then IP4_ADDRESS="$t1";fi
read -p "IPv4 Netmask [$IP4_NETMASK]: " -e t1
if [ -n "$t1" ]; then IP4_NETMASK="$t1";fi
read -p "IPv4 Network [$IP4_NETWORK]: " -e t1
if [ -n "$t1" ]; then IP4_NETWORK="$t1";fi
read -p "IPv4 Broadcast [$IP4_BROADCAST]: " -e t1
if [ -n "$t1" ]; then IP4_BROADCAST="$t1";fi
read -p "IPv4 Gateway Address [$IP4_GATEWAY]: " -e t1
if [ -n "$t1" ]; then IP4_GATEWAY="$t1";fi
read -p "IPv4 Primary DNS server [$IP4_DNS1]: " -e t1
if [ -n "$t1" ]; then IP4_DNS1="$t1";fi
read -p "IPv4 Secondary DNS server [$IP4_DNS2]: " -e t1
if [ -n "$t1" ]; then IP4_DNS2="$t1";fi
fi
# wifi settings
read -p "Wifi Country [$AP_COUNTRY]: " -e t1
if [ -n "$t1" ]; then AP_COUNTRY="$t1";fi
read -p "Wifi Channel Name [$AP_CHAN]: " -e t1
if [ -n "$t1" ]; then AP_CHAN="$t1";fi
read -p "Wifi SSID [$AP_SSID]: " -e t1
if [ -n "$t1" ]; then AP_SSID="$t1";fi
read -p "Wifi PassPhrase (min 8 max 63 characters) [$AP_PASSPHRASE]: " -e t1
if [ -n "$t1" ]; then AP_PASSPHRASE="$t1";fi
###################################################
# Get Decision from User
###################################################
echo "Hotspot Setup"
echo "======================"
echo "Please answer the following question."
echo "Hitting return will continue with the default 'No' option"
echo
# Point of no return
read -p "Do you wish to continue and Setup RPi as an Hotspot? (y/n) " RESP
if [ "$RESP" = "y" ]; then
clear
echo "Configuring RPI as an Hotspot Point...."
# update system
echo ""
echo "#####################PLEASE WAIT##################"######
echo -en "Package list update "
apt-get -qq update
echo -en "[OK]\n"
echo -en "Adding packages ... please wait .... "
apt-get -y -qq install hostapd bridge-utils iw dnsmasq > /dev/null 2>&1
apt-get -y -qq remove ifplugd > /dev/null 2>&1
echo -en "[OK]\n"
#check that iw list fails with 'nl80211 not found'
echo -en "iw list check "
iw list > /dev/null 2>&1 | grep 'nl80211 not found'
rc=$?
if [[ $rc = 0 ]] ; then
echo -en "[FAIL]\n"
echo ""
echo "A check that should have a known outcome has has not"
echo "produced the expected result, it is best to manually"
echo "proceed and ask for assistance from the RPi forum or"
echo "the authour of this version of the script."
echo $CURRENT_AUTHOR
exit $rc
else
echo -en "[OK]\n"
fi
#creat the default file to point at the configuration file
echo -en "Create Default hostapd file "
cat <<EOF > /etc/default/hostapd
#created by $0
DAEMON_CONF="/etc/hostapd/hostapd.conf"
EOF
rc=$?
if [[ $rc != 0 ]] ; then
echo -en "[FAIL]\n"
echo ""
exit $rc
else
echo -en "[OK]\n"
fi
# echo -en "[OK]\n"
#create the hostapd configuration to match what the user has provided
echo -en "Create hostapd.conf file "
cat <<EOF > /etc/hostapd/hostapd.conf
#created by $0
interface=wlan0
driver=rtl871xdrv
country_code=$AP_COUNTRY
ctrl_interface=wlan0
ctrl_interface_group=0
ssid=$AP_SSID
hw_mode=g
channel=$AP_CHAN
#wpa=3
#wpa_passphrase=$AP_PASSPHRASE
#wpa_key_mgmt=WPA-PSK
#wpa_pairwise=TKIP
#rsn_pairwise=CCMP
beacon_int=100
auth_algs=3
macaddr_acl=0
wmm_enabled=1
eap_reauth_period=360000000
EOF
rc=$?
if [[ $rc != 0 ]] ; then
echo -en "[FAIL]\n"
echo ""
exit $rc
else
echo -en "[OK]\n"
fi
# echo -en "[OK]\n"
# backup the existing interfaces file
echo -en "Backup network interface configuration "
cp /etc/network/interfaces /etc/network/interfaces.bak
rc=$?
if [[ $rc != 0 ]] ; then
echo -en "[FAIL]\n"
echo ""
exit $rc
else
echo -en "[OK]\n"
fi
# echo -en "[OK]\n"
# create the following network interface file based on user input
echo -en "Create new network interface configuration "
if [ "$IP4_CONF_TYPE" = "DHCP" ]; then
cat <<EOF > /etc/network/interfaces
#created by $0
auto lo
auto br0
iface lo inet loopback
iface br0 inet dhcp
bridge_fd 1
bridge_hello 3
bridge_maxage 10
bridge_stp off
bridge_ports eth0 wlan0
allow-hotplug eth0
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet manual
EOF
rc=$?
if [[ $rc != 0 ]] ; then
echo -en "[FAIL]\n"
echo ""
exit $rc
else
echo -en "[OK]\n"
fi
# echo -en "[OK]\n"
fi
if [ "$IP4_CONF_TYPE" = "STATIC" ]; then
cat <<EOF > /etc/network/interfaces
#created by $0
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet dhcp
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address $IP4_ADDRESS
network $IP4_NETWORK
netmask $IP4_NETMASK
broadcast $IP4_BROADCAST
EOF
rc=$?
if [[ $rc != 0 ]] ; then
echo -en "[FAIL]\n"
echo ""
exit $rc
else
echo -en "[OK]\n"
fi
# echo -en "[OK]\n"
fi
#create the dnsmasq.conf configuration to match what the user has provided
echo -en "Create dnsmasq.conf file "
cat <<EOF > /etc/dnsmasq.conf
#created by $0
interface=wlan0 # To get dnsmasq to listen only on wlan0.
dhcp-range=$IP4_STARTADDRESS,$IP4_ENDADDRESS,$IP$_NETMASK,12h
EOF
rc=$?
if [[ $rc != 0 ]] ; then
echo -en "[FAIL]\n"
echo ""
exit $rc
else
echo -en "[OK]\n"
fi
#deal with the hostapd binary file
echo -en "change directory "
cd /usr/sbin
rc=$?
if [[ $rc != 0 ]] ; then
echo -en "[FAIL]\n"
echo ""
exit $rc
else
echo -en "[OK]\n"
fi
# echo -en "[OK]\n"
# backup the old hostapd file
echo -en "Backup hostapd file "
cp /usr/sbin/hostapd /usr/sbin/hostapd.bak
rc=$?
if [[ $rc != 0 ]] ; then
echo -en "[FAIL]\n"
echo ""
exit $rc
else
echo -en "[OK]\n"
fi
# echo -en "[OK]\n"
# delete the old hostapd file
echo -en "Delete old hostapd file "
rm -f hostapd
rc=$?
if [[ $rc != 0 ]] ; then
echo -en "[FAIL]\n"
echo ""
exit $rc
else
echo -en "[OK]\n"
fi
# echo -en "[OK]\n"
# Download the replacement file
echo -en "Download the hostapd file "
wget https://www.dropbox.com/s/pl9tn35ay2b92dc/hostapd
#> /dev/null 2>&1
rc=$?
if [[ $rc != 0 ]] ; then
echo -en "[FAIL]\n"
echo ""
exit $rc
else
echo -en "[OK]\n"
fi
# echo -en "[OK]\n"
# make sure root has ownership of the file
echo -en "Modify hostapd ownership "
chown root:root hostapd
rc=$?
if [[ $rc != 0 ]] ; then
echo -en "[FAIL]\n"
echo ""
exit $rc
else
echo -en "[OK]\n"
fi
# echo -en "[OK]\n"
# make the new file executable
echo -en "Modify the hostapd file permissions "
chmod 755 hostapd
rc=$?
if [[ $rc != 0 ]] ; then
echo -en "[FAIL]\n"
echo ""
exit $rc
else
echo -en "[OK]\n"
fi
# echo -en "[OK]\n"
echo "###################INSTALL COMPLETE###############"######
echo "The Pi will now be rebooted to activate the changes"
read -p "Press [Enter] key to reboot... "
reboot
# Restart the networking configuration to activate the changes
#/etc/init.d/networking restart
# Restart the access point software
#/etc/init.d/hostapd restart
####################################################################
else
echo "exiting..."
fi
exit 0