-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpre-image
executable file
·241 lines (184 loc) · 9.03 KB
/
pre-image
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
#!/bin/bash
clear; echo -e "\n\n\n\n\n\n\n\n\n\n"
echo -e "-------------------------------------------------------------------------------------"
echo -e "| Initializing new raspi image |"
echo -e "-------------------------------------------------------------------------------------"
# ----- Refresh System --------------------------------------
refreshSystem=1
# ----- Install NANO configurations -------------------------
installNano=1
# ----- Install Avahi Zeroconf ------------------------------
installAvahi=1
# ----- Install Bluetooth suite -----------------------------
installBluetooth=1
# ----- Setting up US Locale & Keyboard ---------------------
setupLocale=1
# ----- change pi password --------------------------------
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
echo -e "\n\n"
# ----- Setup New user ------------------------------------
setupPrimaryUser=1
cont="n"
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
echo -e "\n\n"
# ----- Install node.js --------------------------------------
installNode=1
# ----- Free Serial Port from console use --------------------------------------
freeSerialPort=1
#####################################################################################
## DEFAULT CHANGES
#####################################################################################
sudo cp -f files/.bashrc /home/pi # Set bash environment
sudo chown pi:pi /home/pi/.bashrc
sudo mkdir /usr/local/bin
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"
fi
#####################################################################################
## Install Nano configuration
#####################################################################################
if [ "$installNano" == "1" ]; then
clear; echo -e "\n\n\n\n\n\n\n\n\n\n"
echo -e " Installing Nano Configuration..."
echo -e "-------------------------------------------------------------------------------------"
sudo cp -f files/.nanorc /home/pi
sudo chown pi:pi /home/pi/.nanorc
sudo cp files/nanofiles/* /usr/share/nano
echo -e "\n\nAvahi Daemon Installed...\n\n"
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"
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"
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"
fi
#####################################################################################
## Free Serial Port
#####################################################################################
if [ "$freeSerialPort" == "1" ]; then
clear; echo -e "\n\n\n\n\n\n\n\n\n\n"
echo -e " Freeing serial port from console use, to enable GPIO..."
echo -e "-------------------------------------------------------------------------------------"
sudo mv /boot/cmdline.txt /boot/cmdline.txt.bk
sudo cp files/cmdlines.txt /boot/
sudo chown "root":"root" /boot/cmdline.txt
sudo mv /etc/inittab /etc/inittab.bk
sudo cp files/inittab /etc/
sudo chown "root":"root" /etc/inittab
echo -e "\n\n Serial port freed... on next reboot"
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
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"
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 "-------------------------------------------------------------------------------------"
curl -sLS https://deb.nodesource.com/setup_4.x | sudo bash
sudo apt-get install -y build-essential python-rpi.gpio nodejs
sudo mkdir /usr/local/bin
sudo ln -s /usr/bin/nodejs /usr/local/bin/node
echo -e "\n\n Node JS install complete -- current version is $(node -v)"
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