-
Notifications
You must be signed in to change notification settings - Fork 71
/
build-a-pi
executable file
·685 lines (611 loc) · 20.8 KB
/
build-a-pi
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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
##################################################################
# #
# # # # # # # ##### # # #
# # # # # # # ## # # # # # #
# # # # # # # # # # # # # #
# ## # # ##### ####### # ## #
# # # # # # # # # # # #
# # # # # # # # # # # #
# # # # # # # # ##### # # #
# #
##################################################################
#20200620
DESK=$(printenv | grep DISPLAY)
MYPATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
LOGO=${MYPATH}/logo.png
RB=${HOME}/.config/KM4ACK
BASE=${MYPATH}/base.txt
ADDITIONAL=${MYPATH}/additional.txt
UTILITY=${MYPATH}/utility.txt
FLSUITE=${MYPATH}/flsuite.txt
CONFIG=${MYPATH}/config
FUNCTIONS=${MYPATH}/functions
TEMPCRON=${MYPATH}/cron.tmp
DIR=${MYPATH}/temp
WHO=$(whoami)
VERSION=$(grep "version=" ${MYPATH}/changelog | sed 's/version=//')
DATE=$(date)
FINISH() {
if [ -f "${BASE}" ]; then
rm ${BASE}
fi
if [ -f "${ADDITIONAL}" ]; then
rm ${ADDITIONAL}
fi
if [ -f "${FLSUITE}" ]; then
rm ${FLSUITE}
fi
if [ -f "${UTILITY}" ]; then
rm ${UTILITY}
fi
}
trap FINISH EXIT
#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
#####################################
# Verify not run as root
#####################################
if [ "$WHO" = 'root' ]; then
yad --form --width=500 --text-align=center --center --title="Build-a-Pi" --text-align=center \
--image ${LOGO} --window-icon=${LOGO} --image-on-top --separator="|" --item-separator="|" \
--text="<b>ROOT DETECTED</b>\rDon't run this script as root. \
Restart the script without sudo" \
--button=gtk-close
exit 1
fi
#####################################
# Old OS Check
#####################################
V_ID=$(grep VERSION_ID /etc/os-release | sed 's/VERSION_ID="//;s/"//')
if [ "$V_ID" -le 10 ]; then
NOTICEPATH=/run/user/$UID
cat <<EOF >${NOTICEPATH}/intro.txt
Build a Pi 3.2.0 and later does not support
RaspiOS Buster or earlier versions of RaspiOS.
You should consider upgrading to RaspiOS 11
(Bullseye). By clicking ok you will be moved
to the last version of Build a Pi (3.1.4) that
supports Pi OS Buster. Please note there are
no plans to update Build a Pi for Buster going
forward. In other words, you are on your own
if it is broke and you are still running Pi OS
10 (Buster).
EOF
INTRO=$(yad --width=600 --height=300 --text-align=center --center --title="Out of Date OS Detected!" --show-uri \
--image ${LOGO} --window-icon=${LOGO} --image-on-top --separator="|" --item-separator="|" \
--text-info \
--button="OK":1 <${NOTICEPATH}/intro.txt \
--button="Exit":2 \
>/dev/null 2>&1)
BUT=$?
echo $BUT
if [ $BUT = 2 ] || [ $BUT = 252 ]; then
exit
fi
rm ${NOTICEPATH}/intro.txt
cd $HOME/pi-build
git checkout buster
bash build-a-pi & exit
fi
#####################################
# end Old OS Check
#####################################
#install YAD & jq as needed
clear
echo
echo
echo "#######################################"
echo "# Updating repository & installing #"
echo "# a few needed items before we begin #"
echo "#######################################"
sudo apt-get update
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
if ! hash bc >/dev/null; then
sudo apt install -y bc
fi
#an issue pops up every now and again concerning xterm.
#link lxterminal to xterm. see https://github.com/km4ack/pi-build/issues/34
sudo ln -s /usr/bin/lxterminal /usr/bin/xterm
#####################################
# Check if run before
#####################################
if [ -f "${RB}" ]; then
bash ${MYPATH}/update &
exit
fi
#####################################
# Check user is pi
#####################################
#This section commented out 12APRIL2022 for testing. Should be removed once testing is complete.
#if [ "$WHO" != 'pi' ]; then
# yad --form --width=500 --text-align=center --center --title="Build-a-Pi" --text-align=center \
# --image ${LOGO} --window-icon=${LOGO} --image-on-top --separator="|" --item-separator="|" \
# --text="<b>USER NAME IS NOT PI</b>\rThis script is designed to be run as the pi user. Please set the user name to pi \
#and try again. You can change the user name after the build is complete but some configuration may not work \
#as expected" \
# --button=gtk-close
# exit 1
#fi
#####################################
# notice to user
#####################################
cat <<EOF >${MYPATH}/intro.txt
This script takes approximately 4 hours to complete
if you choose to install everything. If you find it
helpful please consider a donation to encourage future
development.
https://paypal.me/km4ack
EOF
INTRO=$(yad --width=550 --height=250 --text-align=center --center --title="Build-a-Pi" --show-uri \
--image ${LOGO} --window-icon=${LOGO} --image-on-top --separator="|" --item-separator="|" \
--text-info \
--button="Continue":2 <${MYPATH}/intro.txt \
>/dev/null 2>&1)
BUT=$?
if [ ${BUT} = 252 ]; then
rm ${MYPATH}/intro.txt
exit
fi
rm ${MYPATH}/intro.txt
#####################################
# Create autostart dir
#used to autostart conky at boot
#####################################
mkdir -p ${HOME}/.config/autostart
#####################################
# Get User Call
#####################################
CALL() {
INFO=$(yad --form --width=420 --text-align=center --center --title="Build-a-Pi" \
--image ${LOGO} --window-icon=${LOGO} --image-on-top --separator="|" --item-separator="|" \
--text="<b>version $VERSION</b>" \
--field="Call Sign*" \
--field="<b>* Required</b>":LBL \
--button="Continue":2)
BUT=$?
if [ ${BUT} = 252 ]; then
exit
fi
}
CALL
CALL=$(echo ${INFO} | awk -F "|" '{print $1}')
CALL=${CALL^^}
#Verify call not empty
ATTEMPTS=0
while [ -z "$CALL" ]; do
if [ $ATTEMPTS -eq 3 ]; then
yad --form --width=420 --text-align=center --center --title="Build-a-Pi" --text-align=center \
--image ${LOGO} --window-icon=${LOGO} --image-on-top --separator="|" --item-separator="|" \
--text="<b>Empty callsign after 3 attempts. Quiting!</b>" \
--button=gtk-ok
exit
fi
yad --form --width=420 --text-align=center --center --title="Build-a-Pi" --text-align=center \
--image ${LOGO} --window-icon=${LOGO} --image-on-top --separator="|" --item-separator="|" \
--text="<b>Call Can't be Blank</b>" \
--button=gtk-ok
((ATTEMPTS = ATTEMPTS + 1))
CALL
CALL=$(echo ${INFO} | awk -F "|" '{print $1}')
CALL=${CALL^^}
done
echo "CALL=$CALL" >${CONFIG}
#####################################
# Base Apps
#####################################
yad --center --list --checklist --width=600 --height=600 --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="Build-a-Pi" \
false "HOTSPOT" "Hot Spot Generator for Portable Ops" \
false "HSTOOLS" "Tools to Manage Hot Spot" \
false "GPS" "GPS Software" \
false "GPSUPDATE" "Tool to Manage GPS Devices" \
false "ARDOP" "Modem for HF" \
false "ARDOPGUI" "GUI for ARDOP" \
false "VARA" "VARA Modem - <b>Pi 4 Required</b>" \
false "HAMLIB" "Needed for Rig Control" \
false "DIREWOLF" "Software TNC" \
false "AX25" "Data Link Layer Protocol" \
false "PULSE" "Pulse Audio Control Interface" \
--button="Exit":1 \
--button="Check All and Continue":3 \
--button="Next":2 >${BASE}
BUT=$?
if [ ${BUT} = 252 ] || [ ${BUT} = 1 ]; then
exit
fi
if [ ${BUT} = 3 ]; then
BASEAPPS=(HOTSPOT HSTOOLS GPS ARDOP ARDOPGUI VARA HAMLIB DIREWOLF AX25 PULSE GPSUPDATE)
for i in "${BASEAPPS[@]}"; do
echo "$i" >>${BASE}
done
fi
#If VARA is chosen, make sure we have a Pi 4 32 bit system to work with.
#As of 02OCT2022 the VARA installer only works with the Pi 4.
VARA_CHK=$(grep VARA ${BASE})
if [ -n "$VARA_CHK" ]; then
FREEMEM=$(free -m | grep Mem: | awk '{ print $2 }')
if [ $FREEMEM -lt 1500 ]; then
echo "Not enough memory available"
yad --form --width=500 --text-align=center --center --title="Build-a-Pi" --text-align=center \
--image ${LOGO} --window-icon=${LOGO} --image-on-top --separator="|" --item-separator="|" \
--text="<b>Not enough memory</b>\rVARA requires a Pi 4.\r\rVARA will not be installed during the build." \
--button=gtk-ok
sed -i 's/VARA//;/^$/d' ${BASE}
fi
fi
#check if hotspot is chosen for install & get info if needed
HS=$(grep "HOTSPOT" ${BASE})
if [ -n "$HS" ]; then
HSINFO() {
#unblock wifi
sudo rfkill unblock all >/dev/null 2>&1
#bring wifi up
sudo ifconfig wlan0 up
#LIST=$(sudo iw dev "wlan0" scan ap-force | egrep "^BSS|SSID:" | grep SSID: | sed 's/SSID://' | awk '{ print $1 }')
#LIST=$(echo $LIST | sed 's/ /|/g')
LIST=$(sudo iw dev "wlan0" scan ap-force | sed -ne 's/^.*SSID: \(..*\)/\1/p' | sort | uniq | paste -sd '|')
HSINFO=$(yad --center --form --width=400 --height=400 --separator="|" --item-separator="|" \
--image ${LOGO} --column=Check --column=App --column=Description \
--window-icon=${LOGO} --image-on-top --text-align=center \
--text="<b>HotSpot Information\r\rPlease enter the information\rbelow \
for the Hot Spot\r</b>NOTE: The last field is the password for the hotspot. You will use this password to \
connect to your Pi when it is in hotspot mode <b>This password can only contain letters and numbers</b>" \
--title="Build-a-Pi" \
--field="Home Wifi SSID":CB "$LIST" \
--field="Home Wifi Password":H \
--field="Hot Spot Password" \
--button="Exit":1 \
--button="Continue":2 \
--button="Refresh Wifi":3)
BUT=$?
if [ ${BUT} = 3 ]; then
HSINFO #Call HSINFO function
fi
if [ ${BUT} = 252 ] || [ ${BUT} = 1 ]; then
exit
fi
#}
#HSINFO
#fi
SHACKSSID=$(echo $HSINFO | awk -F "|" '{print $1}')
SHACKPASS=$(echo $HSINFO | awk -F "|" '{print $2}')
HSPASS=$(echo $HSINFO | awk -F "|" '{print $3}')
#Check password length
if [ -n "$HS" ]; then
COUNT=${#HSPASS}
if [ ${COUNT} -lt 8 ]; then
yad --center --form --width=300 --height=200 --separator="|" \
--image ${LOGO} --window-icon=${LOGO} --image-on-top --text-align=center \
--text="<b>Hotspot password has to be 8-63 characters</b>" --title="Build-a-Pi" \
--button=gtk-ok
HSINFO
fi
fi
}
HSINFO
fi
echo "SHACKSSID=$SHACKSSID" >>${CONFIG}
echo "SHACKPASS=\"$SHACKPASS\"" >>${CONFIG}
echo "HSPASS=\"$HSPASS\"" >>${CONFIG}
###################################
#CHECK IF GPS IS CHOSEN TO INSTALL#
###################################
GPSINSTALL=$(cat ${BASE} | grep GPS)
if [ -n "${GPSINSTALL}" ]; then
yad --center --height="300" --width="300" --form --separator="|" --item-separator="|" --title="GPS" \
--image ${LOGO} --window-icon=${LOGO} --image-on-top \
--text="\r\r\r\r\r<b><big>Connect your GPS to the pi</big></b>" \
--button="Continue":2
BUT=$?
USB=$(ls /dev/serial/by-id)
USB=$(echo "NONE $USB") #see https://github.com/km4ack/pi-build/issues/293
USB=$(echo $USB | sed "s/\s/|/g")
GPS=$(yad --center --height="600" --width="300" --form --separator="|" --item-separator="|" --title="GPS" \
--image ${LOGO} --window-icon=${LOGO} --image-on-top \
--text="Choose Your GPS" \
--field="GPS":CB "$USB")
BUT=$?
if [ ${BUT} = 252 ] || [ ${BUT} = 1 ]; then
echo exiting
exit
fi
GPS=$(echo ${GPS} | awk -F "|" '{print $1}')
GPS=/dev/serial/by-id/${GPS}
echo "GPS=${GPS}" >>${CONFIG}
fi
#####################################
# FLSUITE
#####################################
yad --center --list --checklist --width=600 --height=600 --separator="" \
--image ${LOGO} --column=Check --column=App --column=Description \
--print-column=2 --window-icon=${LOGO} --image-on-top --text-align=center \
--text="<b>FLDIGI Suite</b>" --title="Build-a-Pi" \
false "FLRIG" "Rig Contol GUI" \
false "FLDIGI" "Digital Software" \
false "FLAMP" "File Transfer Program" \
false "FLNET" "Net Control Software" \
false "FLMSG" "Forms Manager" \
false "FLWRAP" "File Encapsulation" \
--button="Exit":1 \
--button="Check All and Continue":3 \
--button="Next":2 >${FLSUITE}
BUT=$?
if [ ${BUT} = 252 ] || [ ${BUT} = 1 ]; then
exit
fi
if [ ${BUT} = 3 ]; then
FLAPPS=(FLRIG FLDIGI FLAMP FLNET FLMSG FLWRAP)
for i in "${FLAPPS[@]}"; do
echo "$i" >>${FLSUITE}
done
fi
#####################################
# Ham Apps
#####################################
yad --center --list --checklist --width=600 --height=600 --separator="" \
--image ${LOGO} --column=Check --column=App --column=Description \
--print-column=2 --window-icon=${LOGO} --image-on-top --text-align=center \
--text="<b>Ham Applications</b>" --title="Build-a-Pi" \
false "CONKY" "System Information Display" \
false "PI-APRS" "APRS Message Application" \
false "CHIRP" "Program Radios" \
false "GARIM" "File Transfer Program" \
false "PAT" "Radio Email Application" \
false "PAT-MENU" "Control for Pat Winlink" \
false "JS8CALL" "Weak Signal Digital Mode Software" \
false "M0IAX" "Tools for JS8Call Messages" \
false "WSJTX" "Weak Signal Digital Mode Software" \
false "PYQSO" "Logging Software" \
false "HAMRS" "Logging Software" \
false "CQRLOG" "Logging Software" \
false "EES" "KM4ACK Emergency Email Server" \
false "QSSTV" "Slow Scan TV" \
false "GRIDTRACKER" "Track Grids in WSJTX" \
false "HAMCLOCK" "Clock for Ham Radio Ops" \
false "PROPAGATION" "Propagation Prediction Software" \
false "YAAC" "Yet Another APRS Client" \
false "XASTIR" "APRS Client" \
false "GPREDICT" "Satellite Tracking" \
false "TQSL" "LOTW Software" \
false "GRIDCALC" "Grid Calculation Software" \
false "REPEAT" "Repeater Directory" \
--button="Exit":1 \
--button="Check All and Continue":3 \
--button="Next":2 >${ADDITIONAL}
BUT=$?
if [ ${BUT} = 252 ] || [ ${BUT} = 1 ]; then
exit
fi
if [ ${BUT} = 3 ]; then
ADDAPPS=(CONKY PI-APRS CHIRP GARIM VARIM PAT PAT-MENU JS8CALL M0IAX WSJTX PYQSO
HAMRS EES QSSTV GRIDTRACKER HAMCLOCK PROPAGATION YAAC XASTIR GPREDICT TQSL
GRIDCALC CQRLOG REPEAT)
for i in "${ADDAPPS[@]}"; do
echo "$i" >>${ADDITIONAL}
done
fi
#check if hamclock is being installed
HCCHECK=$(grep "HAMCLOCK" ${ADDITIONAL})
if [ -n "$HCCHECK" ]; then
HC=$(yad --form --width=420 --text-align=center --center --title="Build-a-Pi" \
--image ${LOGO} --window-icon=${LOGO} --image-on-top --separator="|" --item-separator="|" \
--text="<b>version $VERSION</b>" \
--field="Ham Clock Size":CB "SMALL|LARGE" \
--button="Continue":2)
HC=$(echo $HC | awk -F "|" '{print $1}')
sed -i 's/HAMCLOCK//' ${ADDITIONAL}
echo $HC >>${ADDITIONAL}
fi
PATCHECK=$(grep "PAT" ${ADDITIONAL})
if [ -n "$PATCHECK" ]; then
INFO=$(yad --form --width=420 --text-align=center --center --title="Build-a-Pi" \
--image ${LOGO} --window-icon=${LOGO} --image-on-top --separator="|" --item-separator="|" \
--text="<b>version $VERSION</b>" \
--field="Six Character Grid Square" \
--field="Winlink Password":H \
--field="<b>Password is case sensitive</b>":LBL \
--button="Continue":2)
GRID=$(echo ${INFO} | awk -F "|" '{print $1}')
GRID=${GRID^^}
WL2KPASS=$(echo ${INFO} | awk -F "|" '{print $2}')
echo "GRID=$GRID" >>${CONFIG}
echo "WL2KPASS=\"$WL2KPASS\"" >>${CONFIG}
fi
#####################################
# Utilities
#####################################
yad --center --list --checklist --width=600 --height=600 --separator="" \
--image ${LOGO} --column=Check --column=App --column=Description \
--print-column=2 --window-icon=${LOGO} --image-on-top --text-align=center \
--text="<b>Utilities</b>" --title="Build-a-Pi" \
false "DIPOLE" "Dipole Calculator" \
false "PACKETSEARCH" "Winlink Packet Tool" \
false "CALLSIGN" "Call sign lookup" \
false "TEMPCONVERT" "Temperature Converter" \
false "HDOCS" "Reference Materials PDFs" \
false "GPARTED" "Disk Utility Tool" \
false "SHOWLOG" "Log file viewer" \
false "PISTATS" "Pi3/4 Stats Monitor" \
false "TELNET" "Telnet Protocol" \
false "PITERM" "piQtTermTCP Terminal Program" \
false "QTSOUND" "piQtSoundModem" \
false "SECURITY" "File Encryption Software" \
false "YGATE" "Yaesu APRS Software" \
false "BPQ" "LinBPQ Software" \
false "BATT" "Battery Test Script" \
false "VNC" "VNC Client Application" \
false "XYGRIB" "Grib File Viewer" \
--button="Exit":1 \
--button="Check All and Continue":3 \
--button="Install Selected":2 >${UTILITY}
BUT=$?
if [ ${BUT} = 252 ] || [ ${BUT} = 1 ]; then
exit
fi
if [ ${BUT} = 3 ]; then
UTILAPPS=(DIPOLE PACKETSEARCH CALLSIGN TEMPCONVERT HDOCS GPARTED SHOWLOG PISTATS TELNET PITERM QTSOUND SECURITY YGATE BPQ BATT VNC XYGRIB)
for i in "${UTILAPPS[@]}"; do
echo "$i" >>${UTILITY}
done
fi
#backup crontab
crontab -l >$TEMPCRON
echo "@reboot sleep 10 && export DISPLAY=:0 && ${MYPATH}/.complete" >>$TEMPCRON
${MYPATH}/.funfacts &
#upgrade the system
sudo apt-get -y upgrade
sudo apt -y full-upgrade
#fix issue 254 05JULY2021
sudo sed -i 's/#hdmi_force_hotplug=1/hdmi_force_hotplug=1/' config.txt
#set wallpaper
#fix issue 193
sudo cp $HOME/pi-build/bap-wallpaper.jpg /usr/share/rpd-wallpaper/
pcmanfm --set-wallpaper /usr/share/rpd-wallpaper/bap-wallpaper.jpg
mkdir -p ${DIR} 2>/dev/null
#add virtual sound card link for pulse audio
cd ${DIR} || ! echo "Failure"
cat >tempsound <<EOF
pcm.pulse {
type pulse
}
ctl.pulse {
type pulse
}
EOF
sudo chown root:root tempsound
sudo mv tempsound /etc/asound.conf
#mod sound card for Buster May 2020
#so it will always load as card #2
cd ${DIR} || ! echo "Failure"
cat >tempsound <<EOF
#Internal sound
options snd-bcm2835 index=0
#USB soundcard
options snd-usb-audio index=3
EOF
sudo chown root:root tempsound
sudo mv tempsound /etc/modprobe.d/alsa.conf
#install ham radio menu
sudo apt-get install -y extra-xdg-menus
#setup bin dir and put in path
mkdir -p ${HOME}/bin
echo "export PATH=$PATH:${HOME}/bin" >>${HOME}/.bashrc
#set update script to exec
chmod +x ${MYPATH}/update ${MYPATH}/build-a-pi
#create build-a-pi menu item
cd ${MYPATH} || ! echo "Failure"
cat >build-a-pi.desktop <<EOF
[Desktop Entry]
Name=Build-a-Pi
GenericName=KM4ACK Build-a-Pi
Comment=Build-a-Pi App Manager
Exec=${MYPATH}/update
Icon=${MYPATH}/logo.png
Terminal=true
Type=Application
Categories=Settings;DesktopSettings;GTK;X-LXDE-Settings;
EOF
sudo mv build-a-pi.desktop /usr/share/applications/
#create repair-bap tool
cat <<EOF > /run/user/$UID/repair-bap
#!/bin/bash
if [ ! -f $HOME/pi-build/update ]; then
echo "################################"
echo "# BAP update tool not found. #"
echo "# Repairing, please stand by #"
echo "################################"
cd $HOME
git clone https://github.com/km4ack/pi-build.git || echo "Could not connect to Github. Check your internet and try again"
echo "Repair complete. Run the Build a Pi update tool using the shortcut in the Pi menu"
else
clear;echo;echo
echo "Update tool is present on the system."
fi
EOF
chmod +x /run/user/$UID/repair-bap
sudo mv /run/user/$UID/repair-bap /usr/local/bin/
#####################################
# Install Base Apps
#####################################
touch ${RB}
echo "INITIAL=\"build date $DATE version $VERSION\"" >> ${RB}
source ${FUNCTIONS}/base.function
while read i; do
$i
done <${BASE}
#####################################
# Install FLSUITE
#####################################
source ${FUNCTIONS}/flsuite.function
#perform memory increase if needed
CHECKFL="${MYPATH}/flsuite.txt"
if [ -s "$CHECKFL" ]; then
FLSTART
fi
touch ${RB}
while read i; do
$i
done <${FLSUITE}
#Perform memory reset if needed
if [ -s "$CHECKFL" ]; then
FLSTOP
fi
#####################################
# Install ADDITIONAL Apps
#####################################
source ${FUNCTIONS}/additional.function
while read i; do
$i
done <${ADDITIONAL}
#####################################
# Install KM4ACK Utilites
#####################################
source ${FUNCTIONS}/utility.function
while read i; do
$i
done <${UTILITY}
#create new menu subcategories. One for FLDIGI Suite and
#one for Build a Pi.
bash ${HOME}/pi-build/menu-update
#####################################
# END CLEANUP
#####################################
#Remove temp files
rm ${BASE} ${ADDITIONAL} ${UTILITY} ${FLSUITE} >/dev/null 2>&1
rm -rf ${DIR} >/dev/null 2>&1
sudo apt -y autoremove > /dev/null 2>&1
#remove libham (rigctl) installed from apt
#since it conflicts with hamlib installed from source
sudo apt purge -y libhamlib4
#restore crontab
crontab ${TEMPCRON}
rm ${TEMPCRON}
echo "WE ARE ALL DONE HERE. If you close this window, you will have to reboot manually."
#reboot when done
yad --width=400 --height=200 --title="Reboot" --image ${LOGO} \
--text-align=center --skip-taskbar --image-on-top \
--wrap --window-icon=${LOGO} \
--undecorated --text="<big><big><big><b>Build Finished \rReboot Required</b></big></big></big>\r\r" \
--button="Reboot Now":0 \
--button="Exit":1
BUT=$(echo $?)
if [ ${BUT} = 0 ]; then
echo rebooting
sudo reboot
elif [ ${BUT} = 1 ]; then
exit
fi