-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcncjs_install.sh
1687 lines (1378 loc) · 72 KB
/
cncjs_install.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
#!/usr/bin/env bash
# ===========================================================================
# CNCjs Installer
# - https://cnc.js.org
# - https://github.com/cncjs
#
# How-to Use:
# curl -sSL https://raw.githubusercontent.com/cncjs/cncjs-pi-raspbian/master/cncjs_install.sh | bash
#
# License: MIT License
# Copyright (c) 2018-2020 CNCjs (https://github.com/cncjs)
#
# Notes:
# Replaces Prebuilt Images: https://github.com/cncjs/cncjs-pi-raspbian
# Builds from raspi-config https://github.com/RPi-Distro/raspi-config (MIT license)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SCRIPT_TITLE="CNCjs Installer"
SCRIPT_VERSION=1.4.7
SCRIPT_DATE=$(date -I --date '2024/07/12')
SCRIPT_AUTHOR="Austin St. Aubin"
SCRIPT_TITLE_FULL="${SCRIPT_TITLE} v${SCRIPT_VERSION}($(date -I -d ${SCRIPT_DATE})) by: ${SCRIPT_AUTHOR}"
# ===========================================================================
# ----------------------------------------------------------------------------------------------------------------------------------
# -- [ Error / Exception Handling ]
# ----------------------------------------------------------------------------------------------------------------------------------
# -e option instructs bash to immediately exit if any command [1] has a non-zero exit status
# We do not want users to end up with a partially working install, so we exit the script
# instead of continuing the installation with something broken
# set -e
# Catch Expections to users home directory.
cd ~/
# ----------------------------------------------------------------------------------------------------------------------------------
# -- Varrables [ General ] genneral global varables
# ----------------------------------------------------------------------------------------------------------------------------------
readonly SCRIPT_NAME=$(basename $0)
readonly HOST_IP=$(hostname -I | cut -d' ' -f1)
SYSTEM_CHECK=true # Preform system check to insure this script is known to be compatable with this OS
CNCJS_EXT_DIR="${HOME}/.cncjs"
CNCJS_PORT=80
cncjs_flags="--port ${CNCJS_PORT} --watch-directory \\\"${CNCJS_EXT_DIR}/watch\\\"" # --host ${HOST_IP}
COMPATIBLE_OS_ID='^(rasp|de)bian$'
COMPATIBLE_OS_ID_VERSION=11 # greater than or equal
# Detect Compatible GUI
[[ $(dpkg -l|egrep -i "(lxde|openbox)" | grep -v library) ]] && COMPATIBLE_OS_GUI=true || COMPATIBLE_OS_GUI=false
# ----------------------------------------------------------------------------------------------------------------------------------
# -- [ Logging ] log hidden output to journal for use in debugging
# ----------------------------------------------------------------------------------------------------------------------------------
# Sends stdout output to journal.
# To Use/View Journal, use command: journalctl --identifier=cncjs --identifier=cncjs_installer --lines=50 --follow --pager-end
exec 4> >(logger -t cncjs_installer)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Color / Messange Handling
COL_NC='\e[0m' # No Color
COL_GREY='\e[2;31;37m'
COL_BLACK='\e[1;30m'
COL_RED='\e[1;31m'
COL_GREEN='\e[1;32m'
COL_YELLOW='\e[1;33m'
COL_BLUE='\e[1;34m'
COL_MAGENTA='\e[1;35m'
COL_CYAN='\e[1;36m'
COL_WHITE='\e[1;37m'
# Message
PASS="${COL_NC}[${COL_GREEN}✓${COL_NC}]"
FAIL="${COL_NC}[${COL_RED}✗${COL_NC}]"
WARN="${COL_NC}[${COL_YELLOW}"'!'"${COL_NC}]"
INFO="${COL_NC}[${COL_CYAN}i${COL_NC}]"
QSTN="${COL_NC}[${COL_MAGENTA}?${COL_NC}]"
# ----------------------------------------------------------------------------------------------------------------------------------
# -- Function [ Spinner ] spinner animation for commands in progress.
# ----------------------------------------------------------------------------------------------------------------------------------
# https://unix.stackexchange.com/questions/225179/display-spinner-while-waiting-for-some-process-to-finish
# https://wiki.tcl-lang.org/page/Text+Spinner
function spinner() {
# make sure we use non-unicode character type local
# (that way it works for any locale as long as the font supports the characters)
local LC_CTYPE=C
local spin_chars=' ⣷ ⣯ ⣟ ⡿ ⢿ ⣻ ⣽ ⣾ '
local pid=$1 # Process Id of the previous running command
tput civis # cursor invisible
# spin animation
###while kill -0 $pid 2>/dev/null; do
while ps -p $pid >/dev/null; do
for spin_i in ${spin_chars[@]}; do
echo -ne "\r [$spin_i] $2 ";
sleep 0.1;
done;
done
tput cnorm # cursor visible
wait $pid # capture exit code
return $?
}
# ----------------------------------------------------------------------------------------------------------------------------------
# -- Function [ Message ] message formatter, also used for passing commands.
# ----------------------------------------------------------------------------------------------------------------------------------
msg() {
# Logging to journal
logger -p user.notice -t cncjs_installer "$2"
# User Output
case $1 in
'h') # Header
printf "\\n %b ${2} %b\\n" "${COL_WHITE}" "${COL_NC} "
;;
'p') # Pass
printf " %b %b ${2} %b\\n" "${PASS}" "${COL_GREEN}" "${COL_NC} "
;;
'x') # Fail
printf " %b %b ${2} %b\\n" "${FAIL}" "${COL_RED}" "${COL_NC} "
;;
'!') # Warning
printf " %b %b ${2} %b\\n" "${WARN}" "${COL_YELLOW}" "${COL_NC} "
;;
'i') # Informational
printf " %b %b ${2} %b\\n" "${INFO}" "${COL_WHITE}" "${COL_NC} "
;;
'?') # Question
printf " %b %b ${2} %b\\n" "${QSTN}" "${COL_NC}" "${COL_NC} "
;;
'L') # Bracket
printf " %b └── ${2} %b\\n" "${COL_GREY}" "${COL_NC} "
;;
'-') # User Log Output
line_break='- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
echo -e "${COL_GREY} ${2} ${line_break:${#2} + 1}\n ${3}\n ${line_break} ${COL_NC}"
;;
'%') # Spinner / Command
/bin/sh -c "${3}" >&4 2>&1 & spinner $! "${2}"
# Capture Error Code
ERROR_CODE=$?
# Display Pass/Fail based on error Code
if [[ ${ERROR_CODE} -eq 0 ]]; then
echo -ne "\r ${PASS} ${COL_GREEN} ${2} ${COL_NC} \n";
else
echo -ne "\r ${FAIL} ${COL_RED} ${2} ${COL_GREY}|${COL_YELLOW} Error Code: ${ERROR_CODE} ${COL_NC} \n";
echo -e " └── Try to re-run this part of the script after rebooting."
msg - "Latest Journal Entries" "$(journalctl -n 6 --no-pager)"
fi
# Return Error Code
return ${ERROR_CODE}
;;
'%%') # Spinner / Command (No stdout Catpture, only capture stderr)
/bin/sh -c "${3}" 2>&4 & spinner $! "${2}"
# Capture Error Code
ERROR_CODE=$?
# Display Pass/Fail based on error Code
if [[ ${ERROR_CODE} -eq 0 ]]; then
echo -ne "\r ${PASS} ${COL_GREEN} ${2} ${COL_NC} \n";
else
echo -ne "\r ${FAIL} ${COL_RED} ${2} ${COL_GREY}|${COL_YELLOW} Error Code: ${ERROR_CODE} ${COL_NC} \n";
echo -e "└── Try to re-run this part of the script after rebooting."
msg - "Latest Journal Entries" "$(tail -n 6 /var/log/journal)"
fi
# Return Error Code
return ${ERROR_CODE}
;;
*) # Catch-all
echo -e "${@}"
;;
esac
}
# # ----------------------------------------------------------------------------------------------------------------------------------
# # -- Function [ Calculate Whiptail Size ] spinner animation for commands in progress. From raspi-config (MIT license)
# # ----------------------------------------------------------------------------------------------------------------------------------
# calc_wt_size() {
# # NOTE: it's tempting to redirect stderr to /dev/null, so supress error
# # output from tput. However in this case, tput detects neither stdout or
# # stderr is a tty and so only gives default 80, 24 values
# WT_HEIGHT=18
# WT_WIDTH=$(tput cols)
# if [ -z "$WT_WIDTH" ] || [ "$WT_WIDTH" -lt 60 ]; then
# WT_WIDTH=80
# fi
# if [ "$WT_WIDTH" -gt 178 ]; then
# WT_WIDTH=120
# fi
# WT_MENU_HEIGHT=$(($WT_HEIGHT-7))
# }
# ----------------------------------------------------------------------------------------------------------------------------------
# -- Function [ Set/Clear/Get Varables & Settings ] set/clear/get varables to/from file. From raspi-config (MIT license)
# ----------------------------------------------------------------------------------------------------------------------------------
set_config_var() {
touch "$3"
lua - "$1" "$2" "$3" <<EOF > "$3.bak"
local key=assert(arg[1])
local value=assert(arg[2])
local fn=assert(arg[3])
local file=assert(io.open(fn))
local made_change=false
for line in file:lines() do
if line:match("^#?%s*"..key.."=.*$") then
line=key.."="..value
made_change=true
end
print(line)
end
if not made_change then
print(key.."="..value)
end
EOF
mv "$3.bak" "$3"
}
clear_config_var() {
touch "$3"
lua - "$1" "$2" <<EOF > "$2.bak"
local key=assert(arg[1])
local fn=assert(arg[2])
local file=assert(io.open(fn))
for line in file:lines() do
if line:match("^%s*"..key.."=.*$") then
line="#"..line
end
print(line)
end
EOF
mv "$2.bak" "$2"
}
get_config_var() {
lua - "$1" "$2" <<EOF
local key=assert(arg[1])
local fn=assert(arg[2])
local file=assert(io.open(fn))
local found=false
for line in file:lines() do
local val = line:match("^%s*"..key.."=(.*)$")
if (val ~= nil) then
print(val)
found=true
break
end
end
if not found then
print(0)
end
EOF
}
# ----------------------------------------------------------------------------------------------------------------------------------
# -- Output [ Header ] welcome message
# ----------------------------------------------------------------------------------------------------------------------------------
# $(curl --silent "https://api.github.com/repos/cncjs/cncjs/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")') # Get CNCjs Latest Version
echo -e "${COL_BLACK}${SCRIPT_TITLE_FULL}${COL_NC}
_______ ________ _
/ ____/ | / / ____/ (_)____
/ / / |/ / / / / ___/
/ /___/ /| / /___ / (__ )
\____/_/ |_/\____/_/ /____/
/___/
Installing CNCjs
- https://cnc.js.org
- https://github.com/cncjs
CNCjs is a full-featured web-based interface for CNC controllers running Grbl, Marlin, Smoothieware, or TinyG.
For a more complete introduction, see the Introduction section of the wiki page ( \e]8;;https://github.com/cncjs/cncjs/wiki/Introduction\ahttps://github.com/cncjs/cncjs/wiki/Introduction\e]8;;\a ).
${COL_GREY}NOTE: This installer logs to journal. You can view the journal, with terminal command: journalctl --identifier=cncjs --identifier=cncjs_installer --lines=50 --follow --pager-end ${COL_NC}
${COL_WHITE}==========================================================================${COL_NC}"
# Log Infomation
echo "===== Starting CNCjs Install Script =====" >&4
# ----------------------------------------------------------------------------------------------------------------------------------
# -- Menu [ Menu Welcome ] welcome message
# ----------------------------------------------------------------------------------------------------------------------------------
# https://en.wikibooks.org/wiki/Bash_Shell_Scripting/Whiptail
# https://www.bradgillap.com/guide/post/bash-gui-whiptail-menu-tutorial-series-1
# https://gist.github.com/wafsek/b78cb3214787a605a28b
message="This script will install the lastest version of CNCjs w/ NodeJS.
https://github.com/cncjs
*THIS INSTALL SCRIPT IS STILL IN BETA, IT MIGHT HAVE ISSUES.*
Please report any issues with this install script to: https://github.com/cncjs/cncjs-pi-raspbian/issues
If any part of this script fails, try reboooting, then re-run this script.
CNCjs is a full-featured web-based interface for CNC controllers running Grbl, Marlin, Smoothieware, or TinyG. Such CNC controllers are often implemented with a tiny embedded computer such as an Arduino with added hardware for controlling stepper motors, spindles, lasers, 3D printing extruders, and the like. The GCode commands that tell the CNC controller what to do are fed to it from a serial port.
PRESS 'ESC' or 'CTRL + C' TO ABORT INSTALL AT ANY TIME.
Press 'ok' to start install of the lastest version of CNCjs w/ NodeJS"
whiptail --msgbox --title "Introduction" "$message" 20 76
# ----------------------------------------------------------------------------------------------------------------------------------
# -- Menu [ Main Check List ] main installer options for installer
# ----------------------------------------------------------------------------------------------------------------------------------
# https://saveriomiroddi.github.io/Shell-scripting-adventures-part-3/
# https://www.shell-tips.com/bash/arrays/
# Menu Checklist CNCjs Pendants & Widgets
whiptail_title="CNCjs Install Options"
whiptail_message='Install script for CNCjs on Raspberry Pi w/ Raspberry Pi OS\n\nThis install script with get you started quickly with CNCjs on a Raspberry Pi. For a more complete introduction, see the CNCjs Introduction section of the wiki page.\n\nPlease select the best options for your install needs.'
# whiptail_list_entry_options=()
declare whiptail_list_entry_options=(\
"A00 System Check" "Preform system check to insure this script is known to be compatable with this OS." "YES" \
"A01 System Update" "Update System Pacakages." "YES" \
"A02 Install/Update Node.js & NPM via Package Manager" "Install the required NodeJS Framework and Dependacies." "YES" \
"A03 Install CNCjs with NPM" "Install CNCjs unsing Node Package Manager." "YES" \
"A04 Install CNCjs Pendants & Widgets" "(Optional) Install CNCjs Extentions." "YES" \
"A05 Create CNCjs Service for Autostart" "Setup autostart so CNCjs starts when Raspberry Pi boots." "YES" \
# "A06 Setup IPtables" "(Optional) Allows to access web ui from 80 to make web access easier." "YES" \
"A07 Setup Web Kiosk" "(Optional) Setup Chrome Web Kiosk UI to start on boot." "NO" \
"A08 Install & Setup Streamer" "(Optional) Stream connected camera with mjpg stream to a webpage [uStreamer/MPEG-Streamer]." "NO" \
"A09 Install & Setup FFmpeg" "(Optional) Record MPEG Streams from MJPG streaming service and save to file." "NO" \
"A10 Reboot" "(Optional) Reboot after install." "NO" \
"A12 Remove Old NodeJS & NPM Packages" "(Optional) Remove NodeJS or NPM Packages that might have been install incorrectly." "NO" \
)
whiptail_list_entry_count=$((${#whiptail_list_entry_options[@]} / 3 ))
# Present Checklist
whiptail_list_selected_descriptions=$(whiptail --checklist --separate-output --title "${whiptail_title}" "${whiptail_message}" 20 164 $whiptail_list_entry_count -- "${whiptail_list_entry_options[@]}" 3>&1 1>&2 2>&3)
main_list_entry_selected=()
mapfile -t main_list_entry_selected <<< "$whiptail_list_selected_descriptions"
# for checklist_selected_name in "${main_list_entry_selected[@]}"; do
# echo "Selected Name: ${checklist_selected_name}"
# done
# echo " - - - - - - - - "
# echo ${main_list_entry_selected[*]}
# echo ${!main_list_entry_selected[*]}
# echo ${#main_list_entry_selected[*]}
# echo ${main_list_entry_selected[@]}
# echo ${!main_list_entry_selected[@]}
# echo ${#main_list_entry_selected[@]}
# echo " - - - - - - - - "
# ----------------------------------------------------------------------------------------------------------------------------------
# -- Menu [ CNCjs Addons Check List ] selection of CNCjs Addons / Extentions / Pendants & Widgets
# ----------------------------------------------------------------------------------------------------------------------------------
if [[ ${main_list_entry_selected[*]} =~ 'A04' ]]; then
# Menu Checklist CNCjs Pendants & Widgets
whiptail_title="CNCjs Pendants & Widgets"
whiptail_message='CNCjs Pendants and Widgets entend the funtionality of the platform.\n\nThe user interface is organized as a collection of "widgets", each of which manages a specific aspect of machine control. For example, there are widgets for things like toolpath display, jogging, position reporting, spindle control, and many other functions. Users can control which widgets appear on the screen, omitting ones that do not apply to their machine. There is a way to add custom widgets to support new features. \nExample boilerplate pendant can be found at: https://github.com/cncjs/cncjs-pendant-boilerplate\n\nFinally, there is a collection of "pendants" - specialized user interfaces optimized for simplified control panels such as small LCD screens, wireless keyboards, button panels, and the like. Pendants interact with the cncjs server using subsets of the full set of functions that the main user interface uses.\nExample boilerplate pendant can be found at: https://github.com/cncjs/cncjs-pendant-boilerplate\n\nPlease select the Pendants and Widgets you would like to install:'
declare -A whiptail_list_options=(\
[Pendant TinyWeb]="https://github.com/cncjs/cncjs-pendant-tinyweb","NO" \
[Pendant Shopfloor Tablet]="https://github.com/cncjs/cncjs-shopfloor-tablet","YES" \
[Widget Boilerplate]="https://github.com/cncjs/cncjs-widget-boilerplate","NO" \
[Kiosk Custom Webpage]="A customizable web page at: ${CNCJS_EXT_DIR}/kiosk/index.html","NO" \
)
whiptail_list_entry_options=()
whiptail_list_entry_count=${#whiptail_list_options[@]}
for entry in "${!whiptail_list_options[@]}"; do
# echo "TESTING: whiptail_list_options[$entry]}:${whiptail_list_options[$entry]} | entry:$entry | ### $(echo ${whiptail_list_options[$entry]} | cut -d',' -f2)"
whiptail_list_entry_options+=("$entry")
whiptail_list_entry_options+=("$(echo ${whiptail_list_options[$entry]} | cut -d',' -f1) ")
whiptail_list_entry_options+=($(echo ${whiptail_list_options[$entry]} | cut -d',' -f2))
done
# Present Checklist
whiptail_list_selected_descriptions=$(whiptail --checklist --separate-output --title "${whiptail_title}" "${whiptail_message}" 30 90 $whiptail_list_entry_count -- "${whiptail_list_entry_options[@]}" 3>&1 1>&2 2>&3)
addons_list_entry_selected=()
mapfile -t addons_list_entry_selected <<< "$whiptail_list_selected_descriptions"
# for checklist_selected_name in "${addons_list_entry_selected[@]}"; do
# echo "Selected Name: ${checklist_selected_name}"
# done
# echo " - - - - - - - - "
# echo ${addons_list_entry_selected[*]}
# echo ${!addons_list_entry_selected[*]}
# echo ${#addons_list_entry_selected[*]}
# echo ${addons_list_entry_selected[@]}
# echo ${!addons_list_entry_selected[@]}
# echo ${#addons_list_entry_selected[@]}
# echo " - - - - - - - - "
fi
# ----------------------------------------------------------------------------------------------------------------------------------
# -- Menu [ Install & Setup Video Streamer Menu ] selection of ( MPEG-Streamer | uStreamer )
# ----------------------------------------------------------------------------------------------------------------------------------
if [[ ${main_list_entry_selected[*]} =~ 'A08' ]]; then
# Menu Checklist CNCjs Pendants & Widgets
whiptail_title="Video Streamer Options"
whiptail_message='Video Streamer Options.\n\nPlease select which MPEG Streamer you would like to install:'
declare -A whiptail_list_options=(\
[uStreamer]="Newer lightweight and fast mpeg streamer. | https://github.com/pikvm/ustreamer" \
[MPEG-Streamer]="legacy mpeg streamer. | https://github.com/jacksonliam/mjpg-streamer" \
)
whiptail_list_entry_options=()
whiptail_list_entry_count=${#whiptail_list_options[@]}
for entry in "${!whiptail_list_options[@]}"; do
# echo "TESTING: whiptail_list_options[$entry]}:${whiptail_list_options[$entry]} | entry:$entry | ### $(echo ${whiptail_list_options[$entry]} | cut -d',' -f2)"
whiptail_list_entry_options+=("$entry")
whiptail_list_entry_options+=("$(echo ${whiptail_list_options[$entry]} | cut -d',' -f1)")
done
# Present Checklist
whiptail_list_selected_descriptions=$(whiptail --menu --title "${whiptail_title}" "${whiptail_message}" --default-item "uStreamer" 12 100 $whiptail_list_entry_count -- "${whiptail_list_entry_options[@]}" 3>&1 1>&2 2>&3)
streamer_list_entry_selected=()
mapfile -t streamer_list_entry_selected <<< "$whiptail_list_selected_descriptions"
fi
# ----------------------------------------------------------------------------------------------------------------------------------
# -- Main [ OS Handling / Checking ] check if detected operating system is known to be compatable with this script
# ----------------------------------------------------------------------------------------------------------------------------------
detected_os_id=$(cat /etc/*release | grep '^ID=' | cut -d '=' -f2- | tr -d '"')
detected_os_id_version=$(cat /etc/*release | grep '^VERSION_ID=' | cut -d '=' -f2- | tr -d '"')
msg i "Detected HW: $(tr -d '\0' </proc/device-tree/model)"
msg i "Detected OS: [\
$([[ "$detected_os_id" =~ $COMPATIBLE_OS_ID ]] && echo -e ${PASS}${COL_NC} || echo -e ${FAIL}${COL_NC}) $detected_os_id |\
$([[ $detected_os_id_version -ge $COMPATIBLE_OS_ID_VERSION ]] && echo -e ${PASS}${COL_NC} || echo -e ${FAIL}${COL_NC}) $detected_os_id_version |\
$(${COMPATIBLE_OS_GUI} && echo -e ${PASS}${COL_NC} 'Compatible GUI' || echo -e ${WARN}${COL_NC} 'No GUI (or) Incompatable GUI') \
]"
# Log OS Build Info
echo "Raspberry Pi OS Image Version" >&4
cat /boot/issue.txt >&4 # /etc/rpi-issue
# Display OS Build Info
OS_DATE=$(grep -oE "[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}" /boot/issue.txt)
case $(grep -o "stage." /boot/issue.txt) in
'stage1')
msg L "Raspberry Pi OS | Bare Bones | $OS_DATE"
;;
'stage2')
msg L "Raspberry Pi OS | Light | $OS_DATE"
;;
'stage3')
msg L "Raspberry Pi OS | Post-Light | $OS_DATE"
;;
'stage4')
msg L "Raspberry Pi OS with desktop | Standard | $OS_DATE"
;;
'stage5')
msg L "Raspberry Pi OS with desktop and recommended software | Full | $OS_DATE"
;;
*)
msg L "Unknow OS Build"
;;
esac
# Check Compatability
if [[ ${SYSTEM_CHECK} == true ]] && [[ ${main_list_entry_selected[*]} =~ "A00" ]] ; then
if [[ "$detected_os_id" =~ $COMPATIBLE_OS_ID ]] && [[ $detected_os_id_version -ge $COMPATIBLE_OS_ID_VERSION ]]; then
msg p "Detected OS is compatable with this install script."
else
msg x "Detected OS is NOT compatable with this install script!"
msg i "This installer is designed for the [Raspberry Pi](https://www.raspberrypi.org) | ${COMPATIBLE_OS_ID} >= v${COMPATIBLE_OS_ID_VERSION}"
exit 1;
fi
else
msg ! "Skipped OS Checking | Variable: SYSTEM_CHECK=${SYSTEM_CHECK} | Menu:$([[ ${main_list_entry_selected[*]} =~ 'A00' ]] && echo 'true' || echo 'false'))"
fi
# ----------------------------------------------------------------------------------------------------------------------------------
# -- Main [ Update System ] update operating system packages
# ----------------------------------------------------------------------------------------------------------------------------------
if [[ ${main_list_entry_selected[*]} =~ 'A01' ]]; then
msg % "Updating System Packages" \
'sudo apt-get update -qq'
msg % "Upgrading System Packages ${COL_YELLOW}(this can take a while, please wait)${COL_NC}" \
'sudo apt-get upgrade -qq -y'
msg % "Upgrading System Distribution ${COL_YELLOW}(this can take a while, please wait)${COL_NC}" \
'sudo apt-get dist-upgrade -qq -y'
msg % "Fixing Broken Packages (if any)" \
'sudo apt-get update --fix-missing -qq -y'
fi
# ----------------------------------------------------------------------------------------------------------------------------------
# -- Main [ Setup Node.js & NPM ] via Package Manager
# ----------------------------------------------------------------------------------------------------------------------------------
if [[ ${main_list_entry_selected[*]} =~ 'A12' ]] || [[ ${main_list_entry_selected[*]} =~ 'A02' ]]; then
msg h "Setup Node.js & NPM via Package Manager"
# Remove Old NodeJS or NPM Packages (Optional)
if [[ ${main_list_entry_selected[*]} =~ 'A12' ]]; then
msg % "Removing any Old NodeJS or NPM Packages" \
'sudo apt-get purge -y npm nodejs'
msg % "Removing Un-needed Packages" \
'sudo apt-get -y autoremove'
fi
# Install/Update Node.js & NPM via Package Manager
if [[ ${main_list_entry_selected[*]} =~ 'A02' ]]; then
# Raspbian / Debian Spasific Install
if [[ "$detected_os_id" == 'raspbian' ]] && [[ $detected_os_id_version -le 10 ]]; then
# Raspbian 10 (and older)
# https://github.com/nodesource/distributions#rpminstall
# msg % "Installing Node.js v10.x Package Source" \
# 'curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -'
msg % "Installing Node.js v16.x Package Source" \
'curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -'
msg % "Installing Node.js via Package Manager" \
'sudo apt-get install -qq -y nodejs'
else
# Debain
msg % "Installing Node.js & NPM via Package Manager" \
'sudo apt-get install -qq -y nodejs npm'
fi
msg % "Installing Build Essentials" \
'sudo apt-get install -qq -y -f build-essential gcc g++ make'
# msg % "Installing Latest Stable Nodejs and Node Package Manager (NPM)" \
# 'sudo npm install -g npm@latest'
# 'sudo npm cache clean -f; sudo npm install -g n; sudo n stable'
fi
else
msg h "Node.js & NPM Information"
fi
# ----------------------------------------------------------------------------------------------------------------------------------
# -- Output [ NodeJS & NPM Version ] output installed versions info
# ----------------------------------------------------------------------------------------------------------------------------------
if [[ -x $(which node) ]]; then
msg i "NodeJS: \t$(node -v) \t|\t $(which node)"
else
msg i "NodeJS: \tNot Installed"
fi
if [[ -x $(which npm) ]]; then
msg i "NPM: \tv$(npm -v) \t|\t $(which npm)"
else
msg i "NPM: \tNot Installed"
fi
# ----------------------------------------------------------------------------------------------------------------------------------
# -- Main [ Install CNCjs ] w/ NPM
# ----------------------------------------------------------------------------------------------------------------------------------
if [[ ${main_list_entry_selected[*]} =~ 'A03' ]]; then
msg h "Install CNCjs"
# Get Installed Version of CNCjs
if [[ $(command -v cncjs) ]]; then
CNCJS_VERSION_INSTALLED=$(npm view cncjs version) # cncjs --version
else
CNCJS_VERSION_INSTALLED=0
fi
# Menu Checklist CNCjs Pendants & Widgets
whiptail_title="CNCjs Version Selection"
whiptail_message='Select the version of CNCjs to install.\nIf not sure, leave on latest version'
CNCJS_VERSIONS_JSON="$(npm view cncjs versions --json)"
# readarray -t CNCJS_VERSIONS < <(jq -r '.[]' <<<"$json") # sudo apt-get install jq
readarray -t CNCJS_VERSIONS < <((grep '"'| cut -d '"' -f2) <<<"${CNCJS_VERSIONS_JSON}")
declare -p CNCJS_VERSIONS >/dev/null 2>&1
whiptail_list_entry_options=()
whiptail_list_entry_count=${#whiptail_whiptail_list_entry_options[@]}
# First Option (On)
whiptail_list_entry_options+=("${CNCJS_VERSIONS[${whiptail_list_entry_count} -1]}")
# Tag Installed Version
if [[ "$CNCJS_VERSION_INSTALLED" == "${CNCJS_VERSIONS[${whiptail_list_entry_count} -1]}" ]]; then
whiptail_list_entry_options+=("Latest Version * Installed * ")
else
whiptail_list_entry_options+=("Latest Version ")
fi
# Proccess and Flip Array (so newest at top)
# for entry in "${!CNCJS_VERSIONS[@]}"; do
for entry in $(seq $((${#CNCJS_VERSIONS[@]} - 2)) -1 0); do
whiptail_list_entry_options+=("${CNCJS_VERSIONS[$entry]}")
# Tag Installed Version
if [[ "$CNCJS_VERSION_INSTALLED" == "${CNCJS_VERSIONS[$entry]}" ]]; then
whiptail_list_entry_options+=("* Installed * ")
else
whiptail_list_entry_options+=(" ")
fi
done
cncjs_version_install=$(whiptail --menu --title "${whiptail_title}" "${whiptail_message}" 30 62 20 "${whiptail_list_entry_options[@]}" 3>&1 1>&2 2>&3)
#msg % "Install CNCjs with NPM" 'sudo npm install -g cncjs@latest --unsafe-perm'
msg % "Installing CNCjs (v${cncjs_version_install}) with NPM" \
"sudo npm install -g cncjs@${cncjs_version_install} --unsafe-perm"
# User TTY Permissions
# https://www.raspberrypi.org/forums/viewtopic.php?t=171843
msg % "Set User TTY Permissions" \
"sudo usermod -a -G tty ${USER}"
fi
# ----------------------------------------------------------------------------------------------------------------------------------
# -- Main [ Download & Install CNCjs Pendants & Widgets ] get some of the CNCjs extentions
# ----------------------------------------------------------------------------------------------------------------------------------
if [[ -n ${addons_list_entry_selected} ]]; then
msg h "Download & Install CNCjs Pendants & Widgets\t[ ${CNCJS_EXT_DIR} ]"
fi
# Create Needed Directories
if [[ ${main_list_entry_selected[*]} =~ 'A03' ]] || [[ ${main_list_entry_selected[*]} =~ 'A04' ]] || [[ ${main_list_entry_selected[*]} =~ 'A05' ]] || [[ ${main_list_entry_selected[*]} =~ 'A08' ]]; then
msg % "Creating CNCjs Directory for Addons / Extentions / Logs / Watch\t( ${CNCJS_EXT_DIR} )" \
"mkdir -p ${CNCJS_EXT_DIR}/watch"
fi
# Addons
if [[ -n ${addons_list_entry_selected} ]]; then
# Addon: Pendant TinyWeb
if [[ ${addons_list_entry_selected[*]} =~ 'Pendant TinyWeb' ]]; then
name="Pendant TinyWeb"
url="https://codeload.github.com/cncjs/cncjs-pendant-tinyweb"
dir="${CNCJS_EXT_DIR}/pendant-tinyweb"
sub="tinyweb"
cncjs_flags+=" --mount /${sub}:${dir}/src"
url+="/legacy.tar.gz/latest"
msg % "Download & Install: $name\t\t( http://${HOST_IP}/${sub} )\t[ ${dir} ]" \
"mkdir -p ${dir}; curl -sS ${url} | tar -xvzf - -C ${dir} --strip 1"
fi
# Addon: Pendant Shopfloor Tablet
if [[ ${addons_list_entry_selected[*]} =~ 'Pendant Shopfloor Tablet' ]]; then
name="Pendant Shopfloor Tablet"
url="https://codeload.github.com/cncjs/cncjs-shopfloor-tablet"
dir="${CNCJS_EXT_DIR}/pendant-shopfloor-tablet"
sub="tablet"
cncjs_flags+=" --mount /${sub}:${dir}/src"
url+="/legacy.tar.gz/latest"
msg % "Download & Install: $name\t( http://${HOST_IP}/${sub} )\t\t[ ${dir} ]" \
"mkdir -p ${dir}; curl -sS ${url} | tar -xvzf - -C ${dir} --strip 1"
fi
# Addon: Widget Boilerplate
if [[ ${addons_list_entry_selected[*]} =~ 'Widget Boilerplate' ]]; then
name="Widget Boilerplate"
url="https://cncjs.github.io/cncjs-widget-boilerplate/v2/"
sub="widget-boilerplate"
cncjs_flags+=" --mount /${sub}:${url}"
msg p "Setup: $name\t\t\t( http://${HOST_IP}/${sub} )\t( ${url} )"
fi
# Addon: Kiosk Custom Webpage
if [[ ${addons_list_entry_selected[*]} =~ 'Kiosk Custom Webpage' ]]; then
name="Kiosk Custom Webpage"
dir="${CNCJS_EXT_DIR}/kiosk"
sub="kiosk"
cncjs_flags+=" --mount /${sub}:${dir}"
msg % "Setup: $name\t( http://${HOST_IP}/${sub} )\t\t[ ${dir} ]" \
"mkdir -p ${dir}; cat > \"${dir}/index.html\" << EOF
<!DOCTYPE html>
<html>
<head>
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">
<style>
html {
overflow: hidden;
}
body,
html {
height: 100%;
margin: 0;
}
.bg {
/* The image used */
background-image: url(\"http://localhost:8080/?action=stream\");
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
</style>
</head>
<body>
<div class=\"bg\"></div>
<p>This example creates a full page background image. Try to resize the browser window to see how it always will
cover the full screen (when scrolled to top), and that it scales nicely on all screen sizes.</p>
</body>
EOF"
fi
fi
# ----------------------------------------------------------------------------------------------------------------------------------
# -- Main [ Autostart Autostart Service ] start CNCjs on bootup w/ Systemd
# ----------------------------------------------------------------------------------------------------------------------------------
if [[ ${main_list_entry_selected[*]} =~ 'A05' ]]; then
msg h "Create CNCjs Service for Autostart"
# Load Setting if File Exists
if [[ -f "/etc/systemd/system/cncjs.service" ]]; then
# CNCJS_PORT=$(get_config_var KIOSK_URL "/etc/systemd/system/cncjs.service")
CNCJS_PORT=$(sed -n "/^#/! s|.*--port \([[:digit:]]\+\).*|\1|p" "/etc/systemd/system/cncjs.service")
# else
# CNCJS_PORT=80 # Defined in header
fi
# Service
msg i "Creating CNCjs Service w/ Systemd"
# - - - - - - - - - - - - - - - - - - - - - - - - - - -
cat << EOF | sudo tee "/etc/systemd/system/cncjs.service" >/dev/null 2>&1
[Unit]
Description=CNCjs is a full-featured web-based interface for CNC controllers running Grbl, Marlin, Smoothieware, or TinyG.
Documentation=https://github.com/cncjs/cncjs
After=basic.target
After=network.target
Wants=network.target
[Service]
Type=simple
AmbientCapabilities=CAP_NET_BIND_SERVICE
# Restart service after x seconds if node service crashes
Restart=on-failure
RestartSec=5s
# # User & Group
User=${USER}
# Group=user
WorkingDirectory=${HOME}
# Capabilities & Security Settings
CapabilityBoundingSet=CAP_SYS_ADMIN CAP_NET_BIND_SERVICE # Commment this out if you want CNCjs to be able to run "sudo" commands.
# ProtectHome=true
ProtectSystem=full
# Output to journal
StandardOutput=journal
StandardError=journal
SyslogIdentifier=cncjs
# = Start Process =
Environment="NODE_ENV=production"
# CNCjs Parameters
$(cncjs --help | grep . | sed '1d;$d' | sed 's/^/#/')
# cncjs --help
ExecStart=$(which cncjs) --port 80 --watch-directory \"${HOME}/Documents\"
# = Alternative Method = (EnvironmentFile)
#EnvironmentFile=-/etc/cncjs.d/default.conf
#ExecStart=$(which cncjs) \${OPTIONS}
[Install]
WantedBy=multi-user.target
EOF
# -----------------------------------------------------
# Update the CNCjs Port
KIOSK_URL="$(whiptail --inputbox --title 'CNCjs Web UI Port' 'Port to use for CNCjs Web UI (default: 80 | 8000)' 8 39 "${CNCJS_PORT}" 3>&1 1>&2 2>&3)"
msg % "Editing CNCjs Service Start Port" \
"sudo sed -i \"/^#/! s|--port [[:digit:]]\+|--port ${CNCJS_PORT}|\" \"/etc/systemd/system/cncjs.service\" "
# -----------------------------------------------------
# Service Settings
msg i "Creating CNCjs Service Settings File (Optional)"
# --------------------------
sudo mkdir -p "/etc/cncjs.d/" >&4 2>&1
cat << EOF | sudo tee "/etc/cncjs.d/default.conf" >/dev/null 2>&1
# CNCjs Settings
# https://github.com/cncjs/cncjs
$(cncjs --help | grep . | sed '1d;$d' | sed 's/^/#/')
# cncjs --help
OPTIONS="--port ${CNCJS_PORT}"
EOF
# -----------------------------------------------------
# Edit Service File w/ Changes
msg % "Editing CNCjs Service Start Options: OPTIONS HERE" \
"sudo sed -i \"s|ExecStart=.*|ExecStart=$(which cncjs) ${cncjs_flags}|\" \"/etc/systemd/system/cncjs.service\" "
# Outputing Instance Infomation
msg - "Service Settings: /etc/systemd/system/cncjs.service" \
"$(grep "^ExecStart=" "/etc/systemd/system/cncjs.service")
\n Note: These settings can be changed with command: sudo systemctl edit --full cncjs\n Check CNCjs Server Status with: sudo service cncjs status"
# Reload Services
msg % "Reloading Service Deamon" \
"sudo systemctl daemon-reload"
# Instance Start
msg % "Starting Service" \
"sudo systemctl restart cncjs"
# Instance Enable
msg % "Enabling Service" \
"sudo systemctl enable cncjs"
# Instance Status
msg - "Status of Service" \
"$(sudo systemctl status cncjs)"
# Instance URL Infomation
msg i "CNCjs is now started and can be accessed at: ( \e]8;;http://localhost:${CNCJS_PORT}\ahttp://localhost:${CNCJS_PORT}\e]8;;\a ) | ( \e]8;;http://${HOST_IP}:${CNCJS_PORT}\ahttp://${HOST_IP}:${CNCJS_PORT}\e]8;;\a )"
fi
# # ----------------------------------------------------------------------------------------------------------------------------------
# # -- Main [ Setup IPtables ] allow access to port 8000 from port 80
# # ----------------------------------------------------------------------------------------------------------------------------------
# if [[ ${main_list_entry_selected[*]} =~ 'A06' ]]; then
# msg h "Setup IPtables"
# # Install IPtables & any other related packages
# msg % "Install Iptables" \
# 'sudo apt-get install -qq -y -f iptables'
# # Setup IPtables Rule
# msg % "Setup IPtables (allow access to port 8000 from port 80)" \
# 'sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8000'
# # Detect if IPtables Rule(s) Fail to Set, if so try after reboot
# if [[ $? -ne 0 ]]; then
# msg ! "IPtables Setup Failed, running commands after reboot to fix"
# # Create Crontab Job to Run at Next Boot, then remove its self
# msg L "Creating crontab job to run after next reboot, then will remove itself"
# cronjob='@reboot sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8000; sudo netfilter-persistent save; sudo netfilter-persistent reload; sudo bash -c "iptables-save > /etc/iptables/rules.v4"; sudo bash -c "ip6tables-save > /etc/iptables/rules.v6"; touch /home/pi/test01.txt; sudo crontab -u root -l | grep -v "@reboot sudo iptables" | sudo crontab -u root -'
# # (sudo crontab -u root -l; echo "${cronjob}" ) | sudo crontab -u root -
# ((sudo crontab -u root -l | grep -v '@reboot sudo iptables'); echo "${cronjob}" ) | sudo crontab -u root - >&4 2>&1
# # Remove Crontab Job
# # sudo crontab -u root -l | grep -v '@reboot sudo iptables' | sudo crontab -u root -
# # Show Crontab Job
# msg - "$(sudo crontab -u root -l)"
# fi
# # Make Iptables Persistent (silent install)
# echo iptables-persistent iptables-persistent/autosave_v4 boolean true | sudo debconf-set-selections
# echo iptables-persistent iptables-persistent/autosave_v6 boolean true | sudo debconf-set-selections
# msg % "Making Iptables Persistent" \
# 'sudo apt-get install -qq -y -f iptables-persistent'
# # How-to: Save & Reload Rules
# #sudo netfilter-persistent save
# #sudo netfilter-persistent reload
# # How-to: Manually Save Rules
# #sudo sh -c "iptables-save > /etc/iptables/rules.v4"
# #sudo sh -c "ip6tables-save > /etc/iptables/rules.v6"
# # Run this if issues to reconfigure iptables-persistent
# # sudo dpkg-reconfigure iptables-persistent
# fi
# ----------------------------------------------------------------------------------------------------------------------------------
# -- Main [ Setup Web Kiosk ] setup web kiosk for Rasp OS, and Rasp OS Slim
# ----------------------------------------------------------------------------------------------------------------------------------
if [[ ${main_list_entry_selected[*]} =~ 'A07' ]]; then
msg h "Setup Web Kiosk"
# =============================================
if [[ -x $(which lightdm) ]]; then
# Output LXDE Setup w/ Directory Path
msg i "Configuring LXDE to start Web Kiosk on Startup"
mkdir -p "${HOME}/.config/lxsession/LXDE-pi"
# --------------------------------------------
cat > "${HOME}/.config/lxsession/LXDE-pi/autostart" << EOF
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
${CNCJS_EXT_DIR}/cncjs-kiosk.sh
EOF
# --------------------------------------------
# Set Kiosk User Varible
KIOSK_USER=$USER
# Setup Autologin (GUI) on Raspberry Pi
msg i "Enabling Autologin (GUI)"
if [ -e /etc/init.d/lightdm ]; then
sudo systemctl set-default graphical.target
sudo ln -fs /lib/systemd/system/[email protected] /etc/systemd/system/getty.target.wants/[email protected]
sudo sh -c "cat > /etc/systemd/system/[email protected]/autologin.conf << EOF
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin $KIOSK_USER --noclear %I \$TERM
EOF"
sudo sed /etc/lightdm/lightdm.conf -i -e "s/^\(#\|\)autologin-user=.*/autologin-user=$KIOSK_USER/"
else
whiptail --msgbox "lightdm auto login setup error" 20 60 2
return 1
fi
# =============================================
elif [[ ${COMPATIBLE_OS_GUI} == false ]] || [[ -x $(which openbox) ]]; then
msg i "Raspberry PI GUI (lxde) NOT Detected. Raspberry Pi OS (Slim)?"
# Minimum Environment for GUI Applications | bare minimum needed for X server & window manager
msg % "Installing OpenBox GUI" \
"sudo apt-get install -y --no-install-recommends xserver-xorg xserver-xorg-legacy x11-xserver-utils xinit openbox zenity"
# Web Browser | Chromium has a nice kiosk mode
msg % "Chromium Web Browser (for Kiosk Mode)" \
"sudo apt-get install -y --no-install-recommends chromium-browser"
###sudo apt-get install -y --no-install-recommends chromium-browser rpi-chromium-mods # (Optional)
# Output Openbox Setup w/ Directory Path
msg i "Configuring Openbox to start Web Kiosk on Startup"
mkdir -p "${HOME}/.config/openbox/"
# --------------------------------------------
cat > "${HOME}/.config/openbox/autostart" << EOF
${CNCJS_EXT_DIR}/cncjs-kiosk.sh
EOF
# --------------------------------------------
# openbox-session start automatically on load
msg i "Setting Openbox UI to start on login"
# --------------------------------------------
cat > "${HOME}/.xinitrc" << "EOF"
exec openbox-session
EOF
# --------------------------------------------
# Start X automatically on boot
msg i "Setting StartX to start UI on login"
# --------------------------------------------
cat >> "${HOME}/.bashrc" << "EOF"
# Start Web Kiosk
[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && startx -- -nocursor
EOF
# --------------------------------------------
# Setup Autologin (Console > GUI) on Raspberry Pi
msg i "Enabling Autologin (Console > GUI)"
sudo systemctl set-default multi-user.target
sudo ln -fs /lib/systemd/system/[email protected] /etc/systemd/system/getty.target.wants/[email protected]
# --------------------------------------------
cat << EOF | sudo tee "/etc/systemd/system/[email protected]/autologin.conf" >/dev/null 2>&1
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin $USER --noclear %I \$TERM
EOF
# --------------------------------------------
fi
# =============================================
# Load Setting if File Exists
if [[ -f "${CNCJS_EXT_DIR}/cncjs-kiosk.sh" ]]; then
KIOSK_URL=$(get_config_var KIOSK_URL "${CNCJS_EXT_DIR}/cncjs-kiosk.sh")
KIOSK_URL=${parameter:=http://localhost:${CNCJS_PORT}} # Fix if varable blank
else
KIOSK_URL=http://localhost:${CNCJS_PORT}
fi
# Output Chrome Kiosk Script
# --------------------------------------------
cat > "${CNCJS_EXT_DIR}/cncjs-kiosk.sh" << 'EOF'
#!/bin/bash
# Set Display
#export DISPLAY=:0
# URL to open in Chrome Kiosk
KIOSK_URL=http://localhost:80