refactor: refactor gcode_shell_command
Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
@@ -400,97 +400,6 @@ function dependency_check(){
|
||||
fi
|
||||
}
|
||||
|
||||
function setup_gcode_shell_command(){
|
||||
echo
|
||||
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
|
||||
while true; do
|
||||
read -p "${cyan}###### Do you want to continue? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
if [ -d "${KLIPPER_DIR}/klippy/extras" ]; then
|
||||
status_msg "Installing gcode shell command extension ..."
|
||||
if [ -f "${KLIPPER_DIR}/klippy/extras/gcode_shell_command.py" ]; then
|
||||
warn_msg "There is already a file named 'gcode_shell_command.py'\nin 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|"")
|
||||
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
|
||||
ERROR_MSG="Folder ~/klipper/klippy/extras not found!"
|
||||
fi
|
||||
break;;
|
||||
N|n|No|no)
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function install_gcode_shell_command(){
|
||||
do_action_service "stop" "klipper"
|
||||
status_msg "Copy 'gcode_shell_command.py' to '${KLIPPER_DIR}/klippy/extras' ..."
|
||||
cp "${SRCDIR}/kiauh/resources/gcode_shell_command.py" "${KLIPPER_DIR}/klippy/extras"
|
||||
while true; do
|
||||
echo
|
||||
read -p "${cyan}###### Do you want to create the example shell command? (Y/n):${white} " yn
|
||||
case "${yn}" in
|
||||
Y|y|Yes|yes|"")
|
||||
status_msg "Copy shell_command.cfg ..."
|
||||
### create a backup of the config folder
|
||||
backup_klipper_config_dir
|
||||
|
||||
### handle single printer.cfg
|
||||
if [ -f "${klipper_cfg_loc}/printer.cfg" ] && [ ! -f "${klipper_cfg_loc}/shell_command.cfg" ]; then
|
||||
### copy shell_command.cfg to config location
|
||||
cp "${SRCDIR}/kiauh/resources/shell_command.cfg" "${klipper_cfg_loc}"
|
||||
ok_msg "${klipper_cfg_loc}/shell_command.cfg created!"
|
||||
|
||||
### write the include to the very first line of the printer.cfg
|
||||
sed -i "1 i [include shell_command.cfg]" "${klipper_cfg_loc}/printer.cfg"
|
||||
fi
|
||||
|
||||
### handle multi printer.cfg
|
||||
if ls "${klipper_cfg_loc}"/printer_* 2>/dev/null 1>&2; then
|
||||
for config in $(find ${klipper_cfg_loc}/printer_*/printer.cfg); do
|
||||
path=$(echo "${config}" | rev | cut -d"/" -f2- | rev)
|
||||
if [ ! -f "${path}/shell_command.cfg" ]; then
|
||||
### copy shell_command.cfg to config location
|
||||
cp "${SRCDIR}/kiauh/resources/shell_command.cfg" "${path}"
|
||||
ok_msg "${path}/shell_command.cfg created!"
|
||||
|
||||
### write the include to the very first line of the printer.cfg
|
||||
sed -i "1 i [include shell_command.cfg]" "${path}/printer.cfg"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
break;;
|
||||
N|n|No|no)
|
||||
break;;
|
||||
esac
|
||||
done
|
||||
ok_msg "Shell command extension installed!"
|
||||
do_action_service "restart" "klipper"
|
||||
}
|
||||
|
||||
function system_check_webui(){
|
||||
### check system for an installed and enabled octoprint service
|
||||
if sudo systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then
|
||||
|
||||
Reference in New Issue
Block a user