-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·190 lines (168 loc) · 7 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·190 lines (168 loc) · 7 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
#!/bin/bash
# Klipper G-code Preprocessor Installation Script
#
# This script installs the G-code preprocessor system for Klipper
# It can be used standalone or integrated with klipper-toolchanger
KLIPPER_PATH="${HOME}/klipper"
MOONRAKER_PATH="${HOME}/moonraker"
INSTALL_PATH="${HOME}/klipper-gcode-preprocessor"
CONFIG_PATH="${HOME}/printer_data/config"
set -eu
export LC_ALL=C
function preflight_checks {
if [ "$EUID" -eq 0 ]; then
echo "[PRE-CHECK] This script must not be run as root!"
exit -1
fi
if [ "$(sudo systemctl list-units --full -all -t service --no-legend | grep -F 'klipper.service')" ]; then
printf "[PRE-CHECK] Klipper service found! Continuing...\n\n"
else
echo "[ERROR] Klipper service not found, please install Klipper first!"
exit -1
fi
}
function check_download {
local installdirname installbasename
installdirname="$(dirname ${INSTALL_PATH})"
installbasename="$(basename ${INSTALL_PATH})"
if [ ! -d "${INSTALL_PATH}" ]; then
echo "[DOWNLOAD] Downloading repository..."
if git -C $installdirname clone https://github.com/jwellman80/klipper-gcode-preprocessor.git $installbasename; then
chmod +x ${INSTALL_PATH}/install.sh
printf "[DOWNLOAD] Download complete!\n\n"
else
echo "[ERROR] Download of git repository failed!"
echo "[INFO] Continuing with local installation..."
fi
else
printf "[DOWNLOAD] Repository already found locally. Continuing...\n\n"
fi
}
function link_klipper_modules {
echo "[INSTALL] Linking G-code preprocessor modules to Klipper..."
# Link main modules
ln -sfn "${INSTALL_PATH}"/klipper/extras/gcode_preprocessor_base.py "${KLIPPER_PATH}/klippy/extras/"
ln -sfn "${INSTALL_PATH}"/klipper/extras/gcode_preprocessor.py "${KLIPPER_PATH}/klippy/extras/"
# Link preprocessor plugins
mkdir -p "${KLIPPER_PATH}/klippy/extras/preprocessors"
for file in "${INSTALL_PATH}"/klipper/extras/preprocessors/*.py; do
ln -sfn "${file}" "${KLIPPER_PATH}/klippy/extras/preprocessors/"
done
echo "[INSTALL] Klipper modules linked successfully!"
}
function install_config {
echo "[INSTALL] Installing configuration files..."
mkdir -p "${CONFIG_PATH}"/gcode-preprocessor
# Copy config file if it doesn't exist, otherwise show diff
if [ ! -f "${CONFIG_PATH}/gcode-preprocessor/preprocessor.cfg" ]; then
cp "${INSTALL_PATH}"/config/gcode-preprocessor.cfg "${CONFIG_PATH}"/gcode-preprocessor/preprocessor.cfg
echo "[INSTALL] Configuration file installed to ${CONFIG_PATH}/gcode-preprocessor/preprocessor.cfg"
else
echo "[INFO] Configuration file already exists at ${CONFIG_PATH}/gcode-preprocessor/preprocessor.cfg"
echo "[INFO] Review ${INSTALL_PATH}/config/gcode-preprocessor.cfg for any new settings"
fi
echo ""
echo "[INFO] Add the following line to your printer.cfg to enable the preprocessor:"
echo ""
echo " [include gcode-preprocessor/preprocessor.cfg]"
echo ""
}
function install_moonraker_component {
echo -e "\n\nInstall Moonraker component for automatic G-code preprocessing?"
echo "This enables automatic preprocessing when files are uploaded via Mainsail/Fluidd."
echo "You can skip this and use manual preprocessing with PREPROCESS_GCODE_FILE instead."
echo ""
echo "1. Yes, install Moonraker component (recommended)"
echo "2. No, skip Moonraker integration"
read -rp "Select an option [1-2]: " moonraker_choice
case $moonraker_choice in
1)
if [ -d "${MOONRAKER_PATH}/moonraker/components" ]; then
echo "[INSTALL] Installing Moonraker component..."
ln -sfn "${INSTALL_PATH}"/moonraker/gcode_preprocessor.py "${MOONRAKER_PATH}"/moonraker/components/
echo "[INSTALL] Moonraker component installed!"
echo ""
echo "[INFO] Add the following to your moonraker.conf to enable automatic preprocessing:"
echo ""
echo "[gcode_preprocessor]"
echo "enable_preprocessing: True"
echo ""
echo "[INFO] Then restart Moonraker: sudo systemctl restart moonraker"
else
echo "[WARNING] Moonraker components directory not found at ${MOONRAKER_PATH}/moonraker/components"
echo "[WARNING] Moonraker component installation skipped."
echo "[INFO] You can still use manual preprocessing with PREPROCESS_GCODE_FILE"
fi
;;
2)
echo "[INSTALL] Skipping Moonraker component installation."
echo "[INFO] You can use manual preprocessing with PREPROCESS_GCODE_FILE"
;;
*)
echo "[ERROR] Invalid option selected!"
exit -1
;;
esac
}
function restart_services {
echo -e "\n[POST-INSTALL] Restart Klipper and Moonraker now?"
echo "1. Yes, restart both services"
echo "2. No, I'll restart manually later"
read -rp "Select an option [1-2]: " restart_choice
case $restart_choice in
1)
echo "[POST-INSTALL] Restarting Klipper..."
sudo systemctl restart klipper
echo "[POST-INSTALL] Klipper restarted!"
if [ "$(sudo systemctl list-units --full -all -t service --no-legend | grep -F 'moonraker.service')" ]; then
echo "[POST-INSTALL] Restarting Moonraker..."
sudo systemctl restart moonraker
echo "[POST-INSTALL] Moonraker restarted!"
fi
;;
2)
echo "[POST-INSTALL] Please restart services manually when ready:"
echo " sudo systemctl restart klipper"
echo " sudo systemctl restart moonraker"
;;
*)
echo "[WARNING] Invalid option, skipping restart"
;;
esac
}
function show_completion_message {
echo ""
echo "========================================"
echo "Installation Complete!"
echo "========================================"
echo ""
echo "Next steps:"
echo "1. Add to your printer.cfg:"
echo " [include gcode-preprocessor/preprocessor.cfg]"
echo ""
echo "2. Restart services if you haven't already:"
echo " sudo systemctl restart klipper"
echo " sudo systemctl restart moonraker"
echo ""
echo "3. Test the preprocessor with:"
echo " PREPROCESS_GCODE_FILE FILE=/path/to/file.gcode"
echo ""
echo "4. List available processors:"
echo " LIST_GCODE_PROCESSORS"
echo ""
echo "Documentation: ${INSTALL_PATH}/docs/README.md"
echo "Example test file: ${INSTALL_PATH}/examples/test_sample.gcode"
echo ""
}
# Main installation flow
printf "\n============================================\n"
echo " Klipper G-code Preprocessor Installer"
printf "============================================\n\n"
# Run steps
preflight_checks
check_download
link_klipper_modules
install_config
install_moonraker_component
restart_services
show_completion_message