forked from dw-0/kiauh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcode_shell_command.sh
123 lines (106 loc) · 3.99 KB
/
gcode_shell_command.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
#!/usr/bin/env bash
#=======================================================================#
# Copyright (C) 2020 - 2023 Dominik Willner <[email protected]> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
#=================================================#
#======== INSTALL GCODE_SHELL_COMMAND.PY =========#
#=================================================#
function setup_gcode_shell_command() {
top_border
echo -e "| You are about to install the 'G-Code Shell Command' |"
echo -e "| extension. Please make sure to read the instructions |"
echo -e "| before you continue and remember that potential risks |"
echo -e "| can be involved after installing this extension! |"
blank_line
echo -e "| ${red}You accept that you are doing this on your own risk!${white} |"
bottom_border
local yn
while true; do
read -p "${cyan}###### Do you want to continue? (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
if [[ ! -d "${KLIPPER_DIR}/klippy/extras" ]]; then
print_error "Folder ~/klipper/klippy/extras not found!\n Klipper not installed yet?"
return
fi
status_msg "Installing gcode shell command extension ..."
if [[ ! -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py" ]]; then
install_gcode_shell_command
else
echo; warn_msg "File 'gcode_shell_command.py' already exists in the destination location!"
while true; do
read -p "${cyan}###### Do you want to overwrite it? (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
rm -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py"
install_gcode_shell_command
break;;
N|n|No|no)
select_msg "No"
break;;
*)
error_msg "Invalid Input!";;
esac
done
fi
return;;
N|n|No|no)
select_msg "No"
return;;
*)
error_msg "Invalid Input!";;
esac
done
}
function install_gcode_shell_command() {
do_action_service "stop" "klipper"
status_msg "Copy 'gcode_shell_command.py' to '${KLIPPER_DIR}/klippy/extras' ..."
if cp "${KIAUH_SRCDIR}/resources/gcode_shell_command.py" "${KLIPPER_DIR}/klippy/extras"; then
ok_msg "Done!"
else
error_msg "Cannot copy file to target destination...Exiting!"
return 1
fi
local yn
while true; do
echo
read -p "${cyan}###### Create an example shell command? (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
create_example_shell_command
break;;
N|n|No|no)
select_msg "No"
break;;
esac
done
do_action_service "restart" "klipper"
print_confirm "Shell command extension installed!"
return
}
function create_example_shell_command() {
### create a backup of the config folder
backup_klipper_config_dir
local configs regex path
regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/printer\.cfg"
configs=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort)
for cfg in ${configs}; do
path=$(echo "${cfg}" | rev | cut -d"/" -f2- | rev)
if [[ ! -f "${path}/shell_command.cfg" ]]; then
status_msg "Copy shell_command.cfg to ${path} ..."
cp "${KIAUH_SRCDIR}/resources/shell_command.cfg" "${path}"
ok_msg "${path}/shell_command.cfg created!"
### write include to the very first line of the printer.cfg
sed -i "1 i [include shell_command.cfg]" "${cfg}"
fi
done
}