-
Notifications
You must be signed in to change notification settings - Fork 4
/
install.sh
executable file
·260 lines (223 loc) · 6.84 KB
/
install.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
#! /bin/bash
#
# Raspberry Pi YouAreHere Installation script
# Sarah Grant
# Updated 13 June 2016
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# SOME DEFAULT VALUES
#
# WIRELESS RADIO DRIVER
RADIO_DRIVER=nl80211
# ACCESS POINT
AP_CHAN=3
AP_SSID=YouAreHere
AP_IP=192.168.100.1
# DNSMASQ STUFF
DHCP_START=192.168.100.101
DHCP_END=192.168.100.254
DHCP_NETMASK=255.255.255.0
DHCP_LEASE=1h
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# CHECK USER PRIVILEGES
(( `id -u` )) && echo "This script must be ran with root privileges, try prefixing with sudo. i.e sudo $0" && exit 1
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# BEGIN INSTALLATION PROCESS
#
echo "●▬▬▬▬---▬▬▬▬▬▬▬*'¨'*▬▬▬▬▬▬▬---▬▬▬▬●"
echo "| You Are Here Installation |"
echo "●▬▬▬▬▬▬▬▬---▬▬▬*,_,*▬▬▬---▬▬▬▬▬▬▬▬●"
echo ""
read -p "This installation script will configure a wireless access point, captive portal, apache web server and ppp 3G data link. Make sure you have a USB wifi radio connected to your Raspberry Pi before proceeding. Press any key to continue..."
echo ""
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# SOFTWARE INSTALL
#
# update the packages
echo "Updating apt-get and installing hostapd, dnsmasq, ppp, usb-modeswitch, usb-modeswitch-data, apache web server, iw package for network interface configuration..."
apt-get update && apt-get install -y npm hostapd dnsmasq iw ppp usb-modeswitch usb-modeswitch-data apache2 apache2-utils
echo ""
echo "Configuring apache web server..."
chown www-data:www-data /var/www
chmod 775 /var/www
usermod -a -G www-data pi
# create script and file for tracking / analytics
mkdir /var/www/cgi
cp scripts/stats.py /var/www/cgi/
chmod +x /var/www/cgi/stats.py
touch /var/www/stats.txt
chmod 666 /var/www/stats.txt
# configure apache proxy, cache, ssl, rewrite
a2enmod proxy_http proxy proxy_connect ssl cache_disk rewrite cgid
# append scripts/mod_proxy.conf to end of /etc/apache2/apache2.conf...
cat scripts/mod_proxy.conf >> /etc/apache2/apache2.conf
# copy scripts/999-youarehere-rewrite.conf to conf-enabled...
cp scripts/999-youarehere-rewrite.conf /etc/apache2/conf-enabled/
cp scripts/999-youarehere-cgi.conf /etc/apache2/conf-enabled/
# restart apache
service apache2 reload
service apache2 restart
# CHECK USB WIFI HARDWARE IS FOUND
# and that iw list does not fail with 'nl80211 not found'
echo -en "checking that nl80211 USB wifi radio is plugged in... "
iw list > /dev/null 2>&1 | grep 'nl80211 not found'
rc=$?
if [[ $rc = 0 ]] ; then
echo -en "[FAIL]\n"
echo "Make sure you are using a wifi radio that runs via the nl80211 driver."
exit $rc
else
echo -en "[OK]\n"
fi
echo "Configuring Raspberry Pi as Access Point..."
echo ""
# ask how they want to configure their access point
read -p "Wifi Channel Number [$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 "DHCP starting address [$DHCP_START]: " -e t1
if [ -n "$t1" ]; then DHCP_START="$t1";fi
read -p "DHCP ending address [$DHCP_END]: " -e t1
if [ -n "$t1" ]; then DHCP_END="$t1";fi
read -p "DHCP netmask [$DHCP_NETMASK]: " -e t1
if [ -n "$t1" ]; then DHCP_NETMASK="$t1";fi
read -p "DHCP length of lease [$DHCP_LEASE]: " -e t1
if [ -n "$t1" ]; then DHCP_LEASE="$t1";fi
# backup the existing interfaces file
echo -en "Creating backup of network interfaces configuration file... "
cp /etc/network/interfaces /etc/network/interfaces.bak
rc=$?
if [[ $rc != 0 ]] ; then
echo -en "[FAIL]\n"
exit $rc
else
echo -en "[OK]\n"
fi
# CONFIGURE /etc/network/interfaces
echo -en "Creating new network interfaces configuration file with your settings... "
cat <<EOF > /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
iface eth0 inet manual
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address $AP_IP
netmask 255.255.255.0
auto gprs
iface gprs inet ppp
provider gprs
EOF
rc=$?
if [[ $rc != 0 ]] ; then
echo -en "[FAIL]\n"
echo ""
exit $rc
else
echo -en "[OK]\n"
fi
# create hostapd init file
echo -en "Creating default hostapd file... "
cat <<EOF > /etc/default/hostapd
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
# create hostapd configuration with user's settings
echo -en "Creating hostapd.conf file... "
cat <<EOF > /etc/hostapd/hostapd.conf
interface=wlan0
driver=$RADIO_DRIVER
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
ssid=$AP_SSID
hw_mode=g
channel=$AP_CHAN
beacon_int=100
auth_algs=1
wpa=0
macaddr_acl=0
EOF
rc=$?
if [[ $rc != 0 ]] ; then
echo -en "[FAIL]\n"
exit $rc
else
echo -en "[OK]\n"
fi
# CONFIGURE dnsmasq
echo -en "Creating dnsmasq configuration file... "
cat <<EOF > /etc/dnsmasq.conf
interface=wlan0
address=/#/$AP_IP
address=/youarehere.com/$AP_IP
address=/apple.com/0.0.0.0
address=/phiffer.org/173.220.23.228
address=/youarehere.network/192.30.252.153
dhcp-range=$DHCP_START,$DHCP_END,$DHCP_NETMASK,$DHCP_LEASE
EOF
rc=$?
if [[ $rc != 0 ]] ; then
echo -en "[FAIL]\n"
echo ""
exit $rc
else
echo -en "[OK]\n"
fi
# Need to create /etc/usb_modeswitch.conf and prompt for values:
# (DefaultVendor and DefaultProduct are obtainable from lsusb and reading what
# is listed for the Huawei device, after ID)
# DefaultVendor=0x12d1
# DefaultProduct=0x14fe
# MessageEndpoint="0x01"
# MessageContent="55534243123456780000000000000011062000000101000100000000000000"
# Also need to create /etc/ppp/peers/gprs file
# Need to prompt for user, APN
# user ""
# connect "/usr/sbin/chat -v -f /etc/chatscripts/gprs -T fast.t-mobile.com"
# /dev/ttyUSB0
# noipdefault
# defaultroute
# replacedefaultroute
# hide-password
# noauth
# persist
# usepeerdns
# Copy over scripts to configure Huawei E303 3G Modem
cp scripts/usb_modeswitch.conf /etc/usb_modeswitch.conf
cp scripts/gprs /etc/ppp/peers/gprs
cp scripts/huawei_e303.rules /etc/udev/rules.d/huawei_e303.rules
cp scripts/blacklist-bc.conf /etc/modprobe.d/blacklist-bc.conf
# reload rules so data stick is automatically mode switched from storage device to modem
udevadm control --reload-rules
# Build files
# cd www/
# npm install
rsync -r www/build/* /var/www/html/
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# COPY OVER THE ACCESS POINT START UP SCRIPT + enable services
#
clear
update-rc.d hostapd enable
update-rc.d dnsmasq enable
cp scripts/you_are_here.sh /etc/init.d/you_are_here
chmod 755 /etc/init.d/you_are_here
update-rc.d you_are_here defaults
read -p "Do you wish to reboot now? [N] " yn
case $yn in
[Yy]* )
reboot;;
Nn]* ) exit 0;;
esac