-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpi-scripts-install-ssd.sh
executable file
·343 lines (307 loc) · 11.5 KB
/
pi-scripts-install-ssd.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
#!/bin/bash
###########################################################
# #
# # # # # # # ##### # # #
# # # # # # # ## # # # # # #
# # # # # # # # # # # # # #
# ## # # ##### ####### # ## #
# # # # # # # # # # # #
# # # # # # # # # # # #
# # # # # # # # ##### # # #
# #
###########################################################
# #
# Modified for WB0SIO pi-build-install. #
# 6-November-2020 by WB0SIO #
# #
###########################################################
DESK=$(printenv | grep DISPLAY)
MYPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
LOGO=${MYPATH}/logo.png
RB=${HOME}/.config/WB0SIO
BASE=${MYPATH}/base.txt
RADIO=${MYPATH}/radio.txt
PATCH=${MYPATH}/patch.txt
FUNCTIONS=${MYPATH}/functions
TEMPCRON=${MYPATH}/cron.tmp
TEMPFSTAB=${MYPATH}/fstab.tmp
CONFIG=${MYPATH}/config.txt
WHO=$(whoami)
VERSION=$(cat ${MYPATH}/changelog | grep version= | sed 's/version=//')
AUTHOR=$(cat ${MYPATH}/changelog | grep author= | sed 's/author=//')
LASTUPDATE=$(cat ${MYPATH}/changelog | grep LastUpdate= | sed 's/LastUpdate=//')
TODAY=$(date +%Y-%m-%d)
export MYPATH LOGO CONFIG
touch ${CONFIG}
FINISH(){
if [ -f "${BASE}" ]; then
rm ${BASE}
fi
if [ -f "${RADIO}" ]; then
rm ${RADIO}
fi
}
trap FINISH EXIT
CLEANUP(){
# Run solar.sh to update the solar condiions data for conky
/home/pi/bin/solar.sh
/home/pi/bin/solarimage.sh
#Remove temp files
rm ${BASE} > /dev/null 2>&1
rm ${RADIO} > /dev/null 2>&1
rm ${PATCH} > /dev/null 2>&1
sudo rm -rf ${HOME}/pi-build/temp > /dev/null 2>&1
sudo apt -y autoremove
# Enter the installation date in ${HOME}/.config/WB0SIO
echo "# The date pi-build-install.sh was executed" >> ${HOME}/.config/WB0SIO
echo "InstallDate=$TODAY" >> ${HOME}/.config/WB0SIO
}
#####################################
#check for display. can't run from SSH
#####################################
if [ -z "${DESK}" ]
then
cat <<EOF
This script cannot be run from an SSH session.
Please boot into the pi's desktop environment,
open the terminal, and run this script again
EOF
exit 0
fi
#####################################
# Check if run before
#####################################
if [ -f "${RB}" ]; then
bash ${MYPATH}/update.sh &
exit
fi
echo "#######################################"
echo "# Updating repository & installing #"
echo "# a few needed items before we begin #"
echo "#######################################"
cd ${MYPATH}
git config --global user.email "[email protected]"
git config --global user.name "lcgreenwald"
cd
if [ ! -d /usr/local/share/applications/ ]; then
sudo mkdir -p /usr/local/share/applications/
fi
sudo apt update
sudo apt upgrade -y
sudo apt install -y bluetooth bluez-cups bluez-obexd
if ! hash yad 2>/dev/null; then
sudo apt install -y yad
fi
if ! hash jq 2>/dev/null; then
sudo apt install -y jq
fi
#####################################
# notice to user
#####################################
cat <<EOF > ${MYPATH}/intro.txt
pi-build-install by $AUTHOR.
Version $VERSION.
Last version update $LASTUPDATE.
This script is installed in ${MYPATH}
This script updates the operating system and then
downloads and installs some required and some optional
utility software.
It will also optionally install the latest version of
KM4ACK's Build-a-Pi and a custom version of KM4ACK's
HotSpot Tools.
Enjoy! 73 de WB0SIO
EOF
INTRO=$(yad --width=600 --height=500 --text-align=center --center --title="Pi Scripts Install" --show-uri \
--image ${LOGO} --window-icon=${LOGO} --image-on-top --separator="|" --item-separator="|" \
--text-info<${MYPATH}/intro.txt \
--button="Continue":2 > /dev/null 2>&1)
BUT=$?
if [ $BUT = 252 ]; then
rm ${MYPATH}/intro.txt
exit
fi
rm ${MYPATH}/intro.txt
#####################################
# Base Apps
#####################################
yad --center --list --checklist --width=700 --height=800 --separator="" \
--image ${LOGO} --column=Check --column=App --column=Description \
--print-column=2 --window-icon=${LOGO} --image-on-top --text-align=center \
--text="<b>Base Applications</b>" --title="Pi-Scripts Install" \
false "DeskPi" "DeskPi enclosure utilities." \
false "Argon" "Argon One m.2 enclosure utilities." \
false "X715" "X715 power supply hat utilities." \
false "Log2ram" "Create a RAM based log folder to reduce SD card wear." \
false "ZramSwap" "Create a RAM based swap file to improve system response." \
false "Locate" "File search utility" \
false "Plank" "Application dock." \
false "Conky" "System Information Display" \
false "Gparted" "Disk Utility Tool" \
false "Samba" "SMB file system" \
false "Webmin" "Web based system manager." \
false "Screensaver" "X Screensavers" \
false "Disks" "Manage Drives and Media" \
false "PiImager" "Raspberry Pi Imager" \
false "Neofetch" "Display Linux system Information In a Terminal" \
false "CommanderPi" "Easy RaspberryPi4 GUI system managment" \
false "RPiMonitor" "Display Linux system Information in a web browser" \
false "Fortune" "Display random quotes" \
false "PiSafe" "Backup or Restore Raspberry Pi devices" \
false "Weather" "Display weather conditions and forecast." \
false "Timeshift" "Linux system backup utility." \
false "Piapps" "The most popular app store for Raspberry Pi computers." \
--button="Exit":1 \
--button="Check All and Continue":3 \
--button="Next":2 > ${BASE}
BUT=$?
if [ $BUT = 252 ] || [ $BUT = 1 ]; then
CLEANUP
exit
fi
if [ $BUT = 3 ]; then
BASEAPPS=(DeskPi Argon X715 Log2ram ZramSwap Locate Plank Samba Webmin Screensaver Cqrprop Disks PiImager Neofetch CommanderPi RPiMonitor Fortune PiSafe Weather Timeshift Conky Gparted Piapps)
for i in "${BASEAPPS[@]}"
do
echo "$i" >> ${BASE}
done
fi
#check if Weather is chosen for install & get info if needed
Weather=$(grep "Weather" ${BASE})
if [ -n "$Weather" ]; then
WEATHER=$(yad --form --center --width 600 --height 300 --separator="|" --item-separator="|" --title="Weather config" \
--image ${LOGO} --window-icon=${LOGO} --image-on-top --text-align=center \
--text "Enter your API Key, Latitude and Longitude below and press Continue." \
--field="API Key" \
--field="Latitude":NUM \
--field="Longitude":NUM \
--field="Longitude Direction":CB \
--field="Units":CB \
"" " |-90..90|.0001|4" " |-180..180|.0001|4" "W|E" "imperial|metric" \
--button="Exit":1 \
--button="Continue":2 )
BUT=$?
if [ ${BUT} = 252 ] || [ ${BUT} = 1 ]; then
CLEANUP
exit
fi
#update settings
APIKEY=$(echo ${WEATHER} | awk -F "|" '{print $1}')
LAT=$(echo ${WEATHER} | awk -F "|" '{print $2}')
LON=$(echo ${WEATHER} | awk -F "|" '{print $3}')
LONDIR=$(echo ${WEATHER} | awk -F "|" '{print $4}')
UNITS=$(echo ${WEATHER} | awk -F "|" '{print $5}')
echo "APIKEY=$APIKEY" >${CONFIG}
echo "LAT=$LAT" >>${CONFIG}
echo "LON=$LON" >>${CONFIG}
echo "LONDIR=$LONDIR" >>${CONFIG}
echo "UNITS=$UNITS" >>${CONFIG}
fi
#####################################
# Install Base Apps
#####################################
source ${FUNCTIONS}/base.function
while read i ; do
$i
done < ${BASE}
#####################################
# Update crontab
#####################################
crontab -l > ${TEMPCRON}
echo "@reboot sleep 30 && /home/pi/bin/solar.sh" >> ${TEMPCRON}
echo "@reboot sleep 35 && /home/pi/bin/solarimage.sh" >> ${TEMPCRON}
echo "@reboot sleep 40 && /home/pi/bin/writegrid.sh" >> ${TEMPCRON}
echo "*/10 * * * * /home/pi/bin/solar.sh" >> ${TEMPCRON}
echo "*/10 * * * * /home/pi/bin/solarimage.sh" >> ${TEMPCRON}
echo "*/3 * * * * /home/pi/bin/writegrid.sh" >> ${TEMPCRON}
#echo "*/1 * * * * /home/pi/bin/writefreq.sh" >> ${TEMPCRON}
echo "00 03 * * 0 /home/pi/bin/install-updates.sh" >> ${TEMPCRON}
echo "00 03 * * * /home/pi/bin/BackupDigitalModeSettings.sh" >> ${TEMPCRON}
crontab ${TEMPCRON}
rm ${TEMPCRON}
#####################################
# Update aliases in .bashrc.
#####################################
sed -i "s/#alias ll='ls -l'/alias ll='ls -l'/" ${HOME}/.bashrc
sed -i "s/#alias la='ls -A'/alias la='ls -la'/" ${HOME}/.bashrc
sed -i "s/#alias l='ls -CF'/alias psgrep='ps -ef|grep -v grep|grep -i '/" ${HOME}/.bashrc
#####################################
# Update swapfile parameters.
#####################################
sudo sed -i 's/CONF_SWAPSIZE=100/#CONF_SWAPSIZE=100/' /etc/dphys-swapfile
sudo sed -i 's/#CONF_SWAPFACTOR=2/CONF_SWAPFACTOR=1/' /etc/dphys-swapfile
#####################################
# Update HamRadio menu items.
#####################################
bash ${MYPATH}/menu-update-ssd.sh
#####################################
# Install WB0SIO versions of desktop, directory, conky and digi-mode files. Misc folders and sym-links.
#####################################
if [ ! -d ${HOME}/bin 2>/dev/null ] ; then
mkdir ${HOME}/bin
fi
if [ ! -d ${HOME}/bin/conky 2>/dev/null ] ; then
mkdir ${HOME}/bin/conky
fi
#cp -f ${HOME}/hotspot-tools2/hstools.desktop ${HOME}/.local/share/applications/hotspot-tools.desktop
cp -f ${MYPATH}/bin/*.sh ${HOME}/bin/
#cp -f ${MYPATH}/conky/get-grid ${HOME}/bin/conky/
#cp -f ${MYPATH}/conky/get-freq ${HOME}/bin/conky/
cp -f ${MYPATH}/desktop_files/* ${HOME}/.local/share/applications/
sed -i 's/update.sh/update-ssd.sh/' ${HOME}/.local/share/applications/psupdate.desktop
cp -rf ${MYPATH}/local/share/* ${HOME}/.local/share/
#cp -rf ${MYPATH}/xlog/* ${HOME}/.xlog/
cp -f ${MYPATH}/config/* ${HOME}/.config/
cp -f ${MYPATH}/conky/conky-noradio-ssd ${HOME}/.conkyrc
if [ ! -d ${HOME}/bin/conky/solardata 2>/dev/null ] ; then
mkdir ${HOME}/bin/conky/solardata
fi
#####################################
# Update fstab and create mount point
#####################################
cat /etc/fstab > ${TEMPFSTAB}
echo " " >> ${TEMPFSTAB}
echo "# <file system> <mount point> <type> <options>" >> ${TEMPFSTAB}
echo "honshu:public /home/public/mounts/honshu/public nfs rw,sync,bg,auto,intr,soft,_netdev,retry=1" >> ${TEMPFSTAB}
sudo cp ${TEMPFSTAB} /etc/fstab
rm ${TEMPFSTAB}
if [ ! -d /home/public/mounts/honshu/public 2>/dev/null ] ; then
mkdir -p /home/public/mounts/honshu/public
fi
#####################################
# Update the locate database.
#####################################
echo "#######################################"
echo "# Updating the locate database. #"
echo "# This may take a minute or two. #"
echo "#######################################"
sudo updatedb
#####################################
# Update Pi-Build/.complete to show .pscomplete.
#####################################
#echo "${MYPATH}/.pscomplete" >> ${HOME}/pi-build/.complete
#####################################
# END CLEANUP
#####################################
CLEANUP
#####################################
#reboot when done
#####################################
cat <<EOF > ${MYPATH}/intro.txt
Pi-Build-Install finished
Reboot Required
If you close this window, you will have to reboot manually.
EOF
INTRO=$(yad --width=600 --height=300 --text-align=center --center --title="Pi Build Install" --show-uri \
--image ${LOGO} --window-icon=${LOGO} --image-on-top --separator="|" --item-separator="|" \
--text-info<${MYPATH}/intro.txt \
--button="Reboot Now":0 \
--button="Exit":1)
BUT=$(echo $?)
if [ $BUT = 0 ]; then
rm ${MYPATH}/intro.txt
echo rebooting
sudo reboot
elif [ $BUT = 1 ]; then
rm ${MYPATH}/intro.txt
exit
fi