2021-04-03 19:29:59 +02:00
|
|
|
### base variables
|
|
|
|
|
SYSTEMDDIR="/etc/systemd/system"
|
|
|
|
|
|
2020-07-13 16:59:40 +02:00
|
|
|
# setting up some frequently used functions
|
|
|
|
|
check_euid(){
|
|
|
|
|
if [ "$EUID" -eq 0 ]
|
|
|
|
|
then
|
|
|
|
|
echo -e "${red}"
|
2020-07-23 10:20:14 +02:00
|
|
|
top_border
|
|
|
|
|
echo -e "| !!! THIS SCRIPT MUST NOT RAN AS ROOT !!! |"
|
|
|
|
|
bottom_border
|
2020-07-13 16:59:40 +02:00
|
|
|
echo -e "${default}"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-07 15:26:19 +01:00
|
|
|
check_klipper_cfg_path(){
|
|
|
|
|
source_kiauh_ini
|
|
|
|
|
if [ -z $klipper_cfg_loc ]; then
|
|
|
|
|
echo
|
|
|
|
|
top_border
|
|
|
|
|
echo -e "| ${red}!!! WARNING !!!${default} |"
|
|
|
|
|
echo -e "| ${red}No Klipper configuration directory set!${default} |"
|
|
|
|
|
hr
|
2021-01-30 20:42:32 +01:00
|
|
|
echo -e "| Before we can continue, KIAUH needs to know where |"
|
|
|
|
|
echo -e "| you want your printer configuration to be. |"
|
|
|
|
|
blank_line
|
|
|
|
|
echo -e "| Please specify a folder where your Klipper configu- |"
|
|
|
|
|
echo -e "| ration is stored or, if you don't have one yet, in |"
|
|
|
|
|
echo -e "| which it should be saved after the installation. |"
|
2021-01-07 15:26:19 +01:00
|
|
|
bottom_border
|
|
|
|
|
change_klipper_cfg_path
|
2020-08-26 08:18:18 +02:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-07 15:26:19 +01:00
|
|
|
change_klipper_cfg_path(){
|
|
|
|
|
source_kiauh_ini
|
|
|
|
|
old_klipper_cfg_loc="$klipper_cfg_loc"
|
2021-01-29 12:17:42 +01:00
|
|
|
EXAMPLE_FOLDER=$(printf "%s/your_config_folder" "${HOME}")
|
2021-01-07 15:26:19 +01:00
|
|
|
while true; do
|
2021-01-29 12:17:42 +01:00
|
|
|
top_border
|
|
|
|
|
echo -e "| ${red}IMPORTANT:${default} |"
|
2021-01-30 20:42:32 +01:00
|
|
|
echo -e "| Please enter the new path in the following format: |"
|
2021-01-29 12:17:42 +01:00
|
|
|
printf "| ${yellow}%-51s${default} |\n" "$EXAMPLE_FOLDER"
|
|
|
|
|
blank_line
|
|
|
|
|
echo -e "| By default 'klipper_config' is recommended! |"
|
|
|
|
|
bottom_border
|
2021-01-07 15:26:19 +01:00
|
|
|
echo
|
|
|
|
|
echo -e "${cyan}###### Please set the Klipper config directory:${default} "
|
|
|
|
|
if [ -z "$old_klipper_cfg_loc" ]; then
|
|
|
|
|
read -e -i "/home/${USER}/klipper_config" -e new_klipper_cfg_loc
|
|
|
|
|
else
|
|
|
|
|
read -e -i "$old_klipper_cfg_loc" -e new_klipper_cfg_loc
|
|
|
|
|
fi
|
|
|
|
|
echo
|
|
|
|
|
read -p "${cyan}###### Set config directory to '${yellow}$new_klipper_cfg_loc${cyan}' ? (Y/n):${default} " yn
|
|
|
|
|
case "$yn" in
|
|
|
|
|
Y|y|Yes|yes|"")
|
|
|
|
|
echo -e "###### > Yes"
|
|
|
|
|
|
2021-01-10 12:55:24 +01:00
|
|
|
### backup the old config dir
|
|
|
|
|
backup_klipper_config_dir
|
|
|
|
|
|
2021-01-07 15:26:19 +01:00
|
|
|
### write new location to kiauh.ini
|
|
|
|
|
sed -i "s|klipper_cfg_loc=$old_klipper_cfg_loc|klipper_cfg_loc=$new_klipper_cfg_loc|" $INI_FILE
|
|
|
|
|
status_msg "Directory set to '$new_klipper_cfg_loc'!"
|
|
|
|
|
|
|
|
|
|
### write new location to klipper and moonraker service
|
|
|
|
|
set_klipper_cfg_path
|
|
|
|
|
echo; ok_msg "Config directory changed!"
|
|
|
|
|
break;;
|
|
|
|
|
N|n|No|no)
|
|
|
|
|
echo -e "###### > No"
|
|
|
|
|
change_klipper_cfg_path
|
|
|
|
|
break;;
|
|
|
|
|
*)
|
|
|
|
|
print_unkown_cmd
|
|
|
|
|
print_msg && clear_msg;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_klipper_cfg_path(){
|
|
|
|
|
### stop services
|
|
|
|
|
klipper_service "stop" && moonraker_service "stop"
|
|
|
|
|
|
2021-04-03 19:29:59 +02:00
|
|
|
### copy config files to new klipper config folder
|
2021-01-10 12:55:24 +01:00
|
|
|
if [ ! -z "$old_klipper_cfg_loc" ] && [ -d "$old_klipper_cfg_loc" ]; then
|
2021-04-03 19:29:59 +02:00
|
|
|
if [ ! -d "$new_klipper_cfg_loc" ]; then
|
|
|
|
|
status_msg "Copy config files to '$new_klipper_cfg_loc' ..."
|
|
|
|
|
mkdir -p $new_klipper_cfg_loc
|
|
|
|
|
cd $old_klipper_cfg_loc
|
|
|
|
|
cp -r -v ./* $new_klipper_cfg_loc
|
|
|
|
|
ok_msg "Done!"
|
|
|
|
|
fi
|
2021-01-07 15:26:19 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
### handle single klipper instance service file
|
2021-04-03 19:29:59 +02:00
|
|
|
if [ -f $SYSTEMDDIR/klipper.service ]; then
|
2021-01-07 15:26:19 +01:00
|
|
|
status_msg "Configuring Klipper for new path ..."
|
2021-04-03 19:29:59 +02:00
|
|
|
sudo sed -i -r "/ExecStart=/ s| (.+)\/printer.cfg| $new_klipper_cfg_loc/printer.cfg|" $SYSTEMDDIR/klipper.service
|
2021-01-07 15:26:19 +01:00
|
|
|
ok_msg "OK!"
|
|
|
|
|
fi
|
|
|
|
|
### handle multi klipper instance service file
|
2021-04-03 19:29:59 +02:00
|
|
|
if ls $SYSTEMDDIR/klipper-*.service 2>/dev/null 1>&2; then
|
2021-01-07 15:26:19 +01:00
|
|
|
status_msg "Configuring Klipper for new path ..."
|
2021-04-03 19:29:59 +02:00
|
|
|
for service in $(find $SYSTEMDDIR/klipper-*.service); do
|
|
|
|
|
sudo sed -i -r "/ExecStart=/ s| (.+)\/printer_| $new_klipper_cfg_loc/printer_|" $service
|
2021-01-07 15:26:19 +01:00
|
|
|
done
|
|
|
|
|
ok_msg "OK!"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
### handle single moonraker instance service and moonraker.conf file
|
2021-04-03 19:29:59 +02:00
|
|
|
if [ -f $SYSTEMDDIR/moonraker.service ]; then
|
2021-01-07 15:26:19 +01:00
|
|
|
status_msg "Configuring Moonraker for new path ..."
|
2021-04-03 19:29:59 +02:00
|
|
|
sudo sed -i -r "/ExecStart=/ s|-c (.+)\/moonraker\.conf|-c $new_klipper_cfg_loc/moonraker.conf|" $SYSTEMDDIR/moonraker.service
|
|
|
|
|
|
2021-01-07 15:26:19 +01:00
|
|
|
### replace old file path with new one in moonraker.conf
|
2021-04-03 19:29:59 +02:00
|
|
|
sed -i -r "/config_path:/ s|config_path:.*|config_path: $new_klipper_cfg_loc|" $new_klipper_cfg_loc/moonraker.conf
|
2021-01-07 15:26:19 +01:00
|
|
|
ok_msg "OK!"
|
|
|
|
|
fi
|
|
|
|
|
### handle multi moonraker instance service file
|
2021-04-03 19:29:59 +02:00
|
|
|
if ls $SYSTEMDDIR/moonraker-*.service 2>/dev/null 1>&2; then
|
2021-01-07 15:26:19 +01:00
|
|
|
status_msg "Configuring Moonraker for new path ..."
|
2021-04-03 19:29:59 +02:00
|
|
|
for service in $(find $SYSTEMDDIR/moonraker-*.service); do
|
|
|
|
|
sudo sed -i -r "/ExecStart=/ s|-c (.+)\/printer_|-c $new_klipper_cfg_loc/printer_|" $service
|
2021-01-07 15:26:19 +01:00
|
|
|
done
|
2021-01-10 12:55:24 +01:00
|
|
|
### replace old file path with new one in moonraker.conf
|
|
|
|
|
for moonraker_conf in $(find $new_klipper_cfg_loc/printer_*/moonraker.conf); do
|
|
|
|
|
loc=$(echo "$moonraker_conf" | rev | cut -d"/" -f2- | rev)
|
2021-04-03 19:29:59 +02:00
|
|
|
sed -i -r "/config_path:/ s|config_path:.*|config_path: $loc|" $moonraker_conf
|
2021-01-07 15:26:19 +01:00
|
|
|
done
|
|
|
|
|
ok_msg "OK!"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
### reloading units
|
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
|
|
|
|
|
|
### restart services
|
2021-01-07 17:03:14 +01:00
|
|
|
klipper_service "restart" && moonraker_service "restart"
|
2020-07-13 16:59:40 +02:00
|
|
|
}
|
|
|
|
|
|
2021-01-07 15:26:19 +01:00
|
|
|
source_kiauh_ini(){
|
2021-01-29 12:17:42 +01:00
|
|
|
source $INI_FILE
|
2020-07-13 16:59:40 +02:00
|
|
|
}
|
2020-07-13 21:08:31 +02:00
|
|
|
|
2021-01-07 15:26:19 +01:00
|
|
|
klipper_service(){
|
|
|
|
|
### set a variable for the ok and status messages
|
|
|
|
|
[ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
|
|
|
|
|
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
|
|
|
|
|
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
|
|
|
|
|
|
2021-01-07 17:03:14 +01:00
|
|
|
if ls /etc/systemd/system/klipper-*.service 2>/dev/null 1>&2; then
|
2021-01-07 15:26:19 +01:00
|
|
|
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l)
|
|
|
|
|
INSTANCE=1
|
|
|
|
|
status_msg "$ACTION2 $INSTANCE_COUNT Klipper Services ..."
|
|
|
|
|
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
|
|
|
|
|
sudo systemctl $1 klipper-$INSTANCE && ok_msg "Klipper Service #$INSTANCE $ACTION1!"
|
|
|
|
|
### instance counter +1
|
|
|
|
|
INSTANCE=$(expr $INSTANCE + 1)
|
|
|
|
|
done
|
|
|
|
|
elif [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper.service")" ]; then
|
|
|
|
|
status_msg "$ACTION2 Klipper Service ..."
|
|
|
|
|
sudo systemctl $1 klipper && ok_msg "Klipper Service $ACTION1!"
|
|
|
|
|
fi
|
2020-07-13 16:59:40 +02:00
|
|
|
}
|
|
|
|
|
|
2021-01-07 15:26:19 +01:00
|
|
|
moonraker_service(){
|
|
|
|
|
### set a variable for the ok and status messages
|
|
|
|
|
[ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
|
|
|
|
|
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
|
|
|
|
|
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
|
|
|
|
|
|
2021-01-07 17:03:14 +01:00
|
|
|
if ls /etc/systemd/system/moonraker-*.service 2>/dev/null 1>&2; then
|
2021-01-07 15:26:19 +01:00
|
|
|
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service" | wc -l)
|
|
|
|
|
INSTANCE=1
|
|
|
|
|
status_msg "$ACTION2 $INSTANCE_COUNT Moonraker Services ..."
|
|
|
|
|
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
|
|
|
|
|
sudo systemctl $1 moonraker-$INSTANCE && ok_msg "Moonraker Service #$INSTANCE $ACTION1!"
|
|
|
|
|
### instance counter +1
|
|
|
|
|
INSTANCE=$(expr $INSTANCE + 1)
|
|
|
|
|
done
|
|
|
|
|
elif [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker.service")" ]; then
|
|
|
|
|
status_msg "$ACTION2 Moonraker Service ..."
|
|
|
|
|
sudo systemctl $1 moonraker && ok_msg "Moonraker Service $ACTION1!"
|
|
|
|
|
fi
|
2020-07-13 21:08:31 +02:00
|
|
|
}
|
|
|
|
|
|
2021-01-28 23:39:42 +01:00
|
|
|
dwc_service(){
|
|
|
|
|
### set a variable for the ok and status messages
|
|
|
|
|
[ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
|
|
|
|
|
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
|
|
|
|
|
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
|
2020-07-15 18:57:46 +02:00
|
|
|
|
2021-01-28 23:39:42 +01:00
|
|
|
if ls /etc/systemd/system/dwc-*.service 2>/dev/null 1>&2; then
|
|
|
|
|
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "dwc-[[:digit:]].service" | wc -l)
|
|
|
|
|
INSTANCE=1
|
|
|
|
|
status_msg "$ACTION2 $INSTANCE_COUNT DWC-for-Klipper-Socket Services ..."
|
|
|
|
|
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
|
|
|
|
|
sudo systemctl $1 dwc-$INSTANCE && ok_msg "DWC-for-Klipper-Socket Service #$INSTANCE $ACTION1!"
|
|
|
|
|
### instance counter +1
|
|
|
|
|
INSTANCE=$(expr $INSTANCE + 1)
|
|
|
|
|
done
|
|
|
|
|
elif [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "dwc.service")" ]; then
|
|
|
|
|
status_msg "$ACTION2 DWC-for-Klipper-Socket Service ..."
|
|
|
|
|
sudo systemctl $1 dwc && ok_msg "DWC-for-Klipper-Socket Service $ACTION1!"
|
2020-08-22 19:14:11 +02:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-28 23:39:42 +01:00
|
|
|
octoprint_service(){
|
|
|
|
|
### set a variable for the ok and status messages
|
|
|
|
|
[ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting"
|
|
|
|
|
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping"
|
|
|
|
|
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting"
|
|
|
|
|
[ "$1" == "enable" ] && ACTION1="enabled" && ACTION2="Enabling"
|
|
|
|
|
[ "$1" == "disable" ] && ACTION1="disabled" && ACTION2="Disabling"
|
2020-08-22 19:14:11 +02:00
|
|
|
|
2021-01-28 23:39:42 +01:00
|
|
|
if ls /etc/systemd/system/octoprint-*.service 2>/dev/null 1>&2; then
|
|
|
|
|
INSTANCE=1
|
|
|
|
|
INSTANCE_COUNT=$(systemctl list-unit-files | grep -E "octoprint.*" | wc -l)
|
|
|
|
|
status_msg "$ACTION2 $INSTANCE_COUNT OctoPrint Services ..."
|
|
|
|
|
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
|
|
|
|
|
sudo systemctl $1 octoprint-$INSTANCE && ok_msg "OctoPrint Service #$INSTANCE $ACTION1!"
|
|
|
|
|
### instance counter +1
|
|
|
|
|
INSTANCE=$(expr $INSTANCE + 1)
|
|
|
|
|
done
|
|
|
|
|
elif [ "$(systemctl list-unit-files | grep -E "octoprint.*")" ]; then
|
|
|
|
|
status_msg "$ACTION2 OctoPrint Service ..."
|
|
|
|
|
sudo systemctl $1 octoprint && ok_msg "OctoPrint Service $ACTION1!"
|
2020-08-22 19:14:11 +02:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggle_octoprint_service(){
|
2021-01-28 23:39:42 +01:00
|
|
|
if systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then
|
|
|
|
|
octoprint_service "stop"
|
|
|
|
|
octoprint_service "disable"
|
|
|
|
|
sleep 2
|
|
|
|
|
CONFIRM_MSG=" OctoPrint Service is now >>> DISABLED <<< !"
|
|
|
|
|
elif systemctl list-unit-files | grep -E "octoprint.*" | grep "disabled" &>/dev/null; then
|
|
|
|
|
octoprint_service "enable"
|
|
|
|
|
octoprint_service "start"
|
|
|
|
|
sleep 2
|
|
|
|
|
CONFIRM_MSG=" OctoPrint Service is now >>> ENABLED <<< !"
|
2020-08-22 19:14:11 +02:00
|
|
|
else
|
|
|
|
|
ERROR_MSG=" You cannot activate a service that does not exist!"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
read_octoprint_service_status(){
|
2021-01-28 23:39:42 +01:00
|
|
|
unset OPRINT_SERVICE_STATUS
|
|
|
|
|
if systemctl list-unit-files | grep -E "octoprint*" | grep "enabled" &>/dev/null; then
|
2020-08-22 19:14:11 +02:00
|
|
|
OPRINT_SERVICE_STATUS="${red}[Disable]${default} OctoPrint Service "
|
2021-01-28 23:39:42 +01:00
|
|
|
else
|
|
|
|
|
OPRINT_SERVICE_STATUS="${green}[Enable]${default} OctoPrint Service "
|
2020-08-22 19:14:11 +02:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-27 13:44:06 +00:00
|
|
|
start_klipperscreen(){
|
|
|
|
|
status_msg "Starting KlipperScreen Service ..."
|
|
|
|
|
sudo systemctl start KlipperScreen && ok_msg "KlipperScreen Service started!"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stop_klipperscreen(){
|
|
|
|
|
status_msg "Stopping KlipperScreen Service ..."
|
|
|
|
|
sudo systemctl stop KlipperScreen && ok_msg "KlipperScreen Service stopped!"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
restart_klipperscreen(){
|
|
|
|
|
status_msg "Restarting KlipperScreen Service ..."
|
|
|
|
|
sudo systemctl restart KlipperScreen && ok_msg "KlipperScreen Service restarted!"
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-19 22:38:21 +02:00
|
|
|
restart_nginx(){
|
2020-11-19 13:47:26 +01:00
|
|
|
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "nginx.service")" ]; then
|
2021-01-28 16:44:05 +01:00
|
|
|
status_msg "Restarting NGINX Service ..."
|
|
|
|
|
sudo systemctl restart nginx && ok_msg "NGINX Service restarted!"
|
2020-07-19 22:38:21 +02:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-23 10:20:14 +02:00
|
|
|
dependency_check(){
|
2020-08-22 18:23:41 +02:00
|
|
|
status_msg "Checking for the following dependencies:"
|
2020-07-23 10:20:14 +02:00
|
|
|
#check if package is installed, if not write name into array
|
|
|
|
|
for pkg in "${dep[@]}"
|
2020-07-13 16:59:40 +02:00
|
|
|
do
|
2020-08-22 18:23:41 +02:00
|
|
|
echo -e "${cyan}● $pkg ${default}"
|
2020-07-23 10:20:14 +02:00
|
|
|
if [[ ! $(dpkg-query -f'${Status}' --show $pkg 2>/dev/null) = *\ installed ]]; then
|
|
|
|
|
inst+=($pkg)
|
|
|
|
|
fi
|
2020-07-13 16:59:40 +02:00
|
|
|
done
|
2020-07-23 10:20:14 +02:00
|
|
|
#if array is not empty, install packages from array elements
|
|
|
|
|
if [ "${#inst[@]}" != "0" ]; then
|
|
|
|
|
status_msg "Installing the following dependencies:"
|
|
|
|
|
for element in ${inst[@]}
|
|
|
|
|
do
|
|
|
|
|
echo -e "${cyan}● $element ${default}"
|
|
|
|
|
done
|
|
|
|
|
echo
|
2021-03-25 21:40:16 +01:00
|
|
|
sudo apt-get update && sudo apt-get install ${inst[@]} -y
|
2020-07-23 10:20:14 +02:00
|
|
|
ok_msg "Dependencies installed!"
|
|
|
|
|
#clearing the array
|
|
|
|
|
unset inst
|
|
|
|
|
else
|
|
|
|
|
ok_msg "Dependencies already met! Continue..."
|
2020-07-13 16:59:40 +02:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print_error(){
|
|
|
|
|
for data in "${data_arr[@]}"
|
|
|
|
|
do
|
|
|
|
|
if [ ! -e $data ]; then
|
|
|
|
|
data_count+=(0)
|
|
|
|
|
else
|
|
|
|
|
data_count+=(1)
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
sum=$(IFS=+; echo "$((${data_count[*]}))")
|
|
|
|
|
if [ $sum -eq 0 ]; then
|
2020-08-20 17:38:24 +02:00
|
|
|
ERROR_MSG="Looks like $1 was already removed!\n Skipping..."
|
2020-07-13 16:59:40 +02:00
|
|
|
else
|
|
|
|
|
ERROR_MSG=""
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-29 18:27:22 +01:00
|
|
|
setup_gcode_shell_command(){
|
2020-08-26 08:18:59 +02:00
|
|
|
echo
|
|
|
|
|
top_border
|
2020-10-29 18:27:22 +01:00
|
|
|
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!${default} |"
|
2020-08-26 08:18:59 +02:00
|
|
|
bottom_border
|
|
|
|
|
while true; do
|
|
|
|
|
read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn
|
|
|
|
|
case "$yn" in
|
|
|
|
|
Y|y|Yes|yes|"")
|
2020-10-29 18:27:22 +01:00
|
|
|
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
|
2021-02-04 11:39:06 +01:00
|
|
|
warn_msg "There is already a file named 'gcode_shell_command.py'\nin the destination location!"
|
2020-10-29 18:27:22 +01:00
|
|
|
while true; do
|
|
|
|
|
read -p "${cyan}###### Do you want to overwrite it? (Y/n):${default} " 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
|
2020-08-26 08:18:59 +02:00
|
|
|
fi
|
2020-10-29 18:27:22 +01:00
|
|
|
else
|
|
|
|
|
ERROR_MSG="Folder ~/klipper/klippy/extras not found!"
|
2020-08-26 08:18:59 +02:00
|
|
|
fi
|
|
|
|
|
break;;
|
|
|
|
|
N|n|No|no)
|
|
|
|
|
break;;
|
2020-09-11 14:12:49 +02:00
|
|
|
*)
|
|
|
|
|
print_unkown_cmd
|
|
|
|
|
print_msg && clear_msg;;
|
2020-08-26 08:18:59 +02:00
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-29 18:27:22 +01:00
|
|
|
install_gcode_shell_command(){
|
2021-01-07 15:26:19 +01:00
|
|
|
klipper_service "stop"
|
2021-02-04 11:39:06 +01:00
|
|
|
status_msg "Copy 'gcode_shell_command.py' to '$KLIPPER_DIR/klippy/extras' ..."
|
2021-01-20 15:16:22 +01:00
|
|
|
cp ${SRCDIR}/kiauh/resources/gcode_shell_command.py $KLIPPER_DIR/klippy/extras
|
2020-10-29 22:28:24 +01:00
|
|
|
while true; do
|
2021-02-04 11:39:06 +01:00
|
|
|
echo
|
2020-10-29 22:28:24 +01:00
|
|
|
read -p "${cyan}###### Do you want to create the example shell command? (Y/n):${default} " yn
|
|
|
|
|
case "$yn" in
|
|
|
|
|
Y|y|Yes|yes|"")
|
2021-01-20 15:16:22 +01:00
|
|
|
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
|
2020-10-29 22:28:24 +01:00
|
|
|
break;;
|
|
|
|
|
N|n|No|no)
|
|
|
|
|
break;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
2020-10-29 18:27:22 +01:00
|
|
|
ok_msg "Shell command extension installed!"
|
2021-01-07 15:26:19 +01:00
|
|
|
klipper_service "restart"
|
2020-10-29 18:27:22 +01:00
|
|
|
}
|
|
|
|
|
|
2020-11-13 20:48:57 +01:00
|
|
|
create_minimal_cfg(){
|
2020-11-20 11:18:29 +01:00
|
|
|
#create a minimal default config
|
2020-11-13 20:48:57 +01:00
|
|
|
if [ "$SEL_DEF_CFG" = "true" ]; then
|
|
|
|
|
cat <<- EOF >> $PRINTER_CFG
|
|
|
|
|
[mcu]
|
|
|
|
|
serial: </dev/serial/by-id/your-mcu>
|
|
|
|
|
|
|
|
|
|
[printer]
|
2020-11-20 11:18:29 +01:00
|
|
|
kinematics: none
|
|
|
|
|
max_velocity: 1
|
|
|
|
|
max_accel: 1
|
2020-11-13 20:48:57 +01:00
|
|
|
|
|
|
|
|
[virtual_sdcard]
|
|
|
|
|
path: ~/sdcard
|
|
|
|
|
|
|
|
|
|
[pause_resume]
|
|
|
|
|
[display_status]
|
|
|
|
|
EOF
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-29 22:28:24 +01:00
|
|
|
read_printer_cfg(){
|
2020-12-20 19:25:13 +01:00
|
|
|
KIAUH_CFG="$(dirname $PRINTER_CFG)/kiauh.cfg"
|
2020-11-13 20:48:57 +01:00
|
|
|
[ ! -f $KIAUH_CFG ] && KIAUH_CFG_FOUND="false" || KIAUH_CFG_FOUND="true"
|
|
|
|
|
if [ -f $PRINTER_CFG ]; then
|
|
|
|
|
if [ "$1" = "moonraker" ]; then
|
|
|
|
|
[ ! "$(grep '^\[virtual_sdcard\]$' $PRINTER_CFG)" ] && VSD="false" && EDIT_CFG="true"
|
|
|
|
|
[ ! "$(grep '^\[pause_resume\]$' $PRINTER_CFG)" ] && PAUSE_RESUME="false" && EDIT_CFG="true"
|
|
|
|
|
[ ! "$(grep '^\[display_status\]$' $PRINTER_CFG)" ] && DISPLAY_STATUS="false" && EDIT_CFG="true"
|
|
|
|
|
elif [ "$1" = "mainsail" ] || [ "$1" = "fluidd" ]; then
|
|
|
|
|
[ ! "$(grep '^\[include webui_macros\.cfg\]$' $PRINTER_CFG)" ] && WEBUI_MACROS="false" && EDIT_CFG="true"
|
|
|
|
|
elif [ "$1" = "dwc2" ]; then
|
|
|
|
|
[ ! "$(grep '^\[virtual_sdcard\]$' $PRINTER_CFG)" ] && VSD="false" && EDIT_CFG="true"
|
|
|
|
|
fi
|
2020-08-26 08:18:59 +02:00
|
|
|
fi
|
2020-10-29 22:28:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
write_printer_cfg(){
|
2020-11-13 20:48:57 +01:00
|
|
|
#backup printer.cfg if edits will be written
|
|
|
|
|
[ "$EDIT_CFG" = "true" ] && backup_printer_cfg
|
2020-10-29 22:28:24 +01:00
|
|
|
#create kiauh.cfg if its needed and doesn't exist
|
2020-11-13 20:48:57 +01:00
|
|
|
if [ "$KIAUH_CFG_FOUND" = "false" ] && [ "$EDIT_CFG" = "true" ]; then
|
2020-10-29 22:28:24 +01:00
|
|
|
status_msg "Creating kiauh.cfg ..."
|
2020-10-30 12:50:51 +01:00
|
|
|
echo -e "##### AUTOCREATED BY KIAUH #####" > $KIAUH_CFG
|
2020-08-26 08:18:59 +02:00
|
|
|
fi
|
2020-10-29 22:28:24 +01:00
|
|
|
#write each entry to kiauh.cfg if it doesn't exist
|
2020-11-13 20:48:57 +01:00
|
|
|
#Moonraker/DWC2 related config options
|
2020-10-29 22:28:24 +01:00
|
|
|
if [ "$VSD" = "false" ] && [[ ! $(grep '^\[virtual_sdcard\]$' $KIAUH_CFG) ]]; then
|
|
|
|
|
echo -e "\n[virtual_sdcard]\npath: ~/sdcard" >> $KIAUH_CFG
|
|
|
|
|
fi
|
|
|
|
|
if [ "$PAUSE_RESUME" = "false" ] && [[ ! $(grep '^\[pause_resume]$' $KIAUH_CFG) ]]; then
|
|
|
|
|
echo -e "\n[pause_resume]" >> $KIAUH_CFG
|
|
|
|
|
fi
|
|
|
|
|
if [ "$DISPLAY_STATUS" = "false" ] && [[ ! $(grep '^\[display_status]$' $KIAUH_CFG) ]]; then
|
|
|
|
|
echo -e "\n[display_status]" >> $KIAUH_CFG
|
|
|
|
|
fi
|
|
|
|
|
#including the kiauh.cfg into printer.cfg if not already done
|
2020-11-13 20:48:57 +01:00
|
|
|
if [ ! "$(grep '^\[include kiauh\.cfg\]$' $PRINTER_CFG)" ] && [ "$EDIT_CFG" = "true" ]; then
|
2020-10-29 22:28:24 +01:00
|
|
|
status_msg "Writing [include kiauh.cfg] to printer.cfg ..."
|
2020-11-13 20:48:57 +01:00
|
|
|
sed -i '1 i ##### AUTOCREATED BY KIAUH #####\n[include kiauh.cfg]' $PRINTER_CFG
|
2020-08-26 08:18:59 +02:00
|
|
|
fi
|
2020-10-29 22:28:24 +01:00
|
|
|
ok_msg "Done!"
|
2020-10-13 11:41:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init_ini(){
|
2021-01-27 18:51:48 +01:00
|
|
|
### copy an existing kiauh.ini to its new location to keep all possible saved values
|
2021-01-28 17:50:35 +01:00
|
|
|
if [ -f ${SRCDIR}/kiauh/kiauh.ini ] && [ ! -f $INI_FILE ]; then
|
2021-01-27 18:51:48 +01:00
|
|
|
cp ${SRCDIR}/kiauh/kiauh.ini $INI_FILE
|
|
|
|
|
fi
|
2020-10-13 11:55:01 +02:00
|
|
|
if [ ! -f $INI_FILE ]; then
|
|
|
|
|
echo -e "#don't edit this file if you don't know what you are doing...\c" > $INI_FILE
|
|
|
|
|
fi
|
2020-10-13 11:41:57 +02:00
|
|
|
if [ ! $(grep -E "^backup_before_update=." $INI_FILE) ]; then
|
|
|
|
|
echo -e "\nbackup_before_update=false\c" >> $INI_FILE
|
|
|
|
|
fi
|
|
|
|
|
if [ ! $(grep -E "^previous_origin_state=[[:alnum:]]" $INI_FILE) ]; then
|
|
|
|
|
echo -e "\nprevious_origin_state=0\c" >> $INI_FILE
|
|
|
|
|
fi
|
|
|
|
|
if [ ! $(grep -E "^previous_smoothing_state=[[:alnum:]]" $INI_FILE) ]; then
|
|
|
|
|
echo -e "\nprevious_smoothing_state=0\c" >> $INI_FILE
|
|
|
|
|
fi
|
|
|
|
|
if [ ! $(grep -E "^previous_shaping_state=[[:alnum:]]" $INI_FILE) ]; then
|
|
|
|
|
echo -e "\nprevious_shaping_state=0\c" >> $INI_FILE
|
|
|
|
|
fi
|
|
|
|
|
if [ ! $(grep -E "^logupload_accepted=." $INI_FILE) ]; then
|
|
|
|
|
echo -e "\nlogupload_accepted=false\c" >> $INI_FILE
|
|
|
|
|
fi
|
2021-01-07 15:26:19 +01:00
|
|
|
###add empty klipper config path if missing
|
|
|
|
|
if [ ! $(grep -E "^klipper_cfg_loc=" $INI_FILE) ]; then
|
|
|
|
|
echo -e "\nklipper_cfg_loc=\c" >> $INI_FILE
|
|
|
|
|
fi
|
2020-11-27 13:44:06 +00:00
|
|
|
}
|