forked from fpapleux/raspi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sh
executable file
·441 lines (326 loc) · 14 KB
/
init.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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
#!/bin/bash
clear; echo -e "\n\n\n\n\n\n\n\n\n\n"
echo -e "-------------------------------------------------------------------------------------"
echo -e "| Initializing new RaspberryPi |"
echo -e "-------------------------------------------------------------------------------------"
echo -e "\n- Make sure it is connected to the Internet... (probably use an ethernet cable at this point)"
echo -en "\n\n-- Press any key to continue --"; read -n 1 cont; echo
#####################################################################################
## GATHERING USER INPUT
#####################################################################################
clear; echo -e "\n\n\n\n\n\n\n\n\n\n"
echo -e " Gathering configuration input"
echo -e "-------------------------------------------------------------------------------------"
echo -e "\n"
# ----- Refresh System --------------------------------------
cont="n"
refreshSystem=0
echo -n "update & upgrade apt-get packages? ('y' for yes) "
read -n 1 q; echo
if [ "$q" == "y" ] || [ "$q" == "Y" ]; then
refreshSystem=1
fi
# echo -e "\n"
# ----- Install Avahi Zeroconf ------------------------------
cont="n"
installAvahi=0
echo -n "Install Avahi daemon package to access this pi with raspberrypi.local? ('y' for yes) "
read -n 1 q; echo
if [ "$q" == "y" ] || [ "$q" == "Y" ]; then
installAvahi=1
fi
# echo -e "\n"
# ----- Install Bluetooth suite -----------------------------
installBluetooth=0
echo -n "Install bluetooth USB adapter software? ('y' for yes) "
read -n 1 q; echo
if [ "$q" == "y" ] || [ "$q" == "Y" ]; then
installBluetooth=1
fi
# echo -e "\n"
# ----- Setting up US Locale & Keyboard ---------------------
cont="n"
setupLocale=0
echo -n "Set up US locale and keyboard? ('y' for yes) "
read -n 1 q; echo
if [ "$q" == "y" ] || [ "$q" == "Y" ]; then
setupLocale=1
fi
# echo -e "\n"
# ----- Setup Wifi ------------------------------------------
setupWifi=0
echo -n "Set up wireless adapter? ('y' for yes) "
read -n 1 q; echo
if [ "$q" == "y" ] || [ "$q" == "Y" ]; then
setupWifi=1
cont="n"
while [ "$cont" != "y" ] && [ "$cont" != "Y" ]; do
echo -n "Enter your SSID: "; read ssid
echo -n "Enter your WPA key: "; read wpa
echo -n "Wifi information ok [y/n]? "; read -n 1 cont; echo
done
fi
# echo -e "\n"
# ----- change pi password --------------------------------
cont="n"
changePiPwd=0
echo -n "Change pi user password? ('y' for yes) "
read -n 1 q; echo
if [ "$q" == "y" ] || [ "$q" == "Y" ]; then
changePiPwd=1
while [ "$cont" != "y" ] && [ "$cont" != "Y" ]; do
echo -n "Enter new pi user password: "; read piPassword
echo -n "User information ok [y/n]? "; read -n 1 cont; echo
if [ "$piPassword" == "" ]; then cont="n"; fi
done
fi
# echo -e "\n"
# ----- Setup New user ------------------------------------
cont="n"
setupPrimaryUser=0
echo -n "Set up new user? ('y' for yes) "
read -n 1 q; echo
if [ "$q" == "y" ] || [ "$q" == "Y" ]; then
setupPrimaryUser=1
echo -e "\n\nLet's set up a new primary user..."
while [ "$cont" != "y" ] && [ "$cont" != "Y" ]; do
echo -n "Enter username: "; read user
echo -n "Enter full name: "; read userFullName
echo -n "Enter password: "; read password
echo -n "User information ok [y/n]? "; read -n 1 cont; echo
if [ "$user" == "" ]; then cont="n"; fi
done
fi
# echo -e "\n"
# ----- Set Up file system expansion ---------------------
cont="n"
expandFilesytem=0
echo -n "Expand file system to the whole card? ('y' for yes) "
read -n 1 q; echo
if [ "$q" == "y" ] || [ "$q" == "Y" ]; then
expandFilesystem=1
fi
# echo -e "\n"
# ----- Setup hostname --------------------------------------
cont="n"
setupHostname=0
echo -n "Set up new hostname? ('y' for yes) "
read -n 1 q; echo
if [ "$q" == "y" ] || [ "$q" == "Y" ]; then
setupHostname=1
cont="n"
while [ "$cont" != "y" ] && [ "$cont" != "Y" ]; do
echo -n "Enter new hostname: "; read newHostname
echo -n "Hostname ok [y/n]? "; read -n 1 cont; echo
done
fi
# echo -e "\n"
# ----- Install node.js --------------------------------------
cont="n"
installNode=0
compileNode=0
echo -n "Install node.js? ('y' for yes) "
read -n 1 q; echo
if [ "$q" == "y" ] || [ "$q" == "Y" ]; then
installNode=1
cont="n"
echo -n "Do you want to install node.js from source (compile)? ('y' for yes) "
read -n 1 q; echo
if [ "$q" == "y" ] || [ "$q" == "Y" ]; then
compileNode=1
fi
fi
# echo -e "\n"
#####################################################################################
## DEFAULT CHANGES
#####################################################################################
sudo cp -f files/.bashrc /home/pi # Set bash environment
sudo cp -f files/.nanorc /home/pi # Set bash environment
sudo chown pi:pi /home/pi/.bashrc
sudo chown pi:pi /home/pi/.nanorc
mkdir ~/temp
#####################################################################################
## RERESH SYSTEM WITH APT-GET LIBRARY UPDATE & UPGRADE
#####################################################################################
if [ "$refreshSystem" == "1" ]; then
clear; echo -e "\n\n\n\n\n\n\n\n\n\n"
echo -e " Updating APT-GET libraries and installed packages..."
echo -e "-------------------------------------------------------------------------------------"
sudo apt-get -y -qq update # Update library
sudo apt-get -y -qq upgrade # Upgrade all local libraries
sudo apt-get -y autoremove # removes redundant packages after upgrade
echo -e "\n\nAPT-GET update complete\n\n"
# echo -n "-- Press any key to continue --"; read -n 1 cont; echo
fi
#####################################################################################
## Install Avahi Daemon for zeroconf access (raspberrypi.local)
#####################################################################################
if [ "$installAvahi" == "1" ]; then
clear; echo -e "\n\n\n\n\n\n\n\n\n\n"
echo -e " Installing Avahi..."
echo -e "-------------------------------------------------------------------------------------"
sudo apt-get -y install avahi-daemon
echo -e "\n\nAvahi Daemon Installed...\n\n"
# echo -n "-- Press any key to continue --"; read -n 1 cont; echo
fi
#####################################################################################
## Installing bluetooth tools
#####################################################################################
if [ "$installBluetooth" == "1" ]; then
clear; echo -e "\n\n\n\n\n\n\n\n\n\n"
echo -e " Installing Bluetooth tools..."
echo -e "-------------------------------------------------------------------------------------"
sudo apt-get -y install bluez
sudo apt-get -y install python-gobject
echo -e "\n\nVerify that your bluetooth adapter is displayed below:"
hcitool dev
echo -e "\n\nBluetooth installed...\n\n"
# echo -n "-- Press any key to continue --"; read -n 1 cont; echo
fi
#####################################################################################
## ADJUSTING SYSTEM SETTINGS
#####################################################################################
if [ "$setupLocale" == "1" ]; then
clear; echo -e "\n\n\n\n\n\n\n\n\n\n"
echo -e " Setting US locale and keyboard..."
echo -e "-------------------------------------------------------------------------------------"
sudo cp -f files/locale.gen /etc/locale.gen # Set locale to US
sudo cp -f files/keyboard /etc/default/keyboard # Set keyboard layout to US
echo -e "\n\nUS Locale & Keyboard setup complete\n\n"
# echo -n "-- Press any key to continue --"; read -n 1 cont; echo
fi
#####################################################################################
## SETTING UP WIRELESS NETWORKING
#####################################################################################
if [ "$setupWifi" == "1" ]; then
clear; echo -e "\n\n\n\n\n\n\n\n\n\n"
echo -e " Setting up wireless networking..."
echo -e "-------------------------------------------------------------------------------------"
sudo apt-get -y install wireless-tools # drivers for wifi
sudo apt-get -y install wpasupplicant # Other command for wifi drivers
interface="$(ifconfig -a | grep -i wlan | cut -c1-5)"
if [ "$interface" == "" ]; then
echo "---------------------------------------------------------------------------------"
echo "Your wireless adapter hasn't been detected. You may need to reboot before it"
echo "can be configured by this script."
echo "------------------------ PRESS ANY KEY TO CONTINUE ------------------------------"
read -n 1 q; echo
else
## Grab encoded PSK from SSID and WPA Key
# wpaPsk=$(wpa_passphrase "$ssid" "$wpa" | grep 'psk=[^"]' | tr -d "\tpsk=")
cat files/interfaces | sed -e "s/\#INTERFACE/$interface/" -e "s/\#SSID/$ssid/" -e "s/\#WPA/$wpa/" > ./interfaces
sudo mv -f ./interfaces /etc/network/
sudo ifdown $interface
sudo ifup $interface
echo -e "\n\nWireless Networking setup complete\n\n"
fi
# echo -n "-- Press any key to continue --"; read -n 1 cont; echo
fi
#####################################################################################
## SETTING UP USER ENVIRONMENT
#####################################################################################
if [ "$setupPrimaryUser" == "1" ]; then
clear; echo -e "\n\n\n\n\n\n\n\n\n\n"
echo -e " Setting up new primary user..."
echo -e "-------------------------------------------------------------------------------------"
if [ "$user" != "" ]; then
# Code updated to deprecate below system of
# cat files/userinfo | sed -e "s/\#PASSWORD/$password/" -e "s/\#USERFULLNAME/$userFullName/" > ./userinfo
# echo -e "$password\n$password\n\n\n\n\n\ny\n" > ./userinfo # Creating user
# sudo adduser --home /home/"$user" "$user" < ./userinfo # Creating user
# rm ./userinfo
sudo adduser "$user" --gecos "$userFullName, , , " --disabled-password
echo "$user:$password" | sudo chpasswd
# Configuring user environment
sudo cp -f files/.bashrc /home/"$user"/ # Set bash environment
sudo cp -f files/.nanorc /home/"$user"/ # Set bash environment
sudo chown "$user":"$user" /home/"$user"/.bashrc
sudo chown "$user":"$user" /home/"$user"/.nanorc
# Setting up sudo rights
echo -e "$user ALL=(ALL) NOPASSWD: ALL" > ./"$user"
sudo chown -R root:root ./"$user"
sudo chmod 440 ./"$user"
sudo mv -f ./"$user" /etc/sudoers.d
# Setting up raspi in new user's environment to enable next steps
cd /home/"$user"
sudo git clone https://github.com/fpapleux/raspi # clone git repo into new user home
sudo chown -R "$user":"$user" * # change owner of repo files to new user
echo -e "\n\nUser environment setup complete\n\n"
fi
# echo -n "-- Press any key to continue --"; read -n 1 cont; echo
fi
#####################################################################################
## Changing Pi Password
#####################################################################################
if [ "$changePiPwd" == "1" ]; then
clear; echo -e "\n\n\n\n\n\n\n\n\n\n"
echo -e " Changing Pi Password..."
echo -e "-------------------------------------------------------------------------------------"
echo "pi:$piPassword" | sudo chpasswd
echo -e "\n\npi user passowrd changed...\n\n"
# echo -n "-- Press any key to continue --"; read -n 1 cont; echo
fi
#####################################################################################
## Expand filesystem to the maximum on the card
#####################################################################################
if [ "$expandFilesystem" == "1" ]; then
clear; echo -e "\n\n\n\n\n\n\n\n\n\n"
echo -e " Expanding file system..."
echo -e "-------------------------------------------------------------------------------------"
$HOME/raspi/expand_filesystem.sh
echo -e "\n\nFilesystem expansion complete"
# echo -n "-- Press any key to continue --"; read -n 1 cont; echo
fi
#####################################################################################
## Set up new hostname
## --- Thanks to raspi-config, published under the MIT license
#####################################################################################
if [ "$setupHostname" == "1" ]; then
clear; echo -e "\n\n\n\n\n\n\n\n\n\n"
echo -e " Setting up new host name..."
echo -e "-------------------------------------------------------------------------------------"
currentHostname=`sudo cat /etc/hostname | tr -d " \t\n\r"`
if [ $? -eq 0 ]; then
echo $newHostname > ~/hostname
sudo mv -f ~/hostname /etc
sudo cp /etc/hosts ~
sudo sed -i "s/127.0.1.1.*$currentHostname/127.0.1.1\t$newHostname/g" ~/hosts
sudo mv -f ~/hosts /etc
set HOSTNAME="$newHostname"
fi
echo -e "\n\nHostname setup complete"
# echo -n "-- Press any key to continue --"; read -n 1 cont; echo
fi
#####################################################################################
## Install node.js
#####################################################################################
if [ "$installNode" == "1" ]; then
clear; echo -e "\n\n\n\n\n\n\n\n\n\n"
echo -e " Installing node.js..."
echo -e "-------------------------------------------------------------------------------------"
if [ "$compileNode" == "1" ]; then
cd ~/temp
wget http://nodejs.org/dist/v0.12.2/node-v0.12.2.tar.gz
tar -xvf node-v0.12.2.tar.gz
cd node-v0.12.2
sudo ./configure
sudo make
sudo make install
else
curl -sLs https://apt.adafruit.com/add | sudo bash
sudo apt-get install node
fi
node --version
echo -e "\n\n Node JS install complete -- current version is $(node -v)"
# echo -n "-- Press any key to continue --"; read -n 1 cont; echo
fi
#####################################################################################
## Reboot the machine
#####################################################################################
clear; echo -e "\n\n\n\n\n\n\n\n\n\n"
echo "---------------------------------------------------------------------------------"
echo "Based on the work that was just completed we recommend that you restart your"
echo "machine and log back in using your new user account to continue this process."
echo "------------------------ PRESS ANY KEY TO CONTINUE ------------------------------"
read -n 1 q; echo
sudo shutdown -r now