-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimageBuild.sh
executable file
·217 lines (181 loc) · 4.9 KB
/
imageBuild.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
#!/bin/bash
#declare a list of config archives we prepared earlier
configFiles="google_chrome_config.tar.gz desktop_config.tar.gz xconfig.tar.gz rootFM.tar.gz bar.tar.gz"
piwiz="piwiz.tar.gz"
flows="node_red_root_config.tar.gz"
rootRed="node_red_root_config.tar.gz"
#declare a list of npm packages we want to dump into the ~/.node-red folder
nodePackages=\
"node-red-contrib-camerapi node-red-node-pi-neopixel node-red-node-pisrf\
node-red-dashboard node-red-contrib-oled\
node-red-contrib-bme280 node-red-contrib-cpu node-red-contrib-hostip\
node-red-node-ping node-red-contrib-thingspeak42\
node-red-contrib-easybotics-air-quality"
#some flags to set which configuration we'll do, most are true by default
verbose=false
configCopy=false
node=false
ledMatrix=false
wifi=false
piwizFlag=false
bootResizeFlag=false
interfaceFlag=false
piwizBinFlag=false
while getopts "vcnmwprib" opt;
do
case $opt in
v)
echo "enabling verbosity" >&2
verbose=true
;;
c)
if $verbose; then echo "enabling easybotics configs for chrome ect" >&2
fi
configCopy=true
;;
n)
if $verbose; then echo "installing node-red nodes and sensor libraries" >&2
fi
node=true
;;
m)
if $verbose; then echo "installing led-matrix libraries and nodes" >&2
fi
ledMatrix=true
;;
w)
if $verbose; then echo "appending default wifi connection" >&2
fi
wifi=true
;;
p)
if $verbose; then echo "enabling the user-friendly autostart service" >&2
fi
piwizFlag=true
;;
r)
if $verbose; then echo "enabling image expansion on reboot" >&2
fi
bootResizeFlag=true
piwizFlag=true
piwizBinFlag=true
;;
i)
if $verbose; then echo "enabling hardware interfaces" >&2
fi
interfaceFlag=true
;;
b)
if $verbose; then echo "replacing piwiz binary with cut one" >&2
fi
piwizBinFlag=true
;;
\?)
echo "invalid option: -$OPTARG" >&2
;;
esac
done
read -p "Would you like to update packages before starting (recommended) Y/N" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
sudo apt-mark hold raspberrypi-kernel
sudo apt-get update -y
sudo apt-get upgrade -y --fix-missing
sudo apt-get install -y npm
sudo apt-get install -y xscreensaver
sudo apt-get install -y python-games
sudo apt-get install -y ntfs-3g
sudo npm install npm@latest --unsafe-perm -g
fi
if $configCopy
then
#force hdmi audio
sudo amixer cset numid=3 2
#loop over the archives, curl each one and pipe it into tar to unpack them
for i in $configFiles
do
echo "downloading and unpacking $i"
sudo tar -xzf $i -C /
done
#give ownership of root settings for node-red..
sudo chown pi /root/.node-red/settings.js
#install imagemagick
sudo apt-get update
sudo apt-get install -y imagemagick
#loop over wallpapers and super-impose t3 logo
for i in /usr/share/rpd-wallpaper/*.jpg
do
echo "imposing wallpaper on: $i"
sudo composite placeholder.png $i -alpha Set $i
done
fi
if $piwizFlag
then
sudo tar -xzf piwiz.tar.gz -C /
fi
if $piwizBinFLag
then
mkdir /home/pi/piwiz
tar -xzf piwiz_stand.tar.gz -C /home/pi/
location=/usr/bin/piwiz
sudo mv $location $location.old
sudo ln -s /home/pi/.piwiz/run.sh $location
chmod +x /home/pi/.piwiz/run.sh
fi
if $ledMatrix
then
#TODO: setup icons and menu items
echo "installing node-red stuff"
#setup node-red autostart
sudo systemctl enable nodered.service
sudo npm config set unsafe-perm true
npm i --save --prefix /home/pi/.node-red node-red-contrib-easybotics-led-matrix
d=/lib/systemd/system/nodered.service && sudo sed "s/User=pi/User=root/;s/Group=pi/Group=root/" $d > tmp && sudo mv -f tmp $d
# d=/root/.node-red/settings.js && sudo sed "/.*userDir:*./c\userDir: '\/home\/pi\/.node-red\/'," $d > tmp && sudo mv -f tmp $d
d=/boot/config.txt && sudo sed "/.*dtparam=audio=on*./c\dtparam=audio=off" $d > tmp && sudo cp -f tmp $d
sudo tar -xzf $flows -C /
sudo tar -xzf $rootRed -C /
fi
if $node
then
echo "install node-red and nodejs"
bash node-install-script.sh
echo "presetup, neopixel and dht"
#neopixel setup
curl -sS get.pimoroni.com/unicornhat | bash
#dht setup
bash akil_dht.sh
npm update --save --prefix /home/pi/.node-red
#loop over the npm packages, install each one in the ~/.node-red
for i in $nodePackages
do
echo "installing $i"
npm i --save --prefix /home/pi/.node-red $i
done
fi
if $wifi
then
echo "setting up a wifi connection : rpi"
sudo echo 'network={
ssid="rpi"
psk="raspberry"
key_mgmt=WPA-PSK
}'| sudo tee -a /etc/wpa_supplicant/wpa_supplicant.conf
fi
if $interfaceFlag
then
echo "enabling interfaces"
sudo raspi-config nonint do_camera 0
sudo raspi-config nonint do_i2c 0
sudo raspi-config nonint do_serial 2
sudo raspi-config nonint do_ssh 1
sudo raspi-config nonint do_resolution 2 27
echo "enabled interfaces"
fi
read -p "Would you like to reboot now (recommended) Y/N" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
sudo reboot
fi