forked from moggieuk/Happy-Hare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·1552 lines (1424 loc) · 59.6 KB
/
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
#!/bin/bash
# Happy Hare MMU Software
# Installer / Updater script
#
# Copyright (C) 2022 moggieuk#6538 (discord) [email protected]
#
VERSION=2.41 # Important: Keep synced with mmy.py
KLIPPER_HOME="${HOME}/klipper"
MOONRAKER_HOME="${HOME}/moonraker"
KLIPPER_CONFIG_HOME="${HOME}/printer_data/config"
KLIPPER_LOGS_HOME="${HOME}/printer_data/logs"
OLD_KLIPPER_CONFIG_HOME="${HOME}/klipper_config"
SENSORS_SECTION="FILAMENT SENSORS"
LED_SECTION="MMU OPTIONAL NEOPIXEL"
declare -A PIN 2>/dev/null || {
echo "Please run this script with bash $0"
exit 1
}
# Pins for Fysetc Burrows ERB board, Original EASY-BRD and EASY-BRD with Seed Studio XIAO RP2040
# Note: uart pin is shared on original EASY-BRD (with different uart addresses)
#
PIN[ERB,gear_uart_pin]="gpio20"; PIN[EASY-BRD,gear_uart_pin]="PA8"; PIN[EASY-BRD-RP2040,gear_uart_pin]="gpio6"
PIN[ERB,gear_step_pin]="gpio10"; PIN[EASY-BRD,gear_step_pin]="PA4"; PIN[EASY-BRD-RP2040,gear_step_pin]="gpio27"
PIN[ERB,gear_dir_pin]="gpio9"; PIN[EASY-BRD,gear_dir_pin]="PA10"; PIN[EASY-BRD-RP2040,gear_dir_pin]="gpio28"
PIN[ERB,gear_enable_pin]="gpio8"; PIN[EASY-BRD,gear_enable_pin]="PA2"; PIN[EASY-BRD-RP2040,gear_enable_pin]="gpio26"
PIN[ERB,gear_diag_pin]="gpio13"; PIN[EASY-BRD,gear_diag_pin]=""; PIN[EASY-BRD-RP2040,gear_diag_pin]=""
PIN[ERB,selector_uart_pin]="gpio17"; PIN[EASY-BRD,selector_uart_pin]="PA8"; PIN[EASY-BRD-RP2040,selector_uart_pin]="gpio6"
PIN[ERB,selector_step_pin]="gpio16"; PIN[EASY-BRD,selector_step_pin]="PA9"; PIN[EASY-BRD-RP2040,selector_step_pin]="gpio7"
PIN[ERB,selector_dir_pin]="gpio15"; PIN[EASY-BRD,selector_dir_pin]="PB8"; PIN[EASY-BRD-RP2040,selector_dir_pin]="gpio0"
PIN[ERB,selector_enable_pin]="gpio14"; PIN[EASY-BRD,selector_enable_pin]="PA11"; PIN[EASY-BRD-RP2040,selector_enable_pin]="gpio29"
PIN[ERB,selector_diag_pin]="gpio19"; PIN[EASY-BRD,selector_diag_pin]="PA7"; PIN[EASY-BRD-RP2040,selector_diag_pin]="gpio2"
PIN[ERB,selector_endstop_pin]="gpio24"; PIN[EASY-BRD,selector_endstop_pin]="PB9"; PIN[EASY-BRD-RP2040,selector_endstop_pin]="gpio1"
PIN[ERB,servo_pin]="gpio23"; PIN[EASY-BRD,servo_pin]="PA5"; PIN[EASY-BRD-RP2040,servo_pin]="gpio4"
PIN[ERB,encoder_pin]="gpio22"; PIN[EASY-BRD,encoder_pin]="PA6"; PIN[EASY-BRD-RP2040,encoder_pin]="gpio3"
PIN[ERB,neopixel_pin]="gpio21"; PIN[EASY-BRD,neopixel_pin]=""; PIN[EASY-BRD-RP2040,neopixel_pin]=""
PIN[ERB,gate_sensor_pin]="gpio22"; PIN[EASY-BRD,gate_sensor_pin]="PA6"; PIN[EASY-BRD-RP2040,gate_sensor_pin]="gpio3";
PIN[ERB,pre_gate_0_pin]=""; PIN[EASY-BRD,pre_gate_0_pin]=""; PIN[EASY-BRD-RP2040,pre_gate_0_pin]="";
PIN[ERB,pre_gate_1_pin]=""; PIN[EASY-BRD,pre_gate_1_pin]=""; PIN[EASY-BRD-RP2040,pre_gate_1_pin]="";
PIN[ERB,pre_gate_2_pin]=""; PIN[EASY-BRD,pre_gate_2_pin]=""; PIN[EASY-BRD-RP2040,pre_gate_2_pin]="";
PIN[ERB,pre_gate_3_pin]=""; PIN[EASY-BRD,pre_gate_3_pin]=""; PIN[EASY-BRD-RP2040,pre_gate_3_pin]="";
PIN[ERB,pre_gate_4_pin]=""; PIN[EASY-BRD,pre_gate_4_pin]=""; PIN[EASY-BRD-RP2040,pre_gate_4_pin]="";
PIN[ERB,pre_gate_5_pin]=""; PIN[EASY-BRD,pre_gate_5_pin]=""; PIN[EASY-BRD-RP2040,pre_gate_5_pin]="";
PIN[ERB,pre_gate_6_pin]=""; PIN[EASY-BRD,pre_gate_6_pin]=""; PIN[EASY-BRD-RP2040,pre_gate_6_pin]="";
PIN[ERB,pre_gate_7_pin]=""; PIN[EASY-BRD,pre_gate_7_pin]=""; PIN[EASY-BRD-RP2040,pre_gate_7_pin]="";
PIN[ERB,pre_gate_8_pin]=""; PIN[EASY-BRD,pre_gate_8_pin]=""; PIN[EASY-BRD-RP2040,pre_gate_8_pin]="";
PIN[ERB,pre_gate_9_pin]=""; PIN[EASY-BRD,pre_gate_9_pin]=""; PIN[EASY-BRD-RP2040,pre_gate_9_pin]="";
PIN[ERB,pre_gate_10_pin]=""; PIN[EASY-BRD,pre_gate_10_pin]=""; PIN[EASY-BRD-RP2040,pre_gate_10_pin]="";
PIN[ERB,pre_gate_11_pin]=""; PIN[EASY-BRD,pre_gate_11_pin]=""; PIN[EASY-BRD-RP2040,pre_gate_11_pin]="";
# Pins for Mellow EASY-BRD with CANbus
#
PIN[MELLOW-EASY-BRD-CAN,gear_uart_pin]="gpio9";
PIN[MELLOW-EASY-BRD-CAN,gear_step_pin]="gpio7";
PIN[MELLOW-EASY-BRD-CAN,gear_dir_pin]="gpio8";
PIN[MELLOW-EASY-BRD-CAN,gear_enable_pin]="gpio6";
PIN[MELLOW-EASY-BRD-CAN,gear_diag_pin]="gpio23";
PIN[MELLOW-EASY-BRD-CAN,selector_uart_pin]="gpio0";
PIN[MELLOW-EASY-BRD-CAN,selector_step_pin]="gpio2";
PIN[MELLOW-EASY-BRD-CAN,selector_dir_pin]="gpio1";
PIN[MELLOW-EASY-BRD-CAN,selector_enable_pin]="gpio3";
PIN[MELLOW-EASY-BRD-CAN,selector_diag_pin]="gpio22";
PIN[MELLOW-EASY-BRD-CAN,selector_endstop_pin]="gpio20";
PIN[MELLOW-EASY-BRD-CAN,servo_pin]="gpio21";
PIN[MELLOW-EASY-BRD-CAN,encoder_pin]="gpio15";
PIN[MELLOW-EASY-BRD-CAN,neopixel_pin]="";
PIN[MELLOW-EASY-BRD-CAN,gate_sensor_pin]="gpio15";
PIN[MELLOW-EASY-BRD-CAN,pre_gate_0_pin]="";
PIN[MELLOW-EASY-BRD-CAN,pre_gate_1_pin]="";
PIN[MELLOW-EASY-BRD-CAN,pre_gate_2_pin]="";
PIN[MELLOW-EASY-BRD-CAN,pre_gate_3_pin]="";
PIN[MELLOW-EASY-BRD-CAN,pre_gate_4_pin]="";
PIN[MELLOW-EASY-BRD-CAN,pre_gate_5_pin]="";
PIN[MELLOW-EASY-BRD-CAN,pre_gate_6_pin]="";
PIN[MELLOW-EASY-BRD-CAN,pre_gate_7_pin]="";
PIN[MELLOW-EASY-BRD-CAN,pre_gate_8_pin]="";
PIN[MELLOW-EASY-BRD-CAN,pre_gate_9_pin]="";
PIN[MELLOW-EASY-BRD-CAN,pre_gate_10_pin]="";
PIN[MELLOW-EASY-BRD-CAN,pre_gate_11_pin]="";
# Pins for BTT MMB board (gear on motor1, selector on motor2, endstop on STP11, optional gate sensor on STP1 if no gear DIAG use)
#
PIN[MMB,gear_uart_pin]="PA10"; # M1
PIN[MMB,gear_step_pin]="PB15";
PIN[MMB,gear_dir_pin]="PB14";
PIN[MMB,gear_enable_pin]="PA8";
PIN[MMB,gear_diag_pin]="PA3"; # Aka STP1
PIN[MMB,selector_uart_pin]="PC7"; # M2
PIN[MMB,selector_step_pin]="PD2";
PIN[MMB,selector_dir_pin]="PB13";
PIN[MMB,selector_enable_pin]="PD1";
PIN[MMB,selector_diag_pin]="PA4"; # Aka STP2
PIN[MMB,selector_endstop_pin]="PB2"; # STP11
PIN[MMB,servo_pin]="PA0";
PIN[MMB,encoder_pin]="PA1";
PIN[MMB,neopixel_pin]="PA2";
PIN[MMB,gate_sensor_pin]="PA3"; # STP1 (if not DIAG)
PIN[MMB,pre_gate_0_pin]="PB9"; # STP3
PIN[MMB,pre_gate_1_pin]="PB8"; # STP4
PIN[MMB,pre_gate_2_pin]="PC15"; # STP5
PIN[MMB,pre_gate_3_pin]="PC13"; # STP6
PIN[MMB,pre_gate_4_pin]="PC14"; # STP7
PIN[MMB,pre_gate_5_pin]="PB12"; # STP8
PIN[MMB,pre_gate_6_pin]="PB11"; # STP9
PIN[MMB,pre_gate_7_pin]="PB10"; # STP10
PIN[MMB,pre_gate_8_pin]="";
PIN[MMB,pre_gate_9_pin]="";
PIN[MMB,pre_gate_10_pin]="";
PIN[MMB,pre_gate_11_pin]="";
# These pins will usually be on main mcu for wiring simplification
#
PIN[toolhead_sensor_pin]=""
PIN[extruder_sensor_pin]=""
PIN[gantry_servo_pin]=""
PIN[sync_feedback_tension_pin]=""
PIN[sync_feedback_compression_pin]=""
# Screen Colors
OFF='\033[0m' # Text Reset
BLACK='\033[0;30m' # Black
RED='\033[0;31m' # Red
GREEN='\033[0;32m' # Green
YELLOW='\033[0;33m' # Yellow
BLUE='\033[0;34m' # Blue
PURPLE='\033[0;35m' # Purple
CYAN='\033[0;36m' # Cyan
WHITE='\033[0;37m' # White
B_RED='\033[1;31m' # Bold Red
B_GREEN='\033[1;32m' # Bold Green
B_YELLOW='\033[1;33m' # Bold Yellow
B_CYAN='\033[1;36m' # Bold Cyan
B_WHITE='\033[1;37m' # Bold White
TITLE="${B_WHITE}"
DETAIL="${BLUE}"
INFO="${CYAN}"
EMPHASIZE="${B_CYAN}"
ERROR="${B_RED}"
WARNING="${B_YELLOW}"
PROMPT="${CYAN}"
INPUT="${OFF}"
SECTION="----------\n"
function nextfilename {
local name="$1"
if [ -d "${name}" ]; then
printf "%s-%s" ${name%%.*} $(date '+%Y%m%d_%H%M%S')
else
printf "%s-%s.%s-old" ${name%%.*} $(date '+%Y%m%d_%H%M%S') ${name#*.}
fi
}
function nextsuffix {
local name="$1"
local -i num=0
while [ -e "$name.0$num" ]; do
num+=1
done
printf "%s.0%d" "$name" "$num"
}
verify_not_root() {
if [ "$EUID" -eq 0 ]; then
echo -e "${ERROR}This script must not run as root"
exit -1
fi
}
check_klipper() {
if [ "$NOSERVICE" -ne 1 ]; then
if [ "$(sudo systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
echo -e "${INFO}Klipper service found"
else
echo -e "${ERROR}Klipper service not found! Please install Klipper first"
exit -1
fi
fi
}
verify_home_dirs() {
if [ ! -d "${KLIPPER_HOME}" ]; then
echo -e "${ERROR}Klipper home directory (${KLIPPER_HOME}) not found. Use '-k <dir>' option to override"
exit -1
fi
if [ ! -d "${KLIPPER_CONFIG_HOME}" ]; then
if [ ! -d "${OLD_KLIPPER_CONFIG_HOME}" ]; then
echo -e "${ERROR}Klipper config directory (${KLIPPER_CONFIG_HOME} or ${OLD_KLIPPER_CONFIG_HOME}) not found. Use '-c <dir>' option to override"
exit -1
fi
KLIPPER_CONFIG_HOME="${OLD_KLIPPER_CONFIG_HOME}"
fi
echo -e "${INFO}Klipper config directory (${KLIPPER_CONFIG_HOME}) found"
if [ ! -d "${MOONRAKER_HOME}" ]; then
echo -e "${ERROR}Moonraker home directory (${MOONRAKER_HOME}) not found. Use '-m <dir>' option to override"
exit -1
fi
}
# Silently cleanup legacy ERCF-Software-V3 files...
cleanup_old_ercf() {
# Printer configuration files...
ercf_files=$(cd ${KLIPPER_CONFIG_HOME}; ls ercf_*.cfg 2>/dev/null | wc -l || true)
if [ "${ercf_files}" -ne 0 ]; then
echo -e "${INFO}Cleaning up old Happy Hare v1 installation"
if [ ! -d "${KLIPPER_CONFIG_HOME}/ercf.uninstalled" ]; then
mkdir ${KLIPPER_CONFIG_HOME}/ercf.uninstalled
fi
for file in `cd ${KLIPPER_CONFIG_HOME} ; ls ercf_*.cfg 2>/dev/null`; do
mv ${KLIPPER_CONFIG_HOME}/${file} ${KLIPPER_CONFIG_HOME}/ercf.uninstalled/${file}
done
if [ -f "${KLIPPER_CONFIG_HOME}/client_macros.cfg" ]; then
mv ${KLIPPER_CONFIG_HOME}/client_macros.cfg ${KLIPPER_CONFIG_HOME}/ercf.uninstalled/client_macros.cfg
fi
fi
# Klipper modules...
if [ -d "${KLIPPER_HOME}/klippy/extras" ]; then
rm -f "${KLIPPER_HOME}/klippy/extras/ercf*.py"
fi
# Old klipper logs...
if [ -d "${KLIPPER_LOGS_HOME}" ]; then
rm -f "${KLIPPER_LOGS_HOME}/ercf*"
fi
# Moonraker update manager...
file="${KLIPPER_CONFIG_HOME}/moonraker.conf"
if [ -f "${file}" ]; then
v1_section=$(grep -c '\[update_manager ercf-happy_hare\]' ${file} || true)
if [ "${v1_section}" -ne 0 ]; then
cat "${file}" | sed -e " \
/\[update_manager ercf-happy_hare\]/,+6 d; \
" > "${file}.update" && mv "${file}.update" "${file}"
fi
fi
# printer.cfg includes...
dest=${KLIPPER_CONFIG_HOME}/printer.cfg
if test -f $dest; then
next_dest="$(nextfilename "$dest")"
v1_includes=$(grep -c '\[include ercf_parameters.cfg\]' ${dest} || true)
if [ "${v1_includes}" -ne 0 ]; then
cp ${dest} ${next_dest}
cat "${dest}" | sed -e " \
/\[include ercf_software.cfg\]/ d; \
/\[include ercf_parameters.cfg\]/ d; \
/\[include ercf_hardware.cfg\]/ d; \
/\[include ercf_menu.cfg\]/ d; \
/\[include client_macros.cfg\]/ d; \
" > "${dest}.tmp" && mv "${dest}.tmp" "${dest}"
fi
fi
}
# TEMPORARY: Upgrade to mmu-toolhead version from manual_stepper
cleanup_manual_stepper_version() {
# Legacy klipper modules...
if [ -d "${KLIPPER_HOME}/klippy/extras" ]; then
rm -f "${KLIPPER_HOME}/klippy/extras/manual_mh_stepper.py"
rm -f "${KLIPPER_HOME}/klippy/extras/manual_extruder_stepper.py"
# Used as upgrade reminder rm -f "${KLIPPER_HOME}/klippy/extras/mmu_config_setup.py"
fi
# Upgrade mmu_hardware.cfg...
hardware_cfg="${KLIPPER_CONFIG_HOME}/mmu/base/mmu_hardware.cfg"
found_manual_stepper=$(egrep -c "\[mmu_config_setup\]|\[manual_extruder_stepper extruder\]" ${hardware_cfg} || true)
if [ "${found_manual_stepper}" -ne 0 ]; then
cat "${hardware_cfg}" | sed -e " \
/\[mmu_config_setup\]/ d; \
/^velocity: .*/ d; \
/^accel: .*/ d; \
s%\[\(.*\) manual_extruder_stepper extruder\]%# REMOVE/MOVE THIS SECTION vvv\n\[\1 manual_extruder_stepper extruder\]%; \
s%\[manual_extruder_stepper extruder\]%# REMOVE/MOVE THIS SECTION vvv\n\[manual_extruder_stepper extruder\]%; \
s%\[\(.*\) manual_extruder_stepper gear_stepper\]%\[\1 stepper_mmu_gear\]%; \
s%\[manual_extruder_stepper gear_stepper\]%\[stepper_mmu_gear\]%; \
s%\[\(.*\) manual_mh_stepper selector_stepper\]%\[\1 stepper_mmu_selector\]%; \
s%\[manual_mh_stepper selector_stepper\]%\[stepper_mmu_selector\]%; \
s%: \(.*\)_gear_stepper:virtual_endstop%: \1_stepper_mmu_gear:virtual_endstop%; \
s%: \(.*\)_selector_stepper:virtual_endstop%: \1_stepper_mmu_selector:virtual_endstop%; \
" > "${hardware_cfg}.tmp" && mv "${hardware_cfg}.tmp" "${hardware_cfg}"
echo -e "${WARNING}"
echo "------------------------- IMPORTANT INFO ON NEW MMU TOOLHEAD DEFINITION - READ ME --------------------------"
echo " This version of Happy Hare no longer requires the move of the [extruder] definition into mmu_hardware.cfg"
echo " You need to restore the sections marked in your mmu_hardware.cfg back to your original extruder config"
echo " and delete those sections from mmu_hardware.cfg. Also note that the gear are selector stepper definitions"
echo " have been modified to be compatible with the new MMU toolhead feature of this version"
echo
echo " If you see an error similar to:"
echo -e "${ERROR} Option 'microsteps' in section 'manual_extruder_stepper extruder' must be specified"
echo -e "${WARNING}"
echo " Edit mmu_hardware.cfg and restart Klipper to complete the upgrade"
echo "------------------------------------------------------------------------------------------------------------"
echo
fi
}
# TEMPORARY: Upgrade mmu sensors part of mmu_hardware.cfg
upgrade_mmu_sensors() {
hardware_cfg="${KLIPPER_CONFIG_HOME}/mmu/base/mmu_hardware.cfg"
found_mmu_sensors=$(egrep -c "${SENSORS_SECTION}" ${hardware_cfg} || true)
if [ "${found_mmu_sensors}" -eq 0 ]; then
# Form new section ready for insertion at end of existing mmu_hardware.cfg
sed -n "/${SENSORS_SECTION}/,+26p" "${SRCDIR}/config/base/mmu_hardware.cfg" | sed -e " \
s/^/#/; \
" > "${hardware_cfg}.tmp"
# Add new mmu sensors config section
echo -e "${INFO}Adding new mmu sensors section (commented out) to mmu_hardware.cfg..."
cat "${hardware_cfg}.tmp" >> "${hardware_cfg}" && rm "${hardware_cfg}.tmp"
fi
}
# TEMPORARY: Upgrade led effects part of mmu_hardware.cfg (assumed last part of file)
upgrade_led_effects() {
hardware_cfg="${KLIPPER_CONFIG_HOME}/mmu/base/mmu_hardware.cfg"
found_led_effects=$(egrep -c "${LED_SECTION}" ${hardware_cfg} || true)
led_effects_enabled=$(egrep -c "^\[mmu_led_effect" ${hardware_cfg} || true)
# Form new section ready for insertion at end of existing mmu_hardware.cfg
if [ "${led_effects_enabled}" -ne 0 ]; then
# Was enabled
sed -n "/${LED_SECTION}/,\$p" "${SRCDIR}/config/base/mmu_hardware.cfg" | sed -e " \
s/{mmu_num_gates}/${mmu_num_gates}/; \
s/{mmu_num_leds}/${mmu_num_leds}/g; \
" > "${hardware_cfg}.add"
else
# Was disabled
sed -n "/${LED_SECTION}/,\$p" "${SRCDIR}/config/base/mmu_hardware.cfg" | sed -e " \
s/^/#/; \
s/{mmu_num_gates}/${mmu_num_gates}/; \
s/{mmu_num_leds}/${mmu_num_leds}/g; \
" > "${hardware_cfg}.add"
fi
if [ "${found_led_effects}" -ne 0 ]; then
if echo "$FROM_VERSION 2.40" | awk '{exit !(($1 < $2))}'; then
cat "${hardware_cfg}" | sed -e "\
/${LED_SECTION}/,\$ d \
" > ${hardware_cfg}.tmp && mv ${hardware_cfg}.tmp ${hardware_cfg}
# Upgrade led config section
echo -e "${INFO}Updating LED control section in mmu_hardware.cfg..."
cat "${hardware_cfg}.add" >> "${hardware_cfg}" && rm "${hardware_cfg}.add"
else
rm "${hardware_cfg}.add"
fi
else
# Add new led config section
echo -e "${INFO}Adding new LED control section (commented out) to mmu_hardware.cfg..."
cat "${hardware_cfg}.add" >> "${hardware_cfg}" && rm "${hardware_cfg}.add"
fi
}
link_mmu_plugins() {
echo -e "${INFO}Linking mmu extensions to Klipper..."
if [ -d "${KLIPPER_HOME}/klippy/extras" ]; then
for file in `cd ${SRCDIR}/extras ; ls *.py`; do
ln -sf "${SRCDIR}/extras/${file}" "${KLIPPER_HOME}/klippy/extras/${file}"
done
else
echo -e "${WARNING}Klipper extensions not installed because Klipper 'extras' directory not found!"
fi
echo -e "${INFO}Linking mmu extension to Moonraker..."
if [ -d "${MOONRAKER_HOME}/moonraker/components" ]; then
for file in `cd ${SRCDIR}/components ; ls *.py`; do
ln -sf "${SRCDIR}/components/${file}" "${MOONRAKER_HOME}/moonraker/components/${file}"
done
else
echo -e "${WARNING}Moonraker extensions not installed because Moonraker 'components' directory not found!"
fi
}
unlink_mmu_plugins() {
echo -e "${INFO}Unlinking mmu extensions from Klipper..."
if [ -d "${KLIPPER_HOME}/klippy/extras" ]; then
for file in `cd ${SRCDIR}/extras ; ls *.py`; do
rm -f "${KLIPPER_HOME}/klippy/extras/${file}"
done
else
echo -e "${WARNING}MMU modules not uninstalled because Klipper 'extras' directory not found!"
fi
echo -e "${INFO}Unlinking mmu extension from Moonraker..."
if [ -d "${MOONRAKER_HOME}/moonraker/components" ]; then
for file in `cd ${SRCDIR}/components ; ls *.py`; do
rm -f "${MOONRAKER_HOME}/moonraker/components/${file}"
done
else
echo -e "${WARNING}MMU modules not uninstalled because Moonraker 'components' directory not found!"
fi
}
parse_file() {
filename="$1"
prefix_filter="$2"
namespace="$3"
# Read old config files
while IFS= read -r line
do
# Remove comments
line="${line%%#*}"
line="${line%%;*}"
# Check if line is not empty and contains variable or parameter
if [ ! -z "$line" ] && { [ -z "$prefix_filter" ] || [ "${line#$prefix_filter}" != "$line" ]; }; then
# Split the line into parameter and value
IFS=":=" read -r parameter value <<< "$line"
# Remove leading and trailing whitespace
parameter=$(echo "$parameter" | xargs)
# Need to be more careful with value because it can be quoted
value=$(echo "$value" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
# If parameter is one of interest and it has a value remember it
if echo "$parameter" | egrep -q "${prefix_filter}"; then
if [ "${value}" != "" ]; then
if echo "$value" | grep -q '^{.*}$'; then
eval "${namespace}${parameter}=\$${value}"
else
eval "${namespace}${parameter}='${value}'"
fi
fi
fi
fi
done < "${filename}"
}
update_copy_file() {
src="$1"
dest="$2"
prefix_filter="$3"
namespace="$4"
# Read the file line by line
while IFS="" read -r line || [ -n "$line" ]
do
if echo "$line" | egrep -q '^#'; then
# Just copy simple comments
echo "$line"
elif [ ! -z "$line" ] && { [ -z "$prefix_filter" ] || [ "${line#$prefix_filter}" != "$line" ]; }; then
# Line of interest
# Split the line into the part before # and the part after #
parameterAndValueAndSpace=$(echo "$line" | sed 's/^[[:space:]]*//' | cut -d'#' -f1)
comment=$(echo "$line" | cut -s -d'#' -f2-)
space=`printf "%s" "$parameterAndValueAndSpace" | sed 's/.*[^[:space:]]\(.*\)$/\1/'`
if echo "$parameterAndValueAndSpace" | egrep -q "${prefix_filter}"; then
# If parameter and value exist, substitute the value with the in memory variable of the same name
if echo "$parameterAndValueAndSpace" | egrep -q '^\['; then
echo "$line"
elif [ -n "$parameterAndValueAndSpace" ]; then
parameter=$(echo "$parameterAndValueAndSpace" | cut -d':' -f1)
value=$(echo "$parameterAndValueAndSpace" | cut -d':' -f2)
if [ -n "${namespace}${parameter}" ]; then
# If 'parameter' is set and not empty, evaluate its value
new_value=$(eval echo "\$${namespace}${parameter}")
if [ -n "${namespace}" ]; then
# Namespaced, use once
eval unset ${namespace}${parameter}
fi
elif [ -n "${parameter}" ]; then
# Try non-namespaced name, multi-use
new_value=$(eval echo "\$${parameter}")
else
# If 'parameter' is unset or empty leave as token
new_value="{$parameter}"
fi
if [ -n "$comment" ]; then
echo "${parameter}: ${new_value}${space}#${comment}"
else
echo "${parameter}: ${new_value}"
fi
else
echo "$line"
fi
else
echo "$line"
fi
else
# Just copy simple comments
echo "$line"
fi
done < "$src" >"$dest"
}
# Set default token values to the tokens themselves to avoid being parsed out
set_default_tokens() {
brd_type="unknown"
for var in mmu_num_gates mmu_num_leds serial servo_up_angle servo_move_angle servo_down_angle; do
eval "${var}='{$var}'"
done
}
# Set default parameters from the distribution (reference) config files
read_default_config() {
echo -e "${INFO}Reading default configuration parameters..."
parse_file "${SRCDIR}/config/base/mmu_parameters.cfg" "" "_param_"
parse_file "${SRCDIR}/config/base/mmu_software.cfg" "variable_"
parse_file "${SRCDIR}/config/base/mmu_sequence.cfg" "variable_"
parse_file "${SRCDIR}/config/base/mmu_form_tip.cfg" "variable_"
parse_file "${SRCDIR}/config/base/mmu_cut_tip.cfg" "variable_"
}
# Pull parameters from previous installation
read_previous_config() {
cfg="mmu_parameters.cfg"
dest_cfg=${KLIPPER_CONFIG_HOME}/mmu/base/${cfg}
if [ ! -f "${dest_cfg}" ]; then
echo -e "${WARNING}No previous ${cfg} found."
else
echo -e "${INFO}Reading ${cfg} configuration from previous installation..."
parse_file "${dest_cfg}" "" "_param_"
# Upgrade / map / force old parameters
if [ "${_param_form_tip_macro}" == "_MMU_FORM_TIP_STANDALONE" ]; then
_param_form_tip_macro="_MMU_FORM_TIP"
fi
if [ ! "${_param_encoder_unload_buffer}" == "" ]; then
_param_gate_unload_buffer=${_param_encoder_unload_buffer}
fi
if [ ! "${_param_encoder_unload_max}" == "" ]; then
_param_gate_homing_max=${_param_encoder_unload_max}
fi
if [ ! "${_param_encoder_load_retries}" == "" ]; then
_param_gate_load_retries=${_param_encoder_load_retries}
fi
if [ "${_param_toolhead_ignore_load_error}" == "1" ]; then
_param_toolhead_move_error_tolerance=100
fi
if [ ! "${_param_bowden_load_tolerance}" == "" ]; then
_param_bowden_allowable_load_delta=${_param_bowden_load_tolerance}
fi
if [ "${_param_servo_buzz_gear_on_down}" == "" ]; then
if [ "${_param_mmu_vendor}" == "Tradrack" ]; then
_param_servo_buzz_gear_on_down=0
else
_param_servo_buzz_gear_on_down=3
fi
fi
if [ "${_param_gate_parking_distance}" == "" ]; then
if [ ! "${_param_mmu_version}" == "1.1" ]; then
_param_gate_parking_distance=23
else
_param_gate_parking_distance=13
fi
fi
if [ "${_param_gate_endstop_to_encoder}" == "" ]; then
_param_gate_endstop_to_encoder=0
fi
if [ ! "${_param_servo_up_angle}" == "" ]; then
_param_servo_up_angle=$(echo "$_param_servo_up_angle" | awk '{print int($1)}')
fi
if [ ! "${_param_servo_down_angle}" == "" ]; then
_param_servo_down_angle=$(echo "$_param_servo_down_angle" | awk '{print int($1)}')
fi
if [ ! "${_param_servo_move_angle}" == "" ]; then
_param_servo_move_angle=$(echo "$_param_servo_move_angle" | awk '{print int($1)}')
fi
if [ ! "${_param_z_hop_height_error}" == "" ]; then
unset _param_z_hop_heigth_error
fi
fi
cfg="mmu_filametrix.cfg"
dest_cfg=${KLIPPER_CONFIG_HOME}/mmu/base/${cfg}
if [ -f "${dest_cfg}" ]; then
echo -e "${INFO}Reading ${cfg} configuration from previous installation..."
parse_file "${dest_cfg}" "variable_"
# Convert from mm/min to mm/sec and 'spd' to 'speed' for consistency in other macros
#
if [ ! "${variable_rip_speed}" == "" ]; then
variable_rip_speed=$(echo "$variable_rip_speed" | awk '{if ($1 > 250) print int($1 / 60); else print $1}')
fi
if [ ! "${variable_evacuate_speed}" == "" ]; then
variable_evacuate_speed=$(echo "$variable_evacuate_speed" | awk '{if ($1 > 250) print int($1 / 60); else print $1}')
fi
if [ ! "${variable_extruder_move_speed}" == "" ]; then
variable_extruder_move_speed=$(echo "$variable_extruder_move_speed" | awk '{if ($1 > 250) print int($1 / 60); else print $1}')
fi
if [ ! "${variable_travel_spd}" == "" ]; then
variable_travel_speed=$(echo "$variable_travel_spd" | awk '{if ($1 > 250) print int($1 / 60); else print $1}')
fi
if [ ! "${variable_cut_fast_move_spd}" == "" ]; then
variable_cut_fast_move_speed=$(echo "$variable_cut_fast_move_spd" | awk '{if ($1 > 250) print int($1 / 60); else print $1}')
fi
if [ ! "${variable_cut_slow_move_spd}" == "" ]; then
variable_cut_slow_move_speed=$(echo "$variable_cut_slow_move_spd" | awk '{if ($1 > 250) print int($1 / 60); else print $1}')
fi
fi
for cfg in mmu_software.cfg mmu_sequence.cfg mmu_cut_tip.cfg mmu_form_tip.cfg; do
dest_cfg=${KLIPPER_CONFIG_HOME}/mmu/base/${cfg}
if [ ! -f "${dest_cfg}" ]; then
echo -e "${WARNING}No previous ${cfg} found. Will install"
else
echo -e "${INFO}Reading ${cfg} configuration from previous installation..."
parse_file "${dest_cfg}" "variable_"
fi
done
if [ ! "${_param_mmu_num_gates}" == "{mmu_num_gates}" -a ! "${_param_mmu_num_gates}" == "" ] 2>/dev/null; then
mmu_num_gates=$_param_mmu_num_gates
mmu_num_leds=$(expr $mmu_num_gates + 1)
fi
}
copy_config_files() {
mmu_dir="${KLIPPER_CONFIG_HOME}/mmu"
next_mmu_dir="$(nextfilename "${mmu_dir}")"
echo -e "${INFO}Copying configuration files into ${mmu_dir} directory..."
if [ ! -d "${mmu_dir}" ]; then
mkdir ${mmu_dir}
mkdir ${mmu_dir}/base
mkdir ${mmu_dir}/optional
else
echo -e "${DETAIL}Config directory ${mmu_dir} already exists - backing up old config files to ${next_mmu_dir}"
mkdir ${next_mmu_dir}
(cd "${mmu_dir}"; cp -r * "${next_mmu_dir}")
fi
if [ ! "${_param_mmu_num_gates}" == "" ]; then
mmu_num_gates=${_param_mmu_num_gates}
fi
for file in `cd ${SRCDIR}/config/base ; ls *.cfg`; do
src=${SRCDIR}/config/base/${file}
dest=${mmu_dir}/base/${file}
next_dest=${next_mmu_dir}/base/${file}
if [ -f "${dest}" ]; then
if [ "${file}" == "mmu_hardware.cfg" -a "${INSTALL}" -eq 0 ] || [ "${file}" == "mmu.cfg" -a "${INSTALL}" -eq 0 ]; then
echo -e "${WARNING}Skipping copy of hardware config file ${file} because already exists"
continue
else
echo -e "${INFO}Installing/Upgrading configuration file ${file}"
mv ${dest} ${next_dest}
fi
fi
# Hardware files: Special token substitution -----------------------------------------
if [ "${file}" == "mmu.cfg" -o "${file}" == "mmu_hardware.cfg" ]; then
cp ${src} ${dest}
# Correct shared uart_address for EASY-BRD
if [ "${brd_type}" == "EASY-BRD" ]; then
# Share uart_pin to avoid duplicate alias problem
cat ${dest} | sed -e "\
s/^uart_pin: mmu:MMU_SEL_UART/uart_pin: mmu:MMU_GEAR_UART/; \
" > ${dest}.tmp && mv ${dest}.tmp ${dest}
else
# Remove uart_address lines
cat ${dest} | sed -e "\
/^uart_address:/ d; \
" > ${dest}.tmp && mv ${dest}.tmp ${dest}
fi
if [ "${SETUP_SELECTOR_TOUCH}" -eq 1 ]; then
cat ${dest} | sed -e "\
s/^#\(diag_pin: \^mmu:MMU_SEL_DIAG\)/\1/; \
s/^#\(driver_SGTHRS: 75\)/\1/; \
s/^#\(extra_endstop_pins: tmc2209_stepper_mmu_selector:virtual_endstop\)/\1/; \
s/^#\(extra_endstop_names: mmu_sel_touch\)/\1/; \
s/^uart_address:/${uart_comment}uart_address:/; \
" > ${dest}.tmp && mv ${dest}.tmp ${dest}
fi
# Now substitute tokens given brd_type
cat ${dest} | sed -e "\
s/{brd_type}/${brd_type}/; \
s%{serial}%${serial}%; \
s/{mmu_num_gates}/${mmu_num_gates}/; \
s/{mmu_num_leds}/${mmu_num_leds}/; \
s/{gear_gear_ratio}/${gear_gear_ratio}/; \
s/{gear_run_current}/${gear_run_current}/; \
s/{gear_hold_current}/${gear_hold_current}/; \
s/{sel_run_current}/${sel_run_current}/; \
s/{sel_hold_current}/${sel_hold_current}/; \
s/{maximum_servo_angle}/${maximum_servo_angle}/; \
s/{minimum_pulse_width}/${minimum_pulse_width}/; \
s/{maximum_pulse_width}/${maximum_pulse_width}/; \
s/{toolhead_sensor_pin}/${PIN[toolhead_sensor_pin]}/; \
s/{extruder_sensor_pin}/${PIN[extruder_sensor_pin]}/; \
s/{gantry_servo_pin}/${PIN[gantry_servo_pin]}/; \
s/{sync_feedback_tension_pin}/${PIN[sync_feedback_tension_pin]}/; \
s/{sync_feedback_compression_pin}/${PIN[sync_feedback_compression_pin]}/; \
s/{gate_sensor_pin}/${PIN[$brd_type,gate_sensor_pin]}/; \
s/{pre_gate_0_pin}/${PIN[$brd_type,pre_gate_0_pin]}/; \
s/{pre_gate_1_pin}/${PIN[$brd_type,pre_gate_1_pin]}/; \
s/{pre_gate_2_pin}/${PIN[$brd_type,pre_gate_2_pin]}/; \
s/{pre_gate_3_pin}/${PIN[$brd_type,pre_gate_3_pin]}/; \
s/{pre_gate_4_pin}/${PIN[$brd_type,pre_gate_4_pin]}/; \
s/{pre_gate_5_pin}/${PIN[$brd_type,pre_gate_5_pin]}/; \
s/{pre_gate_6_pin}/${PIN[$brd_type,pre_gate_6_pin]}/; \
s/{pre_gate_7_pin}/${PIN[$brd_type,pre_gate_7_pin]}/; \
s/{pre_gate_8_pin}/${PIN[$brd_type,pre_gate_8_pin]}/; \
s/{pre_gate_9_pin}/${PIN[$brd_type,pre_gate_9_pin]}/; \
s/{pre_gate_10_pin}/${PIN[$brd_type,pre_gate_10_pin]}/; \
s/{pre_gate_11_pin}/${PIN[$brd_type,pre_gate_11_pin]}/; \
s/{gear_gear_ratio}/${gear_gear_ratio}/; \
s/{gear_uart_pin}/${PIN[$brd_type,gear_uart_pin]}/; \
s/{gear_step_pin}/${PIN[$brd_type,gear_step_pin]}/; \
s/{gear_dir_pin}/${PIN[$brd_type,gear_dir_pin]}/; \
s/{gear_enable_pin}/${PIN[$brd_type,gear_enable_pin]}/; \
s/{gear_diag_pin}/${PIN[$brd_type,gear_diag_pin]}/; \
s/{selector_uart_pin}/${PIN[$brd_type,selector_uart_pin]}/; \
s/{selector_step_pin}/${PIN[$brd_type,selector_step_pin]}/; \
s/{selector_dir_pin}/${PIN[$brd_type,selector_dir_pin]}/; \
s/{selector_enable_pin}/${PIN[$brd_type,selector_enable_pin]}/; \
s/{selector_diag_pin}/${PIN[$brd_type,selector_diag_pin]}/; \
s/{selector_endstop_pin}/${PIN[$brd_type,selector_endstop_pin]}/; \
s/{servo_pin}/${PIN[$brd_type,servo_pin]}/; \
s/{encoder_pin}/${PIN[$brd_type,encoder_pin]}/; \
s/{neopixel_pin}/${PIN[$brd_type,neopixel_pin]}/; \
" > ${dest}.tmp && mv ${dest}.tmp ${dest}
# Handle LED option - Comment out if disabled
if [ "${file}" == "mmu_hardware.cfg" -a "$SETUP_LED" -eq 0 ]; then
sed "/${LED_SECTION}/,\$s/^/#/" ${dest} > ${dest}.tmp && mv ${dest}.tmp ${dest}
fi
# Conifguration parameters -----------------------------------------------------------
elif [ "${file}" == "mmu_parameters.cfg" ]; then
update_copy_file "$src" "$dest" "" "_param_"
# Ensure that supplemental user added params are retained. These are those that are
# by default set internally in Happy Hare based on vendor and version settings but
# can be overridden. This set also includes a couple of hidden test parameters.
supplemental_params="cad_gate0_pos cad_gate_width cad_bypass_offset cad_last_gate_offset cad_block_width cad_bypass_block_width cad_bypass_block_delta gate_parking_distance encoder_default_resolution"
hidden_params="virtual_selector homing_extruder test_random_failures"
for var in $(set | grep '^_param_' | cut -d'=' -f1); do
param=${var#_param_}
for item in ${supplemental_params} ${hidden_params}; do
if [ "$item" = "$param" ]; then
value=$(eval echo "\$${var}")
echo "${param}: ${value} # User added and retained after upgrade"
fi
done
done >> $dest
# Software macros --------------------------------------------------------------------
elif [ "${file}" == "mmu_software.cfg" ]; then
tx_macros=""
for (( i=0; i<=$(expr $mmu_num_gates - 1); i++ ))
do
tx_macros+="[gcode_macro T${i}]\n"
tx_macros+="gcode: MMU_CHANGE_TOOL TOOL=${i}\n"
done
if [ "${INSTALL}" -eq 1 ]; then
cat ${src} | sed -e "\
s%{klipper_config_home}%${KLIPPER_CONFIG_HOME}%g; \
s%{tx_macros}%${tx_macros}%g; \
s%{led_enable}%${SETUP_LED}%g; \
" > ${dest}
else
cat ${src} | sed -e "\
s%{klipper_config_home}%${KLIPPER_CONFIG_HOME}%g; \
s%{tx_macros}%${tx_macros}%g; \
s%{led_enable}%${SETUP_LED}%g; \
" > ${dest}.tmp
update_copy_file "${dest}.tmp" "${dest}" "variable_" && rm ${dest}.tmp
fi
elif [ "${file}" == "mmu_form_tip.cfg" -o "${file}" == "mmu_cut_tip.cfg" -o "${file}" == "mmu_sequence.cfg" ]; then
if [ "${INSTALL}" -eq 1 ]; then
cat ${src} > ${dest}
else
cat ${src} > ${dest}.tmp
update_copy_file "${dest}.tmp" "${dest}" "variable_" && rm ${dest}.tmp
fi
else
cp ${src} ${dest}
fi
done
for file in mmu_filametrix.cfg; do
dest=${mmu_dir}/base/${file}
if [ -f "${dest}" ]; then
echo -e "${WARNING}Removing deprecated config files ${file}"
rm -f "${dest}"
fi
done
for file in `cd ${SRCDIR}/config/optional ; ls *.cfg`; do
src=${SRCDIR}/config/optional/${file}
dest=${KLIPPER_CONFIG_HOME}/mmu/optional/${file}
cp ${src} ${dest}
done
src=${SRCDIR}/config/mmu_vars.cfg
dest=${KLIPPER_CONFIG_HOME}/mmu/mmu_vars.cfg
if [ -f "${dest}" ]; then
echo -e "${WARNING}Skipping copy of mmu_vars.cfg file because already exists"
else
cp ${src} ${dest}
fi
}
uninstall_config_files() {
if [ -d "${KLIPPER_CONFIG_HOME}/mmu" ]; then
echo -e "${INFO}Removing MMU configuration files from ${KLIPPER_CONFIG_HOME}"
mv "${KLIPPER_CONFIG_HOME}/mmu" /tmp/mmu.uninstalled
fi
}
install_printer_includes() {
# Link in all includes if not already present
dest=${KLIPPER_CONFIG_HOME}/printer.cfg
if test -f $dest; then
klippain_included=$(grep -c "[include config/hardware/mmu.cfg]" ${dest} || true)
if [ "${klippain_included}" -eq 1 ]; then
echo -e "${WARNING}This looks like a Klippain config installation - skipping automatic config install. Please add config includes by hand"
else
next_dest="$(nextfilename "$dest")"
echo -e "${INFO}Copying original printer.cfg file to ${next_dest}"
cp ${dest} ${next_dest}
if [ ${MENU_12864} -eq 1 ]; then
i='\[include mmu/optional/mmu_menu.cfg\]'
already_included=$(grep -c "${i}" ${dest} || true)
if [ "${already_included}" -eq 0 ]; then
sed -i "1i ${i}" ${dest}
fi
fi
if [ ${ERCF_COMPAT} -eq 1 ]; then
i='\[include mmu/optional/mmu_ercf_compat.cfg\]'
already_included=$(grep -c "${i}" ${dest} || true)
if [ "${already_included}" -eq 0 ]; then
sed -i "1i ${i}" ${dest}
fi
fi
if [ ${CLIENT_MACROS} -eq 1 ]; then
i='\[include mmu/optional/client_macros.cfg\]'
already_included=$(grep -c "${i}" ${dest} || true)
if [ "${already_included}" -eq 0 ]; then
sed -i "1i ${i}" ${dest}
fi
fi
for i in \
'\[include mmu/base/\*.cfg\]' ; do
already_included=$(grep -c "${i}" ${dest} || true)
if [ "${already_included}" -eq 0 ]; then
sed -i "1i ${i}" ${dest}
fi
done
fi
else
echo -e "${WARNING}File printer.cfg file not found! Cannot include MMU configuration files"
fi
}
uninstall_printer_includes() {
echo -e "${INFO}Cleaning MMU references from printer.cfg"
dest=${KLIPPER_CONFIG_HOME}/printer.cfg
if test -f $dest; then
next_dest="$(nextfilename "$dest")"
echo -e "${INFO}Copying original printer.cfg file to ${next_dest} before cleaning"
cp ${dest} ${next_dest}
cat "${dest}" | sed -e " \
/\[include mmu\/optional\/client_macros.cfg\]/ d; \
/\[include mmu\/optional\/mmu_menu.cfg\]/ d; \
/\[include mmu\/optional\/mmu_ercf_compat.cfg\]/ d; \
/\[include mmu\/mmu_software.cfg\]/ d; \
/\[include mmu\/mmu_parameters.cfg\]/ d; \
/\[include mmu\/mmu_hardware.cfg\]/ d; \
/\[include mmu\/mmu_filametrix.cfg\]/ d; \
/\[include mmu\/mmu_sequence.cfg\]/ d; \
/\[include mmu\/mmu_form_tip.cfg\]/ d; \
/\[include mmu\/mmu_cut_tip.cfg\]/ d; \
/\[include mmu\/mmu.cfg\]/ d; \
/\[include mmu\/base\/\*.cfg\]/ d; \
" > "${dest}.tmp" && mv "${dest}.tmp" "${dest}"
fi
}
install_update_manager() {
echo -e "${INFO}Adding update manager to moonraker.conf"
file="${KLIPPER_CONFIG_HOME}/moonraker.conf"
if [ -f "${file}" ]; then
restart=0
update_section=$(grep -c '\[update_manager happy-hare\]' ${file} || true)
if [ "${update_section}" -eq 0 ]; then
echo "" >> "${file}"
while read -r line; do
echo -e "${line}" >> "${file}"
done < "${SRCDIR}/moonraker_update.txt"
echo "" >> "${file}"
restart=1
else
echo -e "${WARNING}[update_manager happy-hare] already exists in moonraker.conf - skipping install"
fi
# Quick "catch-up" update for new mmu_service
enable_preprocessor="True"
update_section=$(grep -c '\[mmu_server\]' ${file} || true)
if [ "${update_section}" -eq 0 ]; then
echo "" >> "${file}"
echo "[mmu_server]" >> "${file}"
echo "enable_file_preprocessor: ${enable_preprocessor}" >> "${file}"
echo "" >> "${file}"
restart=1
else
echo -e "${WARNING}[mmu_server] already exists in moonraker.conf - skipping install"
fi
if [ "$restart" -eq 1 ]; then
restart_moonraker
fi
else
echo -e "${WARNING}moonraker.conf not found!"
fi
}
uninstall_update_manager() {
echo -e "${INFO}Removing update manager from moonraker.conf"
file="${KLIPPER_CONFIG_HOME}/moonraker.conf"
if [ -f "${file}" ]; then
restart=0
update_section=$(grep -c '\[update_manager happy-hare\]' ${file} || true)
if [ "${update_section}" -eq 0 ]; then
echo -e "${INFO}[update_manager happy-hare] not found in moonraker.conf - skipping removal"
else
cat "${file}" | sed -e " \
/\[update_manager happy-hare\]/,+6 d; \
" > "${file}.new" && mv "${file}.new" "${file}"
restart=1
fi
update_section=$(grep -c '\[mmu_server\]' ${file} || true)
if [ "${update_section}" -eq 0 ]; then
echo -e "${INFO}[mmu_server] not found in moonraker.conf - skipping removal"
else
cat "${file}" | sed -e " \
/\[mmu_server\]/,+1 d; \
" > "${file}.new" && mv "${file}.new" "${file}"
restart=1
fi
if [ "$restart" -eq 1 ]; then
restart_moonraker
fi
else
echo -e "${WARNING}moonraker.conf not found!"
fi
}
restart_klipper() {
if [ "$NOSERVICE" -ne 1 ]; then
echo -e "${INFO}Restarting Klipper..."
sudo systemctl restart klipper
else
echo -e "${WARNING}Klipper restart suppressed - Please restart by hand"
fi
}
restart_moonraker() {
if [ "$NOSERVICE" -ne 1 ]; then
echo -e "${INFO}Restarting Moonraker..."
sudo systemctl restart moonraker
else
echo -e "${WARNING}Moonraker restart suppressed - Please restart by hand"
fi
}
prompt_yn() {
while true; do
read -n1 -p "$@ (y/n)? " yn
case "${yn}" in
Y|y)
echo "y"
break;;
N|n)
echo "n"
break;;
*)
;;
esac
done
}