From 61dfab568389f9a38b20110061b900acba14d35b Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 7 Jan 2021 15:24:25 +0100 Subject: [PATCH 01/97] feat: klipper config backup function --- kiauh.sh | 11 +++-------- scripts/backup.sh | 19 ++++++++++++++++--- scripts/ui/backup_menu.sh | 29 ++++++++++++++--------------- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index 73604b1..efa91d3 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -17,19 +17,14 @@ for script in "${SRCDIR}/kiauh/scripts/ui/"*.sh; do . $script; done ### set important directories #klipper KLIPPER_DIR=${HOME}/klipper -KLIPPY_ENV_DIR=${HOME}/klippy-env -KLIPPER_SERVICE1=/etc/init.d/klipper -KLIPPER_SERVICE2=/etc/default/klipper -KLIPPER_SERVICE3=/etc/systemd/system/klipper.service +KLIPPY_ENV=${HOME}/klippy-env #nginx NGINX_SA=/etc/nginx/sites-available NGINX_SE=/etc/nginx/sites-enabled NGINX_CONFD=/etc/nginx/conf.d #moonraker MOONRAKER_DIR=${HOME}/moonraker -MOONRAKER_ENV_DIR=${HOME}/moonraker-env -MOONRAKER_SERVICE1=/etc/init.d/moonraker -MOONRAKER_SERVICE2=/etc/default/moonraker +MOONRAKER_ENV=${HOME}/moonraker-env #mainsail MAINSAIL_DIR=${HOME}/mainsail #fluidd @@ -75,7 +70,7 @@ title_msg(){ echo -e "${cyan}$1${default}" } get_date(){ - current_date=$(date +"%Y-%m-%d_%H-%M") + current_date=$(date +"%Y%m%d_%H%M") } print_unkown_cmd(){ ERROR_MSG="Invalid command!" diff --git a/scripts/backup.sh b/scripts/backup.sh index f0a55b1..ac69aca 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -16,6 +16,19 @@ backup_printer_cfg(){ fi } +backup_klipper_config_dir(){ + source_kiauh_ini + check_for_backup_dir + if [ -d "$klipper_cfg_loc" ]; then + get_date + status_msg "Create backup of the Klipper config directory ..." + config_folder_name="$(echo "$klipper_cfg_loc" | rev | cut -d"/" -f1 | rev)" + cp -r "$klipper_cfg_loc" "$BACKUP_DIR/$config_folder_name.$current_date.backup" && ok_msg "Backup complete!" + else + ok_msg "No config directory found! Skipping backup ..." + fi +} + backup_moonraker_conf(){ check_for_backup_dir if [ -f ${HOME}/moonraker.conf ]; then @@ -28,7 +41,7 @@ backup_moonraker_conf(){ } read_bb4u_stat(){ - source_ini + source_kiauh_ini if [ ! "$backup_before_update" = "true" ]; then BB4U_STATUS="${green}[Enable]${default} backups before updating " else @@ -37,7 +50,7 @@ read_bb4u_stat(){ } toggle_backups(){ - source_ini + source_kiauh_ini if [ "$backup_before_update" = "true" ]; then sed -i '/backup_before_update=/s/true/false/' $INI_FILE BB4U_STATUS="${green}[Enable]${default} backups before updating " @@ -51,7 +64,7 @@ toggle_backups(){ } bb4u(){ - source_ini + source_kiauh_ini if [ "$backup_before_update" = "true" ]; then backup_$1 fi diff --git a/scripts/ui/backup_menu.sh b/scripts/ui/backup_menu.sh index 6c7d1e3..ef6c3d2 100755 --- a/scripts/ui/backup_menu.sh +++ b/scripts/ui/backup_menu.sh @@ -4,21 +4,14 @@ backup_ui(){ hr echo -e "| ${yellow}Backup location: ~/kiauh-backups${default} | " hr - echo -e "| Firmware: | " - echo -e "| 1) [Klipper] | " - echo -e "| | " - echo -e "| Klipper API: | " - echo -e "| 2) [Moonraker] | " - echo -e "| | " - echo -e "| Webinterface: | " - echo -e "| 3) [Mainsail] | " - echo -e "| 4) [Fluidd] | " - echo -e "| 5) [DWC2 Web UI] | " - echo -e "| 6) [OctoPrint] | " - echo -e "| | " - echo -e "| HDMI Screen: | " - echo -e "| 7) [KlipperScreen] | " - echo -e "| | " + echo -e "| Configuration folder: | Webinterface: | " + echo -e "| 0) [Klipper configs] | 3) [Mainsail] | " + echo -e "| | 4) [Fluidd] | " + echo -e "| Firmware: | 5) [DWC2 Web UI] | " + echo -e "| 1) [Klipper] | 6) [OctoPrint] | " + echo -e "| | | " + echo -e "| Klipper API: | HDMI Screen: | " + echo -e "| 2) [Moonraker] | 7) [KlipperScreen] | " quit_footer } @@ -29,6 +22,12 @@ backup_menu(){ while true; do read -p "${cyan}Perform action:${default} " action; echo case "$action" in + 0) + clear + print_header + backup_klipper_config_dir + print_msg && clear_msg + backup_ui;; 1) clear print_header From 08ae57d349e09ace41e337ef1364b93146f71acb Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 7 Jan 2021 15:26:19 +0100 Subject: [PATCH 02/97] initial commit of a bigger kiauh rework to make multi instance installations possible --- scripts/functions.sh | 204 ++++++++++++++----- scripts/install_dwc2.sh | 4 +- scripts/install_klipper.sh | 290 ++++++++++++++++++--------- scripts/install_moonraker.sh | 376 +++++++++++++++++++++++++++++++---- scripts/remove.sh | 226 +++++++++++---------- scripts/rollback.sh | 4 +- scripts/status.sh | 10 +- scripts/ui/install_menu.sh | 4 +- scripts/ui/main_menu.sh | 12 +- scripts/ui/settings_menu.sh | 47 +++++ scripts/update.sh | 4 +- scripts/upload_log.sh | 2 +- 12 files changed, 873 insertions(+), 310 deletions(-) create mode 100755 scripts/ui/settings_menu.sh diff --git a/scripts/functions.sh b/scripts/functions.sh index 2c9b402..40c3589 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -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 } diff --git a/scripts/install_dwc2.sh b/scripts/install_dwc2.sh index 1e40db1..d7cd05b 100755 --- a/scripts/install_dwc2.sh +++ b/scripts/install_dwc2.sh @@ -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 diff --git a/scripts/install_klipper.sh b/scripts/install_klipper.sh index a2e956b..1deed08 100755 --- a/scripts/install_klipper.sh +++ b/scripts/install_klipper.sh @@ -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 } diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index ff76230..32ccdaf 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -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 diff --git a/scripts/remove.sh b/scripts/remove.sh index a1dc99a..3eea75c 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -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!" } ############################################################# diff --git a/scripts/rollback.sh b/scripts/rollback.sh index dec2c3a..79a6482 100755 --- a/scripts/rollback.sh +++ b/scripts/rollback.sh @@ -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) diff --git a/scripts/status.sh b/scripts/status.sh index 6775af2..c5153f6 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -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 diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index c50d936..0cf1108 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -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) diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 40396ec..5d10ebd 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -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;; diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh new file mode 100755 index 0000000..5cfe060 --- /dev/null +++ b/scripts/ui/settings_menu.sh @@ -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 +} diff --git a/scripts/update.sh b/scripts/update.sh index de9e306..72d9164 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -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(){ diff --git a/scripts/upload_log.sh b/scripts/upload_log.sh index aa8bf34..fcbd10a 100755 --- a/scripts/upload_log.sh +++ b/scripts/upload_log.sh @@ -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 From bb1c5c4900407278faa070750ecbec61635afa9d Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 7 Jan 2021 16:25:31 +0100 Subject: [PATCH 03/97] fix: add remove method for removing old init.d klipper service --- scripts/remove.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scripts/remove.sh b/scripts/remove.sh index 3eea75c..c08df82 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -1,4 +1,14 @@ remove_klipper(){ + ### remove "legacy" init.d service + 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 + sudo systemctl disable klipper + sudo systemctl daemon-reload + ok_msg "Klipper Service removed!" + fi + ###remove single instance if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then status_msg "Removing Klipper Service ..." From 218700b63dde5bb8052be39245322876637b2837 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 7 Jan 2021 16:27:51 +0100 Subject: [PATCH 04/97] fix: add remove method for init.d moonraker service --- scripts/remove.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/remove.sh b/scripts/remove.sh index c08df82..b6147c3 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -1,5 +1,5 @@ remove_klipper(){ - ### remove "legacy" init.d service + ### remove "legacy" klipper init.d service 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 @@ -139,7 +139,17 @@ remove_dwc2(){ ############################################################# remove_moonraker(){ -###remove single instance + ### remove "legacy" moonraker init.d service + if [[ -e /etc/init.d/moonraker || -e /etc/default/moonraker ]]; then + status_msg "Removing Moonraker Service ..." + sudo rm -rf /etc/init.d/moonraker /etc/default/moonraker + sudo update-rc.d -f moonraker remove + sudo systemctl disable moonraker + sudo systemctl daemon-reload + ok_msg "Moonraker Service removed!" + fi + + ###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 From 08c1807cc79b9c102b63c60e119716e0cea824c3 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 7 Jan 2021 16:40:52 +0100 Subject: [PATCH 05/97] fix: forgot to stop services first --- scripts/remove.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/remove.sh b/scripts/remove.sh index b6147c3..bb2dfb6 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -2,9 +2,10 @@ remove_klipper(){ ### remove "legacy" klipper init.d service if [[ -e /etc/init.d/klipper || -e /etc/default/klipper ]]; then status_msg "Removing Klipper Service ..." + sudo systemctl stop klipper + sudo systemctl disable klipper sudo rm -rf /etc/init.d/klipper /etc/default/klipper sudo update-rc.d -f klipper remove - sudo systemctl disable klipper sudo systemctl daemon-reload ok_msg "Klipper Service removed!" fi @@ -142,9 +143,10 @@ remove_moonraker(){ ### remove "legacy" moonraker init.d service if [[ -e /etc/init.d/moonraker || -e /etc/default/moonraker ]]; then status_msg "Removing Moonraker Service ..." + sudo systemctl stop moonraker + sudo systemctl disable moonraker sudo rm -rf /etc/init.d/moonraker /etc/default/moonraker sudo update-rc.d -f moonraker remove - sudo systemctl disable moonraker sudo systemctl daemon-reload ok_msg "Moonraker Service removed!" fi From 65ec2e5e1a536b652694ecfd1d73f0a60c54c83c Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 7 Jan 2021 17:03:14 +0100 Subject: [PATCH 06/97] fix: bugs --- scripts/functions.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index 40c3589..a91f9ae 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -87,7 +87,7 @@ set_klipper_cfg_path(){ ok_msg "OK!" fi ### handle multi klipper instance service file - if [ "$(ls /etc/systemd/system/klipper-*.service)" > /dev/null 2>&1 ]; then + if ls /etc/systemd/system/klipper-*.service 2>/dev/null 1>&2; 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 @@ -104,7 +104,7 @@ set_klipper_cfg_path(){ ok_msg "OK!" fi ### handle multi moonraker instance service file - if [ "$(ls /etc/systemd/system/moonraker-*.service)" > /dev/null 2>&1 ]; then + if ls /etc/systemd/system/moonraker-*.service 2>/dev/null 1>&2; 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 @@ -120,7 +120,7 @@ set_klipper_cfg_path(){ sudo systemctl daemon-reload ### restart services - klipper_service "stop" && moonraker_service "stop" + klipper_service "restart" && moonraker_service "restart" } source_kiauh_ini(){ @@ -133,7 +133,7 @@ klipper_service(){ [ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping" [ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting" - if [ "$(ls /etc/systemd/system/klipper-*.service)" > /dev/null 2>&1 ]; then + if ls /etc/systemd/system/klipper-*.service 2>/dev/null 1>&2; 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 ..." @@ -154,7 +154,7 @@ moonraker_service(){ [ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping" [ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting" - if [ "$(ls /etc/systemd/system/moonraker-*.service)" > /dev/null 2>&1 ]; then + if ls /etc/systemd/system/moonraker-*.service 2>/dev/null 1>&2; 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 ..." From 88afa55268f6c8728c1b74813586d518ceeb79d1 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 8 Jan 2021 13:56:36 +0100 Subject: [PATCH 07/97] feat: support flashing of multiple connected mcus --- scripts/install_klipper.sh | 231 +++++++++++++++++------------------- scripts/ui/advanced_menu.sh | 12 +- 2 files changed, 112 insertions(+), 131 deletions(-) diff --git a/scripts/install_klipper.sh b/scripts/install_klipper.sh index 1deed08..3f5752f 100755 --- a/scripts/install_klipper.sh +++ b/scripts/install_klipper.sh @@ -1,11 +1,3 @@ -#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" @@ -205,77 +197,108 @@ create_multi_klipper_instance(){ } flash_routine(){ - if [ "$FLASH_FIRMWARE" = "true" ]; then - echo + echo + top_border + echo -e "| ${red}~~~~~~~~~~~ [ ATTENTION! ] ~~~~~~~~~~~~${default} |" + hr + echo -e "| Flashing a Smoothie based board with this script will |" + echo -e "| certainly fail. This applies to boards like the BTT |" + echo -e "| SKR V1.3 or SKR V1.4(Turbo). You have to copy the |" + echo -e "| firmware file to the microSD card manually and rename |" + echo -e "| it to 'firmware.bin'. |" + hr + echo -e "| You can find the file in: ~/klipper/out/klipper.bin |" + bottom_border + while true; do + read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn + case "$yn" in + Y|y|Yes|yes|"") + echo -e "###### > Yes" + get_mcu_id + break;; + N|n|No|no) + echo -e "###### > No" + break;; + *) + print_unkown_cmd + print_msg && clear_msg;; + esac + done +} + +flash_mcu(){ + if [ ${#mcu_list[@]} -ge 1 ]; then top_border - echo -e "| ${red}~~~~~~~~~~~ [ ATTENTION! ] ~~~~~~~~~~~~${default} |" + echo -e "| ${red}!!! IMPORTANT WARNING !!!${default} |" hr - echo -e "| Flashing a Smoothie based board with this script will |" - echo -e "| certainly fail. This applies to boards like the BTT |" - echo -e "| SKR V1.3 or SKR V1.4(Turbo). You have to copy the |" - echo -e "| firmware file to the microSD card manually and rename |" - echo -e "| it to 'firmware.bin'. |" - hr - echo -e "| You can find the file in: ~/klipper/out/klipper.bin |" + echo -e "| Make sure, that you select the correct ID for the MCU |" + echo -e "| you have build the firmware for in the previous step! |" + blank_line + echo -e "| This is especially important if you use different MCU |" + echo -e "| models which each require their own firmware! |" + blank_line + echo -e "| ${red}ONLY flash a firmware created for the respective MCU!${default} |" bottom_border + + ### list all mcus + i=1 + for mcu in ${mcu_list[@]}; do + ### rewrite mcu to cut off everything except the important stuff + mcu=$(echo $mcu | rev | cut -d"/" -f1 | rev) + echo -e "$i) ${cyan}$mcu${default}" + i=$(expr $i + 1) + done while true; do - read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn - case "$yn" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - CONFIRM_FLASHING="true" - CONFIRM_WRITE_PRINTER_USB="true" - get_printer_usb - break;; - N|n|No|no) - echo -e "###### > No" - CONFIRM_FLASHING="false" - CONFIRM_WRITE_PRINTER_USB="false" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac + echo + read -p "${cyan}###### Please select the ID for flashing:${default} " selected_id + mcu_index=$(echo $((selected_id - 1))) + echo -e "\nYou have selected to flash:\n● MCU #$selected_id: ${mcu_list[$mcu_index]}\n" + while true; do + read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn + case "$yn" in + Y|y|Yes|yes|"") + echo -e "###### > Yes" + status_msg "Flashing ${mcu_list[$mcu_index]} ..." + klipper_service "stop" + if ! make flash FLASH_DEVICE="${mcu_list[$mcu_index]}" ; then + warn_msg "Flashing failed!" + warn_msg "Please read the console output above!" + else + ok_msg "Flashing successfull!" + fi + klipper_service "start" + break;; + N|n|No|no) + echo -e "###### > No" + break;; + *) + print_unkown_cmd + print_msg && clear_msg;; + esac + done + break done fi } -flash_mcu(){ - if [ "$CONFIRM_FLASHING" = "true" ] && [ ! -z "$PRINTER_USB" ]; then - 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 - klipper_service "start" - fi -} - build_fw(){ - if [ "$BUILD_FIRMWARE" = "true" ]; then - if [ -d $KLIPPER_DIR ]; then - cd $KLIPPER_DIR - status_msg "Initializing Firmware Setup ..." - make menuconfig - status_msg "Building Firmware ..." - make clean && make && ok_msg "Firmware built!" - else - warn_msg "Can not build Firmware without a Klipper directory!" - fi + if [ -d $KLIPPER_DIR ]; then + cd $KLIPPER_DIR + status_msg "Initializing firmware Setup ..." + make menuconfig + status_msg "Building firmware ..." + make clean && make && ok_msg "Firmware built!" + else + warn_msg "Can not build firmware without a Klipper directory!" fi } -### grab the printers id -get_printer_usb(){ +### grab the mcu id +get_mcu_id(){ echo top_border - echo -e "| Please make sure your printer is connected to the Pi! |" - echo -e "| If the printer is not connected yet, connect it now. |" - hr - echo -e "| Also make sure, that it is the only USB device |" - echo -e "| connected at for now! Otherwise this step may fail! |" + echo -e "| Please make sure your MCU is connected to the Pi! |" + echo -e "| If the MCU is not connected yet, connect it now. |" bottom_border while true; do echo -e "${cyan}" @@ -283,70 +306,30 @@ get_printer_usb(){ echo -e "${default}" case "$yn" in *) - CONFIRM_PRINTER_USB="true" break;; esac done - status_msg "Identifying the correct USB port ..." + status_msg "Identifying the ID of your MCU ..." sleep 2 - unset PRINTER_USB - if [ -e /dev/serial/by-id/* ]; then - if [ -e /dev/serial/by-id/* ]; then - PRINTER_USB=$(ls /dev/serial/by-id/*) - status_msg "The ID of your printer is:" - title_msg "$PRINTER_USB" - else - warn_msg "Could not retrieve ID!" - fi - elif [ -e /dev/serial/by-path/* ]; then - if [ -e /dev/serial/by-path/* ]; then - PRINTER_USB=$(ls /dev/serial/by-path/*) - status_msg "The path of your printer is:" - title_msg "$PRINTER_USB" - else - warn_msg "Could not retrieve path!" - fi + unset MCU_ID + ### if there are devices found, continue, else show warn message + if ls /dev/serial/by-id/* 2>/dev/null 1>&2; then + mcu_count=1 + mcu_list=() + status_msg "The ID of your printers MCU is:" + ### loop over the IDs, write every ID as an item of the array 'mcu_list' + for mcu in /dev/serial/by-id/*; do + declare "mcu_id_$mcu_count"="$mcu" + mcu_id="mcu_id_$mcu_count" + mcu_list+=("${!mcu_id}") + ### rewrite mcu to cut off everything except the important stuff + mcu=$(echo $mcu | rev | cut -d"/" -f1 | rev) + echo " ● MCU #$mcu_count: ${cyan}$mcu${default}" + mcu_count=$(expr $mcu_count + 1) + done + unset mcu_count else + warn_msg "Could not retrieve ID!" warn_msg "Printer not plugged in or not detectable!" -fi -} - -write_printer_usb(){ - locate_printer_cfg - if [ ! -z "$PRINTER_CFG" ] && [ "$CONFIRM_WRITE_PRINTER_USB" = "true" ]; then - SERIAL_OLD=$(grep "serial" $PRINTER_CFG | tail -1 | cut -d" " -f2) - SERIAL_NEW=$PRINTER_USB - if [ "$SERIAL_OLD" != "$SERIAL_NEW" ]; then - unset write_entries - backup_printer_cfg - write_entries+=("[mcu]\nserial: $SERIAL_NEW") - write_entries+=("\\\n############################\n##### CREATED BY KIAUH #####\n############################") - write_entries=("############################\n" "${write_entries[@]}") - #check for a SAVE_CONFIG entry - SC="#*# <---------------------- SAVE_CONFIG ---------------------->" - if [[ $(grep "$SC" $PRINTER_CFG) ]]; then - SC_LINE=$(grep -n "$SC" $PRINTER_CFG | cut -d ":" -f1) - PRE_SC_LINE=$(expr $SC_LINE - 1) - SC_ENTRY="true" - else - SC_ENTRY="false" - fi - status_msg "Writing printer ID/path to printer.cfg ..." - if [ "$SC_ENTRY" = "true" ]; then - PRE_SC_LINE="$(expr $SC_LINE - 1)a" - for entry in "${write_entries[@]}" - do - sed -i "$PRE_SC_LINE $entry" $PRINTER_CFG - done - fi - if [ "$SC_ENTRY" = "false" ]; then - LINE_COUNT="$(wc -l < $PRINTER_CFG)a" - for entry in "${write_entries[@]}" - do - sed -i "$LINE_COUNT $entry" $PRINTER_CFG - done - fi - ok_msg "Done!" - fi fi } \ No newline at end of file diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh index a8b13f3..5e4b2b1 100755 --- a/scripts/ui/advanced_menu.sh +++ b/scripts/ui/advanced_menu.sh @@ -12,7 +12,7 @@ advanced_ui(){ echo -e "| Firmware: | 7) [Shell Command] | " echo -e "| 3) [Build only] | | " echo -e "| 4) [Build + Flash MCU] | | " - echo -e "| 5) [Get Printer-USB] | | " + echo -e "| 5) [Get MCU ID] | | " echo -e "| | | " quit_footer } @@ -47,25 +47,23 @@ advanced_menu(){ 3) clear print_header - unset BUILD_FIRMWARE && BUILD_FIRMWARE="true" build_fw print_msg && clear_msg advanced_ui;; 4) clear print_header - unset FLASH_FIRMWARE && FLASH_FIRMWARE="true" flash_routine - unset BUILD_FIRMWARE && BUILD_FIRMWARE="true" - build_fw - unset CONFIRM_FLASHING && CONFIRM_FLASHING="true" + ### build in a sleep to give the user a chance to have a look at the + ### MCU IDs before directly starting to build the klipper firmware + status_msg "Please wait..." && sleep 10 && build_fw flash_mcu print_msg && clear_msg advanced_ui;; 5) clear print_header - get_printer_usb + get_mcu_id print_msg && clear_msg advanced_ui;; 6) From 33a9fef676f3aeb88dc8ba5c4378535e0cc4c41d Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 8 Jan 2021 14:57:51 +0100 Subject: [PATCH 08/97] fix: check via md5sum of requirements text file if an update of the python env is necessary. if yes, do that update automatically. no user interaction anymore. --- scripts/update.sh | 87 ++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 51 deletions(-) diff --git a/scripts/update.sh b/scripts/update.sh index 72d9164..bf9d59d 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -67,22 +67,31 @@ update_klipper(){ save_klipper_state status_msg "Updating $GET_BRANCH" cd $KLIPPER_DIR + KLIPPER_OLDREQ_MD5SUM="$(md5sum $KLIPPER_DIR/scripts/klippy-requirements.txt | cut -d " " -f1)" + if [ "$DETACHED_HEAD" == "true" ]; then git checkout $GET_BRANCH unset DETACHED_HEAD fi + + ### pull latest files from github git pull && ok_msg "Update successfull!" - #check for possible new dependencies and install them - status_msg "Checking for possible new dependencies ..." - PKGLIST=$(grep "PKGLIST=" ~/klipper/scripts/install-octopi.sh | cut -d'"' -f2- | cut -d'"' -f1 | cut -d"}" -f2) - PYTHONDIR="${HOME}/klippy-env" - sudo apt-get update && sudo apt-get install --yes $PKGLIST - $PYTHONDIR/bin/pip install -r ~/klipper/scripts/klippy-requirements.txt - ok_msg "Dependencies already met or have been installed!" + ### check for possible new dependencies and install them + if [[ $(md5sum $KLIPPER_DIR/scripts/klippy-requirements.txt | cut -d " " -f1) != $KLIPPER_OLDREQ_MD5SUM ]]; then + PYTHONDIR="${HOME}/klippy-env" + status_msg "New dependecies detected..." + + ### always rebuild the pythondir from scratch if new dependencies were detected + rm -rf ${PYTHONDIR} + virtualenv -p python2 ${PYTHONDIR} + $PYTHONDIR/bin/pip install -r $KLIPPER_DIR/scripts/klippy-requirements.txt + ok_msg "Dependencies have been installed!" + fi + ok_msg "Update complete!" fi - klipper_service "start" + klipper_service "restart" } update_dwc2fk(){ @@ -116,51 +125,27 @@ update_fluidd(){ update_moonraker(){ bb4u "moonraker" status_msg "Updating Moonraker ..." - while true; do - echo - top_border - echo -e "| You can now choose how you want to update Moonraker. |" - blank_line - echo -e "| Changes made to the Moonraker code and/or its depen- |" - echo -e "| dencies might require a rebuild of the python virtual |" - echo -e "| environment or downloading of additional packages. |" - blank_line - echo -e "| ${red}Check the docs in the Moonraker repository to see if${default} |" - echo -e "| ${red}rebuilding is necessary (user_changes.md)!${default} |" - blank_line - echo -e "| 1) Update Moonraker (default) |" - echo -e "| 2) Update Moonraker + rebuild virtualenv/dependencies |" - quit_footer - read -p "${cyan}###### Please choose:${default} " action - case "$action" in - 1|"") - echo -e "###### > Update Moonraker" - update_mr="true" && rebuild_env="false" - break;; - 2) - echo -e "###### > Update Moonraker + rebuild virtualenv/dependencies" - update_mr="true" && rebuild_env="true" - break;; - Q|q) - clear; update_menu; break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done - stop_moonraker; echo - if [[ $update_mr = "true" ]] && [[ $rebuild_env = "false" ]]; then - unset update_mr && unset rebuild_env - cd $MOONRAKER_DIR && git pull + moonraker_service "stop"; echo + cd $MOONRAKER_DIR + MOONRAKER_OLDREQ_MD5SUM=$(md5sum $MOONRAKER_DIR/scripts/moonraker-requirements.txt | cut -d " " -f1) + + ### pull latest files from github + git pull && ok_msg "Update successfull!" + + ### check for possible new dependencies and install them + if [[ $(md5sum $MOONRAKER_DIR/scripts/moonraker-requirements.txt | cut -d " " -f1) != $MOONRAKER_OLDREQ_MD5SUM ]]; then + PYTHONDIR="${HOME}/moonraker-env" + status_msg "New dependecies detected..." + ### always rebuild the pythondir from scratch if new dependencies were detected + rm -rf ${PYTHONDIR} + virtualenv -p /usr/bin/python3 ${PYTHONDIR} + ln -s /usr/lib/python3/dist-packages/gpiod* ${PYTHONDIR}/lib/python*/site-packages + ${PYTHONDIR}/bin/pip install -r $MOONRAKER_DIR/scripts/moonraker-requirements.txt + ok_msg "Dependencies have been installed!" fi - if [[ $update_mr = "true" ]] && [[ $rebuild_env = "true" ]]; then - unset update_mr && unset rebuild_env - cd $MOONRAKER_DIR && git pull && ./scripts/install-moonraker.sh -r - fi - #read printer.cfg location and patch /etc/default/klipper if entries don't match - locate_printer_cfg && patch_klipper_sysfile + ok_msg "Update complete!" - restart_moonraker + moonraker_service "restart" } update_klipperscreen(){ From 2a29716bb9792aabe215c1b299abc9c76741a5b7 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 8 Jan 2021 20:02:18 +0100 Subject: [PATCH 09/97] fix: make mcu ids verbose again for easier copy pasting into configs --- scripts/install_klipper.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/install_klipper.sh b/scripts/install_klipper.sh index 3f5752f..02ff4a7 100755 --- a/scripts/install_klipper.sh +++ b/scripts/install_klipper.sh @@ -243,8 +243,6 @@ flash_mcu(){ ### list all mcus i=1 for mcu in ${mcu_list[@]}; do - ### rewrite mcu to cut off everything except the important stuff - mcu=$(echo $mcu | rev | cut -d"/" -f1 | rev) echo -e "$i) ${cyan}$mcu${default}" i=$(expr $i + 1) done @@ -322,8 +320,6 @@ get_mcu_id(){ declare "mcu_id_$mcu_count"="$mcu" mcu_id="mcu_id_$mcu_count" mcu_list+=("${!mcu_id}") - ### rewrite mcu to cut off everything except the important stuff - mcu=$(echo $mcu | rev | cut -d"/" -f1 | rev) echo " ● MCU #$mcu_count: ${cyan}$mcu${default}" mcu_count=$(expr $mcu_count + 1) done From 7dc1bc6cc8f945ed1b8a607af19ad87271f8e6a0 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 8 Jan 2021 20:02:58 +0100 Subject: [PATCH 10/97] fix: add full range of local network to auto-created moonraker.conf files --- scripts/install_moonraker.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index 32ccdaf..e663fed 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -240,6 +240,7 @@ moonraker_conf_creation(){ create_single_moonraker_conf(){ HOSTNAME=$(hostname -I | cut -d" " -f1) + LOCAL_NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-3).0/24" /bin/sh -c "cat > $MOONRAKER_CONF_LOC/moonraker.conf" << MOONRAKERCONF [server] @@ -254,6 +255,7 @@ enabled: True api_key_file: ~/.moonraker_api_key trusted_clients: 127.0.0.1 + $LOCAL_NETWORK cors_domains: http://*.local http://app.fluidd.xyz @@ -268,6 +270,7 @@ MOONRAKERCONF create_multi_moonraker_conf(){ HOSTNAME=$(hostname -I | cut -d" " -f1) + NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-3).0/24" /bin/sh -c "cat > $MOONRAKER_CONF_LOC/moonraker-$INSTANCE.conf" << MOONRAKERCONF [server] @@ -282,7 +285,7 @@ enabled: True api_key_file: ~/.moonraker_api_key trusted_clients: 127.0.0.1 - $HOSTNAME + $LOCAL_NETWORK cors_domains: http://*.local http://app.fluidd.xyz From f782a32e9c3ba4c3fbbe32ead12ae80b42db5d0a Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 9 Jan 2021 16:08:29 +0100 Subject: [PATCH 11/97] fix: bug in assigning correct port to instances --- scripts/install_moonraker.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index e663fed..95938b3 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -204,7 +204,7 @@ create_multi_moonraker_instance(){ moonraker_conf_creation(){ ### default moonraker port - PORT=7125 + DEFAULT_PORT=7125 ### get printer and moonraker config directory source_kiauh_ini @@ -227,7 +227,7 @@ moonraker_conf_creation(){ 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) + PORT=$(expr $DEFAULT_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'!" @@ -260,7 +260,7 @@ cors_domains: http://*.local http://app.fluidd.xyz https://app.fluidd.xyz - http://$HOSTNAME:* + http://$HOSTNAME [update_manager] #client_repo: @@ -290,7 +290,7 @@ cors_domains: http://*.local http://app.fluidd.xyz https://app.fluidd.xyz - http://$HOSTNAME:* + http://$HOSTNAME [update_manager] #client_repo: From 1ab681e71acc99e5f98d266cb9267e36648faa00 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 9 Jan 2021 16:49:10 +0100 Subject: [PATCH 12/97] fix: enable python3 check again, display moonraker IP at the end of the setup --- scripts/install_moonraker.sh | 74 ++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 16 deletions(-) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index 95938b3..1fac67d 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -3,7 +3,26 @@ SYSTEMDDIR="/etc/systemd/system" MOONRAKER_ENV="${HOME}/moonraker-env" MOONRAKER_DIR="${HOME}/moonraker" +python3_check(){ + status_msg "Your Python 3 version is: $(python3 --version)" + major=$(python3 --version | cut -d" " -f2 | cut -d"." -f1) + minor=$(python3 --version | cut -d"." -f2) + if [ $major -ge 3 ] && [ $minor -ge 7 ]; then + ok_msg "Python version ok!" + py_chk_ok="true" + else + warn_msg "Python version not ok!" + py_chk_ok="false" + fi +} + moonraker_setup_dialog(){ + ### check system for python3 before initializing the moonraker installation + python3_check + if [ $py_chk_ok = "false" ]; then + return 0 + fi + status_msg "Initializing Moonraker installation ..." ### check for existing moonraker service installations @@ -152,6 +171,14 @@ moonraker_setup(){ fi } +print_ip_list(){ + i=1 + for ip in ${ip_list[@]}; do + echo -e " ${cyan}● Instance $i:${default} $ip" + i=$((i + 1)) + done +} + create_single_moonraker_instance(){ status_msg "Setting up 1 Moonraker instance ..." @@ -173,7 +200,10 @@ create_single_moonraker_instance(){ sudo systemctl start moonraker ### confirm message - ok_msg "Single Moonraker instance has been set up!\n" + ok_msg "Single Moonraker instance has been set up!" + + ### display moonraker ip to the user + print_ip_list; echo } create_multi_moonraker_instance(){ @@ -199,7 +229,11 @@ create_multi_moonraker_instance(){ INSTANCE=$(expr $INSTANCE + 1) done ### confirm message - ok_msg "$INSTANCE_COUNT Moonraker instances have been set up!\n" + echo; echo; + ok_msg "$INSTANCE_COUNT Moonraker instances have been set up!" + + ### display all moonraker ips to the user + print_ip_list; echo } moonraker_conf_creation(){ @@ -214,8 +248,18 @@ moonraker_conf_creation(){ ### reset instances back to 1 again INSTANCE=1 - ### create moonraker.conf + ### declare empty array for ips which get displayed to the user at the end of the setup + HOSTNAME=$(hostname -I | cut -d" " -f1) + ip_list=() + + ### create single instance moonraker.conf file if [ $INSTANCE_COUNT -eq $INSTANCE ]; then + ### set port + PORT=$DEFAULT_PORT + + ### write the ip and port to the ip list for displaying it later to the user + ip_list+=("$HOSTNAME:$PORT") + 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!" @@ -223,16 +267,26 @@ moonraker_conf_creation(){ warn_msg "There is already a file called 'moonraker.conf'!" warn_msg "Skipping..." fi + + ### create multi instance moonraker.conf files else while [ $INSTANCE -le $INSTANCE_COUNT ]; do + ### set each instance to its own port + PORT=$(expr $DEFAULT_PORT + $INSTANCE - 1) + + ### write the ip and port to the ip list for displaying it later to the user + ip_list+=("$HOSTNAME:$PORT") + + ### start the creation of each instance status_msg "Creating moonraker-$INSTANCE.conf in $MOONRAKER_CONF_LOC" if [ ! -f $MOONRAKER_CONF_LOC/moonraker-$INSTANCE.conf ]; then - PORT=$(expr $DEFAULT_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 + + ### raise instance counter by 1 INSTANCE=$(expr $INSTANCE + 1) done fi @@ -342,18 +396,6 @@ install_moonraker(){ fi } -python3_check(){ - status_msg "Your Python 3 version is: $(python3 --version)" - major=$(python3 --version | cut -d" " -f2 | cut -d"." -f1) - minor=$(python3 --version | cut -d"." -f2) - if [ $major -ge 3 ] && [ $minor -ge 7 ]; then - ok_msg "Python version ok!" - py_chk_ok="true" - else - py_chk_ok="false" - fi -} - system_check_moonraker(){ status_msg "Initializing Moonraker installation ..." #check for existing printer.cfg and for the location From d066999d0b810aa3560a17f49cc88f2c2d849cd6 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 9 Jan 2021 18:02:59 +0100 Subject: [PATCH 13/97] fix: little UI fixes --- scripts/ui/install_menu.sh | 2 +- scripts/ui/remove_menu.sh | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index 0cf1108..2acfede 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -12,7 +12,7 @@ install_ui(){ echo -e "| Klipper API: | 5) [Fluidd] | " echo -e "| 2) [Moonraker] | 6) [Octoprint] | " echo -e "| | | " - echo -e "| | HDMI Screen | " + echo -e "| | HDMI Screen: | " echo -e "| | 7) [KlipperScreen] | " quit_footer } diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh index 10688a9..18ba834 100755 --- a/scripts/ui/remove_menu.sh +++ b/scripts/ui/remove_menu.sh @@ -2,8 +2,7 @@ remove_ui(){ top_border echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${default} | " hr - echo -e "| Files and directories which remain untouched: | " - echo -e "| --> ~/printer.cfg | " + echo -e "| Directories which remain untouched: | " echo -e "| --> ~/klipper_config | " echo -e "| --> ~/kiauh-backups | " echo -e "| You need remove them manually if you wish so. | " From 9ea29bf995ef4d5b324084c4dce7ec7f19ff27de Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 9 Jan 2021 23:17:45 +0100 Subject: [PATCH 14/97] fix: introduce new/better folder structure for multi instance setups --- scripts/install_klipper.sh | 53 +++++++++++++++++++++++++++++------- scripts/install_moonraker.sh | 47 +++++++++++++++----------------- 2 files changed, 65 insertions(+), 35 deletions(-) diff --git a/scripts/install_klipper.sh b/scripts/install_klipper.sh index 02ff4a7..48b56f2 100755 --- a/scripts/install_klipper.sh +++ b/scripts/install_klipper.sh @@ -76,7 +76,7 @@ create_klipper_virtualenv(){ create_single_klipper_startscript(){ ### create systemd service file -sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper.service" << EOF +sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper.service" << SINGLE_STARTSCRIPT #Systemd service file for klipper [Unit] Description=Starts klipper on startup @@ -90,12 +90,12 @@ 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 +SINGLE_STARTSCRIPT } create_multi_klipper_startscript(){ ### create multi instance systemd service file -sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper-$INSTANCE.service" << EOF +sudo /bin/sh -c "cat > $SYSTEMDDIR/klipper-$INSTANCE.service" << MULTI_STARTSCRIPT #Systemd service file for klipper [Unit] Description=Starts klipper instance $INSTANCE on startup @@ -109,7 +109,26 @@ 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 +MULTI_STARTSCRIPT +} + +create_minimal_printer_cfg(){ +/bin/sh -c "cat > $1" << MINIMAL_CFG +[mcu] +serial: /dev/serial/by-id/ +pin_map: arduino + +[pause_resume] +[display_status] + +[virtual_sdcard] +path: ~/gcode_files + +[printer] +kinematics: none +max_velocity: 1 +max_accel: 1 +MINIMAL_CFG } klipper_setup(){ @@ -129,9 +148,9 @@ klipper_setup(){ install_klipper_packages create_klipper_virtualenv - ### create sdcard folder - [ ! -d ${HOME}/sdcard ] && mkdir -p ${HOME}/sdcard - ### create config folder + ### create shared gcode_files folder + [ ! -d ${HOME}/gcode_files ] && mkdir -p ${HOME}/gcode_files + ### create shared config folder [ ! -d $PRINTER_CFG_LOC ] && mkdir -p $PRINTER_CFG_LOC ### create klipper instances @@ -155,6 +174,7 @@ create_single_klipper_instance(){ status_msg "Creating single Klipper instance ..." status_msg "Installing system start script ..." create_single_klipper_startscript + [ ! -f $PRINTER_CFG ] && create_minimal_printer_cfg "$PRINTER_CFG" ### enable instance sudo systemctl enable klipper.service @@ -165,7 +185,8 @@ create_single_klipper_instance(){ sudo systemctl start klipper ### confirm message - ok_msg "Single Klipper instance has been set up!\n" + CONFIRM_MSG="Single Klipper instance has been set up!" + print_msg && clear_msg } create_multi_klipper_instance(){ @@ -175,7 +196,11 @@ create_multi_klipper_instance(){ 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" + PRINTER_CFG="$PRINTER_CFG_LOC/printer_$INSTANCE/printer.cfg" + + ### create printer config folder and write a minimal printer.cfg to it + [ ! -d $PRINTER_CFG_LOC/printer_$INSTANCE ] && mkdir -p $PRINTER_CFG_LOC/printer_$INSTANCE + [ ! -f $PRINTER_CFG ] && create_minimal_printer_cfg "$PRINTER_CFG" ### create instance status_msg "Creating instance #$INSTANCE ..." @@ -192,10 +217,18 @@ create_multi_klipper_instance(){ ### instance counter +1 INSTANCE=$(expr $INSTANCE + 1) done + ### confirm message - ok_msg "$INSTANCE_COUNT Klipper instances have been set up!\n" + CONFIRM_MSG="$INSTANCE_COUNT Klipper instances have been set up!" + print_msg && clear_msg } + +############################################################################################## +#********************************************************************************************# +############################################################################################## + + flash_routine(){ echo top_border diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index 1fac67d..7df5f0f 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -20,7 +20,8 @@ moonraker_setup_dialog(){ ### check system for python3 before initializing the moonraker installation python3_check if [ $py_chk_ok = "false" ]; then - return 0 + ERROR_MSG="Python 3.7 or above required!\n Please upgrade your Python version first." + print_msg && clear_msg && return 0 fi status_msg "Initializing Moonraker installation ..." @@ -157,6 +158,7 @@ moonraker_setup(){ create_moonraker_virtualenv ### create moonraker.conf folder + ### athough it should already exist because its the same as the klipper config folder [ ! -d $MOONRAKER_CONF_LOC ] && mkdir -p $MOONRAKER_CONF_LOC ### create moonraker.confs @@ -200,7 +202,8 @@ create_single_moonraker_instance(){ sudo systemctl start moonraker ### confirm message - ok_msg "Single Moonraker instance has been set up!" + CONFIRM_MSG="Single Moonraker instance has been set up!" + print_msg && clear_msg ### display moonraker ip to the user print_ip_list; echo @@ -211,7 +214,7 @@ create_multi_moonraker_instance(){ while [ $INSTANCE -le $INSTANCE_COUNT ]; do ### multi instance variables MOONRAKER_LOG=/tmp/moonraker-$INSTANCE.log - MOONRAKER_CONF="$MOONRAKER_CONF_LOC/moonraker-$INSTANCE.conf" + MOONRAKER_CONF="$MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.conf" ### create instance status_msg "Creating instance #$INSTANCE ..." @@ -228,9 +231,10 @@ create_multi_moonraker_instance(){ ### instance counter +1 INSTANCE=$(expr $INSTANCE + 1) done + ### confirm message - echo; echo; - ok_msg "$INSTANCE_COUNT Moonraker instances have been set up!" + CONFIRM_MSG="$INSTANCE_COUNT Moonraker instances have been set up!" + print_msg && clear_msg ### display all moonraker ips to the user print_ip_list; echo @@ -278,9 +282,9 @@ moonraker_conf_creation(){ ip_list+=("$HOSTNAME:$PORT") ### start the creation of each instance - status_msg "Creating moonraker-$INSTANCE.conf in $MOONRAKER_CONF_LOC" - if [ ! -f $MOONRAKER_CONF_LOC/moonraker-$INSTANCE.conf ]; then - create_multi_moonraker_conf && ok_msg "moonraker-$INSTANCE.conf created!" + status_msg "Creating moonraker.conf for instance #$INSTANCE" + if [ ! -f $MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.conf ]; then + create_multi_moonraker_conf && ok_msg "moonraker.conf created!" else warn_msg "There is already a file called 'moonraker-$INSTANCE.conf'!" warn_msg "Skipping..." @@ -312,6 +316,8 @@ trusted_clients: $LOCAL_NETWORK cors_domains: http://*.local + http://my.mainsail.app + https://my.mainsail.app http://app.fluidd.xyz https://app.fluidd.xyz http://$HOSTNAME @@ -324,15 +330,15 @@ MOONRAKERCONF create_multi_moonraker_conf(){ HOSTNAME=$(hostname -I | cut -d" " -f1) - NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-3).0/24" + LOCAL_NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-3).0/24" -/bin/sh -c "cat > $MOONRAKER_CONF_LOC/moonraker-$INSTANCE.conf" << MOONRAKERCONF +/bin/sh -c "cat > $MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.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 +config_path: $PRINTER_CFG_LOC/printer_$INSTANCE [authorization] enabled: True @@ -342,6 +348,8 @@ trusted_clients: $LOCAL_NETWORK cors_domains: http://*.local + http://my.mainsail.app + https://my.mainsail.app http://app.fluidd.xyz https://app.fluidd.xyz http://$HOSTNAME @@ -353,20 +361,9 @@ MOONRAKERCONF } - - - - - - - - - - - - - - +############################################################################################## +#********************************************************************************************# +############################################################################################## install_moonraker(){ From b12d344b40f88a03acadbaa804e23ccfc13d7715 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 10 Jan 2021 12:55:24 +0100 Subject: [PATCH 15/97] fix: update the config folder change function (its more like a "rename only" function now and should be plenty sufficient?) --- scripts/functions.sh | 32 +++++++++++++++++--------------- scripts/ui/settings_menu.sh | 12 ++++++------ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index a91f9ae..81cdd99 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -43,13 +43,13 @@ change_klipper_cfg_path(){ Y|y|Yes|yes|"") echo -e "###### > Yes" + ### backup the old config dir + backup_klipper_config_dir + ### 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 @@ -67,17 +67,18 @@ change_klipper_cfg_path(){ } ###? 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. +###? and set the new path. after that, rename the old folder and reload service units. +###! users shouldn't try and move the files into subfolders with this function! as the mv command will fail +###! but the new path still gets written to the service files. if they really need to, they need to move all +###! config files or printer folder into that subfolder (still not recommended!) 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!" + ### rename the klipper config folder + if [ ! -z "$old_klipper_cfg_loc" ] && [ -d "$old_klipper_cfg_loc" ]; then + status_msg "Renaming '$old_klipper_cfg_loc' to '$new_klipper_cfg_loc'!"; echo + mv -v "$old_klipper_cfg_loc" "$new_klipper_cfg_loc" && ok_msg "Done!" fi ### handle single klipper instance service file @@ -90,7 +91,7 @@ set_klipper_cfg_path(){ if ls /etc/systemd/system/klipper-*.service 2>/dev/null 1>&2; 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 + sudo sed -i "/ExecStart=/ s|$old_klipper_cfg_loc/printer_|$new_klipper_cfg_loc/printer_|" $service done ok_msg "OK!" fi @@ -107,11 +108,12 @@ set_klipper_cfg_path(){ if ls /etc/systemd/system/moonraker-*.service 2>/dev/null 1>&2; 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 + sudo sed -i "/ExecStart=/ s|$old_klipper_cfg_loc/printer_|$new_klipper_cfg_loc/printer_|" $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 + ### 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) + sed -i "/config_path:/ s|config_path:.*|config_path: $loc|" $moonraker_conf done ok_msg "OK!" fi diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index 5cfe060..3b07f0f 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -5,18 +5,18 @@ settings_ui(){ 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. | " + echo -e "| When you rename the config folder, be aware that ALL | " + echo -e "| Klipper and Moonraker services will be STOPPED, | " + echo -e "| reconfigured and then restarted again. | " blank_line - echo -e "| ${red}DO NOT change the folder location during printing!${default} | " + echo -e "| ${red}DO NOT rename the folder during printing!${default} | " hr blank_line - echo -e "| ${yellow}● Current Klipper configuration folder:${default} | " + echo -e "| ${yellow}● Current Klipper config folder:${default} | " printf "|%-55s|\n" " $klipper_cfg_loc" blank_line hr - echo -e "| 1) Change configuration folder | " + echo -e "| 1) Rename config folder | " quit_footer } From bd78fa8ef7de78b6d0d50138d0fa5f6521da2ca2 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 10 Jan 2021 13:05:58 +0100 Subject: [PATCH 16/97] add: quick and simple solution to start, stop, restart klipper/moonraker from within the main menu --- scripts/ui/main_menu.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 5d10ebd..b378ced 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -43,6 +43,36 @@ main_menu(){ while true; do read -p "${cyan}Perform action:${default} " action; echo case "$action" in + "start klipper") + clear + print_header + klipper_service "start" + main_ui;; + "stop klipper") + clear + print_header + klipper_service "stop" + main_ui;; + "restart klipper") + clear + print_header + klipper_service "restart" + main_ui;; + "start moonraker") + clear + print_header + moonraker_service "start" + main_ui;; + "stop moonraker") + clear + print_header + moonraker_service "stop" + main_ui;; + "restart moonraker") + clear + print_header + moonraker_service "restart" + main_ui;; update) clear print_header From 146586f89454dae01236153ade20cc2f6e75cf6f Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 13 Jan 2021 18:04:36 +0100 Subject: [PATCH 17/97] fix: correct mjpgstreamer port --- resources/moonraker_nginx.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/moonraker_nginx.cfg b/resources/moonraker_nginx.cfg index c868181..dfd1ea2 100644 --- a/resources/moonraker_nginx.cfg +++ b/resources/moonraker_nginx.cfg @@ -9,5 +9,5 @@ upstream apiserver { upstream mjpgstreamer { #edit your webcam port here ip_hash; - server 127.0.0.1:8081; + server 127.0.0.1:8080; } \ No newline at end of file From 715ab5f4e2b9f4d3b04e762cb47f8f0b8d8ea950 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 15 Jan 2021 17:50:43 +0100 Subject: [PATCH 18/97] fix: display instance count in main menu status --- scripts/status.sh | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/scripts/status.sh b/scripts/status.sh index c5153f6..d5b8ecb 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -17,19 +17,29 @@ klipper_status(){ $KLIPPER_DIR $KLIPPY_ENV_DIR ) - #remove the "SERVICE" entry from the klipper_data array if a klipper service is installed + ### remove the "SERVICE" entry from the klipper_data array if a klipper service is installed 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 + + ### count+1 for each found data-item from array for kd in "${klipper_data[@]}" do if [ -e $kd ]; then kcount=$(expr $kcount + 1) fi done + + ### count amount of klipper services + if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then + instances=1 + else + instances=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l) + fi + + ### display status if [ "$kcount" == "${#klipper_data[*]}" ]; then - KLIPPER_STATUS="${green}Installed!${default} " + KLIPPER_STATUS="$(printf "${green}Installed: %-5s${default}" $instances)" elif [ "$kcount" == 0 ]; then KLIPPER_STATUS="${red}Not installed!${default} " else @@ -71,15 +81,25 @@ moonraker_status(){ 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 + + ### count+1 for each found data-item from array for mrd in "${moonraker_data[@]}" do if [ -e $mrd ]; then mrcount=$(expr $mrcount + 1) fi done + + ### count amount of moonraker services + if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then + instances=1 + else + instances=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l) + fi + + ### display status if [ "$mrcount" == "${#moonraker_data[*]}" ]; then - MOONRAKER_STATUS="${green}Installed!${default} " + MOONRAKER_STATUS="$(printf "${green}Installed: %-5s${default}" $instances)" elif [ "$mrcount" == 0 ]; then MOONRAKER_STATUS="${red}Not installed!${default} " else From 4d2eb49e85a005eec30871700f88b235f8f84fda Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 15 Jan 2021 17:52:04 +0100 Subject: [PATCH 19/97] fix: big refactoring of the moonraker installer --- scripts/install_moonraker.sh | 873 ++++++++++++++--------------------- 1 file changed, 336 insertions(+), 537 deletions(-) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index 7df5f0f..e0f51f7 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -1,9 +1,14 @@ +############################################################################################## +#********************************************************************************************# +############################################################################################## + ### base variables SYSTEMDDIR="/etc/systemd/system" MOONRAKER_ENV="${HOME}/moonraker-env" MOONRAKER_DIR="${HOME}/moonraker" -python3_check(){ +system_check_moonraker(){ + ### python 3 check status_msg "Your Python 3 version is: $(python3 --version)" major=$(python3 --version | cut -d" " -f2 | cut -d"." -f1) minor=$(python3 --version | cut -d"." -f2) @@ -14,18 +19,37 @@ python3_check(){ warn_msg "Python version not ok!" py_chk_ok="false" fi + + ### check system for an installed octoprint service + if systemctl is-enabled octoprint.service -q 2>/dev/null; then + OCTOPRINT_ENABLED="true" + fi + + ### check system for an installed haproxy service + if [[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]]; then + HAPROXY_FOUND="true" + fi + + ### check system for an installed lighttpd service + if [[ $(dpkg-query -f'${Status}' --show lighttpd 2>/dev/null) = *\ installed ]]; then + LIGHTTPD_FOUND="true" + fi + } +### check the users linux system moonraker_setup_dialog(){ - ### check system for python3 before initializing the moonraker installation - python3_check + status_msg "Initializing Moonraker installation ..." + + ### check system for several requirements before initializing the moonraker installation + system_check_moonraker + + ### exit moonraker setup if python version is not ok if [ $py_chk_ok = "false" ]; then ERROR_MSG="Python 3.7 or above required!\n Please upgrade your Python version first." print_msg && clear_msg && return 0 fi - 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 @@ -46,11 +70,19 @@ moonraker_setup_dialog(){ ### initial moonraker.conf path check check_klipper_cfg_path - ### ask for amount of instances to create + ### ask user how to handle OctoPrint, Haproxy and Lighttpd + process_octoprint_dialog + process_haproxy_lighttpd_dialog + + ### instance confirmation dialog while true; do echo top_border - printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!" + if [ $INSTANCE_COUNT -gt 1 ]; then + printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!" + else + echo -e "| 1 Klipper instance was found! | " + fi echo -e "| You need one Moonraker instance per Klipper instance. | " bottom_border echo @@ -73,6 +105,46 @@ moonraker_setup_dialog(){ done } +moonraker_setup(){ + ### get printer config directory + source_kiauh_ini + MOONRAKER_CONF_LOC="$klipper_cfg_loc" + + ### step 1: clone moonraker + status_msg "Downloading Moonraker ..." + ### force remove existing moonraker dir and clone into fresh moonraker dir + [ -d $MOONRAKER_DIR ] && rm -rf $MOONRAKER_DIR + cd ${HOME} && git clone $MOONRAKER_REPO + status_msg "Download complete!" + + ### step 2: install moonraker dependencies and create python virtualenv + status_msg "Installing dependencies ..." + install_moonraker_packages + create_moonraker_virtualenv + + ### step 3: create moonraker.conf folder and moonraker.confs + [ ! -d $MOONRAKER_CONF_LOC ] && mkdir -p $MOONRAKER_CONF_LOC + moonraker_conf_creation + + ### step 4: set up moonrakers nginx configs + setup_moonraker_nginx_cfg + + ### step 5: process possible disruptive services + process_haproxy_lighttpd_services + + ### step 6: create final moonraker instances + INSTANCE=1 + if [ $INSTANCE_COUNT -eq $INSTANCE ]; then + create_single_moonraker_instance + else + create_multi_moonraker_instance + fi +} + +############################################################################################## +#********************************************************************************************# +############################################################################################## + install_moonraker_packages(){ PKGLIST="python3-virtualenv python3-dev nginx libopenjp2-7 python3-libgpiod" @@ -138,41 +210,74 @@ RestartSec=10 EOF } -moonraker_setup(){ - ### get printer config directory - source_kiauh_ini - MOONRAKER_CONF_LOC="$klipper_cfg_loc" +create_single_moonraker_conf(){ + HOSTNAME=$(hostname -I | cut -d" " -f1) + LOCAL_NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-3).0/24" - ### clone moonraker - status_msg "Downloading Moonraker ..." - ### force remove existing moonraker dir - [ -d $MOONRAKER_DIR ] && rm -rf $MOONRAKER_DIR +/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 - ### clone into fresh moonraker dir - cd ${HOME} && git clone $MOONRAKER_REPO - status_msg "Download complete!" +[authorization] +enabled: True +api_key_file: ~/.moonraker_api_key +trusted_clients: + 127.0.0.1 + $LOCAL_NETWORK +cors_domains: + http://*.local + http://my.mainsail.app + https://my.mainsail.app + http://app.fluidd.xyz + https://app.fluidd.xyz + http://$HOSTNAME - ### install klipper dependencies and create python virtualenv - status_msg "Installing dependencies ..." - install_moonraker_packages - create_moonraker_virtualenv - - ### create moonraker.conf folder - ### athough it should already exist because its the same as the klipper config 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 +[update_manager] +#client_repo: +#client_path: +MOONRAKERCONF } +create_multi_moonraker_conf(){ + HOSTNAME=$(hostname -I | cut -d" " -f1) + LOCAL_NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-3).0/24" + +/bin/sh -c "cat > $MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.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/printer_$INSTANCE + +[authorization] +enabled: True +api_key_file: ~/.moonraker_api_key +trusted_clients: + 127.0.0.1 + $LOCAL_NETWORK +cors_domains: + http://*.local + http://my.mainsail.app + https://my.mainsail.app + http://app.fluidd.xyz + https://app.fluidd.xyz + http://$HOSTNAME + +[update_manager] +#client_repo: +#client_path: +MOONRAKERCONF +} + +############################################################################################## +#********************************************************************************************# +############################################################################################## + print_ip_list(){ i=1 for ip in ${ip_list[@]}; do @@ -240,6 +345,22 @@ create_multi_moonraker_instance(){ print_ip_list; echo } +setup_moonraker_nginx_cfg(){ + get_date + + ### backup existing nginx configs + [ -f $NGINX_CONFD/upstreams.conf ] && sudo mv $NGINX_CONFD/upstreams.conf $NGINX_CONFD/$current_date_upstreams.conf + [ -f $NGINX_CONFD/common_vars.conf ] && sudo mv $NGINX_CONFD/common_vars.conf $NGINX_CONFD/$current_date_common_vars.conf + + ### copy nginx configs to target destination + if [ ! -f $NGINX_CONFD/upstreams.conf ]; then + sudo cp ${SRCDIR}/kiauh/resources/moonraker_nginx.cfg $NGINX_CONFD/upstreams.conf + fi + if [ ! -f $NGINX_CONFD/common_vars.conf ]; then + sudo cp ${SRCDIR}/kiauh/resources/common_vars_nginx.cfg $NGINX_CONFD/common_vars.conf + fi +} + moonraker_conf_creation(){ ### default moonraker port DEFAULT_PORT=7125 @@ -296,249 +417,59 @@ moonraker_conf_creation(){ fi } -create_single_moonraker_conf(){ - HOSTNAME=$(hostname -I | cut -d" " -f1) - LOCAL_NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-3).0/24" - -/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 - $LOCAL_NETWORK -cors_domains: - http://*.local - http://my.mainsail.app - https://my.mainsail.app - 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) - LOCAL_NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-3).0/24" - -/bin/sh -c "cat > $MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.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/printer_$INSTANCE - -[authorization] -enabled: True -api_key_file: ~/.moonraker_api_key -trusted_clients: - 127.0.0.1 - $LOCAL_NETWORK -cors_domains: - http://*.local - http://my.mainsail.app - https://my.mainsail.app - http://app.fluidd.xyz - https://app.fluidd.xyz - http://$HOSTNAME - -[update_manager] -#client_repo: -#client_path: -MOONRAKERCONF -} - - ############################################################################################## #********************************************************************************************# ############################################################################################## +# add_trusted_clients_dialog(){ +# #ask user for more trusted clients +# while true; do +# echo +# top_border +# echo -e "| Apart from devices of your local network, you can add |" +# echo -e "| additional trusted clients to the moonraker.conf file |" +# bottom_border +# read -p "${cyan}###### Add additional trusted clients? (y/N):${default} " yn +# case "$yn" in +# Y|y|Yes|yes) +# echo -e "###### > Yes" +# ADD_TRUSTED_CLIENT="true" +# custom_trusted_clients +# break;; +# N|n|No|no|"") +# echo -e "###### > No" +# ADD_TRUSTED_CLIENT="false" +# break;; +# *) +# print_unkown_cmd +# print_msg && clear_msg;; +# esac +# done +# } -install_moonraker(){ - python3_check - if [ $py_chk_ok = "true" ]; then - system_check_moonraker - #ask user for customization - get_user_selections_moonraker - #disable/remove haproxy/lighttpd - handle_haproxy_lighttpd - #moonraker main installation - moonraker_setup - check_for_folder_moonraker - #setup configs - setup_printer_config_moonraker - setup_moonraker_conf - #execute customizations - write_custom_trusted_clients - symlinks_moonraker - disable_octoprint - #after install actions - restart_moonraker - klipper_service "restart" - else - ERROR_MSG="Python 3.7 or above required!\n Please upgrade your Python version first." - print_msg && clear_msg - fi -} - -system_check_moonraker(){ - status_msg "Initializing Moonraker installation ..." - #check for existing printer.cfg and for the location - locate_printer_cfg - if [ -f $PRINTER_CFG ]; then - PRINTER_CFG_FOUND="true" - PRINTER_CFG_LOC=$PRINTER_CFG - else - PRINTER_CFG_FOUND="false" - fi - #check for existing klippy.log symlink in /klipper_config - [ ! -e ${HOME}/klipper_config/klippy.log ] && KLIPPY_SL_FOUND="false" - #check for existing moonraker.log symlink in /klipper_config - [ ! -e ${HOME}/klipper_config/moonraker.log ] && MOONRAKER_SL_FOUND="false" - #check for existing moonraker.conf - if [ ! -f ${HOME}/moonraker.conf ]; then - MOONRAKER_CONF_FOUND="false" - else - MOONRAKER_CONF_FOUND="true" - fi - #check if octoprint is installed - if systemctl is-enabled octoprint.service -q 2>/dev/null; then - unset OCTOPRINT_ENABLED - OCTOPRINT_ENABLED="true" - fi - #check if haproxy is installed - if [[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]]; then - HAPROXY_FOUND="true" - fi - #check if lighttpd is installed - if [[ $(dpkg-query -f'${Status}' --show lighttpd 2>/dev/null) = *\ installed ]]; then - LIGHTTPD_FOUND="true" - fi -} - -get_user_selections_moonraker(){ - #user selection for printer.cfg - if [ "$PRINTER_CFG_FOUND" = "false" ]; then - while true; do - echo - top_border - echo -e "| ${red}WARNING! - No printer.cfg was found!${default} |" - hr - echo -e "| KIAUH can create a minimal printer.cfg with only the |" - echo -e "| recommended Moonraker config entries if you wish. |" - echo -e "| |" - echo -e "| Please be aware, that this option will ${red}NOT${default} create a |" - echo -e "| fully working printer.cfg for you! |" - bottom_border - read -p "${cyan}###### Create a default printer.cfg? (Y/n):${default} " yn - case "$yn" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - SEL_DEF_CFG="true" - break;; - N|n|No|no) - echo -e "###### > No" - SEL_DEF_CFG="false" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done - fi - #user selection for moonraker.log symlink - if [ "$KLIPPY_SL_FOUND" = "false" ]; then - while true; do - echo - read -p "${cyan}###### Create klippy.log symlink? (y/N):${default} " yn - case "$yn" in - Y|y|Yes|yes) - echo -e "###### > Yes" - SEL_KLIPPYLOG_SL="true" - break;; - N|n|No|no|"") - echo -e "###### > No" - SEL_KLIPPYLOG_SL="false" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done - fi - #user selection for moonraker.log symlink - if [ "$MOONRAKER_SL_FOUND" = "false" ]; then - while true; do - echo - read -p "${cyan}###### Create moonraker.log symlink? (y/N):${default} " yn - case "$yn" in - Y|y|Yes|yes) - echo -e "###### > Yes" - SEL_MRLOG_SL="true" - break;; - N|n|No|no|"") - echo -e "###### > No" - SEL_MRLOG_SL="false" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done - fi - #ask user for more trusted clients - while true; do - echo - top_border - echo -e "| Apart from devices of your local network, you can add |" - echo -e "| additional trusted clients to the moonraker.conf file |" - bottom_border - read -p "${cyan}###### Add additional trusted clients? (y/N):${default} " yn - case "$yn" in - Y|y|Yes|yes) - echo -e "###### > Yes" - ADD_TRUSTED_CLIENT="true" - custom_trusted_clients - break;; - N|n|No|no|"") - echo -e "###### > No" - ADD_TRUSTED_CLIENT="false" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done - #ask user to disable octoprint when such installed service was found +process_octoprint_dialog(){ + #ask user to disable octoprint when its service was found if [ "$OCTOPRINT_ENABLED" = "true" ]; then - unset DISABLE_OPRINT while true; do echo - warn_msg "OctoPrint service found!" - echo -e "You might consider disabling the OctoPrint service," - echo -e "since an active OctoPrint service may lead to unexpected" - echo -e "behavior of the Mainsail Webinterface." + top_border + echo -e "| ${red}!!! WARNING - OctoPrint service found !!!${default} |" + hr + echo -e "| You might consider disabling the OctoPrint service, |" + echo -e "| since an active OctoPrint service may lead to unex- |" + echo -e "| pected behavior of the Klipper Webinterfaces. |" + bottom_border read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn case "$yn" in Y|y|Yes|yes|"") echo -e "###### > Yes" - DISABLE_OPRINT="true" + status_msg "Stopping OctoPrint ..." + sudo systemctl stop octoprint && ok_msg "OctoPrint service stopped!" + status_msg "Disabling OctoPrint ..." + sudo systemctl disable octoprint && ok_msg "OctoPrint service disabled!" break;; N|n|No|no) echo -e "###### > No" - DISABLE_OPRINT="false" break;; *) print_unkown_cmd @@ -546,6 +477,51 @@ get_user_selections_moonraker(){ esac done fi +} + +process_haproxy_lighttpd_services(){ + #handle haproxy service + if [ "$DISABLE_HAPROXY" = "true" ] || [ "$REMOVE_HAPROXY" = "true" ]; then + if systemctl is-active haproxy -q; then + status_msg "Stopping haproxy service ..." + sudo systemctl stop haproxy && ok_msg "Service stopped!" + fi + + ### disable haproxy + if [ "$DISABLE_HAPROXY" = "true" ]; then + status_msg "Disabling haproxy ..." + sudo systemctl disable haproxy && ok_msg "Haproxy service disabled!" + + ### remove haproxy + if [ "$REMOVE_HAPROXY" = "true" ]; then + status_msg "Removing haproxy ..." + sudo apt-get remove haproxy -y && sudo update-rc.d -f haproxy remove && ok_msg "Haproxy removed!" + fi + fi + fi + + ### handle lighttpd service + if [ "$DISABLE_LIGHTTPD" = "true" ] || [ "$REMOVE_LIGHTTPD" = "true" ]; then + if systemctl is-active lighttpd -q; then + status_msg "Stopping lighttpd service ..." + sudo systemctl stop lighttpd && ok_msg "Service stopped!" + fi + + ### disable lighttpd + if [ "$DISABLE_LIGHTTPD" = "true" ]; then + status_msg "Disabling lighttpd ..." + sudo systemctl disable lighttpd && ok_msg "Lighttpd service disabled!" + + ### remove lighttpd + if [ "$REMOVE_LIGHTTPD" = "true" ]; then + status_msg "Removing lighttpd ..." + sudo apt-get remove lighttpd -y && sudo update-rc.d -f lighttpd remove && ok_msg "Lighttpd removed!" + fi + fi + fi +} + +process_haproxy_lighttpd_dialog(){ #notify user about haproxy or lighttpd services found and possible issues if [ "$HAPROXY_FOUND" = "true" ] || [ "$LIGHTTPD_FOUND" = "true" ]; then while true; do @@ -572,11 +548,11 @@ get_user_selections_moonraker(){ 1) echo -e "###### > Remove packages" if [ "$HAPROXY_FOUND" = "true" ]; then - DISABLE_HAPROXY="false" + DISABLE_HAPROXY="true" REMOVE_HAPROXY="true" fi if [ "$LIGHTTPD_FOUND" = "true" ]; then - DISABLE_LIGHTTPD="false" + DISABLE_LIGHTTPD="true" REMOVE_LIGHTTPD="true" fi break;; @@ -593,10 +569,6 @@ get_user_selections_moonraker(){ break;; 3) echo -e "###### > Skip" - DISABLE_LIGHTTPD="false" - REMOVE_LIGHTTPD="false" - DISABLE_HAPROXY="false" - REMOVE_HAPROXY="false" break;; *) print_unkown_cmd @@ -604,277 +576,104 @@ get_user_selections_moonraker(){ esac done fi - status_msg "Installation will start now! Please wait ..." } ############################################################# ############################################################# -#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!" -#} +# setup_moonraker_conf(){ +# if [ "$MOONRAKER_CONF_FOUND" = "false" ]; then +# status_msg "Creating moonraker.conf ..." +# cp ${HOME}/kiauh/resources/moonraker.conf ${HOME} +# ok_msg "moonraker.conf created!" +# status_msg "Writing trusted clients to config ..." +# write_default_trusted_clients +# ok_msg "Trusted clients written!" +# fi +# #check for at least one trusted client in an already existing moonraker.conf +# #if no entry is found, write default trusted client +# if [ "$MOONRAKER_CONF_FOUND" = "true" ]; then +# if grep "trusted_clients:" ${HOME}/moonraker.conf -q; then +# TC_LINE=$(grep -n "trusted_clients:" ${HOME}/moonraker.conf | cut -d ":" -f1) +# FIRST_IP_LINE=$(expr $TC_LINE + 1) +# FIRST_IP=$(sed -n "$FIRST_IP_LINE"p ${HOME}/moonraker.conf | cut -d" " -f5) +# #if [[ ! $FIRST_IP =~ ([0-9].[0-9].[0-9].[0-9]) ]]; then +# if [ "$FIRST_IP" = "" ]; then +# status_msg "Writing trusted clients to config ..." +# backup_moonraker_conf && write_default_trusted_clients +# ok_msg "Trusted clients written!" +# fi +# fi +# fi +# } -patch_klipper_sysfile(){ - 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 - if [ "$1" = "moonraker" ]; then - if ! grep -q "/klipper_config/printer.cfg" $KLIPPER_SERVICE3; then - status_msg "Patching new printer.cfg location to /etc/systemd/system/klipper.service ..." - sudo sed -i "/ExecStart=/ s|$PRINTER_CFG|/home/${USER}/klipper_config/printer.cfg|" $KLIPPER_SERVICE3 - ok_msg "New location is: '/home/${USER}/klipper_config/printer.cfg'" - #set variable if file got edited - SERVICE_FILE_PATCHED="true" - fi - fi - #patching new UDS argument to /etc/systemd/system/klipper.service - if [ "$1" = "moonraker" ] || [ "$1" = "dwc2" ]; then - if ! grep -q -- "-a /tmp/klippy_uds" $KLIPPER_SERVICE3; then - status_msg "Patching unix domain socket to /etc/systemd/system/klipper.service ..." - #append the new argument to /tmp/klippy.log argument - sudo sed -i "/ExecStart/s/\.log/\.log -a \/tmp\/klippy_uds/" $KLIPPER_SERVICE3 - ok_msg "Patching done!" - #set variable if file got edited - SERVICE_FILE_PATCHED="true" - fi - fi - #reloading the units is only needed when the service file was patched. - [ "$SERVICE_FILE_PATCHED" = "true" ] && status_msg "Reloading unit ..." && sudo systemctl daemon-reload - fi - ok_msg "Check complete!" - echo -} +# ############################################################# +# ############################################################# -check_for_folder_moonraker(){ - #check for / create sdcard folder - if [ ! -d ${HOME}/sdcard ]; then - status_msg "Creating sdcard directory ..." - mkdir ${HOME}/sdcard - ok_msg "sdcard directory created!" - fi - ##check for / create klipper_config folder - if [ ! -d ${HOME}/klipper_config ]; then - status_msg "Creating klipper_config directory ..." - mkdir ${HOME}/klipper_config - ok_msg "klipper_config directory created!" - fi -} +# custom_trusted_clients(){ +# if [ "$ADD_TRUSTED_CLIENT" = "true" ]; then +# unset trusted_arr +# echo +# top_border +# echo -e "| You can now add additional trusted clients to your |" +# echo -e "| moonraker.conf file. Be warned, that there is no |" +# echo -e "| spellcheck to check for valid input. |" +# echo -e "| Make sure to type the IP correct! |" +# echo -e "| |" +# echo -e "| If you want to add IP ranges, you can type in e.g.: |" +# echo -e "| 192.168.1.0/24 |" +# echo -e "| This will add the IPs 192.168.1.1 to 192.168.1.254 |" +# echo -e "|-------------------------------------------------------|" +# echo -e "| You can add as many IPs / IP ranges as you want. |" +# echo -e "| When you are done type '${cyan}done${default}' to exit this dialoge. |" +# bottom_border +# while true; do +# read -p "${cyan}###### Enter IP and press ENTER:${default} " TRUSTED_IP +# case "$TRUSTED_IP" in +# done) +# echo +# echo -e "List of IPs to add:" +# for ip in ${trusted_arr[@]} +# do +# echo -e "${cyan}● $ip ${default}" +# done +# while true; do +# echo +# echo -e "Select 'Yes' to confirm, 'No' to start again" +# echo -e "or 'Q' to abort and skip." +# read -p "${cyan}###### Confirm writing (Y/n/q):${default} " yn +# case "$yn" in +# Y|y|Yes|yes|"") +# echo -e "###### > Yes" +# TUSTED_CLIENT_CONFIRM="true" +# break;; +# N|n|No|no) +# echo -e "###### > No" +# custom_trusted_clients +# break;; +# Q|q) +# unset trusted_arr +# echo -e "###### > Abort" +# echo -e "${red}Aborting ...${default}" +# break;; +# esac +# done +# break;; +# *) +# trusted_arr+=($TRUSTED_IP);; +# esac +# done +# fi +# } -############################################################# -############################################################# - -setup_printer_config_moonraker(){ - if [ "$PRINTER_CFG_FOUND" = "true" ]; then - #copy printer.cfg to new location if there is no printer.cfg at the new location already - if [ -f ${HOME}/printer.cfg ] && [ ! -f ${HOME}/klipper_config/printer.cfg ]; then - status_msg "Copy printer.cfg to new location ..." - cp ${HOME}/printer.cfg $PRINTER_CFG - ok_msg "printer.cfg location: '$PRINTER_CFG'" - ok_msg "Done!" - fi - #check printer.cfg for necessary moonraker entries - read_printer_cfg "moonraker" && write_printer_cfg - fi - if [ "$SEL_DEF_CFG" = "true" ]; then - status_msg "Creating minimal default printer.cfg ..." - create_minimal_cfg - ok_msg "printer.cfg location: '$PRINTER_CFG'" - ok_msg "Done!" - fi -} - -setup_moonraker_conf(){ - if [ "$MOONRAKER_CONF_FOUND" = "false" ]; then - status_msg "Creating moonraker.conf ..." - cp ${HOME}/kiauh/resources/moonraker.conf ${HOME} - ok_msg "moonraker.conf created!" - status_msg "Writing trusted clients to config ..." - write_default_trusted_clients - ok_msg "Trusted clients written!" - fi - #check for at least one trusted client in an already existing moonraker.conf - #if no entry is found, write default trusted client - if [ "$MOONRAKER_CONF_FOUND" = "true" ]; then - if grep "trusted_clients:" ${HOME}/moonraker.conf -q; then - TC_LINE=$(grep -n "trusted_clients:" ${HOME}/moonraker.conf | cut -d ":" -f1) - FIRST_IP_LINE=$(expr $TC_LINE + 1) - FIRST_IP=$(sed -n "$FIRST_IP_LINE"p ${HOME}/moonraker.conf | cut -d" " -f5) - #if [[ ! $FIRST_IP =~ ([0-9].[0-9].[0-9].[0-9]) ]]; then - if [ "$FIRST_IP" = "" ]; then - status_msg "Writing trusted clients to config ..." - backup_moonraker_conf && write_default_trusted_clients - ok_msg "Trusted clients written!" - fi - fi - fi -} - -setup_moonraker_nginx_cfg(){ - if [ ! -f $NGINX_CONFD/upstreams.conf ]; then - sudo cp ${SRCDIR}/kiauh/resources/moonraker_nginx.cfg $NGINX_CONFD/upstreams.conf - fi - if [ ! -f $NGINX_CONFD/common_vars.conf ]; then - sudo cp ${SRCDIR}/kiauh/resources/common_vars_nginx.cfg $NGINX_CONFD/common_vars.conf - fi -} - -############################################################# -############################################################# - -write_default_trusted_clients(){ - DEFAULT_IP=$(hostname -I) - status_msg "Your devices current IP adress is:\n${cyan}● $DEFAULT_IP ${default}" - #make IP of the device KIAUH is exectuted on as - #default trusted client and expand the IP range from 0 - 255 - DEFAULT_IP_RANGE="$(echo "$DEFAULT_IP" | cut -d"." -f1-3).0/24" - status_msg "Writing the following IP range to moonraker.conf:\n${cyan}● $DEFAULT_IP_RANGE ${default}" - #write the ip range in the first line below "trusted clients" - #example: 192.168.1.0/24 - sed -i "/trusted_clients\:/a \ \ \ \ $DEFAULT_IP_RANGE" ${HOME}/moonraker.conf - ok_msg "IP range of ● $DEFAULT_IP_RANGE written to moonraker.conf!" -} - -############################################################# -############################################################# - -custom_trusted_clients(){ - if [ "$ADD_TRUSTED_CLIENT" = "true" ]; then - unset trusted_arr - echo - top_border - echo -e "| You can now add additional trusted clients to your |" - echo -e "| moonraker.conf file. Be warned, that there is no |" - echo -e "| spellcheck to check for valid input. |" - echo -e "| Make sure to type the IP correct! |" - echo -e "| |" - echo -e "| If you want to add IP ranges, you can type in e.g.: |" - echo -e "| 192.168.1.0/24 |" - echo -e "| This will add the IPs 192.168.1.1 to 192.168.1.254 |" - echo -e "|-------------------------------------------------------|" - echo -e "| You can add as many IPs / IP ranges as you want. |" - echo -e "| When you are done type '${cyan}done${default}' to exit this dialoge. |" - bottom_border - while true; do - read -p "${cyan}###### Enter IP and press ENTER:${default} " TRUSTED_IP - case "$TRUSTED_IP" in - done) - echo - echo -e "List of IPs to add:" - for ip in ${trusted_arr[@]} - do - echo -e "${cyan}● $ip ${default}" - done - while true; do - echo - echo -e "Select 'Yes' to confirm, 'No' to start again" - echo -e "or 'Q' to abort and skip." - read -p "${cyan}###### Confirm writing (Y/n/q):${default} " yn - case "$yn" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - TUSTED_CLIENT_CONFIRM="true" - break;; - N|n|No|no) - echo -e "###### > No" - custom_trusted_clients - break;; - Q|q) - unset trusted_arr - echo -e "###### > Abort" - echo -e "${red}Aborting ...${default}" - break;; - esac - done - break;; - *) - trusted_arr+=($TRUSTED_IP);; - esac - done - fi -} - -write_custom_trusted_clients(){ - if [ "$TUSTED_CLIENT_CONFIRM" = "true" ]; then - if [ "${#trusted_arr[@]}" != "0" ]; then - for ip in ${trusted_arr[@]} - do - sed -i "/trusted_clients\:/a \ \ \ \ $ip" ${HOME}/moonraker.conf - done - ok_msg "Custom IPs written to moonraker.conf!" - fi - fi -} - -symlinks_moonraker(){ - #create a klippy.log/moonraker.log symlink in klipper_config-dir just for convenience - if [ "$SEL_KLIPPYLOG_SL" = "true" ] && [ ! -e ${HOME}/klipper_config/klippy.log ]; then - status_msg "Creating klippy.log symlink ..." - ln -s /tmp/klippy.log ${HOME}/klipper_config - ok_msg "Symlink created!" - fi - if [ "$SEL_MRLOG_SL" = "true" ] && [ ! -e ${HOME}/klipper_config/moonraker.log ]; then - status_msg "Creating moonraker.log symlink ..." - ln -s /tmp/moonraker.log ${HOME}/klipper_config - ok_msg "Symlink created!" - fi -} - -handle_haproxy_lighttpd(){ - #handle haproxy - if [ "$DISABLE_HAPROXY" = "true" ]; then - if systemctl is-active haproxy -q; then - status_msg "Stopping haproxy service ..." - sudo /etc/init.d/haproxy stop && ok_msg "Service stopped!" - fi - sudo systemctl disable haproxy - ok_msg "Haproxy service disabled!" - else - if [ "$REMOVE_HAPROXY" = "true" ]; then - if systemctl is-active haproxy -q; then - status_msg "Stopping haproxy service ..." - sudo /etc/init.d/haproxy stop && ok_msg "Service stopped!" - fi - status_msg "Removing haproxy ..." - sudo apt-get remove haproxy -y - sudo update-rc.d -f haproxy remove - ok_msg "Haproxy removed!" - fi - fi - #handle lighttpd - if [ "$DISABLE_LIGHTTPD" = "true" ]; then - if systemctl is-active lighttpd -q; then - status_msg "Stopping lighttpd service ..." - sudo /etc/init.d/lighttpd stop && ok_msg "Service stopped!" - fi - sudo systemctl disable lighttpd - ok_msg "Lighttpd service disabled!" - else - if [ "$REMOVE_LIGHTTPD" = "true" ]; then - if systemctl is-active lighttpd -q; then - status_msg "Stopping lighttpd service ..." - sudo /etc/init.d/lighttpd stop && ok_msg "Service stopped!" - fi - status_msg "Removing lighttpd ..." - sudo apt-get remove lighttpd -y - sudo update-rc.d -f lighttpd remove - ok_msg "Lighttpd removed!" - fi - fi -} \ No newline at end of file +# write_custom_trusted_clients(){ +# if [ "$TUSTED_CLIENT_CONFIRM" = "true" ]; then +# if [ "${#trusted_arr[@]}" != "0" ]; then +# for ip in ${trusted_arr[@]} +# do +# sed -i "/trusted_clients\:/a \ \ \ \ $ip" ${HOME}/moonraker.conf +# done +# ok_msg "Custom IPs written to moonraker.conf!" +# fi +# fi +# } \ No newline at end of file From 86e7f37f7bb097e2d4ff6d2f6353752f596a06fc Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 15 Jan 2021 19:52:56 +0100 Subject: [PATCH 20/97] fix: bigger refactoring of the klipper webui installer --- scripts/install_klipper_webui.sh | 235 +++++++++++++++++-------------- 1 file changed, 130 insertions(+), 105 deletions(-) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index 84d8878..c1b203d 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -1,6 +1,6 @@ check_moonraker(){ status_msg "Checking for Moonraker service ..." - if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ]; then + 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 ok_msg "Moonraker service found!"; echo MOONRAKER_SERVICE_FOUND="true" else @@ -10,86 +10,104 @@ check_moonraker(){ fi } -get_user_selection_webui(){ - #ask user for webui default macros - while true; do - unset ADD_WEBUI_MACROS - echo - top_border - echo -e "| It is recommended to have some important macros to |" - echo -e "| have full functionality of the web interface. |" - blank_line - echo -e "| If you do not have such macros, you can choose to |" - echo -e "| install the suggested default macros now. |" - bottom_border - read -p "${cyan}###### Add the recommended macros? (Y/n):${default} " yn - case "$yn" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - ADD_WEBUI_MACROS="true" - break;; - N|n|No|no) - echo -e "###### > No" - ADD_WEBUI_MACROS="false" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done -} +# get_user_selection_webui(){ +# #ask user for webui default macros +# while true; do +# unset ADD_WEBUI_MACROS +# echo +# top_border +# echo -e "| It is recommended to have some important macros to |" +# echo -e "| have full functionality of the web interface. |" +# blank_line +# echo -e "| If you do not have such macros, you can choose to |" +# echo -e "| install the suggested default macros now. |" +# bottom_border +# read -p "${cyan}###### Add the recommended macros? (Y/n):${default} " yn +# case "$yn" in +# Y|y|Yes|yes|"") +# echo -e "###### > Yes" +# ADD_WEBUI_MACROS="true" +# break;; +# N|n|No|no) +# echo -e "###### > No" +# ADD_WEBUI_MACROS="false" +# break;; +# *) +# print_unkown_cmd +# print_msg && clear_msg;; +# esac +# done +# } install_mainsail(){ - get_user_selection_webui - #check if moonraker is already installed + ###! outdated dialog, see comment below regarding webui macros + #get_user_selection_webui + + ### check if moonraker is already installed check_moonraker + if [ "$MOONRAKER_SERVICE_FOUND" = "true" ]; then - #check for other enabled web interfaces + ### check for other enabled web interfaces unset SET_LISTEN_PORT detect_enabled_sites - #check if another site already listens to port 80 + + ### check if another site already listens to port 80 mainsail_port_check - #creating the mainsail nginx cfg + + ### creating the mainsail nginx cfg set_nginx_cfg "mainsail" - #test_nginx "$SET_LISTEN_PORT" - locate_printer_cfg && read_printer_cfg "mainsail" - install_webui_macros + + ###! outdated way of locating the printer.cfg. need a new way to install the webui-macros + ###! especially for multi instances, therefore disabling this function for now... + #locate_printer_cfg && read_printer_cfg "mainsail" + #install_webui_macros + + ### install mainsail mainsail_setup fi } install_fluidd(){ - get_user_selection_webui - #check if moonraker is already installed + ###! outdated dialog, see comment below regarding webui macros + #get_user_selection_webui + + ### check if moonraker is already installed check_moonraker + if [ "$MOONRAKER_SERVICE_FOUND" = "true" ]; then - #check for other enabled web interfaces + ### check for other enabled web interfaces unset SET_LISTEN_PORT detect_enabled_sites - #check if another site already listens to port 80 + + ### check if another site already listens to port 80 fluidd_port_check - #creating the fluidd nginx cfg + + ### creating the fluidd nginx cfg set_nginx_cfg "fluidd" - #test_nginx "$SET_LISTEN_PORT" - locate_printer_cfg && read_printer_cfg "fluidd" - install_webui_macros + + ###! outdated way of locating the printer.cfg. need a new way to install the webui-macros + ###! especially for multi instances, therefore disabling this function for now... + #locate_printer_cfg && read_printer_cfg "fluidd" + #install_webui_macros + + ### install fluidd fluidd_setup fi } -install_webui_macros(){ - #copy webui_macros.cfg - if [ "$ADD_WEBUI_MACROS" = "true" ]; then - status_msg "Create webui_macros.cfg ..." - if [ ! -f ${HOME}/klipper_config/webui_macros.cfg ]; then - cp ${HOME}/kiauh/resources/webui_macros.cfg ${HOME}/klipper_config - ok_msg "File created!" - else - warn_msg "File already exists! Skipping ..." - fi - fi - write_printer_cfg -} +# install_webui_macros(){ +# #copy webui_macros.cfg +# if [ "$ADD_WEBUI_MACROS" = "true" ]; then +# status_msg "Create webui_macros.cfg ..." +# if [ ! -f ${HOME}/klipper_config/webui_macros.cfg ]; then +# cp ${HOME}/kiauh/resources/webui_macros.cfg ${HOME}/klipper_config +# ok_msg "File created!" +# else +# warn_msg "File already exists! Skipping ..." +# fi +# fi +# write_printer_cfg +# } mainsail_port_check(){ if [ "$MAINSAIL_ENABLED" = "false" ]; then @@ -204,75 +222,82 @@ get_fluidd_ver(){ } mainsail_setup(){ - #get mainsail download url + ### get mainsail download url MAINSAIL_DL_URL=$(curl -s https://api.github.com/repositories/240875926/releases | grep browser_download_url | cut -d'"' -f4 | head -1) - #clean up an existing mainsail folder + + ### remove existing and create fresh mainsail folder, then download mainsail [ -d $MAINSAIL_DIR ] && rm -rf $MAINSAIL_DIR - #create fresh mainsail folder and download mainsail mkdir $MAINSAIL_DIR && cd $MAINSAIL_DIR status_msg "Downloading Mainsail $MAINSAIL_VERSION ..." wget $MAINSAIL_DL_URL && ok_msg "Download complete!" - #extract archive + + ### extract archive status_msg "Extracting archive ..." unzip -q -o *.zip && ok_msg "Done!" - #delete downloaded zip + + ### delete downloaded zip status_msg "Remove downloaded archive ..." rm -rf *.zip && ok_msg "Done!" && ok_msg "Mainsail installation complete!" echo } fluidd_setup(){ - #get fluidd download url + ### get fluidd download url FLUIDD_DL_URL=$(curl -s https://api.github.com/repositories/295836951/releases/latest | grep browser_download_url | cut -d'"' -f4) - #clean up an existing fluidd folder + + ### remove existing and create fresh fluidd folder, then download fluidd [ -d $FLUIDD_DIR ] && rm -rf $FLUIDD_DIR - #create fresh fluidd folder and download fluidd mkdir $FLUIDD_DIR && cd $FLUIDD_DIR status_msg "Downloading Fluidd $FLUIDD_VERSION ..." wget $FLUIDD_DL_URL && ok_msg "Download complete!" - #extract archive + + ### extract archive status_msg "Extracting archive ..." unzip -q -o *.zip && ok_msg "Done!" - #patch moonraker.conf to apply cors domains if needed - backup_moonraker_conf - patch_moonraker - #delete downloaded zip + + ###! this will be difficult to achieve for multi instances, so i will disable those functions for now.... + ###! will be probably easier to tell the user to simply re-install moonraker, those entries will be there then. + ### patch moonraker.conf to apply cors domains if needed + #backup_moonraker_conf + #patch_moonraker + + ### delete downloaded zip status_msg "Remove downloaded archive ..." rm -rf *.zip && ok_msg "Done!" && ok_msg "Fluidd installation complete!" echo } -patch_moonraker(){ - status_msg "Patching moonraker.conf ..." - mr_conf=${HOME}/moonraker.conf - # remove the now deprecated enable_cors option from moonraker.conf if it still exists - if [ "$(grep "^enable_cors:" $mr_conf)" ]; then - line="$(grep -n "^enable_cors:" ~/moonraker.conf | cut -d":" -f1)d" - sed -i "$line" $mr_conf && mr_restart="true" - fi - # looking for a cors_domain entry in moonraker.conf - if [ ! "$(grep "^cors_domains:$" $mr_conf)" ]; then - #find trusted_clients line number and subtract one, to insert cors_domains later - line="$(grep -n "^trusted_clients:$" $mr_conf | cut -d":" -f1)i" - sed -i "$line cors_domains:" $mr_conf && mr_restart="true" - fi - if [ "$(grep "^cors_domains:$" $mr_conf)" ]; then - hostname=$(hostname -I | cut -d" " -f1) - url1="\ \ \ \ http://*.local" - url2="\ \ \ \ http://app.fluidd.xyz" - url3="\ \ \ \ https://app.fluidd.xyz" - url4="\ \ \ \ http://$hostname:*" - #find cors_domains line number and add one, to insert urls later - line="$(expr $(grep -n "cors_domains:" $mr_conf | cut -d":" -f1) + 1)i" - [ ! "$(grep -E '^\s+http:\/\/\*\.local$' $mr_conf)" ] && sed -i "$line $url1" $mr_conf && mr_restart="true" - [ ! "$(grep -E '^\s+http:\/\/app\.fluidd\.xyz$' $mr_conf)" ] && sed -i "$line $url2" $mr_conf && mr_restart="true" - [ ! "$(grep -E '^\s+https:\/\/app\.fluidd\.xyz$' $mr_conf)" ] && sed -i "$line $url3" $mr_conf && mr_restart="true" - [ ! "$(grep -E '^\s+http:\/\/([0-9]{1,3}\.){3}[0-9]{1,3}' $mr_conf)" ] && sed -i "$line $url4" $mr_conf && mr_restart="true" - fi - #restart moonraker service if mr_restart was set to true - if [[ $mr_restart == "true" ]]; then - ok_msg "Patching done!" && restart_moonraker - else - ok_msg "No patching was needed!" - fi -} +# patch_moonraker(){ +# status_msg "Patching moonraker.conf ..." +# mr_conf=${HOME}/moonraker.conf +# # remove the now deprecated enable_cors option from moonraker.conf if it still exists +# if [ "$(grep "^enable_cors:" $mr_conf)" ]; then +# line="$(grep -n "^enable_cors:" ~/moonraker.conf | cut -d":" -f1)d" +# sed -i "$line" $mr_conf && mr_restart="true" +# fi +# # looking for a cors_domain entry in moonraker.conf +# if [ ! "$(grep "^cors_domains:$" $mr_conf)" ]; then +# #find trusted_clients line number and subtract one, to insert cors_domains later +# line="$(grep -n "^trusted_clients:$" $mr_conf | cut -d":" -f1)i" +# sed -i "$line cors_domains:" $mr_conf && mr_restart="true" +# fi +# if [ "$(grep "^cors_domains:$" $mr_conf)" ]; then +# hostname=$(hostname -I | cut -d" " -f1) +# url1="\ \ \ \ http://*.local" +# url2="\ \ \ \ http://app.fluidd.xyz" +# url3="\ \ \ \ https://app.fluidd.xyz" +# url4="\ \ \ \ http://$hostname:*" +# #find cors_domains line number and add one, to insert urls later +# line="$(expr $(grep -n "cors_domains:" $mr_conf | cut -d":" -f1) + 1)i" +# [ ! "$(grep -E '^\s+http:\/\/\*\.local$' $mr_conf)" ] && sed -i "$line $url1" $mr_conf && mr_restart="true" +# [ ! "$(grep -E '^\s+http:\/\/app\.fluidd\.xyz$' $mr_conf)" ] && sed -i "$line $url2" $mr_conf && mr_restart="true" +# [ ! "$(grep -E '^\s+https:\/\/app\.fluidd\.xyz$' $mr_conf)" ] && sed -i "$line $url3" $mr_conf && mr_restart="true" +# [ ! "$(grep -E '^\s+http:\/\/([0-9]{1,3}\.){3}[0-9]{1,3}' $mr_conf)" ] && sed -i "$line $url4" $mr_conf && mr_restart="true" +# fi +# #restart moonraker service if mr_restart was set to true +# if [[ $mr_restart == "true" ]]; then +# ok_msg "Patching done!" && restart_moonraker +# else +# ok_msg "No patching was needed!" +# fi +# } From 9cde005e0842272b6dde6d9680e9ccf535a75d34 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 15 Jan 2021 20:10:19 +0100 Subject: [PATCH 21/97] fix: better default park position for printers with less than 230mm on x and y --- resources/webui_macros.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/webui_macros.cfg b/resources/webui_macros.cfg index 5becc06..54090c7 100644 --- a/resources/webui_macros.cfg +++ b/resources/webui_macros.cfg @@ -4,8 +4,8 @@ [gcode_macro PAUSE] rename_existing: BASE_PAUSE -default_parameter_X: 230 #edit to your park position -default_parameter_Y: 230 #edit to your park position +default_parameter_X: 0 #edit to your park position +default_parameter_Y: 0 #edit to your park position default_parameter_Z: 10 #edit to your park position default_parameter_E: 1 #edit to your retract length gcode: From 94762727ae9c93708460c478adf6afc6c4b3fd72 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Jan 2021 11:17:37 +0100 Subject: [PATCH 22/97] fix: rename webui_macros.cfg to kiauh_macros.cfg --- resources/{webui_macros.cfg => kiauh_macros.cfg} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename resources/{webui_macros.cfg => kiauh_macros.cfg} (100%) diff --git a/resources/webui_macros.cfg b/resources/kiauh_macros.cfg similarity index 100% rename from resources/webui_macros.cfg rename to resources/kiauh_macros.cfg From c1a21c52b6a1a3f2b86ecf2c830ce1dc77e958a5 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Jan 2021 11:18:09 +0100 Subject: [PATCH 23/97] fix: create cfg directories if they are missing for whatever reason. --- scripts/install_klipper.sh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/install_klipper.sh b/scripts/install_klipper.sh index 48b56f2..d9fc694 100755 --- a/scripts/install_klipper.sh +++ b/scripts/install_klipper.sh @@ -114,6 +114,8 @@ MULTI_STARTSCRIPT create_minimal_printer_cfg(){ /bin/sh -c "cat > $1" << MINIMAL_CFG +[include kiauh_macros.cfg] + [mcu] serial: /dev/serial/by-id/ pin_map: arduino @@ -174,7 +176,13 @@ create_single_klipper_instance(){ status_msg "Creating single Klipper instance ..." status_msg "Installing system start script ..." create_single_klipper_startscript + + ### create printer config directory if missing + [ ! -d $PRINTER_CFG_LOC ] && mkdir -p $PRINTER_CFG_LOC + + ### create basic configs if missing [ ! -f $PRINTER_CFG ] && create_minimal_printer_cfg "$PRINTER_CFG" + [ ! -f $PRINTER_CFG_LOC/kiauh_macros.cfg ] && cp ${SRCDIR}/kiauh/resources/kiauh_macros.cfg $PRINTER_CFG_LOC/kiauh_macros.cfg ### enable instance sudo systemctl enable klipper.service @@ -198,14 +206,17 @@ create_multi_klipper_instance(){ TMP_PRINTER=/tmp/printer-$INSTANCE PRINTER_CFG="$PRINTER_CFG_LOC/printer_$INSTANCE/printer.cfg" - ### create printer config folder and write a minimal printer.cfg to it - [ ! -d $PRINTER_CFG_LOC/printer_$INSTANCE ] && mkdir -p $PRINTER_CFG_LOC/printer_$INSTANCE - [ ! -f $PRINTER_CFG ] && create_minimal_printer_cfg "$PRINTER_CFG" - ### create instance status_msg "Creating instance #$INSTANCE ..." create_multi_klipper_startscript + ### create printer config directory if missing + [ ! -d $PRINTER_CFG_LOC/printer_$INSTANCE ] && mkdir -p $PRINTER_CFG_LOC/printer_$INSTANCE + + ### create basic configs if missing + [ ! -f $PRINTER_CFG ] && create_minimal_printer_cfg "$PRINTER_CFG" + [ ! -f $PRINTER_CFG_LOC/printer_$INSTANCE/kiauh_macros.cfg ] && cp ${SRCDIR}/kiauh/resources/kiauh_macros.cfg $PRINTER_CFG_LOC/printer_$INSTANCE/kiauh_macros.cfg + ### enable instance sudo systemctl enable klipper-$INSTANCE.service ok_msg "Klipper instance $INSTANCE created!" From d705a043c94c5684f4d0cfc0b82f6b1277078708 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Jan 2021 11:19:22 +0100 Subject: [PATCH 24/97] fix: add more trusted clients, cors domains, auto create a config folder if missing for whatever reason --- scripts/install_moonraker.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index e0f51f7..fc0cf52 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -214,7 +214,7 @@ create_single_moonraker_conf(){ HOSTNAME=$(hostname -I | cut -d" " -f1) LOCAL_NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-3).0/24" -/bin/sh -c "cat > $MOONRAKER_CONF_LOC/moonraker.conf" << MOONRAKERCONF + /bin/sh -c "cat > $MOONRAKER_CONF_LOC/moonraker.conf" << MOONRAKERCONF [server] host: 0.0.0.0 port: $PORT @@ -228,17 +228,16 @@ api_key_file: ~/.moonraker_api_key trusted_clients: 127.0.0.1 $LOCAL_NETWORK + ::1/128 + FE80::/10 cors_domains: + http://*.* http://*.local http://my.mainsail.app https://my.mainsail.app http://app.fluidd.xyz https://app.fluidd.xyz http://$HOSTNAME - -[update_manager] -#client_repo: -#client_path: MOONRAKERCONF } @@ -246,7 +245,7 @@ create_multi_moonraker_conf(){ HOSTNAME=$(hostname -I | cut -d" " -f1) LOCAL_NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-3).0/24" -/bin/sh -c "cat > $MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.conf" << MOONRAKERCONF + /bin/sh -c "cat > $MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.conf" << MOONRAKERCONF [server] host: 0.0.0.0 port: $PORT @@ -260,17 +259,16 @@ api_key_file: ~/.moonraker_api_key trusted_clients: 127.0.0.1 $LOCAL_NETWORK + ::1/128 + FE80::/10 cors_domains: + http://*.* http://*.local http://my.mainsail.app https://my.mainsail.app http://app.fluidd.xyz https://app.fluidd.xyz http://$HOSTNAME - -[update_manager] -#client_repo: -#client_path: MOONRAKERCONF } @@ -386,6 +384,7 @@ moonraker_conf_creation(){ ip_list+=("$HOSTNAME:$PORT") status_msg "Creating moonraker.conf in $MOONRAKER_CONF_LOC" + [ ! -d $MOONRAKER_CONF_LOC ] && mkdir -p $MOONRAKER_CONF_LOC if [ ! -f $MOONRAKER_CONF_LOC/moonraker.conf ]; then create_single_moonraker_conf && ok_msg "moonraker.conf created!" else @@ -404,6 +403,7 @@ moonraker_conf_creation(){ ### start the creation of each instance status_msg "Creating moonraker.conf for instance #$INSTANCE" + [ ! -d $MOONRAKER_CONF_LOC/printer_$INSTANCE ] && mkdir -p $MOONRAKER_CONF_LOC/printer_$INSTANCE if [ ! -f $MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.conf ]; then create_multi_moonraker_conf && ok_msg "moonraker.conf created!" else From cd1489f0e58cb19008dce38996c39bb133b23375 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Jan 2021 11:20:57 +0100 Subject: [PATCH 25/97] fix: move the update manager function to the webinterface installations --- scripts/install_klipper_webui.sh | 62 ++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index c1b203d..65fc2dc 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -54,6 +54,9 @@ install_mainsail(){ ### check if another site already listens to port 80 mainsail_port_check + ### ask user to enable the moonraker update manager + enable_update_manager "mainsail" + ### creating the mainsail nginx cfg set_nginx_cfg "mainsail" @@ -82,6 +85,9 @@ install_fluidd(){ ### check if another site already listens to port 80 fluidd_port_check + ### ask user to enable the moonraker update manager + enable_update_manager "fluidd" + ### creating the fluidd nginx cfg set_nginx_cfg "fluidd" @@ -267,6 +273,62 @@ fluidd_setup(){ echo } +enable_update_manager(){ + source_kiauh_ini + ### ask user if he wants to enable the moonraker update manager + while true; do + echo + top_border + echo -e "| Do you want to enable the Moonraker Update Manager | " + echo -e "| for the selected webinterface? | " + hr + echo -e "| ${yellow}Please note:${default} | " + echo -e "| Entries for an already enabled update manager will be | " + echo -e "| overwritten if you decide to choose 'Yes'! | " + bottom_border + echo + read -p "${cyan}###### Enable Update Manager? (Y/n):${default} " yn + case "$yn" in + Y|y|Yes|yes|"") + echo -e "###### > Yes" + if [ $1 = "mainsail" ]; then + MOONRAKER_UPDATE_MANAGER="[update_manager]\nclient_repo: meteyou/mainsail\nclient_path: /home/${USER}/mainsail" + elif [ $1 = "fluidd" ]; then + MOONRAKER_UPDATE_MANAGER="[update_manager]\nclient_repo: cadriel/fluidd\nclient_path: /home/${USER}/fluidd" + else + unset MOONRAKER_UPDATE_MANAGER + fi + ### handle single moonraker install + if [ -f /etc/systemd/system/moonraker.service ]; then + ### delete existing entries + sed -i "/update_manager/d" $klipper_cfg_loc/moonraker.conf + sed -i "/client_repo/d" $klipper_cfg_loc/moonraker.conf + sed -i "/client_path/d" $klipper_cfg_loc/moonraker.conf + echo -e $MOONRAKER_UPDATE_MANAGER >> $klipper_cfg_loc/moonraker.conf + fi + ### handle multi moonraker installs + if ls /etc/systemd/system/moonraker-*.service 2>/dev/null 1>&2; then + for moonraker_conf in $(find $klipper_cfg_loc/printer_*/moonraker.conf); do + ### delete existing entries + sed -i "/update_manager/d" $moonraker_conf + sed -i "/client_repo/d" $moonraker_conf + sed -i "/client_path/d" $moonraker_conf + echo -e $MOONRAKER_UPDATE_MANAGER >> $moonraker_conf + done + fi + moonraker_service "restart" + break;; + N|n|No|no) + echo -e "###### > No" + unset MOONRAKER_UPDATE_MANAGER + break;; + *) + print_unkown_cmd + print_msg && clear_msg;; + esac + done +} + # patch_moonraker(){ # status_msg "Patching moonraker.conf ..." # mr_conf=${HOME}/moonraker.conf From dd2a26e2d0c1c70c55a568e23bbd0de5d3d366c1 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Jan 2021 11:23:26 +0100 Subject: [PATCH 26/97] del: remove now unused moonraker.conf template from resources --- resources/moonraker.conf | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 resources/moonraker.conf diff --git a/resources/moonraker.conf b/resources/moonraker.conf deleted file mode 100644 index 09f7b06..0000000 --- a/resources/moonraker.conf +++ /dev/null @@ -1,10 +0,0 @@ -[server] -host: 0.0.0.0 -port: 7125 -enable_debug_logging: True -config_path: ~/klipper_config - -[authorization] -enabled: True -trusted_clients: - 127.0.0.1 From 6b2175e4393bfc48f350fcfdcf45384ea7ee535d Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Jan 2021 11:28:14 +0100 Subject: [PATCH 27/97] fix: make klipperscreen installer use the klipper_cfg_loc variable for the printer config directory --- scripts/install_klipperscreen.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/install_klipperscreen.sh b/scripts/install_klipperscreen.sh index d028342..1f58d44 100644 --- a/scripts/install_klipperscreen.sh +++ b/scripts/install_klipperscreen.sh @@ -1,6 +1,7 @@ install_klipperscreen(){ python3_check if [ $py_chk_ok = "true" ]; then + source_kiauh_ini system_check_klipperscreen #ask user for customization get_user_selections_klipperscreen @@ -29,7 +30,7 @@ python3_check(){ } system_check_klipperscreen(){ - [ ! -e ${HOME}/klipper_config/KlipperScreen.log ] && KLIPPERSCREEN_SL_FOUND="false" + [ ! -e $klipper_cfg_loc/KlipperScreen.log ] && KLIPPERSCREEN_SL_FOUND="false" } get_user_selections_klipperscreen(){ @@ -71,9 +72,9 @@ klipperscreen_setup(){ symlinks_klipperscreen(){ #create a KlipperScreen.log symlink in klipper_config-dir just for convenience - if [ "$SEL_KSLOG_SL" = "true" ] && [ ! -e ${HOME}/klipper_config/KlipperScreen.log ]; then + if [ "$SEL_KSLOG_SL" = "true" ] && [ ! -e $klipper_cfg_loc/KlipperScreen.log ]; then status_msg "Creating KlipperScreen.log symlink ..." - ln -s /tmp/KlipperScreen.log ${HOME}/klipper_config + ln -s /tmp/KlipperScreen.log $klipper_cfg_loc ok_msg "Symlink created!" fi } From 7a4ccfe4dfe880ddef6bbc4b273df4336ed97550 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Jan 2021 11:50:20 +0100 Subject: [PATCH 28/97] fix: remove the functionality of patching an old/existing moonraker.conf only for making it compatible again. it will be way easier now to simply re-install moonraker and let those configs be created from scratch. --- scripts/install_klipper_webui.sh | 41 -------------------------------- 1 file changed, 41 deletions(-) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index 65fc2dc..5a4fab1 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -261,12 +261,6 @@ fluidd_setup(){ status_msg "Extracting archive ..." unzip -q -o *.zip && ok_msg "Done!" - ###! this will be difficult to achieve for multi instances, so i will disable those functions for now.... - ###! will be probably easier to tell the user to simply re-install moonraker, those entries will be there then. - ### patch moonraker.conf to apply cors domains if needed - #backup_moonraker_conf - #patch_moonraker - ### delete downloaded zip status_msg "Remove downloaded archive ..." rm -rf *.zip && ok_msg "Done!" && ok_msg "Fluidd installation complete!" @@ -328,38 +322,3 @@ enable_update_manager(){ esac done } - -# patch_moonraker(){ -# status_msg "Patching moonraker.conf ..." -# mr_conf=${HOME}/moonraker.conf -# # remove the now deprecated enable_cors option from moonraker.conf if it still exists -# if [ "$(grep "^enable_cors:" $mr_conf)" ]; then -# line="$(grep -n "^enable_cors:" ~/moonraker.conf | cut -d":" -f1)d" -# sed -i "$line" $mr_conf && mr_restart="true" -# fi -# # looking for a cors_domain entry in moonraker.conf -# if [ ! "$(grep "^cors_domains:$" $mr_conf)" ]; then -# #find trusted_clients line number and subtract one, to insert cors_domains later -# line="$(grep -n "^trusted_clients:$" $mr_conf | cut -d":" -f1)i" -# sed -i "$line cors_domains:" $mr_conf && mr_restart="true" -# fi -# if [ "$(grep "^cors_domains:$" $mr_conf)" ]; then -# hostname=$(hostname -I | cut -d" " -f1) -# url1="\ \ \ \ http://*.local" -# url2="\ \ \ \ http://app.fluidd.xyz" -# url3="\ \ \ \ https://app.fluidd.xyz" -# url4="\ \ \ \ http://$hostname:*" -# #find cors_domains line number and add one, to insert urls later -# line="$(expr $(grep -n "cors_domains:" $mr_conf | cut -d":" -f1) + 1)i" -# [ ! "$(grep -E '^\s+http:\/\/\*\.local$' $mr_conf)" ] && sed -i "$line $url1" $mr_conf && mr_restart="true" -# [ ! "$(grep -E '^\s+http:\/\/app\.fluidd\.xyz$' $mr_conf)" ] && sed -i "$line $url2" $mr_conf && mr_restart="true" -# [ ! "$(grep -E '^\s+https:\/\/app\.fluidd\.xyz$' $mr_conf)" ] && sed -i "$line $url3" $mr_conf && mr_restart="true" -# [ ! "$(grep -E '^\s+http:\/\/([0-9]{1,3}\.){3}[0-9]{1,3}' $mr_conf)" ] && sed -i "$line $url4" $mr_conf && mr_restart="true" -# fi -# #restart moonraker service if mr_restart was set to true -# if [[ $mr_restart == "true" ]]; then -# ok_msg "Patching done!" && restart_moonraker -# else -# ok_msg "No patching was needed!" -# fi -# } From e5ce64201822edd4ba0a465ae518cee163a5e502 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Jan 2021 12:44:42 +0100 Subject: [PATCH 29/97] fix: reorder the klippy_uds to the bottom --- scripts/install_moonraker.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index fc0cf52..1a7e6e1 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -218,9 +218,9 @@ create_single_moonraker_conf(){ [server] host: 0.0.0.0 port: $PORT -klippy_uds_address: /tmp/klippy_uds enable_debug_logging: True config_path: $PRINTER_CFG_LOC +klippy_uds_address: /tmp/klippy_uds [authorization] enabled: True @@ -249,9 +249,9 @@ create_multi_moonraker_conf(){ [server] host: 0.0.0.0 port: $PORT -klippy_uds_address: /tmp/klippy_uds-$INSTANCE enable_debug_logging: True config_path: $PRINTER_CFG_LOC/printer_$INSTANCE +klippy_uds_address: /tmp/klippy_uds-$INSTANCE [authorization] enabled: True From feb912da8a883cf1d265f03b2decff37520356f6 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Jan 2021 12:58:25 +0100 Subject: [PATCH 30/97] fix: make adding the kiauh_macros optional --- resources/kiauh_macros.cfg | 15 +++- scripts/install_klipper.sh | 4 - scripts/install_klipper_webui.sh | 131 ++++++++++++++++++------------- 3 files changed, 87 insertions(+), 63 deletions(-) diff --git a/resources/kiauh_macros.cfg b/resources/kiauh_macros.cfg index 54090c7..ede2aa2 100644 --- a/resources/kiauh_macros.cfg +++ b/resources/kiauh_macros.cfg @@ -1,6 +1,12 @@ -### AUTOCREATED WITH KIAUH ### -#is required to load the pause_resume module in klipper +######################################################################################### +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ AUTOCREATED WITH KIAUH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # +######################################################################################### +# Those are the recommended macros and config entries if you use Mainsail or Fluidd! # +# Feel free to edit or delete those macros if you already have them defined elsewhere! # +######################################################################################### + [pause_resume] +[display_status] [gcode_macro PAUSE] rename_existing: BASE_PAUSE @@ -34,5 +40,6 @@ gcode: CLEAR_PAUSE SDCARD_RESET_FILE BASE_CANCEL_PRINT -########################## -########################## + +######################################################################################### +######################################################################################### diff --git a/scripts/install_klipper.sh b/scripts/install_klipper.sh index d9fc694..4c20377 100755 --- a/scripts/install_klipper.sh +++ b/scripts/install_klipper.sh @@ -114,8 +114,6 @@ MULTI_STARTSCRIPT create_minimal_printer_cfg(){ /bin/sh -c "cat > $1" << MINIMAL_CFG -[include kiauh_macros.cfg] - [mcu] serial: /dev/serial/by-id/ pin_map: arduino @@ -182,7 +180,6 @@ create_single_klipper_instance(){ ### create basic configs if missing [ ! -f $PRINTER_CFG ] && create_minimal_printer_cfg "$PRINTER_CFG" - [ ! -f $PRINTER_CFG_LOC/kiauh_macros.cfg ] && cp ${SRCDIR}/kiauh/resources/kiauh_macros.cfg $PRINTER_CFG_LOC/kiauh_macros.cfg ### enable instance sudo systemctl enable klipper.service @@ -215,7 +212,6 @@ create_multi_klipper_instance(){ ### create basic configs if missing [ ! -f $PRINTER_CFG ] && create_minimal_printer_cfg "$PRINTER_CFG" - [ ! -f $PRINTER_CFG_LOC/printer_$INSTANCE/kiauh_macros.cfg ] && cp ${SRCDIR}/kiauh/resources/kiauh_macros.cfg $PRINTER_CFG_LOC/printer_$INSTANCE/kiauh_macros.cfg ### enable instance sudo systemctl enable klipper-$INSTANCE.service diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index 5a4fab1..132bef2 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -10,39 +10,39 @@ check_moonraker(){ fi } -# get_user_selection_webui(){ -# #ask user for webui default macros -# while true; do -# unset ADD_WEBUI_MACROS -# echo -# top_border -# echo -e "| It is recommended to have some important macros to |" -# echo -e "| have full functionality of the web interface. |" -# blank_line -# echo -e "| If you do not have such macros, you can choose to |" -# echo -e "| install the suggested default macros now. |" -# bottom_border -# read -p "${cyan}###### Add the recommended macros? (Y/n):${default} " yn -# case "$yn" in -# Y|y|Yes|yes|"") -# echo -e "###### > Yes" -# ADD_WEBUI_MACROS="true" -# break;; -# N|n|No|no) -# echo -e "###### > No" -# ADD_WEBUI_MACROS="false" -# break;; -# *) -# print_unkown_cmd -# print_msg && clear_msg;; -# esac -# done -# } +get_user_selection_kiauh_macros(){ + #ask user for webui default macros + while true; do + unset ADD_KIAUH_MACROS + echo + top_border + echo -e "| It is recommended to have some important macros to |" + echo -e "| have full functionality of the web interface. |" + blank_line + echo -e "| If you don't have those macros, you can choose to |" + echo -e "| install suggested default macros now. |" + blank_line + echo -e "| If unsure which macros are meant, just go ahead and |" + echo -e "| select 'Yes'. You can always delete them later. |" + bottom_border + read -p "${cyan}###### Add the recommended macros? (Y/n):${default} " yn + case "$yn" in + Y|y|Yes|yes|"") + echo -e "###### > Yes" + ADD_KIAUH_MACROS="true" + break;; + N|n|No|no) + echo -e "###### > No" + ADD_KIAUH_MACROS="false" + break;; + *) + print_unkown_cmd + print_msg && clear_msg;; + esac + done +} install_mainsail(){ - ###! outdated dialog, see comment below regarding webui macros - #get_user_selection_webui - ### check if moonraker is already installed check_moonraker @@ -54,16 +54,17 @@ install_mainsail(){ ### check if another site already listens to port 80 mainsail_port_check + ### ask user to install the recommended webinterface macros + get_user_selection_kiauh_macros + ### ask user to enable the moonraker update manager enable_update_manager "mainsail" ### creating the mainsail nginx cfg set_nginx_cfg "mainsail" - ###! outdated way of locating the printer.cfg. need a new way to install the webui-macros - ###! especially for multi instances, therefore disabling this function for now... - #locate_printer_cfg && read_printer_cfg "mainsail" - #install_webui_macros + ### copy the kiauh_macros.cfg to the config location + install_kiauh_macros ### install mainsail mainsail_setup @@ -71,9 +72,6 @@ install_mainsail(){ } install_fluidd(){ - ###! outdated dialog, see comment below regarding webui macros - #get_user_selection_webui - ### check if moonraker is already installed check_moonraker @@ -85,35 +83,58 @@ install_fluidd(){ ### check if another site already listens to port 80 fluidd_port_check + ### ask user to install the recommended webinterface macros + get_user_selection_kiauh_macros + ### ask user to enable the moonraker update manager enable_update_manager "fluidd" ### creating the fluidd nginx cfg set_nginx_cfg "fluidd" - ###! outdated way of locating the printer.cfg. need a new way to install the webui-macros - ###! especially for multi instances, therefore disabling this function for now... - #locate_printer_cfg && read_printer_cfg "fluidd" - #install_webui_macros + ### copy the kiauh_macros.cfg to the config location + install_kiauh_macros ### install fluidd fluidd_setup fi } -# install_webui_macros(){ -# #copy webui_macros.cfg -# if [ "$ADD_WEBUI_MACROS" = "true" ]; then -# status_msg "Create webui_macros.cfg ..." -# if [ ! -f ${HOME}/klipper_config/webui_macros.cfg ]; then -# cp ${HOME}/kiauh/resources/webui_macros.cfg ${HOME}/klipper_config -# ok_msg "File created!" -# else -# warn_msg "File already exists! Skipping ..." -# fi -# fi -# write_printer_cfg -# } +install_kiauh_macros(){ + source_kiauh_ini + ### copy kiauh_macros.cfg + if [ "$ADD_KIAUH_MACROS" = "true" ]; then + ### 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/kiauh_macros.cfg ]; then + ### copy kiauh_macros.cfg to config location + cp ${SRCDIR}/kiauh/resources/kiauh_macros.cfg $klipper_cfg_loc + ok_msg "$klipper_cfg_loc/kiauh_macros.cfg created!" + + ### write the include to the very first line of the printer.cfg + sed -i "1 i [include kiauh_macros.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/kiauh_macros.cfg ]; then + ### copy kiauh_macros.cfg to config location + cp ${SRCDIR}/kiauh/resources/kiauh_macros.cfg $path + ok_msg "$path/kiauh_macros.cfg created!" + + ### write the include to the very first line of the printer.cfg + sed -i "1 i [include kiauh_macros.cfg]" $path/printer.cfg + done + fi + + ### restart klipper service to parse the modified printer.cfg + klipper_service "restart" + fi +} mainsail_port_check(){ if [ "$MAINSAIL_ENABLED" = "false" ]; then From 2fa975e3c2624d5fe8e6d87d96680fced403f403 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Jan 2021 14:29:06 +0100 Subject: [PATCH 31/97] fix: missed closing an if statement --- scripts/install_klipper_webui.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index 132bef2..3b67992 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -128,6 +128,7 @@ install_kiauh_macros(){ ### write the include to the very first line of the printer.cfg sed -i "1 i [include kiauh_macros.cfg]" $path/printer.cfg + fi done fi From e24afa42ac79b601fbef085fb491bf6ef9086cb1 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Jan 2021 14:29:36 +0100 Subject: [PATCH 32/97] fix: made log upload function multi instance capable --- scripts/upload_log.sh | 56 ++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/scripts/upload_log.sh b/scripts/upload_log.sh index fcbd10a..c203ef1 100755 --- a/scripts/upload_log.sh +++ b/scripts/upload_log.sh @@ -39,42 +39,54 @@ accept_upload_conditions(){ upload_selection(){ source_kiauh_ini [ "$logupload_accepted" = "false" ] && accept_upload_conditions - KLIPPY_LOG=/tmp/klippy.log - MOONRAKER_LOG=/tmp/moonraker.log - DWC2_LOG=/tmp/dwc2.log + + ### find all suitable logfiles for klipper + logfiles=() + if ls /tmp/klippy*.log 2>/dev/null 1>&2; then + for kl_log in $(find /tmp/klippy*.log); do + logfiles+=($kl_log) + done + fi + if ls /tmp/moonraker*.log 2>/dev/null 1>&2; then + for mr_log in $(find /tmp/moonraker*.log); do + logfiles+=($mr_log) + done + fi + if ls /tmp/dwc2*.log 2>/dev/null 1>&2; then + for dwc_log in $(find /tmp/dwc2*.log); do + logfiles+=($dwc_log) + done + fi + + ### draw interface + i=0 top_border echo -e "| ${yellow}~~~~~~~~~~~~~~~ [ Log Upload ] ~~~~~~~~~~~~~~${default} |" hr echo -e "| You can choose the following files for uploading: |" - echo -e "| 1) klippy.log |" - echo -e "| 2) moonraker.log |" - echo -e "| 3) dwc2.log |" + for log in ${logfiles[@]}; do + printf "| $i) %-50s|\n" "${logfiles[$i]}" + i=$((i + 1)) + done quit_footer while true; do read -p "${cyan}Please select:${default} " choice - case "$choice" in - 1) - clear && print_header - upload_log "$KLIPPY_LOG" + if [ $choice = "q" ] || [ $choice = "Q" ]; then + clear && main_menu && break + elif [ $choice -le ${#logfiles[@]} ]; then + upload_log "${logfiles[$choice]}" upload_selection - ;; - 2) + else clear && print_header - upload_log "$MOONRAKER_LOG" + ERROR_MSG="File not found!" && print_msg && clear_msg upload_selection - ;; - 3) - clear && print_header - upload_log "$DWC2_LOG" - upload_selection - ;; - q | Q) clear; main_menu; break;; - esac + fi done } upload_log(){ if [ -f "$1" ]; then + clear && print_header status_msg "Uploading $1 ..." LINK=$(curl -s --upload-file $1 'http://paste.c-net.org/') [ ! -z "$LINK" ] && ok_msg "$1 upload successfull!" @@ -83,7 +95,7 @@ upload_log(){ unset LINK else clear && print_header - ERROR_MSG="$1 not found!" && print_msg && clear_msg + ERROR_MSG="File not found!" && print_msg && clear_msg upload_selection fi } \ No newline at end of file From e71f1b9dfd58132562424c67de9cec592a77a83d Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Jan 2021 14:44:10 +0100 Subject: [PATCH 33/97] fix: refactor install_menu --- scripts/ui/install_menu.sh | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index 2acfede..074479f 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -6,14 +6,16 @@ install_ui(){ echo -e "| all necessary dependencies for the various | " echo -e "| functions on a completely fresh system. | " hr - echo -e "| Firmware: | Webinterface: | " - echo -e "| 1) [Klipper] | 3) [DWC2] | " - echo -e "| | 4) [Mainsail] | " - echo -e "| Klipper API: | 5) [Fluidd] | " - echo -e "| 2) [Moonraker] | 6) [Octoprint] | " + echo -e "| Firmware: | Klipper Webinterface: | " + echo -e "| 1) [Klipper] | 3) [Mainsail] | " + echo -e "| | 4) [Fluidd] | " + echo -e "| Klipper API: | | " + echo -e "| 2) [Moonraker] | HDMI Screen: | " + echo -e "| | 5) [KlipperScreen] | " echo -e "| | | " - echo -e "| | HDMI Screen: | " - echo -e "| | 7) [KlipperScreen] | " + echo -e "| | Other: | " + echo -e "| | 6) [Duet Web Control] | " + echo -e "| | 7) [OctoPrint] | " quit_footer } @@ -38,31 +40,31 @@ install_menu(){ 3) clear print_header - install_dwc2 + install_mainsail print_msg && clear_msg install_ui;; 4) clear print_header - install_mainsail + install_fluidd print_msg && clear_msg install_ui;; 5) clear print_header - install_fluidd + install_klipperscreen print_msg && clear_msg install_ui;; 6) clear print_header - install_octoprint + install_dwc2 print_msg && clear_msg install_ui;; 7) clear print_header - install_klipperscreen + install_octoprint print_msg && clear_msg install_ui;; Q|q) From 6c33282d43af78f541b6a429a9156dad30628081 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 17 Jan 2021 14:50:55 +0100 Subject: [PATCH 34/97] fix: refactor main_menu --- scripts/ui/main_menu.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index b378ced..593bf95 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -7,12 +7,12 @@ main_ui(){ echo -e "| 1) [Install] | |" echo -e "| 2) [Update] | Moonraker: $MOONRAKER_STATUS|" echo -e "| 3) [Remove] | |" - 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|" + echo -e "| 4) [Advanced] | Fluidd: $FLUIDD_STATUS|" + echo -e "| 5) [Backup] | Mainsail: $MAINSAIL_STATUS|" + echo -e "| | KlipperScreen: $KLIPPERSCREEN_STATUS|" + echo -e "| 6) [Settings] | |" + echo -e "| | DWC2: $DWC2_STATUS|" + echo -e "| ${cyan}$KIAUH_VER${default}| Octoprint: $OCTOPRINT_STATUS|" quit_footer } From ab9d73b5b5e1eb74509138d46642f93b6e3ae73f Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 20 Jan 2021 14:55:20 +0100 Subject: [PATCH 35/97] fix: minimal cfg --- scripts/install_klipper.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/install_klipper.sh b/scripts/install_klipper.sh index 4c20377..752fb88 100755 --- a/scripts/install_klipper.sh +++ b/scripts/install_klipper.sh @@ -116,7 +116,6 @@ create_minimal_printer_cfg(){ /bin/sh -c "cat > $1" << MINIMAL_CFG [mcu] serial: /dev/serial/by-id/ -pin_map: arduino [pause_resume] [display_status] From 4748c154241e5459845e04ebe017e84102015fef Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 20 Jan 2021 15:00:12 +0100 Subject: [PATCH 36/97] fix: update UI nginx configs --- resources/fluidd_nginx.cfg | 40 ++++++------------------------------ resources/mainsail_nginx.cfg | 40 ++++++------------------------------ 2 files changed, 12 insertions(+), 68 deletions(-) diff --git a/resources/fluidd_nginx.cfg b/resources/fluidd_nginx.cfg index 36adf37..bbcd70a 100644 --- a/resources/fluidd_nginx.cfg +++ b/resources/fluidd_nginx.cfg @@ -23,35 +23,15 @@ server { index index.html; server_name _; - #max upload size for gcodes - client_max_body_size 200M; + #disable max upload size + client_max_body_size 0; location / { try_files $uri $uri/ /index.html; } - location /printer { - proxy_pass http://apiserver/printer; - proxy_set_header Host $http_host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Scheme $scheme; - } - - location /api { - proxy_pass http://apiserver/api; - proxy_set_header Host $http_host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Scheme $scheme; - } - - location /access { - proxy_pass http://apiserver/access; - proxy_set_header Host $http_host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Scheme $scheme; + location = /index.html { + add_header Cache-Control "no-store, no-cache, must-revalidate"; } location /websocket { @@ -65,16 +45,8 @@ server { proxy_read_timeout 86400; } - location /machine { - proxy_pass http://apiserver/machine; - proxy_set_header Host $http_host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Scheme $scheme; - } - - location /server { - proxy_pass http://apiserver/server; + location ~ ^/(printer|api|access|machine|server)/ { + proxy_pass http://apiserver$request_uri; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; diff --git a/resources/mainsail_nginx.cfg b/resources/mainsail_nginx.cfg index 4a3e93f..53c97be 100644 --- a/resources/mainsail_nginx.cfg +++ b/resources/mainsail_nginx.cfg @@ -23,35 +23,15 @@ server { index index.html; server_name _; - #max upload size for gcodes - client_max_body_size 200M; + #disable max upload size + client_max_body_size 0; location / { try_files $uri $uri/ /index.html; } - location /printer { - proxy_pass http://apiserver/printer; - proxy_set_header Host $http_host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Scheme $scheme; - } - - location /api { - proxy_pass http://apiserver/api; - proxy_set_header Host $http_host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Scheme $scheme; - } - - location /access { - proxy_pass http://apiserver/access; - proxy_set_header Host $http_host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Scheme $scheme; + location = /index.html { + add_header Cache-Control "no-store, no-cache, must-revalidate"; } location /websocket { @@ -65,16 +45,8 @@ server { proxy_read_timeout 86400; } - location /machine { - proxy_pass http://apiserver/machine; - proxy_set_header Host $http_host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Scheme $scheme; - } - - location /server { - proxy_pass http://apiserver/server; + location ~ ^/(printer|api|access|machine|server)/ { + proxy_pass http://apiserver$request_uri; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; From db856de8e503fbe6f94db62450107d432cbab7fd Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 20 Jan 2021 15:16:22 +0100 Subject: [PATCH 37/97] fix: fix shell command installation --- resources/shell_command.cfg | 7 +++++ scripts/functions.sh | 54 ++++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 resources/shell_command.cfg diff --git a/resources/shell_command.cfg b/resources/shell_command.cfg new file mode 100644 index 0000000..34e7581 --- /dev/null +++ b/resources/shell_command.cfg @@ -0,0 +1,7 @@ +[gcode_shell_command hello_world] +command: echo hello world +timeout: 2. +verbose: True +[gcode_macro HELLO_WORLD] +gcode: + RUN_SHELL_COMMAND CMD=hello_world \ No newline at end of file diff --git a/scripts/functions.sh b/scripts/functions.sh index 81cdd99..1e30472 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -355,19 +355,41 @@ setup_gcode_shell_command(){ install_gcode_shell_command(){ 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 + status_msg "Copy 'gcode_shell_command.py' to $KLIPPER_DIR/klippy/extras" + cp ${SRCDIR}/kiauh/resources/gcode_shell_command.py $KLIPPER_DIR/klippy/extras echo while true; do read -p "${cyan}###### Do you want to create the example shell command? (Y/n):${default} " yn case "$yn" in Y|y|Yes|yes|"") - ADD_SHELL_CMD_MACRO="true" - status_msg "Creating example macro ..." - locate_printer_cfg - read_printer_cfg "gcode_shell_command" - write_printer_cfg - ok_msg "Example macro created!" + 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;; @@ -433,22 +455,6 @@ write_printer_cfg(){ if [ "$DISPLAY_STATUS" = "false" ] && [[ ! $(grep '^\[display_status]$' $KIAUH_CFG) ]]; then echo -e "\n[display_status]" >> $KIAUH_CFG fi - #Klipper webui related config options - if [ "$WEBUI_MACROS" = "false" ] && [ "$ADD_WEBUI_MACROS" = "true" ] && [[ ! $(grep '^\[include webui_macros.cfg]$' $KIAUH_CFG) ]]; then - echo -e "\n[include webui_macros.cfg]" >> $KIAUH_CFG - fi - #G-Code Shell Command extension related config options - if [ "$ADD_SHELL_CMD_MACRO" = "true" ] && [[ ! $(grep '^\[gcode_shell_command hello_world]$' $KIAUH_CFG) ]]; then - cat <<-EOF >> $KIAUH_CFG - [gcode_shell_command hello_world] - command: echo hello world - timeout: 2. - verbose: True - [gcode_macro HELLO_WORLD] - gcode: - RUN_SHELL_COMMAND CMD=hello_world -EOF - fi #including the kiauh.cfg into printer.cfg if not already done if [ ! "$(grep '^\[include kiauh\.cfg\]$' $PRINTER_CFG)" ] && [ "$EDIT_CFG" = "true" ]; then status_msg "Writing [include kiauh.cfg] to printer.cfg ..." From 1ef67fa05c98553749570b6257be936605d43d85 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 20 Jan 2021 15:16:41 +0100 Subject: [PATCH 38/97] fix: insert blank lines in output --- scripts/backup.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/backup.sh b/scripts/backup.sh index ac69aca..9b27ecd 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -24,8 +24,10 @@ backup_klipper_config_dir(){ status_msg "Create backup of the Klipper config directory ..." config_folder_name="$(echo "$klipper_cfg_loc" | rev | cut -d"/" -f1 | rev)" cp -r "$klipper_cfg_loc" "$BACKUP_DIR/$config_folder_name.$current_date.backup" && ok_msg "Backup complete!" + echo else ok_msg "No config directory found! Skipping backup ..." + echo fi } From 3d9722f877a250ea53a46e870e12554ac87fcca6 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 20 Jan 2021 20:19:53 +0100 Subject: [PATCH 39/97] fix: rename array --- scripts/install_moonraker.sh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index 1a7e6e1..f1bc8ec 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -37,7 +37,6 @@ system_check_moonraker(){ } -### check the users linux system moonraker_setup_dialog(){ status_msg "Initializing Moonraker installation ..." @@ -276,9 +275,9 @@ MOONRAKERCONF #********************************************************************************************# ############################################################################################## -print_ip_list(){ +print_mr_ip_list(){ i=1 - for ip in ${ip_list[@]}; do + for ip in ${mr_ip_list[@]}; do echo -e " ${cyan}● Instance $i:${default} $ip" i=$((i + 1)) done @@ -309,7 +308,7 @@ create_single_moonraker_instance(){ print_msg && clear_msg ### display moonraker ip to the user - print_ip_list; echo + print_mr_ip_list; echo } create_multi_moonraker_instance(){ @@ -340,7 +339,7 @@ create_multi_moonraker_instance(){ print_msg && clear_msg ### display all moonraker ips to the user - print_ip_list; echo + print_mr_ip_list; echo } setup_moonraker_nginx_cfg(){ @@ -373,7 +372,7 @@ moonraker_conf_creation(){ ### declare empty array for ips which get displayed to the user at the end of the setup HOSTNAME=$(hostname -I | cut -d" " -f1) - ip_list=() + mr_ip_list=() ### create single instance moonraker.conf file if [ $INSTANCE_COUNT -eq $INSTANCE ]; then @@ -381,7 +380,7 @@ moonraker_conf_creation(){ PORT=$DEFAULT_PORT ### write the ip and port to the ip list for displaying it later to the user - ip_list+=("$HOSTNAME:$PORT") + mr_ip_list+=("$HOSTNAME:$PORT") status_msg "Creating moonraker.conf in $MOONRAKER_CONF_LOC" [ ! -d $MOONRAKER_CONF_LOC ] && mkdir -p $MOONRAKER_CONF_LOC @@ -399,7 +398,7 @@ moonraker_conf_creation(){ PORT=$(expr $DEFAULT_PORT + $INSTANCE - 1) ### write the ip and port to the ip list for displaying it later to the user - ip_list+=("$HOSTNAME:$PORT") + mr_ip_list+=("$HOSTNAME:$PORT") ### start the creation of each instance status_msg "Creating moonraker.conf for instance #$INSTANCE" From cf1e37fb2add0ead6db6c292f498a65842922170 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 20 Jan 2021 20:23:55 +0100 Subject: [PATCH 40/97] fix: rework octoprint remove function for removing multi instances --- kiauh.sh | 3 -- scripts/remove.sh | 79 +++++++++++++++++++++++------------------------ 2 files changed, 39 insertions(+), 43 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index efa91d3..9b08080 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -35,9 +35,6 @@ DWC_ENV_DIR=${HOME}/dwc-env DWC2_DIR=${HOME}/sdcard/web #octoprint OCTOPRINT_DIR=${HOME}/OctoPrint -OCTOPRINT_CFG_DIR=${HOME}/.octoprint -OCTOPRINT_SERVICE1=/etc/init.d/octoprint -OCTOPRINT_SERVICE2=/etc/default/octoprint #KlipperScreen KLIPPERSCREEN_DIR=${HOME}/KlipperScreen KLIPPERSCREEN_ENV_DIR=${HOME}/.KlipperScreen-env diff --git a/scripts/remove.sh b/scripts/remove.sh index bb2dfb6..8988302 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -40,6 +40,7 @@ remove_klipper(){ 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") @@ -47,6 +48,7 @@ remove_klipper(){ 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-*") @@ -54,6 +56,7 @@ remove_klipper(){ 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-*") @@ -271,47 +274,43 @@ remove_fluidd(){ ############################################################# remove_octoprint(){ - data_arr=( - $OCTOPRINT_SERVICE1 - $OCTOPRINT_SERVICE2 - $OCTOPRINT_DIR - $OCTOPRINT_CFG_DIR - ${HOME}/octoprint.log - /etc/sudoers.d/octoprint-shutdown - /etc/nginx/sites-available/octoprint - /etc/nginx/sites-enabled/octoprint - ) - print_error "OctoPrint" && data_count=() - if [ "$ERROR_MSG" = "" ]; then - stop_octoprint - if [[ -e $OCTOPRINT_SERVICE1 || -e $OCTOPRINT_SERVICE2 ]]; then - status_msg "Removing OctoPrint Service ..." - sudo update-rc.d -f octoprint remove - sudo rm -rf $OCTOPRINT_SERVICE1 $OCTOPRINT_SERVICE2 && ok_msg "OctoPrint Service removed!" - fi - if [[ -d $OCTOPRINT_DIR || -d $OCTOPRINT_CFG_DIR ]]; then - status_msg "Removing OctoPrint and .octoprint directory ..." - rm -rf $OCTOPRINT_DIR $OCTOPRINT_CFG_DIR && ok_msg "Directories removed!" - fi - if [ -f /etc/sudoers.d/octoprint-shutdown ]; then - sudo rm -rf /etc/sudoers.d/octoprint-shutdown - fi - if [ -L ${HOME}/octoprint.log ]; then - status_msg "Removing octoprint.log Symlink ..." - rm -rf ${HOME}/octoprint.log && ok_msg "Symlink removed!" - fi - #remove octoprint config for nginx - if [ -e /etc/nginx/sites-available/octoprint ]; then - status_msg "Removing OctoPrint configuration for Nginx ..." - sudo rm /etc/nginx/sites-available/octoprint && ok_msg "File removed!" - fi - #remove octoprint symlink for nginx - if [ -L /etc/nginx/sites-enabled/octoprint ]; then - status_msg "Removing OctoPrint Symlink for Nginx ..." - sudo rm /etc/nginx/sites-enabled/octoprint && ok_msg "File removed!" - fi - CONFIRM_MSG=" OctoPrint successfully removed!" + ###remove single instance + if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "octoprint.service")" ]; then + status_msg "Removing OctoPrint Service ..." + sudo systemctl stop octoprint + sudo systemctl disable octoprint + sudo rm -f $SYSTEMDDIR/octoprint.service + ok_msg "OctoPrint Service removed!" fi + + ###remove multi instance services + if [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "octoprint-[[:digit:]].service")" ]; then + status_msg "Removing OctoPrint Services ..." + for service in $(find $SYSTEMDDIR -maxdepth 1 -name "octoprint-*.service" | cut -d"/" -f5) + do + status_msg "Removing $service ..." + sudo systemctl stop $service + sudo systemctl disable $service + sudo rm -f $SYSTEMDDIR/$service + ok_msg "OctoPrint Service removed!" + done + fi + + ###reloading units + sudo systemctl daemon-reload + + ### remove .octoprint directories + if [ -d ${HOME}/OctoPrint ] || [ -d ${HOME}/.octoprint* ]; then + status_msg "Removing OctoPrint and .octoprint directory ..." + rm -rf ${HOME}/OctoPrint ${HOME}/.octoprint* && ok_msg "Directories removed!" + fi + + ### remove sudoers file + if [ -f /etc/sudoers.d/octoprint-shutdown ]; then + sudo rm -rf /etc/sudoers.d/octoprint-shutdown + fi + + CONFIRM_MSG=" OctoPrint successfully removed!" } ############################################################# From ee252d185ad6851162de89b91c5e88f110e0df25 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 20 Jan 2021 20:24:24 +0100 Subject: [PATCH 41/97] fix: update octoprint installer for multi instances --- scripts/install_octoprint.sh | 383 ++++++++++++++++++++--------------- scripts/status.sh | 20 +- scripts/ui/install_menu.sh | 2 +- 3 files changed, 242 insertions(+), 163 deletions(-) diff --git a/scripts/install_octoprint.sh b/scripts/install_octoprint.sh index 273a129..3a117bc 100755 --- a/scripts/install_octoprint.sh +++ b/scripts/install_octoprint.sh @@ -1,30 +1,50 @@ -install_octoprint(){ - #check for other enabled web interfaces - unset SET_LISTEN_PORT - detect_enabled_sites - #ask user for customization - get_user_selections_octoprint - #octoprint main installation - octoprint_dependencies - octoprint_setup - add_groups - configure_autostart - add_reboot_permission - create_config_yaml - #execute customizations - set_nginx_cfg "octoprint" - set_hostname - #after install actions - load_octoprint_server -} +############################################################################################## +#********************************************************************************************# +############################################################################################## -get_user_selections_octoprint(){ +### base variables +SYSTEMDDIR="/etc/systemd/system" +OCTOPRINT_ENV="${HOME}/OctoPrint" + +octoprint_setup_dialog(){ status_msg "Initializing OctoPrint installation ..." - #ask user to set a reverse proxy - octoprint_reverse_proxy_dialog - #ask to change hostname - [ "$SET_NGINX_CFG" = "true" ] && create_custom_hostname - status_msg "Installation will start now! Please wait ..." + + ### 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 + + ### instance confirmation dialog + while true; do + echo + top_border + if [ $INSTANCE_COUNT -gt 1 ]; then + printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!" + else + echo -e "| 1 Klipper instance was found! | " + fi + echo -e "| You need one OctoPrint instance per Klipper instance. | " + bottom_border + echo + read -p "${cyan}###### Create $INSTANCE_COUNT OctoPrint instances? (Y/n):${default} " yn + case "$yn" in + Y|y|Yes|yes|"") + echo -e "###### > Yes" + status_msg "Creating $INSTANCE_COUNT OctoPrint instances ..." + octoprint_setup + break;; + N|n|No|no) + echo -e "###### > No" + warn_msg "Exiting OctoPrint setup ..." + echo + break;; + *) + print_unkown_cmd + print_msg && clear_msg;; + esac + done } octoprint_dependencies(){ @@ -42,25 +62,39 @@ octoprint_dependencies(){ } octoprint_setup(){ - if [ ! -d $OCTOPRINT_DIR ];then - status_msg "Create OctoPrint directory ..." - mkdir -p $OCTOPRINT_DIR && ok_msg "Directory created!" - fi - cd $OCTOPRINT_DIR - #create the virtualenv + ### check and install all dependencies + octoprint_dependencies + + ### add user to usergroups and add reboot permissions + add_to_groups + add_reboot_permission + + ### create and activate the virtualenv + [ ! -d $OCTOPRINT_ENV ] && mkdir -p $OCTOPRINT_ENV status_msg "Set up virtualenv ..." + cd $OCTOPRINT_ENV virtualenv venv source venv/bin/activate - #install octoprint with pip + + ### install octoprint with pip status_msg "Download and install OctoPrint ..." pip install pip --upgrade pip install --no-cache-dir octoprint ok_msg "Download complete!" - #leave virtualenv + + ### leave virtualenv deactivate + + ### set up instances + INSTANCE=1 + if [ $INSTANCE_COUNT -eq $INSTANCE ]; then + create_single_octoprint_instance + else + create_multi_octoprint_instance + fi } -add_groups(){ +add_to_groups(){ if [ ! "$(groups | grep tty)" ]; then status_msg "Adding user '${USER}' to group 'tty' ..." sudo usermod -a -G tty ${USER} && ok_msg "Done!" @@ -71,143 +105,176 @@ add_groups(){ fi } -configure_autostart(){ - USER=$(whoami) - cd $OCTOPRINT_DIR - status_msg "Downloading files ..." - wget https://github.com/foosel/OctoPrint/raw/master/scripts/octoprint.init - wget https://github.com/foosel/OctoPrint/raw/master/scripts/octoprint.default - ok_msg "Files downloaded successfully!" - #make necessary changes in default file - status_msg "Configure OctoPrint Service ..." - DEFAULT_FILE=$OCTOPRINT_DIR/octoprint.default - sed -i "s/pi/$USER/g" $DEFAULT_FILE - sed -i "s/#BASEDIR=/BASEDIR=/" $DEFAULT_FILE - sed -i "s/#CONFIGFILE=/CONFIGFILE=/" $DEFAULT_FILE - sed -i "s/#DAEMON=/DAEMON=/" $DEFAULT_FILE - #move files to correct location - sudo mv octoprint.init $OCTOPRINT_SERVICE1 - sudo mv octoprint.default $OCTOPRINT_SERVICE2 - #make file in init.d executable - sudo chmod +x $OCTOPRINT_SERVICE1 - status_msg "Reload systemd configuration files" - sudo update-rc.d octoprint defaults - sudo systemctl daemon-reload - ok_msg "Configuration complete!" - ok_msg "OctoPrint installed!" +create_single_octoprint_startscript(){ +### create single instance systemd service file +sudo /bin/sh -c "cat > ${SYSTEMDDIR}/octoprint.service" << OCTOPRINT +[Unit] +Description=Starts OctoPrint on startup +After=network-online.target +Wants=network-online.target + +[Service] +Environment="LC_ALL=C.UTF-8" +Environment="LANG=C.UTF-8" +Type=simple +User=$USER +ExecStart=${OCTOPRINT_ENV}/venv/bin/octoprint --basedir ${BASEDIR} --config ${CONFIG_YAML} --port=${PORT} serve + +[Install] +WantedBy=multi-user.target +OCTOPRINT +} + +create_multi_octoprint_startscript(){ +### create multi instance systemd service file +sudo /bin/sh -c "cat > ${SYSTEMDDIR}/octoprint-$INSTANCE.service" << OCTOPRINT +[Unit] +Description=Starts OctoPrint instance $INSTANCE on startup +After=network-online.target +Wants=network-online.target + +[Service] +Environment="LC_ALL=C.UTF-8" +Environment="LANG=C.UTF-8" +Type=simple +User=$USER +ExecStart=${OCTOPRINT_ENV}/venv/bin/octoprint --basedir ${BASEDIR} --config ${CONFIG_YAML} --port=${PORT} serve + +[Install] +WantedBy=multi-user.target +OCTOPRINT +} + +create_config_yaml(){ +### create multi instance config.yaml file +/bin/sh -c "cat > ${BASEDIR}/config.yaml" << CONFIGYAML +serial: + additionalPorts: + - ${TMP_PRINTER} + disconnectOnErrors: false + port: ${TMP_PRINTER} +server: + commands: + serverRestartCommand: ${RESTART_COMMAND} + systemRestartCommand: sudo shutdown -r now + systemShutdownCommand: sudo shutdown -h now +CONFIGYAML +} + +create_single_octoprint_instance(){ + status_msg "Setting up 1 OctoPrint instance ..." + + ### single instance variables + PORT=5000 + BASEDIR="${HOME}/.octoprint" + TMP_PRINTER="/tmp/printer" + CONFIG_YAML="$BASEDIR/config.yaml" + RESTART_COMMAND="sudo service octoprint restart" + + ### declare empty array for ips which get displayed to the user at the end of the setup + HOSTNAME=$(hostname -I | cut -d" " -f1) + op_ip_list=() + + ### create instance + status_msg "Creating single OctoPrint instance ..." + create_single_octoprint_startscript + op_ip_list+=("$HOSTNAME:$PORT") + + ### create the config.yaml + if [ ! -f $BASEDIR/config.yaml ]; then + status_msg "Creating config.yaml ..." + [ ! -d $BASEDIR ] && mkdir $BASEDIR + create_config_yaml + ok_msg "Config created!" + fi + + ### enable instance + sudo systemctl enable octoprint.service + ok_msg "Single OctoPrint instance created!" + + ### launching instance + status_msg "Launching OctoPrint instance ..." + sudo systemctl start octoprint + + ### confirm message + CONFIRM_MSG="Single OctoPrint instance has been set up!" + print_msg && clear_msg + + ### display all octoprint ips to the user + print_op_ip_list; echo +} + +create_multi_octoprint_instance(){ + status_msg "Setting up $INSTANCE_COUNT instances of OctoPrint ..." + + ### declare empty array for ips which get displayed to the user at the end of the setup + HOSTNAME=$(hostname -I | cut -d" " -f1) + op_ip_list=() + + ### default port + PORT=5000 + + while [ $INSTANCE -le $INSTANCE_COUNT ]; do + ### multi instance variables + BASEDIR="${HOME}/.octoprint-$INSTANCE" + TMP_PRINTER="/tmp/printer-$INSTANCE" + CONFIG_YAML="$BASEDIR/config.yaml" + RESTART_COMMAND="sudo service octoprint restart" + + ### create instance + status_msg "Creating instance #$INSTANCE ..." + create_multi_octoprint_startscript + op_ip_list+=("$HOSTNAME:$PORT") + + ### create the config.yaml + if [ ! -f $BASEDIR/config.yaml ]; then + status_msg "Creating config.yaml for instance #$INSTANCE..." + [ ! -d $BASEDIR ] && mkdir $BASEDIR + create_config_yaml + ok_msg "Config #$INSTANCE created!" + fi + + ### enable instance + sudo systemctl enable octoprint-$INSTANCE.service + ok_msg "OctoPrint instance $INSTANCE created!" + + ### launching instance + status_msg "Launching OctoPrint instance $INSTANCE ..." + sudo systemctl start octoprint-$INSTANCE + + ### instance counter +1 + INSTANCE=$(expr $INSTANCE + 1) + + ### port +1 + PORT=$(expr $PORT + 1) + done + + ### confirm message + CONFIRM_MSG="$INSTANCE_COUNT OctoPrint instances have been set up!" + print_msg && clear_msg + + ### display all moonraker ips to the user + print_op_ip_list; echo } add_reboot_permission(){ - USER=$(whoami) + USER=${USER} #create a backup when file already exists if [ -f /etc/sudoers.d/octoprint-shutdown ]; then sudo mv /etc/sudoers.d/octoprint-shutdown /etc/sudoers.d/octoprint-shutdown.old fi #create new permission file status_msg "Add reboot permission to user '$USER' ..." - cd $OCTOPRINT_DIR - echo "$USER ALL=NOPASSWD: /sbin/shutdown" > octoprint-shutdown + cd ${HOME} && echo "$USER ALL=NOPASSWD: /sbin/shutdown" > octoprint-shutdown sudo chown 0 octoprint-shutdown sudo mv octoprint-shutdown /etc/sudoers.d/octoprint-shutdown ok_msg "Permission set!" - sleep 2 } -octoprint_reverse_proxy_dialog(){ - echo - top_border - echo -e "| If you want to have nicer URLs or simply need | " - echo -e "| OctoPrint to run on port 80 (http's default port) | " - echo -e "| due to some network restrictions, you can set up a | " - echo -e "| reverse proxy instead of configuring OctoPrint to | " - echo -e "| run on port 80. | " - bottom_border - while true; do - echo -e "${cyan}" - read -p "###### Do you want to set up a reverse proxy now? (y/N): " yn - echo -e "${default}" - case "$yn" in - Y|y|Yes|yes) - octoprint_port_check - break;; - N|n|No|no|"") - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac +print_op_ip_list(){ + i=1 + for ip in ${op_ip_list[@]}; do + echo -e " ${cyan}● Instance $i:${default} $ip" + i=$((i + 1)) done -} - -octoprint_port_check(){ - if [ "$OCTOPRINT_ENABLED" = "false" ]; then - if [ "$SITE_ENABLED" = "true" ]; then - status_msg "Detected other enabled interfaces:" - [ "$MAINSAIL_ENABLED" = "true" ] && echo " ${cyan}● Mainsail - Port:$MAINSAIL_PORT${default}" - [ "$FLUIDD_ENABLED" = "true" ] && echo " ${cyan}● Fluidd - Port:$FLUIDD_PORT${default}" - [ "$DWC2_ENABLED" = "true" ] && echo " ${cyan}● DWC2 - Port:$DWC2_PORT${default}" - if [ "$MAINSAIL_PORT" = "80" ] || [ "$DWC2_PORT" = "80" ] || [ "$FLUIDD_PORT" = "80" ]; then - PORT_80_BLOCKED="true" - select_octoprint_port - fi - else - DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/octoprint_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) - SET_LISTEN_PORT=$DEFAULT_PORT - fi - SET_NGINX_CFG="true" - else - SET_NGINX_CFG="false" - fi -} - -select_octoprint_port(){ - if [ "$PORT_80_BLOCKED" = "true" ]; then - echo - top_border - echo -e "| ${red}!!!WARNING!!!${default} |" - echo -e "| ${red}You need to choose a different port for OctoPrint!${default} |" - echo -e "| ${red}The following web interface is listening at port 80:${default} |" - blank_line - [ "$MAINSAIL_PORT" = "80" ] && echo "| ● Mainsail |" - [ "$FLUIDD_PORT" = "80" ] && echo "| ● Fluidd |" - [ "$DWC2_PORT" = "80" ] && echo "| ● DWC2 |" - blank_line - echo -e "| Make sure you don't choose a port which was already |" - echo -e "| assigned to one of the other web interfaces! |" - blank_line - echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |" - echo -e "| input. So make sure to choose a valid port! |" - bottom_border - while true; do - read -p "${cyan}Please enter a new Port:${default} " NEW_PORT - if [ "$NEW_PORT" != "$MAINSAIL_PORT" ] && [ "$NEW_PORT" != "$FLUIDD_PORT" ] && [ "$NEW_PORT" != "$DWC2_PORT" ]; then - echo "Setting port $NEW_PORT for OctoPrint!" - SET_LISTEN_PORT=$NEW_PORT - break - else - echo "That port is already taken! Select a different one!" - fi - done - fi -} - -create_config_yaml(){ - if [ ! -d $OCTOPRINT_CFG_DIR ]; then - status_msg "Creating config.yaml ..." - mkdir $OCTOPRINT_CFG_DIR - cp ${HOME}/kiauh/resources/octoprint_config.cfg $OCTOPRINT_CFG_DIR/config.yaml - ok_msg "Config created!" - fi -} - -load_octoprint_server(){ - start_octoprint - #create an octoprint.log symlink in home-dir just for convenience - if [ ! -e ${HOME}/octoprint.log ]; then - status_msg "Creating octoprint.log Symlink ..." - ln -s ${HOME}/.octoprint/logs/octoprint.log ${HOME}/octoprint.log && ok_msg "Symlink created!" - fi - ok_msg "OctoPrint is now running on:" - ok_msg "$(hostname -I | cut -d " " -f1):5000 or" - ok_msg "http://localhost:5000"; echo } \ No newline at end of file diff --git a/scripts/status.sh b/scripts/status.sh index d5b8ecb..5c5a204 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -156,11 +156,21 @@ fluidd_status(){ octoprint_status(){ ocount=0 octoprint_data=( + SERVICE $OCTOPRINT_DIR - $OCTOPRINT_CFG_DIR - $OCTOPRINT_SERVICE1 - $OCTOPRINT_SERVICE2 ) + #remove the "SERVICE" entry from the octoprint array if an octoprint service is installed + if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "octoprint.service")" ] || [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "octoprint-[[:digit:]].service")" ]; then + unset octoprint_data[0] + fi + + ### count amount of octoprint services + if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "octoprint.service")" ]; then + instances=1 + else + instances=$(systemctl list-units --full -all -t service --no-legend | grep -E "octoprint-[[:digit:]].service" | wc -l) + fi + #count+1 for each found data-item from array for op in "${octoprint_data[@]}" do @@ -168,8 +178,10 @@ octoprint_status(){ ocount=$(expr $ocount + 1) fi done + + ### display status if [ "$ocount" == "${#octoprint_data[*]}" ]; then - OCTOPRINT_STATUS="${green}Installed!${default} " + OCTOPRINT_STATUS="$(printf "${green}Installed: %-5s${default}" $instances)" elif [ "$ocount" == 0 ]; then OCTOPRINT_STATUS="${red}Not installed!${default} " else diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index 074479f..db12c2e 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -64,7 +64,7 @@ install_menu(){ 7) clear print_header - install_octoprint + octoprint_setup_dialog print_msg && clear_msg install_ui;; Q|q) From 51207e2eb94dcf5b1d1dc8593287854d513260cb Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 20 Jan 2021 20:25:48 +0100 Subject: [PATCH 42/97] fix: remove file, config.yaml gets dynamically created now --- resources/octoprint_config.cfg | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 resources/octoprint_config.cfg diff --git a/resources/octoprint_config.cfg b/resources/octoprint_config.cfg deleted file mode 100644 index 9ad22c6..0000000 --- a/resources/octoprint_config.cfg +++ /dev/null @@ -1,10 +0,0 @@ -serial: - additionalPorts: - - /tmp/printer - disconnectOnErrors: false - port: /tmp/printer -server: - commands: - serverRestartCommand: sudo service octoprint restart - systemRestartCommand: sudo shutdown -r now - systemShutdownCommand: sudo shutdown -h now From 598c106c3aa5f10a09a1f2641321ffcfa40e8af8 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 21 Jan 2021 10:23:08 +0100 Subject: [PATCH 43/97] fix: correct mainsail url --- scripts/install_moonraker.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index f1bc8ec..32a1a15 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -232,8 +232,8 @@ trusted_clients: cors_domains: http://*.* http://*.local - http://my.mainsail.app - https://my.mainsail.app + http://my.mainsail.xyz + https://my.mainsail.xyz http://app.fluidd.xyz https://app.fluidd.xyz http://$HOSTNAME @@ -263,8 +263,8 @@ trusted_clients: cors_domains: http://*.* http://*.local - http://my.mainsail.app - https://my.mainsail.app + http://my.mainsail.xyz + https://my.mainsail.xyz http://app.fluidd.xyz https://app.fluidd.xyz http://$HOSTNAME From d098eef08ee5e5d8024706ab359d98b3e4132cc5 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 21 Jan 2021 10:28:04 +0100 Subject: [PATCH 44/97] fix: rename files to their correct name --- resources/{common_vars_nginx.cfg => common_vars.conf} | 0 resources/{moonraker_nginx.cfg => upstreams.conf} | 0 scripts/install_moonraker.sh | 4 ++-- 3 files changed, 2 insertions(+), 2 deletions(-) rename resources/{common_vars_nginx.cfg => common_vars.conf} (100%) rename resources/{moonraker_nginx.cfg => upstreams.conf} (100%) diff --git a/resources/common_vars_nginx.cfg b/resources/common_vars.conf similarity index 100% rename from resources/common_vars_nginx.cfg rename to resources/common_vars.conf diff --git a/resources/moonraker_nginx.cfg b/resources/upstreams.conf similarity index 100% rename from resources/moonraker_nginx.cfg rename to resources/upstreams.conf diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index 32a1a15..ae9aa20 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -351,10 +351,10 @@ setup_moonraker_nginx_cfg(){ ### copy nginx configs to target destination if [ ! -f $NGINX_CONFD/upstreams.conf ]; then - sudo cp ${SRCDIR}/kiauh/resources/moonraker_nginx.cfg $NGINX_CONFD/upstreams.conf + sudo cp ${SRCDIR}/kiauh/resources/upstreams.conf $NGINX_CONFD fi if [ ! -f $NGINX_CONFD/common_vars.conf ]; then - sudo cp ${SRCDIR}/kiauh/resources/common_vars_nginx.cfg $NGINX_CONFD/common_vars.conf + sudo cp ${SRCDIR}/kiauh/resources/common_vars.conf $NGINX_CONFD fi } From 738269adaea1bc6c4a43dabb22e0030724587329 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 21 Jan 2021 11:28:31 +0100 Subject: [PATCH 45/97] fix: make use of the delivered .version files to read mainsail and fluidd version --- scripts/status.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/scripts/status.sh b/scripts/status.sh index 5c5a204..befe6fa 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -400,10 +400,9 @@ compare_moonraker_versions(){ read_local_mainsail_version(){ unset MAINSAIL_VER_FOUND - MAINSAIL_APP_FILE=$(find $MAINSAIL_DIR/js -name "app.*.js" 2>/dev/null) - if [ ! -z $MAINSAIL_APP_FILE ]; then - MAINSAIL_LOCAL_VER=$(grep -o -E 'state:{packageVersion:.+' $MAINSAIL_APP_FILE | cut -d'"' -f2) + if [ -e $MAINSAIL_DIR/.version ]; then MAINSAIL_VER_FOUND="true" + MAINSAIL_LOCAL_VER=$(head -n 1 $MAINSAIL_DIR/.version) else MAINSAIL_VER_FOUND="false" && unset MAINSAIL_LOCAL_VER fi @@ -440,10 +439,9 @@ compare_mainsail_versions(){ read_local_fluidd_version(){ unset FLUIDD_VER_FOUND - FLUIDD_APP_FILE=$(find $FLUIDD_DIR/js -name "app.*.js" 2>/dev/null) - if [ ! -z $FLUIDD_APP_FILE ]; then - FLUIDD_LOCAL_VER=$(grep -o -E '"version/setVersion",".+"' $FLUIDD_APP_FILE | cut -d'"' -f4) + if [ -e $FLUIDD_DIR/.version ]; then FLUIDD_VER_FOUND="true" + FLUIDD_LOCAL_VER=$(head -n 1 $FLUIDD_DIR/.version) else FLUIDD_VER_FOUND="false" && unset FLUIDD_LOCAL_VER fi From 7eb0fe24f8aea9592a1f6cfa43da6222e562b4f8 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 21 Jan 2021 17:35:21 +0100 Subject: [PATCH 46/97] fix: some typos in moonraker installer --- scripts/install_moonraker.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index ae9aa20..eda69f0 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -114,7 +114,7 @@ moonraker_setup(){ ### force remove existing moonraker dir and clone into fresh moonraker dir [ -d $MOONRAKER_DIR ] && rm -rf $MOONRAKER_DIR cd ${HOME} && git clone $MOONRAKER_REPO - status_msg "Download complete!" + ok_msg "Download complete!" ### step 2: install moonraker dependencies and create python virtualenv status_msg "Installing dependencies ..." @@ -182,7 +182,7 @@ After=network.target WantedBy=multi-user.target [Service] Type=simple -User=$USER +User=${USER} RemainAfterExit=yes ExecStart=${MOONRAKER_ENV}/bin/python ${MOONRAKER_DIR}/moonraker/moonraker.py -l ${MOONRAKER_LOG} -c ${MOONRAKER_CONF} Restart=always @@ -201,7 +201,7 @@ After=network.target WantedBy=multi-user.target [Service] Type=simple -User=$USER +User=${USER} RemainAfterExit=yes ExecStart=${MOONRAKER_ENV}/bin/python ${MOONRAKER_DIR}/moonraker/moonraker.py -l ${MOONRAKER_LOG} -c ${MOONRAKER_CONF} Restart=always @@ -292,7 +292,6 @@ create_single_moonraker_instance(){ ### create instance status_msg "Creating single Moonraker instance ..." - status_msg "Installing system start script ..." create_single_moonraker_startscript ### enable instance From fb1d3a8cd9c9fe43178e99003b063b4a38aaaaab Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 21 Jan 2021 17:38:21 +0100 Subject: [PATCH 47/97] fix: dwc installer rework, only for single instance atm. multi instance tbd... --- scripts/install_dwc2.sh | 380 ++++++++++++++++++------------------- scripts/status.sh | 6 +- scripts/ui/install_menu.sh | 2 +- 3 files changed, 190 insertions(+), 198 deletions(-) diff --git a/scripts/install_dwc2.sh b/scripts/install_dwc2.sh index d7cd05b..de6a324 100755 --- a/scripts/install_dwc2.sh +++ b/scripts/install_dwc2.sh @@ -1,124 +1,99 @@ -install_dwc2(){ - if [ -d $KLIPPER_DIR ]; then - system_check_dwc2 - #check for other enabled web interfaces - unset SET_LISTEN_PORT - detect_enabled_sites - #ask user for customization - get_user_selections_dwc2 - #dwc2 main installation - klipper_service "stop" - dwc2_setup - #setup config - setup_printer_config_dwc2 - #execute customizations - disable_octoprint - set_nginx_cfg "dwc2" - set_hostname - #after install actions - klipper_service "restart" - else - ERROR_MSG=" Please install Klipper first!\n Skipping..." - fi -} +############################################################################################## +#********************************************************************************************# +############################################################################################## + +### base variables +SYSTEMDDIR="/etc/systemd/system" +DWC_ENV="${HOME}/dwc-env" +DWC2_DIR="${HOME}/sdcard/web" system_check_dwc2(){ - status_msg "Initializing DWC2 installation ..." - #check for existing printer.cfg - locate_printer_cfg - if [ -f $PRINTER_CFG ]; then - PRINTER_CFG_FOUND="true" - else - PRINTER_CFG_FOUND="false" - fi - #check if octoprint is installed + ### check system for an installed octoprint service if systemctl is-enabled octoprint.service -q 2>/dev/null; then OCTOPRINT_ENABLED="true" fi } -get_user_selections_dwc2(){ - #let user choose to install systemd or init.d service +dwc_setup_dialog(){ + status_msg "Initializing DWC2 installation ..." + + ### check system for several requirements before initializing the dwc2 installation + system_check_dwc2 + + ### 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 config path check + check_klipper_cfg_path + + ### ask user how to handle OctoPrint, Haproxy and Lighttpd + process_octoprint_dialog_dwc2 + process_haproxy_lighttpd_dialog + + ### instance confirmation dialog while true; do - echo - top_border - echo -e "| Do you want to install dwc2-for-klipper-socket 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 a 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_DWC2_INITD="true" - INST_DWC2_SYSTEMD="false" - break;; - 2) - echo -e "###### > 1) Systemd" - INST_DWC2_INITD="false" - INST_DWC2_SYSTEMD="true" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done - #user selection for printer.cfg - if [ "$PRINTER_CFG_FOUND" = "false" ]; then - while true; do echo top_border - echo -e "| ${red}WARNING! - No printer.cfg was found!${default} |" - hr - echo -e "| KIAUH can create a minimal printer.cfg with only the |" - echo -e "| necessary config entries if you wish. |" - echo -e "| |" - echo -e "| Please be aware, that this option will ${red}NOT${default} create a |" - echo -e "| fully working printer.cfg for you! |" + if [ $INSTANCE_COUNT -gt 1 ]; then + printf "|%-55s|\n" " $INSTANCE_COUNT Klipper instances were found!" + else + echo -e "| 1 Klipper instance was found! | " + fi + echo -e "| You need one DWC instance per Klipper instance. | " bottom_border - read -p "${cyan}###### Create a default printer.cfg? (Y/n):${default} " yn + echo + read -p "${cyan}###### Create $INSTANCE_COUNT DWC instances? (Y/n):${default} " yn case "$yn" in Y|y|Yes|yes|"") echo -e "###### > Yes" - SEL_DEF_CFG="true" + status_msg "Creating $INSTANCE_COUNT DWC instances ..." + dwc_setup break;; N|n|No|no) echo -e "###### > No" - SEL_DEF_CFG="false" + warn_msg "Exiting DWC setup ..." + echo break;; *) print_unkown_cmd print_msg && clear_msg;; - esac - done - fi - #ask user to install reverse proxy - dwc2_reverse_proxy_dialog - #ask to change hostname - [ "$SET_NGINX_CFG" = "true" ] && create_custom_hostname - #ask user to disable octoprint when such installed service was found + esac + done +} + +###TODO for future: should be some kind of shared function between moonraker and this installer, since it does the same +process_octoprint_dialog_dwc2(){ + ### ask user to disable octoprint when its service was found if [ "$OCTOPRINT_ENABLED" = "true" ]; then while true; do echo - warn_msg "OctoPrint service found!" - echo -e "You might consider disabling the OctoPrint service," - echo -e "since an active OctoPrint service may lead to unexpected" - echo -e "behavior of the DWC2 Webinterface." + top_border + echo -e "| ${red}!!! WARNING - OctoPrint service found !!!${default} |" + hr + echo -e "| You might consider disabling the OctoPrint service, |" + echo -e "| since an active OctoPrint service may lead to unex- |" + echo -e "| pected behavior of Duet Web Control for Klipper. |" + bottom_border read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn case "$yn" in Y|y|Yes|yes|"") echo -e "###### > Yes" - DISABLE_OPRINT="true" + status_msg "Stopping OctoPrint ..." + sudo systemctl stop octoprint && ok_msg "OctoPrint service stopped!" + status_msg "Disabling OctoPrint ..." + sudo systemctl disable octoprint && ok_msg "OctoPrint service disabled!" break;; N|n|No|no) echo -e "###### > No" - DISABLE_OPRINT="false" break;; *) print_unkown_cmd @@ -132,36 +107,39 @@ get_user_selections_dwc2(){ ############################################################# ############################################################# -get_dwc2_ver(){ +get_dwc_ver(){ DWC2_VERSION=$(curl -s https://api.github.com/repositories/28820678/releases/latest | grep tag_name | cut -d'"' -f4) } -dwc2_setup(){ - #check dependencies +dwc_setup(){ + ### check dependencies dep=(git wget gzip tar curl) dependency_check - #get dwc2-for-klipper - status_msg "Cloning DWC2-for-Klipper-Socket repository ..." + + ### step 1: get dwc2-for-klipper + status_msg "Downloading DWC2-for-Klipper-Socket ..." cd ${HOME} && git clone $DWC2FK_REPO - ok_msg "DWC2-for-Klipper successfully cloned!" - #copy installers from kiauh srcdir to dwc-for-klipper-socket - status_msg "Copy installers to $DWC2FK_DIR" - cp -r ${SRCDIR}/kiauh/scripts/dwc2-for-klipper-socket-installer $DWC2FK_DIR/scripts - ok_msg "Done!" - status_msg "Starting service-installer ..." - if [ "$INST_DWC2_INITD" = "true" ]; then - $DWC2FK_DIR/scripts/install-octopi.sh - elif [ "$INST_DWC2_SYSTEMD" = "true" ]; then - $DWC2FK_DIR/scripts/install-debian.sh + ok_msg "Download complete!" + + ### step 2: install dwc2 dependencies and create python virtualenv + status_msg "Installing dependencies ..." + install_dwc_packages + create_dwc_virtualenv + + ### step 3: download Duet Web Control + download_dwc_webui + + ### step 4: create dwc instances + INSTANCE=1 + if [ $INSTANCE_COUNT -eq $INSTANCE ]; then + create_single_dwc_instance + else + #create_multi_dwc_instance + warn_msg "Sorry, at the moment only single instance installations are supported!" fi - ok_msg "Service installed!" - #patch /etc/default/klipper to append the uds argument - patch_klipper_sysfile "dwc2" - #download Duet Web Control - download_dwc2_webui } -download_dwc2_webui(){ +download_dwc_webui(){ #get Duet Web Control GET_DWC2_URL=$(curl -s https://api.github.com/repositories/28820678/releases/latest | grep browser_download_url | cut -d'"' -f4) status_msg "Downloading DWC2 Web UI ..." @@ -176,7 +154,7 @@ download_dwc2_webui(){ done ok_msg "Done!" status_msg "Writing DWC version to file ..." - echo $GET_DWC2_URL | cut -d/ -f8 > $DWC2_DIR/version + echo $GET_DWC2_URL | cut -d/ -f8 > $DWC2_DIR/.version ok_msg "Done!" status_msg "Do a little cleanup ..." rm -rf DuetWebControl-SD.zip @@ -184,95 +162,109 @@ download_dwc2_webui(){ ok_msg "DWC2 Web UI installed!" } -############################################################# -############################################################# +############################################################################################## +#********************************************************************************************# +############################################################################################## -setup_printer_config_dwc2(){ - if [ "$PRINTER_CFG_FOUND" = "true" ]; then - #check printer.cfg for necessary dwc2 entries - read_printer_cfg "dwc2" && write_printer_cfg - fi - if [ "$SEL_DEF_CFG" = "true" ]; then - status_msg "Creating minimal default printer.cfg ..." - create_minimal_cfg - ok_msg "printer.cfg location: '$PRINTER_CFG'" - ok_msg "Done!" - fi +install_dwc_packages() +{ + PKGLIST="python3-virtualenv python3-dev python3-tornado" + + # 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_dwc_virtualenv() +{ + status_msg "Installing python virtual environment..." -dwc2_reverse_proxy_dialog(){ - echo - top_border - echo -e "| If you want to have a nicer URL or simply need/want | " - echo -e "| DWC2 to run on port 80 (http's default port) you | " - echo -e "| can set up a reverse proxy to run DWC2 on port 80. | " - bottom_border - while true; do - read -p "${cyan}###### Do you want to set up a reverse proxy now? (y/N):${default} " yn - case "$yn" in - Y|y|Yes|yes) - dwc2_port_check - break;; - N|n|No|no|"") - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac + # Create virtualenv if it doesn't already exist + [ ! -d ${DWC_ENV} ] && virtualenv -p /usr/bin/python3 ${DWC_ENV} + + # Install/update dependencies + ${DWC_ENV}/bin/pip install tornado==6.0.4 +} + +create_single_dwc_startscript(){ +### create systemd service file +sudo /bin/sh -c "cat > ${SYSTEMDDIR}/dwc.service" << DWC +#Systemd service file for DWC +[Unit] +Description=dwc_webif +After=network.target +[Install] +WantedBy=multi-user.target +[Service] +Type=simple +User=${USER} +RemainAfterExit=yes +ExecStart=${DWC_ENV}/bin/python3 ${DWC2FK_DIR}/web_dwc2.py +Restart=always +RestartSec=10 +DWC +} + +create_multi_dwc_startscript(){ + ###! atm not possible due to hardcoded log and config files used by dwc2-for-klipper-socket! + ###! either needs a PR to read start-arguments passed over by the service file or + ###! every instance needs its own copy of dwc2-for-klipper-socket with a modifief web_dwc2.py + ###! on line 223, 228 and probably 217 as well +} + +############################################################################################## +#********************************************************************************************# +############################################################################################## + +print_dwc_ip_list(){ + i=1 + for ip in ${dwc_ip_list[@]}; do + echo -e " ${cyan}● Instance $i:${default} $ip" + i=$((i + 1)) done } -dwc2_port_check(){ - if [ "$DWC2_ENABLED" = "false" ]; then - if [ "$SITE_ENABLED" = "true" ]; then - status_msg "Detected other enabled interfaces:" - [ "$OCTOPRINT_ENABLED" = "true" ] && echo " ${cyan}● OctoPrint - Port:$OCTOPRINT_PORT${default}" - [ "$MAINSAIL_ENABLED" = "true" ] && echo " ${cyan}● Mainsail - Port:$MAINSAIL_PORT${default}" - [ "$FLUIDD_ENABLED" = "true" ] && echo " ${cyan}● Fluidd - Port:$FLUIDD_PORT${default}" - if [ "$MAINSAIL_PORT" = "80" ] || [ "$OCTOPRINT_PORT" = "80" ] || [ "$FLUIDD_PORT" = "80" ]; then - PORT_80_BLOCKED="true" - select_dwc2_port - fi - else - DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/dwc2_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) - SET_LISTEN_PORT=$DEFAULT_PORT - fi - SET_NGINX_CFG="true" - else - SET_NGINX_CFG="false" - fi +create_single_dwc_instance(){ + status_msg "Setting up 1 Duet Web Control instance ..." + + ### single instance variables + PORT=4750 + DWC_LOG=/tmp/dwc.log + + ### declare empty array for ips which get displayed to the user at the end of the setup + HOSTNAME=$(hostname -I | cut -d" " -f1) + dwc_ip_list=() + + ### create instance + status_msg "Creating single DWC instance ..." + create_single_dwc_startscript + + ### write the ip and port to the ip list for displaying it later to the user + dwc_ip_list+=("$HOSTNAME:$PORT") + + ### enable instance + sudo systemctl enable dwc.service + ok_msg "Single DWC instance created!" + + ### launching instance + status_msg "Launching DWC instance ..." + sudo systemctl start dwc + + ### confirm message + CONFIRM_MSG="Single DWC instance has been set up!" + print_msg && clear_msg + + ### display moonraker ip to the user + print_dwc_ip_list; echo } -select_dwc2_port(){ - if [ "$PORT_80_BLOCKED" = "true" ]; then - echo - top_border - echo -e "| ${red}!!!WARNING!!!${default} |" - echo -e "| ${red}You need to choose a different port for DWC2!${default} |" - echo -e "| ${red}The following web interface is listening at port 80:${default} |" - blank_line - [ "$OCTOPRINT_PORT" = "80" ] && echo "| ● OctoPrint |" - [ "$MAINSAIL_PORT" = "80" ] && echo "| ● Mainsail |" - [ "$FLUIDD_PORT" = "80" ] && echo "| ● Fluidd |" - blank_line - echo -e "| Make sure you don't choose a port which was already |" - echo -e "| assigned to one of the other web interfaces! |" - blank_line - echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |" - echo -e "| input. So make sure to choose a valid port! |" - bottom_border - while true; do - read -p "${cyan}Please enter a new Port:${default} " NEW_PORT - if [ "$NEW_PORT" != "$MAINSAIL_PORT" ] && [ "$NEW_PORT" != "$FLUIDD_PORT" ] && [ "$NEW_PORT" != "$OCTOPRINT_PORT" ]; then - echo "Setting port $NEW_PORT for DWC2!" - SET_LISTEN_PORT=$NEW_PORT - break - else - echo "That port is already taken! Select a different one!" - fi - done - fi +create_multi_dwc_instance(){ + ###! atm not possible due to hardcoded log and config files used by dwc2-for-klipper-socket! + ###! either needs a PR to read start-arguments passed over by the service file or + ###! every instance needs its own copy of dwc2-for-klipper-socket with a modifief web_dwc2.py + ###! on line 223, 228 and probably 217 as well } \ No newline at end of file diff --git a/scripts/status.sh b/scripts/status.sh index befe6fa..760ae73 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -331,9 +331,9 @@ compare_dwc2fk_versions(){ read_local_dwc2_version(){ unset DWC2_VER_FOUND - if [ -e $DWC2_DIR/version ]; then + if [ -e $DWC2_DIR/.version ]; then DWC2_VER_FOUND="true" - DWC2_LOCAL_VER=$(head -n 1 $DWC2_DIR/version) + DWC2_LOCAL_VER=$(head -n 1 $DWC2_DIR/.version) else DWC2_VER_FOUND="false" && unset DWC2_LOCAL_VER fi @@ -344,7 +344,7 @@ read_remote_dwc2_version(){ if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then DWC2_REMOTE_VER=$NONE else - get_dwc2_ver + get_dwc_ver DWC2_REMOTE_VER=$DWC2_VERSION fi } diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index db12c2e..883d68a 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -58,7 +58,7 @@ install_menu(){ 6) clear print_header - install_dwc2 + dwc_setup_dialog print_msg && clear_msg install_ui;; 7) From d958c1ba2ae84365189d9fa780cb8753343437e9 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 21 Jan 2021 23:34:25 +0100 Subject: [PATCH 48/97] fix: prepare for possible multi instance capabilities of dwc2-for-klipper-socket --- kiauh.sh | 5 +- scripts/install_dwc2.sh | 174 ++++++++++++++++++++++++++++++++++------ 2 files changed, 153 insertions(+), 26 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index 9b08080..cebfa29 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -32,7 +32,8 @@ FLUIDD_DIR=${HOME}/fluidd #dwc2 DWC2FK_DIR=${HOME}/dwc2-for-klipper-socket DWC_ENV_DIR=${HOME}/dwc-env -DWC2_DIR=${HOME}/sdcard/web +#DWC2_DIR=${HOME}/sdcard/web +DWC2_DIR=${HOME}/duetwebcontrol #octoprint OCTOPRINT_DIR=${HOME}/OctoPrint #KlipperScreen @@ -46,7 +47,7 @@ BACKUP_DIR=${HOME}/kiauh-backups KLIPPER_REPO=https://github.com/KevinOConnor/klipper.git ARKSINE_REPO=https://github.com/Arksine/klipper.git DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git -DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper-socket.git +DWC2FK_REPO=https://github.com/th33xitus/dwc2-for-klipper-socket.git MOONRAKER_REPO=https://github.com/Arksine/moonraker.git KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git #branches diff --git a/scripts/install_dwc2.sh b/scripts/install_dwc2.sh index de6a324..60fb04b 100755 --- a/scripts/install_dwc2.sh +++ b/scripts/install_dwc2.sh @@ -112,6 +112,10 @@ get_dwc_ver(){ } dwc_setup(){ + ### get printer config directory + source_kiauh_ini + DWC_CONF_LOC="$klipper_cfg_loc" + ### check dependencies dep=(git wget gzip tar curl) dependency_check @@ -126,16 +130,20 @@ dwc_setup(){ install_dwc_packages create_dwc_virtualenv - ### step 3: download Duet Web Control + ### step 3: create dwc2.cfg folder and dwc2.cfg + [ ! -d $DWC_CONF_LOC ] && mkdir -p $DWC_CONF_LOC + dwc_cfg_creation + + ### step 4: download Duet Web Control download_dwc_webui - ### step 4: create dwc instances + ### step 5: create dwc instances INSTANCE=1 if [ $INSTANCE_COUNT -eq $INSTANCE ]; then create_single_dwc_instance else #create_multi_dwc_instance - warn_msg "Sorry, at the moment only single instance installations are supported!" + create_multi_dwc_instance fi } @@ -191,11 +199,10 @@ create_dwc_virtualenv() } create_single_dwc_startscript(){ -### create systemd service file -sudo /bin/sh -c "cat > ${SYSTEMDDIR}/dwc.service" << DWC -#Systemd service file for DWC + ### create systemd service file + sudo /bin/sh -c "cat > ${SYSTEMDDIR}/dwc.service" << DWC [Unit] -Description=dwc_webif +Description=DuetWebControl After=network.target [Install] WantedBy=multi-user.target @@ -203,17 +210,62 @@ WantedBy=multi-user.target Type=simple User=${USER} RemainAfterExit=yes -ExecStart=${DWC_ENV}/bin/python3 ${DWC2FK_DIR}/web_dwc2.py +ExecStart=${DWC_ENV}/bin/python3 ${DWC2FK_DIR}/web_dwc2.py -l ${DWC_LOG} -c ${DWC_CFG} Restart=always RestartSec=10 DWC } create_multi_dwc_startscript(){ - ###! atm not possible due to hardcoded log and config files used by dwc2-for-klipper-socket! - ###! either needs a PR to read start-arguments passed over by the service file or - ###! every instance needs its own copy of dwc2-for-klipper-socket with a modifief web_dwc2.py - ###! on line 223, 228 and probably 217 as well + ### create systemd service file + sudo /bin/sh -c "cat > ${SYSTEMDDIR}/dwc-$INSTANCE.service" << DWC +[Unit] +Description=DuetWebControl +After=network.target +[Install] +WantedBy=multi-user.target +[Service] +Type=simple +User=${USER} +RemainAfterExit=yes +ExecStart=${DWC_ENV}/bin/python3 ${DWC2FK_DIR}/web_dwc2.py -l ${DWC_LOG} -c ${DWC_CFG} +Restart=always +RestartSec=10 +DWC +} + +create_single_dwcfk_cfg(){ +### create single instance config file +/bin/sh -c "cat > $DWC_CONF_LOC/dwc2.cfg" << DWCCFG +[webserver] +listen_adress: 0.0.0.0 +web_root: ~/duetwebcontrol +port: ${PORT} + +[reply_filters] +regex: + max_accel: \d+.\d+ + max_accel_to_decel: \d+.\d+ + square_corner_velocity: \d+.\d+ + max_velocity: \d+.\d+ +DWCCFG +} + +create_multi_dwcfk_cfg(){ +### create single instance config file +/bin/sh -c "cat > $DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg" << DWCCFG +[webserver] +listen_adress: 0.0.0.0 +web_root: ~/duetwebcontrol +port: ${PORT} + +[reply_filters] +regex: + max_accel: \d+.\d+ + max_accel_to_decel: \d+.\d+ + square_corner_velocity: \d+.\d+ + max_velocity: \d+.\d+ +DWCCFG } ############################################################################################## @@ -232,20 +284,13 @@ create_single_dwc_instance(){ status_msg "Setting up 1 Duet Web Control instance ..." ### single instance variables - PORT=4750 DWC_LOG=/tmp/dwc.log - - ### declare empty array for ips which get displayed to the user at the end of the setup - HOSTNAME=$(hostname -I | cut -d" " -f1) - dwc_ip_list=() + DWC_CFG="$DWC_CONF_LOC/dwc2.cfg" ### create instance status_msg "Creating single DWC instance ..." create_single_dwc_startscript - ### write the ip and port to the ip list for displaying it later to the user - dwc_ip_list+=("$HOSTNAME:$PORT") - ### enable instance sudo systemctl enable dwc.service ok_msg "Single DWC instance created!" @@ -263,8 +308,89 @@ create_single_dwc_instance(){ } create_multi_dwc_instance(){ - ###! atm not possible due to hardcoded log and config files used by dwc2-for-klipper-socket! - ###! either needs a PR to read start-arguments passed over by the service file or - ###! every instance needs its own copy of dwc2-for-klipper-socket with a modifief web_dwc2.py - ###! on line 223, 228 and probably 217 as well + status_msg "Setting up $INSTANCE_COUNT instances of Duet Web Control ..." + while [ $INSTANCE -le $INSTANCE_COUNT ]; do + ### multi instance variables + DWC_LOG=/tmp/dwc-$INSTANCE.log + DWC_CFG="$DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg" + + ### create instance + status_msg "Creating instance #$INSTANCE ..." + create_multi_dwc_startscript + + ### enable instance + sudo systemctl enable dwc-$INSTANCE.service + ok_msg "DWC instance $INSTANCE created!" + + ### launching instance + status_msg "Launching DWC instance $INSTANCE ..." + sudo systemctl start dwc-$INSTANCE + + ### instance counter +1 + INSTANCE=$(expr $INSTANCE + 1) + done + + ### confirm message + CONFIRM_MSG="$INSTANCE_COUNT DWC instances has been set up!" + print_msg && clear_msg + + ### display moonraker ip to the user + print_dwc_ip_list; echo +} + +dwc_cfg_creation(){ + ### default dwc port + DEFAULT_PORT=4750 + + ### get printer config directory + source_kiauh_ini + DWC_CONF_LOC="$klipper_cfg_loc" + + ### reset instances back to 1 again + INSTANCE=1 + + ### declare empty array for ips which get displayed to the user at the end of the setup + HOSTNAME=$(hostname -I | cut -d" " -f1) + dwc_ip_list=() + + ### create single instance dwc2.cfg file + if [ $INSTANCE_COUNT -eq $INSTANCE ]; then + ### set port + PORT=$DEFAULT_PORT + + ### write the ip and port to the ip list for displaying it later to the user + dwc_ip_list+=("$HOSTNAME:$PORT") + + status_msg "Creating dwc2.cfg in $DWC_CONF_LOC" + [ ! -d $DWC_CONF_LOC ] && mkdir -p $DWC_CONF_LOC + if [ ! -f $DWC_CONF_LOC/dwc2.cfg ]; then + create_single_dwcfk_cfg && ok_msg "dwc2.cfg created!" + else + warn_msg "There is already a file called 'dwc2.cfg'!" + warn_msg "Skipping..." + fi + + ### create multi instance moonraker.conf files + else + while [ $INSTANCE -le $INSTANCE_COUNT ]; do + ### set each instance to its own port + PORT=$(expr $DEFAULT_PORT + $INSTANCE - 1) + + ### write the ip and port to the ip list for displaying it later to the user + dwc_ip_list+=("$HOSTNAME:$PORT") + + ### start the creation of each instance + status_msg "Creating dwc2.cfg for instance #$INSTANCE" + [ ! -d $DWC_CONF_LOC/printer_$INSTANCE ] && mkdir -p $DWC_CONF_LOC/printer_$INSTANCE + if [ ! -f $DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg ]; then + create_multi_dwcfk_cfg && ok_msg "dwc2.cfg created!" + else + warn_msg "There is already a file called 'dwc2.cfg'!" + warn_msg "Skipping..." + fi + + ### raise instance counter by 1 + INSTANCE=$(expr $INSTANCE + 1) + done + fi } \ No newline at end of file From d9e697216fead4b1a3a05e476c49fa61e4179e9a Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 21 Jan 2021 23:47:29 +0100 Subject: [PATCH 49/97] fix: small dwc2 related fixes --- kiauh.sh | 1 - scripts/install_dwc2.sh | 20 ++++++++++---------- scripts/status.sh | 18 ++++++++++++++++-- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index cebfa29..9183f3a 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -32,7 +32,6 @@ FLUIDD_DIR=${HOME}/fluidd #dwc2 DWC2FK_DIR=${HOME}/dwc2-for-klipper-socket DWC_ENV_DIR=${HOME}/dwc-env -#DWC2_DIR=${HOME}/sdcard/web DWC2_DIR=${HOME}/duetwebcontrol #octoprint OCTOPRINT_DIR=${HOME}/OctoPrint diff --git a/scripts/install_dwc2.sh b/scripts/install_dwc2.sh index 60fb04b..963fe8f 100755 --- a/scripts/install_dwc2.sh +++ b/scripts/install_dwc2.sh @@ -239,15 +239,15 @@ create_single_dwcfk_cfg(){ /bin/sh -c "cat > $DWC_CONF_LOC/dwc2.cfg" << DWCCFG [webserver] listen_adress: 0.0.0.0 -web_root: ~/duetwebcontrol +web_root: ${HOME}/duetwebcontrol port: ${PORT} [reply_filters] regex: - max_accel: \d+.\d+ - max_accel_to_decel: \d+.\d+ - square_corner_velocity: \d+.\d+ - max_velocity: \d+.\d+ + max_accel: \d+.\d+ + max_accel_to_decel: \d+.\d+ + square_corner_velocity: \d+.\d+ + max_velocity: \d+.\d+ DWCCFG } @@ -256,15 +256,15 @@ create_multi_dwcfk_cfg(){ /bin/sh -c "cat > $DWC_CONF_LOC/printer_$INSTANCE/dwc2.cfg" << DWCCFG [webserver] listen_adress: 0.0.0.0 -web_root: ~/duetwebcontrol +web_root: ${HOME}/duetwebcontrol port: ${PORT} [reply_filters] regex: - max_accel: \d+.\d+ - max_accel_to_decel: \d+.\d+ - square_corner_velocity: \d+.\d+ - max_velocity: \d+.\d+ + max_accel: \d+.\d+ + max_accel_to_decel: \d+.\d+ + square_corner_velocity: \d+.\d+ + max_velocity: \d+.\d+ DWCCFG } diff --git a/scripts/status.sh b/scripts/status.sh index 760ae73..f60d9ba 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -50,10 +50,16 @@ klipper_status(){ dwc2_status(){ dcount=0 dwc2_data=( + SERVICE + $DWC2_DIR $DWC2FK_DIR $DWC_ENV_DIR - $DWC2_DIR ) + ### remove the "SERVICE" entry from the klipper_data array if a klipper service is installed + if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "dwc.service")" ] || [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "dwc-[[:digit:]].service")" ]; then + unset dwc2_data[0] + fi + #count+1 for each found data-item from array for dd in "${dwc2_data[@]}" do @@ -61,8 +67,16 @@ dwc2_status(){ dcount=$(expr $dcount + 1) fi done + + ### count amount of klipper services + if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then + instances=1 + else + instances=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l) + fi + if [ "$dcount" == "${#dwc2_data[*]}" ]; then - DWC2_STATUS="${green}Installed!${default} " + DWC2_STATUS="$(printf "${green}Installed: %-5s${default}" $instances)" elif [ "$dcount" == 0 ]; then DWC2_STATUS="${red}Not installed!${default} " else From c14289a8a6af017d1bc843d222de164bae2b3649 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Mon, 25 Jan 2021 18:50:25 +0100 Subject: [PATCH 50/97] fix: add the new update manager entries to moonraker.conf --- scripts/install_moonraker.sh | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index eda69f0..7fcfdfb 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -230,13 +230,24 @@ trusted_clients: ::1/128 FE80::/10 cors_domains: - http://*.* http://*.local http://my.mainsail.xyz https://my.mainsail.xyz http://app.fluidd.xyz https://app.fluidd.xyz http://$HOSTNAME + +[update_manager] + +[update_manager client mainsail] +type: web +repo: meteyou/mainsail +path: ~/mainsail + +[update_manager client fluidd] +type: web +repo: cadriel/fluidd +path: ~/fluidd MOONRAKERCONF } @@ -261,13 +272,24 @@ trusted_clients: ::1/128 FE80::/10 cors_domains: - http://*.* http://*.local http://my.mainsail.xyz https://my.mainsail.xyz http://app.fluidd.xyz https://app.fluidd.xyz http://$HOSTNAME + +[update_manager] + +[update_manager client mainsail] +type: web +repo: meteyou/mainsail +path: ~/mainsail + +[update_manager client fluidd] +type: web +repo: cadriel/fluidd +path: ~/fluidd MOONRAKERCONF } From e3d242017d7299ec1e281429203ab7518666740e Mon Sep 17 00:00:00 2001 From: th33xitus Date: Mon, 25 Jan 2021 18:50:49 +0100 Subject: [PATCH 51/97] fix: update a comment in nginx configs --- resources/fluidd_nginx.cfg | 2 +- resources/mainsail_nginx.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/fluidd_nginx.cfg b/resources/fluidd_nginx.cfg index bbcd70a..7510ce8 100644 --- a/resources/fluidd_nginx.cfg +++ b/resources/fluidd_nginx.cfg @@ -23,7 +23,7 @@ server { index index.html; server_name _; - #disable max upload size + #max upload size for gcodes (0 = no limit) client_max_body_size 0; location / { diff --git a/resources/mainsail_nginx.cfg b/resources/mainsail_nginx.cfg index 53c97be..7393c11 100644 --- a/resources/mainsail_nginx.cfg +++ b/resources/mainsail_nginx.cfg @@ -23,7 +23,7 @@ server { index index.html; server_name _; - #disable max upload size + #max upload size for gcodes (0 = no limit) client_max_body_size 0; location / { From 65062bdfda4cb2decd04c22e2abc87856e490402 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Mon, 25 Jan 2021 18:51:31 +0100 Subject: [PATCH 52/97] fix: update the macros used for pause, cancel resume by mainsail and fluidd to better ones --- resources/kiauh_macros.cfg | 65 +++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/resources/kiauh_macros.cfg b/resources/kiauh_macros.cfg index ede2aa2..96e7ad6 100644 --- a/resources/kiauh_macros.cfg +++ b/resources/kiauh_macros.cfg @@ -6,33 +6,9 @@ ######################################################################################### [pause_resume] + [display_status] -[gcode_macro PAUSE] -rename_existing: BASE_PAUSE -default_parameter_X: 0 #edit to your park position -default_parameter_Y: 0 #edit to your park position -default_parameter_Z: 10 #edit to your park position -default_parameter_E: 1 #edit to your retract length -gcode: - SAVE_GCODE_STATE NAME=PAUSE_state - BASE_PAUSE - G91 - G1 E-{E} F2100 - G1 Z{Z} - G90 - G1 X{X} Y{Y} F6000 - -[gcode_macro RESUME] -rename_existing: BASE_RESUME -default_parameter_E: 1 #edit to your retract length -gcode: - G91 - G1 E{E} F2100 - G90 - RESTORE_GCODE_STATE NAME=PAUSE_state MOVE=1 - BASE_RESUME - [gcode_macro CANCEL_PRINT] rename_existing: BASE_CANCEL_PRINT gcode: @@ -41,5 +17,44 @@ gcode: SDCARD_RESET_FILE BASE_CANCEL_PRINT +[gcode_macro PAUSE] +rename_existing: BASE_PAUSE +# change this if you need more or less extrusion +variable_extrude: 1.0 +gcode: + ##### read E from pause macro ##### + {% set E = printer["gcode_macro PAUSE"].extrude|float %} + ##### set park positon for x and y ##### + # default is your max posion from your printer.cfg + {% set x_park = printer.toolhead.axis_maximum.x|float - 5.0 %} + {% set y_park = printer.toolhead.axis_maximum.y|float - 5.0 %} + ##### calculate save lift position ##### + {% set max_z = printer.toolhead.axis_maximum.z|float %} + {% set act_z = printer.toolhead.position.x|float %} + {% if act_z < (max_z - 2.0) %} + {% set z_safe = 2.0 %} + {% else %} + {% set z_safe = max_z - act_z %} + {% endif %} + ##### end of definitions ##### + SAVE_GCODE_STATE NAME=PAUSE_state + BASE_PAUSE + G91 + G1 E-{E} F2100 + G1 Z{z_safe} F900 + G90 + G1 X{x_park} Y{y_park} F6000 + +[gcode_macro RESUME] +rename_existing: BASE_RESUME +gcode: + ##### read E from pause macro ##### + {% set E = printer["gcode_macro PAUSE"].extrude|float %} + ##### end of definitions ##### + G91 + G1 E{E} F2100 + RESTORE_GCODE_STATE NAME=PAUSE_state + BASE_RESUME + ######################################################################################### ######################################################################################### From f10a604f97b5515326fff8cd62427a3d42497f14 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Mon, 25 Jan 2021 19:09:30 +0100 Subject: [PATCH 53/97] fix: small clean-up --- kiauh.sh | 2 ++ scripts/install_dwc2.sh | 16 +++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index 9183f3a..ce86d7a 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -46,7 +46,9 @@ BACKUP_DIR=${HOME}/kiauh-backups KLIPPER_REPO=https://github.com/KevinOConnor/klipper.git ARKSINE_REPO=https://github.com/Arksine/klipper.git DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git +###TODO use my own dwc2-for-klipper-socket repo as long as the needed start argument PR is not merged yet DWC2FK_REPO=https://github.com/th33xitus/dwc2-for-klipper-socket.git +#DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper-socket.git MOONRAKER_REPO=https://github.com/Arksine/moonraker.git KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git #branches diff --git a/scripts/install_dwc2.sh b/scripts/install_dwc2.sh index fc72b53..3bcb491 100755 --- a/scripts/install_dwc2.sh +++ b/scripts/install_dwc2.sh @@ -1,9 +1,9 @@ ### base variables SYSTEMDDIR="/etc/systemd/system" DWC_ENV="${HOME}/dwc-env" -DWC2_DIR="${HOME}/sdcard/web" +DWC2_DIR="${HOME}/duetwebcontrol" -system_check_dwc2(){ +system_check_dwc(){ ### check system for an installed octoprint service if systemctl is-enabled octoprint.service -q 2>/dev/null; then OCTOPRINT_ENABLED="true" @@ -11,10 +11,10 @@ system_check_dwc2(){ } dwc_setup_dialog(){ - status_msg "Initializing DWC2 installation ..." + status_msg "Initializing Duet Web Control installation ..." ### check system for several requirements before initializing the dwc2 installation - system_check_dwc2 + system_check_dwc ### 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 @@ -150,7 +150,7 @@ download_dwc_webui(){ [ ! -d $DWC2_DIR ] && mkdir -p $DWC2_DIR cd $DWC2_DIR && wget $GET_DWC2_URL ok_msg "Download complete!" - status_msg "Unzipping archive ..." + status_msg "Extracting archive ..." unzip -q -o *.zip for f_ in $(find . | grep '.gz') do @@ -160,10 +160,8 @@ download_dwc_webui(){ status_msg "Writing DWC version to file ..." echo $GET_DWC2_URL | cut -d/ -f8 > $DWC2_DIR/.version ok_msg "Done!" - status_msg "Do a little cleanup ..." - rm -rf DuetWebControl-SD.zip - ok_msg "Done!" - ok_msg "DWC2 Web UI installed!" + status_msg "Remove downloaded archive ..." + rm -rf *.zip && ok_msg "Done!" && ok_msg "Duet Web Control installed!" } ############################################################################################## From bc53de626f09cacaab58278eb2524416e8918f81 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 27 Jan 2021 18:13:21 +0100 Subject: [PATCH 54/97] fix: version comparing and displaying issues --- scripts/install_klipper_webui.sh | 4 ++-- scripts/status.sh | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index 3b67992..f40d9cb 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -242,11 +242,11 @@ select_fluidd_port(){ } get_mainsail_ver(){ - MAINSAIL_VERSION=$(curl -s https://api.github.com/repositories/240875926/releases | grep tag_name | cut -d'"' -f4 | cut -d"v" -f2 | head -1) + MAINSAIL_VERSION=$(curl -s https://api.github.com/repositories/240875926/releases | grep tag_name | cut -d'"' -f4 | head -1) } get_fluidd_ver(){ - FLUIDD_VERSION=$(curl -s https://api.github.com/repositories/295836951/releases | grep tag_name | cut -d'"' -f4 | cut -d"v" -f2 | head -1) + FLUIDD_VERSION=$(curl -s https://api.github.com/repositories/295836951/releases | grep tag_name | cut -d'"' -f4 | head -1) } mainsail_setup(){ diff --git a/scripts/status.sh b/scripts/status.sh index f60d9ba..c1cbd25 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -437,16 +437,16 @@ compare_mainsail_versions(){ read_local_mainsail_version && read_remote_mainsail_version if [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER == $MAINSAIL_REMOTE_VER ]]; then #printf fits the string for displaying it in the ui to a total char length of 12 - MAINSAIL_LOCAL_VER="${green}$(printf "v%-11s" "$MAINSAIL_LOCAL_VER")${default}" - MAINSAIL_REMOTE_VER="${green}$(printf "v%-11s" "$MAINSAIL_REMOTE_VER")${default}" + MAINSAIL_LOCAL_VER="${green}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${default}" + MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" elif [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER != $MAINSAIL_REMOTE_VER ]]; then - MAINSAIL_LOCAL_VER="${yellow}$(printf "v%-11s" "$MAINSAIL_LOCAL_VER")${default}" - MAINSAIL_REMOTE_VER="${green}$(printf "v%-11s" "$MAINSAIL_REMOTE_VER")${default}" + MAINSAIL_LOCAL_VER="${yellow}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${default}" + MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" # set flag for the multi update function MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail) else MAINSAIL_LOCAL_VER=$NONE - MAINSAIL_REMOTE_VER="${green}$(printf "v%-11s" "$MAINSAIL_REMOTE_VER")${default}" + MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" MAINSAIL_UPDATE_AVAIL="false" fi } @@ -476,16 +476,16 @@ compare_fluidd_versions(){ read_local_fluidd_version && read_remote_fluidd_version if [[ $FLUIDD_VER_FOUND = "true" ]] && [[ $FLUIDD_LOCAL_VER == $FLUIDD_REMOTE_VER ]]; then #printf fits the string for displaying it in the ui to a total char length of 12 - FLUIDD_LOCAL_VER="${green}$(printf "v%-11s" "$FLUIDD_LOCAL_VER")${default}" - FLUIDD_REMOTE_VER="${green}$(printf "v%-11s" "$FLUIDD_REMOTE_VER")${default}" + FLUIDD_LOCAL_VER="${green}$(printf "%-12s" "$FLUIDD_LOCAL_VER")${default}" + FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}" elif [[ $FLUIDD_VER_FOUND = "true" ]] && [[ $FLUIDD_LOCAL_VER != $FLUIDD_REMOTE_VER ]]; then - FLUIDD_LOCAL_VER="${yellow}$(printf "v%-11s" "$FLUIDD_LOCAL_VER")${default}" - FLUIDD_REMOTE_VER="${green}$(printf "v%-11s" "$FLUIDD_REMOTE_VER")${default}" + FLUIDD_LOCAL_VER="${yellow}$(printf "%-12s" "$FLUIDD_LOCAL_VER")${default}" + FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}" # set flag for the multi update function FLUIDD_UPDATE_AVAIL="true" && update_arr+=(update_fluidd) else FLUIDD_LOCAL_VER=$NONE - FLUIDD_REMOTE_VER="${green}$(printf "v%-11s" "$FLUIDD_REMOTE_VER")${default}" + FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}" FLUIDD_UPDATE_AVAIL="false" fi } From fb52c7e4ab6cbe9788b0a115f3f709d92ceb8ee0 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 27 Jan 2021 18:51:48 +0100 Subject: [PATCH 55/97] fix: relocate the kiauh.ini file to ~/.config to keep values even after reinstalling kiauh. --- kiauh.sh | 2 +- scripts/functions.sh | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/kiauh.sh b/kiauh.sh index ce86d7a..33e781c 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -39,7 +39,7 @@ OCTOPRINT_DIR=${HOME}/OctoPrint KLIPPERSCREEN_DIR=${HOME}/KlipperScreen KLIPPERSCREEN_ENV_DIR=${HOME}/.KlipperScreen-env #misc -INI_FILE=${SRCDIR}/kiauh/kiauh.ini +INI_FILE=${HOME}/.config/kiauh.ini BACKUP_DIR=${HOME}/kiauh-backups ### set github repos diff --git a/scripts/functions.sh b/scripts/functions.sh index 1e30472..e8823c2 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -464,6 +464,10 @@ write_printer_cfg(){ } init_ini(){ + ### copy an existing kiauh.ini to its new location to keep all possible saved values + if [ -f ${SRCDIR}/kiauh/kiauh.ini ] || [ ! -f $INI_FILE ]; then + cp ${SRCDIR}/kiauh/kiauh.ini $INI_FILE + fi 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 From e233d8435a738fbdd6d32f90e7d21ab0a1a28bb0 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 27 Jan 2021 19:57:19 +0100 Subject: [PATCH 56/97] fix: new date format, fix a typo, restructure backup.sh --- kiauh.sh | 2 +- scripts/backup.sh | 106 +++++++++++++++++++++++++--------------------- 2 files changed, 59 insertions(+), 49 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index 33e781c..0727eab 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -69,7 +69,7 @@ title_msg(){ echo -e "${cyan}$1${default}" } get_date(){ - current_date=$(date +"%Y%m%d_%H%M") + current_date=$(date +"%y%m%d-%H%M") } print_unkown_cmd(){ ERROR_MSG="Invalid command!" diff --git a/scripts/backup.sh b/scripts/backup.sh index 9b27ecd..a27d62a 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -5,52 +5,6 @@ check_for_backup_dir(){ fi } -backup_printer_cfg(){ - check_for_backup_dir - if [ -f $PRINTER_CFG ]; then - get_date - status_msg "Create backup of printer.cfg ..." - cp $PRINTER_CFG $BACKUP_DIR/printer.cfg."$current_date".backup && ok_msg "Backup complete!" - else - ok_msg "No printer.cfg found! Skipping backup ..." - fi -} - -backup_klipper_config_dir(){ - source_kiauh_ini - check_for_backup_dir - if [ -d "$klipper_cfg_loc" ]; then - get_date - status_msg "Create backup of the Klipper config directory ..." - config_folder_name="$(echo "$klipper_cfg_loc" | rev | cut -d"/" -f1 | rev)" - cp -r "$klipper_cfg_loc" "$BACKUP_DIR/$config_folder_name.$current_date.backup" && ok_msg "Backup complete!" - echo - else - ok_msg "No config directory found! Skipping backup ..." - echo - fi -} - -backup_moonraker_conf(){ - check_for_backup_dir - if [ -f ${HOME}/moonraker.conf ]; then - get_date - status_msg "Create backup of moonraker.conf ..." - cp ${HOME}/moonraker.conf $BACKUP_DIR/moonraker.conf."$current_date".backup && ok_msg "Backup complete!" - else - ok_msg "No moonraker.conf found! Skipping backup ..." - fi -} - -read_bb4u_stat(){ - source_kiauh_ini - if [ ! "$backup_before_update" = "true" ]; then - BB4U_STATUS="${green}[Enable]${default} backups before updating " - else - BB4U_STATUS="${red}[Disable]${default} backups before updating " - fi -} - toggle_backups(){ source_kiauh_ini if [ "$backup_before_update" = "true" ]; then @@ -72,14 +26,70 @@ bb4u(){ fi } +read_bb4u_stat(){ + source_kiauh_ini + if [ ! "$backup_before_update" = "true" ]; then + BB4U_STATUS="${green}[Enable]${default} backups before updating " + else + BB4U_STATUS="${red}[Disable]${default} backups before updating " + fi +} + +############################################################################################## +#********************************************************************************************# +############################################################################################## + +backup_printer_cfg(){ + check_for_backup_dir + if [ -f $PRINTER_CFG ]; then + get_date + status_msg "Timestamp: $current_date" + status_msg "Create backup of printer.cfg ..." + cp $PRINTER_CFG $BACKUP_DIR/printer.cfg."$current_date".backup && ok_msg "Backup complete!" + else + ok_msg "No printer.cfg found! Skipping backup ..." + fi +} + +backup_klipper_config_dir(){ + source_kiauh_ini + check_for_backup_dir + if [ -d "$klipper_cfg_loc" ]; then + get_date + status_msg "Timestamp: $current_date" + status_msg "Create backup of the Klipper config directory ..." + config_folder_name="$(echo "$klipper_cfg_loc" | rev | cut -d"/" -f1 | rev)" + mkdir -p $BACKUP_DIR/$config_folder_name/$current_date + cp -r "$klipper_cfg_loc" "$_" && ok_msg "Backup complete!" + echo + else + ok_msg "No config directory found! Skipping backup ..." + echo + fi +} + + +###TODO re-evaluate if this function is still needed (just backup the full klipper_config dir instead?) +backup_moonraker_conf(){ + check_for_backup_dir + if [ -f ${HOME}/moonraker.conf ]; then + get_date + status_msg "Timestamp: $current_date" + status_msg "Create backup of moonraker.conf ..." + cp ${HOME}/moonraker.conf $BACKUP_DIR/moonraker.conf."$current_date".backup && ok_msg "Backup complete!" + else + ok_msg "No moonraker.conf found! Skipping backup ..." + fi +} + backup_klipper(){ - if [ -d $KLIPPER_DIR ] && [ -d $KLIPPY_ENV_DIR ]; then + if [ -d $KLIPPER_DIR ] && [ -d $KLIPPY_ENV ]; then status_msg "Creating Klipper backup ..." check_for_backup_dir get_date status_msg "Timestamp: $current_date" mkdir -p $BACKUP_DIR/klipper-backups/"$current_date" - cp -r $KLIPPER_DIR $_ && cp -r $KLIPPY_ENV_DIR $_ && ok_msg "Backup complete!" + cp -r $KLIPPER_DIR $_ && cp -r $KLIPPY_ENV $_ && ok_msg "Backup complete!" else ERROR_MSG=" Can't backup klipper and/or klipper-env directory! Not found!" fi From 69eb96d006efc52eeb347c0fbc5b8b2d8cd56b72 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 28 Jan 2021 16:20:35 +0100 Subject: [PATCH 57/97] fix: typo in moonraker backup function --- scripts/backup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index a27d62a..f7f5057 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -136,13 +136,13 @@ backup_fluidd(){ } backup_moonraker(){ - if [ -d $MOONRAKER_DIR ] && [ -d $MOONRAKER_ENV_DIR ]; then + if [ -d $MOONRAKER_DIR ] && [ -d $MOONRAKER_ENV ]; then status_msg "Creating Moonraker backup ..." check_for_backup_dir get_date status_msg "Timestamp: $current_date" mkdir -p $BACKUP_DIR/moonraker-backups/"$current_date" - cp -r $MOONRAKER_DIR $_ && cp -r $MOONRAKER_ENV_DIR $_ && ok_msg "Backup complete!" + cp -r $MOONRAKER_DIR $_ && cp -r $MOONRAKER_ENV $_ && ok_msg "Backup complete!" else ERROR_MSG=" Can't backup moonraker and/or moonraker-env directory! Not found!" fi From 8ad7f5d47c81e0f829c003039e3e5dc058c9f754 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 28 Jan 2021 16:21:24 +0100 Subject: [PATCH 58/97] fix: remove update manager question. thanks to the recent changes to the update manager, mainsail and fluidd can be supported at the same time. --- scripts/install_klipper_webui.sh | 64 +------------------------------- 1 file changed, 1 insertion(+), 63 deletions(-) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index f40d9cb..b4f8a50 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -57,9 +57,6 @@ install_mainsail(){ ### ask user to install the recommended webinterface macros get_user_selection_kiauh_macros - ### ask user to enable the moonraker update manager - enable_update_manager "mainsail" - ### creating the mainsail nginx cfg set_nginx_cfg "mainsail" @@ -86,9 +83,6 @@ install_fluidd(){ ### ask user to install the recommended webinterface macros get_user_selection_kiauh_macros - ### ask user to enable the moonraker update manager - enable_update_manager "fluidd" - ### creating the fluidd nginx cfg set_nginx_cfg "fluidd" @@ -287,60 +281,4 @@ fluidd_setup(){ status_msg "Remove downloaded archive ..." rm -rf *.zip && ok_msg "Done!" && ok_msg "Fluidd installation complete!" echo -} - -enable_update_manager(){ - source_kiauh_ini - ### ask user if he wants to enable the moonraker update manager - while true; do - echo - top_border - echo -e "| Do you want to enable the Moonraker Update Manager | " - echo -e "| for the selected webinterface? | " - hr - echo -e "| ${yellow}Please note:${default} | " - echo -e "| Entries for an already enabled update manager will be | " - echo -e "| overwritten if you decide to choose 'Yes'! | " - bottom_border - echo - read -p "${cyan}###### Enable Update Manager? (Y/n):${default} " yn - case "$yn" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - if [ $1 = "mainsail" ]; then - MOONRAKER_UPDATE_MANAGER="[update_manager]\nclient_repo: meteyou/mainsail\nclient_path: /home/${USER}/mainsail" - elif [ $1 = "fluidd" ]; then - MOONRAKER_UPDATE_MANAGER="[update_manager]\nclient_repo: cadriel/fluidd\nclient_path: /home/${USER}/fluidd" - else - unset MOONRAKER_UPDATE_MANAGER - fi - ### handle single moonraker install - if [ -f /etc/systemd/system/moonraker.service ]; then - ### delete existing entries - sed -i "/update_manager/d" $klipper_cfg_loc/moonraker.conf - sed -i "/client_repo/d" $klipper_cfg_loc/moonraker.conf - sed -i "/client_path/d" $klipper_cfg_loc/moonraker.conf - echo -e $MOONRAKER_UPDATE_MANAGER >> $klipper_cfg_loc/moonraker.conf - fi - ### handle multi moonraker installs - if ls /etc/systemd/system/moonraker-*.service 2>/dev/null 1>&2; then - for moonraker_conf in $(find $klipper_cfg_loc/printer_*/moonraker.conf); do - ### delete existing entries - sed -i "/update_manager/d" $moonraker_conf - sed -i "/client_repo/d" $moonraker_conf - sed -i "/client_path/d" $moonraker_conf - echo -e $MOONRAKER_UPDATE_MANAGER >> $moonraker_conf - done - fi - moonraker_service "restart" - break;; - N|n|No|no) - echo -e "###### > No" - unset MOONRAKER_UPDATE_MANAGER - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done -} +} \ No newline at end of file From b2b19f446b0a272f82909739ffcea7003adfd07f Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 28 Jan 2021 16:25:25 +0100 Subject: [PATCH 59/97] fix: use $klipper_cfg_loc in klipperscreen system check --- scripts/install_klipperscreen.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/install_klipperscreen.sh b/scripts/install_klipperscreen.sh index 142c153..80c7d0c 100755 --- a/scripts/install_klipperscreen.sh +++ b/scripts/install_klipperscreen.sh @@ -30,7 +30,8 @@ python3_check(){ } system_check_klipperscreen(){ - if [ ! -e ${HOME}/klipper_config/KlipperScreen.log ]; then + source_kiauh_ini + if [ ! -e $klipper_cfg_loc/KlipperScreen.log ]; then KLIPPERSCREEN_SL_FOUND="false" else KLIPPERSCREEN_SL_FOUND="true" From 19aed15db0c9904f63ba8f63231cd6c1df932fd6 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 28 Jan 2021 16:44:05 +0100 Subject: [PATCH 60/97] fix: typos --- scripts/functions.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index e8823c2..000b271 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -257,8 +257,8 @@ restart_klipperscreen(){ restart_nginx(){ if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "nginx.service")" ]; then - status_msg "Restarting Nginx Service ..." - sudo systemctl restart nginx && ok_msg "Nginx Service restarted!" + status_msg "Restarting NGINX Service ..." + sudo systemctl restart nginx && ok_msg "NGINX Service restarted!" fi } From 254e1b8244827b129aec0f1861ede2994112b1a3 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 28 Jan 2021 16:45:12 +0100 Subject: [PATCH 61/97] fix: create mainsail or fluidd nginx config from template --- ...uidd_nginx.cfg => klipper_webui_nginx.cfg} | 12 ++-- resources/mainsail_nginx.cfg | 59 ------------------- scripts/network_functions.sh | 3 +- 3 files changed, 8 insertions(+), 66 deletions(-) rename resources/{fluidd_nginx.cfg => klipper_webui_nginx.cfg} (88%) delete mode 100644 resources/mainsail_nginx.cfg diff --git a/resources/fluidd_nginx.cfg b/resources/klipper_webui_nginx.cfg similarity index 88% rename from resources/fluidd_nginx.cfg rename to resources/klipper_webui_nginx.cfg index 8e6dd70..c0db5cc 100644 --- a/resources/fluidd_nginx.cfg +++ b/resources/klipper_webui_nginx.cfg @@ -1,11 +1,11 @@ -# /etc/nginx/sites-available/fluidd +# /etc/nginx/sites-available/<> server { listen 80; listen [::]:80; - access_log /var/log/nginx/fluidd-access.log; - error_log /var/log/nginx/fluidd-error.log; + access_log /var/log/nginx/<>-access.log; + error_log /var/log/nginx/<>-error.log; #disable this section on smaller hardware like a pi zero gzip on; @@ -17,8 +17,8 @@ server { gzip_http_version 1.1; gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/json application/xml; - #web_path from fluidd static files - root /home/pi/fluidd; + #web_path from <> static files + root /home/pi/<>; index index.html; server_name _; @@ -56,4 +56,4 @@ server { location /webcam/ { proxy_pass http://mjpgstreamer/; } -} +} \ No newline at end of file diff --git a/resources/mainsail_nginx.cfg b/resources/mainsail_nginx.cfg deleted file mode 100644 index 8e0adef..0000000 --- a/resources/mainsail_nginx.cfg +++ /dev/null @@ -1,59 +0,0 @@ -# /etc/nginx/sites-available/mainsail - -server { - listen 80; - listen [::]:80; - - access_log /var/log/nginx/mainsail-access.log; - error_log /var/log/nginx/mainsail-error.log; - - #disable this section on smaller hardware like a pi zero - gzip on; - gzip_vary on; - gzip_proxied any; - gzip_proxied expired no-cache no-store private auth; - gzip_comp_level 4; - gzip_buffers 16 8k; - gzip_http_version 1.1; - gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/json application/xml; - - #web_path from mainsail static files - root /home/pi/mainsail; - - index index.html; - server_name _; - - #max upload size for gcodes (0 = no limit) - client_max_body_size 0; - - location / { - try_files $uri $uri/ /index.html; - } - - location = /index.html { - add_header Cache-Control "no-store, no-cache, must-revalidate"; - } - - location /websocket { - proxy_pass http://apiserver/websocket; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection $connection_upgrade; - proxy_set_header Host $http_host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_read_timeout 86400; - } - - location ~ ^/(printer|api|access|machine|server)/ { - proxy_pass http://apiserver$request_uri; - proxy_set_header Host $http_host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Scheme $scheme; - } - - location /webcam/ { - proxy_pass http://mjpgstreamer/; - } -} diff --git a/scripts/network_functions.sh b/scripts/network_functions.sh index 9002638..23fb554 100755 --- a/scripts/network_functions.sh +++ b/scripts/network_functions.sh @@ -6,8 +6,9 @@ set_nginx_cfg(){ #execute operations status_msg "Creating Nginx configuration for $1 ..." #copy content from resources to the respective nginx config file - cat ${SRCDIR}/kiauh/resources/$1_nginx.cfg > ${SRCDIR}/kiauh/resources/$1 + cat ${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg > ${SRCDIR}/kiauh/resources/$1 ##edit the nginx config file before moving it + sed -i "s/<>/$1/g" ${SRCDIR}/kiauh/resources/$1 if [ "$SET_LISTEN_PORT" != "$DEFAULT_PORT" ]; then status_msg "Configuring port for $1 ..." #set listen port ipv4 From d01140638aeda65de2b6e077c8c0259c41547230 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 28 Jan 2021 16:48:36 +0100 Subject: [PATCH 62/97] fix: some typos when creating minimal cfg --- scripts/install_klipper.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/install_klipper.sh b/scripts/install_klipper.sh index a964c0e..05f1107 100755 --- a/scripts/install_klipper.sh +++ b/scripts/install_klipper.sh @@ -115,9 +115,10 @@ MULTI_STARTSCRIPT create_minimal_printer_cfg(){ /bin/sh -c "cat > $1" << MINIMAL_CFG [mcu] -serial: /dev/serial/by-id/ +serial: /dev/serial/by-id/ [pause_resume] + [display_status] [virtual_sdcard] @@ -125,8 +126,8 @@ path: ~/gcode_files [printer] kinematics: none -max_velocity: 1 -max_accel: 1 +max_velocity: 1000 +max_accel: 1000 MINIMAL_CFG } From 1c92987b4248fc622ef765744885ae6805065ad5 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 28 Jan 2021 17:50:35 +0100 Subject: [PATCH 63/97] fix: logic error --- scripts/functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index 000b271..db95e05 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -465,7 +465,7 @@ write_printer_cfg(){ init_ini(){ ### copy an existing kiauh.ini to its new location to keep all possible saved values - if [ -f ${SRCDIR}/kiauh/kiauh.ini ] || [ ! -f $INI_FILE ]; then + if [ -f ${SRCDIR}/kiauh/kiauh.ini ] && [ ! -f $INI_FILE ]; then cp ${SRCDIR}/kiauh/kiauh.ini $INI_FILE fi if [ ! -f $INI_FILE ]; then From a6156ebdf345103efd0396d768726378b5c0c96f Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 28 Jan 2021 17:56:23 +0100 Subject: [PATCH 64/97] fix: make kiauh.ini a hidden file in users home folder --- kiauh.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kiauh.sh b/kiauh.sh index 0727eab..5c8b2b3 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -39,7 +39,7 @@ OCTOPRINT_DIR=${HOME}/OctoPrint KLIPPERSCREEN_DIR=${HOME}/KlipperScreen KLIPPERSCREEN_ENV_DIR=${HOME}/.KlipperScreen-env #misc -INI_FILE=${HOME}/.config/kiauh.ini +INI_FILE=${HOME}/.kiauh.ini BACKUP_DIR=${HOME}/kiauh-backups ### set github repos From 4652e5c177c4ebfc87d8785e21b21c326da16d54 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 28 Jan 2021 18:02:21 +0100 Subject: [PATCH 65/97] fix: added one more cors domain and changed ip-range for local network --- scripts/install_moonraker.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index ea7c491..0ab0058 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -249,7 +249,7 @@ MOONRAKERCONF create_multi_moonraker_conf(){ HOSTNAME=$(hostname -I | cut -d" " -f1) - LOCAL_NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-3).0/24" + LOCAL_NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-3).0/16" /bin/sh -c "cat > $MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.conf" << MOONRAKERCONF [server] @@ -269,6 +269,7 @@ trusted_clients: FE80::/10 cors_domains: http://*.local + https://*.local http://my.mainsail.xyz https://my.mainsail.xyz http://app.fluidd.xyz From 0c4f1a53784f30bb1b3f4d3f6930d7cc4c279fa2 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 28 Jan 2021 18:52:53 +0100 Subject: [PATCH 66/97] fix: rework/refactor remove functions --- scripts/remove.sh | 280 +++++++++++++++++++++++----------------------- 1 file changed, 142 insertions(+), 138 deletions(-) diff --git a/scripts/remove.sh b/scripts/remove.sh index 8988302..10e83d9 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -69,9 +69,13 @@ remove_klipper(){ 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!" + if [ -d $KLIPPER_DIR ]; then + status_msg "Removing Klipper directory ..." + rm -rf $KLIPPER_DIR && ok_msg "Directory removed!" + fi + if [ -d $KLIPPY_ENV ]; then + status_msg "Removing klippy-env directory ..." + rm -rf $KLIPPY_ENV && ok_msg "Directory removed!" fi CONFIRM_MSG=" Klipper was successfully removed!" @@ -81,62 +85,68 @@ remove_klipper(){ ############################################################# remove_dwc2(){ - data_arr=( - /etc/init.d/dwc - /etc/default/dwc - /etc/systemd/system/dwc.service - $DWC2FK_DIR - $DWC_ENV_DIR - $DWC2_DIR - /etc/nginx/sites-available/dwc2 - /etc/nginx/sites-enabled/dwc2 - ) - print_error "DWC2-for-Klipper-Socket &\n DWC2 Web UI" && data_count=() - if [ "$ERROR_MSG" = "" ]; then - if systemctl is-active dwc -q; then - status_msg "Stopping DWC2-for-Klipper-Socket Service ..." - sudo systemctl stop dwc && sudo systemctl disable dwc - ok_msg "Service stopped!" - fi - #remove if init.d service - if [[ -e /etc/init.d/dwc || -e /etc/default/dwc ]]; then - status_msg "Init.d Service found ..." - status_msg "Removing DWC2-for-Klipper-Socket Service ..." - sudo rm -rf /etc/init.d/dwc /etc/default/dwc - sudo update-rc.d -f dwc remove - ok_msg "DWC2-for-Klipper-Socket Service removed!" - fi - #remove if systemd service - if [ -e /etc/systemd/system/dwc.service ]; then - status_msg "Systemd Service found ..." - status_msg "Removing DWC2-for-Klipper-Socket Service ..." - sudo rm -rf /etc/systemd/system/dwc.service - ok_msg "DWC2-for-Klipper-Socket Service removed!" - fi - if [ -d $DWC2FK_DIR ]; then - status_msg "Removing DWC2-for-Klipper-Socket directory ..." - rm -rf $DWC2FK_DIR && ok_msg "Directory removed!" - fi - if [ -d $DWC_ENV_DIR ]; then - status_msg "Removing DWC2-for-Klipper-Socket virtualenv ..." - rm -rf $DWC_ENV_DIR && ok_msg "File removed!" - fi - if [ -d $DWC2_DIR ]; then - status_msg "Removing DWC2 directory ..." - rm -rf $DWC2_DIR && ok_msg "Directory removed!" - fi - #remove dwc2 config for nginx - if [ -e /etc/nginx/sites-available/dwc2 ]; then - status_msg "Removing DWC2 configuration for Nginx ..." - sudo rm /etc/nginx/sites-available/dwc2 && ok_msg "File removed!" - fi - #remove dwc2 symlink for nginx - if [ -L /etc/nginx/sites-enabled/dwc2 ]; then - status_msg "Removing DWC2 Symlink for Nginx ..." - sudo rm /etc/nginx/sites-enabled/dwc2 && ok_msg "File removed!" - fi - CONFIRM_MSG=" DWC2-for-Klipper-Socket & DWC2 successfully removed!" + ### remove "legacy" init.d service + if [[ -e /etc/init.d/dwc || -e /etc/default/dwc ]]; then + status_msg "Removing DWC2-for-Klipper-Socket Service ..." + sudo systemctl stop dwc + sudo systemctl disable dwc + sudo rm -rf /etc/init.d/dwc /etc/default/dwc + sudo update-rc.d -f dwc remove + sudo systemctl daemon-reload + ok_msg "DWC2-for-Klipper-Socket Service removed!" fi + + ### remove single instance + if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "dwc.service")" ]; then + status_msg "Removing DWC2-for-Klipper-Socket Service ..." + sudo systemctl stop dwc + sudo systemctl disable dwc + sudo rm -f $SYSTEMDDIR/dwc.service + ok_msg "DWC2-for-Klipper-Socket Service removed!" + fi + if [ -f /tmp/dwc.log ]; then + status_msg "Removing /tmp/dwc.log ..." && rm -f /tmp/dwc.log && ok_msg "Done!" + fi + + ### remove multi instance services + if [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "dwc-[[:digit:]].service")" ]; then + status_msg "Removing DWC2-for-Klipper-Socket Services ..." + for service in $(find $SYSTEMDDIR -maxdepth 1 -name "dwc-*.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 "dwc-*.log")" ]; then + for logfile in $(find /tmp -maxdepth 1 -name "dwc-*.log") + do + status_msg "Removing $logfile ..." && rm -f $logfile && ok_msg "Done!" + done + fi + + ### reloading units + sudo systemctl daemon-reload + + ### removing the rest of the folders + if [ -d $DWC2FK_DIR ]; then + status_msg "Removing DWC2-for-Klipper-Socket directory ..." + rm -rf $DWC2FK_DIR && ok_msg "Directory removed!" + fi + if [ -d $DWC_ENV_DIR ]; then + status_msg "Removing DWC2-for-Klipper-Socket virtualenv ..." + rm -rf $DWC_ENV_DIR && ok_msg "Directory removed!" + fi + if [ -d $DWC2_DIR ]; then + status_msg "Removing DWC2 directory ..." + rm -rf $DWC2_DIR && ok_msg "Directory removed!" + fi + + CONFIRM_MSG=" DWC2-for-Klipper-Socket was successfully removed!" } ############################################################# @@ -189,12 +199,6 @@ remove_moonraker(){ ###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 ..." @@ -210,6 +214,16 @@ remove_moonraker(){ status_msg "Removing API Key ..." && rm ${HOME}/.moonraker_api_key && ok_msg "Done!" fi + ###removing moonraker and moonraker-env folder + if [ -d $MOONRAKER_DIR ]; then + status_msg "Removing Moonraker directory ..." + rm -rf $MOONRAKER_DIR && ok_msg "Directory removed!" + fi + if [ -d $MOONRAKER_ENV ]; then + status_msg "Removing moonraker-env directory ..." + rm -rf $MOONRAKER_ENV && ok_msg "Directory removed!" + fi + CONFIRM_MSG=" Moonraker was successfully removed!" } @@ -217,57 +231,47 @@ remove_moonraker(){ ############################################################# remove_mainsail(){ - data_arr=( - $MAINSAIL_DIR - /etc/nginx/sites-available/mainsail - /etc/nginx/sites-enabled/mainsail - ) - print_error "Mainsail" && data_count=() - if [ "$ERROR_MSG" = "" ]; then - #remove mainsail dir - if [ -d $MAINSAIL_DIR ]; then - status_msg "Removing Mainsail directory ..." - rm -rf $MAINSAIL_DIR && ok_msg "Directory removed!" - fi - #remove mainsail config for nginx - if [ -e /etc/nginx/sites-available/mainsail ]; then - status_msg "Removing Mainsail configuration for Nginx ..." - sudo rm /etc/nginx/sites-available/mainsail && ok_msg "File removed!" - fi - #remove mainsail symlink for nginx - if [ -L /etc/nginx/sites-enabled/mainsail ]; then - status_msg "Removing Mainsail Symlink for Nginx ..." - sudo rm /etc/nginx/sites-enabled/mainsail && ok_msg "File removed!" - fi - CONFIRM_MSG="Mainsail successfully removed!" + ### remove mainsail dir + if [ -d $MAINSAIL_DIR ]; then + status_msg "Removing Mainsail directory ..." + rm -rf $MAINSAIL_DIR && ok_msg "Directory removed!" fi + + ### remove mainsail config for nginx + if [ -e /etc/nginx/sites-available/mainsail ]; then + status_msg "Removing Mainsail configuration for Nginx ..." + sudo rm /etc/nginx/sites-available/mainsail && ok_msg "File removed!" + fi + + ### remove mainsail symlink for nginx + if [ -L /etc/nginx/sites-enabled/mainsail ]; then + status_msg "Removing Mainsail Symlink for Nginx ..." + sudo rm /etc/nginx/sites-enabled/mainsail && ok_msg "File removed!" + fi + + CONFIRM_MSG="Mainsail successfully removed!" } remove_fluidd(){ - data_arr=( - $FLUIDD_DIR - /etc/nginx/sites-available/fluidd - /etc/nginx/sites-enabled/fluidd - ) - print_error "Fluidd" && data_count=() - if [ "$ERROR_MSG" = "" ]; then - #remove fluidd dir - if [ -d $FLUIDD_DIR ]; then - status_msg "Removing Fluidd directory ..." - rm -rf $FLUIDD_DIR && ok_msg "Directory removed!" - fi - #remove fluidd config for nginx - if [ -e /etc/nginx/sites-available/fluidd ]; then - status_msg "Removing Fluidd configuration for Nginx ..." - sudo rm /etc/nginx/sites-available/fluidd && ok_msg "File removed!" - fi - #remove fluidd symlink for nginx - if [ -L /etc/nginx/sites-enabled/fluidd ]; then - status_msg "Removing Fluidd Symlink for Nginx ..." - sudo rm /etc/nginx/sites-enabled/fluidd && ok_msg "File removed!" - fi - CONFIRM_MSG="Fluidd successfully removed!" + ### remove fluidd dir + if [ -d $FLUIDD_DIR ]; then + status_msg "Removing Fluidd directory ..." + rm -rf $FLUIDD_DIR && ok_msg "Directory removed!" fi + + ### remove fluidd config for nginx + if [ -e /etc/nginx/sites-available/fluidd ]; then + status_msg "Removing Fluidd configuration for Nginx ..." + sudo rm /etc/nginx/sites-available/fluidd && ok_msg "File removed!" + fi + + ### remove fluidd symlink for nginx + if [ -L /etc/nginx/sites-enabled/fluidd ]; then + status_msg "Removing Fluidd Symlink for Nginx ..." + sudo rm /etc/nginx/sites-enabled/fluidd && ok_msg "File removed!" + fi + + CONFIRM_MSG="Fluidd successfully removed!" } ############################################################# @@ -299,17 +303,21 @@ remove_octoprint(){ ###reloading units sudo systemctl daemon-reload - ### remove .octoprint directories - if [ -d ${HOME}/OctoPrint ] || [ -d ${HOME}/.octoprint* ]; then - status_msg "Removing OctoPrint and .octoprint directory ..." - rm -rf ${HOME}/OctoPrint ${HOME}/.octoprint* && ok_msg "Directories removed!" - fi - ### remove sudoers file if [ -f /etc/sudoers.d/octoprint-shutdown ]; then sudo rm -rf /etc/sudoers.d/octoprint-shutdown fi + ### remove OctoPrint and .octoprint directories + if [ -d ${HOME}/OctoPrint ]; then + status_msg "Removing OctoPrint directory ..." + rm -rf ${HOME}/OctoPrint && ok_msg "Directory removed!" + fi + if [ -d ${HOME}/.octoprint* ]; then + status_msg "Removing .octoprint directory ..." + rm -rf ${HOME}/.octoprint* && ok_msg "Directory removed!" + fi + CONFIRM_MSG=" OctoPrint successfully removed!" } @@ -333,27 +341,23 @@ remove_nginx(){ } remove_klipperscreen(){ - data_arr=( - $KLIPPERSCREEN_DIR - $KLIPPERSCREEN_ENV_DIR - /etc/systemd/system/KlipperScreen.service - ) - print_error "KlipperScreen" && data_count=() - if [ "$ERROR_MSG" = "" ]; then - #remove KlipperScreen dir - if [ -d $KLIPPERSCREEN_DIR ]; then - status_msg "Removing KlipperScreen directory ..." - rm -rf $KLIPPERSCREEN_DIR && ok_msg "Directory removed!" - fi - if [ -d $KLIPPERSCREEN_ENV_DIR ]; then - status_msg "Removing KlipperScreen VENV directory ..." - rm -rf $KLIPPERSCREEN_ENV_DIR && ok_msg "Directory removed!" - fi - #remove KlipperScreen systemd file - if [ -e /etc/systemd/system/KlipperScreen.service ]; then - status_msg "Removing KlipperScreen Service ..." - sudo rm /etc/systemd/system/KlipperScreen.service && ok_msg "File removed!" - fi - CONFIRM_MSG="KlipperScreen successfully removed!" + ### remove KlipperScreen dir + if [ -d $KLIPPERSCREEN_DIR ]; then + status_msg "Removing KlipperScreen directory ..." + rm -rf $KLIPPERSCREEN_DIR && ok_msg "Directory removed!" fi + + ### remove KlipperScreen VENV dir + if [ -d $KLIPPERSCREEN_ENV_DIR ]; then + status_msg "Removing KlipperScreen VENV directory ..." + rm -rf $KLIPPERSCREEN_ENV_DIR && ok_msg "Directory removed!" + fi + + ### remove KlipperScreen systemd file + if [ -e /etc/systemd/system/KlipperScreen.service ]; then + status_msg "Removing KlipperScreen Service ..." + sudo rm /etc/systemd/system/KlipperScreen.service && ok_msg "File removed!" + fi + + CONFIRM_MSG="KlipperScreen successfully removed!" } From f8aa88f4800ca0a8d7154c20670b3253947a97af Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 28 Jan 2021 18:54:02 +0100 Subject: [PATCH 67/97] fix: rework menus and UI --- scripts/ui/advanced_menu.sh | 49 +++++------------------ scripts/ui/backup_menu.sh | 78 ++++++++++-------------------------- scripts/ui/general_ui.sh | 23 +++++++++++ scripts/ui/install_menu.sh | 51 +++++------------------- scripts/ui/main_menu.sh | 60 +++++++--------------------- scripts/ui/remove_menu.sh | 79 ++++++++++--------------------------- 6 files changed, 98 insertions(+), 242 deletions(-) diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh index 5e4b2b1..8fe288d 100755 --- a/scripts/ui/advanced_menu.sh +++ b/scripts/ui/advanced_menu.sh @@ -18,10 +18,8 @@ quit_footer } advanced_menu(){ - print_header - print_msg && clear_msg read_octoprint_service_status - advanced_ui + do_action "" "advanced_ui" while true; do read -p "${cyan}Perform action:${default} " action; echo case "$action" in @@ -33,23 +31,11 @@ advanced_menu(){ print_msg && clear_msg advanced_ui;; 1) - clear - print_header - switch_menu - print_msg && clear_msg - advanced_ui;; + do_action "switch_menu" "advanced_ui";; 2) - clear - print_header - load_klipper_state - print_msg && clear_msg - advanced_ui;; + do_action "load_klipper_state" "advanced_ui";; 3) - clear - print_header - build_fw - print_msg && clear_msg - advanced_ui;; + do_action "build_fw" "advanced_ui";; 4) clear print_header @@ -61,11 +47,7 @@ advanced_menu(){ print_msg && clear_msg advanced_ui;; 5) - clear - print_header - get_mcu_id - print_msg && clear_msg - advanced_ui;; + do_action "get_mcu_id" "advanced_ui";; 6) clear print_header @@ -73,19 +55,11 @@ advanced_menu(){ print_msg && clear_msg advanced_ui;; 7) - clear - print_header - setup_gcode_shell_command - print_msg && clear_msg - advanced_ui;; + do_action "setup_gcode_shell_command" "advanced_ui";; Q|q) clear; main_menu; break;; *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - advanced_ui;; + deny_action "advanced_ui";; esac done advanced_menu @@ -115,8 +89,7 @@ switch_ui(){ switch_menu(){ if [ -d $KLIPPER_DIR ]; then read_branch - print_msg && clear_msg - switch_ui + do_action "" "switch_ui" while true; do read -p "${cyan}Perform action:${default} " action; echo case "$action" in @@ -151,11 +124,7 @@ switch_menu(){ Q|q) clear; advanced_menu; break;; *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - switch_ui;; + deny_action "switch_ui";; esac done else diff --git a/scripts/ui/backup_menu.sh b/scripts/ui/backup_menu.sh index ef6c3d2..83780cd 100755 --- a/scripts/ui/backup_menu.sh +++ b/scripts/ui/backup_menu.sh @@ -4,81 +4,45 @@ backup_ui(){ hr echo -e "| ${yellow}Backup location: ~/kiauh-backups${default} | " hr - echo -e "| Configuration folder: | Webinterface: | " - echo -e "| 0) [Klipper configs] | 3) [Mainsail] | " - echo -e "| | 4) [Fluidd] | " - echo -e "| Firmware: | 5) [DWC2 Web UI] | " - echo -e "| 1) [Klipper] | 6) [OctoPrint] | " - echo -e "| | | " - echo -e "| Klipper API: | HDMI Screen: | " - echo -e "| 2) [Moonraker] | 7) [KlipperScreen] | " + echo -e "| Configuration folder: | Klipper Webinterface: | " + echo -e "| 0) [Klipper configs] | 3) [Mainsail] | " + echo -e "| | 4) [Fluidd] | " + echo -e "| Firmware: | | " + echo -e "| 1) [Klipper] | HDMI Screen: | " + echo -e "| | 5) [KlipperScreen] | " + echo -e "| Klipper API: | | " + echo -e "| 2) [Moonraker] | Other: | " + echo -e "| | 6) [Duet Web Control] | " + echo -e "| | 7) [OctoPrint] | " quit_footer } backup_menu(){ - print_header - print_msg && clear_msg - backup_ui + do_action "" "backup_ui" while true; do read -p "${cyan}Perform action:${default} " action; echo case "$action" in 0) - clear - print_header - backup_klipper_config_dir - print_msg && clear_msg - backup_ui;; + do_action "backup_klipper_config_dir" "backup_ui";; 1) - clear - print_header - backup_klipper - print_msg && clear_msg - backup_ui;; + do_action "backup_klipper" "backup_ui";; 2) - clear - print_header - backup_moonraker - print_msg && clear_msg - backup_ui;; + do_action "backup_moonraker" "backup_ui";; 3) - clear - print_header - backup_mainsail - print_msg && clear_msg - backup_ui;; + do_action "backup_mainsail" "backup_ui";; 4) - clear - print_header - backup_fluidd - print_msg && clear_msg - backup_ui;; + do_action "backup_fluidd" "backup_ui";; 5) - clear - print_header - backup_dwc2 - print_msg && clear_msg - backup_ui;; + do_action "backup_klipperscreen" "backup_ui";; 6) - clear - print_header - backup_octoprint - print_msg && clear_msg - backup_ui;; + do_action "backup_dwc2" "backup_ui";; 7) - clear - print_header - backup_klipperscreen - print_msg && clear_msg - backup_ui;; + do_action "backup_octoprint" "backup_ui";; Q|q) clear; main_menu; break;; *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - backup_ui;; + deny_action "backup_ui";; esac done backup_menu -} +} \ No newline at end of file diff --git a/scripts/ui/general_ui.sh b/scripts/ui/general_ui.sh index f9aa137..0735131 100755 --- a/scripts/ui/general_ui.sh +++ b/scripts/ui/general_ui.sh @@ -38,3 +38,26 @@ kiauh_update_msg(){ echo -e "| ${yellow}either to the script or the installable components!${default} | " bottom_border } + +############################################################################################## +#********************************************************************************************# +############################################################################################## +### TODO: rework other menus to make use of the following functions too and make them more readable + +do_action(){ + clear + print_header + ### $1 is the action the user wants to fire + $1 + print_msg && clear_msg + ### $2 is the menu the user usually gets directed back to after an action is completed + $2 +} + +deny_action(){ + clear + print_header + print_unkown_cmd + print_msg && clear_msg + $1 +} \ No newline at end of file diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index 883d68a..3a31fa9 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -20,61 +20,28 @@ install_ui(){ } install_menu(){ - print_header - install_ui + do_action "" "install_ui" while true; do read -p "${cyan}Perform action:${default} " action; echo case "$action" in 1) - clear - print_header - klipper_setup_dialog - print_msg && clear_msg - install_ui;; + do_action "klipper_setup_dialog" "install_ui";; 2) - clear - print_header - moonraker_setup_dialog - print_msg && clear_msg - install_ui;; + do_action "moonraker_setup_dialog" "install_ui";; 3) - clear - print_header - install_mainsail - print_msg && clear_msg - install_ui;; + do_action "install_mainsail" "install_ui";; 4) - clear - print_header - install_fluidd - print_msg && clear_msg - install_ui;; + do_action "install_fluidd" "install_ui";; 5) - clear - print_header - install_klipperscreen - print_msg && clear_msg - install_ui;; + do_action "install_klipperscreen" "install_ui";; 6) - clear - print_header - dwc_setup_dialog - print_msg && clear_msg - install_ui;; + do_action "dwc_setup_dialog" "install_ui";; 7) - clear - print_header - octoprint_setup_dialog - print_msg && clear_msg - install_ui;; + do_action "octoprint_setup_dialog" "install_ui";; Q|q) clear; main_menu; break;; *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - install_ui;; + deny_action "install_ui";; esac done install_menu diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 593bf95..091dc47 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -44,80 +44,50 @@ main_menu(){ read -p "${cyan}Perform action:${default} " action; echo case "$action" in "start klipper") - clear - print_header + clear && print_header klipper_service "start" main_ui;; "stop klipper") - clear - print_header + clear && print_header klipper_service "stop" main_ui;; "restart klipper") - clear - print_header + clear && print_header klipper_service "restart" main_ui;; "start moonraker") - clear - print_header + clear && print_header moonraker_service "start" main_ui;; "stop moonraker") - clear - print_header + clear && print_header moonraker_service "stop" main_ui;; "restart moonraker") - clear - print_header + clear && print_header moonraker_service "restart" main_ui;; update) - clear - print_header - update_kiauh - print_msg && clear_msg - main_ui;; + do_action "update_kiauh" "main_ui";; 0) - clear - print_header - upload_selection - print_msg && clear_msg - main_ui;; + do_action "upload_selection" "main_ui";; 1) - clear - install_menu - break;; + clear && install_menu && break;; 2) - clear - update_menu - break;; + clear && update_menu && break;; 3) - clear - remove_menu - break;; + clear && remove_menu && break;; 4) - clear - advanced_menu - break;; + clear && advanced_menu && break;; 5) - clear - backup_menu - break;; + clear && backup_menu && break;; 6) - clear - settings_menu - break;; + clear && settings_menu && break;; Q|q) echo -e "${green}###### Happy printing! ######${default}"; echo exit -1;; *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - main_ui;; + deny_action "main_ui";; esac done clear; main_menu diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh index 18ba834..ba9161f 100755 --- a/scripts/ui/remove_menu.sh +++ b/scripts/ui/remove_menu.sh @@ -3,86 +3,49 @@ remove_ui(){ echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${default} | " hr echo -e "| Directories which remain untouched: | " - echo -e "| --> ~/klipper_config | " + echo -e "| --> Your printer configuration directory | " echo -e "| --> ~/kiauh-backups | " echo -e "| You need remove them manually if you wish so. | " hr - echo -e "| Firmware: | Webinterface: | " - echo -e "| 1) [Klipper] | 3) [DWC2] | " - echo -e "| | 4) [Mainsail] | " - echo -e "| Klipper API: | 5) [Fluidd] | " - echo -e "| 2) [Moonraker] | 6) [Octoprint] | " + echo -e "| Firmware: | Klipper Webinterface: | " + echo -e "| 1) [Klipper] | 3) [Mainsail] | " + echo -e "| | 4) [Fluidd] | " + echo -e "| Klipper API: | | " + echo -e "| 2) [Moonraker] | HDMI Screen: | " + echo -e "| | 5) [KlipperScreen] | " echo -e "| | | " - echo -e "| | Webserver: | " - echo -e "| | 7) [Nginx] | " - echo -e "| | | " - echo -e "| | HDMI Screen: | " - echo -e "| | 8) [KlipperScreen] | " + echo -e "| | Other: | " + echo -e "| | 6) [Duet Web Control] | " + echo -e "| | 7) [OctoPrint] | " + echo -e "| | 8) [NGINX] | " quit_footer } remove_menu(){ - print_header - remove_ui + do_action "" "remove_ui" while true; do read -p "${cyan}Perform action:${default} " action; echo case "$action" in 1) - clear - print_header - remove_klipper - print_msg && clear_msg - remove_ui;; + do_action "remove_klipper" "remove_ui";; 2) - clear - print_header - remove_moonraker - print_msg && clear_msg - remove_ui;; + do_action "remove_moonraker" "remove_ui";; 3) - clear - print_header - remove_dwc2 - print_msg && clear_msg - remove_ui;; + do_action "remove_mainsail" "remove_ui";; 4) - clear - print_header - remove_mainsail - print_msg && clear_msg - remove_ui;; + do_action "remove_fluidd" "remove_ui";; 5) - clear - print_header - remove_fluidd - print_msg && clear_msg - remove_ui;; + do_action "remove_klipperscreen" "remove_ui";; 6) - clear - print_header - remove_octoprint - print_msg && clear_msg - remove_ui;; + do_action "remove_dwc2" "remove_ui";; 7) - clear - print_header - remove_nginx - print_msg && clear_msg - remove_ui;; + do_action "remove_octoprint" "remove_ui";; 8) - clear - print_header - remove_klipperscreen - print_msg && clear_msg - remove_ui;; + do_action "remove_nginx" "remove_ui";; Q|q) clear; main_menu; break;; *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - remove_ui;; + deny_action "remove_ui";; esac done remove_menu From 04f204e4c784bf0c1c8006ebec507622345e2b45 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 28 Jan 2021 18:56:11 +0100 Subject: [PATCH 68/97] fix: re-arrange mainsail and fluidd --- scripts/ui/main_menu.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 091dc47..f10bf3c 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -7,8 +7,8 @@ main_ui(){ echo -e "| 1) [Install] | |" echo -e "| 2) [Update] | Moonraker: $MOONRAKER_STATUS|" echo -e "| 3) [Remove] | |" - echo -e "| 4) [Advanced] | Fluidd: $FLUIDD_STATUS|" - echo -e "| 5) [Backup] | Mainsail: $MAINSAIL_STATUS|" + echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|" + echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|" echo -e "| | KlipperScreen: $KLIPPERSCREEN_STATUS|" echo -e "| 6) [Settings] | |" echo -e "| | DWC2: $DWC2_STATUS|" From 61d1c4669471ed77160aeebfcd065c12ac8f94f2 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 28 Jan 2021 22:57:35 +0100 Subject: [PATCH 69/97] fix: dependency check was missing for moonraker installation --- scripts/install_moonraker.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index 0ab0058..ffc0f1d 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -105,6 +105,12 @@ moonraker_setup(){ source_kiauh_ini MOONRAKER_CONF_LOC="$klipper_cfg_loc" + ### checking dependencies + dep=(wget curl unzip dfu-util) + ### additional deps for kiauh compatibility for armbian + dep+=(libjpeg-dev zlib1g-dev) + dependency_check + ### step 1: clone moonraker status_msg "Downloading Moonraker ..." ### force remove existing moonraker dir and clone into fresh moonraker dir From 0eb2d066bea6e3a8988c2e64277af34dc68cce4f Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 28 Jan 2021 23:39:42 +0100 Subject: [PATCH 70/97] fix: rework dwc and octoprint service handling --- scripts/functions.sh | 100 +++++++++++++++++++++---------------------- scripts/update.sh | 6 +-- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index db95e05..9274a62 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -171,72 +171,72 @@ moonraker_service(){ fi } -start_dwc(){ - status_msg "Starting DWC-for-Klipper-Socket Service ..." - sudo systemctl start dwc && ok_msg "DWC-for-Klipper-Socket Service started!" -} +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" -stop_dwc(){ - status_msg "Stopping DWC-for-Klipper-Socket Service ..." - sudo systemctl stop dwc && ok_msg "DWC-for-Klipper-Socket Service stopped!" -} - -start_octoprint(){ - status_msg "Starting OctoPrint Service ..." - sudo systemctl start octoprint && ok_msg "OctoPrint Service started!" -} - -stop_octoprint(){ - status_msg "Stopping OctoPrint Service ..." - sudo systemctl stop octoprint && ok_msg "OctoPrint Service stopped!" -} - -restart_octoprint(){ - status_msg "Restarting OctoPrint Service ..." - sudo systemctl restart octoprint && ok_msg "OctoPrint Service restarted!" -} - -enable_octoprint_service(){ - if [[ -f $OCTOPRINT_SERVICE1 && -f $OCTOPRINT_SERVICE2 ]]; then - status_msg "OctoPrint Service is disabled! Enabling now ..." - sudo systemctl enable octoprint -q && sudo systemctl start octoprint + 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!" fi } -disable_octoprint(){ - if [ "$DISABLE_OPRINT" = "true" ]; then - disable_octoprint_service - fi -} +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" -disable_octoprint_service(){ - if [[ -f $OCTOPRINT_SERVICE1 && -f $OCTOPRINT_SERVICE2 ]]; then - status_msg "OctoPrint Service is enabled! Disabling now ..." - sudo systemctl stop octoprint && sudo systemctl disable octoprint -q + 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!" fi } toggle_octoprint_service(){ - if [[ -f $OCTOPRINT_SERVICE1 && -f $OCTOPRINT_SERVICE2 ]]; then - if systemctl is-enabled octoprint.service -q; then - disable_octoprint_service - sleep 2 - CONFIRM_MSG=" OctoPrint Service is now >>> DISABLED <<< !" - else - enable_octoprint_service - sleep 2 - CONFIRM_MSG=" OctoPrint Service is now >>> ENABLED <<< !" - fi + 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 <<< !" else ERROR_MSG=" You cannot activate a service that does not exist!" fi } read_octoprint_service_status(){ - if ! systemctl is-enabled octoprint.service -q &>/dev/null; then - OPRINT_SERVICE_STATUS="${green}[Enable]${default} OctoPrint Service " - else + unset OPRINT_SERVICE_STATUS + if systemctl list-unit-files | grep -E "octoprint*" | grep "enabled" &>/dev/null; then OPRINT_SERVICE_STATUS="${red}[Disable]${default} OctoPrint Service " + else + OPRINT_SERVICE_STATUS="${green}[Enable]${default} OctoPrint Service " fi } diff --git a/scripts/update.sh b/scripts/update.sh index 2b157d1..054efac 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -97,14 +97,14 @@ update_klipper(){ } update_dwc2fk(){ - stop_dwc + dwc_service "stop" bb4u "dwc2" if [ ! -d $DWC2FK_DIR ]; then cd ${HOME} && git clone $DWC2FK_REPO else cd $DWC2FK_DIR && git pull fi - start_dwc + dwc_service "start" } update_dwc2(){ @@ -125,9 +125,9 @@ update_fluidd(){ } update_moonraker(){ + moonraker_service "stop" bb4u "moonraker" status_msg "Updating Moonraker ..." - moonraker_service "stop"; echo cd $MOONRAKER_DIR MOONRAKER_OLDREQ_MD5SUM=$(md5sum $MOONRAKER_DIR/scripts/moonraker-requirements.txt | cut -d " " -f1) From 1570fd588ea491b906ca611fdd0da704af6cdc93 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 28 Jan 2021 23:40:37 +0100 Subject: [PATCH 71/97] fix: display disabled octoprint services as installed, and show the number of instances --- scripts/status.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/scripts/status.sh b/scripts/status.sh index c1cbd25..df5babf 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -174,16 +174,12 @@ octoprint_status(){ $OCTOPRINT_DIR ) #remove the "SERVICE" entry from the octoprint array if an octoprint service is installed - if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "octoprint.service")" ] || [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "octoprint-[[:digit:]].service")" ]; then + if systemctl list-unit-files | grep -E "octoprint.*" &>/dev/null; then unset octoprint_data[0] fi ### count amount of octoprint services - if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "octoprint.service")" ]; then - instances=1 - else - instances=$(systemctl list-units --full -all -t service --no-legend | grep -E "octoprint-[[:digit:]].service" | wc -l) - fi + instances=$(systemctl list-unit-files | grep -E "octoprint.*" | wc -l) #count+1 for each found data-item from array for op in "${octoprint_data[@]}" From 7224040f8a030a5e8214e3daab0c80df550f4e02 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 28 Jan 2021 23:41:54 +0100 Subject: [PATCH 72/97] fix: check for multiple installed and enabled octoprint services --- scripts/install_moonraker.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index ffc0f1d..900b9b3 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -16,8 +16,8 @@ system_check_moonraker(){ py_chk_ok="false" fi - ### check system for an installed octoprint service - if systemctl is-enabled octoprint.service -q 2>/dev/null; then + ### check system for an installed and enabled octoprint service + if systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then OCTOPRINT_ENABLED="true" fi @@ -487,9 +487,9 @@ process_octoprint_dialog(){ Y|y|Yes|yes|"") echo -e "###### > Yes" status_msg "Stopping OctoPrint ..." - sudo systemctl stop octoprint && ok_msg "OctoPrint service stopped!" + octoprint_service "stop" && ok_msg "OctoPrint service stopped!" status_msg "Disabling OctoPrint ..." - sudo systemctl disable octoprint && ok_msg "OctoPrint service disabled!" + octoprint_service "disable" && ok_msg "OctoPrint service disabled!" break;; N|n|No|no) echo -e "###### > No" From 69d134d9d176cad443b082b2237eb40de93ebf24 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 28 Jan 2021 23:42:38 +0100 Subject: [PATCH 73/97] fix: rework .octoprint folder remove function to be able to remove multiple instances --- scripts/remove.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/remove.sh b/scripts/remove.sh index 10e83d9..ac5962f 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -308,14 +308,18 @@ remove_octoprint(){ sudo rm -rf /etc/sudoers.d/octoprint-shutdown fi - ### remove OctoPrint and .octoprint directories + ### remove OctoPrint directory if [ -d ${HOME}/OctoPrint ]; then status_msg "Removing OctoPrint directory ..." rm -rf ${HOME}/OctoPrint && ok_msg "Directory removed!" fi - if [ -d ${HOME}/.octoprint* ]; then - status_msg "Removing .octoprint directory ..." - rm -rf ${HOME}/.octoprint* && ok_msg "Directory removed!" + + ###remove .octoprint directories + if [ "$(find ${HOME} -maxdepth 1 -name ".octoprint*")" ]; then + for folder in $(find ${HOME} -maxdepth 1 -name ".octoprint*") + do + status_msg "Removing $folder ..." && rm -rf $folder && ok_msg "Done!" + done fi CONFIRM_MSG=" OctoPrint successfully removed!" From a0e53655bdf355119657ae115119174d0b2753cd Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 29 Jan 2021 12:17:42 +0100 Subject: [PATCH 74/97] fix: bug with sourcing the kiauh.ini and improve config change function --- scripts/functions.sh | 11 +++++++++-- scripts/ui/settings_menu.sh | 8 ++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index 9274a62..6133ee3 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -29,7 +29,15 @@ check_klipper_cfg_path(){ change_klipper_cfg_path(){ source_kiauh_ini old_klipper_cfg_loc="$klipper_cfg_loc" + EXAMPLE_FOLDER=$(printf "%s/your_config_folder" "${HOME}") while true; do + top_border + echo -e "| ${red}IMPORTANT:${default} |" + echo -e "| Please enter the new path in the following form: |" + printf "| ${yellow}%-51s${default} |\n" "$EXAMPLE_FOLDER" + blank_line + echo -e "| By default 'klipper_config' is recommended! |" + bottom_border echo echo -e "${cyan}###### Please set the Klipper config directory:${default} " if [ -z "$old_klipper_cfg_loc" ]; then @@ -52,7 +60,6 @@ change_klipper_cfg_path(){ ### write new location to klipper and moonraker service set_klipper_cfg_path - echo; ok_msg "Config directory changed!" break;; N|n|No|no) @@ -126,7 +133,7 @@ set_klipper_cfg_path(){ } source_kiauh_ini(){ - source ${SRCDIR}/kiauh/kiauh.ini + source $INI_FILE } klipper_service(){ diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index 3b07f0f..f2fc941 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -5,18 +5,18 @@ settings_ui(){ echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") | " hr echo -e "| ${red}Caution:${default} | " - echo -e "| When you rename the config folder, be aware that ALL | " + echo -e "| When you change the config folder, be aware that ALL | " echo -e "| Klipper and Moonraker services will be STOPPED, | " echo -e "| reconfigured and then restarted again. | " blank_line - echo -e "| ${red}DO NOT rename the folder during printing!${default} | " + echo -e "| ${red}DO NOT change the folder during printing!${default} | " hr blank_line - echo -e "| ${yellow}● Current Klipper config folder:${default} | " + echo -e "| ${cyan}● Current Klipper config folder:${default} | " printf "|%-55s|\n" " $klipper_cfg_loc" blank_line hr - echo -e "| 1) Rename config folder | " + echo -e "| 1) Change config folder | " quit_footer } From 53aa86d138c19aea12c610ef586d329e272ab453 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 29 Jan 2021 13:28:10 +0100 Subject: [PATCH 75/97] fix: missed updating a file name --- scripts/install_klipper_webui.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index b4f8a50..5bf96fc 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -143,7 +143,7 @@ mainsail_port_check(){ select_mainsail_port fi else - DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/mainsail_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) + DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) SET_LISTEN_PORT=$DEFAULT_PORT fi SET_NGINX_CFG="true" @@ -164,7 +164,7 @@ fluidd_port_check(){ select_fluidd_port fi else - DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/fluidd_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) + DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) SET_LISTEN_PORT=$DEFAULT_PORT fi SET_NGINX_CFG="true" From 55dad5ffb607700135c7b43cf6b5ac30e5d2f83a Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 29 Jan 2021 15:14:13 +0100 Subject: [PATCH 76/97] fix: switch back to stephans repo, PR was merged. --- kiauh.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index 5c8b2b3..3cdaa0f 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -46,9 +46,7 @@ BACKUP_DIR=${HOME}/kiauh-backups KLIPPER_REPO=https://github.com/KevinOConnor/klipper.git ARKSINE_REPO=https://github.com/Arksine/klipper.git DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git -###TODO use my own dwc2-for-klipper-socket repo as long as the needed start argument PR is not merged yet -DWC2FK_REPO=https://github.com/th33xitus/dwc2-for-klipper-socket.git -#DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper-socket.git +DWC2FK_REPO=https://github.com/Stephan3/dwc2-for-klipper-socket.git MOONRAKER_REPO=https://github.com/Arksine/moonraker.git KLIPPERSCREEN_REPO=https://github.com/jordanruthe/KlipperScreen.git #branches From 6105122467926ef1dc0b97932049b51c31d49865 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 29 Jan 2021 17:13:19 +0100 Subject: [PATCH 77/97] fix: better explanation in the macro dialog --- scripts/install_klipper_webui.sh | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index 5bf96fc..c33f142 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -16,14 +16,19 @@ get_user_selection_kiauh_macros(){ unset ADD_KIAUH_MACROS echo top_border - echo -e "| It is recommended to have some important macros to |" - echo -e "| have full functionality of the web interface. |" + echo -e "| It is recommended to have some important macros set |" + echo -e "| up in your printer configuration to have $1|" + echo -e "| fully functional and working. |" blank_line - echo -e "| If you don't have those macros, you can choose to |" - echo -e "| install suggested default macros now. |" + echo -e "| Those macros are: |" + echo -e "| ${cyan}● [gcode_macro PAUSE]${default} |" + echo -e "| ${cyan}● [gcode_macro RESUME]${default} |" + echo -e "| ${cyan}● [gcode_macro CANCEL_PRINT]${default} |" blank_line - echo -e "| If unsure which macros are meant, just go ahead and |" - echo -e "| select 'Yes'. You can always delete them later. |" + echo -e "| If you already have these macros in your config file |" + echo -e "| you can skip this step and choose 'no'. |" + echo -e "| Otherwise you should consider to answer with 'yes' to |" + echo -e "| add the recommended example macros to your config. |" bottom_border read -p "${cyan}###### Add the recommended macros? (Y/n):${default} " yn case "$yn" in @@ -55,7 +60,7 @@ install_mainsail(){ mainsail_port_check ### ask user to install the recommended webinterface macros - get_user_selection_kiauh_macros + get_user_selection_kiauh_macros "Mainsail " ### creating the mainsail nginx cfg set_nginx_cfg "mainsail" @@ -81,7 +86,7 @@ install_fluidd(){ fluidd_port_check ### ask user to install the recommended webinterface macros - get_user_selection_kiauh_macros + get_user_selection_kiauh_macros "Fluidd " ### creating the fluidd nginx cfg set_nginx_cfg "fluidd" From 0d29bf9f3154ac756f3170e0feb020c00231fafc Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 29 Jan 2021 18:00:47 +0100 Subject: [PATCH 78/97] fix: wording, description dialog --- scripts/install_klipper_webui.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index c33f142..07e5f0f 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -191,7 +191,8 @@ select_mainsail_port(){ [ "$DWC2_PORT" = "80" ] && echo "| ● DWC2 |" blank_line echo -e "| Make sure you don't choose a port which was already |" - echo -e "| assigned to one of the other web interfaces! |" + echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${default} |" + echo -e "| use ports in the range of 4750 or above! |" blank_line echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |" echo -e "| input. So make sure to choose a valid port! |" @@ -222,7 +223,8 @@ select_fluidd_port(){ [ "$DWC2_PORT" = "80" ] && echo "| ● DWC2 |" blank_line echo -e "| Make sure you don't choose a port which was already |" - echo -e "| assigned to one of the other web interfaces! |" + echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${default} |" + echo -e "| use ports in the range of 4750 or above! |" blank_line echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |" echo -e "| input. So make sure to choose a valid port! |" From 17524bf49b534558f85bf589c7052bbac91e7846 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 29 Jan 2021 20:10:04 +0100 Subject: [PATCH 79/97] fix: lock changing config folder function until klipper was installed through kiauh. --- scripts/ui/settings_menu.sh | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index f2fc941..1c06c70 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -1,6 +1,5 @@ settings_ui(){ source_kiauh_ini - [ -z $klipper_cfg_loc ] && klipper_cfg_loc="----------" top_border echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") | " hr @@ -16,31 +15,29 @@ settings_ui(){ printf "|%-55s|\n" " $klipper_cfg_loc" blank_line hr + if [ -z $klipper_cfg_loc ]; then + echo -e "| ${red}N/A) Install Klipper with KIAUH first to unlock!${default} | " + else echo -e "| 1) Change config folder | " + fi quit_footer } settings_menu(){ - print_header - print_msg && clear_msg - settings_ui + do_action "" "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;; + if [ ! -z $klipper_cfg_loc ]; then + do_action "change_klipper_cfg_path" "settings_ui" + else + deny_action "settings_ui" + fi;; Q|q) clear; main_menu; break;; *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - settings_ui;; + deny_action "settings_ui";; esac done settings_ui From 47cf96ef7451495cb2d66fccbb64ecbb3cbb0536 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 29 Jan 2021 20:12:53 +0100 Subject: [PATCH 80/97] fix: more verbose error message --- scripts/install_klipper.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install_klipper.sh b/scripts/install_klipper.sh index 05f1107..eb505f4 100755 --- a/scripts/install_klipper.sh +++ b/scripts/install_klipper.sh @@ -8,7 +8,7 @@ klipper_setup_dialog(){ ### 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 + ERROR_MSG="At least one Klipper service is already installed!\n Please remove Klipper first, before installing it again." && return 0 fi ### initial printer.cfg path check From 2ef3273b7460951a671861720065538f3bb1c04d Mon Sep 17 00:00:00 2001 From: th33xitus Date: Fri, 29 Jan 2021 20:23:55 +0100 Subject: [PATCH 81/97] fix: make remove function now also remove disabled octoprint services --- scripts/remove.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/remove.sh b/scripts/remove.sh index ac5962f..7cb885c 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -279,7 +279,7 @@ remove_fluidd(){ remove_octoprint(){ ###remove single instance - if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "octoprint.service")" ]; then + if [ "$(systemctl list-unit-files | grep -F "octoprint.service")" ]; then status_msg "Removing OctoPrint Service ..." sudo systemctl stop octoprint sudo systemctl disable octoprint @@ -288,7 +288,7 @@ remove_octoprint(){ fi ###remove multi instance services - if [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "octoprint-[[:digit:]].service")" ]; then + if [ "$(systemctl list-unit-files | grep -E "octoprint-[[:digit:]].service")" ]; then status_msg "Removing OctoPrint Services ..." for service in $(find $SYSTEMDDIR -maxdepth 1 -name "octoprint-*.service" | cut -d"/" -f5) do From c3468c04e4876648f7bfa77e8c45be2efaf8feec Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 30 Jan 2021 10:15:24 +0100 Subject: [PATCH 82/97] fix: bug when creating the local network ip range for moonraker.conf --- scripts/install_moonraker.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index 900b9b3..dc7e182 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -213,7 +213,7 @@ EOF create_single_moonraker_conf(){ HOSTNAME=$(hostname -I | cut -d" " -f1) - LOCAL_NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-3).0/24" + LOCAL_NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16" /bin/sh -c "cat > $MOONRAKER_CONF_LOC/moonraker.conf" << MOONRAKERCONF [server] @@ -255,7 +255,7 @@ MOONRAKERCONF create_multi_moonraker_conf(){ HOSTNAME=$(hostname -I | cut -d" " -f1) - LOCAL_NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-3).0/16" + LOCAL_NETWORK="$(hostname -I | cut -d" " -f1 | cut -d"." -f1-2).0.0/16" /bin/sh -c "cat > $MOONRAKER_CONF_LOC/printer_$INSTANCE/moonraker.conf" << MOONRAKERCONF [server] From 8a64fe495ebee0857a0d25462f394cd227100cae Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 30 Jan 2021 12:52:58 +0100 Subject: [PATCH 83/97] fix: add inactive klipperscreen entry to moonraker.conf --- scripts/install_moonraker.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index dc7e182..f725fd6 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -250,6 +250,14 @@ path: ~/mainsail type: web repo: cadriel/fluidd path: ~/fluidd + +#[update_manager client KlipperScreen] +#type: git_repo +#path: /home/${HOME}/KlipperScreen +#origin: https://github.com/jordanruthe/KlipperScreen.git +#env: /home/${HOME}/.KlipperScreen-env/bin/python +#requirements: scripts/KlipperScreen-requirements.txt +#install_script: scripts/KlipperScreen-install.sh MOONRAKERCONF } @@ -293,6 +301,14 @@ path: ~/mainsail type: web repo: cadriel/fluidd path: ~/fluidd + +#[update_manager client KlipperScreen] +#type: git_repo +#path: /home/${USER}/KlipperScreen +#origin: https://github.com/jordanruthe/KlipperScreen.git +#env: /home/${USER}/.KlipperScreen-env/bin/python +#requirements: scripts/KlipperScreen-requirements.txt +#install_script: scripts/KlipperScreen-install.sh MOONRAKERCONF } From 99209f97ded92dba43ffeceaeffda0594ee0596c Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 30 Jan 2021 14:19:51 +0100 Subject: [PATCH 84/97] fix: refactor webui installer --- scripts/install_klipper_webui.sh | 69 ++++++++++++-------------------- scripts/ui/install_menu.sh | 4 +- 2 files changed, 27 insertions(+), 46 deletions(-) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index 07e5f0f..0e58f25 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -1,12 +1,9 @@ check_moonraker(){ status_msg "Checking for Moonraker service ..." 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 - ok_msg "Moonraker service found!"; echo - MOONRAKER_SERVICE_FOUND="true" + moonraker_chk_ok="true" else - warn_msg "Moonraker service not found!" - warn_msg "Please install Moonraker first!"; echo - MOONRAKER_SERVICE_FOUND="false" + moonraker_chk_ok="false" fi } @@ -47,56 +44,40 @@ get_user_selection_kiauh_macros(){ done } -install_mainsail(){ +install_webui(){ ### check if moonraker is already installed check_moonraker - if [ "$MOONRAKER_SERVICE_FOUND" = "true" ]; then - ### check for other enabled web interfaces - unset SET_LISTEN_PORT - detect_enabled_sites + [ $1 == "mainsail" ] && INTERFACE="Mainsail" + [ $1 == "fluidd" ] && INTERFACE="Mainsail" - ### check if another site already listens to port 80 - mainsail_port_check - - ### ask user to install the recommended webinterface macros - get_user_selection_kiauh_macros "Mainsail " - - ### creating the mainsail nginx cfg - set_nginx_cfg "mainsail" - - ### copy the kiauh_macros.cfg to the config location - install_kiauh_macros - - ### install mainsail - mainsail_setup + ### exit mainsail/fluidd setup if moonraker not found + if [ $moonraker_chk_ok = "false" ]; then + ERROR_MSG="Moonraker service not found!\n Please install Moonraker first!" + print_msg && clear_msg && return 0 + else + ok_msg "Moonraker service found!" + status_msg "Initializing $INTERFACE installation ..." fi -} -install_fluidd(){ - ### check if moonraker is already installed - check_moonraker + ### check for other enabled web interfaces + unset SET_LISTEN_PORT + detect_enabled_sites - if [ "$MOONRAKER_SERVICE_FOUND" = "true" ]; then - ### check for other enabled web interfaces - unset SET_LISTEN_PORT - detect_enabled_sites + ### check if another site already listens to port 80 + $1_port_check - ### check if another site already listens to port 80 - fluidd_port_check + ### ask user to install the recommended webinterface macros + get_user_selection_kiauh_macros "$INTERFACE " - ### ask user to install the recommended webinterface macros - get_user_selection_kiauh_macros "Fluidd " + ### creating the mainsail/fluidd nginx cfg + set_nginx_cfg "$1" - ### creating the fluidd nginx cfg - set_nginx_cfg "fluidd" + ### copy the kiauh_macros.cfg to the config location + install_kiauh_macros - ### copy the kiauh_macros.cfg to the config location - install_kiauh_macros - - ### install fluidd - fluidd_setup - fi + ### install mainsail/fluidd + $1_setup } install_kiauh_macros(){ diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index 3a31fa9..850d6a4 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -29,9 +29,9 @@ install_menu(){ 2) do_action "moonraker_setup_dialog" "install_ui";; 3) - do_action "install_mainsail" "install_ui";; + do_action "install_webui mainsail" "install_ui";; 4) - do_action "install_fluidd" "install_ui";; + do_action "install_webui fluidd" "install_ui";; 5) do_action "install_klipperscreen" "install_ui";; 6) From 5f142da1b645cd050d7fb499dbadc5214c6f26a9 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 30 Jan 2021 14:57:38 +0100 Subject: [PATCH 85/97] fix: activate remoteMode for mainsail when moonraker multi-instances are found --- scripts/install_klipper_webui.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index 0e58f25..53b4361 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -247,8 +247,15 @@ mainsail_setup(){ ### delete downloaded zip status_msg "Remove downloaded archive ..." - rm -rf *.zip && ok_msg "Done!" && ok_msg "Mainsail installation complete!" - echo + rm -rf *.zip && ok_msg "Done!" + + ### check for moonraker multi-instance and if multi-instance was found, activate mainsail remoteMode + if [ $(ls /etc/systemd/system/moonraker* | wc -l) -gt 1 ]; then + rm -f $MAINSAIL_DIR/config.json + echo -e "{\n \"remoteMode\":true\n}" >> $MAINSAIL_DIR/config.json + fi + + ok_msg "Mainsail installation complete!\n" } fluidd_setup(){ From a7b7b362f33d11e2d37e858f28a18002b5223560 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 30 Jan 2021 15:43:59 +0100 Subject: [PATCH 86/97] fix: typo in moonraker instance count status --- scripts/status.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/status.sh b/scripts/status.sh index df5babf..1ab7ff1 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -105,10 +105,10 @@ moonraker_status(){ done ### count amount of moonraker services - if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then + if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ]; then instances=1 else - instances=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l) + instances=$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service" | wc -l) fi ### display status From 31c3f344e58630eee5d0bffa2cf275a8a4bb6007 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 30 Jan 2021 15:54:28 +0100 Subject: [PATCH 87/97] fix: add dialog: ask user to remove moonraker after klipper --- scripts/remove.sh | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/scripts/remove.sh b/scripts/remove.sh index 7cb885c..cb22d36 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -1,4 +1,36 @@ remove_klipper(){ + ### ask the user if he wants to uninstall moonraker too. + ###? currently usefull if the user wants to switch from single-instance to multi-instance + if [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker*.")" ]; then + while true; do + unset REM_MR + top_border + echo -e "| Do you want to remove Moonraker afterwards? |" + echo -e "| |" + echo -e "| This is useful in case you want to switch from a |" + echo -e "| single-instance to a multi-instance installation, |" + echo -e "| which makes a re-installation of Moonraker necessary. |" + echo -e "| |" + echo -e "| If for any other reason you only want to uninstall |" + echo -e "| Klipper, please select 'No' and continue. |" + bottom_border + read -p "${cyan}###### Remove Moonraker afterwards? (y/N):${default} " yn + case "$yn" in + Y|y|Yes|yes) + echo -e "###### > Yes" + REM_MR="true" + break;; + N|n|No|no|"") + echo -e "###### > No" + REM_MR="false" + break;; + *) + print_unkown_cmd + print_msg && clear_msg;; + esac + done + fi + ### remove "legacy" klipper init.d service if [[ -e /etc/init.d/klipper || -e /etc/default/klipper ]]; then status_msg "Removing Klipper Service ..." @@ -78,7 +110,11 @@ remove_klipper(){ rm -rf $KLIPPY_ENV && ok_msg "Directory removed!" fi - CONFIRM_MSG=" Klipper was successfully removed!" + CONFIRM_MSG=" Klipper was successfully removed!" && print_msg && clear_msg + + if [ "$REM_MR" == "true" ]; then + remove_moonraker + fi } ############################################################# From 82227f8d0b5084ac77d4d0e86ca35ef44d0271b7 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 30 Jan 2021 16:13:20 +0100 Subject: [PATCH 88/97] fix: bug while creating the kiauh_macros.cfg --- scripts/install_klipper_webui.sh | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index 53b4361..fde87a8 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -86,17 +86,6 @@ install_kiauh_macros(){ if [ "$ADD_KIAUH_MACROS" = "true" ]; then ### 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/kiauh_macros.cfg ]; then - ### copy kiauh_macros.cfg to config location - cp ${SRCDIR}/kiauh/resources/kiauh_macros.cfg $klipper_cfg_loc - ok_msg "$klipper_cfg_loc/kiauh_macros.cfg created!" - - ### write the include to the very first line of the printer.cfg - sed -i "1 i [include kiauh_macros.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 @@ -105,13 +94,18 @@ install_kiauh_macros(){ ### copy kiauh_macros.cfg to config location cp ${SRCDIR}/kiauh/resources/kiauh_macros.cfg $path ok_msg "$path/kiauh_macros.cfg created!" - ### write the include to the very first line of the printer.cfg sed -i "1 i [include kiauh_macros.cfg]" $path/printer.cfg fi done + ### handle single printer.cfg + elif [ -f $klipper_cfg_loc/printer.cfg ] && [ ! -f $klipper_cfg_loc/kiauh_macros.cfg ]; then + ### copy kiauh_macros.cfg to config location + cp ${SRCDIR}/kiauh/resources/kiauh_macros.cfg $klipper_cfg_loc + ok_msg "$klipper_cfg_loc/kiauh_macros.cfg created!" + ### write the include to the very first line of the printer.cfg + sed -i "1 i [include kiauh_macros.cfg]" $klipper_cfg_loc/printer.cfg fi - ### restart klipper service to parse the modified printer.cfg klipper_service "restart" fi From dc6fea8c3bc57048e2afc99b5386ffa291f7faee Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 30 Jan 2021 18:19:49 +0100 Subject: [PATCH 89/97] fix: enable mainsail remoteMode if its already installed before moonraker --- scripts/install_klipper_webui.sh | 10 +++++++--- scripts/install_moonraker.sh | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index fde87a8..cf7c5cb 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -243,15 +243,19 @@ mainsail_setup(){ status_msg "Remove downloaded archive ..." rm -rf *.zip && ok_msg "Done!" - ### check for moonraker multi-instance and if multi-instance was found, activate mainsail remoteMode + ### check for moonraker multi-instance and if multi-instance was found, enable mainsails remoteMode if [ $(ls /etc/systemd/system/moonraker* | wc -l) -gt 1 ]; then - rm -f $MAINSAIL_DIR/config.json - echo -e "{\n \"remoteMode\":true\n}" >> $MAINSAIL_DIR/config.json + enable_mainsail_remotemode fi ok_msg "Mainsail installation complete!\n" } +enable_mainsail_remotemode(){ + rm -f $MAINSAIL_DIR/config.json + echo -e "{\n \"remoteMode\":true\n}" >> $MAINSAIL_DIR/config.json +} + fluidd_setup(){ ### get fluidd download url FLUIDD_DL_URL=$(curl -s https://api.github.com/repositories/295836951/releases/latest | grep browser_download_url | cut -d'"' -f4) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index f725fd6..db7fd5f 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -139,6 +139,10 @@ moonraker_setup(){ create_single_moonraker_instance else create_multi_moonraker_instance + ### step 6.5: enable mainsails remoteMode if its already installed + if [ -d $MAINSAIL_DIR ]; then + enable_mainsail_remotemode + fi fi } From 538c179671fe9de824888461809fdee9b5141f52 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 30 Jan 2021 19:33:38 +0100 Subject: [PATCH 90/97] fix: visual bug in the webui installer --- scripts/install_klipper_webui.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh index cf7c5cb..b82a6f5 100755 --- a/scripts/install_klipper_webui.sh +++ b/scripts/install_klipper_webui.sh @@ -48,8 +48,8 @@ install_webui(){ ### check if moonraker is already installed check_moonraker - [ $1 == "mainsail" ] && INTERFACE="Mainsail" - [ $1 == "fluidd" ] && INTERFACE="Mainsail" + [ $1 == "mainsail" ] && IF_NAME1="Mainsail" && IF_NAME2="Mainsail " + [ $1 == "fluidd" ] && IF_NAME1="Fluidd" && IF_NAME2="Fluidd " ### exit mainsail/fluidd setup if moonraker not found if [ $moonraker_chk_ok = "false" ]; then @@ -57,7 +57,7 @@ install_webui(){ print_msg && clear_msg && return 0 else ok_msg "Moonraker service found!" - status_msg "Initializing $INTERFACE installation ..." + status_msg "Initializing $IF_NAME1 installation ..." fi ### check for other enabled web interfaces @@ -68,7 +68,7 @@ install_webui(){ $1_port_check ### ask user to install the recommended webinterface macros - get_user_selection_kiauh_macros "$INTERFACE " + get_user_selection_kiauh_macros "$IF_NAME2" ### creating the mainsail/fluidd nginx cfg set_nginx_cfg "$1" From 5aaebc2bec183a1617386dcf9b2591253007d315 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 30 Jan 2021 19:34:41 +0100 Subject: [PATCH 91/97] fix: add new cors domain to allow other ports than 80 only too. --- scripts/install_moonraker.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index db7fd5f..f76c19b 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -242,6 +242,7 @@ cors_domains: http://app.fluidd.xyz https://app.fluidd.xyz http://$HOSTNAME + http://$HOSTNAME:* [update_manager] @@ -293,6 +294,7 @@ cors_domains: http://app.fluidd.xyz https://app.fluidd.xyz http://$HOSTNAME + http://$HOSTNAME:* [update_manager] From d0b895a46919a9c7511a6f4e0820eaf82cf0e2de Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 30 Jan 2021 20:42:32 +0100 Subject: [PATCH 92/97] fix.: make warning more clear --- scripts/functions.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index 6133ee3..5baa1e4 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -19,8 +19,12 @@ check_klipper_cfg_path(){ 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! |" + 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. |" bottom_border change_klipper_cfg_path fi @@ -33,7 +37,7 @@ change_klipper_cfg_path(){ while true; do top_border echo -e "| ${red}IMPORTANT:${default} |" - echo -e "| Please enter the new path in the following form: |" + echo -e "| Please enter the new path in the following format: |" printf "| ${yellow}%-51s${default} |\n" "$EXAMPLE_FOLDER" blank_line echo -e "| By default 'klipper_config' is recommended! |" From dc08d8e7e32d7c7d81ed5cdd32a48171593be76b Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 31 Jan 2021 13:32:16 +0100 Subject: [PATCH 93/97] fix: should fix #65 --- scripts/status.sh | 4 ++-- scripts/update.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/status.sh b/scripts/status.sh index 1ab7ff1..d9ffccb 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -1,8 +1,8 @@ kiauh_status(){ if [ -d "${SRCDIR}/kiauh/.git" ]; then - cd ${HOME}/kiauh - git fetch -q + cd ${SRCDIR}/kiauh if git branch -a | grep "* master" -q; then + git fetch -q if [[ "$(git rev-parse --short=8 origin/master)" != "$(git rev-parse --short=8 HEAD)" ]]; then KIAUH_UPDATE_AVAIL="true" fi diff --git a/scripts/update.sh b/scripts/update.sh index 054efac..13b8142 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -1,7 +1,7 @@ update_kiauh(){ if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then status_msg "Updating KIAUH ..." - cd ${HOME}/kiauh + cd ${SRCDIR}/kiauh ### force reset kiauh before updating git reset --hard git pull && ok_msg "Update complete! Please restart KIAUH." From fa8a9ff7ba025435a07ea0bc63f1c9417a12a5c3 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 31 Jan 2021 14:04:23 +0100 Subject: [PATCH 94/97] fix: don't use systemctl commands anymore for reading the status if a service is installed and how much instances. instead only count the service files in /etc/systemd/system. this significantly improves performance of the script on low power hardware like a pi zero --- scripts/status.sh | 82 ++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 47 deletions(-) diff --git a/scripts/status.sh b/scripts/status.sh index d9ffccb..30709ad 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -17,10 +17,12 @@ klipper_status(){ $KLIPPER_DIR $KLIPPY_ENV_DIR ) + + ### count amount of klipper service files in /etc/systemd/system + SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "klipper" | wc -l) + ### remove the "SERVICE" entry from the klipper_data array if a klipper service is installed - 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 + [ $SERVICE_FILE_COUNT -gt 0 ] && unset klipper_data[0] ### count+1 for each found data-item from array for kd in "${klipper_data[@]}" @@ -30,16 +32,9 @@ klipper_status(){ fi done - ### count amount of klipper services - if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then - instances=1 - else - instances=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l) - fi - ### display status if [ "$kcount" == "${#klipper_data[*]}" ]; then - KLIPPER_STATUS="$(printf "${green}Installed: %-5s${default}" $instances)" + KLIPPER_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)" elif [ "$kcount" == 0 ]; then KLIPPER_STATUS="${red}Not installed!${default} " else @@ -49,34 +44,29 @@ klipper_status(){ dwc2_status(){ dcount=0 - dwc2_data=( + dwc_data=( SERVICE $DWC2_DIR $DWC2FK_DIR $DWC_ENV_DIR ) - ### remove the "SERVICE" entry from the klipper_data array if a klipper service is installed - if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "dwc.service")" ] || [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "dwc-[[:digit:]].service")" ]; then - unset dwc2_data[0] - fi + + ### count amount of dwc service files in /etc/systemd/system + SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "dwc" | wc -l) + + ### remove the "SERVICE" entry from the dwc_data array if a dwc service is installed + [ $SERVICE_FILE_COUNT -gt 0 ] && unset dwc_data[0] #count+1 for each found data-item from array - for dd in "${dwc2_data[@]}" + for dd in "${dwc_data[@]}" do if [ -e $dd ]; then dcount=$(expr $dcount + 1) fi done - ### count amount of klipper services - if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "klipper.service")" ]; then - instances=1 - else - instances=$(systemctl list-units --full -all -t service --no-legend | grep -E "klipper-[[:digit:]].service" | wc -l) - fi - - if [ "$dcount" == "${#dwc2_data[*]}" ]; then - DWC2_STATUS="$(printf "${green}Installed: %-5s${default}" $instances)" + if [ "$dcount" == "${#dwc_data[*]}" ]; then + DWC2_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)" elif [ "$dcount" == 0 ]; then DWC2_STATUS="${red}Not installed!${default} " else @@ -91,10 +81,12 @@ moonraker_status(){ $MOONRAKER_DIR $MOONRAKER_ENV_DIR ) - #remove the "SERVICE" entry from the moonraker_data array if a moonraker service is installed - 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 amount of moonraker service files in /etc/systemd/system + SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "moonraker" | wc -l) + + ### remove the "SERVICE" entry from the moonraker_data array if a moonraker service is installed + [ $SERVICE_FILE_COUNT -gt 0 ] && unset moonraker_data[0] ### count+1 for each found data-item from array for mrd in "${moonraker_data[@]}" @@ -104,16 +96,9 @@ moonraker_status(){ fi done - ### count amount of moonraker services - if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ]; then - instances=1 - else - instances=$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service" | wc -l) - fi - ### display status if [ "$mrcount" == "${#moonraker_data[*]}" ]; then - MOONRAKER_STATUS="$(printf "${green}Installed: %-5s${default}" $instances)" + MOONRAKER_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)" elif [ "$mrcount" == 0 ]; then MOONRAKER_STATUS="${red}Not installed!${default} " else @@ -173,13 +158,11 @@ octoprint_status(){ SERVICE $OCTOPRINT_DIR ) - #remove the "SERVICE" entry from the octoprint array if an octoprint service is installed - if systemctl list-unit-files | grep -E "octoprint.*" &>/dev/null; then - unset octoprint_data[0] - fi + ### count amount of octoprint service files in /etc/systemd/system + SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "octoprint" | wc -l) - ### count amount of octoprint services - instances=$(systemctl list-unit-files | grep -E "octoprint.*" | wc -l) + ### remove the "SERVICE" entry from the octoprint_data array if a octoprint service is installed + [ $SERVICE_FILE_COUNT -gt 0 ] && unset octoprint_data[0] #count+1 for each found data-item from array for op in "${octoprint_data[@]}" @@ -191,7 +174,7 @@ octoprint_status(){ ### display status if [ "$ocount" == "${#octoprint_data[*]}" ]; then - OCTOPRINT_STATUS="$(printf "${green}Installed: %-5s${default}" $instances)" + OCTOPRINT_STATUS="$(printf "${green}Installed: %-5s${default}" $SERVICE_FILE_COUNT)" elif [ "$ocount" == 0 ]; then OCTOPRINT_STATUS="${red}Not installed!${default} " else @@ -206,8 +189,13 @@ klipperscreen_status(){ $KLIPPERSCREEN_DIR $KLIPPERSCREEN_ENV_DIR ) - #remove the "SERVICE" entry from the klipperscreen_data array if a klipperscreen service is installed - [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "KlipperScreen.service")" ] && unset klipperscreen_data[0] + + ### count amount of klipperscreen_data service files in /etc/systemd/system + SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "KlipperScreen" | wc -l) + + ### remove the "SERVICE" entry from the klipperscreen_data array if a KlipperScreen service is installed + [ $SERVICE_FILE_COUNT -gt 0 ] && unset klipperscreen_data[0] + #count+1 for each found data-item from array for klscd in "${klipperscreen_data[@]}" do From 26eecbc94bee75d1c353428010bf1bc099cf6861 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 31 Jan 2021 15:59:50 +0100 Subject: [PATCH 95/97] fix: refactor main menu, add dwc and octoprint commands --- scripts/ui/general_ui.sh | 6 ++---- scripts/ui/main_menu.sh | 36 ++++++++++++++++++------------------ 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/scripts/ui/general_ui.sh b/scripts/ui/general_ui.sh index 0735131..e871c9a 100755 --- a/scripts/ui/general_ui.sh +++ b/scripts/ui/general_ui.sh @@ -45,8 +45,7 @@ kiauh_update_msg(){ ### TODO: rework other menus to make use of the following functions too and make them more readable do_action(){ - clear - print_header + clear && print_header ### $1 is the action the user wants to fire $1 print_msg && clear_msg @@ -55,8 +54,7 @@ do_action(){ } deny_action(){ - clear - print_header + clear && print_header print_unkown_cmd print_msg && clear_msg $1 diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index f10bf3c..bf28ea8 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -44,29 +44,29 @@ main_menu(){ read -p "${cyan}Perform action:${default} " action; echo case "$action" in "start klipper") - clear && print_header - klipper_service "start" - main_ui;; + do_action "klipper_service start" "main_ui";; "stop klipper") - clear && print_header - klipper_service "stop" - main_ui;; + do_action "klipper_service stop" "main_ui";; "restart klipper") - clear && print_header - klipper_service "restart" - main_ui;; + do_action "klipper_service restart" "main_ui";; "start moonraker") - clear && print_header - moonraker_service "start" - main_ui;; + do_action "moonraker_service start" "main_ui";; "stop moonraker") - clear && print_header - moonraker_service "stop" - main_ui;; + do_action "moonraker_service stop" "main_ui";; "restart moonraker") - clear && print_header - moonraker_service "restart" - main_ui;; + do_action "moonraker_service restart" "main_ui";; + "start dwc") + do_action "dwc_service start" "main_ui";; + "stop dwc") + do_action "dwc_service stop" "main_ui";; + "restart dwc") + do_action "dwc_service restart" "main_ui";; + "start octoprint") + do_action "octoprint_service start" "main_ui";; + "stop octoprint") + do_action "octoprint_service stop" "main_ui";; + "restart octoprint") + do_action "octoprint_service restart" "main_ui";; update) do_action "update_kiauh" "main_ui";; 0) From c3af82745b623bd94e6bc88fddbf56b06fd86ba4 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 31 Jan 2021 16:09:00 +0100 Subject: [PATCH 96/97] Update docs --- README.md | 32 ++++++++++++++++------------ docs/changelog.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++ docs/features.md | 5 ----- 3 files changed, 73 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index d72f5b1..e95bff1 100644 --- a/README.md +++ b/README.md @@ -12,24 +12,23 @@ This script acts as a helping hand for you to get set up in a fast and comfortable way.\ **This does not mean, it will relieve you of using your brain.exe! 🧠**\ +Please also always pay attention to the individual component repositories (all linked below).\ Feel free to give it a try. If you have suggestions or encounter any problems, please report them. --- ## **🛠️ Instructions:** -For downloading this script it is best to have git already installed.\ +For downloading this script it is necessary to have git installed.\ If you haven't, please run `sudo apt-get install git -y` to install git first.\ -You will need it anyways! +You will need it anyways! 😄 After git is installed, use the following commands in the given order to download and execute the script: ```shell cd ~ git clone https://github.com/th33xitus/kiauh.git -cd kiauh -chmod +x kiauh.sh scripts/* -./kiauh.sh +./kiauh/kiauh.sh ``` ## Additional Instructions: @@ -43,11 +42,14 @@ Feel free to check out his work. ## **🧰 Functions and Features:** +- **New in v3.0** You can now install multiple instances (Klipper/Moonraker/DWC/Octoprint) on the same Pi! +--- ### **Core Functions:** -- **Installing** of the Klipper Firmware to your Raspberry Pi or other Linux Distribution which makes use of init.d. -- **Installing** of several different web interfaces such as Duet Web Control, Mainsail, Fluidd or OctoPrint including their dependencies. -- **Installing** of the Moonraker API +- **Installing** Klipper to your Raspberry Pi or other Debian based Linux Distribution. +- **Installing** of the Moonraker API (needed for Mainsail, Fluidd and KlipperScreen) +- **Installing** several different web interfaces such as Mainsail, Fluidd, Duet Web Control or OctoPrint including their dependencies. +- **Installing** of KlipperScreen (OctoScreen but for Klipper!) - **Updating** of all the listed installations above excluding OctoPrint. For updating OctoPrint, please use the OctoPrint interface! - **Removing** of all the listed installations above. - **Backup** of all the listed installations above. @@ -56,8 +58,7 @@ Feel free to check out his work. - Build the Klipper Firmware - Flash the MCU -- Read ID of the currently connected printer (only one at the time) -- Write necessary entries to your printer.cfg, some of them customizable right in the CLI. +- Read ID of the currently connected MCU - and more ... ### **For a list of additional features please see: [Feature List](docs/features.md)** @@ -67,13 +68,18 @@ Feel free to check out his work. ## **📝 Notes:** - Tested **only** on Raspberry Pi OS Lite (Debian Buster) +- ( Although similar Debian based distributions might also work... ) - During the use of this script you might be asked for your sudo password. There are several functions involved which need sudo privileges. --- ## **🛈 Sources & Further Information** -For more information or instructions, please check out the appropriate repositories listed below: +If you need some more detailed instructions on how to install Klipper and Mainsail with KIAUH, check out this website:\ +[Installing Klipper and Mainsail](https://3dp.tumbleweedlabs.com/firmware/klipper-firmware/installing-klipper-and-mainsail-on-your-raspberry-pi)\ +Credits for these instructions go to [@tumbleweedlabs](https://github.com/tumbleweedlabs). + +For more information or instructions to the various components KIAUH can install, please check out the corresponding repositories listed below: --- @@ -135,6 +141,6 @@ https://github.com/OctoPrint/OctoPrint ## **❓ FAQ** -**_Q: Can i use this script to install multiple instancec of Klipper on the same Pi? (Multisession?)_** +**_Q: Can i use this script to install multiple instances of Klipper on the same Pi? (Multisession?)_** -**A:** No, and at the moment i don't plan to implement this function. For multisession installations take a look at this script manu7irl created: https://github.com/manu7irl/klipper-DWC2-installer . Keep in mind that klipper-DWC2-installer and KIAUH are **NOT** compatible with each other. +**A:** Yes, it is finally possible 🙂 diff --git a/docs/changelog.md b/docs/changelog.md index 482478e..598fe60 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,60 @@ This document covers possible important changes to KIAUH. +### 2021-01-31 + +* **This is a big one... KIAUH v3.0 is out.**\ +With this update you can now install multiple instances of Klipper, Moonraker, Duet Web Control or Octoprint on the same Pi. This was quite a big rework of the whole script. So bugs can appear but with the help of some testers, i think there shouldn't be any critical ones anymore. In this regards thanks to @lixxbox and @zellneralex for testing. + +* Important changes to how installations are set up now: All components get installed as systemd services. Installation via init.d was dropped completely! This shouldn't affect you at all, since the common linux distributions like RaspberryPi OS or custom distributions like MainsailOS, FluiddPi or OctoPi support both ways of installing services. I just wanted to mention it here. + +* Now with KIAUH v3.0 and multi-instance installation capabilities, there are some things to point out. You will now need to tell KIAUH where your printers configurations are located when installing Klipper for the first time. Even though it is not recommended, you can change this location with the help of KIAUH and rewrite Klipper and Moonraker to use the new location. + +* When setting up a multi-instance system, the folder structure will only change slightly. The goal was to keep it as compatible as possible with the custom distributions like mainsailOS and FluiddPi. This should help converting a single-instance setup of mainsailOS/FluiddPi to a multi-instance setup in no time, but keeping single-instance backwards compatibility if needed at a later point in time. + +* The folder structure is as follows when setting up multi-instances:\ +Each printer instance will get its own folder within your configuration location. The decision to this specific structure was made to make it as painless and easy as possible to convert to a multi-instance setup. +Here is an example: + ```shell + /home/ + └── klipper_config + ├── printer_1 + │ ├── printer.cfg + │ └── moonraker.conf + ├── printer_2 + │ ├── printer.cfg + │ └── moonraker.conf + └── printer_n + ├── printer.cfg + └── moonraker.conf + ``` +* Also when setting up multi-instances of each service, the name of each service slightly changes. +Each service gets its corresponding instance added to the service filename. + + **This only applies to multi-instances! Single instance installations with KIAUH will keep their original names!** + + Corresponding to the filetree example from above that would mean: + ``` + Klipper services: + --> klipper-1.service + --> klipper-2.service + --> klipper-n.service + + Moonraker services: + --> moonraker-1.service + --> moonraker-2.service + --> moonraker-n.service + ``` +* The same service file rules from above apply to DWC and OctoPrint even though only Klipper and Moonraker are shown in this example. + +* You can start, stop and restart all Klipper, Moonraker, DWC and OctoPrint instances from the KIAUH main menu. For doing this, just type "stop klipper", "start moonraker", "restart octoprint" and so on. + +* KIAUH v3.0 relocated its ini-file. It is now a hidden file in the users home-directory calles `.kiauh.ini`. This has the benefit of keeping all values in that file between possible re-installations of KIAUH. Otherwise that file would be lost. + +* The option of adding more trusted clients to the moonraker.conf file was dropped. Since you can edit this file right inside of Mainsail or Fluidd, only some basic entries are made which get you running. + +* I bet i have missed mentioning other stuff as well because it took me quite some time to re-write many functions. So i just hope you like the new version 😄 + ### 2020-11-28 * KIAUH now supports the installation, update and removal of [KlipperScreen](https://github.com/jordanruthe/KlipperScreen). This feature was was provided by [jordanruthe](https://github.com/jordanruthe)! Thank you! diff --git a/docs/features.md b/docs/features.md index c8571c1..c55714a 100644 --- a/docs/features.md +++ b/docs/features.md @@ -17,11 +17,6 @@ That means: - set the behavior to "Cancel any ongoing prints but stay connected to the printer" - **Enable/Disable OctoPrint Service:**\ Usefull when using DWC2/Mainsail/Fluidd and OctoPrint at the same time to prevent them interfering with each other -- **Set up reverse proxy for DWC2, Mainsail, Fluidd and OctoPrint and changing the hostname:** - - The script can install and configure Nginx for the selected webinterface - - It also allows you to make your webinterface reachable over an URL like `.local` via avahi - - Example: If you name the host "my-printer", type `my-printer.local` in your webbrowser to open the installed webinterface - - If there is more than one webinterface installed, you have to append the port to that adress - **Installing a G-Code Shell Command extension:**\ For further information about that extension please see the [G-Code Shell Command Extension Doc](gcode_shell_command.md) From 431f58af4b18e5b5fe8492a20ced39c02297814b Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 31 Jan 2021 16:16:44 +0100 Subject: [PATCH 97/97] fix: code cleanup --- scripts/install_moonraker.sh | 128 +---------------------------------- 1 file changed, 1 insertion(+), 127 deletions(-) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index f76c19b..7119d6c 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -466,32 +466,6 @@ moonraker_conf_creation(){ #********************************************************************************************# ############################################################################################## -# add_trusted_clients_dialog(){ -# #ask user for more trusted clients -# while true; do -# echo -# top_border -# echo -e "| Apart from devices of your local network, you can add |" -# echo -e "| additional trusted clients to the moonraker.conf file |" -# bottom_border -# read -p "${cyan}###### Add additional trusted clients? (y/N):${default} " yn -# case "$yn" in -# Y|y|Yes|yes) -# echo -e "###### > Yes" -# ADD_TRUSTED_CLIENT="true" -# custom_trusted_clients -# break;; -# N|n|No|no|"") -# echo -e "###### > No" -# ADD_TRUSTED_CLIENT="false" -# break;; -# *) -# print_unkown_cmd -# print_msg && clear_msg;; -# esac -# done -# } - process_octoprint_dialog(){ #ask user to disable octoprint when its service was found if [ "$OCTOPRINT_ENABLED" = "true" ]; then @@ -621,104 +595,4 @@ process_haproxy_lighttpd_dialog(){ esac done fi -} - -############################################################# -############################################################# - -# setup_moonraker_conf(){ -# if [ "$MOONRAKER_CONF_FOUND" = "false" ]; then -# status_msg "Creating moonraker.conf ..." -# cp ${HOME}/kiauh/resources/moonraker.conf ${HOME} -# ok_msg "moonraker.conf created!" -# status_msg "Writing trusted clients to config ..." -# write_default_trusted_clients -# ok_msg "Trusted clients written!" -# fi -# #check for at least one trusted client in an already existing moonraker.conf -# #if no entry is found, write default trusted client -# if [ "$MOONRAKER_CONF_FOUND" = "true" ]; then -# if grep "trusted_clients:" ${HOME}/moonraker.conf -q; then -# TC_LINE=$(grep -n "trusted_clients:" ${HOME}/moonraker.conf | cut -d ":" -f1) -# FIRST_IP_LINE=$(expr $TC_LINE + 1) -# FIRST_IP=$(sed -n "$FIRST_IP_LINE"p ${HOME}/moonraker.conf | cut -d" " -f5) -# #if [[ ! $FIRST_IP =~ ([0-9].[0-9].[0-9].[0-9]) ]]; then -# if [ "$FIRST_IP" = "" ]; then -# status_msg "Writing trusted clients to config ..." -# backup_moonraker_conf && write_default_trusted_clients -# ok_msg "Trusted clients written!" -# fi -# fi -# fi -# } - -# ############################################################# -# ############################################################# - -# custom_trusted_clients(){ -# if [ "$ADD_TRUSTED_CLIENT" = "true" ]; then -# unset trusted_arr -# echo -# top_border -# echo -e "| You can now add additional trusted clients to your |" -# echo -e "| moonraker.conf file. Be warned, that there is no |" -# echo -e "| spellcheck to check for valid input. |" -# echo -e "| Make sure to type the IP correct! |" -# echo -e "| |" -# echo -e "| If you want to add IP ranges, you can type in e.g.: |" -# echo -e "| 192.168.1.0/24 |" -# echo -e "| This will add the IPs 192.168.1.1 to 192.168.1.254 |" -# echo -e "|-------------------------------------------------------|" -# echo -e "| You can add as many IPs / IP ranges as you want. |" -# echo -e "| When you are done type '${cyan}done${default}' to exit this dialoge. |" -# bottom_border -# while true; do -# read -p "${cyan}###### Enter IP and press ENTER:${default} " TRUSTED_IP -# case "$TRUSTED_IP" in -# done) -# echo -# echo -e "List of IPs to add:" -# for ip in ${trusted_arr[@]} -# do -# echo -e "${cyan}● $ip ${default}" -# done -# while true; do -# echo -# echo -e "Select 'Yes' to confirm, 'No' to start again" -# echo -e "or 'Q' to abort and skip." -# read -p "${cyan}###### Confirm writing (Y/n/q):${default} " yn -# case "$yn" in -# Y|y|Yes|yes|"") -# echo -e "###### > Yes" -# TUSTED_CLIENT_CONFIRM="true" -# break;; -# N|n|No|no) -# echo -e "###### > No" -# custom_trusted_clients -# break;; -# Q|q) -# unset trusted_arr -# echo -e "###### > Abort" -# echo -e "${red}Aborting ...${default}" -# break;; -# esac -# done -# break;; -# *) -# trusted_arr+=($TRUSTED_IP);; -# esac -# done -# fi -# } - -# write_custom_trusted_clients(){ -# if [ "$TUSTED_CLIENT_CONFIRM" = "true" ]; then -# if [ "${#trusted_arr[@]}" != "0" ]; then -# for ip in ${trusted_arr[@]} -# do -# sed -i "/trusted_clients\:/a \ \ \ \ $ip" ${HOME}/moonraker.conf -# done -# ok_msg "Custom IPs written to moonraker.conf!" -# fi -# fi -# } \ No newline at end of file +} \ No newline at end of file