mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-13 02:24:27 +05:00
initial commit of a bigger kiauh rework to make multi instance installations possible
This commit is contained in:
@@ -11,47 +11,162 @@ check_euid(){
|
||||
fi
|
||||
}
|
||||
|
||||
locate_printer_cfg(){
|
||||
unset PRINTER_CFG
|
||||
if [ -e $KLIPPER_SERVICE2 ]; then
|
||||
status_msg "Locating printer.cfg via $KLIPPER_SERVICE2 ..."
|
||||
#reads /etc/default/klipper and gets the default printer.cfg location
|
||||
KLIPPY_ARGS_LINE="$(grep "KLIPPY_ARGS=" /etc/default/klipper)"
|
||||
KLIPPY_ARGS_COUNT="$(grep -o " " <<< "$KLIPPY_ARGS_LINE" | wc -l)"
|
||||
i=1
|
||||
PRINTER_CFG=$(while [ "$i" != "$KLIPPY_ARGS_COUNT" ]; do grep -E "(\/[A-Za-z0-9\_-]+)+\/printer\.cfg" /etc/default/klipper | cut -d" " -f"$i"; i=$(( $i + 1 )); done | grep "printer.cfg")
|
||||
ok_msg "printer.cfg location: '$PRINTER_CFG'"
|
||||
elif [ -e $KLIPPER_SERVICE3 ]; then
|
||||
status_msg "Locating printer.cfg via $KLIPPER_SERVICE3 ..."
|
||||
#reads /etc/systemd/system/klipper.service and gets the default printer.cfg location
|
||||
KLIPPY_ARGS_LINE="$(grep "ExecStart=" /etc/systemd/system/klipper.service)"
|
||||
KLIPPY_ARGS_COUNT="$(grep -o " " <<< "$KLIPPY_ARGS_LINE" | wc -l)"
|
||||
i=1
|
||||
PRINTER_CFG=$(while [ "$i" != "$KLIPPY_ARGS_COUNT" ]; do grep -E "(\/[A-Za-z0-9\_-]+)+\/printer\.cfg" /etc/systemd/system/klipper.service | cut -d" " -f"$i"; i=$(( $i + 1 )); done | grep "printer.cfg")
|
||||
ok_msg "printer.cfg location: '$PRINTER_CFG'"
|
||||
else
|
||||
PRINTER_CFG=""
|
||||
warn_msg "Can't read printer.cfg location!"
|
||||
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
|
||||
echo -e "| Before we can continue, you need to specify a folder |"
|
||||
echo -e "| where your Klipper configuration(s) will be stored! |"
|
||||
bottom_border
|
||||
change_klipper_cfg_path
|
||||
fi
|
||||
}
|
||||
|
||||
source_ini(){
|
||||
change_klipper_cfg_path(){
|
||||
source_kiauh_ini
|
||||
old_klipper_cfg_loc="$klipper_cfg_loc"
|
||||
while true; do
|
||||
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"
|
||||
|
||||
### 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'!"
|
||||
|
||||
### backup the old config dir
|
||||
backup_klipper_config_dir
|
||||
|
||||
### 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
|
||||
}
|
||||
|
||||
###? if path was changed in 'change_klipper_cfg_path', we need to edit the service files
|
||||
###? and set the new path. after that, copy configs to new location and reload service units.
|
||||
set_klipper_cfg_path(){
|
||||
### stop services
|
||||
klipper_service "stop" && moonraker_service "stop"
|
||||
|
||||
### copy config files to new location if old location exists
|
||||
[ ! -d "$new_klipper_cfg_loc" ] && mkdir -p "$new_klipper_cfg_loc"
|
||||
if [ ! -z "$old_klipper_cfg_loc" ]; then
|
||||
status_msg "Copy files to '$new_klipper_cfg_loc'!"; echo
|
||||
cd $old_klipper_cfg_loc
|
||||
cp -avr * "$new_klipper_cfg_loc/" && ok_msg "Done!"
|
||||
fi
|
||||
|
||||
### handle single klipper instance service file
|
||||
if [ -f /etc/systemd/system/klipper.service ]; then
|
||||
status_msg "Configuring Klipper for new path ..."
|
||||
sudo sed -i "/ExecStart=/ s|$old_klipper_cfg_loc/printer.cfg|$new_klipper_cfg_loc/printer.cfg|" /etc/systemd/system/klipper.service
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
### handle multi klipper instance service file
|
||||
if [ "$(ls /etc/systemd/system/klipper-*.service)" > /dev/null 2>&1 ]; then
|
||||
status_msg "Configuring Klipper for new path ..."
|
||||
for service in $(find /etc/systemd/system/klipper-*.service); do
|
||||
sudo sed -i "/ExecStart=/ s|$old_klipper_cfg_loc/printer-|$new_klipper_cfg_loc/printer-|" $service
|
||||
done
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
|
||||
### handle single moonraker instance service and moonraker.conf file
|
||||
if [ -f /etc/systemd/system/moonraker.service ]; then
|
||||
status_msg "Configuring Moonraker for new path ..."
|
||||
sudo sed -i "/ExecStart=/ s|$old_klipper_cfg_loc/moonraker.conf|$new_klipper_cfg_loc/moonraker.conf|" /etc/systemd/system/moonraker.service
|
||||
### replace old file path with new one in moonraker.conf
|
||||
sed -i "/config_path:/ s|config_path:.*|config_path: $new_klipper_cfg_loc|" $new_klipper_cfg_loc/moonraker.conf
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
### handle multi moonraker instance service file
|
||||
if [ "$(ls /etc/systemd/system/moonraker-*.service)" > /dev/null 2>&1 ]; then
|
||||
status_msg "Configuring Moonraker for new path ..."
|
||||
for service in $(find /etc/systemd/system/moonraker-*.service); do
|
||||
sudo sed -i "/ExecStart=/ s|$old_klipper_cfg_loc/moonraker-|$new_klipper_cfg_loc/moonraker-|" $service
|
||||
done
|
||||
### replace old file path with new one in moonraker-*.conf
|
||||
for moonraker_conf in $(find $new_klipper_cfg_loc/moonraker-*.conf); do
|
||||
sed -i "/config_path:/ s|config_path:.*|config_path: $new_klipper_cfg_loc|" $moonraker_conf
|
||||
done
|
||||
ok_msg "OK!"
|
||||
fi
|
||||
|
||||
### reloading units
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
### restart services
|
||||
klipper_service "stop" && moonraker_service "stop"
|
||||
}
|
||||
|
||||
source_kiauh_ini(){
|
||||
source ${SRCDIR}/kiauh/kiauh.ini
|
||||
}
|
||||
|
||||
start_klipper(){
|
||||
status_msg "Starting Klipper Service ..."
|
||||
sudo systemctl start klipper && ok_msg "Klipper Service started!"
|
||||
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"
|
||||
|
||||
if [ "$(ls /etc/systemd/system/klipper-*.service)" > /dev/null 2>&1 ]; then
|
||||
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
|
||||
}
|
||||
|
||||
stop_klipper(){
|
||||
status_msg "Stopping Klipper Service ..."
|
||||
sudo systemctl stop klipper && ok_msg "Klipper Service stopped!"
|
||||
}
|
||||
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"
|
||||
|
||||
restart_klipper(){
|
||||
status_msg "Restarting Klipper Service ..."
|
||||
sudo systemctl restart klipper && ok_msg "Klipper Service restarted!"
|
||||
if [ "$(ls /etc/systemd/system/moonraker-*.service)" > /dev/null 2>&1 ]; then
|
||||
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
|
||||
}
|
||||
|
||||
start_dwc(){
|
||||
@@ -64,21 +179,6 @@ stop_dwc(){
|
||||
sudo systemctl stop dwc && ok_msg "DWC-for-Klipper-Socket Service stopped!"
|
||||
}
|
||||
|
||||
start_moonraker(){
|
||||
status_msg "Starting Moonraker Service ..."
|
||||
sudo systemctl start moonraker && ok_msg "Moonraker Service started!"
|
||||
}
|
||||
|
||||
stop_moonraker(){
|
||||
status_msg "Stopping Moonraker Service ..."
|
||||
sudo systemctl stop moonraker && ok_msg "Moonraker Service stopped!"
|
||||
}
|
||||
|
||||
restart_moonraker(){
|
||||
status_msg "Restarting Moonraker Service ..."
|
||||
sudo systemctl restart moonraker && ok_msg "Moonraker Service restarted!"
|
||||
}
|
||||
|
||||
start_octoprint(){
|
||||
status_msg "Starting OctoPrint Service ..."
|
||||
sudo systemctl start octoprint && ok_msg "OctoPrint Service started!"
|
||||
@@ -252,8 +352,8 @@ setup_gcode_shell_command(){
|
||||
}
|
||||
|
||||
install_gcode_shell_command(){
|
||||
stop_klipper
|
||||
status_msg "Copy 'gcode_shell_command.py' to $KLIPPER_DIR/klippy/extras"
|
||||
klipper_service "stop"
|
||||
status_msg "Copy 'gcode_shell_command.py' to $KLIKLIPPER_DIRPPER/klippy/extras"
|
||||
cp ${HOME}/kiauh/resources/gcode_shell_command.py $KLIPPER_DIR/klippy/extras
|
||||
echo
|
||||
while true; do
|
||||
@@ -272,7 +372,7 @@ install_gcode_shell_command(){
|
||||
esac
|
||||
done
|
||||
ok_msg "Shell command extension installed!"
|
||||
restart_klipper
|
||||
klipper_service "restart"
|
||||
}
|
||||
|
||||
create_minimal_cfg(){
|
||||
@@ -374,4 +474,8 @@ init_ini(){
|
||||
if [ ! $(grep -E "^logupload_accepted=." $INI_FILE) ]; then
|
||||
echo -e "\nlogupload_accepted=false\c" >> $INI_FILE
|
||||
fi
|
||||
###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
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ install_dwc2(){
|
||||
#ask user for customization
|
||||
get_user_selections_dwc2
|
||||
#dwc2 main installation
|
||||
stop_klipper
|
||||
klipper_service "stop"
|
||||
dwc2_setup
|
||||
#setup config
|
||||
setup_printer_config_dwc2
|
||||
@@ -16,7 +16,7 @@ install_dwc2(){
|
||||
set_nginx_cfg "dwc2"
|
||||
set_hostname
|
||||
#after install actions
|
||||
restart_klipper
|
||||
klipper_service "restart"
|
||||
else
|
||||
ERROR_MSG=" Please install Klipper first!\n Skipping..."
|
||||
fi
|
||||
|
||||
@@ -1,103 +1,207 @@
|
||||
install_klipper(){
|
||||
if [ -e $KLIPPER_SERVICE1 ] && [ -e $KLIPPER_SERVICE2 ] || [ -e $KLIPPER_SERVICE3 ]; then
|
||||
ERROR_MSG="Looks like Klipper is already installed!"
|
||||
else
|
||||
get_user_selections_klipper
|
||||
klipper_setup
|
||||
build_fw
|
||||
flash_mcu
|
||||
write_printer_usb
|
||||
#install_klipper(){
|
||||
# get_user_selections_klipper
|
||||
# klipper_setup
|
||||
# build_fw
|
||||
# flash_mcu
|
||||
# write_printer_usb
|
||||
#}
|
||||
|
||||
### base variables
|
||||
SYSTEMDDIR="/etc/systemd/system"
|
||||
KLIPPY_ENV="${HOME}/klippy-env"
|
||||
KLIPPER_DIR="${HOME}/klipper"
|
||||
|
||||
klipper_setup_dialog(){
|
||||
status_msg "Initializing Klipper installation ..."
|
||||
|
||||
### check for existing klipper service installations
|
||||
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ] || [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service")" ]; then
|
||||
ERROR_MSG="At least one Klipper service is already installed!" && return 0
|
||||
fi
|
||||
|
||||
### initial printer.cfg path check
|
||||
check_klipper_cfg_path
|
||||
|
||||
### ask for amount of instances to create
|
||||
while true; do
|
||||
echo
|
||||
read -p "${cyan}###### How many Klipper instances do you want to set up?:${default} " INSTANCE_COUNT
|
||||
echo
|
||||
if [ $INSTANCE_COUNT == 1 ]; then
|
||||
read -p "${cyan}###### Create $INSTANCE_COUNT single instance? (Y/n):${default} " yn
|
||||
else
|
||||
read -p "${cyan}###### Create $INSTANCE_COUNT instances? (Y/n):${default} " yn
|
||||
fi
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
echo -e "###### > Yes"
|
||||
status_msg "Creating $INSTANCE_COUNT Klipper instances ..."
|
||||
klipper_setup
|
||||
break;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
warn_msg "Exiting Klipper setup ..."
|
||||
echo
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
get_user_selections_klipper(){
|
||||
status_msg "Initializing Klipper installation ..."
|
||||
#let user choose to install systemd or init.d service
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| Do you want to install Klipper as: |"
|
||||
echo -e "| 1) Init.d Service (default) |"
|
||||
echo -e "| 2) Systemd Service |"
|
||||
hr
|
||||
echo -e "| Please use the appropriate option for your chosen |"
|
||||
echo -e "| Linux distribution. If you are unsure what to select, |"
|
||||
echo -e "| please do some research before. |"
|
||||
hr
|
||||
echo -e "| If you run Raspberry Pi OS, both options will work. |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Please choose:${default} " action
|
||||
case "$action" in
|
||||
1|"")
|
||||
echo -e "###### > 1) Init.d"
|
||||
INST_KLIPPER_INITD="true"
|
||||
INST_KLIPPER_SYSTEMD="false"
|
||||
break;;
|
||||
2)
|
||||
echo -e "###### > 2) Systemd"
|
||||
INST_KLIPPER_INITD="false"
|
||||
INST_KLIPPER_SYSTEMD="true"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
#ask user for building firmware
|
||||
while true; do
|
||||
echo
|
||||
read -p "${cyan}###### Do you want to build the Firmware? (y/N):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes)
|
||||
echo -e "###### > Yes"
|
||||
BUILD_FIRMWARE="true"
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
echo -e "###### > No"
|
||||
BUILD_FIRMWARE="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
#ask user for flashing mcu
|
||||
while true; do
|
||||
echo
|
||||
read -p "${cyan}###### Do you want to flash your MCU? (y/N):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes)
|
||||
echo -e "###### > Yes"
|
||||
FLASH_FIRMWARE="true"
|
||||
flash_routine
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
echo -e "###### > No"
|
||||
FLASH_FIRMWARE="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
install_klipper_packages(){
|
||||
### Packages for python cffi
|
||||
PKGLIST="python-virtualenv virtualenv python-dev libffi-dev build-essential"
|
||||
### kconfig requirements
|
||||
PKGLIST="${PKGLIST} libncurses-dev"
|
||||
### hub-ctrl
|
||||
PKGLIST="${PKGLIST} libusb-dev"
|
||||
### AVR chip installation and building
|
||||
PKGLIST="${PKGLIST} avrdude gcc-avr binutils-avr avr-libc"
|
||||
### ARM chip installation and building
|
||||
PKGLIST="${PKGLIST} stm32flash libnewlib-arm-none-eabi"
|
||||
PKGLIST="${PKGLIST} gcc-arm-none-eabi binutils-arm-none-eabi libusb-1.0"
|
||||
### dbus requirement for DietPi
|
||||
PKGLIST="${PKGLIST} dbus"
|
||||
|
||||
### Update system package info
|
||||
status_msg "Running apt-get update..."
|
||||
sudo apt-get update
|
||||
|
||||
### Install desired packages
|
||||
status_msg "Installing packages..."
|
||||
sudo apt-get install --yes ${PKGLIST}
|
||||
}
|
||||
|
||||
create_klipper_virtualenv(){
|
||||
status_msg "Installing python virtual environment..."
|
||||
# Create virtualenv if it doesn't already exist
|
||||
[ ! -d ${KLIPPY_ENV} ] && virtualenv -p python2 ${KLIPPY_ENV}
|
||||
# Install/update dependencies
|
||||
${KLIPPY_ENV}/bin/pip install -r ${KLIPPER_DIR}/scripts/klippy-requirements.txt
|
||||
}
|
||||
|
||||
create_single_klipper_startscript(){
|
||||
### create systemd service file
|
||||
sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper.service" << EOF
|
||||
#Systemd service file for klipper
|
||||
[Unit]
|
||||
Description=Starts klipper on startup
|
||||
After=network.target
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
[Service]
|
||||
Type=simple
|
||||
User=$USER
|
||||
RemainAfterExit=yes
|
||||
ExecStart=${KLIPPY_ENV}/bin/python ${KLIPPER_DIR}/klippy/klippy.py ${PRINTER_CFG} -l ${KLIPPER_LOG} -a ${KLIPPY_UDS}
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
EOF
|
||||
}
|
||||
|
||||
create_multi_klipper_startscript(){
|
||||
### create multi instance systemd service file
|
||||
sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper-$INSTANCE.service" << EOF
|
||||
#Systemd service file for klipper
|
||||
[Unit]
|
||||
Description=Starts klipper instance $INSTANCE on startup
|
||||
After=network.target
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
[Service]
|
||||
Type=simple
|
||||
User=$USER
|
||||
RemainAfterExit=yes
|
||||
ExecStart=${KLIPPY_ENV}/bin/python ${KLIPPER_DIR}/klippy/klippy.py ${PRINTER_CFG} -I ${TMP_PRINTER} -l ${KLIPPER_LOG} -a ${KLIPPY_UDS}
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
EOF
|
||||
}
|
||||
|
||||
klipper_setup(){
|
||||
#check for dependencies
|
||||
dep=(git dbus)
|
||||
dependency_check
|
||||
#execute operation
|
||||
### get printer config directory
|
||||
source_kiauh_ini
|
||||
PRINTER_CFG_LOC="$klipper_cfg_loc"
|
||||
|
||||
### clone klipper
|
||||
cd ${HOME}
|
||||
status_msg "Cloning Klipper repository ..."
|
||||
status_msg "Downloading Klipper ..."
|
||||
[ -d $KLIPPER_DIR ] && rm -rf $KLIPPER_DIR
|
||||
git clone $KLIPPER_REPO
|
||||
ok_msg "Klipper successfully cloned!"
|
||||
status_msg "Installing Klipper Service ..."
|
||||
if [ "$INST_KLIPPER_INITD" = "true" ]; then
|
||||
$KLIPPER_DIR/scripts/install-octopi.sh
|
||||
elif [ "$INST_KLIPPER_SYSTEMD" = "true" ]; then
|
||||
$KLIPPER_DIR/scripts/install-debian.sh
|
||||
status_msg "Download complete!"
|
||||
|
||||
### install klipper dependencies and create python virtualenv
|
||||
status_msg "Installing dependencies ..."
|
||||
install_klipper_packages
|
||||
create_klipper_virtualenv
|
||||
|
||||
### create sdcard folder
|
||||
[ ! -d ${HOME}/sdcard ] && mkdir -p ${HOME}/sdcard
|
||||
### create config folder
|
||||
[ ! -d $PRINTER_CFG_LOC ] && mkdir -p $PRINTER_CFG_LOC
|
||||
|
||||
### create klipper instances
|
||||
INSTANCE=1
|
||||
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
|
||||
create_single_klipper_instance
|
||||
else
|
||||
create_multi_klipper_instance
|
||||
fi
|
||||
ok_msg "Klipper installation complete!"
|
||||
}
|
||||
|
||||
create_single_klipper_instance(){
|
||||
status_msg "Setting up 1 Klipper instance ..."
|
||||
|
||||
### single instance variables
|
||||
KLIPPER_LOG=/tmp/klippy.log
|
||||
KLIPPY_UDS=/tmp/klippy_uds
|
||||
PRINTER_CFG="$PRINTER_CFG_LOC/printer.cfg"
|
||||
|
||||
### create instance
|
||||
status_msg "Creating single Klipper instance ..."
|
||||
status_msg "Installing system start script ..."
|
||||
create_single_klipper_startscript
|
||||
|
||||
### enable instance
|
||||
sudo systemctl enable klipper.service
|
||||
ok_msg "Single Klipper instance created!"
|
||||
|
||||
### launching instance
|
||||
status_msg "Launching Klipper instance ..."
|
||||
sudo systemctl start klipper
|
||||
|
||||
### confirm message
|
||||
ok_msg "Single Klipper instance has been set up!\n"
|
||||
}
|
||||
|
||||
create_multi_klipper_instance(){
|
||||
status_msg "Setting up $INSTANCE_COUNT instances of Klipper ..."
|
||||
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
|
||||
### multi instance variables
|
||||
KLIPPER_LOG=/tmp/klippy-$INSTANCE.log
|
||||
KLIPPY_UDS=/tmp/klippy_uds-$INSTANCE
|
||||
TMP_PRINTER=/tmp/printer-$INSTANCE
|
||||
PRINTER_CFG="$PRINTER_CFG_LOC/printer-$INSTANCE.cfg"
|
||||
|
||||
### create instance
|
||||
status_msg "Creating instance #$INSTANCE ..."
|
||||
create_multi_klipper_startscript
|
||||
|
||||
### enable instance
|
||||
sudo systemctl enable klipper-$INSTANCE.service
|
||||
ok_msg "Klipper instance $INSTANCE created!"
|
||||
|
||||
### launching instance
|
||||
status_msg "Launching Klipper instance $INSTANCE ..."
|
||||
sudo systemctl start klipper-$INSTANCE
|
||||
|
||||
### instance counter +1
|
||||
INSTANCE=$(expr $INSTANCE + 1)
|
||||
done
|
||||
### confirm message
|
||||
ok_msg "$INSTANCE_COUNT Klipper instances have been set up!\n"
|
||||
}
|
||||
|
||||
flash_routine(){
|
||||
@@ -138,14 +242,14 @@ flash_routine(){
|
||||
|
||||
flash_mcu(){
|
||||
if [ "$CONFIRM_FLASHING" = "true" ] && [ ! -z "$PRINTER_USB" ]; then
|
||||
stop_klipper
|
||||
klipper_service "stop"
|
||||
if ! make flash FLASH_DEVICE="$PRINTER_USB" ; then
|
||||
warn_msg "Flashing failed!"
|
||||
warn_msg "Please read the console output above!"
|
||||
else
|
||||
ok_msg "Flashing successfull!"
|
||||
fi
|
||||
start_klipper
|
||||
klipper_service "start"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,317 @@
|
||||
### base variables
|
||||
SYSTEMDDIR="/etc/systemd/system"
|
||||
MOONRAKER_ENV="${HOME}/moonraker-env"
|
||||
MOONRAKER_DIR="${HOME}/moonraker"
|
||||
|
||||
moonraker_setup_dialog(){
|
||||
status_msg "Initializing Moonraker installation ..."
|
||||
|
||||
### check for existing moonraker service installations
|
||||
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ] || [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service")" ]; then
|
||||
ERROR_MSG="At least one Moonraker service is already installed!" && return 0
|
||||
fi
|
||||
|
||||
### check for existing klipper service installations
|
||||
if [ ! "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ] && [ ! "$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service")" ]; then
|
||||
ERROR_MSG="Klipper service not found, please install Klipper first!" && return 0
|
||||
fi
|
||||
|
||||
### count amount of klipper services
|
||||
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
|
||||
INSTANCE_COUNT=1
|
||||
else
|
||||
INSTANCE_COUNT=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l)
|
||||
fi
|
||||
|
||||
### initial moonraker.conf path check
|
||||
check_klipper_cfg_path
|
||||
|
||||
### ask for amount of instances to create
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!"
|
||||
echo -e "| You need one Moonraker instance per Klipper instance. | "
|
||||
bottom_border
|
||||
echo
|
||||
read -p "${cyan}###### Create $INSTANCE_COUNT Moonraker instances? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
echo -e "###### > Yes"
|
||||
status_msg "Creating $INSTANCE_COUNT Moonraker instances ..."
|
||||
moonraker_setup
|
||||
break;;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
warn_msg "Exiting Moonraker setup ..."
|
||||
echo
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
install_moonraker_packages(){
|
||||
PKGLIST="python3-virtualenv python3-dev nginx libopenjp2-7 python3-libgpiod"
|
||||
|
||||
### Update system package info
|
||||
status_msg "Running apt-get update..."
|
||||
sudo apt-get update
|
||||
|
||||
### Install desired packages
|
||||
status_msg "Installing packages..."
|
||||
sudo apt-get install --yes ${PKGLIST}
|
||||
}
|
||||
|
||||
create_moonraker_virtualenv(){
|
||||
status_msg "Installing python virtual environment..."
|
||||
|
||||
### If venv exists and user prompts a rebuild, then do so
|
||||
if [ -d ${MOONRAKER_ENV} ] && [ $REBUILD_ENV = "y" ]; then
|
||||
status_msg "Removing old virtualenv"
|
||||
rm -rf ${MOONRAKER_ENV}
|
||||
fi
|
||||
|
||||
[ ! -d ${MOONRAKER_ENV} ] && virtualenv -p /usr/bin/python3 --system-site-packages ${MOONRAKER_ENV}
|
||||
|
||||
### Install/update dependencies
|
||||
${MOONRAKER_ENV}/bin/pip install -r ${MOONRAKER_DIR}/scripts/moonraker-requirements.txt
|
||||
}
|
||||
|
||||
create_single_moonraker_startscript(){
|
||||
### create systemd service file
|
||||
sudo /bin/sh -c "cat > ${SYSTEMDDIR}/moonraker.service" << EOF
|
||||
#Systemd service file for moonraker
|
||||
[Unit]
|
||||
Description=Starts Moonraker on startup
|
||||
After=network.target
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
[Service]
|
||||
Type=simple
|
||||
User=$USER
|
||||
RemainAfterExit=yes
|
||||
ExecStart=${MOONRAKER_ENV}/bin/python ${MOONRAKER_DIR}/moonraker/moonraker.py -l ${MOONRAKER_LOG} -c ${MOONRAKER_CONF}
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
EOF
|
||||
}
|
||||
|
||||
create_multi_moonraker_startscript(){
|
||||
### create multi instance systemd service file
|
||||
sudo /bin/sh -c "cat > ${SYSTEMDDIR}/moonraker-$INSTANCE.service" << EOF
|
||||
#Systemd service file for moonraker
|
||||
[Unit]
|
||||
Description=Starts Moonraker instance $INSTANCE on startup
|
||||
After=network.target
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
[Service]
|
||||
Type=simple
|
||||
User=$USER
|
||||
RemainAfterExit=yes
|
||||
ExecStart=${MOONRAKER_ENV}/bin/python ${MOONRAKER_DIR}/moonraker/moonraker.py -l ${MOONRAKER_LOG} -c ${MOONRAKER_CONF}
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
EOF
|
||||
}
|
||||
|
||||
moonraker_setup(){
|
||||
### get printer config directory
|
||||
source_kiauh_ini
|
||||
MOONRAKER_CONF_LOC="$klipper_cfg_loc"
|
||||
|
||||
### clone moonraker
|
||||
status_msg "Downloading Moonraker ..."
|
||||
### force remove existing moonraker dir
|
||||
[ -d $MOONRAKER_DIR ] && rm -rf $MOONRAKER_DIR
|
||||
|
||||
### clone into fresh moonraker dir
|
||||
cd ${HOME} && git clone $MOONRAKER_REPO
|
||||
status_msg "Download complete!"
|
||||
|
||||
### install klipper dependencies and create python virtualenv
|
||||
status_msg "Installing dependencies ..."
|
||||
install_moonraker_packages
|
||||
create_moonraker_virtualenv
|
||||
|
||||
### create moonraker.conf folder
|
||||
[ ! -d $MOONRAKER_CONF_LOC ] && mkdir -p $MOONRAKER_CONF_LOC
|
||||
|
||||
### create moonraker.confs
|
||||
moonraker_conf_creation
|
||||
|
||||
### create moonraker instances
|
||||
INSTANCE=1
|
||||
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
|
||||
create_single_moonraker_instance
|
||||
else
|
||||
create_multi_moonraker_instance
|
||||
fi
|
||||
}
|
||||
|
||||
create_single_moonraker_instance(){
|
||||
status_msg "Setting up 1 Moonraker instance ..."
|
||||
|
||||
### single instance variables
|
||||
MOONRAKER_LOG=/tmp/moonraker.log
|
||||
MOONRAKER_CONF="$MOONRAKER_CONF_LOC/moonraker.conf"
|
||||
|
||||
### create instance
|
||||
status_msg "Creating single Moonraker instance ..."
|
||||
status_msg "Installing system start script ..."
|
||||
create_single_moonraker_startscript
|
||||
|
||||
### enable instance
|
||||
sudo systemctl enable moonraker.service
|
||||
ok_msg "Single Moonraker instance created!"
|
||||
|
||||
### launching instance
|
||||
status_msg "Launching Moonraker instance ..."
|
||||
sudo systemctl start moonraker
|
||||
|
||||
### confirm message
|
||||
ok_msg "Single Moonraker instance has been set up!\n"
|
||||
}
|
||||
|
||||
create_multi_moonraker_instance(){
|
||||
status_msg "Setting up $INSTANCE_COUNT instances of Moonraker ..."
|
||||
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
|
||||
### multi instance variables
|
||||
MOONRAKER_LOG=/tmp/moonraker-$INSTANCE.log
|
||||
MOONRAKER_CONF="$MOONRAKER_CONF_LOC/moonraker-$INSTANCE.conf"
|
||||
|
||||
### create instance
|
||||
status_msg "Creating instance #$INSTANCE ..."
|
||||
create_multi_moonraker_startscript
|
||||
|
||||
### enable instance
|
||||
sudo systemctl enable moonraker-$INSTANCE.service
|
||||
ok_msg "Moonraker instance $INSTANCE created!"
|
||||
|
||||
### launching instance
|
||||
status_msg "Launching Moonraker instance $INSTANCE ..."
|
||||
sudo systemctl start moonraker-$INSTANCE
|
||||
|
||||
### instance counter +1
|
||||
INSTANCE=$(expr $INSTANCE + 1)
|
||||
done
|
||||
### confirm message
|
||||
ok_msg "$INSTANCE_COUNT Moonraker instances have been set up!\n"
|
||||
}
|
||||
|
||||
moonraker_conf_creation(){
|
||||
### default moonraker port
|
||||
PORT=7125
|
||||
|
||||
### get printer and moonraker config directory
|
||||
source_kiauh_ini
|
||||
PRINTER_CFG_LOC="$klipper_cfg_loc"
|
||||
MOONRAKER_CONF_LOC="$klipper_cfg_loc"
|
||||
|
||||
### reset instances back to 1 again
|
||||
INSTANCE=1
|
||||
|
||||
### create moonraker.conf
|
||||
if [ $INSTANCE_COUNT -eq $INSTANCE ]; then
|
||||
status_msg "Creating moonraker.conf in $MOONRAKER_CONF_LOC"
|
||||
if [ ! -f $MOONRAKER_CONF_LOC/moonraker.conf ]; then
|
||||
create_single_moonraker_conf && ok_msg "moonraker.conf created!"
|
||||
else
|
||||
warn_msg "There is already a file called 'moonraker.conf'!"
|
||||
warn_msg "Skipping..."
|
||||
fi
|
||||
else
|
||||
while [ $INSTANCE -le $INSTANCE_COUNT ]; do
|
||||
status_msg "Creating moonraker-$INSTANCE.conf in $MOONRAKER_CONF_LOC"
|
||||
if [ ! -f $MOONRAKER_CONF_LOC/moonraker-$INSTANCE.conf ]; then
|
||||
PORT=$(expr $PORT + $INSTANCE - 1)
|
||||
create_multi_moonraker_conf && ok_msg "moonraker-$INSTANCE.conf created!"
|
||||
else
|
||||
warn_msg "There is already a file called 'moonraker-$INSTANCE.conf'!"
|
||||
warn_msg "Skipping..."
|
||||
fi
|
||||
INSTANCE=$(expr $INSTANCE + 1)
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
create_single_moonraker_conf(){
|
||||
HOSTNAME=$(hostname -I | cut -d" " -f1)
|
||||
|
||||
/bin/sh -c "cat > $MOONRAKER_CONF_LOC/moonraker.conf" << MOONRAKERCONF
|
||||
[server]
|
||||
host: 0.0.0.0
|
||||
port: $PORT
|
||||
klippy_uds_address: /tmp/klippy_uds
|
||||
enable_debug_logging: True
|
||||
config_path: $PRINTER_CFG_LOC
|
||||
|
||||
[authorization]
|
||||
enabled: True
|
||||
api_key_file: ~/.moonraker_api_key
|
||||
trusted_clients:
|
||||
127.0.0.1
|
||||
cors_domains:
|
||||
http://*.local
|
||||
http://app.fluidd.xyz
|
||||
https://app.fluidd.xyz
|
||||
http://$HOSTNAME:*
|
||||
|
||||
[update_manager]
|
||||
#client_repo:
|
||||
#client_path:
|
||||
MOONRAKERCONF
|
||||
}
|
||||
|
||||
create_multi_moonraker_conf(){
|
||||
HOSTNAME=$(hostname -I | cut -d" " -f1)
|
||||
|
||||
/bin/sh -c "cat > $MOONRAKER_CONF_LOC/moonraker-$INSTANCE.conf" << MOONRAKERCONF
|
||||
[server]
|
||||
host: 0.0.0.0
|
||||
port: $PORT
|
||||
klippy_uds_address: /tmp/klippy_uds-$INSTANCE
|
||||
enable_debug_logging: True
|
||||
config_path: $PRINTER_CFG_LOC
|
||||
|
||||
[authorization]
|
||||
enabled: True
|
||||
api_key_file: ~/.moonraker_api_key
|
||||
trusted_clients:
|
||||
127.0.0.1
|
||||
$HOSTNAME
|
||||
cors_domains:
|
||||
http://*.local
|
||||
http://app.fluidd.xyz
|
||||
https://app.fluidd.xyz
|
||||
http://$HOSTNAME:*
|
||||
|
||||
[update_manager]
|
||||
#client_repo:
|
||||
#client_path:
|
||||
MOONRAKERCONF
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
install_moonraker(){
|
||||
python3_check
|
||||
if [ $py_chk_ok = "true" ]; then
|
||||
@@ -18,7 +332,7 @@ install_moonraker(){
|
||||
disable_octoprint
|
||||
#after install actions
|
||||
restart_moonraker
|
||||
restart_klipper
|
||||
klipper_service "restart"
|
||||
else
|
||||
ERROR_MSG="Python 3.7 or above required!\n Please upgrade your Python version first."
|
||||
print_msg && clear_msg
|
||||
@@ -254,48 +568,28 @@ get_user_selections_moonraker(){
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
moonraker_setup(){
|
||||
dep=(wget curl unzip dfu-util)
|
||||
dependency_check
|
||||
status_msg "Downloading Moonraker ..."
|
||||
#force remove existing moonraker dir
|
||||
[ -d $MOONRAKER_DIR ] && rm -rf $MOONRAKER_DIR
|
||||
#clone into fresh moonraker dir
|
||||
cd ${HOME} && git clone $MOONRAKER_REPO
|
||||
ok_msg "Download complete!"
|
||||
status_msg "Installing Moonraker ..."
|
||||
$MOONRAKER_DIR/scripts/install-moonraker.sh
|
||||
#copy moonraker configuration for nginx to /etc/nginx/conf.d
|
||||
setup_moonraker_nginx_cfg
|
||||
#backup a possible existing printer.cfg at the old location and before patching in the new location
|
||||
backup_printer_cfg
|
||||
patch_klipper_sysfile "moonraker"
|
||||
#re-run printer.cfg location function to read the new path for the printer.cfg
|
||||
locate_printer_cfg
|
||||
echo; ok_msg "Moonraker successfully installed!"
|
||||
}
|
||||
#moonraker_setup(){
|
||||
# dep=(wget curl unzip dfu-util)
|
||||
# dependency_check
|
||||
# status_msg "Downloading Moonraker ..."
|
||||
# #force remove existing moonraker dir
|
||||
# [ -d $MOONRAKER_DIR ] && rm -rf $MOONRAKER_DIR
|
||||
# #clone into fresh moonraker dir
|
||||
# cd ${HOME} && git clone $MOONRAKER_REPO
|
||||
# ok_msg "Download complete!"
|
||||
# status_msg "Installing Moonraker ..."
|
||||
# $MOONRAKER_DIR/scripts/install-moonraker.sh
|
||||
# #copy moonraker configuration for nginx to /etc/nginx/conf.d
|
||||
# setup_moonraker_nginx_cfg
|
||||
# #backup a possible existing printer.cfg at the old location and before patching in the new location
|
||||
# backup_printer_cfg
|
||||
# patch_klipper_sysfile "moonraker"
|
||||
# #re-run printer.cfg location function to read the new path for the printer.cfg
|
||||
# locate_printer_cfg
|
||||
# echo; ok_msg "Moonraker successfully installed!"
|
||||
#}
|
||||
|
||||
patch_klipper_sysfile(){
|
||||
if [ -e $KLIPPER_SERVICE2 ]; then
|
||||
status_msg "Checking /etc/default/klipper for necessary entries ..."
|
||||
#patching new printer.cfg location to /etc/default/klipper
|
||||
if [ "$1" = "moonraker" ]; then
|
||||
if ! grep -q "/klipper_config/printer.cfg" $KLIPPER_SERVICE2; then
|
||||
status_msg "Patching new printer.cfg location to /etc/default/klipper ..."
|
||||
sudo sed -i "/KLIPPY_ARGS=/ s|$PRINTER_CFG|/home/${USER}/klipper_config/printer.cfg|" $KLIPPER_SERVICE2
|
||||
ok_msg "New location is: '/home/${USER}/klipper_config/printer.cfg'"
|
||||
fi
|
||||
fi
|
||||
#patching new UDS argument to /etc/default/klipper
|
||||
if [ "$1" = "moonraker" ] || [ "$1" = "dwc2" ]; then
|
||||
if ! grep -q -- "-a /tmp/klippy_uds" $KLIPPER_SERVICE2; then
|
||||
status_msg "Patching unix domain socket to /etc/default/klipper ..."
|
||||
#append the new argument to /tmp/klippy.log argument
|
||||
sudo sed -i "/KLIPPY_ARGS/s/\.log/\.log -a \/tmp\/klippy_uds/" $KLIPPER_SERVICE2
|
||||
ok_msg "Patching done!"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
if [ -e $KLIPPER_SERVICE3 ]; then
|
||||
status_msg "Checking /etc/systemd/system/klipper.service for necessary entries ..."
|
||||
#patching new printer.cfg location to /etc/systemd/system/klipper.service
|
||||
|
||||
@@ -1,38 +1,66 @@
|
||||
remove_klipper(){
|
||||
data_arr=(
|
||||
/etc/init.d/klipper
|
||||
/etc/default/klipper
|
||||
/etc/systemd/system/klipper.service
|
||||
$KLIPPER_DIR
|
||||
$KLIPPY_ENV_DIR
|
||||
${HOME}/klippy.log
|
||||
)
|
||||
print_error "Klipper" && data_count=()
|
||||
if [ "$ERROR_MSG" = "" ]; then
|
||||
stop_klipper
|
||||
if [[ -e /etc/init.d/klipper || -e /etc/default/klipper ]]; then
|
||||
status_msg "Removing Klipper Service ..."
|
||||
sudo rm -rf /etc/init.d/klipper /etc/default/klipper
|
||||
sudo update-rc.d -f klipper remove
|
||||
ok_msg "Klipper Service removed!"
|
||||
fi
|
||||
if [ -e /etc/systemd/system/klipper.service ]; then
|
||||
status_msg "Removing Klipper Service ..."
|
||||
sudo rm -rf /etc/systemd/system/klipper.service
|
||||
sudo update-rc.d -f klipper remove
|
||||
sudo systemctl daemon-reload
|
||||
ok_msg "Klipper Service removed!"
|
||||
fi
|
||||
if [[ -d $KLIPPER_DIR || -d $KLIPPY_ENV_DIR ]]; then
|
||||
status_msg "Removing Klipper and klippy-env directory ..."
|
||||
rm -rf $KLIPPER_DIR $KLIPPY_ENV_DIR && ok_msg "Directories removed!"
|
||||
fi
|
||||
if [[ -L ${HOME}/klippy.log || -e /tmp/klippy.log ]]; then
|
||||
status_msg "Removing klippy.log Symlink ..."
|
||||
rm -rf ${HOME}/klippy.log /tmp/klippy.log && ok_msg "Symlink removed!"
|
||||
fi
|
||||
CONFIRM_MSG=" Klipper successfully removed!"
|
||||
###remove single instance
|
||||
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then
|
||||
status_msg "Removing Klipper Service ..."
|
||||
sudo systemctl stop klipper
|
||||
sudo systemctl disable klipper
|
||||
sudo rm -f $SYSTEMDDIR/klipper.service
|
||||
ok_msg "Klipper Service removed!"
|
||||
fi
|
||||
if [ -f /tmp/klippy.log ]; then
|
||||
status_msg "Removing /tmp/klippy.log ..." && rm -f /tmp/klippy.log && ok_msg "Done!"
|
||||
fi
|
||||
if [ -e /tmp/klippy_uds ]; then
|
||||
status_msg "Removing /tmp/klippy_uds ..." && rm -f /tmp/klippy_uds && ok_msg "Done!"
|
||||
fi
|
||||
if [ -h /tmp/printer ]; then
|
||||
status_msg "Removing /tmp/printer ..." && rm -f /tmp/printer && ok_msg "Done!"
|
||||
fi
|
||||
|
||||
###remove multi instance services
|
||||
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service")" ]; then
|
||||
status_msg "Removing Klipper Services ..."
|
||||
for service in $(find $SYSTEMDDIR -maxdepth 1 -name "klipper-*.service" | cut -d"/" -f5)
|
||||
do
|
||||
status_msg "Removing $service ..."
|
||||
sudo systemctl stop $service
|
||||
sudo systemctl disable $service
|
||||
sudo rm -f $SYSTEMDDIR/$service
|
||||
ok_msg "Done!"
|
||||
done
|
||||
fi
|
||||
###remove multi instance logfiles
|
||||
if [ "$(find /tmp -maxdepth 1 -name "klippy-*.log")" ]; then
|
||||
for logfile in $(find /tmp -maxdepth 1 -name "klippy-*.log")
|
||||
do
|
||||
status_msg "Removing $logfile ..." && rm -f $logfile && ok_msg "Done!"
|
||||
done
|
||||
fi
|
||||
###remove multi instance UDS
|
||||
if [ "$(find /tmp -maxdepth 1 -name "klippy_uds-*")" ]; then
|
||||
for uds in $(find /tmp -maxdepth 1 -name "klippy_uds-*")
|
||||
do
|
||||
status_msg "Removing $uds ..." && rm -f $uds && ok_msg "Done!"
|
||||
done
|
||||
fi
|
||||
###remove multi instance tmp-printer
|
||||
if [ "$(find /tmp -maxdepth 1 -name "printer-*")" ]; then
|
||||
for tmp_printer in $(find /tmp -maxdepth 1 -name "printer-*")
|
||||
do
|
||||
status_msg "Removing $tmp_printer ..." && rm -f $tmp_printer && ok_msg "Done!"
|
||||
done
|
||||
fi
|
||||
|
||||
###reloading units
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
###removing klipper and klippy-env folders
|
||||
if [ -d $KLIPPER_DIR ] || [ -d $KLIPPY_ENV ]; then
|
||||
status_msg "Removing Klipper and klippy-env directory ..."
|
||||
rm -rf $KLIPPER_DIR $KLIPPY_ENV && ok_msg "Directories removed!"
|
||||
fi
|
||||
|
||||
CONFIRM_MSG=" Klipper was successfully removed!"
|
||||
}
|
||||
|
||||
#############################################################
|
||||
@@ -101,83 +129,63 @@ remove_dwc2(){
|
||||
#############################################################
|
||||
|
||||
remove_moonraker(){
|
||||
data_arr=(
|
||||
$MOONRAKER_SERVICE1
|
||||
$MOONRAKER_SERVICE2
|
||||
$MOONRAKER_DIR
|
||||
$MOONRAKER_ENV_DIR
|
||||
$NGINX_CONFD/upstreams.conf
|
||||
$NGINX_CONFD/common_vars.conf
|
||||
${HOME}/moonraker.conf
|
||||
${HOME}/moonraker.log
|
||||
${HOME}/klipper_config/moonraker.log
|
||||
${HOME}/klipper_config/klippy.log
|
||||
${HOME}/.klippy_api_key
|
||||
${HOME}/.moonraker_api_key
|
||||
)
|
||||
print_error "Moonraker" && data_count=()
|
||||
if [ "$ERROR_MSG" = "" ]; then
|
||||
if [ -e ${HOME}/moonraker.conf ]; then
|
||||
unset REMOVE_MOONRAKER_CONF
|
||||
while true; do
|
||||
echo
|
||||
read -p "${cyan}###### Delete moonraker.conf? (y/N):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes)
|
||||
echo -e "###### > Yes"
|
||||
REMOVE_MOONRAKER_CONF="true"
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
echo -e "###### > No"
|
||||
REMOVE_MOONRAKER_CONF="false"
|
||||
break;;
|
||||
*)
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
status_msg "Processing ..."
|
||||
stop_moonraker
|
||||
#remove moonraker services
|
||||
if [[ -e /etc/init.d/moonraker || -e /etc/default/moonraker ]]; then
|
||||
status_msg "Removing Moonraker Service ..."
|
||||
sudo update-rc.d -f moonraker remove
|
||||
sudo rm -rf /etc/init.d/moonraker /etc/default/moonraker && ok_msg "Moonraker Service removed!"
|
||||
fi
|
||||
#remove moonraker and moonraker-env dir
|
||||
if [[ -d $MOONRAKER_DIR || -d $MOONRAKER_ENV_DIR ]]; then
|
||||
status_msg "Removing Moonraker and moonraker-env directory ..."
|
||||
rm -rf $MOONRAKER_DIR $MOONRAKER_ENV_DIR && ok_msg "Directories removed!"
|
||||
fi
|
||||
#remove moonraker.conf
|
||||
if [ "$REMOVE_MOONRAKER_CONF" = "true" ]; then
|
||||
status_msg "Removing moonraker.conf ..."
|
||||
rm -rf ${HOME}/moonraker.conf && ok_msg "File removed!"
|
||||
fi
|
||||
#remove moonraker.log and symlink
|
||||
if [[ -L ${HOME}/moonraker.log || -L ${HOME}/klipper_config/moonraker.log || -L ${HOME}/klipper_config/klippy.log || -e /tmp/moonraker.log ]]; then
|
||||
status_msg "Removing Logs and Symlinks ..."
|
||||
rm -rf ${HOME}/moonraker.log ${HOME}/klipper_config/moonraker.log ${HOME}/klipper_config/klippy.log /tmp/moonraker.log
|
||||
ok_msg "Files removed!"
|
||||
fi
|
||||
#remove moonraker nginx config
|
||||
if [[ -e $NGINX_CONFD/upstreams.conf || -e $NGINX_CONFD/common_vars.conf ]]; then
|
||||
status_msg "Removing Moonraker NGINX configuration ..."
|
||||
sudo rm -f $NGINX_CONFD/upstreams.conf $NGINX_CONFD/common_vars.conf && ok_msg "Moonraker NGINX configuration removed!"
|
||||
fi
|
||||
#remove legacy api key
|
||||
if [ -e ${HOME}/.klippy_api_key ]; then
|
||||
status_msg "Removing legacy API Key ..."
|
||||
rm ${HOME}/.klippy_api_key && ok_msg "Done!"
|
||||
fi
|
||||
#remove api key
|
||||
if [ -e ${HOME}/.moonraker_api_key ]; then
|
||||
status_msg "Removing API Key ..."
|
||||
rm ${HOME}/.moonraker_api_key && ok_msg "Done!"
|
||||
fi
|
||||
CONFIRM_MSG="Moonraker successfully removed!"
|
||||
###remove single instance
|
||||
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ]; then
|
||||
status_msg "Removing Moonraker Service ..."
|
||||
sudo systemctl stop moonraker
|
||||
sudo systemctl disable moonraker
|
||||
sudo rm -f $SYSTEMDDIR/moonraker.service
|
||||
ok_msg "Moonraker Service removed!"
|
||||
fi
|
||||
if [ -f /tmp/moonraker.log ]; then
|
||||
status_msg "Removing /tmp/moonraker.log ..." && rm -f /tmp/moonraker.log && ok_msg "Done!"
|
||||
fi
|
||||
|
||||
###remove multi instance services
|
||||
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service")" ]; then
|
||||
status_msg "Removing Moonraker Services ..."
|
||||
for service in $(find $SYSTEMDDIR -maxdepth 1 -name "moonraker-*.service" | cut -d"/" -f5)
|
||||
do
|
||||
status_msg "Removing $service ..."
|
||||
sudo systemctl stop $service
|
||||
sudo systemctl disable $service
|
||||
sudo rm -f $SYSTEMDDIR/$service
|
||||
ok_msg "Done!"
|
||||
done
|
||||
fi
|
||||
###remove multi instance logfiles
|
||||
if [ "$(find /tmp -maxdepth 1 -name "moonraker-*.log")" ]; then
|
||||
for logfile in $(find /tmp -maxdepth 1 -name "moonraker-*.log")
|
||||
do
|
||||
status_msg "Removing $logfile ..." && rm -f $logfile && ok_msg "Done!"
|
||||
done
|
||||
fi
|
||||
|
||||
###reloading units
|
||||
sudo systemctl daemon-reload
|
||||
|
||||
###removing moonraker and moonraker-env folders
|
||||
if [ -d $MOONRAKER_DIR ] || [ -d $MOONRAKER_ENV ]; then
|
||||
status_msg "Removing Moonraker and moonraker-env directory ..."
|
||||
rm -rf $MOONRAKER_DIR $MOONRAKER_ENV && ok_msg "Directories removed!"
|
||||
fi
|
||||
|
||||
#remove moonraker nginx config
|
||||
if [[ -e $NGINX_CONFD/upstreams.conf || -e $NGINX_CONFD/common_vars.conf ]]; then
|
||||
status_msg "Removing Moonraker NGINX configuration ..."
|
||||
sudo rm -f $NGINX_CONFD/upstreams.conf $NGINX_CONFD/common_vars.conf && ok_msg "Moonraker NGINX configuration removed!"
|
||||
fi
|
||||
|
||||
#remove legacy api key
|
||||
if [ -e ${HOME}/.klippy_api_key ]; then
|
||||
status_msg "Removing legacy API Key ..." && rm ${HOME}/.klippy_api_key && ok_msg "Done!"
|
||||
fi
|
||||
#remove api key
|
||||
if [ -e ${HOME}/.moonraker_api_key ]; then
|
||||
status_msg "Removing API Key ..." && rm ${HOME}/.moonraker_api_key && ok_msg "Done!"
|
||||
fi
|
||||
|
||||
CONFIRM_MSG=" Moonraker was successfully removed!"
|
||||
}
|
||||
|
||||
#############################################################
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
save_klipper_state(){
|
||||
source_ini
|
||||
source_kiauh_ini
|
||||
#read current klipper state
|
||||
cd $KLIPPER_DIR
|
||||
COMMIT_STATE=$(git rev-parse --short HEAD)
|
||||
@@ -19,7 +19,7 @@ save_klipper_state(){
|
||||
}
|
||||
|
||||
load_klipper_state(){
|
||||
source_ini
|
||||
source_kiauh_ini
|
||||
print_branch
|
||||
cd $KLIPPER_DIR
|
||||
CURRENT_COMMIT=$(git rev-parse --short=8 HEAD)
|
||||
|
||||
@@ -18,7 +18,9 @@ klipper_status(){
|
||||
$KLIPPY_ENV_DIR
|
||||
)
|
||||
#remove the "SERVICE" entry from the klipper_data array if a klipper service is installed
|
||||
[ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ] && unset klipper_data[0]
|
||||
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ] || [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service")" ]; then
|
||||
unset klipper_data[0]
|
||||
fi
|
||||
#count+1 for each found data-item from array
|
||||
for kd in "${klipper_data[@]}"
|
||||
do
|
||||
@@ -64,11 +66,11 @@ moonraker_status(){
|
||||
SERVICE
|
||||
$MOONRAKER_DIR
|
||||
$MOONRAKER_ENV_DIR
|
||||
$NGINX_CONFD/upstreams.conf
|
||||
$NGINX_CONFD/common_vars.conf
|
||||
)
|
||||
#remove the "SERVICE" entry from the moonraker_data array if a moonraker service is installed
|
||||
[ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ] && unset moonraker_data[0]
|
||||
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ] || [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service")" ]; then
|
||||
unset moonraker_data[0]
|
||||
fi
|
||||
#count+1 for each found data-item from array
|
||||
for mrd in "${moonraker_data[@]}"
|
||||
do
|
||||
|
||||
@@ -26,13 +26,13 @@ install_menu(){
|
||||
1)
|
||||
clear
|
||||
print_header
|
||||
install_klipper
|
||||
klipper_setup_dialog
|
||||
print_msg && clear_msg
|
||||
install_ui;;
|
||||
2)
|
||||
clear
|
||||
print_header
|
||||
install_moonraker
|
||||
moonraker_setup_dialog
|
||||
print_msg && clear_msg
|
||||
install_ui;;
|
||||
3)
|
||||
|
||||
@@ -7,10 +7,10 @@ main_ui(){
|
||||
echo -e "| 1) [Install] | |"
|
||||
echo -e "| 2) [Update] | Moonraker: $MOONRAKER_STATUS|"
|
||||
echo -e "| 3) [Remove] | |"
|
||||
echo -e "| | DWC2: $DWC2_STATUS|"
|
||||
echo -e "| 4) [Advanced] | Fluidd: $FLUIDD_STATUS|"
|
||||
echo -e "| 5) [Backup] | Mainsail: $MAINSAIL_STATUS|"
|
||||
echo -e "| | Octoprint: $OCTOPRINT_STATUS|"
|
||||
echo -e "| 4) [Advanced] | DWC2: $DWC2_STATUS|"
|
||||
echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|"
|
||||
echo -e "| | Mainsail: $MAINSAIL_STATUS|"
|
||||
echo -e "| 6) [Settings] | Octoprint: $OCTOPRINT_STATUS|"
|
||||
echo -e "| | |"
|
||||
echo -e "| ${cyan}$KIAUH_VER${default}| KlipperScreen: $KLIPPERSCREEN_STATUS|"
|
||||
quit_footer
|
||||
@@ -75,6 +75,10 @@ main_menu(){
|
||||
clear
|
||||
backup_menu
|
||||
break;;
|
||||
6)
|
||||
clear
|
||||
settings_menu
|
||||
break;;
|
||||
Q|q)
|
||||
echo -e "${green}###### Happy printing! ######${default}"; echo
|
||||
exit -1;;
|
||||
|
||||
47
scripts/ui/settings_menu.sh
Executable file
47
scripts/ui/settings_menu.sh
Executable file
@@ -0,0 +1,47 @@
|
||||
settings_ui(){
|
||||
source_kiauh_ini
|
||||
[ -z $klipper_cfg_loc ] && klipper_cfg_loc="----------"
|
||||
top_border
|
||||
echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") | "
|
||||
hr
|
||||
echo -e "| ${red}Caution:${default} | "
|
||||
echo -e "| Changing the path below will COPY the config files | "
|
||||
echo -e "| to the new location. During that process ALL Klipper | "
|
||||
echo -e "| and Moonraker services get stopped and reconfigured. | "
|
||||
blank_line
|
||||
echo -e "| ${red}DO NOT change the folder location during printing!${default} | "
|
||||
hr
|
||||
blank_line
|
||||
echo -e "| ${yellow}● Current Klipper configuration folder:${default} | "
|
||||
printf "|%-55s|\n" " $klipper_cfg_loc"
|
||||
blank_line
|
||||
hr
|
||||
echo -e "| 1) Change configuration folder | "
|
||||
quit_footer
|
||||
}
|
||||
|
||||
settings_menu(){
|
||||
print_header
|
||||
print_msg && clear_msg
|
||||
settings_ui
|
||||
while true; do
|
||||
read -p "${cyan}Perform action:${default} " action; echo
|
||||
case "$action" in
|
||||
1)
|
||||
clear
|
||||
print_header
|
||||
change_klipper_cfg_path
|
||||
print_msg && clear_msg
|
||||
settings_ui;;
|
||||
Q|q)
|
||||
clear; main_menu; break;;
|
||||
*)
|
||||
clear
|
||||
print_header
|
||||
print_unkown_cmd
|
||||
print_msg && clear_msg
|
||||
settings_ui;;
|
||||
esac
|
||||
done
|
||||
settings_ui
|
||||
}
|
||||
@@ -58,7 +58,7 @@ update_all(){
|
||||
}
|
||||
|
||||
update_klipper(){
|
||||
stop_klipper
|
||||
klipper_service "stop"
|
||||
if [ ! -d $KLIPPER_DIR ]; then
|
||||
cd ${HOME} && git clone $KLIPPER_REPO
|
||||
else
|
||||
@@ -82,7 +82,7 @@ update_klipper(){
|
||||
ok_msg "Dependencies already met or have been installed!"
|
||||
ok_msg "Update complete!"
|
||||
fi
|
||||
start_klipper
|
||||
klipper_service "start"
|
||||
}
|
||||
|
||||
update_dwc2fk(){
|
||||
|
||||
@@ -37,7 +37,7 @@ accept_upload_conditions(){
|
||||
}
|
||||
|
||||
upload_selection(){
|
||||
source_ini
|
||||
source_kiauh_ini
|
||||
[ "$logupload_accepted" = "false" ] && accept_upload_conditions
|
||||
KLIPPY_LOG=/tmp/klippy.log
|
||||
MOONRAKER_LOG=/tmp/moonraker.log
|
||||
|
||||
Reference in New Issue
Block a user