-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmirror.sh
executable file
·2545 lines (2432 loc) · 74.9 KB
/
mirror.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
#
## @file mirror.sh
## @brief Convenience script to manage multiple MagicMirror configurations
## @author Ronald Joe Record (rr at ronrecord dot com)
## @copyright Copyright (c) 2020-2022, Ronald Joe Record, all rights reserved.
## @date Written 1-feb-2020
## @version 4.0.1
##
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# The Software is provided "as is", without warranty of any kind, express or
# implied, including but not limited to the warranties of merchantability,
# fitness for a particular purpose and noninfringement. In no event shall the
# authors or copyright holders be liable for any claim, damages or other
# liability, whether in an action of contract, tort or otherwise, arising from,
# out of or in connection with the Software or the use or other dealings in
# the Software.
#
# User configurable settings. Make sure these are correct for your system.
# -----------------------------------------------------------------------
# Set this to your MagicMirror installation directory, typically $HOME/MagicMirror
MM="__MagicMirror_Home__"
[ -d ${MM}/config ] || {
MM=
for homedir in /usr/local /home/*
do
[ "${homedir}" == "/home/*" ] && continue
[ -d ${homedir}/MagicMirror/config ] && {
MM="${homedir}/MagicMirror"
break
}
done
}
[ "${MM}" ] || MM="${HOME}/MagicMirror"
# Set the IP and PORT to the values on your system
# IP is the IP address of your MagicMirror Raspberry Pi or 'localhost'
IP="MM.M.M.MM"
# PORT is the port your MMM-Remote-Control module is running on
PORT="8080"
#
# Set you MMM-Remote-Control API Key here or leave blank if you have not configured one
#
# Replace with your MMM-Remote-Control API Key
apikey="xxx_Remote-Control-API-Key_xxxxx"
# Uncomment this line if you have not configured an MMM-Remote-Control API Key
# apikey=
#
# By default, the mirror script uses the PM2 process named "MagicMirror" to
# stop/start/restart and get the status of MagicMirror. If you have setup
# PM2 to manage your MagicMirror process then either name that PM2 process
# "MagicMirror" or change the setting below to your MagicMirror PM2 process name.
#
# Replace with your PM2 MagicMirror process name
PM2_PROCESS_NAME="MagicMirror"
#
modurl="http://${IP}:${PORT}/api/module"
apiurl="http://${IP}:${PORT}/api/notification"
MCL_HOME="/usr/local/MirrorCommand"
[ -d ${MCL_HOME}/bin ] && {
export PATH=${PATH}:${MCL_HOME}/bin
}
fake_vcgencmd=
have_vcgencmd=`type -p vcgencmd`
[ "${have_vcgencmd}" == "${MCL_HOME}/bin/vcgencmd" ] && fake_vcgencmd=1
# Set this to the X11 DISPLAY you are using. DISPLAY=:0 works for most systems.
export DISPLAY=${DISPLAY:=:0}
MIRRORSCREEN="${MCL_HOME}/etc/mirrorscreen"
HAVE_PORT=
have_xdpyinfo=`type -p xdpyinfo`
[ -f ${MIRRORSCREEN} ] || MIRRORSCREEN="${MM}/.mirrorscreen"
[ -f ${MIRRORSCREEN} ] && {
. ${MIRRORSCREEN}
screen=SCREEN_${MM_SCREEN}[mode]
[ ${!screen+_} ] && {
PORTRAIT=${!screen}
HAVE_PORT=1
}
}
[ "${HAVE_PORT}" ] || {
PORTRAIT=1
if [ "${have_xdpyinfo}" ]
then
SCREEN_RES=`xdpyinfo | awk '/dimensions/ {print $2}'`
echo ${SCREEN_RES} | grep x > /dev/null && {
SCREEN_WIDTH=`echo ${SCREEN_RES} | awk -F 'x' ' { print $1 } '`
SCREEN_HEIGHT=`echo ${SCREEN_RES} | awk -F 'x' ' { print $2 } '`
}
if ! [[ "$SCREEN_WIDTH" =~ ^[0-9]+$ ]]
then
SCREEN_WIDTH=`xrandr | grep current | awk -F ',' ' { print $2 } ' | awk ' { print $2 } '`
fi
if ! [[ "$SCREEN_HEIGHT" =~ ^[0-9]+$ ]]
then
SCREEN_HEIGHT=`xrandr | grep current | awk -F ',' ' { print $2 } ' | awk ' { print $4 } '`
fi
else
SCREEN_WIDTH=`xrandr | grep current | awk -F ',' ' { print $2 } ' | awk ' { print $2 } '`
SCREEN_HEIGHT=`xrandr | grep current | awk -F ',' ' { print $2 } ' | awk ' { print $4 } '`
fi
[ ${SCREEN_WIDTH} -gt ${SCREEN_HEIGHT} ] && PORTRAIT=
}
device=SCREEN_${MM_SCREEN}[hdmi]
if [ ${!device+_} ]
then
HDMI=${!device}
else
HDMI=`xrandr --listactivemonitors | grep ${MM_SCREEN}: | awk ' { print $4 } '`
fi
# -----------------------------------------------------------------------
CONFDIR="${MM}/config"
CSSDIR="${MM}/css"
# MagicMirror configuration files organized into subdirectories listed here
CONF_SUBDIRS="Artists JAV Models Photos Photographers YouTube test"
MMCFMSG="MagicMirror configuration file"
SLISDIR="${MCL_HOME}/pics"
ARTIST_TEMPLATE="${CONFDIR}/Templates/config-artist-template.js"
JAV_TEMPLATE="${CONFDIR}/Templates/config-jav-template.js"
MODEL_TEMPLATE="${CONFDIR}/Templates/config-model-template.js"
PHOTO_TEMPLATE="${CONFDIR}/Templates/config-photo-template.js"
WHVN_TEMPLATE="${CONFDIR}/Templates/config-whvn-template.js"
WHVNDIR="Pictures/Wallhaven"
CONFS=
PLEASE="Please enter your MagicMirror"
NUMPROMPT="Enter either a number or text of one of the menu entries"
SUBDIR_CONFS=
START_DEV=
TELEGRAM=
ERROR_EXIT=1
INFO="all"
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
usejq=`type -p jq`
usepm2=`type -p pm2`
# Need this if not using PM2 because MagicMirror does not have a 'stop' npm script
mirror_stop() {
ps -ef | grep pocket | grep -v "grep" | awk '{print $2}' | while read pocketpid
do
sudo kill -9 ${pocketpid} > /dev/null 2>&1
done
ps -ef | grep node | grep -v "grep" | awk '{print $2}' | while read nodepid
do
sudo kill -9 ${nodepid} > /dev/null 2>&1
done
ps -ef | grep chromium-browser | grep -v "grep" | awk '{print $2}' | while read chromepid
do
sudo kill -9 ${chromepid} > /dev/null 2>&1
done
}
pm2msg() {
printf "\nPM2 is installed but no PM2 process named ${PM2_PROCESS_NAME}"
printf "\nwas found. Reverting to direct use of npm to manage MagicMirror."
printf "\nIf you wish to use PM2 to manage your MagicMirror via this script"
printf "\nthen create a PM2 process named ${PM2_PROCESS_NAME} that can be"
printf "\nused to start/stop/restart MagicMirror."
printf "\n\nContinuing but some functionality disabled.\n"
usepm2=
}
[ "${usepm2}" ] && {
if [ "${usejq}" ]
then
pm2 jlist | jq .[].name | grep ${PM2_PROCESS_NAME} > /dev/null || pm2msg
else
pm2 list | grep ${PM2_PROCESS_NAME} > /dev/null || pm2msg
fi
}
echo "${apikey}" | grep _Remote-Control-API-Key_ > /dev/null && {
printf "\nMMM-Remote-Control API Key is not configured."
printf "\nEither add your key or comment out the empty setting"
printf "\nfor 'apikey' near the beginning of this script."
printf "\n\nContinuing but some functionality disabled.\n"
}
[ -d "${CONFDIR}" ] || {
printf "\nCONFDIR does not exist or is not a directory. Exiting.\n"
exit ${ERROR_EXIT}
}
cd "${CONFDIR}"
check_config() {
if [ "$1" == "all" ]
then
current=`ls -l config.js | awk ' { print $11 } '`
echo "Saving $current MagicMirror configuration"
for config in config-*.js
do
[ "$config" == "config-*.js" ] && {
echo "No ${MMCFMSG}s config-*.js found in $CONFDIR"
continue
}
rm -f config.js
ln -s ${config} config.js
echo "Checking ${config} ..."
npm run --silent config:check
echo "Done"
done
echo "Restoring $current MagicMirror configuration"
rm -f config.js
if [ -f ${current} ]
then
ln -s ${current} config.js
else
echo "Config file ${current} does not exist. Using default."
setconf default
fi
else
if [ -L config.js ] && [ -f config.js ]
then
npm run --silent config:check
else
if [ -f config.js ]
then
npm run --silent config:check
else
echo "Config file config.js is a broken symbolic link. Removing."
rm -f config.js
echo "Installing default config file, config-default.js"
setconf default
fi
fi
fi
}
display_status() {
vcgencmd display_power | egrep 'display_power=1|On' > /dev/null && \
echo 'Display ON' || echo 'Display OFF'
}
getconfs() {
numconfs=0
CONFS=
for i in config-*.js
do
j=`echo $i | sed -e "s/config-//" -e "s/.js//"`
CONFS="${CONFS} $j"
[ "$1" == "usage" ] && {
numconfs=`expr $numconfs + 1`
[ $numconfs -gt 8 ] && {
CONFS="${CONFS}\n\t"
numconfs=0
}
}
done
[ "$1" == "usage" ] || {
CONFS=`echo "${CONFS}" | tr ' ' '\n' | LC_ALL=C sort | tr '\n' ' '`
}
}
list_mods() {
[ "$1" ] || {
printf "\nArgument of 'active', 'installed', or 'configs' required to list modules."
list_usage
}
if [ "$1" == "active" ]
then
printf "\n${BOLD}Listing Active MagicMirror modules${NORMAL}\n\n"
if [ "${TELEGRAM}" ]
then
if [ "$usejq" ]
then
if [ "${apikey}" ]
then
curl -X GET ${modurl}?apiKey=${apikey} 2> /dev/null | jq '.data | .[] | .name'
else
curl -X GET ${modurl} 2> /dev/null | jq '.data | .[] | .name'
fi
else
printf "\nInstall jq to list active MagicMirror modules\n"
fi
else
if [ "$usejq" ]
then
if [ "${apikey}" ]
then
curl -X GET ${modurl}?apiKey=${apikey} 2> /dev/null | jq .
else
curl -X GET ${modurl} 2> /dev/null | jq .
fi
else
if [ "${apikey}" ]
then
curl -X GET ${modurl}?apiKey=${apikey}
else
curl -X GET ${modurl}
fi
echo ""
fi
fi
else
if [ "$1" == "installed" ]
then
printf "\n${BOLD}Listing Installed MagicMirror modules${NORMAL}\n\n"
if [ "${TELEGRAM}" ]
then
if [ "$usejq" ]
then
if [ "${apikey}" ]
then
curl -X GET ${modurl}/installed?apiKey=${apikey} 2> /dev/null | jq '.data | .[] | .longname'
else
curl -X GET ${modurl}/installed 2> /dev/null | jq '.data | .[] | .longname'
fi
else
printf "\nInstall jq to list installed MagicMirror modules\n"
fi
else
if [ "$usejq" ]
then
if [ "${apikey}" ]
then
curl -X GET ${modurl}/installed?apiKey=${apikey} 2> /dev/null | jq .
else
curl -X GET ${modurl}/installed 2> /dev/null | jq .
fi
else
if [ "${apikey}" ]
then
curl -X GET ${modurl}/installed?apiKey=${apikey}
else
curl -X GET ${modurl}/installed
fi
echo ""
fi
fi
else
if [ "$1" == "configs" ]
then
printf "\n${BOLD}Listing ${MMCFMSG}s:${NORMAL}\n\n"
if [ "${TELEGRAM}" ]
then
# /bin/ls config-*.js | cut -c -4000
configlist=
for c in config-*.js
do
[ "$c" == "config-*.js" ] && continue
echo $c | grep 'sample\|test\|unknown' > /dev/null && continue
#echo $c | grep test > /dev/null && continue
config_name=`echo $c | sed -e "s/config-//" -e "s/.js//"`
configlist="$configlist $config_name"
list_size=`echo $configlist | wc -c`
[ $list_size -gt 350 ] && break
done
[ "$configlist" ] && echo $configlist | sed -e "s/ /\n/g"
else
ls config-*.js
fi
[ "${TELEGRAM}" ] || {
for confdir in __none__ ${CONF_SUBDIRS}
do
[ "${confdir}" == "__none__" ] && continue
[ -d ${confdir} ] && {
printf "\n${BOLD}Listing MagicMirror ${confdir} configuration files:${NORMAL}\n\n"
ls ${confdir}/config-*.js
}
done
}
else
printf "\nmirror list $1 is not an accepted 2nd argument."
printf "\nValid 2nd arguments to the list command are 'active', 'installed', and 'configs'"
list_usage
fi
fi
fi
}
rotate_all_screens() {
[ -f ${MIRRORSCREEN} ] && {
numscreen=0
while [ ${numscreen} -lt ${NUMSCREENS} ]
do
screenmode=SCREEN_${numscreen}[mode]
[ ${!screenmode+_} ] && {
screenmode=${!screenmode}
hdmi=SCREEN_${numscreen}[hdmi]
[ ${!hdmi+_} ] && {
hdmi=${!hdmi}
if [ "${screenmode}" ]
then
printf "\n${BOLD}Rotating ${hdmi} screen ${numscreen} right ${NORMAL}\n"
xrandr --output ${hdmi} --auto --rotate right
else
printf "\n${BOLD}Rotating ${hdmi} screen ${numscreen} normal ${NORMAL}\n"
xrandr --output ${hdmi} --auto --rotate normal
fi
printf "\n${BOLD}Done${NORMAL}\n"
}
}
((numscreen+=1))
done
}
}
rotate_screen() {
case "$1" in
inverted|left|right|normal)
[ "${HDMI}" ] && {
printf "\n${BOLD}Rotating screen display $1 ${NORMAL}\n"
xrandr --output ${HDMI} --rotate $1
printf "\n${BOLD}Done${NORMAL}\n"
}
;;
default)
rotate_all_screens
;;
*)
printf "\nUsage: rotate option takes an argument of 'left', 'right',"
printf "\n\t'inverted', 'default', or 'normal'"
printf "\n Exiting.\n"
usage
;;
esac
}
set_screen() {
scn=$1
curscr=${MM_SCREEN}
[ "${scn}" == "one" ] && scn=1
[ "${scn}" == "two" ] && scn=2
[ "${scn}" == "switch" ] && {
((MM_SCREEN+=1))
[ ${MM_SCREEN} -ge ${NUMSCREENS} ] && MM_SCREEN=0
scn=${MM_SCREEN}
}
if [ "${scn}" -eq "${scn}" ] 2> /dev/null
then
[ ${scn} -eq 0 ] && scn=1
((scn-=1))
switched=
hdmi=SCREEN_${scn}[hdmi]
if [ ${!hdmi+_} ]
then
if [ ${curscr} -eq ${scn} ]
then
echo "Current screen is already set to $1"
else
HDMI=${!hdmi}
[ -f ${MIRRORSCREEN} ] && {
cat ${MIRRORSCREEN} | sed -e "s/^MM_SCREEN=.*/MM_SCREEN=${scn}/" > /tmp/mm$$
cp /tmp/mm$$ ${MIRRORSCREEN}
rm -f /tmp/mm$$
MM_SCREEN=${scn}
screen=SCREEN_${MM_SCREEN}[mode]
[ ${!screen+_} ] && {
[ "${PORTRAIT}" == "${!screen}" ] || {
# The screen mode is switching between portrait and landscape
# Check to see if we need to switch out the config.js
cd "${CONFDIR}"
if [ "${PORTRAIT}" ]
then
MM_CONFDIR="config-landscape"
TG_CONFDIR="config-landscape-notelegram"
[ -L ${CONFDIR}/config.js ] && {
CONFLINK=`readlink ${CONFDIR}/config.js`
echo ${CONFLINK} | grep landscape > /dev/null || {
NEWLINK=`dirname ${CONFLINK} | sed -e "s/config-/config-landscape/"`
OLDBASE=`basename ${CONFLINK}`
[ -f ${NEWLINK}/${OLDBASE} ] && {
# Relink to landscape mode version of this config file
rm -f config.js
ln -s ${NEWLINK}/${OLDBASE} config.js
switched=1
}
}
}
else
MM_CONFDIR="config"
TG_CONFDIR="config-notelegram"
[ -L ${CONFDIR}/config.js ] && {
CONFLINK=`readlink ${CONFDIR}/config.js`
echo ${CONFLINK} | grep landscape > /dev/null && {
NEWLINK=`dirname ${CONFLINK} | sed -e "s/config-landscape/config-/"`
OLDBASE=`basename ${CONFLINK}`
[ -f ${NEWLINK}/${OLDBASE} ] && {
# Relink to portrait mode version of this config file
rm -f config.js
ln -s ${NEWLINK}/${OLDBASE} config.js
switched=1
}
}
}
fi
}
PORTRAIT=${!screen}
}
((scn+=1))
[ -x /usr/local/bin/mmscreen ] && /usr/local/bin/mmscreen ${scn}
[ "${switched}" ] && {
[ -L ${MCL_HOME}/pics ] && {
rm -f ${MCL_HOME}/pics
if [ "${PORTRAIT}" ]
then
[ -d ${MCL_HOME}/pics-portrait ] && {
ln -s ${MCL_HOME}/pics-portrait ${MCL_HOME}/pics
}
else
[ -d ${MCL_HOME}/pics-landscape ] && {
ln -s ${MCL_HOME}/pics-landscape ${MCL_HOME}/pics
}
fi
}
pm2 restart MagicMirror --update-env
}
}
fi
else
echo "No configured screen number ${scn}"
fi
else
usage
fi
}
screen_control() {
if [ "$1" ]
then
if [ "$1" == "on" ]
then
vcgencmd display_power 1 > /dev/null
else
if [ "$1" == "off" ]
then
vcgencmd display_power 0 > /dev/null
else
if [ "$1" == "status" ] || [ "$1" == "info" ]
then
INFO="screen"
system_info
else
set_screen $1
fi
fi
fi
else
INFO="screen"
system_info
fi
}
screen_shot() {
SCREEN_SHOT_DIR=$HOME/Pictures/ScreenShots
[ -d ${SCREEN_SHOT_DIR} ] || mkdir -p ${SCREEN_SHOT_DIR}
havescrot=`type -p scrot`
if [ "$havescrot" ]
then
printf "\n${BOLD}Saving PNG format screenshot in ${SCREEN_SHOT_DIR}${NORMAL}\n"
scrot -e 'mv $f ~/Pictures/ScreenShots'
else
printf "\n${BOLD}Could not locate scrot command in $PATH${NORMAL}\n"
printf "\n${BOLD}Install scrot with 'sudo apt-get install scrot'${NORMAL}\n"
fi
printf "\n${BOLD}Done${NORMAL}\n"
}
start_dev() {
printf "\n${BOLD}Starting MagicMirror in developer mode${NORMAL}\n"
cd "${MM}"
# export ELECTRON_ENABLE_LOGGING=true
if [ "${usepm2}" ]
then
pm2 stop MagicMirror
else
mirror_stop
fi
npm start dev
printf "\n${BOLD}Done${NORMAL}\n"
}
get_brightness() {
printf "\n${BOLD}MagicMirror Brightness Level:${NORMAL} "
if [ "$usejq" ]
then
if [ "${apikey}" ]
then
curl -X GET http://${IP}:${PORT}/api/brightness?apiKey=${apikey} 2> /dev/null | jq '.result'
else
curl -X GET http://${IP}:${PORT}/api/brightness 2> /dev/null | jq '.result'
fi
else
if [ "${apikey}" ]
then
curl -X GET http://${IP}:${PORT}/api/brightness?apiKey=${apikey}
else
curl -X GET http://${IP}:${PORT}/api/brightness
fi
echo ""
fi
}
set_brightness() {
[ "$1" ] || {
printf "\nNumeric argument required to specify Mirror brightness.\n"
setb_usage
}
if [ "$1" -ge 0 ] && [ "$1" -le 200 ]
then
printf "\n${BOLD}Setting MagicMirror Brightness Level to $1${NORMAL}\n"
if [ "$usejq" ]
then
if [ "${apikey}" ]
then
curl -X GET http://${IP}:${PORT}/api/brightness/$1?apiKey=${apikey} 2> /dev/null | jq .
else
curl -X GET http://${IP}:${PORT}/api/brightness/$1 2> /dev/null | jq .
fi
else
if [ "${apikey}" ]
then
curl -X GET http://${IP}:${PORT}/api/brightness/$1?apiKey=${apikey}
else
curl -X GET http://${IP}:${PORT}/api/brightness/$1
fi
echo ""
fi
else
printf "\nBrightness setting $1 out of range or not a number"
printf "\nValid brightness values are integer values [0-200]\n"
setb_usage
fi
}
set_volume() {
[ "$1" ] || {
printf "\nArgument required to specify Mirror volume.\n"
vol_usage
}
havevol=`type -p vol`
if [ "$havevol" ]
then
case "$1" in
"mute")
echo "Muting MagicMirror volume"
vol -q -m
;;
"unmute")
echo "Unmuting MagicMirror volume"
vol -q -m
;;
"save")
echo "Saving MagicMirror volume"
vol -q -s
;;
"restore")
echo "Restoring MagicMirror volume"
vol -q -r
;;
"get")
echo "Retrieving MagicMirror volume"
vol
;;
*)
echo "Setting MagicMirror volume to $1 percent"
vol -q $1
;;
esac
else
echo "Cannot locate vol script."
echo "Install vol.sh from the MirrorCommand repository."
fi
}
act_scene() {
printf "\n${BOLD}MMM-Scenes scene by name/id${NORMAL}\n"
case "$1" in
[0-9]*)
scenespec="index=$1"
;;
*)
scenespec="name=$1"
;;
esac
if [ "$usejq" ]
then
if [ "${apikey}" ]
then
curl -X GET "${apiurl}/SCENES_ACT?${scenespec}&apiKey=${apikey}" 2> /dev/null | jq .
else
curl -X GET "${apiurl}/SCENES_ACT?${scenespec}" 2> /dev/null | jq .
fi
else
if [ "${apikey}" ]
then
curl -X GET "${apiurl}/SCENES_ACT?${scenespec}&apiKey=${apikey}"
else
curl -X GET "${apiurl}/SCENES_ACT?${scenespec}"
fi
echo ""
fi
}
info_scene() {
printf "\n${BOLD}MMM-Scenes configuration info${NORMAL}\n"
if [ "$usejq" ]
then
if [ "${apikey}" ]
then
curl -X GET ${modurl}/MMM-Scenes?apiKey=${apikey} 2> /dev/null | jq .
else
curl -X GET ${modurl}/MMM-Scenes 2> /dev/null | jq .
fi
else
if [ "${apikey}" ]
then
curl -X GET ${modurl}/MMM-Scenes?apiKey=${apikey}
else
curl -X GET ${modurl}/MMM-Scenes
fi
echo ""
fi
}
next_scene() {
printf "\n${BOLD}Next MMM-Scenes scene${NORMAL}\n"
if [ "$usejq" ]
then
if [ "${apikey}" ]
then
curl -X GET ${apiurl}/SCENES_NEXT?apiKey=${apikey} 2> /dev/null | jq .
else
curl -X GET ${apiurl}/SCENES_NEXT 2> /dev/null | jq .
fi
else
if [ "${apikey}" ]
then
curl -X GET ${apiurl}/SCENES_NEXT?apiKey=${apikey}
else
curl -X GET ${apiurl}/SCENES_NEXT
fi
echo ""
fi
}
prev_scene() {
printf "\n${BOLD}Previous MMM-Scenes scene${NORMAL}\n"
if [ "$usejq" ]
then
if [ "${apikey}" ]
then
curl -X GET ${apiurl}/SCENES_PREV?apiKey=${apikey} 2> /dev/null | jq .
else
curl -X GET ${apiurl}/SCENES_PREV 2> /dev/null | jq .
fi
else
if [ "${apikey}" ]
then
curl -X GET ${apiurl}/SCENES_PREV?apiKey=${apikey}
else
curl -X GET ${apiurl}/SCENES_PREV
fi
echo ""
fi
}
hide_video() {
printf "\n${BOLD}Hide MagicMirror Video${NORMAL}\n"
if [ "$usejq" ]
then
if [ "${apikey}" ]
then
curl -X GET ${modurl}/MMM-Videoplayer/hide?apiKey=${apikey} 2> /dev/null | jq .
else
curl -X GET ${modurl}/MMM-Videoplayer/hide 2> /dev/null | jq .
fi
else
if [ "${apikey}" ]
then
curl -X GET ${modurl}/MMM-Videoplayer/hide?apiKey=${apikey}
else
curl -X GET ${modurl}/MMM-Videoplayer/hide
fi
echo ""
fi
}
show_video() {
printf "\n${BOLD}Show MagicMirror Video${NORMAL}\n"
if [ "$usejq" ]
then
if [ "${apikey}" ]
then
curl -X GET ${modurl}/MMM-Videoplayer/show?apiKey=${apikey} 2> /dev/null | jq .
else
curl -X GET ${modurl}/MMM-Videoplayer/show 2> /dev/null | jq .
fi
else
if [ "${apikey}" ]
then
curl -X GET ${modurl}/MMM-Videoplayer/show?apiKey=${apikey}
else
curl -X GET ${modurl}/MMM-Videoplayer/show
fi
echo ""
fi
}
next_video() {
printf "\n${BOLD}Play Next MagicMirror Video${NORMAL}\n"
if [ "$usejq" ]
then
if [ "${apikey}" ]
then
curl -X GET ${apiurl}/VIDEOPLAYER1/NEXT?apiKey=${apikey} 2> /dev/null | jq .
else
curl -X GET ${apiurl}/VIDEOPLAYER1/NEXT 2> /dev/null | jq .
fi
else
if [ "${apikey}" ]
then
curl -X GET ${apiurl}/VIDEOPLAYER1/NEXT?apiKey=${apikey}
else
curl -X GET ${apiurl}/VIDEOPLAYER1/NEXT
fi
echo ""
fi
}
replay_video() {
printf "\n${BOLD}Replay MagicMirror Video${NORMAL}\n"
if [ "$usejq" ]
then
if [ "${apikey}" ]
then
curl -X GET ${apiurl}/VIDEOPLAYER1/REPLAY?apiKey=${apikey} 2> /dev/null | jq .
else
curl -X GET ${apiurl}/VIDEOPLAYER1/REPLAY 2> /dev/null | jq .
fi
else
if [ "${apikey}" ]
then
curl -X GET ${apiurl}/VIDEOPLAYER1/REPLAY?apiKey=${apikey}
else
curl -X GET ${apiurl}/VIDEOPLAYER1/REPLAY
fi
echo ""
fi
}
toggle_videoplay() {
printf "\n${BOLD}Toggle MagicMirror Video Play/Pause${NORMAL}\n"
if [ "$usejq" ]
then
if [ "${apikey}" ]
then
curl -X GET ${apiurl}/VIDEOPLAYER1/TOGGLE?apiKey=${apikey} 2> /dev/null | jq .
else
curl -X GET ${apiurl}/VIDEOPLAYER1/TOGGLE 2> /dev/null | jq .
fi
else
if [ "${apikey}" ]
then
curl -X GET ${apiurl}/VIDEOPLAYER1/TOGGLE?apiKey=${apikey}
else
curl -X GET ${apiurl}/VIDEOPLAYER1/TOGGLE
fi
echo ""
fi
}
model_create() {
[ "$1" ] || {
printf "\nFolder argument required to specify Slideshow dir.\n"
usage
}
PICDIR="$1"
# Create a configuration file for this model if one does not exist
printf "\nCreating config file ${CONFDIR}/Models/config-${PICDIR}.js\n"
cd "${CONFDIR}/Models"
[ -f "config-${PICDIR}.js" ] || {
if [ -f ${MODEL_TEMPLATE} ]
then
cat ${MODEL_TEMPLATE} | sed -e "s/MODEL_DIR_HOLDER/${PICDIR}/" > "config-${PICDIR}.js"
else
echo "Model config template $MODEL_TEMPLATE not found"
exit ${ERROR_EXIT}
fi
}
if [ -d "${SLISDIR}/Models/${PICDIR}" ]
then
# Already have a prepared folder for this model
printf "\nUsing existing model folder pics\n"
setconf ${PICDIR} Models
else
if [ -x ${MCL_HOME}/bin/mknewmodel ]
then
${MCL_HOME}/bin/mknewmodel ${PICDIR}
else
echo "${MCL_HOME}/bin/mknewmodel does not exist or is not executable."
fi
fi
}
model_remove() {
[ "$1" ] || {
printf "\nFolder argument required to specify Slideshow dir.\n"
usage
}
PICDIR="$1"
[ -d "${SLISDIR}/Models/${PICDIR}" ] && {
printf "\nRemoving config file and pic folder for Models/${PICDIR}\n"
rm -rf "${SLISDIR}/Models/${PICDIR}"
}
rm -f "${CONFDIR}/Models/config-${PICDIR}.js"
set_config default
}
artist_create() {
[ "$1" ] || {
printf "\nFolder argument required to specify Slideshow dir.\n"
usage
}
PICDIR="$1"
printf "\nCreating config file ${CONFDIR}/Artists/config-${PICDIR}.js\n"
cd "${CONFDIR}/Artists"
[ -f "config-${PICDIR}.js" ] || {
if [ -f ${ARTIST_TEMPLATE} ]
then
cat ${ARTIST_TEMPLATE} | sed -e "s/ARTIST_DIR_HOLDER/${PICDIR}/" > "config-${PICDIR}.js"
else
echo "Artist config template $ARTIST_TEMPLATE not found"
exit ${ERROR_EXIT}
fi
}
if [ -d "${MCL_HOME}/pics/Artists/${PICDIR}" ]
then
# Already have a prepared folder for this artist
printf "\nUsing existing ${PICDIR} image folder\n"
setconf ${PICDIR} Artists
else
if [ -x ${MCL_HOME}/bin/mknewartist ]
then
${MCL_HOME}/bin/mknewartist ${PICDIR}
else
echo "${MCL_HOME}/bin/mknewartist does not exist or is not executable."
fi
fi
}
artist_remove() {
[ "$1" ] || {
printf "\nFolder argument required to specify Slideshow dir.\n"
usage
}
PICDIR="$1"
[ -d "${SLISDIR}/Artists/${PICDIR}" ] && {
printf "\nRemoving config file and pic folder for Artists/${PICDIR}\n"
rm -rf "${SLISDIR}/Artists/${PICDIR}"
}
rm -f "${CONFDIR}/Artists/config-${PICDIR}.js"
set_config default
}
jav_create() {
[ "$1" ] || {
printf "\nFolder argument required to specify Slideshow dir.\n"
usage
}
PICDIR="$1"
printf "\nCreating config file ${CONFDIR}/JAV/config-${PICDIR}.js\n"
cd "${CONFDIR}/JAV"
[ -f "config-${PICDIR}.js" ] || {
if [ -f ${JAV_TEMPLATE} ]
then
cat ${JAV_TEMPLATE} | sed -e "s/JAV_DIR_HOLDER/${PICDIR}/" > "config-${PICDIR}.js"
else
echo "JAV config template $JAV_TEMPLATE not found"
exit ${ERROR_EXIT}
fi
}
if [ -d "${MCL_HOME}/pics/JAV/${PICDIR}" ]
then
# Already have a prepared folder for this photographer
printf "\nUsing existing ${PICDIR} image folder\n"
setconf ${PICDIR} JAV
else
if [ -x ${MCL_HOME}/bin/mknewjav ]
then
${MCL_HOME}/bin/mknewjav ${PICDIR}
else
echo "${MCL_HOME}/bin/mknewjav does not exist or is not executable."
fi