forked from sdetweil/MagicMirror_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraspberry.sh
executable file
·755 lines (717 loc) · 29.4 KB
/
raspberry.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
#!/bin/bash
# This is an installer script for MagicMirror2. It works well enough
# that it can detect if you have Node installed, run a binary script
# and then download and run MagicMirror2.
if [ $USER == 'root' ]; then
echo Please login as a user to execute the MagicMirror installation, not root
exit 1
fi
echo -e "\e[0m"
echo '$$\ $$\ $$\ $$\ $$\ $$\ $$$$$$\'
echo '$$$\ $$$ | \__| $$$\ $$$ |\__| $$ __$$\'
echo '$$$$\ $$$$ | $$$$$$\ $$$$$$\ $$\ $$$$$$$\ $$$$\ $$$$ |$$\ $$$$$$\ $$$$$$\ $$$$$$\ $$$$$$\ \__/ $$ |'
echo '$$\$$\$$ $$ | \____$$\ $$ __$$\ $$ |$$ _____|$$\$$\$$ $$ |$$ |$$ __$$\ $$ __$$\ $$ __$$\ $$ __$$\ $$$$$$ |'
echo '$$ \$$$ $$ | $$$$$$$ |$$ / $$ |$$ |$$ / $$ \$$$ $$ |$$ |$$ | \__|$$ | \__|$$ / $$ |$$ | \__|$$ ____/'
echo '$$ |\$ /$$ |$$ __$$ |$$ | $$ |$$ |$$ | $$ |\$ /$$ |$$ |$$ | $$ | $$ | $$ |$$ | $$ |'
echo '$$ | \_/ $$ |\$$$$$$$ |\$$$$$$$ |$$ |\$$$$$$$\ $$ | \_/ $$ |$$ |$$ | $$ | \$$$$$$ |$$ | $$$$$$$$\'
echo '\__| \__| \_______| \____$$ |\__| \_______|\__| \__|\__|\__| \__| \______/ \__| \________|'
echo ' $$\ $$ |'
echo ' \$$$$$$ |'
echo ' \______/'
echo -e "\e[0m"
doInstall=1
true=1
false=0
# Define the tested version of Node.js.
NODE_TESTED="v16.13.0"
NPM_TESTED="V7.11.2"
NODE_STABLE_BRANCH="${NODE_TESTED:1:2}.x"
USER=`whoami`
PM2_FILE=pm2_MagicMirror.json
forced_arch=
pm2setup=$false
JustProd="--only=prod"
trim() {
local var="$*"
# remove leading whitespace characters
var="${var#"${var%%[![:space:]]*}"}"
# remove trailing whitespace characters
var="${var%"${var##*[![:space:]]}"}"
echo -n "$var"
}
beginswith() { case $2 in "$1"*) true;; *) false;; esac; }
cd $HOME
mac=$(uname -s)
if [ 0 -eq 1 ]; then
if [ "$0" == "bash" ]; then
logdir=.
else
if [ $mac == 'Darwin' ]; then
echo this is a mac >> $logfile
logdir=$(dirname "$0")
else
# put the log where the script is located
logdir=$(dirname $(readlink -f "$0"))
fi
fi
# if the script was execute from the web
if [[ $logdir != *"MagicMirror/installers"* ]]; then
# use the MagicMirror/installers folder, if setup
if [ -d MagicMirror ]; then
cd ~/MagicMirror/installers >/dev/null
logdir=$(pwd)
cd - >/dev/null
else
# use the users home folder if initial install
logdir=$HOME
fi
fi
fi
logfile=$HOME/install.log
echo install log being saved to $logfile
# Determine which Pi is running.
date +"install starting - %a %b %e %H:%M:%S %Z %Y" >>$logfile
ARM=$(uname -m)
echo installing on $ARM processor system >>$logfile
lsb_info=$(lsb_release -a 2>/dev/null)
echo the os is $lsb_info >> $logfile
OS=$(echo $lsb_info | awk -F: '{print $NF}' | awk '{print $1}')
if [ "$(echo $lsb_info | grep -i raspbian)." != '.' ]; then
# file only exists on raspian
ostype=$(cat /boot/issue.txt)
echo issue.txt info $ostype >>$logfile
#if [ "$(echo $ostype | grep stage4)." == '.' ]; then
# echo wrong operating system type, need full desktop version | tee -a $logfile
# date +"install completed - %a %b %e %H:%M:%S %Z %Y" >>$logfile
# exit 1
#fi
# is system in grpahical mode
if [ $(cat /etc/systemd/system/default.target | grep -i 'Graphical Interface' | wc -l) -ne 1 ]; then
# no
# is Xorg installed?
if [ "$(type Xorg)." == "." ]; then
# no
echo wrong operating system type, need full desktop version | tee -a $logfile
else
# yes, but running in text mode
echo system running in command line mode, need graphical desktop, see raspi-config | tee -a $logfile
fi
date +"install completed - %a %b %e %H:%M:%S %Z %Y" >>$logfile
exit 1
else
# graphical mode, is X running?
if [ "$(pidof Xorg)." == "." ]; then
echo system running in command line mode, configured for graphical desktop, please reboot | tee -a $logfile
date +"install completed - %a %b %e %H:%M:%S %Z %Y" >>$logfile
exit 2
fi
fi
fi
# Check the Raspberry Pi version.
if [ 0 == 1 ]; then
if [ "$ARM" != "armv7l" ]; then
read -p "this appears not to be a Raspberry Pi 2, 3 or 4, do you want to continue installation (y/N)?" choice
choice="${choice:-N}"
if [[ $choice =~ ^[Nn]$ ]]; then
echo user stopped install on $ARM hardware >>$logfile
echo -e "\e[91mSorry, your Raspberry Pi is not supported."
echo -e "\e[91mPlease run MagicMirror on a Raspberry Pi 2, 3 or 4"
echo -e "\e[91mIf this is a Pi Zero, the setup will configure to run in server only mode wih a local browser."
exit;
fi
fi
fi
# Define helper methods.
function command_exists () { type "$1" &> /dev/null ;}
function verlte() { [ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ];}
function verlt() { [ "$1" = "$2" ] && return 1 || verlte $1 $2 ;}
# Update before first apt-get
if [ $mac != 'Darwin' ]; then
# Installing helper tools
echo -e "\e[96mInstalling helper tools ...\e[90m" | tee -a $logfile
sudo apt-get --assume-yes install curl wget git build-essential unzip pv >>$logfile
echo -e "\e[96mUpdating packages ...\e[90m" | tee -a $logfile
upgrade=$false
update=$(sudo apt-get update --allow-releaseinfo-change>&1)
# save return code before any other command is issued
update_rc=$?
echo $update >> $logfile
if [ $(echo $update | grep -i "is not valid yet" | wc -l) -ne 0 ]; then
echo -e "\e[91mSystem date/time is in the past, please correct ...\e[90m" | tee -a $logfile
exit 1
fi
# if we had a problem with update
if [ $update_rc -ne 0 ]; then
echo -e "\e[91mUpdate failed, retrying installation ...\e[90m" | tee -a $logfile
if [ $(echo $update | grep -e "apt-secure" -e "oldstable" | wc -l) -eq 1 ]; then
update=$(sudo apt-get update --allow-releaseinfo-change 2>&1)
update_rc=$?
echo $update >> $logfile
if [ $update_rc -ne 0 ]; then
echo "second apt-get update failed" $update | tee -a $logfile
exit 1
else
echo "second apt-get update completed ok" >> $logfile
upgrade=$true
fi
fi
else
echo "apt-get update completed ok" >> $logfile
upgrade=$true
fi
if [ $upgrade -eq $true ]; then
echo "apt-get upgrade started" >> $logfile
upgrade_result=$(sudo apt-get --assume-yes upgrade 2>&1 | pv -l -p)
upgrade_rc=$?
echo apt upgrade result ="rc=$upgrade_rc $upgrade_result" >> $logfile
fi
fi
npminstalled=$false
if [ $OS = "bullseye" -a $ARM != "armv6l" ]; then
# is npm installed?
echo "installing on bullseye" >>$logfile
npm=$(which npm)
if [ "$npm". != "." ]; then
npminstalled=$true
# yes
# check if node is already at the right level
# get node version
v=$(node -v)
if [ "$v." != "." ]; then
if [ ${v:1:2} -lt ${NODE_TESTED:1:2} ]; then
echo -e "\e[96minstalling correct version of node and npm, please wait\e[90m" | tee -a $logfile
nr=$(sudo npm install -g n)
sudo n ${NODE_TESTED:1} >> $logfile
PATH="$PATH"
nodev=$(node -v)
if [ "${nodev:0:3}" != ${NODE_TESTED:0:3} ]; then
echo node failed to install, exiting | tee -a $logfile
exit
fi
fi
else
echo -e "\e[92mnode failed to execute, please check the error message and resolve before trying again\e[0m" | tee -a $logfile
date +"install aborted - %a %b %e %H:%M:%S %Z %Y" >>$logfile
exit 2
fi
fi
fi
if [ $npminstalled == $false ]; then
# Check if we need to install or upgrade Node.js.
echo -e "\e[96mCheck current Node installation ...\e[0m" | tee -a $logfile
NODE_INSTALL=false
if command_exists node; then
echo -e "\e[0mNode currently installed. Checking version number." | tee -a $logfile
NODE_CURRENT=$(node -v)
if [ "$NODE_CURRENT." == "." ]; then
NODE_CURRENT="V1.0.0"
echo forcing low Node version >> $logfile
fi
echo -e "\e[0mMinimum Node version: \e[1m$NODE_TESTED\e[0m" | tee -a $logfile
echo -e "\e[0mInstalled Node version: \e[1m$NODE_CURRENT\e[0m" | tee -a $logfile
if verlt $NODE_CURRENT $NODE_TESTED; then
echo -e "\e[96mNode should be upgraded.\e[0m" | tee -a $logfile
NODE_INSTALL=true
# Check if a node process is currenlty running.
# If so abort installation.
node_running=$(ps -ef | grep node | grep -v grep)
if [ "$node_running." != "." ]; then
echo -e "\e[91mA Node process is currently running. Can't upgrade." | tee -a $logfile
echo "Please quit all Node processes and restart the installer." | tee -a $logfile
echo
echo $node_running | tee -a $logfile
exit;
fi
else
echo -e "\e[92mNo Node.js upgrade necessary.\e[0m" | tee -a $logfile
fi
else
echo -e "\e[93mNode.js is not installed.\e[0m" | tee -a $logfile
NODE_INSTALL=true
fi
# Install or upgrade node if necessary.
if $NODE_INSTALL; then
echo -e "\e[96mInstalling Node.js ...\e[90m" | tee -a $logfile
# Fetch the latest version of Node.js from the selected branch
# The NODE_STABLE_BRANCH variable will need to be manually adjusted when a new branch is released. (e.g. 7.x)
# Only tested (stable) versions are recommended as newer versions could break MagicMirror.
if [ $mac == 'Darwin' ]; then
brew install node
else
if [ $OS == 'bullseye' ]; then
if [ -e /usr/share/doc/nodejs/api/embedding.json.gz ]; then
sudo chmod 666 /usr/share/doc/nodejs/api/embedding.json.gz
fi
fi
# sudo apt-get install --only-upgrade libstdc++6
node_info=$(curl -sL https://deb.nodesource.com/setup_$NODE_STABLE_BRANCH | sudo -E bash - )
echo Node release info = $node_info >> $logfile
sudo apt-get install -y nodejs
if [ "$(echo $node_info | grep "not currently supported")." == "." ]; then
sudo apt-get install -y nodejs
else
echo node $NODE_STABLE_BRANCH version installer not available, doing manually >>$logfile
# no longer supported install
sudo apt-get install -y --only-upgrade libstdc++6 >> $logfile
# have to do it manually
ARM1=$ARM
if [ $ARM == 'armv6l' ]; then
curl -sL https://unofficial-builds.nodejs.org/download/release/${NODE_TESTED}/node-${NODE_TESTED}-linux-armv6l.tar.gz >node_release-${NODE_TESTED}.tar.gz
node_ver=$NODE_TESTED
else
node_vnum=$(echo $NODE_STABLE_BRANCH | awk -F. '{print $1}')
if [ $ARM == 'x86_64' ]; then
ARM1= x64
fi
# get the highest release number in the stable branch line for this processor architecture
node_ver=$(curl -sL https://nodejs.org/download/release/index.tab | grep $ARM1 | grep -m 1 v$node_vnum | awk '{print $1}')
echo "latest release in the $NODE_STABLE_BRANCH family for $ARM is $node_ver" >> $logfile
# download that file
curl -sL https://nodejs.org/download/release/v$node_ver/node-v$node_ver-linux-$ARM1.tar.gz >node_release-$node_ver.tar.gz
fi
cd /usr/local
echo using release tar file = node_release-$node_ver.tar.gz >> $logfile
sudo tar --strip-components 1 -xzf $HOME/node_release-$node_ver.tar.gz
cd - >/dev/null
rm ./node_release-$node_ver.tar.gz
fi
# get the new node version number
new_ver=$(node -v 2>&1)
# if there is a failure to get it due to a missing library
if [ $(echo $new_ver | grep "not found" | wc -l) -ne 0 ]; then
#
sudo apt-get install -y --only-upgrade libstdc++6 >> $logfile
fi
echo node version is $(node -v 2>&1) >>$logfile
fi
echo -e "\e[92mNode.js installation Done! version=$(node -v)\e[0m" | tee -a $logfile
fi
# Check if we need to install or upgrade npm.
echo -e "\e[96mCheck current NPM installation ...\e[0m" | tee -a $logfile
NPM_INSTALL=false
if command_exists npm; then
echo -e "\e[0mNPM currently installed. Checking version number." | tee -a $logfile
NPM_CURRENT='V'$(npm -v)
echo -e "\e[0mMinimum npm version: \e[1m$NPM_TESTED\e[0m" | tee -a $logfile
echo -e "\e[0mInstalled npm version: \e[1m$NPM_CURRENT\e[0m" | tee -a $logfile
if verlte $NPM_CURRENT $NPM_TESTED; then
echo -e "\e[96mnpm should be upgraded.\e[0m" | tee -a $logfile
NPM_INSTALL=true
# Check if a node process is currently running.
# If so abort installation.
if pgrep "npm" > /dev/null; then
echo -e "\e[91mA npm process is currently running. Can\'t upgrade." | tee -a $logfile
echo "Please quit all npm processes and restart the installer." | tee -a $logfile
exit;
fi
else
echo -e "\e[92mNo npm upgrade necessary.\e[0m" | tee -a $logfile
fi
else
echo -e "\e[93mnpm is not installed.\e[0m" | tee -a $logfile
NPM_INSTALL=true
fi
# Install or upgrade node if necessary.
if $NPM_INSTALL; then
echo -e "\e[96mInstalling npm ...\e[90m" | tee -a $logfile
# Fetch the latest version of npm from the selected branch
# The NODE_STABLE_BRANCH variable will need to be manually adjusted when a new branch is released. (e.g. 7.x)
# Only tested (stable) versions are recommended as newer versions could break MagicMirror.
#NODE_STABLE_BRANCH="9.x"
#curl -sL https://deb.nodesource.com/setup_$NODE_STABLE_BRANCH | sudo -E bash -
#
# if this is a mac, npm was installed with node
if [ $mac != 'Darwin' ]; then
sudo apt-get install -y npm >>$logfile
fi
# update to the latest.
echo upgrading npm to latest >> $logfile
sudo npm i -g npm@${NPM_TESTED:1:1} >>$logfile
NPM_CURRENT='V'$(npm -v)
echo -e "\e[92mnpm installation Done! version=$NPM_CURRENT\e[0m" | tee -a $logfile
fi
else
NPM_CURRENT='V'$(npm -v)
fi
# Install MagicMirror
cd ~
if [ $doInstall == 1 ]; then
if [ -d "$HOME/MagicMirror" ] ; then
echo -e "\e[93mIt seems like MagicMirror is already installed." | tee -a $logfile
echo -e "To prevent overwriting, the installer will be aborted." | tee -a $logfile
echo -e "Please rename the \e[1m~/MagicMirror\e[0m\e[93m folder and try again.\e[0m" | tee -a $logfile
echo ""
#echo -e "If you want to upgrade your installation run \e[1m\e[97mupgrade-script\e[0m from the ~/MagicMirror/installers directory." | tee -a $logfile
echo ""
exit;
fi
echo -e "\e[96mCloning MagicMirror ...\e[90m" | tee -a $logfile
if git clone --depth=1 https://github.com/MichMich/MagicMirror.git; then
echo -e "\e[92mCloning MagicMirror Done!\e[90m" | tee -a $logfile
# replace faulty run-start.sh
curl -sL https://raw.githubusercontent.com/sdetweil/MagicMirror_scripts/master/run-start.sh >MagicMirror/run-start.sh
chmod +x MagicMirror/run-start.sh
sudo touch /etc/chromium-browser/customizations/01-disable-update-check 2>/dev/null;echo CHROMIUM_FLAGS=\"\$\{CHROMIUM_FLAGS\} --check-for-update-interval=31536000\" | sudo tee /etc/chromium-browser/customizations/01-disable-update-check >/dev/null 2>&1
else
echo -e "\e[91mUnable to clone MagicMirror. \e[90m" | tee -a $logfile
exit;
fi
cd ~/MagicMirror || exit
if [ $(grep version package.json | awk -F: '{print $2}') == '"2.11.0",' -a $ARM == 'x86_64' ]; then
git fetch https://github.com/MichMich/MagicMirror.git develop >/dev/null 2>&1
git branch develop FETCH_HEAD > /dev/null 2>&1
git checkout develop > /dev/null 2>&1
fi
# if this is v 2.11 or higher
newver=$(grep -i version package.json | awk -F\" '{ print $4 }')
if verlte "2.11.0" $newver; then
# add fix to disable chromium update checks for a year from time started
# sudo touch /etc/chromium-browser/customizations/01-disable-update-check;echo CHROMIUM_FLAGS=\"\$\{CHROMIUM_FLAGS\} --check-for-update-interval=31536000\" | sudo tee /etc/chromium-browser/customizations/01-disable-update-check >/dev/null
if [ "$ARM" == "x86_64" -a "$OS" == 'buster' ]; then
cd fonts
sed '/roboto-fontface/ c \ "roboto-fontface": "latest"' < package.json >new_package.json
if [ -s new_package.json ]; then
cp new_package.json package.json
rm new_package.json
echo "package.json update for x86 fontface completed ok" >>$logfile
fi
cd -
elif [ $mac == 'Darwin' ]; then
rm vendor/package-lock.json
echo "erase vendor package-lock.json to allow later nan/fsevents install on mac" >>$logfile
fi
fi
if [ ! -e css/custom.css ]; then
touch css/custom.css
fi
if [ $newver == '2.13.0' ]; then
# fix downlevel node-ical
sed '/node-ical/ c \ "node-ical\"\:\"^0.12.1\",' < package.json >new_package.json
rm package.json
mv new_package.json package.json
fi
echo -e "\e[96mInstalling dependencies ...\e[90m" | tee -a $logfile
# check for NPM v8 or higher, changed parms for prod only on npm install
if [ ${NPM_CURRENT:1:1} -ge 8 ]; then
JustProd="--no-audit --no-fund --no-update-notifier"
fi
rm package-lock.json 2>/dev/null
npm_i_r=$(npm $forced_arch $Justprod --omit=dev install)
npm_i_rc=$?
# add the npm install messages to the logfile
echo $npm_i_r >> $logfile
if [ $npm_i_rc -eq 0 ]; then
echo -e "\e[92mDependencies installation Done!\e[90m" | tee -a $logfile
else
if [ $(echo $npm_i_r | grep "CERT_NOT_YET_VALID" | wc -l) -ne 0 ]; then
echo "\e[91mSystem date/time is in the past, please correct \e[90m" | tee -a $logfile
fi
echo -e "\e[91mUnable to install dependencies! \e[90m" | tee -a $logfile
exit;
fi
# fixup permissions on sandbox file if it exists
if [ -f node_modules/electron/dist/chrome-sandbox ]; then
echo "fixing sandbox permissions" >>$logfile
sudo chown root node_modules/electron/dist/chrome-sandbox 2>/dev/null
sudo chmod 4755 node_modules/electron/dist/chrome-sandbox 2>/dev/null
fi
# assume electron installed ok
el_installed=$true
# if the folder isn't there, then we have problems
if [ ! -d node_modules/electron ]; then
el_installed=$false
fi
# if one of the older devices, fix the start script to execute in serveronly mode
if [ "$ARM" == "armv6l" -o "$ARM" == "i686" -o $el_installed == $false ]; then
# fixup the start script
sed '/start/ c \ "start\"\:\"./run-start.sh $1\",' < package.json >new_package.json
if [ -s new_package.json ]; then
cp new_package.json package.json
rm new_package.json
echo "package.json update for $ARM or Electron missing, completed ok" >>$logfile
else
echo "package.json update for $ARM failed " >>$logfile
fi
# on armv6l, new OS's have a bug in browser support
# install older chromium if not present
v=$(uname -r); v=${v:0:1}
if [ "$(which chromium-browser)." == '.' -a ${v:0:1} -ne 4 ]; then
sudo apt install -y chromium-browser >>$logfile
fi
fi
# Use sample config for start MagicMirror
echo setting up initial config.js | tee -a $logfile
cp config/config.js.sample config/config.js
fi
# Check if plymouth is installed (default with PIXEL desktop environment), then install custom splashscreen.
echo -e "\e[96mCheck plymouth installation ...\e[0m" | tee -a $logfile
if command_exists plymouth; then
THEME_DIR="/usr/share/plymouth/themes"
echo -e "\e[90mSplashscreen: Checking themes directory.\e[0m" | tee -a $logfile
if [ -d $THEME_DIR ]; then
echo -e "\e[90mSplashscreen: Create theme directory if not exists.\e[0m" | tee -a $logfile
if [ ! -d $THEME_DIR/MagicMirror ]; then
sudo mkdir $THEME_DIR/MagicMirror
fi
if sudo cp ~/MagicMirror/splashscreen/splash.png $THEME_DIR/MagicMirror/splash.png && sudo cp ~/MagicMirror/splashscreen/MagicMirror.plymouth $THEME_DIR/MagicMirror/MagicMirror.plymouth && sudo cp ~/MagicMirror/splashscreen/MagicMirror.script $THEME_DIR/MagicMirror/MagicMirror.script; then
echo
if [ "$(which plymouth-set-default-theme)." != "." ]; then
if sudo plymouth-set-default-theme -R MagicMirror; then
echo -e "\e[92mSplashscreen: Changed theme to MagicMirror successfully.\e[0m" | tee -a $logfile
else
echo -e "\e[91mSplashscreen: Couldn't change theme to MagicMirror!\e[0m" | tee -a $logfile
fi
fi
else
echo -e "\e[91mSplashscreen: Copying theme failed!\e[0m" | tee -a $logfile
fi
else
echo -e "\e[91mSplashscreen: Themes folder doesn't exist!\e[0m" | tee -a $logfile
fi
else
echo -e "\e[93mplymouth is not installed.\e[0m" | tee -a $logfile
fi
# Use pm2 control like a service MagicMirror
read -p "Do you want use pm2 for auto starting of your MagicMirror (y/N)?" choice
choice="${choice:-N}"
if [[ $choice =~ ^[Yy]$ ]]; then
echo install and setup pm2 | tee -a $logfile
# assume pm2 will be found on the path
pm2cmd=pm2
up=""
if [ $mac == 'Darwin' ]; then
up="--unsafe-perm"
launchctl=launchctl
launchctl_path=$(which $launchctl)
`export PATH=$PATH:${launchctl_path%/$launchctl}`
fi
# check to see if already installed
pm2_installed=$(which $pm2cmd)
if [ "$pm2_installed." != "." ]; then
# does it work?
pm2_fails=$(pm2 list | grep -i -m 1 "uptime" | wc -l )
if [ $pm2_fails != 1 ]; then
# uninstall it
echo pm2 installed, but does not work, uninstalling >> $logfile
sudo npm uninstall $up -g pm2 >> $logfile
# force reinstall
pm2_installed=
fi
fi
# if not installed
if [ "$pm2_installed." == "." ]; then
# install it.
echo pm2 not installed, installing >>$logfile
result=$(sudo npm $up $JustProd install -g pm2 2>&1)
echo pm2 install result $result >>$logfile
pm2cmd=pm2
# if this is a mac
if [ $mac == 'Darwin1' ]; then
echo "this is a mac, fixup for path" >>$logfile
# get the location of pm2 install
# parse the npm install output to get the command
pm2cmd=`echo $result | awk -F - '{print $1}' | tr -d '[:space:]'`
c='/pm2'
# get the path only
echo ${pm2cmd%$c} >installers/pm2path
fi
fi
echo "get the pm2 platform specific startup command" >>$logfile
# get the platform specific pm2 startup command
v=$($pm2cmd startup | tail -n 1)
if [ $mac != 'Darwin' ]; then
# check to see if we can get the OS package name (Ubuntu)
if [ $(which lsb_release| wc -l) -gt 0 ]; then
# fix command
# if ubuntu 18.04, pm2 startup gets something wrong
if [ $(lsb_release -r | grep -m1 18.04 | wc -l) -gt 0 ]; then
v=$(echo $v | sed 's/\/bin/\/bin:\/bin/')
fi
fi
fi
echo "startup command = $v" >>$logfile
# execute the command returned
$v 2>&1 >>$logfile 2>&1
echo "pm2 startup command done" >>$logfile
# is this is mac
# need to fix pm2 startup, only on catalina
if [ $mac == 'Darwin1' ]; then
if [ $(sw_vers -productVersion | head -c 6) == '10.15.' ]; then
# only do if the faulty tag is present (pm2 may fix this, before the script is fixed)
if [ $(grep -m 1 UserName /Users/$USER/Library/LaunchAgents/pm2.$USER.plist | wc -l) -eq 1 ]; then
# copy the pm2 startup file config
cp /Users/$USER/Library/LaunchAgents/pm2.$USER.plist .
# edit out the UserName key/value strings
sed -e '/UserName/{N;d;}' pm2.$USER.plist > pm2.$USER.plist.new
# copy the file back
sudo cp pm2.$USER.plist.new /Users/$USER/Library/LaunchAgents/pm2.$USER.plist
fi
fi
fi
# if the user is no pi, we have to fixup the pm2 json file
echo "configure the pm2 config file for MagicMirror" >>$logfile
# if the files we need aren't here, get them
if [ ! -e installers/pm2_MagicMirror.json ]; then
curl -sL https://raw.githubusercontent.com/sdetweil/MagicMirror_scripts/master/pm2_MagicMirror.json >installers/pm2_MagicMirror.json
curl -sl https://raw.githubusercontent.com/sdetweil/MagicMirror_scripts/master/mm.sh >installers/mm.sh
chmod +x installers/mm.sh
fi
if [ "$USER" != "pi" ]; then
echo the user is not pi >>$logfile
# go to the installers folder
cd installers
# edit the startup script for the right user
echo change mm.sh >>$logfile
if [ ! -e mm_temp.sh ]; then
echo save copy of mm.sh >> $logfile
cp mm.sh mm_temp.sh
fi
if [ $(grep pi mm_temp.sh | wc -l) -gt 0 ]; then
echo change hard coded pi username >> $logfile
sed 's/pi/'$USER'/g' mm_temp.sh >mm.sh
else
echo change relative home path to hard coded path >> $logfile
hf=$(echo $HOME |sed 's/\//\\\//g')
sed 's/\~/'$hf'/g' mm_temp.sh >mm.sh
fi
# edit the pms config file for the right user
echo change $PM2_FILE >>$logfile
sed 's/pi/'$USER'/g' $PM2_FILE > pm2_MagicMirror_new.json
# make sure to use the updated file
PM2_FILE=pm2_MagicMirror_new.json
# if this is a mac
if [ $mac == 'Darwin' ]; then
# copy the path file to the system paths list
#sudo cp ./pm2path /etc/paths.d
# change the name of the home path for mac
sed 's/home/Users/g' $PM2_FILE > pm2_MagicMirror_new1.json
# make sure to use the updated file
PM2_FILE=pm2_MagicMirror_new1.json
fi
echo now using this config file $PM2_FILE >>$logfile
# go back one cd level
cd - >/dev/null
fi
echo start MagicMirror via pm2 now >>$logfile
# tell pm2 to start the app defined in the config file
$pm2cmd start $HOME/MagicMirror/installers/$PM2_FILE
# tell pm2 to save that configuration, for start at boot
echo save MagicMirror pm2 config now >>$logfile
$pm2cmd save
echo stop MagicMirror via pm2 now >>$logfile
#$pm2cmd stop MagicMirror
pm2setup=$true
fi
# Disable Screensaver
read -p "Do you want to disable the screen saver? (y/N)?" choice
choice="${choice:-Y}"
if [[ $choice =~ ^[Yy]$ ]]; then
# if this is a mac
if [ $mac == 'Darwin' ]; then
# get the current setting
setting=$(defaults -currentHost read com.apple.screensaver idleTime)
# if its on
if [ "$setting" != 0 ] ; then
# turn it off
echo disable screensaver via mac profile >> $logfile
defaults -currentHost write com.apple.screensaver idleTime 0
else
echo mac profile screen saver already disabled >> $logfile
fi
else
# find out if some screen saver running
# get just the running processes and args
# just want the program name (1st token)
# find the 1st with 'saver' in it (should only be one)
# parse with path char, get the last field ( the actual pgm name)
screen_saver_running=$(ps -A -o args | awk '{print $1}' | grep -m1 [s]aver | awk -F\/ '{print $NF}');
# if we found something
if [ "$screen_saver_running." != "." ]; then
# some screensaver running
case "$screen_saver_running" in
mate-screensaver) echo 'mate screen saver' >>$logfile
gsettings set org.mate.screensaver lock-enabled false 2>/dev/null
gsettings set org.mate.screensaver idle-activation-enabled false 2>/dev/null
gsettings set org.mate.screensaver lock_delay 0 2>/dev/null
echo " $screen_saver_running disabled" >> $logfile
DISPLAY=:0 mate-screensaver >/dev/null 2>&1 &
;;
gnome-screensaver) echo 'gnome screen saver' >>$logfile
gnome_screensaver-command -d >/dev/null 2>&1
echo " $screen_saver_running disabled" >> $logfile
;;
xscreensaver) echo 'xscreensaver running' | tee -a $logfile
xsetting=$(grep -m1 'mode:' ~/.xscreensaver )
if [ $(echo $xsetting | awk '{print $2}') != 'off' ]; then
sed -i "s/$xsetting/mode: off/" "$HOME/.xscreensaver"
echo " xscreensaver set to off" >> $logfile
else
echo " xscreensaver already disabled" >> $logfile
fi
;;
gsd-screensaver | gsd-screensaver-proxy)
setting=$(gsettings get org.gnome.desktop.screensaver lock-enabled 2>/dev/null)
setting1=$(gsettings get org.gnome.desktop.session idle-delay 2>/dev/null)
if [ "$setting. $setting1." != '. .' ]; then
if [ "$setting $setting1" != 'false uint32 0' ]; then
echo "disable screensaver via gsettings was $setting and $setting1" >> $logfile
gsettings set org.gnome.desktop.screensaver lock-enabled false
gsettings set org.gnome.desktop.screensaver idle-activation-enabled false
gsettings set org.gnome.desktop.session idle-delay 0
else
echo "gsettings screen saver already disabled" >> $logfile
fi
fi
;;
*) echo "some other screensaver $screen_saver_running" found | tee -a $logfile
echo "please configure it manually" | tee -a $logfile
;;
esac
fi
if [ $(which gsettings | wc -l) == 1 ]; then
setting=$(gsettings get org.gnome.desktop.screensaver lock-enabled 2>/dev/null)
setting1=$(gsettings get org.gnome.desktop.session idle-delay 2>/dev/null)
if [ "$setting. $setting1." != '. .' ]; then
if [ "$setting $setting1" != 'false uint32 0' ]; then
echo "disable screensaver via gsettings was $setting and $setting1">> $logfile
gsettings set org.gnome.desktop.screensaver lock-enabled false
gsettings set org.gnome.desktop.screensaver idle-activation-enabled false
gsettings set org.gnome.desktop.session idle-delay 0
else
echo "gsettings screen saver already disabled" >> $logfile
fi
fi
fi
if [ -e "/etc/lightdm/lightdm.conf" ]; then
# if screen saver NOT already disabled?
if [ $(grep 'xserver-command=X -s 0 -dpms' /etc/lightdm/lightdm.conf | wc -l) == 0 ]; then
echo "disable screensaver via lightdm.conf" >> $logfile
sudo sed -i '/^\[Seat:/a xserver-command=X -s 0 -dpms' /etc/lightdm/lightdm.conf
else
echo "screensaver via lightdm already disabled" >> $logfile
fi
fi
if [ -d "/etc/xdg/lxsession/LXDE-pi" ]; then
currently_set=$(grep -m1 '\-dpms' /etc/xdg/lxsession/LXDE-pi/autostart)
if [ "$currently_set." == "." ]; then
echo "disable screensaver via lxsession" >> $logfile
# turn it off for the future
sudo su -c "echo -e '@xset s noblank\n@xset s off\n@xset -dpms' >> /etc/xdg/lxsession/LXDE-pi/autostart"
# turn it off now
export DISPLAY=:0; xset s noblank;xset s off;xset -dpms
else
echo "lxsession screen saver already disabled" >> $logfile
fi
fi
fi
fi
echo " "
if [ $pm2setup -eq $true ]; then
rmessage="pm2 start MagicMirror"
else
rmessage="DISPLAY=:0 npm start"
fi
echo -e "\e[92mWe're ready! Run \e[1m\e[97m$rmessage\e[0m\e[92m from the ~/MagicMirror directory to start your MagicMirror.\e[0m" | tee -a $logfile
echo " "
echo " "
date +"install completed - %a %b %e %H:%M:%S %Z %Y" >>$logfile