Repository navigation
Expand file tree
/
Copy pathinstaller.sh
More file actions
executable file
·889 lines (744 loc) · 32.9 KB
/
Copy pathinstaller.sh
File metadata and controls
executable file
·889 lines (744 loc) · 32.9 KB
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
#!/bin/bash
# =============================================================================
# ACE Pro Klipper Driver - Interactive Installer
# =============================================================================
# This script performs the necessary installation steps to set up the ACE Pro
# driver for Klipper, including configuration file setup and symlinks.
#
# Compatible with: Raspberry Pi OS, Debian, Ubuntu
# Usage: ./installer.sh
#
# =============================================================================
set -u # Exit on undefined variables
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Script directory (where this script is located)
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Resolve installation user/home for defaults (works when run via sudo).
INSTALL_USER="${SUDO_USER:-$(id -un)}"
INSTALL_HOME="$(getent passwd "$INSTALL_USER" 2>/dev/null | cut -d: -f6 || true)"
if [ -z "$INSTALL_HOME" ]; then
INSTALL_HOME="$HOME"
fi
# ============================================================================
# Helper Functions
# ============================================================================
print_header() {
echo -e "\n${BLUE}========================================${NC}"
echo -e "${BLUE}$1${NC}"
echo -e "${BLUE}========================================${NC}\n"
}
print_info() {
echo -e "${BLUE}ℹ ${1}${NC}"
}
print_success() {
echo -e "${GREEN}✓ ${1}${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠ ${1}${NC}"
}
print_error() {
echo -e "${RED}✗ ${1}${NC}"
}
# Yes/No prompt
prompt_yes_no() {
local prompt="$1"
local response
while true; do
read -p "$(echo -e ${BLUE}${prompt}${NC} [y/N]: )" response
case "$response" in
[yY][eE][sS]|[yY]) return 0 ;;
[nN][oO]|[nN]|"") return 1 ;;
*) echo "Please answer y or n" ;;
esac
done
}
# Prompt for input with default
prompt_input() {
local prompt="$1"
local default="$2"
local response
read -p "$(echo -e ${BLUE}${prompt}${NC} [${default}]: )" response
echo "${response:-$default}"
}
# Create backup with timestamp
backup_file() {
local file="$1"
if [ -f "$file" ]; then
local timestamp=$(date +"%Y%m%d_%H%M%S")
local backup="${file}.backup_${timestamp}"
cp "$file" "$backup"
print_success "Backed up: $file → $backup"
return 0
fi
return 1
}
# Remove a symlink if it exists and show what it pointed to
remove_symlink_if_exists() {
local path="$1"
if is_symlink "$path"; then
local target=$(readlink "$path")
rm -f "$path"
print_info "Removed symlink: $path (was pointing to: $target)"
return 0
fi
return 1
}
# Check if path is a symlink
is_symlink() {
[ -L "$1" ]
}
# Add a KlipperScreen menu entry (handles user-editable section vs auto-generated marker)
ensure_menu_entry() {
local conf="$1"
local header="$2"
local block="$3"
local label="$4"
# Extract user-editable section (lines before the #~# auto-generated marker)
local user_section
user_section=$(sed '/^#~# --- Do not edit/,$d' "$conf" 2>/dev/null || cat "$conf" 2>/dev/null || true)
if echo "$user_section" | grep -qF "$header"; then
print_success "KlipperScreen.conf: $label entry already present"
return 0
fi
print_info "Adding $label entry to $conf"
local tmpfile
tmpfile=$(mktemp)
if grep -q '^#~# --- Do not edit' "$conf" 2>/dev/null; then
# Insert the block just before the auto-generated marker
awk -v block="$block" '
/^#~# --- Do not edit/ && !done {
print block; print ""; done=1
}
{ print }
' "$conf" > "$tmpfile" && mv "$tmpfile" "$conf"
else
# No marker — append at end of file
printf '\n%s\n' "$block" >> "$conf"
fi
print_success "KlipperScreen.conf: added $label entry"
}
# Ensure the ACE Pro menu entry exists in main and print menus
ensure_klipperscreen_acepro_menu() {
local conf="$1"
local entry_block_main='[menu __main acepro]\nname: ACE Pro\nicon: settings\npanel: acepro'
local entry_block_print='[menu __print acepro]\nname: ACE Pro\nicon: settings\npanel: acepro'
ensure_menu_entry "$conf" "[menu __main acepro]" "$entry_block_main" "ACE Pro (main menu)"
ensure_menu_entry "$conf" "[menu __print acepro]" "$entry_block_print" "ACE Pro (print menu)"
}
# Ensure [ace_status] section exists in moonraker.conf (create file if missing)
ensure_moonraker_ace_status() {
local conf="$1"
if [ -f "$conf" ] && grep -qi '^[[:space:]]*\[ace_status\]' "$conf"; then
print_success "moonraker.conf: [ace_status] already present"
return 0
fi
mkdir -p "$(dirname "$conf")"
if [ ! -f "$conf" ]; then
printf '# Moonraker configuration\n\n' > "$conf"
print_warning "Created new moonraker.conf at $conf"
fi
printf '\n# ACE status extension\n[ace_status]\n' >> "$conf"
print_success "Added [ace_status] to $conf"
}
# Ensure font_size = small is set in the user-editable section of KlipperScreen.conf
# Handles missing file, missing [main] section, wrong value, and #~# auto-generated block.
ensure_klipperscreen_font_size() {
local conf="$1"
if [ ! -f "$conf" ]; then
printf '[main]\nfont_size = small\n' > "$conf"
print_success "Created $conf with font_size = small"
return 0
fi
# Extract user-editable section (lines before the #~# auto-generated marker)
local user_section
user_section=$(sed '/^#~# --- Do not edit/,$d' "$conf")
# Already correct?
if echo "$user_section" | grep -qiE '^[[:space:]]*font_size[[:space:]]*=[[:space:]]*small[[:space:]]*$'; then
print_success "KlipperScreen.conf: font_size = small is already configured"
return 0
fi
print_info "Configuring font_size = small in $conf"
local tmpfile
tmpfile=$(mktemp)
if echo "$user_section" | grep -qiE '^[[:space:]]*font_size[[:space:]]*='; then
# font_size exists with a different value — update first occurrence before #~# block
awk '
/^#~# --- Do not edit/ { in_auto=1 }
!in_auto && /^[[:space:]]*font_size[[:space:]]*=/ && !replaced {
print "font_size = small"; replaced=1; next
}
{ print }
' "$conf" > "$tmpfile" && mv "$tmpfile" "$conf"
print_success "KlipperScreen.conf: updated font_size to small"
elif echo "$user_section" | grep -q '^\[main\]'; then
# [main] exists in user section but no font_size — insert after first [main]
awk '
/^#~# --- Do not edit/ { in_auto=1 }
!in_auto && /^\[main\]$/ && !done {
print; print "font_size = small"; done=1; next
}
{ print }
' "$conf" > "$tmpfile" && mv "$tmpfile" "$conf"
print_success "KlipperScreen.conf: added font_size = small under [main]"
else
# No [main] in user section — insert block before #~# marker or prepend
if grep -q '^#~# --- Do not edit' "$conf"; then
awk '
/^#~# --- Do not edit/ && !done {
print "[main]"; print "font_size = small"; print ""; done=1
}
{ print }
' "$conf" > "$tmpfile" && mv "$tmpfile" "$conf"
else
{ printf '[main]\nfont_size = small\n\n'; cat "$conf"; } > "$tmpfile" && mv "$tmpfile" "$conf"
fi
print_success "KlipperScreen.conf: added [main] section with font_size = small"
fi
}
# Create or replace symlink
create_or_replace_symlink() {
local source="$1"
local target="$2"
local description="$3"
if [ ! -e "$source" ]; then
print_error "$source does not exist, skipping symlink"
return 1
fi
if [ -e "$target" ] || is_symlink "$target"; then
if is_symlink "$target"; then
print_warning "Symlink already exists: $target"
local current_target=$(readlink "$target")
print_info " → Currently points to: $current_target"
else
print_warning "File/directory already exists: $target"
fi
if prompt_yes_no "Replace it?"; then
rm -f "$target"
ln -sf "$source" "$target"
print_success "Symlink created: $target → $source"
return 0
else
print_info "Skipped symlink for $description"
return 1
fi
else
# Target doesn't exist, create symlink
mkdir -p "$(dirname "$target")"
ln -sf "$source" "$target"
print_success "Symlink created: $target → $source"
return 0
fi
}
# ============================================================================
# Main Installation
# ============================================================================
main() {
print_header "ACE Pro Klipper Driver - Interactive Installer"
# Track backup files for final instructions
PRINTER_CONFIG_BACKUP=""
PRINTER_GENERIC_MACROS_BACKUP=""
ACE_CONFIG_BACKUP=""
ACE_MACROS_BACKUP=""
MOONRAKER_RESTART_NEEDED=0
# ========================================================================
# Step 1: Gather user input
# ========================================================================
print_info "Gathering installation parameters...\n"
print_info "Installer source directory: $SCRIPT_DIR"
print_info "Default target user/home: $INSTALL_USER ($INSTALL_HOME)"
# 1.1 - Klipper installation directory
DEFAULT_KLIPPER_DIR="$INSTALL_HOME/klipper"
KLIPPER_DIR=$(prompt_input "Klipper installation directory (press ENTER to use default)" "$DEFAULT_KLIPPER_DIR")
if [ ! -d "$KLIPPER_DIR" ]; then
print_error "Klipper directory not found: $KLIPPER_DIR"
exit 1
fi
print_success "Using Klipper directory: $KLIPPER_DIR"
# 1.2 - Printer model
echo ""
echo "Which printer model?"
echo " 1) Kobra 3"
echo " 2) Kobra KS1"
echo " 3) Kobra K3M (BETA testing)"
read -p "$(echo -e ${BLUE}Select [1, 2 or 3]${NC}: )" printer_choice
case "$printer_choice" in
1)
PRINTER_MODEL="K3"
PRINTER_NAME="Kobra 3"
;;
2)
PRINTER_MODEL="KS1"
PRINTER_NAME="Kobra S1"
;;
3)
PRINTER_MODEL="K3M"
PRINTER_NAME="Kobra K3M (BETA testing)"
;;
*)
print_error "Invalid choice"
exit 1
;;
esac
print_success "Selected printer: $PRINTER_NAME"
# 1.3 - Config directory
DEFAULT_CONFIG_DIR="$INSTALL_HOME/printer_data/config"
CONFIG_DIR=$(prompt_input "\nKlipper config directory" "$DEFAULT_CONFIG_DIR")
if [ ! -d "$CONFIG_DIR" ]; then
print_error "Config directory not found: $CONFIG_DIR"
exit 1
fi
print_success "Using config directory (press ENTER to use default): $CONFIG_DIR"
# ========================================================================
# Step 2: Ask for confirmation
# ========================================================================
echo ""
print_header "Installation Summary"
cat << EOF
Script directory: $SCRIPT_DIR
Klipper directory: $KLIPPER_DIR
Printer model: $PRINTER_NAME
Config directory: $CONFIG_DIR
Installation steps:
1. Link ace module to Klipper extras
1b. (Optional) Install ACE status Moonraker component + dashboard symlinks
2. Backup and install printer.cfg for $PRINTER_NAME
3. Copy printer_generic_macros.cfg (backup if exists)
4. Copy ACE configuration file
5. Copy ACE macro file
6. Link optional ACE temperature sensor
7. Link KlipperScreen panel (if available)
8. Optionally restart services
EOF
if ! prompt_yes_no "Continue with installation?"; then
print_info "Installation cancelled"
exit 0
fi
# ========================================================================
# Step 1: Link ace module to Klipper extras
# ========================================================================
print_header "Step 1: Linking ACE module to Klipper extras"
ACE_SOURCE="$SCRIPT_DIR/extras/ace"
ACE_TARGET="$KLIPPER_DIR/klippy/extras/ace"
if [ ! -d "$ACE_SOURCE" ]; then
print_error "ACE source directory not found: $ACE_SOURCE"
exit 1
fi
create_or_replace_symlink "$ACE_SOURCE" "$ACE_TARGET" "ACE module"
VP_SOURCE="$SCRIPT_DIR/extras/virtual_pins.py"
VP_TARGET="$KLIPPER_DIR/klippy/extras/virtual_pins.py"
if [ ! -f "$VP_SOURCE" ]; then
print_error "virtual_pins.py not found: $ACE_SOURCE"
exit 1
fi
create_or_replace_symlink "$VP_SOURCE" "$VP_TARGET" "virtual_pins module"
# Optional ACE temperature sensor (safe to link even if unused)
TEMP_SOURCE="$SCRIPT_DIR/extras/temperature_ace.py"
TEMP_TARGET="$KLIPPER_DIR/klippy/extras/temperature_ace.py"
if [ -f "$TEMP_SOURCE" ]; then
print_info "Linking optional ACE temperature sensor (temperature_ace.py)..."
create_or_replace_symlink "$TEMP_SOURCE" "$TEMP_TARGET" "temperature_ace sensor"
else
print_warning "temperature_ace.py not found; skipping sensor symlink"
fi
# ========================================================================
# Step 1b: ACE Status Integration (Optional)
# ========================================================================
ACE_STATUS_DIR="$SCRIPT_DIR/ace_status_integration"
if [ -d "$ACE_STATUS_DIR" ]; then
print_header "Step 1b: ACE Status Integration (Optional)"
if prompt_yes_no "Install ACE status Moonraker component + dashboard symlinks?"; then
ACE_MOONRAKER_DEFAULT="$INSTALL_HOME/moonraker"
ACE_MAINSAIL_DEFAULT="$INSTALL_HOME/mainsail"
ACE_FLUIDD_DEFAULT="$INSTALL_HOME/fluidd"
ACE_MOONRAKER_CONF_DEFAULT="$INSTALL_HOME/printer_data/config/moonraker.conf"
# Moonraker component
ACE_MOONRAKER_DIR=$(prompt_input "Moonraker directory (press ENTER to use default)" "$ACE_MOONRAKER_DEFAULT")
ACE_MOONRAKER_COMPONENTS="$ACE_MOONRAKER_DIR/moonraker/components"
if [ -d "$ACE_MOONRAKER_COMPONENTS" ]; then
ACE_STATUS_SOURCE="$ACE_STATUS_DIR/moonraker/ace_status.py"
ACE_STATUS_TARGET="$ACE_MOONRAKER_COMPONENTS/ace_status.py"
create_or_replace_symlink "$ACE_STATUS_SOURCE" "$ACE_STATUS_TARGET" "ACE status Moonraker component"
MOONRAKER_RESTART_NEEDED=1
# Ensure moonraker.conf has [ace_status]
ACE_MOONRAKER_CONF=$(prompt_input "moonraker.conf path (press ENTER to use default)" "$ACE_MOONRAKER_CONF_DEFAULT")
ensure_moonraker_ace_status "$ACE_MOONRAKER_CONF"
else
print_warning "Moonraker components directory not found: $ACE_MOONRAKER_COMPONENTS"
print_info "Skipping Moonraker ACE status symlink"
fi
# Mainsail dashboard files
if prompt_yes_no "Link dashboard files into Mainsail?"; then
ACE_MAINSAIL_DIR=$(prompt_input "Mainsail install directory" "$ACE_MAINSAIL_DEFAULT")
if [ -d "$ACE_MAINSAIL_DIR" ]; then
for ace_file in ace.html ace-dashboard.js ace-dashboard.css ace-dashboard-config.js favicon.svg; do
create_or_replace_symlink "$ACE_STATUS_DIR/web/$ace_file" "$ACE_MAINSAIL_DIR/$ace_file" "Mainsail $ace_file"
done
else
print_warning "Mainsail directory not found: $ACE_MAINSAIL_DIR"
print_info "Skipped Mainsail dashboard links"
fi
fi
# Fluidd dashboard files
if prompt_yes_no "Link dashboard files into Fluidd?"; then
ACE_FLUIDD_DIR=$(prompt_input "Fluidd install directory" "$ACE_FLUIDD_DEFAULT")
if [ -d "$ACE_FLUIDD_DIR" ]; then
for ace_file in ace.html ace-dashboard.js ace-dashboard.css ace-dashboard-config.js favicon.svg; do
create_or_replace_symlink "$ACE_STATUS_DIR/web/$ace_file" "$ACE_FLUIDD_DIR/$ace_file" "Fluidd $ace_file"
done
else
print_warning "Fluidd directory not found: $ACE_FLUIDD_DIR"
print_info "Skipped Fluidd dashboard links"
fi
fi
else
print_info "ACE status integration skipped"
fi
fi
# ========================================================================
# Step 2: Backup and copy printer configuration
# ========================================================================
print_header "Step 2: Printer Configuration"
PRINTER_CONFIG_SOURCE="$SCRIPT_DIR/config/printer_${PRINTER_MODEL}.cfg"
PRINTER_CONFIG_TARGET="$CONFIG_DIR/printer.cfg"
if [ ! -f "$PRINTER_CONFIG_SOURCE" ]; then
print_error "Printer config file not found: $PRINTER_CONFIG_SOURCE"
exit 1
fi
# Backup existing printer.cfg
if [ -f "$PRINTER_CONFIG_TARGET" ]; then
print_warning "printer.cfg already exists"
local was_symlink=0
if is_symlink "$PRINTER_CONFIG_TARGET"; then
was_symlink=1
print_info "Current printer.cfg is a symlink (→ $(readlink "$PRINTER_CONFIG_TARGET"))"
fi
if ! prompt_yes_no "Back up and replace printer.cfg?"; then
print_info "Skipped printer configuration installation"
else
local timestamp=$(date +"%Y%m%d_%H%M%S")
PRINTER_CONFIG_BACKUP="${PRINTER_CONFIG_TARGET}.backup_${timestamp}"
cp "$PRINTER_CONFIG_TARGET" "$PRINTER_CONFIG_BACKUP"
print_success "Backed up: $PRINTER_CONFIG_TARGET → $PRINTER_CONFIG_BACKUP"
if [ "$was_symlink" -eq 1 ]; then
remove_symlink_if_exists "$PRINTER_CONFIG_TARGET"
fi
cp "$PRINTER_CONFIG_SOURCE" "$PRINTER_CONFIG_TARGET"
print_success "Copied: $PRINTER_CONFIG_SOURCE → $PRINTER_CONFIG_TARGET"
fi
else
cp "$PRINTER_CONFIG_SOURCE" "$PRINTER_CONFIG_TARGET"
print_success "Copied: $PRINTER_CONFIG_SOURCE → $PRINTER_CONFIG_TARGET"
fi
# ========================================================================
# Step 3: Copy printer_generic_macros.cfg
# ========================================================================
print_header "Step 3: Printer Generic Macros"
PRINTER_GENERIC_MACROS_SOURCE="$SCRIPT_DIR/config/printer_generic_macros.cfg"
PRINTER_GENERIC_MACROS_TARGET="$CONFIG_DIR/printer_generic_macros.cfg"
if [ ! -f "$PRINTER_GENERIC_MACROS_SOURCE" ]; then
print_error "printer_generic_macros.cfg not found: $PRINTER_GENERIC_MACROS_SOURCE"
exit 1
fi
if [ -f "$PRINTER_GENERIC_MACROS_TARGET" ]; then
print_warning "printer_generic_macros.cfg already exists"
local was_symlink=0
if is_symlink "$PRINTER_GENERIC_MACROS_TARGET"; then
was_symlink=1
print_info "Current printer_generic_macros.cfg is a symlink (→ $(readlink "$PRINTER_GENERIC_MACROS_TARGET"))"
fi
if ! prompt_yes_no "Back up and replace printer_generic_macros.cfg?"; then
print_info "Skipped printer_generic_macros.cfg installation"
else
local timestamp=$(date +"%Y%m%d_%H%M%S")
PRINTER_GENERIC_MACROS_BACKUP="${PRINTER_GENERIC_MACROS_TARGET}.backup_${timestamp}"
cp "$PRINTER_GENERIC_MACROS_TARGET" "$PRINTER_GENERIC_MACROS_BACKUP"
print_success "Backed up: $PRINTER_GENERIC_MACROS_TARGET → $PRINTER_GENERIC_MACROS_BACKUP"
if [ "$was_symlink" -eq 1 ]; then
remove_symlink_if_exists "$PRINTER_GENERIC_MACROS_TARGET"
fi
cp "$PRINTER_GENERIC_MACROS_SOURCE" "$PRINTER_GENERIC_MACROS_TARGET"
print_success "Copied: $PRINTER_GENERIC_MACROS_SOURCE → $PRINTER_GENERIC_MACROS_TARGET"
fi
else
cp "$PRINTER_GENERIC_MACROS_SOURCE" "$PRINTER_GENERIC_MACROS_TARGET"
print_success "Copied: $PRINTER_GENERIC_MACROS_SOURCE → $PRINTER_GENERIC_MACROS_TARGET"
fi
# Legacy filename support (cleanup old printer_macros_generic.cfg symlinks)
LEGACY_PRINTER_GENERIC_MACROS_TARGET="$CONFIG_DIR/printer_macros_generic.cfg"
if is_symlink "$LEGACY_PRINTER_GENERIC_MACROS_TARGET"; then
print_warning "Legacy printer_macros_generic.cfg symlink detected"
print_info "Current printer_macros_generic.cfg is a symlink (→ $(readlink "$LEGACY_PRINTER_GENERIC_MACROS_TARGET"))"
if prompt_yes_no "Replace printer_macros_generic.cfg with a local copy?"; then
local timestamp=$(date +"%Y%m%d_%H%M%S")
local legacy_backup="${LEGACY_PRINTER_GENERIC_MACROS_TARGET}.backup_${timestamp}"
cp "$LEGACY_PRINTER_GENERIC_MACROS_TARGET" "$legacy_backup"
print_success "Backed up: $LEGACY_PRINTER_GENERIC_MACROS_TARGET → $legacy_backup"
remove_symlink_if_exists "$LEGACY_PRINTER_GENERIC_MACROS_TARGET"
cp "$PRINTER_GENERIC_MACROS_SOURCE" "$LEGACY_PRINTER_GENERIC_MACROS_TARGET"
print_success "Copied: $PRINTER_GENERIC_MACROS_SOURCE → $LEGACY_PRINTER_GENERIC_MACROS_TARGET"
else
print_info "Skipped printer_macros_generic.cfg replacement"
fi
fi
# ========================================================================
# Step 4: Copy ACE configuration file
# ========================================================================
print_header "Step 4: ACE Configuration Files"
ACE_CONFIG_SOURCE="$SCRIPT_DIR/config/ace_${PRINTER_MODEL}.cfg"
ACE_CONFIG_TARGET="$CONFIG_DIR/ace_${PRINTER_MODEL}.cfg"
if [ ! -f "$ACE_CONFIG_SOURCE" ]; then
print_error "ACE config file not found: $ACE_CONFIG_SOURCE"
exit 1
fi
if [ -f "$ACE_CONFIG_TARGET" ]; then
print_warning "ace_${PRINTER_MODEL}.cfg already exists"
local was_symlink=0
if is_symlink "$ACE_CONFIG_TARGET"; then
was_symlink=1
print_info "Current ace_${PRINTER_MODEL}.cfg is a symlink (→ $(readlink "$ACE_CONFIG_TARGET"))"
fi
if ! prompt_yes_no "Back up and replace ace_${PRINTER_MODEL}.cfg?"; then
print_info "Skipped ace_${PRINTER_MODEL}.cfg installation"
else
local timestamp=$(date +"%Y%m%d_%H%M%S")
ACE_CONFIG_BACKUP="${ACE_CONFIG_TARGET}.backup_${timestamp}"
cp "$ACE_CONFIG_TARGET" "$ACE_CONFIG_BACKUP"
print_success "Backed up: $ACE_CONFIG_TARGET → $ACE_CONFIG_BACKUP"
if [ "$was_symlink" -eq 1 ]; then
remove_symlink_if_exists "$ACE_CONFIG_TARGET"
fi
cp "$ACE_CONFIG_SOURCE" "$ACE_CONFIG_TARGET"
print_success "Copied: $ACE_CONFIG_SOURCE → $ACE_CONFIG_TARGET"
fi
else
cp "$ACE_CONFIG_SOURCE" "$ACE_CONFIG_TARGET"
print_success "Copied: $ACE_CONFIG_SOURCE → $ACE_CONFIG_TARGET"
fi
# ========================================================================
# Step 5: Copy ACE macro file
# ========================================================================
print_header "Step 5: ACE Macro Files"
MACROS_SOURCE="$SCRIPT_DIR/config/ace_macros_generic.cfg"
MACROS_TARGET="$CONFIG_DIR/ace_macros_generic.cfg"
if [ ! -f "$MACROS_SOURCE" ]; then
print_error "ACE macros file not found: $MACROS_SOURCE"
exit 1
fi
if [ -f "$MACROS_TARGET" ]; then
print_warning "ace_macros_generic.cfg already exists"
local was_symlink=0
if is_symlink "$MACROS_TARGET"; then
was_symlink=1
print_info "Current ace_macros_generic.cfg is a symlink (→ $(readlink "$MACROS_TARGET"))"
fi
if ! prompt_yes_no "Back up and replace ace_macros_generic.cfg?"; then
print_info "Skipped ace_macros_generic.cfg installation"
else
local timestamp=$(date +"%Y%m%d_%H%M%S")
ACE_MACROS_BACKUP="${MACROS_TARGET}.backup_${timestamp}"
cp "$MACROS_TARGET" "$ACE_MACROS_BACKUP"
print_success "Backed up: $MACROS_TARGET → $ACE_MACROS_BACKUP"
if [ "$was_symlink" -eq 1 ]; then
remove_symlink_if_exists "$MACROS_TARGET"
fi
cp "$MACROS_SOURCE" "$MACROS_TARGET"
print_success "Copied: $MACROS_SOURCE → $MACROS_TARGET"
fi
else
cp "$MACROS_SOURCE" "$MACROS_TARGET"
print_success "Copied: $MACROS_SOURCE → $MACROS_TARGET"
fi
# ========================================================================
# Step 6: Link KlipperScreen panel (if available)
# ========================================================================
print_header "Step 6: KlipperScreen Integration (Optional)"
KLIPPERSCREEN_ROOT_DIR="$INSTALL_HOME/KlipperScreen"
KLIPPERSCREEN_PANELS_DIR="$KLIPPERSCREEN_ROOT_DIR/panels"
KLIPPERSCREEN_PANEL_SOURCE="$SCRIPT_DIR/KlipperScreen/acepro.py"
KLIPPERSCREEN_PANEL_TARGET="$KLIPPERSCREEN_PANELS_DIR/acepro.py"
if [ ! -d "$KLIPPERSCREEN_PANELS_DIR" ]; then
print_warning "KlipperScreen panels directory not found: $KLIPPERSCREEN_PANELS_DIR"
print_info "KlipperScreen integration skipped (not installed)"
else
if [ ! -f "$KLIPPERSCREEN_PANEL_SOURCE" ]; then
print_error "KlipperScreen panel file not found: $KLIPPERSCREEN_PANEL_SOURCE"
else
print_info "KlipperScreen panels directory found"
create_or_replace_symlink "$KLIPPERSCREEN_PANEL_SOURCE" "$KLIPPERSCREEN_PANEL_TARGET" "acepro.py panel"
fi
fi
# Optional: patch KlipperScreen core to subscribe to ACE objects
KLIPPERSCREEN_PATCH="$SCRIPT_DIR/patches/ace_global_subscription.patch"
if [ -d "$KLIPPERSCREEN_ROOT_DIR" ] && [ -f "$KLIPPERSCREEN_PATCH" ]; then
echo ""
print_info "ACE patch available for KlipperScreen core subscription."
if prompt_yes_no "Apply ACE KlipperScreen patch now?"; then
print_info "Checking ACE patch applicability..."
if patch -d "$KLIPPERSCREEN_ROOT_DIR" -p1 --forward --dry-run < "$KLIPPERSCREEN_PATCH"; then
print_info "Applying ACE patch to $KLIPPERSCREEN_ROOT_DIR"
if patch -d "$KLIPPERSCREEN_ROOT_DIR" -p1 --forward < "$KLIPPERSCREEN_PATCH"; then
print_success "KlipperScreen patch applied"
else
print_warning "Patch failed during apply (unexpected). Please review output."
fi
else
print_warning "Patch did not apply cleanly (likely already applied or conflicting changes). Skipping."
fi
else
print_info "Skipped KlipperScreen patch (you can apply $KLIPPERSCREEN_PATCH manually later)"
fi
elif [ ! -f "$KLIPPERSCREEN_PATCH" ]; then
print_warning "KlipperScreen patch file not found: $KLIPPERSCREEN_PATCH"
fi
# Ensure KlipperScreen.conf has font_size = small and ACE Pro menu entry
if [ -d "$KLIPPERSCREEN_ROOT_DIR" ]; then
KLIPPERSCREEN_CONF="$CONFIG_DIR/KlipperScreen.conf"
echo ""
print_info "Checking KlipperScreen.conf for font_size setting..."
ensure_klipperscreen_font_size "$KLIPPERSCREEN_CONF"
print_info "Checking KlipperScreen.conf for ACE Pro menu entries (main + print menus)..."
ensure_klipperscreen_acepro_menu "$KLIPPERSCREEN_CONF"
fi
# ========================================================================
# Step 7: Service restart
# ========================================================================
print_header "Step 7: Service Restart"
echo "Moonraker (if ACE status was linked), Klipper and KlipperScreen need to be restarted for changes to take effect."
echo ""
if [ "$MOONRAKER_RESTART_NEEDED" -eq 1 ]; then
if prompt_yes_no "Restart Moonraker service now?"; then
print_info "Restarting Moonraker..."
sudo systemctl restart moonraker
if [ $? -eq 0 ]; then
print_success "Moonraker restarted"
else
print_error "Failed to restart Moonraker"
fi
else
print_warning "Moonraker not restarted. You can restart manually:"
echo " sudo systemctl restart moonraker"
fi
echo ""
fi
if prompt_yes_no "Restart Klipper service now?"; then
print_info "Restarting Klipper..."
sudo systemctl restart klipper
if [ $? -eq 0 ]; then
print_success "Klipper restarted"
else
print_error "Failed to restart Klipper"
fi
else
print_warning "Klipper not restarted. You can restart manually:"
echo " sudo systemctl restart klipper"
fi
if [ -d "$KLIPPERSCREEN_PANELS_DIR" ]; then
echo ""
if prompt_yes_no "Restart KlipperScreen service now?"; then
print_info "Restarting KlipperScreen..."
sudo systemctl restart KlipperScreen 2>/dev/null || \
sudo supervisorctl restart klipperscreen 2>/dev/null || \
print_warning "Could not restart KlipperScreen. You can restart manually or via supervisor"
if [ $? -eq 0 ]; then
print_success "KlipperScreen restarted"
fi
else
print_warning "KlipperScreen not restarted. You can restart manually:"
echo " sudo systemctl restart KlipperScreen"
echo " or: sudo supervisorctl restart klipperscreen"
fi
fi
# ========================================================================
# Installation complete
# ========================================================================
print_header "Installation Complete!"
cat << EOF
ACE Pro driver installation finished!
Configuration Files:
New printer.cfg: $PRINTER_CONFIG_TARGET
EOF
# Show backup file if one was created
if [ -n "$PRINTER_CONFIG_BACKUP" ] && [ -f "$PRINTER_CONFIG_BACKUP" ]; then
cat << EOF
Backed up printer.cfg: $PRINTER_CONFIG_BACKUP
EOF
fi
if [ -f "$PRINTER_GENERIC_MACROS_TARGET" ]; then
cat << EOF
New printer_generic_macros.cfg: $PRINTER_GENERIC_MACROS_TARGET
EOF
fi
if [ -n "$PRINTER_GENERIC_MACROS_BACKUP" ] && [ -f "$PRINTER_GENERIC_MACROS_BACKUP" ]; then
cat << EOF
Backed up printer_generic_macros.cfg: $PRINTER_GENERIC_MACROS_BACKUP
EOF
fi
if [ -f "$ACE_CONFIG_TARGET" ]; then
cat << EOF
New ace_${PRINTER_MODEL}.cfg: $ACE_CONFIG_TARGET
EOF
fi
if [ -n "$ACE_CONFIG_BACKUP" ] && [ -f "$ACE_CONFIG_BACKUP" ]; then
cat << EOF
Backed up ace_${PRINTER_MODEL}.cfg: $ACE_CONFIG_BACKUP
EOF
fi
if [ -f "$MACROS_TARGET" ]; then
cat << EOF
New ace_macros_generic.cfg: $MACROS_TARGET
EOF
fi
if [ -n "$ACE_MACROS_BACKUP" ] && [ -f "$ACE_MACROS_BACKUP" ]; then
cat << EOF
Backed up ace_macros_generic.cfg: $ACE_MACROS_BACKUP
EOF
fi
cat << EOF
Next steps:
1. Review and customize ACE configuration:
$CONFIG_DIR/ace_${PRINTER_MODEL}.cfg
- Set ace_count to number of ACE units
- Adjust feed/retract speeds
- Configure sensor pins if needed
- Re-run installer after updates to pick up template changes
2. Review and merge printer configuration:
New config: $PRINTER_CONFIG_TARGET
EOF
# Show backup for reference if it exists
if [ -n "$PRINTER_CONFIG_BACKUP" ] && [ -f "$PRINTER_CONFIG_BACKUP" ]; then
cat << EOF
Original backup: $PRINTER_CONFIG_BACKUP
Manually review and merge any custom changes from the backup file
into the new printer.cfg file, especially:
- Custom macros
- Non-standard hardware settings
- Personal customizations
EOF
fi
cat << EOF
3. Review printer_generic_macros.cfg if you plan to customize pause/resume, velocity stack, or purge helpers:
$CONFIG_DIR/printer_generic_macros.cfg
4. Review ace_macros_generic.cfg if you plan to tweak ACE hooks or safety wrappers:
$CONFIG_DIR/ace_macros_generic.cfg
5. Restart Klipper if not already restarted:
sudo systemctl restart klipper
6. Test basic commands in Klipper console:
e.g. ACE_GET_STATUS
7. Optional but recommened: Set inventory for each tool:
ACE_SET_SLOT INSTANCE=0 INDEX=0 COLOR=255,0,0 MATERIAL=PLA TEMP=210
8. If using Orca Slicer:
Install the orca_flush_to_purgelength.py post-processing script on your host PC
See README.md section on Orca Slicer integration for detailed instructions
EOF
}
# ============================================================================
# Entry Point
# ============================================================================
if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
main "$@"
fi