mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-14 02:54:28 +05:00
fix: little rework and fixes of shell command extension installation
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
# Shell Command Extension
|
# G-Code Shell Command Extension
|
||||||
|
|
||||||
### Creator of this extension is [Arksine](https://github.com/Arksine).
|
### Creator of this extension is [Arksine](https://github.com/Arksine).
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ After installing the extension you can execute linux commands or even scripts fr
|
|||||||
# Runs a linux command or script from within klipper. Note that sudo commands
|
# Runs a linux command or script from within klipper. Note that sudo commands
|
||||||
# that require password authentication are disallowed. All executable scripts
|
# that require password authentication are disallowed. All executable scripts
|
||||||
# should include a shebang.
|
# should include a shebang.
|
||||||
# [shell_command my_shell_cmd]
|
# [gcode_shell_command my_shell_cmd]
|
||||||
#command:
|
#command:
|
||||||
# The linux shell command/script to be executed. This parameter must be
|
# The linux shell command/script to be executed. This parameter must be
|
||||||
# provided
|
# provided
|
||||||
@@ -31,7 +31,7 @@ Once you have set up a shell command with the given parameters from above in you
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
```
|
```
|
||||||
[shell_command hello_world]
|
[gcode_shell_command hello_world]
|
||||||
command: echo hello world
|
command: echo hello world
|
||||||
timeout: 2.
|
timeout: 2.
|
||||||
verbose: True
|
verbose: True
|
||||||
@@ -189,33 +189,42 @@ print_error(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
install_extension_shell_command(){
|
setup_gcode_shell_command(){
|
||||||
echo
|
echo
|
||||||
top_border
|
top_border
|
||||||
echo -e "| You are about to install the shell command extension. |"
|
echo -e "| You are about to install the G-Code Shell Command |"
|
||||||
echo -e "| Please make sure to read the instructions before you |"
|
echo -e "| extension. Please make sure to read the instructions |"
|
||||||
echo -e "| continue and remember that there are potential risks! |"
|
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!${default} |"
|
||||||
bottom_border
|
bottom_border
|
||||||
while true; do
|
while true; do
|
||||||
read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn
|
read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn
|
||||||
case "$yn" in
|
case "$yn" in
|
||||||
Y|y|Yes|yes|"")
|
Y|y|Yes|yes|"")
|
||||||
if [ -d $KLIPPER_DIR/klippy/extras ] && [ ! -f $KLIPPER_DIR/klippy/extras/shell_command.py ] ; then
|
if [ -d $KLIPPER_DIR/klippy/extras ]; then
|
||||||
status_msg "Installing shell command extension ..."
|
status_msg "Installing gcode shell command extension ..."
|
||||||
stop_klipper
|
status_msg "Copy gcode_shell_command.py to '$KLIPPER_DIR/klippy/extras' ..."
|
||||||
cp ${HOME}/kiauh/resources/shell_command.py $KLIPPER_DIR/klippy/extras
|
if [ -f $KLIPPER_DIR/klippy/extras/gcode_shell_command.py ]; then
|
||||||
status_msg "Creating example macro ..."
|
warn_msg "There is already a file named 'gcode_shell_command.py'"
|
||||||
create_shell_command_example
|
warn_msg "in the destination location!"
|
||||||
ok_msg "Example macro created!"
|
while true; do
|
||||||
ok_msg "Shell command extension installed!"
|
read -p "${cyan}###### Do you want to overwrite it? (Y/n):${default} " yn
|
||||||
restart_klipper
|
case "$yn" in
|
||||||
|
Y|y|Yes|yes|"")
|
||||||
|
rm -f $KLIPPER_DIR/klippy/extras/gcode_shell_command.py
|
||||||
|
install_gcode_shell_command
|
||||||
|
break;;
|
||||||
|
N|n|No|no)
|
||||||
|
break;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
else
|
||||||
|
install_gcode_shell_command
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
if [ ! -d $KLIPPER_DIR/klippy/extras ]; then
|
ERROR_MSG="Folder ~/klipper/klippy/extras not found!"
|
||||||
ERROR_MSG="Folder ~/klipper/klippy/extras not found!"
|
|
||||||
fi
|
|
||||||
if [ -f $KLIPPER_DIR/klippy/extras/shell_command.py ]; then
|
|
||||||
ERROR_MSG="Extension already installed!"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
break;;
|
break;;
|
||||||
N|n|No|no)
|
N|n|No|no)
|
||||||
@@ -227,12 +236,23 @@ install_extension_shell_command(){
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
install_gcode_shell_command(){
|
||||||
|
stop_klipper
|
||||||
|
cp ${HOME}/kiauh/resources/gcode_shell_command.py $KLIPPER_DIR/klippy/extras
|
||||||
|
status_msg "Creating example macro ..."
|
||||||
|
locate_printer_cfg
|
||||||
|
create_shell_command_example
|
||||||
|
ok_msg "Example macro created!"
|
||||||
|
ok_msg "Shell command extension installed!"
|
||||||
|
restart_klipper
|
||||||
|
}
|
||||||
|
|
||||||
create_shell_command_example(){
|
create_shell_command_example(){
|
||||||
unset SC_ENTRY
|
unset SC_ENTRY
|
||||||
unset write_entries
|
unset write_entries
|
||||||
#check for a SAVE_CONFIG entry
|
#check for a SAVE_CONFIG entry
|
||||||
SC="#*# <---------------------- SAVE_CONFIG ---------------------->"
|
SC="#*# <---------------------- SAVE_CONFIG ---------------------->"
|
||||||
if [[ $(grep "$SC" ${HOME}/printer.cfg) ]]; then
|
if [[ $(grep "$SC" $PRINTER_CFG) ]]; then
|
||||||
SC_LINE=$(grep -n "$SC" $PRINTER_CFG | cut -d ":" -f1)
|
SC_LINE=$(grep -n "$SC" $PRINTER_CFG | cut -d ":" -f1)
|
||||||
PRE_SC_LINE=$(expr $SC_LINE - 1)
|
PRE_SC_LINE=$(expr $SC_LINE - 1)
|
||||||
SC_ENTRY="true"
|
SC_ENTRY="true"
|
||||||
@@ -243,10 +263,6 @@ create_shell_command_example(){
|
|||||||
write_entries+=("[shell_command hello_world]\ncommand: echo hello world\ntimeout: 2.\nverbose: True")
|
write_entries+=("[shell_command hello_world]\ncommand: echo hello world\ntimeout: 2.\nverbose: True")
|
||||||
#example macro
|
#example macro
|
||||||
write_entries+=("[gcode_macro HELLO_WORLD]\ngcode:\n RUN_SHELL_COMMAND CMD=hello_world")
|
write_entries+=("[gcode_macro HELLO_WORLD]\ngcode:\n RUN_SHELL_COMMAND CMD=hello_world")
|
||||||
if [ "${#write_entries[@]}" != "0" ]; then
|
|
||||||
write_entries+=("\\\n############################\n##### CREATED BY KIAUH #####\n############################")
|
|
||||||
write_entries=("############################\n" "${write_entries[@]}")
|
|
||||||
fi
|
|
||||||
#execute writing
|
#execute writing
|
||||||
status_msg "Writing to printer.cfg ..."
|
status_msg "Writing to printer.cfg ..."
|
||||||
if [ "$SC_ENTRY" = "true" ]; then
|
if [ "$SC_ENTRY" = "true" ]; then
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ advanced_menu(){
|
|||||||
7)
|
7)
|
||||||
clear
|
clear
|
||||||
print_header
|
print_header
|
||||||
install_extension_shell_command
|
setup_gcode_shell_command
|
||||||
print_msg && clear_msg
|
print_msg && clear_msg
|
||||||
advanced_ui;;
|
advanced_ui;;
|
||||||
Q|q)
|
Q|q)
|
||||||
|
|||||||
Reference in New Issue
Block a user