forked from ronnyzhao/mosbuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mosbuild_worker.sh
1329 lines (1156 loc) · 36.3 KB
/
mosbuild_worker.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
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
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# moOde OS Image Builder (C) 2017 Koda59
#
# This Program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This Program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# 2017-12-08 TC v1.0 adapted Koda59 original script
# 2017-12-17 Koda59 v1.1
# - fix waitForRc time when apt command just after
# - fix force apt-get using IPv4 when proxy set (apt issue)
# 2017-12-20 Koda59 v2.0 add method without USB SD Card reader (all from cuurent SD - fresh Raspbian)
# 2017-12-23 Koda59 v2.1 take control of Act LED during build
# 2017-12-24 Koda59 v2.11
# - add total time to build to the mosbuild.log
# - don't clean mosbuild directory in cancelBuild to enable resume after reboot
# 2018-01-19 TC v2.2
# - simplified and adapted
# - split COMP_C1_C9 into C1_C7 folowwed by C8_C9 because of repo fails in C8
# - use single squeezelite binary in COMPONENT 5
# - reset dir permissions for var local in STEP 8
# 2018-04-02 TC v2.4
# - sync with Build Recipe ver
# - set permissions for localui.service in STEP 8
# - specify Linux kernel ver and git hash in STEP 11
# - add echo "y" to rpi-update in STEP 11, reqd for prompt in 4.14.y branch
# - add apt-get clean to STEP 11
# - bump to MPD 0.20.18 in STEP 6
# - bump to upmpdcli-code-1.2.16 in COMPONENT 6 for Tidal fixes
# - bump to Bluetooth 5.49 in STEP 4
# - use local libupnppsamples-code sources in COMPONENT 6
# - remove djmount in COMPONENT 1 and /mnt/UPNP in STEP 7
# - set time zone to America/Detroit in STEP 2
# - add apt-get update in STEP 3B for robustness
# 2018-07-11 v2.5
# - Use BlueZ-master-4e926f8.zip in STEP 4
# - Use bluez-alsa-master-88aefee.zip in STEP 4
# - Add header to default bluealsa.service file in STEP 4
# - Add -y to apt-get autoremove in STEP 6
# - Bump to WiringPi 2.46 in STEP 5
# - Set 0755 perm on home/pi/*.sh and *.php
# - add mpc update to Final Cleanup
# - add systemctl set-default multi-user.target to STEP 3A
#
VER="v2.5"
# check environment
[[ $EUID -ne 0 ]] && { echo "*** You must be root to run the script! ***" ; exit 1 ; } ;
# Wait a bit to be sure rc.local is not starting too fast
waitForRc () {
TIMESTAMP=$(date)
echo "** "$TIMESTAMP
sleep $1
}
cancelBuild () {
if [ $# -gt 0 ] ; then
echo "$1"
fi
echo "** Error: image build exited"
echo "** Error: reboot to resume the build"
# cd /home/pi
# rm -rf mosbuild 2> /dev/null
# rm -f *.zip 2> /dev/null
#### Power off Act LED
echo 0 >/sys/class/leds/led0/brightness
sleep 1
#### Now we are going reset to default control ACT LED
echo mmc0 >/sys/class/leds/led0/trigger
sleep 1
exit 1
}
loadProperties () {
local MOSBUILD_PROP=/home/pi/mosbuild/mosbuild.properties
if [ -f $MOSBUILD_PROP ] ; then
. $MOSBUILD_PROP
else
cancelBuild "** Error: unable to find properties file"
fi
}
STEP_2 () {
waitForRc 10
cd $MOSBUILD_DIR
timedatectl set-timezone "America/Detroit"
if [ -z "$DIRECT" ] ; then
echo
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// STEP 2 - Expand the root partition to 3GB"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo
else
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// STEP 2 - Direct build so no need to expand Root partition"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo
sed -i "s/raspberry.*//" /etc/hosts
fi
local MOODE_REL_ZIP=`echo $MOODE_REL | awk -F"/" '{ print $NF }'`
echo "** Change password for user pi to moodeaudio"
echo "pi:moodeaudio" | chpasswd
if [ $? -ne 0 ] ; then
cancelBuild "** Error: password change failed"
fi
echo "** Download latest moOde release"
wget -q $MOODE_REL
if [ $? -ne 0 ] ; then
cancelBuild "** Error: download failed"
fi
echo "** Unzip release"
unzip -o -q $MOODE_REL_ZIP
if [ $? -ne 0 ] ; then
cancelBuild "** Error: unzip failed"
fi
rm -f $MOODE_REL_ZIP
if [ -z "$DIRECT" ] || [ `df -k --output=size / | tail -1` -lt 2500000 ] ; then
echo "** Expand SDCard to 3GB"
cp ./rel-stretch/www/command/resizefs.sh ./
chmod 0755 resizefs.sh
sed -i "/PART_END=/c\PART_END=+3000M" ./resizefs.sh
./resizefs.sh start
fi
echo "** Install boot/config.txt"
cp ./rel-stretch/boot/config.txt.default /boot/config.txt
if [ -z "$DIRECT" ] ; then
echo "** Cleanup"
rm -f resizefs.sh
fi
echo "** Reboot 1"
echo "3A" > $MOSBUILD_STEP
sync
reboot
}
STEP_3A () {
waitForRc 30
cd $MOSBUILD_DIR
echo
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// STEP 3A - Install core packages"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo
echo "** Basic optimizations"
dphys-swapfile swapoff
update-rc.d dphys-swapfile remove
rm -f /var/swap
systemctl disable cron.service
systemctl enable rpcbind
systemctl set-default multi-user.target
DEBIAN_FRONTEND=noninteractive apt-get -y purge triggerhappy
if [ $? -ne 0 ] ; then
dpkg --configure -a
cancelBuild "** Error: unable to purge triggerhappy"
fi
if [ -z "$http_proxy" ] ; then
echo "** No proxy configured"
else
echo "** Configuring proxy for Internet access"
echo "Acquire::http::Proxy \"$http_proxy\";" > /etc/apt/apt.conf.d/10proxy
echo "Acquire::ForceIPv4 \"true\";" > /etc/apt/apt.conf.d/99force-ipv4
fi
echo "** Update Raspbian package list"
DEBIAN_FRONTEND=noninteractive apt-get update
if [ $? -ne 0 ] ; then
cancelBuild "** Error: update failed"
fi
echo "** Upgrading Raspbian installed packages to latest available"
DEBIAN_FRONTEND=noninteractive apt-get -y upgrade
if [ $? -ne 0 ] ; then
cancelBuild "** Error: upgrade failed"
fi
echo "** Reboot 2"
echo "3B-4" > $MOSBUILD_STEP
sync
reboot
}
STEP_3B_4 () {
waitForRc 30
cd $MOSBUILD_DIR
echo
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// STEP 3B - Install core packages"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo
echo "** Refresh Raspbian package list"
DEBIAN_FRONTEND=noninteractive apt-get update
if [ $? -ne 0 ] ; then
cancelBuild "** Error: refresh failed"
fi
echo "** Install core packages"
DEBIAN_FRONTEND=noninteractive apt-get -y install rpi-update php-fpm nginx sqlite3 php-sqlite3 memcached php-memcache mpc \
bs2b-ladspa libbs2b0 libasound2-plugin-equal telnet automake sysstat squashfs-tools tcpdump shellinabox \
samba smbclient udisks-glue ntfs-3g exfat-fuse git inotify-tools libav-tools avahi-utils
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Install failed"
fi
echo "** Disable shellinabox"
systemctl disable shellinabox
echo
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// STEP 4 - Install enhanced networking"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo
echo "** Install Host AP Mode packages"
DEBIAN_FRONTEND=noninteractive apt-get -y install dnsmasq hostapd
if [ $? -ne 0 ] ; then
cancelBuild "** Error: install failed"
fi
echo "** Disable hostapd and dnsmasq services"
systemctl daemon-reload
systemctl disable hostapd
systemctl disable dnsmasq
echo "** Install Bluetooth packages"
DEBIAN_FRONTEND=noninteractive apt-get -y install bluez-firmware pi-bluetooth \
dh-autoreconf expect libdbus-1-dev libortp-dev libbluetooth-dev libasound2-dev \
libusb-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev libsbc1 libsbc-dev
if [ $? -ne 0 ] ; then
cancelBuild "** Error: install failed"
fi
echo "** Compile bluez"
# Compile bluez 5.49
# 2018-05-02 commit 4e926f8e3ef2e3321f9b169db54ec256d9b41207
cp ./rel-stretch/other/bluetooth/BlueZ-master-4e926f8.zip ./
unzip BlueZ-master-4e926f8.zip
cd BlueZ-master
autoreconf --install
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-library
make
make install
cd ..
rm -rf ./BlueZ-master
rm ./BlueZ-master-4e926f8.zip
echo "** Delete symlink and bin for old bluetoothd"
rm /usr/sbin/bluetoothd
rm -rf /usr/lib/bluetooth
echo "** Create symlink for new bluetoothd"
ln -s /usr/libexec/bluetooth/bluetoothd /usr/sbin/bluetoothd
echo "** Compile bluez-alsa"
# Compile bluealsa 1.2.0
# 2018-04-16 commit 88aefeea56b7ea20668796c2c7a8312bf595eef4
cp ./rel-stretch/other/bluetooth/bluez-alsa-master-88aefee.zip ./
unzip bluez-alsa-master-88aefee.zip
echo "Ignore warnings from autoreconf and configure"
cd bluez-alsa-master
autoreconf --install
mkdir build
cd build
../configure --disable-hcitop --with-alsaplugindir=/usr/lib/arm-linux-gnueabihf/alsa-lib
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Configure failed"
fi
make
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Make failed"
fi
make install
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Make install failed"
fi
cd ../..
rm -rf ./bluez-alsa-master
rm ./bluez-alsa-master-88aefee.zip
echo "** Check for default bluealsa.service file"
if [ ! -f /lib/systemd/system/bluealsa.service ] ; then
echo "** Creating default bluealsa.service file"
echo "#" > /lib/systemd/system/bluealsa.service
echo "# Created by Moode OS Builder" >> /lib/systemd/system/bluealsa.service
echo "# The corresponfing file in /etc/systemd/system takes precidence" >> /lib/systemd/system/bluealsa.service
echo "#" >> /lib/systemd/system/bluealsa.service
echo "[Unit]" >> /lib/systemd/system/bluealsa.service
echo "Description=BluezAlsa proxy" >> /lib/systemd/system/bluealsa.service
echo "Requires=bluetooth.service" >> /lib/systemd/system/bluealsa.service
echo "After=bluetooth.service" >> /lib/systemd/system/bluealsa.service
echo >> /lib/systemd/system/bluealsa.service
echo "[Service]" >> /lib/systemd/system/bluealsa.service
echo "Type=simple" >> /lib/systemd/system/bluealsa.service
echo "ExecStart=/usr/bin/bluealsa" >> /lib/systemd/system/bluealsa.service
echo >> /lib/systemd/system/bluealsa.service
echo "[Install]" >> /lib/systemd/system/bluealsa.service
echo "WantedBy=multi-user.target" >> /lib/systemd/system/bluealsa.service
echo >> /lib/systemd/system/bluealsa.service
fi
echo "** Disable bluetooth services"
systemctl daemon-reload
systemctl disable bluetooth.service
systemctl disable bluealsa.service
systemctl disable hciuart.service
mkdir -p /var/run/bluealsa
sync
echo "** Cleanup"
DEBIAN_FRONTEND=noninteractive apt-get clean
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Cleanup failed"
fi
echo "** Reboot 3"
echo "5-6" > $MOSBUILD_STEP
sync
reboot
}
STEP_5_6 () {
waitForRc 10
cd $MOSBUILD_DIR
echo
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// STEP 5 - Install Rotary encoder driver"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo
echo "** Compile WiringPi"
cp ./rel-stretch/other/wiringpi/wiringPi-2.46-8d188fa0.tar.gz ./
tar xfz wiringPi-2.46-8d188fa0.tar.gz
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Un-tar failed"
fi
cd wiringPi-2.46-8d188fa0
./build
if [ $? -ne 0 ] ; then
cancelBuild "** Compile failed"
fi
cd ..
rm -rf wiringPi-2.46-8d188fa0
rm -f wiringPi-2.46-8d188fa0.tar.gz
echo "** Compile rotary encoder driver"
cp rel-stretch/other/rotenc/rotenc.c ./
gcc -std=c99 rotenc.c -orotenc -lwiringPi
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Compile failed"
fi
echo "** Cleanup"
cp ./rotenc /usr/local/bin
rm ./rotenc*
echo
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// STEP 6 - Compile and install MPD"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo
cd $MOSBUILD_DIR
echo "** Create MPD runtime environment"
useradd mpd
mkdir /var/lib/mpd
mkdir /var/lib/mpd/music
mkdir /var/lib/mpd/playlists
touch /var/lib/mpd/state
chown -R mpd:audio /var/lib/mpd
mkdir /var/log/mpd
touch /var/log/mpd/log
chmod 644 /var/log/mpd/log
chown -R mpd:audio /var/log/mpd
cp ./rel-stretch/mpd/mpd.conf.default /etc/mpd.conf
chown mpd:audio /etc/mpd.conf
chmod 0666 /etc/mpd.conf
echo "** Install MPD devlibs"
DEBIAN_FRONTEND=noninteractive apt-get -y install libmad0-dev libmpg123-dev libid3tag0-dev \
libflac-dev libvorbis-dev libfaad-dev \
libwavpack-dev libavcodec-dev libavformat-dev \
libmp3lame-dev libsoxr-dev libcdio-paranoia-dev libiso9660-dev \
libcurl4-gnutls-dev libasound2-dev libshout3-dev libyajl-dev \
libmpdclient-dev libavahi-client-dev libsystemd-dev \
libwrap0-dev libboost-dev libicu-dev libglib2.0-dev
if [ $? -ne 0 ] ; then
cancelBuild "** Error: install failed"
fi
# Check for binary
if [ -f ./rel-stretch/other/mpd/$MPD_BIN ] ; then
echo "** Install pre-compiled binary"
cp ./rel-stretch/other/mpd/$MPD_BIN /usr/local/bin/mpd
echo "** Cleanup"
DEBIAN_FRONTEND=noninteractive apt-get clean
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Cleanup failed"
fi
DEBIAN_FRONTEND=noninteractive apt-get -y autoremove
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Autoremove failed"
fi
else
wget http://www.musicpd.org/download/mpd/0.20/mpd-0.20.18.tar.xz
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Download failed"
fi
tar xf mpd-0.20.18.tar.xz
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Un-tar failed"
fi
cd mpd-0.20.18
sh autogen.sh
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Autogen failed"
fi
./configure --enable-database --enable-libmpdclient --enable-alsa \
--enable-curl --enable-dsd --enable-ffmpeg --enable-flac \
--enable-id3 --enable-soundcloud --enable-lame-encoder --enable-mad \
--enable-mpg123 --enable-pipe-output --enable-recorder-output --enable-shout \
--enable-vorbis --enable-wave-encoder --enable-wavpack --enable-httpd-output \
--enable-soxr --with-zeroconf=avahi \
--disable-bzip2 --disable-zzip --disable-fluidsynth --disable-gme \
--disable-wildmidi --disable-sqlite --disable-jack --disable-ao --disable-oss \
--disable-ipv6 --disable-pulse --disable-nfs --disable-smbclient \
--disable-upnp --disable-expat --disable-lsr \
--disable-sndfile --disable-audiofile --disable-sidplay
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Configure failed"
fi
make
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Make failed"
fi
make install
if [ $? -ne 0 ] ; then
cancelBuild "** Error: install failed"
fi
strip --strip-unneeded /usr/local/bin/mpd
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Strip failed"
fi
echo "** Cleanup"
cd $MOSBUILD_DIR
rm -rf ./mpd-0.20.18
DEBIAN_FRONTEND=noninteractive apt-get clean
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Cleanup failed"
fi
DEBIAN_FRONTEND=noninteractive apt-get -y autoremove
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Autoremove failed"
fi
fi
echo "** Reboot 4"
echo "7-8" > $MOSBUILD_STEP
sync
reboot
}
STEP_7_8 () {
waitForRc 10
cd $MOSBUILD_DIR
echo
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// STEP 7 - Create moOde runtime environment"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo
echo "** Create directories"
mkdir /var/local/www
mkdir /var/local/www/commandw
mkdir /var/local/www/cssw
mkdir /var/local/www/jsw
mkdir /var/local/www/imagesw
mkdir /var/local/www/imagesw/toggle
mkdir /var/local/www/db
mkdir /var/local/www/templatesw
chmod -R 0755 /var/local/www
mkdir /var/lib/mpd/music/RADIO
echo "** Create mount points"
mkdir /mnt/NAS
mkdir /mnt/SDCARD
echo "** Create symlinks"
ln -s /mnt/NAS /var/lib/mpd/music/NAS
ln -s /mnt/SDCARD /var/lib/mpd/music/SDCARD
ln -s /media /var/lib/mpd/music/USB
ln -s /var/lib/mpd/music /var/www/vlmm03846271
echo "** Create logfiles"
touch /var/log/moode.log
chmod 0666 /var/log/moode.log
touch /var/log/php_errors.log
chmod 0666 /var/log/php_errors.log
echo "** Create misc files"
cp ./rel-stretch/mpd/sticker.sql /var/lib/mpd
cp -r "./rel-stretch/other/sdcard/Stereo Test/" /var/lib/mpd/music/SDCARD/
cp ./rel-stretch/network/interfaces.default /etc/network/interfaces
cp ./rel-stretch/network/dhcpcd.conf.default /etc/dhcpcd.conf
cp ./rel-stretch/network/hostapd.conf.default /etc/hostapd/hostapd.conf
cp ./rel-stretch/var/local/www/db/moode-sqlite3.db.default /var/local/www/db/moode-sqlite3.db
# if we are building over wifi, wpa_supplicant will already be configred
# with ssid and pwd so we need to update cfg_network to match.
if [ -z $SSID ] ; then
cp ./rel-stretch/network/wpa_supplicant.conf.default /etc/wpa_supplicant/wpa_supplicant.conf
else
sqlite3 /var/local/www/db/moode-sqlite3.db "UPDATE cfg_network SET wlanssid='$SSID', wlanpwd='$PSK' WHERE id=2"
fi
echo "** Establish permissions"
chmod 0777 /var/lib/mpd/music/RADIO
chmod -R 0777 /var/local/www/db
echo "** Misc deletes"
rm -r /var/www/html
rm /etc/update-motd.d/10-uname
echo
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// STEP 8 - Install moOde sources and configs"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo
echo "** Install application sources and configs"
rm /var/lib/mpd/music/RADIO/* 2> /dev/null
rm -rf /var/www/images/radio-logos/ 2> /dev/null
cp ./rel-stretch/mpd/RADIO/* /var/lib/mpd/music/RADIO
cp ./rel-stretch/mpd/playlists/* /var/lib/mpd/playlists
cp -r ./rel-stretch/etc/* /etc
cp -r ./rel-stretch/home/* /home/pi
mv /home/pi/dircolors /home/pi/.dircolors
mv /home/pi/xinitrc.default /home/pi/.xinitrc
cp -r ./rel-stretch/lib/* /lib
cp -r ./rel-stretch/usr/* /usr
cp -r ./rel-stretch/var/* /var
cp -r ./rel-stretch/www/* /var/www
chmod 0755 /home/pi/*.sh
chmod 0755 /home/pi/*.php
chmod 0755 /var/www/command/*
/var/www/command/util.sh emerald "27ae60" "rgba(39,174,96,0.71)"
sqlite3 /var/local/www/db/moode-sqlite3.db "update cfg_system set value='Emerald' where param='themecolor'"
echo "** Establish permissions for service files"
echo "** MPD"
chmod 0755 /etc/init.d/mpd
chmod 0644 /lib/systemd/system/mpd.service
chmod 0644 /lib/systemd/system/mpd.socket
echo "** Bluetooth"
chmod 0666 /etc/bluealsaaplay.conf
chmod 0644 /etc/systemd/system/bluealsa-aplay@.service
chmod 0644 /etc/systemd/system/bluealsa.service
chmod 0644 /lib/systemd/system/bluetooth.service
chmod 0755 /usr/local/bin/a2dp-autoconnect
echo "** Rotenc"
chmod 0644 /lib/systemd/system/rotenc.service
echo "** Udev"
chmod 0644 /etc/udev/rules.d/*
echo "Localui"
chmod 0644 /lib/systemd/system/localui.service
echo "** Services are started by moOde Worker so lets disable them here"
systemctl daemon-reload
systemctl disable mpd.service
systemctl disable mpd.socket
systemctl disable rotenc.service
echo "** Binaries will not have been installed yet, but let's disable the services here"
chmod 0644 /lib/systemd/system/squeezelite.service
systemctl disable squeezelite
chmod 0644 /lib/systemd/system/upmpdcli.service
systemctl disable upmpdcli.service
echo "** Reset dir permissions for var local"
chmod -R 0755 /var/local/www
chmod -R 0777 /var/local/www/db
chmod -R ug-s /var/local/www
echo "** Initial permissions for certain files. These also get set during moOde Worker startup"
chmod 0777 /var/local/www/playhistory.log
chmod 0777 /var/local/www/currentsong.txt
touch /var/local/www/libcache.json
chmod 0777 /var/local/www/libcache.json
echo "** Re-establish image build autorun in rc.local"
sed -i "s/^exit.*//" /etc/rc.local
echo "$MOSBUILD_DIR/mosbuild_worker.sh >> /home/pi/mosbuild.log 2>> /home/pi/mosbuild.log" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
echo "** Update sudoers file"
cp /etc/sudoers /tmp/sudoers.bak
chmod 0777 /tmp/sudoers.bak
echo -e "pi\tALL=(ALL) NOPASSWD: ALL" >> /tmp/sudoers.bak
echo -e "www-data\tALL=(ALL) NOPASSWD: ALL" >> /tmp/sudoers.bak
visudo -cf /tmp/sudoers.bak
if [ $? -eq 0 ]; then
cp /tmp/sudoers.bak /etc/sudoers
else
cancelBuild "** Error: Update sudoers file failed"
fi
echo "** Reboot 5"
echo "9-10" > $MOSBUILD_STEP
sync
reboot
}
STEP_9_10 () {
waitForRc 10
cd $MOSBUILD_DIR
echo
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// STEP 9 - Alsaequal"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo
echo "** Install alsaequal"
amixer -D alsaequal > /dev/null
echo "** Establish permissions"
chmod 0755 /usr/local/bin/alsaequal.bin
chown mpd:audio /usr/local/bin/alsaequal.bin
rm /usr/share/alsa/alsa.conf.d/equal.conf
echo "** Wait 45 secs for moOde Startup to complete"
sleep 45
echo "** List MPD outputs"
mpc outputs
echo "** Enable only output 1"
mpc enable only 1
echo "** Alsaequal installed"
if [ -z "$SQUASH_FS" ] ; then
echo "** STEP 10 - Squashfs option not selected"
STEP_11
else
echo
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// STEP 10 - Optionally squash /var/www"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo
echo "** Add squashfs mount to /etc/fstab"
echo "/var/local/moode.sqsh /var/www squashfs ro,defaults 0 0" >> /etc/fstab
echo "** Squash /var/www"
rm /var/local/moode.sqsh
mksquashfs /var/www /var/local/moode.sqsh
echo "** Remove contents of /var/www"
rm -rf /var/www/*
fi
echo "** Reboot 6"
echo "11" > $MOSBUILD_STEP
sync
reboot
}
STEP_11 () {
waitForRc 30
cd $MOSBUILD_DIR
if [ -z "$LATEST_KERNEL" ] ; then
echo "** STEP 11 - Updated kernel option not selected"
STEP_12_13
else
echo
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// STEP 11 - Optionally, install updated Linux Kernel"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo
echo "** Download and install Linux kernel $KERNEL_VER"
echo "y" | PRUNE_MODULES=1 rpi-update $KERNEL_HASH
if [ $? -ne 0 ] ; then
cancelBuild "** Error: rpi-update failed"
else
echo "** Cleanup"
rm -rf /lib/modules.bak
rm -rf /boot.bak
DEBIAN_FRONTEND=noninteractive apt-get clean
echo "** Reboot 7"
echo "12-13" > $MOSBUILD_STEP
sync
reboot
fi
fi
}
STEP_12_13 () {
waitForRc 10
cd $MOSBUILD_DIR
echo
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// STEP 12 - Launch and configure moOde!"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo
echo "1. Initial configuration"
echo
echo "a. http://moode"
echo "b. Browse Tab, Default Playlist, Add"
echo "c. Menu, Configure, Sources, UPDATE mpd database"
echo "d. Menu, Audio, Mpd options, EDIT SETTINGS, APPLY"
echo "e. Menu, System, Set timezone"
echo "f. Clear system logs"
echo "g. Compact sqlite database"
echo "h. Keyboard"
echo
echo "2. Verification"
echo
echo "a) Playback tab"
echo "b) Scroll to the last item which should be the Stereo Test track"
echo "c) Click to begin play"
echo "d) Menu, Audio info"
echo "e) Verify Output stream is 16 bit 48 kHz"
echo
echo
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// STEP 13 - Final prep for image"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo
echo "1. Optionally check the boot partition."
echo
echo "NOTE: Run these commands one at a time."
echo
echo "If the message 'There are differences between boot sector and its backup' appears,"
echo "enter 1 'Copy original to backup', then y to 'Perform changes ?'"
echo
echo "sudo umount /boot"
echo "sudo dosfsck -tawl /dev/mmcblk0p1"
echo "sudo dosfsck -r /dev/mmcblk0p1"
echo "sudo dosfsck -V /dev/mmcblk0p1"
echo "sudo mount /boot"
echo
echo "** Clear system logs"
/var/www/command/util.sh clear-syslogs
echo "** Remove DHCP lease files "
rm /var/lib/dhcpcd5/*
echo "** Reset network config to defaults "
cp ./rel-stretch/network/interfaces.default /etc/network/interfaces
# cp ./rel-stretch/network/wpa_supplicant.conf.default /etc/wpa_supplicant/wpa_supplicant.conf
cp ./rel-stretch/network/dhcpcd.conf.default /etc/dhcpcd.conf
cp ./rel-stretch/network/hostapd.conf.default /etc/hostapd/hostapd.conf
if [ -z "$ADDL_COMPONENTS" ] ; then
echo "** Additional components option not selected"
finalCleanup
else
echo "** Reboot 8"
echo "C1_C7" > $MOSBUILD_STEP
echo "** Reboot"
sync
reboot
fi
}
COMP_C1_C7 () {
waitForRc 30
cd $MOSBUILD_DIR
echo
echo "################################################################"
echo "#"
echo "#"
echo "# Install additional components"
echo "#"
echo "#"
echo "################################################################"
echo
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// COMPONENT 1 - MiniDLNA"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo
echo "** Install MiniDLNA package"
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install minidlna
if [ $? -ne 0 ] ; then
cancelBuild "** Error: install failed"
fi
echo "** Disable MiniDLNA service"
systemctl disable minidlna
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Disable failed"
fi
echo
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// COMPONENT 2 - Auto-shuffle"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo
cd $MOSBUILD_DIR
echo "** Build Auto-shuffle"
git clone https://github.com/Joshkunz/ashuffle.git
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Git clone failed"
fi
cd $MOSBUILD_DIR/ashuffle
make
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Make failed"
fi
echo "** Install binary"
cd ..
cp ./ashuffle/ashuffle /usr/local/bin
rm -rf ./ashuffle
echo
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// COMPONENT 3 - MPD Audio Scrobbler"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo
cd $MOSBUILD_DIR
echo "** Build MPDAS"
git clone https://github.com/hrkfdn/mpdas
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Git clone failed"
fi
cd $MOSBUILD_DIR/mpdas
make
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Make failed"
fi
echo "** Install binary"
cp ./mpdas /usr/local/bin
cd ..
rm -rf ./mpdas
echo "** Install conf file"
cp ./rel-stretch/usr/local/etc/mpdasrc.default /usr/local/etc/mpdasrc
chmod 0755 /usr/local/etc/mpdasrc
echo
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// COMPONENT 4 - Shairport-sync"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo
cd $MOSBUILD_DIR
echo "** Install shairport-sync devlibs"
DEBIAN_FRONTEND=noninteractive apt-get -y install autoconf libtool libdaemon-dev libasound2-dev libpopt-dev libconfig-dev \
avahi-daemon libavahi-client-dev libssl-dev libsoxr-dev
if [ $? -ne 0 ] ; then
cancelBuild "** Error: install failed"
fi
# Check for binary
if [ -f ./rel-stretch/other/shairport-sync/$SPS_BIN ] ; then
echo "** Install pre-compiled binary"
cp ./rel-stretch/other/shairport-sync/$SPS_BIN /usr/local/bin/shairport-sync
else
echo "** Compile shairport-sync"
git clone https://github.com/mikebrady/shairport-sync.git
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Git clone failed"
fi
cd shairport-sync
autoreconf -i -f
./configure --with-alsa --with-avahi --with-ssl=openssl --with-soxr --with-metadata --with-stdout --with-systemd
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Configure failed"
fi
make
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Make failed"
fi
make install
if [ $? -ne 0 ] ; then
cancelBuild "** Error: install failed"
fi
echo "** Disable shairport-sync service"
systemctl disable shairport-sync
fi
echo "** Install conf file"
cd ..
cp ./rel-stretch/usr/local/etc/shairport-sync.conf /usr/local/etc
rm -rf ./shairport-sync
echo "** Cleanup"
DEBIAN_FRONTEND=noninteractive apt-get clean
if [ $? -ne 0 ] ; then
cancelBuild "** Error: Cleanup failed"
fi
echo
echo "////////////////////////////////////////////////////////////////"
echo "//"
echo "// COMPONENT 5 - Squeezelite"
echo "//"
echo "////////////////////////////////////////////////////////////////"
echo