From c82e21419c4db621ef1ed73aab80a107ab4bfbce Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Thu, 20 Aug 2020 16:29:15 +0200 Subject: [PATCH 01/31] fix: change color variables --- kiauh.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index f4465c5..129c37d 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -4,11 +4,11 @@ set -e ### set some variables ERROR_MSG="" -green="\e[92m" -yellow="\e[93m" -red="\e[91m" -cyan="\e[96m" -default="\e[39m" +green=$(echo -en "\001\033[01;32m\002") +yellow=$(echo -en "\001\033[01;33m\002") +red=$(echo -en "\001\033[01;31m\002") +cyan=$(echo -en "\001\033[01;36m\002") +default=$(echo -en "\001\033[0m\002") ### set some messages warn_msg(){ @@ -178,7 +178,7 @@ install_menu(){ 3) clear print_header - mainsail_install_routine + install_moonraker print_msg && clear_msg install_ui;; 4) From 0dc5edfd7b9a0a574f6dc17797ec7d0b31e9e43f Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Thu, 20 Aug 2020 16:30:40 +0200 Subject: [PATCH 02/31] add: mainsail_macros.cfg --- resources/mainsail_macros.cfg | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 resources/mainsail_macros.cfg diff --git a/resources/mainsail_macros.cfg b/resources/mainsail_macros.cfg new file mode 100644 index 0000000..214c6c3 --- /dev/null +++ b/resources/mainsail_macros.cfg @@ -0,0 +1,42 @@ +########################## +### CREATED WITH KIAUH ### +########################## +[gcode_macro CANCEL_PRINT] +rename_existing: BASE_CANCEL_PRINT +default_parameter_X: 230 +default_parameter_Y: 230 +default_parameter_Z: 10 +gcode: + M104 S0 + M140 S0 + M141 S0 + M106 S0 + CLEAR_PAUSE + SDCARD_RESET_FILE + BASE_CANCEL_PRINT + +[gcode_macro PAUSE] +rename_existing: BASE_PAUSE +default_parameter_X: 230 +default_parameter_Y: 230 +default_parameter_Z: 10 +gcode: + SAVE_GCODE_STATE NAME=PAUSE_state + BASE_PAUSE + G91 + G1 E-1.7 F2100 + G1 Z{Z} + G90 + G1 X{X} Y{Y} F6000 + G91 + +[gcode_macro RESUME] +rename_existing: BASE_RESUME +gcode: + G91 + G1 E1.7 F2100 + G91 + RESTORE_GCODE_STATE NAME=PAUSE_state MOVE=1 + BASE_RESUME +########################## +########################## \ No newline at end of file From 1a037c687b45b319206503631487be9a0d037b9b Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Thu, 20 Aug 2020 16:31:28 +0200 Subject: [PATCH 03/31] add: new log location to mainsail remove data_arr --- scripts/remove.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/remove.sh b/scripts/remove.sh index bfa3c7a..44f6722 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -67,6 +67,7 @@ remove_mainsail(){ $MOONRAKER_ENV_DIR ${HOME}/moonraker.conf ${HOME}/moonraker.log + ${HOME}/klipper_config/moonraker.log ${HOME}/.klippy_api_key ${HOME}/.moonraker_api_key /etc/nginx/sites-available/mainsail @@ -104,9 +105,10 @@ remove_mainsail(){ cp ${HOME}/klipper_config/printer.cfg ${HOME} && ok_msg "File copied!" fi #remove moonraker.log and symlink - if [[ -L ${HOME}/moonraker.log || -e /tmp/moonraker.log ]]; then + if [[ -L ${HOME}/moonraker.log || -L ${HOME}/klipper_config/moonraker.log || -e /tmp/moonraker.log ]]; then status_msg "Removing moonraker.log and Symlink ..." - rm -rf ${HOME}/moonraker.log /tmp/moonraker.log && ok_msg "Files removed!" + rm -rf ${HOME}/moonraker.log ${HOME}/klipper_config/moonraker.log /tmp/moonraker.log + ok_msg "Files removed!" fi #remove mainsail cfg if [ -e /etc/nginx/sites-available/mainsail ]; then From 716b21a62942fcf191e81d41923fd9e3657f5627 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Thu, 20 Aug 2020 16:32:01 +0200 Subject: [PATCH 04/31] feature: new experimental moonraker/mainsail install routine --- resources/moonraker.conf | 3 +- scripts/functions.sh | 122 ++++++----- scripts/install_mainsail.sh | 201 +++-------------- scripts/install_moonraker.sh | 405 +++++++++++++++++++++++++++++++++++ 4 files changed, 503 insertions(+), 228 deletions(-) create mode 100755 scripts/install_moonraker.sh diff --git a/resources/moonraker.conf b/resources/moonraker.conf index 3fc16e1..715bd8e 100644 --- a/resources/moonraker.conf +++ b/resources/moonraker.conf @@ -5,5 +5,4 @@ config_path: ~/klipper_config [authorization] enabled: true trusted_clients: - 127.0.0.1 - 192.168.1.0/24 \ No newline at end of file + 127.0.0.1 \ No newline at end of file diff --git a/scripts/functions.sh b/scripts/functions.sh index 7904a14..8faca3c 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -312,63 +312,83 @@ create_custom_hostname(){ echo -e "| browsing to: http://my-printer.local |" bottom_border while true; do - echo -e "${cyan}" - read -p "###### Do you want to change the hostname? (Y/n): " yn - echo -e "${default}" + read -p "${cyan}###### Do you want to change the hostname? (y/N):${default} " yn case "$yn" in - Y|y|Yes|yes|"") set_hostname; break;; - N|n|No|no) break;; + Y|y|Yes|yes) + user_input_hostname + break;; + N|n|No|no|"") break;; esac done } -set_hostname(){ - #check for dependencies - dep=(avahi-daemon) - dependency_check - #execute operations - #get current hostname and write to variable - HOSTNAME=$(hostname) - #create host file if missing or create backup of existing one with current date&time - if [ -f /etc/hosts ]; then - status_msg "Creating backup of hosts file ..." - get_date - sudo cp /etc/hosts /etc/hosts."$current_date".bak - ok_msg "Backup done!" - ok_msg "File:'/etc/hosts."$current_date".bak'" - else - sudo touch /etc/hosts - fi - echo - top_border - echo -e "| ${green}Allowed characters: a-z, 0-9 and single '-'${default} |" - echo -e "| ${red}No special characters allowed!${default} |" - echo -e "| ${red}No leading or trailing '-' allowed!${default} |" - bottom_border - while true; do - echo -e "${cyan}" - read -p "###### Please set the new hostname: " NEW_HOSTNAME - echo -e "${default}" - if [[ $NEW_HOSTNAME =~ ^[^\-]+([0-9a-z]\-{0,1})+[^\-]+$ ]]; then - ok_msg "'$NEW_HOSTNAME' is a valid hostname!" - #set hostname in /etc/hostname - status_msg "Setting hostname to '$NEW_HOSTNAME' ..." - status_msg "Please wait ..." - sudo hostnamectl set-hostname $NEW_HOSTNAME - #write new hostname to /etc/hosts - status_msg "Writing new hostname to /etc/hosts ..." - if cat /etc/hosts | grep "###set by kiauh" &>/dev/null; then - sudo sed -i "/###set by kiauh/s/\<$HOSTNAME\>/$NEW_HOSTNAME/" /etc/hosts - else - echo "127.0.0.1 $NEW_HOSTNAME ###set by kiauh" | sudo tee -a /etc/hosts &>/dev/null - fi - ok_msg "New hostname successfully configured!" - ok_msg "Remember to reboot your machine for the changes to take effect!" +user_input_hostname(){ + unset NEW_HOSTNAME + echo + top_border + echo -e "| ${green}Allowed characters: a-z, 0-9 and single '-'${default} |" + echo -e "| ${red}No special characters allowed!${default} |" + echo -e "| ${red}No leading or trailing '-' allowed!${default} |" + bottom_border + while true; do + read -p "${cyan}###### Please set the new hostname:${default} " NEW_HOSTNAME + if [[ $NEW_HOSTNAME =~ ^[^\-\_]+([0-9a-z]\-{0,1})+[^\-\_]+$ ]]; then + ok_msg "'$NEW_HOSTNAME' is a valid hostname!" + HOSTNAME_VALID="true" + while true; do + echo + read -p "${cyan}###### Do you want '$NEW_HOSTNAME' to be the new hostname? (Y/n):${default} " yn + case "$yn" in + Y|y|Yes|yes|"") + echo -e "###### > Yes" + HOSTENAME_CONFIRM="true" + break;; + N|n|No|no) + echo -e "###### > No" + echo -e "${red}Skip hostname change ...${default}" + HOSTENAME_CONFIRM="false" + break;; + esac + done break + else + warn_msg "'$NEW_HOSTNAME' is not a valid hostname!" + fi + done +} + +set_hostname(){ + if [ "$HOSTNAME_VALID" = "true" ] && [ "$HOSTENAME_CONFIRM" = "true" ]; then + #check for dependencies + dep=(avahi-daemon) + dependency_check + #execute operations + #get current hostname and write to variable + HOSTNAME=$(hostname) + #create host file if missing or create backup of existing one with current date&time + if [ -f /etc/hosts ]; then + status_msg "Creating backup of hosts file ..." + get_date + sudo cp /etc/hosts /etc/hosts."$current_date".bak + ok_msg "Backup done!" + ok_msg "File:'/etc/hosts."$current_date".bak'" else - warn_msg "'$NEW_HOSTNAME' is not a valid hostname!" + sudo touch /etc/hosts fi - done + #set hostname in /etc/hostname + status_msg "Setting hostname to '$NEW_HOSTNAME' ..." + status_msg "Please wait ..." + sudo hostnamectl set-hostname "$NEW_HOSTNAME" + #write new hostname to /etc/hosts + status_msg "Writing new hostname to /etc/hosts ..." + if cat /etc/hosts | grep "###set by kiauh" &>/dev/null; then + sudo sed -i "/###set by kiauh/s/\<$HOSTNAME\>/$NEW_HOSTNAME/" /etc/hosts + else + echo "127.0.0.1 $NEW_HOSTNAME ###set by kiauh" | sudo tee -a /etc/hosts &>/dev/null + fi + ok_msg "New hostname successfully configured!" + ok_msg "Remember to reboot for the changes to take effect!" + fi } remove_branding(){ @@ -379,9 +399,7 @@ remove_branding(){ echo -e "| this action again, everytime you updated Mainsail. |" bottom_border while true; do - echo -e "${cyan}" - read -p "###### Do you want to continue? (Y/n): " yn - echo -e "${default}" + read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn case "$yn" in Y|y|Yes|yes|"") cd $MAINSAIL_DIR/css diff --git a/scripts/install_mainsail.sh b/scripts/install_mainsail.sh index ec06a8f..eaff8c6 100755 --- a/scripts/install_mainsail.sh +++ b/scripts/install_mainsail.sh @@ -1,179 +1,24 @@ -mainsail_install_routine(){ - if [ -d $KLIPPER_DIR ]; then +install_mainsail(){ + if [ -d $KLIPPER_DIR ] && [ "$INST_MAINSAIL" = "true" ]; then #disable octoprint service if installed if systemctl is-enabled octoprint.service -q 2>/dev/null; then disable_octoprint_service fi disable_haproxy_lighttpd - remove_haproxy_lighttpd - install_moonraker - check_printer_cfg - restart_moonraker - restart_klipper + #remove_haproxy_lighttpd + #beginning of mainsail installation create_reverse_proxy "mainsail" test_api test_nginx - install_mainsail - create_custom_hostname + mainsail_setup ok_msg "Mainsail installation complete!"; echo else ERROR_MSG=" Please install Klipper first!\n Skipping..." fi } -install_moonraker(){ - dep=(wget curl unzip) - dependency_check - status_msg "Downloading Moonraker ..." - cd ${HOME} && git clone $MOONRAKER_REPO - ok_msg "Download complete!" - backup_printer_cfg - status_msg "Installing Moonraker ..." - $MOONRAKER_DIR/scripts/install-moonraker.sh && ok_msg "Moonraker successfully installed!" - #copy basic moonraker.conf - if [ ! -e ${HOME}/moonraker.conf ]; then - status_msg "Creating moonraker.conf ..." - cp ${HOME}/kiauh/resources/moonraker.conf ${HOME} - ok_msg "moonraker.conf created!" - fi - #create sdcard folder - if [ ! -d ${HOME}/sdcard ]; then - status_msg "Creating sdcard directory ..." - mkdir ${HOME}/sdcard - ok_msg "sdcard directory created!" - fi - #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 - #move printer.cfg to new config location - if [ -e ${HOME}/printer.cfg ]; then - status_msg "Moving printer.cfg to its new location ..." - mv ${HOME}/printer.cfg ${HOME}/klipper_config - ok_msg "Done!" - status_msg "Create symlink in home directory ..." - ln -s ${HOME}/klipper_config/printer.cfg ${HOME} - ok_msg "Done!" - else - warn_msg "No printer.cfg was found!" - status_msg "Creating a default printer.cfg ..." - create_default_cfg - create_mainsail_macro_cfg - ln -s ${HOME}/klipper_config/printer.cfg ${HOME} - ok_msg "Default printer.cfg created!" - fi - #create a moonraker.log symlink in home-dir just for convenience - if [ ! -e ${HOME}/moonraker.log ]; then - status_msg "Creating moonraker.log symlink ..." - ln -s /tmp/moonraker.log ${HOME}/moonraker.log && ok_msg "Symlink created!" - fi -} - -check_printer_cfg(){ - if [ -e $PRINTER_CFG ]; then - check_vsdcard_section - fi -} - -check_vsdcard_section(){ - # check if virtual sdcard is present in printer.cfg - status_msg "Checking for virtual_sdcard configuration ..." - if [ $(grep '^\[virtual_sdcard\]$' $PRINTER_CFG) ]; then - ok_msg "Virtual sdcard already configured!" - else - status_msg "No virtual sdcard entry found." - ok_msg "Virtual sdcard entry added to printer.cfg!" -# append the following lines to printer.cfg -cat <> $PRINTER_CFG - -########################## -### CREATED WITH KIAUH ### -########################## -[virtual_sdcard] -path: ~/sdcard - -[pause_resume] -[display_status] -########################## -########################## -VSDCARD - fi -} - -create_default_cfg(){ -#create default config -touch ${HOME}/klipper_config/printer.cfg -cat <> ${HOME}/klipper_config/printer.cfg - -########################## -### CREATED WITH KIAUH ### -########################## -[virtual_sdcard] -path: ~/sdcard - -[pause_resume] -[display_status] -[include ~/klipper_config/mainsail_macros.cfg] - -########################## -########################## -DEFAULT_CFG -} - -create_mainsail_macro_cfg(){ -#create extra mainsail macro config -touch ${HOME}/klipper_config/mainsail_macros.cfg -cat <> ${HOME}/klipper_config/mainsail_macros.cfg -########################## -### CREATED WITH KIAUH ### -########################## -[gcode_macro CANCEL] -default_parameter_X: 230 -default_parameter_Y: 230 -default_parameter_Z: 10 -gcode: - M104 S0 - M140 S0 - M141 S0 - M106 S0 - CLEAR_PAUSE - SDCARD_RESET_FILE - -[gcode_macro CANCEL_PRINT] -gcode: - CANCEL - -[gcode_macro PAUSE] -rename_existing: BASE_PAUSE -default_parameter_X: 230 -default_parameter_Y: 230 -default_parameter_Z: 10 -gcode: - SAVE_GCODE_STATE NAME=PAUSE_state - BASE_PAUSE - G91 - G1 E-1.7 F2100 - G1 Z{Z} - G90 - G1 X{X} Y{Y} F6000 - G91 - -[gcode_macro RESUME] -rename_existing: BASE_RESUME -gcode: - G91 - G1 E1.7 F2100 - G91 - RESTORE_GCODE_STATE NAME=PAUSE_state MOVE=1 - BASE_RESUME -########################## -########################## -MAINSAIL_MACRO_CFG -} - disable_haproxy_lighttpd(){ + disable_service=(haproxy lighttpd) if systemctl is-active haproxy -q; then status_msg "Stopping haproxy service ..." sudo /etc/init.d/haproxy stop && ok_msg "Service stopped!" @@ -182,26 +27,34 @@ disable_haproxy_lighttpd(){ status_msg "Stopping lighttpd service ..." sudo /etc/init.d/lighttpd stop && ok_msg "Service stopped!" fi -} - -remove_haproxy_lighttpd(){ - rem=(haproxy lighttpd) - for remove in "${rem[@]}" + for service in "${disable_service[@]}" do - if [[ $(dpkg-query -f'${Status}' --show $remove 2>/dev/null) = *\ installed ]]; then - delete+=($remove) + if [[ $(dpkg-query -f'${Status}' --show $service 2>/dev/null) = *\ installed ]]; then + status_msg "Disabling $service service ..." + sudo apt-get disable $service + ok_msg "$service service disabled!" fi done - if ! [ ${#delete[@]} -eq 0 ]; then - sudo apt-get remove ${delete[@]} -y - fi } +#remove_haproxy_lighttpd(){ +# rem=(haproxy lighttpd) +# for remove in "${rem[@]}" +# do +# if [[ $(dpkg-query -f'${Status}' --show $remove 2>/dev/null) = *\ installed #]]; then +# delete+=($remove) +# fi +# done +# if ! [ ${#delete[@]} -eq 0 ]; then +# sudo apt-get remove ${delete[@]} -y +# fi +#} + test_api(){ status_msg "Testing API ..." sleep 5 status_msg "API response from http://localhost:7125/printer/info:" - API_RESPONSE="$(curl -sG4 http://localhost:7125/printer/info)" + API_RESPONSE=$(curl -sG4m5 http://localhost:7125/printer/info) echo -e "${cyan}$API_RESPONSE${default}" if [ $(curl -sG4 "http://localhost:7125/printer/info" | grep '^{"result"' -c) -eq 1 ]; then echo; ok_msg "Klipper API is working correctly!"; echo @@ -215,7 +68,7 @@ test_nginx(){ status_msg "Testing Nginx ..." sleep 5 status_msg "API response from http://localhost/printer/info:" - API_RESPONSE="$(curl -sG4 http://localhost/printer/info)" + API_RESPONSE="$(curl -sG4m5 http://localhost/printer/info)" echo -e "${cyan}$API_RESPONSE${default}" if [ $(curl -sG4 "http://localhost/printer/info" | grep '^{"result"' -c) -eq 1 ]; then echo; ok_msg "Nginx is working correctly!"; echo @@ -233,7 +86,7 @@ mainsail_dl_url(){ MAINSAIL_URL=https://github.com/meteyou/mainsail/releases/download/v"$MAINSAIL_VERSION"/mainsail-beta-"$MAINSAIL_VERSION".zip } -install_mainsail(){ +mainsail_setup(){ mainsail_dl_url if [ ! -d $MAINSAIL_DIR ]; then mkdir $MAINSAIL_DIR diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh new file mode 100755 index 0000000..48c42a7 --- /dev/null +++ b/scripts/install_moonraker.sh @@ -0,0 +1,405 @@ +install_moonraker(){ + system_check_moonraker + #ask user for customization + get_user_selections_moonraker + #moonraker main installation + moonraker_setup + check_for_folder + #setup configs + setup_printer_config + setup_moonraker_conf + #execute customizations + write_custom_trusted_clients + symlink_moonraker_log + install_mainsail + set_hostname + #after install actions + restart_moonraker + restart_klipper +} + +system_check_moonraker(){ + status_msg "Initializing Moonraker installation ..." + #check for existing printer.cfg and for the location + if [ ! -e ${HOME}/printer.cfg ] && [ ! -e ${HOME}/klipper_config/printer.cfg ]; then + PRINTER_CFG_FOUND="false" + else + if [ -f ${HOME}/printer.cfg ]; then + PRINTER_CFG_FOUND="true" + PRINTER_CFG_LOC="${HOME}/printer.cfg" + fi + if [ -f ${HOME}/klipper_config/printer.cfg ]; then + PRINTER_CFG_FOUND="true" + PRINTER_CFG_LOC="${HOME}/klipper_config/printer.cfg" + fi + fi + #check for existing moonraker.log symlink in /klipper_config + if [ ! -e ${HOME}/klipper_config/moonraker.log ]; then + MOONRAKER_SL_FOUND="false" + else + MOONRAKER_SL_FOUND="true" + fi + #check for existing moonraker.conf + if [ ! -f ${HOME}/moonraker.conf ]; then + MOONRAKER_CONF_FOUND="false" + else + MOONRAKER_CONF_FOUND="true" + fi +} + +get_user_selections_moonraker(){ + #ask if moonraker only or moonraker + mainsail + while true; do + echo + top_border + echo -e "| Do you want to install Moonraker and Mainsail? |" + echo -e "| You can choose to install Moonraker only by answering |" + echo -e "| with 'No'. |" + hr + echo -e "| If you select 'Yes' please be aware that an existing |" + echo -e "| Mainsail installation will then be overwritten! |" + bottom_border + read -p "${cyan}###### Install Moonraker + Mainsail? (Y/n):${default} " yn + case "$yn" in + Y|y|Yes|yes|"") + echo -e "###### > Yes" + INST_MAINSAIL="true";; + N|n|No|no) + echo -e "###### > No" + INST_MAINSAIL="false";; + esac + break + done + #ask to change hostname if mainsail should be installed as well + if [ "$INST_MAINSAIL" = "true" ]; then + create_custom_hostname + fi + #user selection for printer.cfg + if [ "$PRINTER_CFG_FOUND" = "false" ]; then + while true; do + echo + warn_msg "No printer.cfg found!" + 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";; + N|n|No|no) + echo -e "###### > No" + SEL_DEF_CFG="false";; + esac + break + 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";; + N|n|No|no) + echo -e "###### > No" + SEL_MRLOG_SL="false";; + esac + break + 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 + ;; + N|n|No|no|"") + echo -e "###### > No" + ADD_TRUSTED_CLIENT="false";; + esac + break + done + #ask user for mainsail default macros + while true; do + echo + read -p "${cyan}###### Add the recommended Mainsail macros? (Y/n):${default} " + case "$yn" in + Y|y|Yes|yes|"") + echo -e "###### > Yes" + ADD_MAINSAIL_MACROS="true";; + N|n|No|no) + echo -e "###### > No" + ADD_MAINSAIL_MACROS="false";; + esac + break + done +} + +############################################################# +############################################################# + +moonraker_setup(){ + dep=(wget curl unzip) + dependency_check + status_msg "Downloading Moonraker ..." + if [ -d $MOONRAKER_DIR ]; then + mv -f $MOONRAKER_DIR ${HOME}/moonraker_bak + fi + cd ${HOME} && git clone $MOONRAKER_REPO + ok_msg "Download complete!" + status_msg "Installing Moonraker ..." + $MOONRAKER_DIR/scripts/install-moonraker.sh + ok_msg "Moonraker successfully installed!" +} + +check_for_folder(){ + #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 +} + +############################################################# +############################################################# + +setup_printer_config(){ + if [ "$PRINTER_CFG_FOUND" = "true" ]; then + backup_printer_cfg + if [ "$PRINTER_CFG_LOC" != "${HOME}/klipper_config/printer.cfg" ]; then + status_msg "Moving printer.cfg to ~/klipper_config ..." + mv $PRINTER_CFG_LOC ${HOME}/klipper_config + ok_msg "Done!" + fi + status_msg "Create symlink in home directory ..." + if [ -f ${HOME}/printer.cfg ]; then + mv ${HOME}/printer.cfg ${HOME}/printer_old.cfg + fi + ln -s ${HOME}/klipper_config/printer.cfg ${HOME} + ok_msg "Done!" + #check printer.cfg for necessary entries + read_printer_cfg + write_printer_cfg + fi + if [ "$SEL_DEF_CFG" = "true" ]; then + create_default_printer_cfg + status_msg "Create symlink in home directory ..." + ln -s ${HOME}/klipper_config/printer.cfg ${HOME} + ok_msg "Done!" + fi + #copy mainsail_macro.cfg + if [ "$ADD_MAINSAIL_MACROS" = "true" ]; then + status_msg "Create mainsail_macros.cfg ..." + if [ ! -f ${HOME}/klipper_config/mainsail_macros.cfg ]; then + cp ${HOME}/kiauh/resources/mainsail_macros.cfg ${HOME}/klipper_config + ok_msg "File created!" + else + warn_msg "File does already exist! Skipping ..." + fi + fi +} + +read_printer_cfg(){ + SC="#*# <---------------------- SAVE_CONFIG ---------------------->" + if [ ! $(grep '^\[virtual_sdcard\]$' ${HOME}/klipper_config/printer.cfg) ]; then + VSD="false" + fi + if [ ! $(grep '^\[pause_resume\]$' ${HOME}/klipper_config/printer.cfg) ]; then + PAUSE_RESUME="false" + fi + if [ ! $(grep '^\[display_status\]$' ${HOME}/klipper_config/printer.cfg) ]; then + DISPLAY_STATUS="false" + fi + #check for a SAVE_CONFIG entry + if [[ $(grep "$SC" ${HOME}/klipper_config/printer.cfg) ]]; then + SC_LINE=$(grep -n "$SC" ${HOME}/klipper_config/printer.cfg | cut -d ":" -f1) + PRE_SC_LINE=$(expr $SC_LINE - 1) + SC_ENTRY="true" + fi +} + +write_printer_cfg(){ + unset write_entries + if [ "$ADD_MAINSAIL_MACROS" = "true" ]; then + write_entries+=("[include klipper_config/mainsail_macros.cfg]") + fi + if [ "$PAUSE_RESUME" = "false" ]; then + write_entries+=("[pause_resume]") + fi + if [ "$DISPLAY_STATUS" = "false" ]; then + write_entries+=("[display_status]") + fi + if [ "$VSD" = "false" ]; then + write_entries+=("[virtual_sdcard]\npath: ~/sdcard") + fi + if [ "${#write_entries[@]}" != "0" ]; then + write_entries+=("\\\n############################\n##### CREATED BY KIAUH #####\n############################") + write_entries=("############################\n" "${write_entries[@]}") + fi + #execute writing + 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" ${HOME}/klipper_config/printer.cfg + done + fi + if [ "$SC_ENTRY" = "false" ]; then + LINE_COUNT="$(wc -l < ${HOME}/klipper_config/printer.cfg)a" + for entry in "${write_entries[@]}" + do + sed -i "$LINE_COUNT $entry" ${HOME}/klipper_config/printer.cfg + 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 + #in 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 2p ${HOME}/moonraker.conf | cut -d" " -f5) + if [[ ! $FIRST_IP =~ ([0-9].[0-9].[0-9].[0-9]) ]]; then + status_msg "Writing trusted clients to config ..." + write_default_trusted_clients + ok_msg "Trusted clients written!" + fi + fi + fi +} + +############################################################# +############################################################# + +create_default_printer_cfg(){ +#create default config +touch ${HOME}/klipper_config/printer.cfg +cat <> ${HOME}/klipper_config/printer.cfg + +########################## +### CREATED WITH KIAUH ### +########################## +[virtual_sdcard] +path: ~/sdcard + +[pause_resume] +[display_status] +[include klipper_config/mainsail_macros.cfg] + +########################## +########################## +DEFAULT_CFG +} + +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 ${cyan}$DEFAULT_IP_RANGE${default} 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 "| You can add as many IPs 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 +} + +symlink_moonraker_log(){ + #create a moonraker.log symlink in klipper_config-dir just for convenience + if [ "$SEL_MRLOG_SL" = "true" ]; then + status_msg "Creating moonraker.log symlink ..." + ln -s /tmp/moonraker.log ${HOME}/klipper_config/moonraker.log + ok_msg "Symlink created!" + fi +} \ No newline at end of file From d78670e0ab147f6d9132b8ca69827a43297bb758 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Thu, 20 Aug 2020 17:38:24 +0200 Subject: [PATCH 05/31] fix: formatting --- scripts/functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index 8faca3c..68e395b 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -122,7 +122,7 @@ print_error(){ done sum=$(IFS=+; echo "$((${data_count[*]}))") if [ $sum -eq 0 ]; then - ERROR_MSG=" Looks like $1 was already removed!\n Skipping..." + ERROR_MSG="Looks like $1 was already removed!\n Skipping..." else ERROR_MSG="" fi From db5b906e5b1c2576da61319705df629a0175f8dc Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Thu, 20 Aug 2020 18:30:56 +0200 Subject: [PATCH 06/31] add: separate install/remove function for mainsail and moonraker --- kiauh.sh | 22 ++++++++++++---- scripts/install_mainsail.sh | 33 ++++++++++++------------ scripts/remove.sh | 51 ++++++++++++++++++++++--------------- scripts/ui.sh | 34 ++++++++++++------------- 4 files changed, 80 insertions(+), 60 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index 129c37d..e6545aa 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -172,16 +172,22 @@ install_menu(){ 2) clear print_header - dwc2_install_routine + install_moonraker print_msg && clear_msg install_ui;; 3) clear print_header - install_moonraker + dwc2_install_routine print_msg && clear_msg install_ui;; 4) + clear + print_header + INST_MAINSAIL="true" && install_mainsail + print_msg && clear_msg + install_ui;; + 5) clear print_header octoprint_install_routine @@ -279,22 +285,28 @@ remove_menu(){ 2) clear print_header - remove_dwc2 + remove_moonraker print_msg && clear_msg remove_ui;; 3) clear print_header - remove_mainsail + remove_dwc2 print_msg && clear_msg remove_ui;; 4) clear print_header - remove_octoprint + remove_mainsail print_msg && clear_msg remove_ui;; 5) + clear + print_header + remove_octoprint + print_msg && clear_msg + remove_ui;; + 6) clear print_header remove_nginx diff --git a/scripts/install_mainsail.sh b/scripts/install_mainsail.sh index eaff8c6..1c9a832 100755 --- a/scripts/install_mainsail.sh +++ b/scripts/install_mainsail.sh @@ -1,19 +1,21 @@ install_mainsail(){ - if [ -d $KLIPPER_DIR ] && [ "$INST_MAINSAIL" = "true" ]; then - #disable octoprint service if installed - if systemctl is-enabled octoprint.service -q 2>/dev/null; then - disable_octoprint_service - fi - disable_haproxy_lighttpd - #remove_haproxy_lighttpd - #beginning of mainsail installation - create_reverse_proxy "mainsail" - test_api - test_nginx - mainsail_setup - ok_msg "Mainsail installation complete!"; echo - else - ERROR_MSG=" Please install Klipper first!\n Skipping..." + if [ "$INST_MAINSAIL" = "true" ]; then + if [ -d $KLIPPER_DIR ]; then + #disable octoprint service if installed + if systemctl is-enabled octoprint.service -q 2>/dev/null; then + disable_octoprint_service + fi + disable_haproxy_lighttpd + #remove_haproxy_lighttpd + #beginning of mainsail installation + create_reverse_proxy "mainsail" + test_api + test_nginx + mainsail_setup + ok_msg "Mainsail installation complete!"; echo + else + ERROR_MSG=" Please install Klipper first!\n Skipping..." + fi fi } @@ -64,7 +66,6 @@ test_api(){ } test_nginx(){ - sudo /etc/init.d/nginx restart status_msg "Testing Nginx ..." sleep 5 status_msg "API response from http://localhost/printer/info:" diff --git a/scripts/remove.sh b/scripts/remove.sh index 44f6722..50392b9 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -58,11 +58,10 @@ remove_dwc2(){ fi } -remove_mainsail(){ +remove_moonraker(){ data_arr=( $MOONRAKER_SERVICE1 $MOONRAKER_SERVICE2 - $MAINSAIL_DIR $MOONRAKER_DIR $MOONRAKER_ENV_DIR ${HOME}/moonraker.conf @@ -70,10 +69,8 @@ remove_mainsail(){ ${HOME}/klipper_config/moonraker.log ${HOME}/.klippy_api_key ${HOME}/.moonraker_api_key - /etc/nginx/sites-available/mainsail - /etc/nginx/sites-enabled/mainsail ) - print_error "Mainsail" && data_count=() + print_error "Moonraker" && data_count=() if [ "$ERROR_MSG" = "" ]; then stop_moonraker #remove moonraker services @@ -82,11 +79,6 @@ remove_mainsail(){ sudo update-rc.d -f moonraker remove sudo rm -rf /etc/init.d/moonraker /etc/default/moonraker && ok_msg "Moonraker Service removed!" fi - #remove mainsail dir - if [ -d $MAINSAIL_DIR ]; then - status_msg "Removing Mainsail directory ..." - rm -rf $MAINSAIL_DIR && ok_msg "Directory 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 ..." @@ -110,16 +102,6 @@ remove_mainsail(){ rm -rf ${HOME}/moonraker.log ${HOME}/klipper_config/moonraker.log /tmp/moonraker.log ok_msg "Files removed!" fi - #remove mainsail cfg - 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 - 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 #remove legacy api key if [ -e ${HOME}/.klippy_api_key ]; then status_msg "Removing legacy API Key ..." @@ -130,7 +112,34 @@ remove_mainsail(){ status_msg "Removing API Key ..." rm ${HOME}/.moonraker_api_key && ok_msg "Done!" fi - CONFIRM_MSG=" Mainsail successfully removed!" + CONFIRM_MSG="Moonraker successfully removed!" + fi +} + +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!" fi } diff --git a/scripts/ui.sh b/scripts/ui.sh index f331ce8..ab63ec6 100755 --- a/scripts/ui.sh +++ b/scripts/ui.sh @@ -45,25 +45,23 @@ main_ui(){ install_ui(){ top_border - echo -e "| $(title_msg "~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~") | " + echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${default} | " hr echo -e "| You need this menu usually only for installing | " echo -e "| all necessary dependencies for the various | " echo -e "| functions on a completely fresh system. | " hr - echo -e "| Firmware: | | " - echo -e "| 1) [Klipper] | | " - echo -e "| | | " - echo -e "| Webinterface: | | " - echo -e "| 2) [DWC2] | | " - echo -e "| 3) [Mainsail] | | " - echo -e "| 4) [Octoprint] | | " + echo -e "| Firmware: | Webinterface: | " + echo -e "| 1) [Klipper] | 3) [DWC2] | " + echo -e "| | 4) [Mainsail] | " + echo -e "| Klipper API: | 5) [Octoprint] | " + echo -e "| 2) [Moonraker] | | " quit_footer } update_ui(){ top_border - echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~") | " + echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${default} | " hr echo -e "| It is a good idea to check the following website | " echo -e "| for important software changes to the config file | " @@ -89,26 +87,26 @@ update_ui(){ remove_ui(){ top_border - echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~") | " + echo -e "| ${red}~~~~~~~~~~~~~~ [ Remove Menu ] ~~~~~~~~~~~~~~${default} | " hr echo -e "| Files and directories which remain untouched: | " echo -e "| --> ~/printer.cfg | " echo -e "| --> ~/kiauh-backups | " echo -e "| You need remove them manually if you wish so. | " hr - echo -e "| Firmware: | | " - echo -e "| 1) [Klipper] | 5) [Nginx] | " - echo -e "| | | " - echo -e "| Webinterface: | | " - echo -e "| 2) [DWC2] | | " - echo -e "| 3) [Mainsail] | | " - echo -e "| 4) [Octoprint] | | " + echo -e "| Firmware: | Webinterface: | " + echo -e "| 1) [Klipper] | 3) [DWC2] | " + echo -e "| | 4) [Mainsail] | " + echo -e "| Klipper API: | 5) [Octoprint] | " + echo -e "| 2) [Moonraker] | | " + echo -e "| | Webserver: | " + echo -e "| | 6) [Nginx] | " quit_footer } advanced_ui(){ top_border - echo -e "| $(title_msg "~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~") | " + echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${default} | " hr echo -e "| 0) $OPRINT_SERVICE_STATUS| " hr From 92b4bc41ac23e4d415af3a9cd5116fe67f06fcc8 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Thu, 20 Aug 2020 18:58:57 +0200 Subject: [PATCH 07/31] fix: move test_api to moonraker install routine --- scripts/install_mainsail.sh | 33 ++------------------------------- scripts/install_moonraker.sh | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/scripts/install_mainsail.sh b/scripts/install_mainsail.sh index 1c9a832..26d69f7 100755 --- a/scripts/install_mainsail.sh +++ b/scripts/install_mainsail.sh @@ -6,12 +6,9 @@ install_mainsail(){ disable_octoprint_service fi disable_haproxy_lighttpd - #remove_haproxy_lighttpd - #beginning of mainsail installation create_reverse_proxy "mainsail" - test_api - test_nginx mainsail_setup + test_nginx ok_msg "Mainsail installation complete!"; echo else ERROR_MSG=" Please install Klipper first!\n Skipping..." @@ -39,36 +36,10 @@ disable_haproxy_lighttpd(){ done } -#remove_haproxy_lighttpd(){ -# rem=(haproxy lighttpd) -# for remove in "${rem[@]}" -# do -# if [[ $(dpkg-query -f'${Status}' --show $remove 2>/dev/null) = *\ installed #]]; then -# delete+=($remove) -# fi -# done -# if ! [ ${#delete[@]} -eq 0 ]; then -# sudo apt-get remove ${delete[@]} -y -# fi -#} - -test_api(){ - status_msg "Testing API ..." - sleep 5 - status_msg "API response from http://localhost:7125/printer/info:" - API_RESPONSE=$(curl -sG4m5 http://localhost:7125/printer/info) - echo -e "${cyan}$API_RESPONSE${default}" - if [ $(curl -sG4 "http://localhost:7125/printer/info" | grep '^{"result"' -c) -eq 1 ]; then - echo; ok_msg "Klipper API is working correctly!"; echo - else - echo; warn_msg "Klipper API not working correctly!"; echo - fi -} - test_nginx(){ status_msg "Testing Nginx ..." sleep 5 - status_msg "API response from http://localhost/printer/info:" + status_msg "API response from http://localhost/printer/info :" API_RESPONSE="$(curl -sG4m5 http://localhost/printer/info)" echo -e "${cyan}$API_RESPONSE${default}" if [ $(curl -sG4 "http://localhost/printer/info" | grep '^{"result"' -c) -eq 1 ]; then diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index 48c42a7..4590f00 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -16,6 +16,7 @@ install_moonraker(){ #after install actions restart_moonraker restart_klipper + test_api } system_check_moonraker(){ @@ -402,4 +403,20 @@ symlink_moonraker_log(){ ln -s /tmp/moonraker.log ${HOME}/klipper_config/moonraker.log ok_msg "Symlink created!" fi +} + +############################################################# +############################################################# + +test_api(){ + status_msg "Testing API ..." + sleep 5 + status_msg "API response from http://localhost:7125/printer/info :" + API_RESPONSE=$(curl -sG4m5 http://localhost:7125/printer/info) + echo -e "${cyan}$API_RESPONSE${default}" + if [ $(curl -sG4 "http://localhost:7125/printer/info" | grep '^{"result"' -c) -eq 1 ]; then + echo; ok_msg "Klipper API is working correctly!"; echo + else + echo; warn_msg "Klipper API not working correctly!"; echo + fi } \ No newline at end of file From 60dc9d623ed9f725356eda9b550901565697d451 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sat, 22 Aug 2020 09:09:00 +0200 Subject: [PATCH 08/31] fix: rollback function --- scripts/rollback.sh | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/scripts/rollback.sh b/scripts/rollback.sh index cd5f9ae..2335ef6 100755 --- a/scripts/rollback.sh +++ b/scripts/rollback.sh @@ -1,24 +1,29 @@ save_klipper_state(){ source_ini #read current klipper state + cd $KLIPPER_DIR COMMIT_STATE=$(git rev-parse --short HEAD) - if [ $GET_BRANCH = origin/master ]; then + if [ "$GET_BRANCH" = "origin/master" ]; then ORI_OLD=$previous_origin_state ORI_NEW=$COMMIT_STATE sed -i "/previous_origin_state=/s/$ORI_OLD/$ORI_NEW/" $INI_FILE - elif [ $GET_BRANCH = dmbutyugin/scurve-shaping ]; then + elif [ "$GET_BRANCH" = "origin" ]; then + ORI_OLD=$previous_origin_state + ORI_NEW=$COMMIT_STATE + sed -i "/previous_origin_state=/s/$ORI_OLD/$ORI_NEW/" $INI_FILE + elif [ "$GET_BRANCH" = "dmbutyugin/scurve-shaping" ]; then SHA_OLD=$previous_shaping_state SHA_NEW=$COMMIT_STATE sed -i "/previous_shaping_state=/s/$SHA_OLD/$SHA_NEW/" $INI_FILE - elif [ $GET_BRANCH = dmbutyugin/scurve-smoothing ]; then + elif [ "$GET_BRANCH" = "dmbutyugin/scurve-smoothing" ]; then SMO_OLD=$previous_smoothing_state SMO_NEW=$COMMIT_STATE sed -i "/previous_smoothing_state=/s/$SMO_OLD/$SMO_NEW/" $INI_FILE - elif [ $GET_BRANCH = Arksine/work-web_server-20200131 ]; then + elif [ "$GET_BRANCH" = "Arksine/work-web_server-20200131" ]; then WWS_OLD=$previous_moonraker_state WWS_NEW=$COMMIT_STATE sed -i "/previous_moonraker_state=/s/$WWS_OLD/$WWS_NEW/" $INI_FILE - elif [ $GET_BRANCH = Arksine/dev-moonraker-testing ]; then + elif [ "$GET_BRANCH" = "Arksine/dev-moonraker-testing" ]; then DMT_OLD=$previous_dev_moonraker_state DMT_NEW=$COMMIT_STATE sed -i "/previous_dev_moonraker_state=/s/$DMT_OLD/$DMT_NEW/" $INI_FILE @@ -29,15 +34,15 @@ load_klipper_state(){ source_ini print_branch CURR_COMM=$(git rev-parse --short=8 HEAD) - if [ "$GET_BRANCH" == "origin/master" ]; then + if [ "$GET_BRANCH" = "origin/master" ]; then PREV_COMM=$previous_origin_state - elif [ "$GET_BRANCH" == "dmbutyugin/scurve-shaping" ]; then + elif [ "$GET_BRANCH" = "dmbutyugin/scurve-shaping" ]; then PREV_COMM=$previous_shaping_state - elif [ "$GET_BRANCH" == "dmbutyugin/scurve-smoothing" ]; then + elif [ "$GET_BRANCH" = "dmbutyugin/scurve-smoothing" ]; then PREV_COMM=$previous_smoothing_state - elif [ "$GET_BRANCH" == "Arksine/work-web_server-20200131" ]; then + elif [ "$GET_BRANCH" = "Arksine/work-web_server-20200131" ]; then PREV_COMM=$previous_moonraker_state - elif [ "$GET_BRANCH" == "Arksine/dev-moonraker-testing" ]; then + elif [ "$GET_BRANCH" = "Arksine/dev-moonraker-testing" ]; then PREV_COMM=$previous_dev_moonraker_state fi PREV_COMM_DATE=$(git show -s --format=%cd --date=short $PREV_COMM) From 7dda59649b47c50916b0711e71855f162b3c7b0f Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sat, 22 Aug 2020 09:09:28 +0200 Subject: [PATCH 09/31] fix: ui not printing branch --- scripts/status.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/status.sh b/scripts/status.sh index f454f89..c27d35d 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -151,6 +151,8 @@ print_branch(){ read_branch if [ "$GET_BRANCH" == "origin/master" ]; then PRINT_BRANCH="$GET_BRANCH " + elif [ "$GET_BRANCH" == "origin" ]; then + PRINT_BRANCH="origin/master " elif [ "$GET_BRANCH" == "master" ]; then PRINT_BRANCH="origin/master " elif [ "$GET_BRANCH" == "dmbutyugin/scurve-shaping" ]; then From cc1c804730f33031a740d0900c1ddba45b54968a Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sat, 22 Aug 2020 09:10:09 +0200 Subject: [PATCH 10/31] fix: klipper update function --- scripts/update.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/update.sh b/scripts/update.sh index 65491ca..31efa9c 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -18,15 +18,17 @@ update_klipper(){ status_msg "Updating $GET_BRANCH" #fetching origin/master -> error #rewriting origin/master to origin - if [ "$GET_BRANCH" == "origin/master" ]; then + if [ "$GET_BRANCH" = "origin/master" ]; then FETCH_BRANCH="origin" else FETCH_BRANCH=$(echo "$GET_BRANCH" | cut -d "/" -f1) fi status_msg "Fetching from $FETCH_BRANCH" + cd $KLIPPER_DIR git fetch $FETCH_BRANCH -q && ok_msg "Fetch successfull!" - status_msg "Checking out $GET_BRANCH" - git checkout $GET_BRANCH -q && ok_msg "Checkout successfull!" && echo; ok_msg "Update complete!" + status_msg "Checking out $FETCH_BRANCH" + echo "git checkout $FETCH_BRANCH" + git checkout $FETCH_BRANCH -q && ok_msg "Checkout successfull!" && echo; ok_msg "Update complete!" fi start_klipper; echo } From eb6b2465c7d5fa132fb2c1ec7b8dc0b081d81ac7 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sat, 22 Aug 2020 17:47:47 +0200 Subject: [PATCH 11/31] fix: mainsail/moonraker related --- scripts/install_mainsail.sh | 5 +--- scripts/install_moonraker.sh | 52 ++++++++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/scripts/install_mainsail.sh b/scripts/install_mainsail.sh index 26d69f7..bf90610 100755 --- a/scripts/install_mainsail.sh +++ b/scripts/install_mainsail.sh @@ -1,11 +1,8 @@ install_mainsail(){ if [ "$INST_MAINSAIL" = "true" ]; then if [ -d $KLIPPER_DIR ]; then - #disable octoprint service if installed - if systemctl is-enabled octoprint.service -q 2>/dev/null; then - disable_octoprint_service - fi disable_haproxy_lighttpd + unset SET_REVERSE_PROXY && SET_REVERSE_PROXY"true" #quick and dirty hack to make mainsail reverse proxy install, needs polish create_reverse_proxy "mainsail" mainsail_setup test_nginx diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index 4590f00..49bc3bd 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -4,13 +4,14 @@ install_moonraker(){ get_user_selections_moonraker #moonraker main installation moonraker_setup - check_for_folder + check_for_folder_moonraker #setup configs - setup_printer_config + setup_printer_config_mainsail setup_moonraker_conf #execute customizations write_custom_trusted_clients symlink_moonraker_log + disable_octoprint install_mainsail set_hostname #after install actions @@ -46,6 +47,11 @@ system_check_moonraker(){ 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 } get_user_selections_moonraker(){ @@ -77,6 +83,7 @@ get_user_selections_moonraker(){ fi #user selection for printer.cfg if [ "$PRINTER_CFG_FOUND" = "false" ]; then + unset SEL_DEF_CFG while true; do echo warn_msg "No printer.cfg found!" @@ -142,6 +149,27 @@ get_user_selections_moonraker(){ esac break done + #ask user to disable octoprint when such installed 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." + 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";; + N|n|No|no) + echo -e "###### > No" + DISABLE_OPRINT="false";; + esac + break + done + fi } ############################################################# @@ -161,7 +189,7 @@ moonraker_setup(){ ok_msg "Moonraker successfully installed!" } -check_for_folder(){ +check_for_folder_moonraker(){ #check for / create sdcard folder if [ ! -d ${HOME}/sdcard ]; then status_msg "Creating sdcard directory ..." @@ -179,7 +207,7 @@ check_for_folder(){ ############################################################# ############################################################# -setup_printer_config(){ +setup_printer_config_mainsail(){ if [ "$PRINTER_CFG_FOUND" = "true" ]; then backup_printer_cfg if [ "$PRINTER_CFG_LOC" != "${HOME}/klipper_config/printer.cfg" ]; then @@ -193,12 +221,12 @@ setup_printer_config(){ fi ln -s ${HOME}/klipper_config/printer.cfg ${HOME} ok_msg "Done!" - #check printer.cfg for necessary entries - read_printer_cfg - write_printer_cfg + #check printer.cfg for necessary mainsail entries + read_printer_cfg_mainsail + write_printer_cfg_mainsail fi if [ "$SEL_DEF_CFG" = "true" ]; then - create_default_printer_cfg + create_default_mainsail_printer_cfg status_msg "Create symlink in home directory ..." ln -s ${HOME}/klipper_config/printer.cfg ${HOME} ok_msg "Done!" @@ -215,7 +243,7 @@ setup_printer_config(){ fi } -read_printer_cfg(){ +read_printer_cfg_mainsail(){ SC="#*# <---------------------- SAVE_CONFIG ---------------------->" if [ ! $(grep '^\[virtual_sdcard\]$' ${HOME}/klipper_config/printer.cfg) ]; then VSD="false" @@ -234,7 +262,7 @@ read_printer_cfg(){ fi } -write_printer_cfg(){ +write_printer_cfg_mainsail(){ unset write_entries if [ "$ADD_MAINSAIL_MACROS" = "true" ]; then write_entries+=("[include klipper_config/mainsail_macros.cfg]") @@ -253,6 +281,7 @@ write_printer_cfg(){ write_entries=("############################\n" "${write_entries[@]}") fi #execute writing + status_msg "Writing to printer.cfg ..." if [ "$SC_ENTRY" = "true" ]; then PRE_SC_LINE="$(expr $SC_LINE - 1)a" for entry in "${write_entries[@]}" @@ -267,6 +296,7 @@ write_printer_cfg(){ sed -i "$LINE_COUNT $entry" ${HOME}/klipper_config/printer.cfg done fi + ok_msg "Done!" } setup_moonraker_conf(){ @@ -297,7 +327,7 @@ setup_moonraker_conf(){ ############################################################# ############################################################# -create_default_printer_cfg(){ +create_default_mainsail_printer_cfg(){ #create default config touch ${HOME}/klipper_config/printer.cfg cat <> ${HOME}/klipper_config/printer.cfg From 2be2ce12c6fa601073dda381aa3b04d188af1f48 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sat, 22 Aug 2020 17:48:52 +0200 Subject: [PATCH 12/31] add: variable triggered function to disable octoprint service --- scripts/functions.sh | 48 ++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index 68e395b..adf1ef3 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -246,6 +246,12 @@ enable_octoprint_service(){ fi } +disable_octoprint(){ + if [ "$DISABLE_OPRINT" = "true" ]; then + disable_octoprint_service + fi +} + disable_octoprint_service(){ if [[ -f $OCTOPRINT_SERVICE1 && -f $OCTOPRINT_SERVICE2 ]]; then status_msg "OctoPrint Service is enabled! Disabling now ..." @@ -278,27 +284,29 @@ read_octoprint_service_status(){ } create_reverse_proxy(){ - #check for dependencies - dep=(nginx) - dependency_check - #execute operations - status_msg "Creating Nginx configuration for $1 ..." - cat ${HOME}/kiauh/resources/$1_nginx.cfg > ${HOME}/kiauh/resources/$1 - sudo mv ${HOME}/kiauh/resources/$1 /etc/nginx/sites-available/$1 - #ONLY FOR MAINSAIL: replace username if not "pi" - if [ "$1" = "mainsail" ]; then - sudo sed -i "/root/s/pi/${USER}/" /etc/nginx/sites-available/mainsail + if [ "$SET_REVERSE_PROXY" = "true" ]; then + #check for dependencies + dep=(nginx) + dependency_check + #execute operations + status_msg "Creating Nginx configuration for $1 ..." + cat ${HOME}/kiauh/resources/$1_nginx.cfg > ${HOME}/kiauh/resources/$1 + sudo mv ${HOME}/kiauh/resources/$1 /etc/nginx/sites-available/$1 + #ONLY FOR MAINSAIL: replace username if not "pi" + if [ "$1" = "mainsail" ]; then + sudo sed -i "/root/s/pi/${USER}/" /etc/nginx/sites-available/mainsail + fi + ok_msg "Nginx configuration for $1 was set!" + #remove default config + if [ -e /etc/nginx/sites-enabled/default ]; then + sudo rm /etc/nginx/sites-enabled/default fi - ok_msg "Nginx configuration for $1 was set!" - #remove default config - if [ -e /etc/nginx/sites-enabled/default ]; then - sudo rm /etc/nginx/sites-enabled/default + #create symlink for own configs + if [ ! -e /etc/nginx/sites-enabled/$1 ]; then + sudo ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled/ + fi + restart_nginx fi - #create symlink for own configs - if [ ! -e /etc/nginx/sites-enabled/$1 ]; then - sudo ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled/ - fi - restart_nginx } create_custom_hostname(){ @@ -308,7 +316,7 @@ create_custom_hostname(){ echo -e "| that name to open the Interface in your browser. |" echo -e "| |" echo -e "| Example: If you set the hostname to 'my-printer' |" - echo -e "| you can open Mainsail/Octoprint by |" + echo -e "| you can open DWC2/Mainsail/Octoprint by |" echo -e "| browsing to: http://my-printer.local |" bottom_border while true; do From 68cb5427b6631b64aa9121cee78aa3cccabc2588 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sat, 22 Aug 2020 17:49:35 +0200 Subject: [PATCH 13/31] fix: rewrite dwc2 installation --- kiauh.sh | 2 +- scripts/install_dwc2.sh | 334 ++++++++++++++++++++++++++++++---------- 2 files changed, 255 insertions(+), 81 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index e6545aa..5fa700c 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -178,7 +178,7 @@ install_menu(){ 3) clear print_header - dwc2_install_routine + install_dwc2 print_msg && clear_msg install_ui;; 4) diff --git a/scripts/install_dwc2.sh b/scripts/install_dwc2.sh index a1a3aad..8f2cc4d 100755 --- a/scripts/install_dwc2.sh +++ b/scripts/install_dwc2.sh @@ -1,30 +1,134 @@ -#TODO: -# - ask for permission to disable octoprint service - -dwc2_install_routine(){ +install_dwc2(){ if [ -d $KLIPPER_DIR ]; then - # check for existing installation - if [ -d $DWC2FK_DIR ] && [ -d $DWC2_DIR ]; then - ERROR_MSG=" Looks like DWC2 is already installed!\n Skipping..." - return - fi - stop_klipper - #disable octoprint service if installed - if systemctl is-enabled octoprint.service -q 2>/dev/null; then - disable_octoprint_service - fi - install_tornado - install_dwc2fk && dwc2fk_cfg - install_dwc2 - dwc2_reverse_proxy_dialog - create_custom_hostname - start_klipper + system_check_dwc2 + #ask user for customization + get_user_selections_dwc2 + #dwc2 main installation + check_for_folder_dwc2 + tornado_setup + dwc2fk_setup + dwc2_setup + #setup config + write_printer_cfg_dwc2 + write_custom_printer_cfg_dwc2 + #execute customizations + disable_octoprint + create_reverse_proxy "dwc2" + set_hostname + #after install actions + restart_klipper else ERROR_MSG=" Please install Klipper first!\n Skipping..." fi } -install_tornado(){ +system_check_dwc2(){ + status_msg "Initializing DWC2 installation ..." + stop_klipper + #check for existing printer.cfg + if [ -e ${HOME}/printer.cfg ]; then + PRINTER_CFG_FOUND="true" + PRINTER_CFG_LOC="${HOME}/printer.cfg" + else + PRINTER_CFG_FOUND="false" + fi + #check if octoprint is installed + if systemctl is-enabled octoprint.service -q 2>/dev/null; then + unset OCTOPRINT_ENABLED + OCTOPRINT_ENABLED="true" + fi +} + +get_user_selections_dwc2(){ + #user selection for printer.cfg + if [ "$PRINTER_CFG_FOUND" = "false" ]; then + unset SEL_DEF_CFG + unset SEL_CUS_CFG + while true; do + echo + top_border + echo -e "| ${red}WARNING! - No printer.cfg was found!${default} |" + hr + echo -e "| You can now either select to create a printer.cfg |" + echo -e "| with the default entries (1), customize the settings |" + echo -e "| before writing them (2) or you can skip the creation |" + echo -e "| of a printer.cfg at all. |" + echo -e "| |" + echo -e "| Please keep in mind that DWC2 will ONLY load if you |" + echo -e "| have a correctly defined printer.cfg. Any missing |" + echo -e "| option or error will prevent DWC2 from loading and |" + echo -e "| you need to check klippy.log to resolve the error. |" + echo -e "| |" + echo -e "| Neither option 1 or 2 of this script will create a |" + echo -e "| fully working printer.cfg for you! |" + hr + echo -e "| 1) [Create default configuration] |" + echo -e "| 2) [Create custom configuration] |" + echo -e "| 3) ${red}[Skip]${default} |" + bottom_border + read -p "${cyan}###### Please select:${default} " choice + case "$choice" in + 1) + echo -e "###### > Create default configuration" + SEL_DEF_CFG="true" + SEL_CUS_CFG="false" + break;; + 2) + echo -e "###### > Create custom configuration" + SEL_DEF_CFG="false" + SEL_CUS_CFG="true" + break;; + 3) + echo -e "###### > Skip" + SEL_DEF_CFG="false" + SEL_CUS_CFG="false" + echo "${red}Skipping ...${default}"; break;; + esac + break + done + fi + # + setup_printer_config_dwc2 + #ask user to install reverse proxy + dwc2_reverse_proxy_dialog + #ask to change hostname + if [ "$SET_REVERSE_PROXY" = "true" ]; then + create_custom_hostname + fi + #ask user to disable octoprint when such installed 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 DWC2 Webinterface." + 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";; + N|n|No|no) + echo -e "###### > No" + DISABLE_OPRINT="false";; + esac + break + done + fi +} + +############################################################# +############################################################# + +check_for_folder_dwc2(){ + #check for needed folder + if [ ! -d $DWC2_DIR/web ]; then + mkdir -p $DWC2_DIR/web + fi +} + +tornado_setup(){ if [ "$(cd $KLIPPY_ENV_DIR/bin/ && $_/pip list 2>/dev/null | grep "tornado" | cut -d" " -f9)" = "5.1.1" ]; then ok_msg "Tornado 5.1.1 is already installed! Continue..." else @@ -37,7 +141,7 @@ install_tornado(){ fi } -install_dwc2fk(){ +dwc2fk_setup(){ cd ${HOME} status_msg "Cloning DWC2-for-Klipper repository ..." git clone $DWC2FK_REPO && ok_msg "DWC2-for-Klipper successfully cloned!" @@ -48,40 +152,111 @@ install_dwc2fk(){ fi } -dwc2fk_cfg(){ - while true; do - echo -e "${cyan}" - read -p "###### Do you want to create the config now? (Y/n): " yn - echo -e "${default}" - case "$yn" in - Y|y|Yes|yes|"") create_dwc2fk_cfg; break;; - N|n|No|no) break;; - esac - done +dwc2_setup(){ + #check dependencies + dep=(wget gzip tar curl) + dependency_check + #execute operation + GET_DWC2_URL=`curl -s https://api.github.com/repositories/28820678/releases/latest | grep browser_download_url | cut -d'"' -f4` + cd $DWC2_DIR/web + status_msg "Downloading DWC2 Web UI ..." + wget -q $GET_DWC2_URL && ok_msg "Download complete!" + status_msg "Unzipping archive ..." + unzip -q -o *.zip && for f_ in $(find . | grep '.gz');do gunzip -f ${f_};done && ok_msg "Done!" + status_msg "Writing version to file ..." + echo $GET_DWC2_URL | cut -d/ -f8 > $DWC2_DIR/web/version && ok_msg "Done!" + status_msg "Do a little cleanup ..." + rm -rf DuetWebControl-SD.zip && ok_msg "Done!" + ok_msg "DWC2 Web UI installed!" } -create_dwc2fk_cfg(){ - echo -e "/=================================================\ " - echo -e "| 1) [Default configuration] | " - echo -e "| 2) [Custom configuration] | " - echo -e "| 3) [Skip] | " - echo -e "\=================================================/ " - while true; do - read -p "Please select: " choice; echo - case "$choice" in - 1) dwc2fk_default_cfg && ok_msg "Config written ..."; break;; - 2) create_dwc2fk_custom_cfg && ok_msg "Config written ..."; break;; - 3) echo "Skipping ..."; break;; - esac - done +############################################################# +############################################################# + +setup_printer_config_dwc2(){ + if [ "$PRINTER_CFG_FOUND" = "true" ]; then + backup_printer_cfg + #check printer.cfg for necessary dwc2 entries + read_printer_cfg_dwc2 + fi + if [ "$SEL_DEF_CFG" = "true" ]; then + create_default_dwc2_printer_cfg + fi + if [ "$SEL_CUS_CFG" = "true" ]; then + #get user input for custom config + create_custom_dwc2_printer_cfg + fi } -dwc2fk_default_cfg(){ - cat <> $PRINTER_CFG +read_printer_cfg_dwc2(){ + unset SC_ENTRY + SC="#*# <---------------------- SAVE_CONFIG ---------------------->" + if [ ! $(grep '^\[virtual_sdcard\]$' ${HOME}/printer.cfg) ]; then + VSD="false" + fi + if [ ! $(grep '^\[web_dwc2\]$' ${HOME}/printer.cfg) ]; then + WEB_DWC2="false" + fi + #check for a SAVE_CONFIG entry + if [[ $(grep "$SC" ${HOME}/printer.cfg) ]]; then + SC_LINE=$(grep -n "$SC" ${HOME}/printer.cfg | cut -d ":" -f1) + PRE_SC_LINE=$(expr $SC_LINE - 1) + SC_ENTRY="true" + fi +} + +write_printer_cfg_dwc2(){ + unset write_entries + if [ "$WEB_DWC2" = "false" ]; then + write_entries+=("[web_dwc2]\nprinter_name: my_printer\nlisten_adress: 0.0.0.0\nlisten_port: 4750\nweb_path: dwc2/web") + fi + if [ "$VSD" = "false" ]; then + write_entries+=("[virtual_sdcard]\npath: ~/sdcard") + fi + if [ "${#write_entries[@]}" != "0" ]; then + write_entries+=("\\\n############################\n##### CREATED BY KIAUH #####\n############################") + write_entries=("############################\n" "${write_entries[@]}") + fi + #execute writing + status_msg "Writing 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" ${HOME}/printer.cfg + done + fi + if [ "$SC_ENTRY" = "false" ]; then + LINE_COUNT="$(wc -l < ${HOME}/printer.cfg)a" + for entry in "${write_entries[@]}" + do + sed -i "$LINE_COUNT $entry" ${HOME}/printer.cfg + done + fi + ok_msg "Done!" +} + +write_custom_printer_cfg_dwc2(){ + if [ "$CONFIRM_CUSTOM_CFG" = "true" ]; then + echo -e "$DWC2_CFG" >> ${HOME}/printer.cfg + fi +} + +create_default_dwc2_printer_cfg(){ +#create default config +touch ${HOME}/printer.cfg +cat <> ${HOME}/printer.cfg ########################## ### CREATED WITH KIAUH ### ########################## +[printer] +kinematics: cartesian +max_velocity: 300 +max_accel: 3000 +max_z_velocity: 5 +max_z_accel: 100 + [virtual_sdcard] path: ~/sdcard @@ -92,10 +267,19 @@ listen_port: 4750 web_path: dwc2/web ########################## ########################## -DWC2 +DEFAULT_DWC2_CFG } -create_dwc2fk_custom_cfg(){ +############################################################# +############################################################# + +create_custom_dwc2_printer_cfg(){ + echo + top_border + echo -e "| Please fill in custom values for the following |" + echo -e "| configuration options. If you are unsure what to put |" + echo -e "| in, keep the pre-entered values. |" + bottom_border echo -e "${cyan}" read -e -p "Printer name: " -i "my_printer" PRINTER_NAME read -e -p "Listen adress: " -i "0.0.0.0" LISTEN_ADRESS @@ -122,50 +306,40 @@ DWC2 echo "The following lines will be written:" echo -e "$DWC2_CFG" while true; do - echo -e "${cyan}" - read -p "###### Write now (Y) or start over (n)? (Y/n): " yn - echo -e "${default}" + echo + read -p "${cyan}###### Confirm (Y) or start over (n)? (Y/n):${default} " yn case "$yn" in - Y|y|Yes|yes|"") echo -e "$DWC2_CFG" >> $PRINTER_CFG; break;; - N|n|No|no) create_dwc2fk_custom_cfg;; + Y|y|Yes|yes|"") + CONFIRM_CUSTOM_CFG="true" + break;; + N|n|No|no) + CONFIRM_CUSTOM_CFG="false" + create_custom_dwc2_printer_cfg + break;; esac done } -install_dwc2(){ - #check dependencies - dep=(wget gzip tar curl) - dependency_check - #execute operation - GET_DWC2_URL=`curl -s https://api.github.com/repositories/28820678/releases/latest | grep browser_download_url | cut -d'"' -f4` - if [ ! -d $DWC2_DIR/web ]; then - mkdir -p $DWC2_DIR/web - fi - cd $DWC2_DIR/web - status_msg "Downloading DWC2 Web UI ..." - wget -q $GET_DWC2_URL && ok_msg "Download complete!" - status_msg "Unzipping archive ..." - unzip -q -o *.zip && for f_ in $(find . | grep '.gz');do gunzip -f ${f_};done && ok_msg "Done!" - status_msg "Writing version to file ..." - echo $GET_DWC2_URL | cut -d/ -f8 > $DWC2_DIR/web/version && ok_msg "Done!" - status_msg "Do a little cleanup ..." - rm -rf DuetWebControl-SD.zip && ok_msg "Done!" - ok_msg "DWC2 Web UI installed!" -} +############################################################# +############################################################# dwc2_reverse_proxy_dialog(){ + unset SET_REVERSE_PROXY + 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 - echo -e "${cyan}" - read -p "###### Do you want to set up a reverse proxy now? (Y/n): " yn - echo -e "${default}" + read -p "${cyan}###### Do you want to set up a reverse proxy now? (y/N):${default} " yn case "$yn" in - Y|y|Yes|yes|"") create_reverse_proxy "dwc2"; break;; - N|n|No|no) break;; + Y|y|Yes|yes) + SET_REVERSE_PROXY="true" + break;; + N|n|No|no|"") + SET_REVERSE_PROXY="false" + break;; esac done } \ No newline at end of file From f3a139f31749727637c44df7bef6366fd3dc943d Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sat, 22 Aug 2020 18:19:33 +0200 Subject: [PATCH 14/31] fix: remove_ui --- scripts/ui.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/ui.sh b/scripts/ui.sh index ab63ec6..63390b1 100755 --- a/scripts/ui.sh +++ b/scripts/ui.sh @@ -91,6 +91,7 @@ remove_ui(){ hr echo -e "| Files and directories which remain untouched: | " echo -e "| --> ~/printer.cfg | " + echo -e "| --> ~/klipper_config | " echo -e "| --> ~/kiauh-backups | " echo -e "| You need remove them manually if you wish so. | " hr From 63f65a02b4d37b136a5689e551748b8045345f26 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sat, 22 Aug 2020 18:23:41 +0200 Subject: [PATCH 15/31] fix: a more verbose dependency check message --- scripts/functions.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index adf1ef3..1fe7a6e 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -86,10 +86,11 @@ restart_nginx(){ } dependency_check(){ - status_msg "Checking for dependencies ..." + status_msg "Checking for the following dependencies:" #check if package is installed, if not write name into array for pkg in "${dep[@]}" do + echo -e "${cyan}● $pkg ${default}" if [[ ! $(dpkg-query -f'${Status}' --show $pkg 2>/dev/null) = *\ installed ]]; then inst+=($pkg) fi From 2532fc7e4c862731c4154f1517868005be972b41 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sat, 22 Aug 2020 19:14:11 +0200 Subject: [PATCH 16/31] fix: restructure functions.sh --- scripts/functions.sh | 204 ++++++++++--------------------------------- 1 file changed, 44 insertions(+), 160 deletions(-) diff --git a/scripts/functions.sh b/scripts/functions.sh index 1fe7a6e..7919aa3 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -78,6 +78,50 @@ restart_octoprint(){ fi } +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 + fi +} + +disable_octoprint(){ + if [ "$DISABLE_OPRINT" = "true" ]; then + disable_octoprint_service + fi +} + +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 + 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 + 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 + OPRINT_SERVICE_STATUS="${red}[Disable]${default} OctoPrint Service " + fi +} + restart_nginx(){ if [ -e /etc/init.d/nginx ]; then status_msg "Restarting Nginx Service ..." @@ -240,166 +284,6 @@ flash_mcu(){ start_klipper } -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 - fi -} - -disable_octoprint(){ - if [ "$DISABLE_OPRINT" = "true" ]; then - disable_octoprint_service - fi -} - -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 - 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 - 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 - OPRINT_SERVICE_STATUS="${red}[Disable]${default} OctoPrint Service " - fi -} - -create_reverse_proxy(){ - if [ "$SET_REVERSE_PROXY" = "true" ]; then - #check for dependencies - dep=(nginx) - dependency_check - #execute operations - status_msg "Creating Nginx configuration for $1 ..." - cat ${HOME}/kiauh/resources/$1_nginx.cfg > ${HOME}/kiauh/resources/$1 - sudo mv ${HOME}/kiauh/resources/$1 /etc/nginx/sites-available/$1 - #ONLY FOR MAINSAIL: replace username if not "pi" - if [ "$1" = "mainsail" ]; then - sudo sed -i "/root/s/pi/${USER}/" /etc/nginx/sites-available/mainsail - fi - ok_msg "Nginx configuration for $1 was set!" - #remove default config - if [ -e /etc/nginx/sites-enabled/default ]; then - sudo rm /etc/nginx/sites-enabled/default - fi - #create symlink for own configs - if [ ! -e /etc/nginx/sites-enabled/$1 ]; then - sudo ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled/ - fi - restart_nginx - fi -} - -create_custom_hostname(){ - echo - top_border - echo -e "| You can change the hostname of this machine to use |" - echo -e "| that name to open the Interface in your browser. |" - echo -e "| |" - echo -e "| Example: If you set the hostname to 'my-printer' |" - echo -e "| you can open DWC2/Mainsail/Octoprint by |" - echo -e "| browsing to: http://my-printer.local |" - bottom_border - while true; do - read -p "${cyan}###### Do you want to change the hostname? (y/N):${default} " yn - case "$yn" in - Y|y|Yes|yes) - user_input_hostname - break;; - N|n|No|no|"") break;; - esac - done -} - -user_input_hostname(){ - unset NEW_HOSTNAME - echo - top_border - echo -e "| ${green}Allowed characters: a-z, 0-9 and single '-'${default} |" - echo -e "| ${red}No special characters allowed!${default} |" - echo -e "| ${red}No leading or trailing '-' allowed!${default} |" - bottom_border - while true; do - read -p "${cyan}###### Please set the new hostname:${default} " NEW_HOSTNAME - if [[ $NEW_HOSTNAME =~ ^[^\-\_]+([0-9a-z]\-{0,1})+[^\-\_]+$ ]]; then - ok_msg "'$NEW_HOSTNAME' is a valid hostname!" - HOSTNAME_VALID="true" - while true; do - echo - read -p "${cyan}###### Do you want '$NEW_HOSTNAME' to be the new hostname? (Y/n):${default} " yn - case "$yn" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - HOSTENAME_CONFIRM="true" - break;; - N|n|No|no) - echo -e "###### > No" - echo -e "${red}Skip hostname change ...${default}" - HOSTENAME_CONFIRM="false" - break;; - esac - done - break - else - warn_msg "'$NEW_HOSTNAME' is not a valid hostname!" - fi - done -} - -set_hostname(){ - if [ "$HOSTNAME_VALID" = "true" ] && [ "$HOSTENAME_CONFIRM" = "true" ]; then - #check for dependencies - dep=(avahi-daemon) - dependency_check - #execute operations - #get current hostname and write to variable - HOSTNAME=$(hostname) - #create host file if missing or create backup of existing one with current date&time - if [ -f /etc/hosts ]; then - status_msg "Creating backup of hosts file ..." - get_date - sudo cp /etc/hosts /etc/hosts."$current_date".bak - ok_msg "Backup done!" - ok_msg "File:'/etc/hosts."$current_date".bak'" - else - sudo touch /etc/hosts - fi - #set hostname in /etc/hostname - status_msg "Setting hostname to '$NEW_HOSTNAME' ..." - status_msg "Please wait ..." - sudo hostnamectl set-hostname "$NEW_HOSTNAME" - #write new hostname to /etc/hosts - status_msg "Writing new hostname to /etc/hosts ..." - if cat /etc/hosts | grep "###set by kiauh" &>/dev/null; then - sudo sed -i "/###set by kiauh/s/\<$HOSTNAME\>/$NEW_HOSTNAME/" /etc/hosts - else - echo "127.0.0.1 $NEW_HOSTNAME ###set by kiauh" | sudo tee -a /etc/hosts &>/dev/null - fi - ok_msg "New hostname successfully configured!" - ok_msg "Remember to reboot for the changes to take effect!" - fi -} - remove_branding(){ echo top_border From 41789fd158fd1c63c053aebfa02ca2f16ebba9c5 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sat, 22 Aug 2020 19:18:08 +0200 Subject: [PATCH 17/31] fix: restructuring reverse proxy and hostname functions --- scripts/set_reverse_proxy.sh | 117 +++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100755 scripts/set_reverse_proxy.sh diff --git a/scripts/set_reverse_proxy.sh b/scripts/set_reverse_proxy.sh new file mode 100755 index 0000000..b9164a1 --- /dev/null +++ b/scripts/set_reverse_proxy.sh @@ -0,0 +1,117 @@ +create_reverse_proxy(){ + if [ "$SET_REVERSE_PROXY" = "true" ]; then + #check for dependencies + dep=(nginx) + dependency_check + #execute operations + status_msg "Creating Nginx configuration for $1 ..." + cat ${HOME}/kiauh/resources/$1_nginx.cfg > ${HOME}/kiauh/resources/$1 + sudo mv ${HOME}/kiauh/resources/$1 /etc/nginx/sites-available/$1 + #ONLY FOR MAINSAIL: replace username if not "pi" + if [ "$1" = "mainsail" ]; then + sudo sed -i "/root/s/pi/${USER}/" /etc/nginx/sites-available/mainsail + fi + ok_msg "Nginx configuration for $1 was set!" + #remove default config + if [ -e /etc/nginx/sites-enabled/default ]; then + sudo rm /etc/nginx/sites-enabled/default + fi + #create symlink for own configs + if [ ! -e /etc/nginx/sites-enabled/$1 ]; then + sudo ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled/ + fi + restart_nginx + fi +} + +create_custom_hostname(){ + echo + top_border + echo -e "| You can change the hostname of this machine to use |" + echo -e "| that name to open the Interface in your browser. |" + echo -e "| |" + echo -e "| Example: If you set the hostname to 'my-printer' |" + echo -e "| you can open DWC2/Mainsail/Octoprint by |" + echo -e "| browsing to: http://my-printer.local |" + bottom_border + while true; do + read -p "${cyan}###### Do you want to change the hostname? (y/N):${default} " yn + case "$yn" in + Y|y|Yes|yes) + user_input_hostname + break;; + N|n|No|no|"") break;; + esac + done +} + +user_input_hostname(){ + unset NEW_HOSTNAME + unset HOSTNAME_VALID + unset HOSTENAME_CONFIRM + echo + top_border + echo -e "| ${green}Allowed characters: a-z, 0-9 and single '-'${default} |" + echo -e "| ${red}No special characters allowed!${default} |" + echo -e "| ${red}No leading or trailing '-' allowed!${default} |" + bottom_border + while true; do + read -p "${cyan}###### Please set the new hostname:${default} " NEW_HOSTNAME + if [[ $NEW_HOSTNAME =~ ^[^\-\_]+([0-9a-z]\-{0,1})+[^\-\_]+$ ]]; then + ok_msg "'$NEW_HOSTNAME' is a valid hostname!" + HOSTNAME_VALID="true" + while true; do + echo + read -p "${cyan}###### Do you want '$NEW_HOSTNAME' to be the new hostname? (Y/n):${default} " yn + case "$yn" in + Y|y|Yes|yes|"") + echo -e "###### > Yes" + HOSTENAME_CONFIRM="true" + break;; + N|n|No|no) + echo -e "###### > No" + echo -e "${red}Skip hostname change ...${default}" + HOSTENAME_CONFIRM="false" + break;; + esac + done + break + else + warn_msg "'$NEW_HOSTNAME' is not a valid hostname!" + fi + done +} + +set_hostname(){ + if [ "$HOSTNAME_VALID" = "true" ] && [ "$HOSTENAME_CONFIRM" = "true" ]; then + #check for dependencies + dep=(avahi-daemon) + dependency_check + #execute operations + #get current hostname and write to variable + HOSTNAME=$(hostname) + #create host file if missing or create backup of existing one with current date&time + if [ -f /etc/hosts ]; then + status_msg "Creating backup of hosts file ..." + get_date + sudo cp /etc/hosts /etc/hosts."$current_date".bak + ok_msg "Backup done!" + ok_msg "File:'/etc/hosts."$current_date".bak'" + else + sudo touch /etc/hosts + fi + #set hostname in /etc/hostname + status_msg "Setting hostname to '$NEW_HOSTNAME' ..." + status_msg "Please wait ..." + sudo hostnamectl set-hostname "$NEW_HOSTNAME" + #write new hostname to /etc/hosts + status_msg "Writing new hostname to /etc/hosts ..." + if cat /etc/hosts | grep "###set by kiauh" &>/dev/null; then + sudo sed -i "/###set by kiauh/s/\<$HOSTNAME\>/$NEW_HOSTNAME/" /etc/hosts + else + echo "127.0.0.1 $NEW_HOSTNAME ###set by kiauh" | sudo tee -a /etc/hosts &>/dev/null + fi + ok_msg "New hostname successfully configured!" + ok_msg "Remember to reboot for the changes to take effect!" + fi +} From 5392e2a9ab86a1c35cfccb71dd29cd588cf7114b Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sat, 22 Aug 2020 19:18:27 +0200 Subject: [PATCH 18/31] add: status message for starting installation --- scripts/install_dwc2.sh | 1 + scripts/install_moonraker.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/scripts/install_dwc2.sh b/scripts/install_dwc2.sh index 8f2cc4d..fcc1080 100755 --- a/scripts/install_dwc2.sh +++ b/scripts/install_dwc2.sh @@ -116,6 +116,7 @@ get_user_selections_dwc2(){ break done fi + status_msg "Installation will start now! Please wait ..." } ############################################################# diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index 49bc3bd..95340fb 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -170,6 +170,7 @@ get_user_selections_moonraker(){ break done fi + status_msg "Installation will start now! Please wait ..." } ############################################################# From 09e4c7bea522b44199700d2bbb67168ea787fe90 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sat, 22 Aug 2020 19:30:35 +0200 Subject: [PATCH 19/31] fix: bring octoprint installation routine into line with dwc2 and mainsail/moonraker routines --- kiauh.sh | 2 +- scripts/install_octoprint.sh | 42 +++++++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index 5fa700c..6714d88 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -190,7 +190,7 @@ install_menu(){ 5) clear print_header - octoprint_install_routine + install_octoprint print_msg && clear_msg install_ui;; Q|q) diff --git a/scripts/install_octoprint.sh b/scripts/install_octoprint.sh index 2cc48fe..cc049ba 100755 --- a/scripts/install_octoprint.sh +++ b/scripts/install_octoprint.sh @@ -1,13 +1,29 @@ -octoprint_install_routine(){ +install_octoprint(){ + #ask user for customization + get_user_selections_octoprint + #octoprint main installation octoprint_dependencies - install_octoprint + octoprint_setup add_groups configure_autostart add_reboot_permission - octoprint_reverse_proxy_dialog - create_custom_hostname create_config_yaml - load_server + #execute customizations + create_reverse_proxy "octoprint" + set_hostname + #after install actions + load_octoprint_server +} + +get_user_selections_octoprint(){ + status_msg "Initializing OctoPrint installation ..." + #ask user to set a reverse proxy + octoprint_reverse_proxy_dialog + #ask to change hostname + if [ "$SET_REVERSE_PROXY" = "true" ]; then + create_custom_hostname + fi + status_msg "Installation will start now! Please wait ..." } octoprint_dependencies(){ @@ -24,7 +40,7 @@ octoprint_dependencies(){ dependency_check } -install_octoprint(){ +octoprint_setup(){ if [ ! -d $OCTOPRINT_DIR ];then status_msg "Create OctoPrint directory ..." mkdir -p $OCTOPRINT_DIR && ok_msg "Directory created!" @@ -97,6 +113,8 @@ add_reboot_permission(){ } octoprint_reverse_proxy_dialog(){ + unset SET_REVERSE_PROXY + 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) | " @@ -106,11 +124,15 @@ octoprint_reverse_proxy_dialog(){ bottom_border while true; do echo -e "${cyan}" - read -p "###### Do you want to set up a reverse proxy now? (Y/n): " yn + 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|"") create_reverse_proxy "octoprint"; break;; - N|n|No|no) break;; + Y|y|Yes|yes) + SET_REVERSE_PROXY="true" + break;; + N|n|No|no|"") + SET_REVERSE_PROXY="false" + break;; esac done } @@ -124,7 +146,7 @@ create_config_yaml(){ fi } -load_server(){ +load_octoprint_server(){ start_octoprint #create an octoprint.log symlink in home-dir just for convenience if [ ! -e ${HOME}/octoprint.log ]; then From 9a3e41716ec97549012d6be5482f0d55ddb8fd95 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sat, 22 Aug 2020 20:05:56 +0200 Subject: [PATCH 20/31] fix: delete a debug msg --- scripts/update.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/update.sh b/scripts/update.sh index 31efa9c..27cf319 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -27,7 +27,6 @@ update_klipper(){ cd $KLIPPER_DIR git fetch $FETCH_BRANCH -q && ok_msg "Fetch successfull!" status_msg "Checking out $FETCH_BRANCH" - echo "git checkout $FETCH_BRANCH" git checkout $FETCH_BRANCH -q && ok_msg "Checkout successfull!" && echo; ok_msg "Update complete!" fi start_klipper; echo From e32cc9d3cb18ea99625daf527e0a54c7d4ad5336 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sat, 22 Aug 2020 20:29:22 +0200 Subject: [PATCH 21/31] fix: remove deprecated main menu entry --- scripts/ui.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/ui.sh b/scripts/ui.sh index 63390b1..f8ea188 100755 --- a/scripts/ui.sh +++ b/scripts/ui.sh @@ -32,14 +32,14 @@ main_ui(){ top_border echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |" hr - echo -e "| 0) [System status] | |" - echo -e "| | Klipper: $KLIPPER_STATUS|" - echo -e "| 1) [Install] | Branch: ${cyan}$PRINT_BRANCH${default}|" - echo -e "| 2) [Update] | |" - echo -e "| 3) [Remove] | DWC2: $DWC2_STATUS|" - echo -e "| | Mainsail: $MAINSAIL_STATUS|" - echo -e "| 4) [Advanced] | Octoprint: $OCTOPRINT_STATUS|" - echo -e "| 5) [Backup] | |" + echo -e "| | |" + echo -e "| 1) [Install] | Klipper: $KLIPPER_STATUS|" + echo -e "| 2) [Update] | Branch: ${cyan}$PRINT_BRANCH${default}|" + echo -e "| 3) [Remove] | |" + echo -e "| | DWC2: $DWC2_STATUS|" + echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|" + echo -e "| 5) [Backup] | Octoprint: $OCTOPRINT_STATUS|" + echo -e "| | |" quit_footer } From 35ecf3ae65e06955717ad7453a59ebf30f55cd85 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sat, 22 Aug 2020 21:58:55 +0200 Subject: [PATCH 22/31] fix: kiauh update function (finally?) --- scripts/status.sh | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/scripts/status.sh b/scripts/status.sh index c27d35d..ff3ec7d 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -1,21 +1,12 @@ kiauh_status(){ cd ${HOME}/kiauh git fetch --all -q - if [ $(git branch -a | grep "* master" | cut -d" " -f2) ]; then - CURR_KIAUH_BRANCH="master" - elif [ $(git branch -a | grep "* dev-2.0" | cut -d" " -f2) ]; then - CURR_KIAUH_BRANCH="dev-2.0" - fi - if [ "$CURR_KIAUH_BRANCH" = "master" ]; then - REMOTE_KIAUH_COMMIT=$(git rev-parse --short=8 origin/master) - LOCAL_KIAUH_COMMIT=$(git rev-parse --short=8 HEAD) - if [ "$REMOTE_KIAUH_COMMIT" != "$LOCAL_KIAUH_COMMIT" ]; then + if git branch -a | grep "* master" -q; then + if [[ "$(git rev-parse --short=8 origin/master)" != "$(git rev-parse --short=8 HEAD)" ]]; then KIAUH_UPDATE_AVAIL="true" fi - elif [ "$CURR_KIAUH_BRANCH" = "dev-2.0" ]; then - REMOTE_KIAUH_COMMIT=$(git rev-parse --short=8 dev-2.0) - LOCAL_KIAUH_COMMIT=$(git rev-parse --short=8 HEAD) - if [ "$REMOTE_KIAUH_COMMIT" != "$LOCAL_KIAUH_COMMIT" ]; then + elif git branch -a | grep "* dev-2.0" -q; then + if [[ "$(git rev-parse --short=8 origin/dev-2.0)" != "$(git rev-parse --short=8 HEAD)" ]]; then KIAUH_UPDATE_AVAIL="true" fi fi From 612a4225befd9b7ac8fec666d20e0acd7e264bd1 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sat, 22 Aug 2020 22:20:13 +0200 Subject: [PATCH 23/31] fix: recreate deleted variable --- scripts/status.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/status.sh b/scripts/status.sh index ff3ec7d..6f226cd 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -2,10 +2,12 @@ kiauh_status(){ cd ${HOME}/kiauh git fetch --all -q if git branch -a | grep "* master" -q; then + CURR_KIAUH_BRANCH="master" #needed to display branch in UI if [[ "$(git rev-parse --short=8 origin/master)" != "$(git rev-parse --short=8 HEAD)" ]]; then KIAUH_UPDATE_AVAIL="true" fi elif git branch -a | grep "* dev-2.0" -q; then + CURR_KIAUH_BRANCH="dev-2.0" #needed to display branch in UI if [[ "$(git rev-parse --short=8 origin/dev-2.0)" != "$(git rev-parse --short=8 HEAD)" ]]; then KIAUH_UPDATE_AVAIL="true" fi From 613e0d779f9e01b3c17cab4bde9923b3dd933f3a Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sat, 22 Aug 2020 23:21:26 +0200 Subject: [PATCH 24/31] fix: rollback function --- scripts/rollback.sh | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/scripts/rollback.sh b/scripts/rollback.sh index 2335ef6..a61c049 100755 --- a/scripts/rollback.sh +++ b/scripts/rollback.sh @@ -33,43 +33,51 @@ save_klipper_state(){ load_klipper_state(){ source_ini print_branch - CURR_COMM=$(git rev-parse --short=8 HEAD) - if [ "$GET_BRANCH" = "origin/master" ]; then - PREV_COMM=$previous_origin_state + cd $KLIPPER_DIR + CURRENT_COMMIT=$(git rev-parse --short=8 HEAD) + if [ "$GET_BRANCH" = "origin/master" ] || [ "$GET_BRANCH" = "origin" ]; then + PREVIOUS_COMMIT=$previous_origin_state elif [ "$GET_BRANCH" = "dmbutyugin/scurve-shaping" ]; then - PREV_COMM=$previous_shaping_state + PREVIOUS_COMMIT=$previous_shaping_state elif [ "$GET_BRANCH" = "dmbutyugin/scurve-smoothing" ]; then - PREV_COMM=$previous_smoothing_state + PREVIOUS_COMMIT=$previous_smoothing_state elif [ "$GET_BRANCH" = "Arksine/work-web_server-20200131" ]; then - PREV_COMM=$previous_moonraker_state + PREVIOUS_COMMIT=$previous_moonraker_state elif [ "$GET_BRANCH" = "Arksine/dev-moonraker-testing" ]; then - PREV_COMM=$previous_dev_moonraker_state + PREVIOUS_COMMIT=$previous_dev_moonraker_state fi - PREV_COMM_DATE=$(git show -s --format=%cd --date=short $PREV_COMM) - CURR_COMM_DATE=$(git show -s --format=%cd --date=short $CURR_COMM) - if [ $CURR_COMM = $PREV_COMM ]; then - CURR_UI=$(echo -e "${green}$CURR_COMM from $CURR_COMM_DATE${default}") - PREV_UI=$(echo -e "${green}$PREV_COMM from $PREV_COMM_DATE${default}") + CURRENT_COMMIT_DATE=$(git show -s --format=%cd --date=short $CURRENT_COMMIT) + if [ "$PREVIOUS_COMMIT" != "0" ]; then + PREVIOUS_COMMIT_DATE=$(git show -s --format=%cd --date=short $PREVIOUS_COMMIT) + fi + if [ "$PREVIOUS_COMMIT" = "0" ]; then + CURR_UI=$(echo -e "${green}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${default}") + PREV_UI=$(echo -e "${red}None${default} ") else - CURR_UI=$(echo -e "${yellow}$CURR_COMM from $CURR_COMM_DATE${default}") - PREV_UI=$(echo -e "${yellow}$PREV_COMM from $PREV_COMM_DATE${default}") + if [ "$CURRENT_COMMIT" = "$PREVIOUS_COMMIT" ]; then + CURR_UI=$(echo -e "${green}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${default}") + PREV_UI=$(echo -e "${green}$PREVIOUS_COMMIT from $PREVIOUS_COMMIT_DATE${default}") + else + CURR_UI=$(echo -e "${yellow}$CURRENT_COMMIT from $CURRENT_COMMIT_DATE${default}") + PREV_UI=$(echo -e "${yellow}$PREVIOUS_COMMIT from $PREVIOUS_COMMIT_DATE${default}") + fi fi rollback_ui rollback_klipper } rollback_klipper(){ - if [ "$CURR_COMM" != "$PREV_COMM" ]; then + if [ "$PREVIOUS_COMMIT" != "0" ] && [ "$CURRENT_COMMIT" != "$PREVIOUS_COMMIT" ]; then while true; do echo -e "${cyan}" - read -p "###### Do you want to rollback to $PREV_COMM? (Y/n): " yn + read -p "###### Do you want to rollback to $PREVIOUS_COMMIT? (Y/n): " yn echo -e "${default}" case "$yn" in Y|y|Yes|yes|"") clear print_header - status_msg "Rolling back to $PREV_COMM ..." - git reset --hard $PREV_COMM -q + status_msg "Rolling back to $PREVIOUS_COMMIT ..." + git reset --hard $PREVIOUS_COMMIT -q ok_msg "Rollback complete!"; echo load_klipper_state break;; From dd16a2503b64f74796ad71e0359d0f986f9f19d7 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sat, 22 Aug 2020 23:32:35 +0200 Subject: [PATCH 25/31] fix: extend description --- scripts/install_moonraker.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index 95340fb..70e82b5 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -373,8 +373,12 @@ custom_trusted_clients(){ 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 as you want. |" + 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 From be5643958719b929c261415a8522aebc7f01d889 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sun, 23 Aug 2020 16:31:55 +0200 Subject: [PATCH 26/31] fix: typo in mainsail installer --- scripts/install_mainsail.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install_mainsail.sh b/scripts/install_mainsail.sh index bf90610..1502280 100755 --- a/scripts/install_mainsail.sh +++ b/scripts/install_mainsail.sh @@ -2,7 +2,7 @@ install_mainsail(){ if [ "$INST_MAINSAIL" = "true" ]; then if [ -d $KLIPPER_DIR ]; then disable_haproxy_lighttpd - unset SET_REVERSE_PROXY && SET_REVERSE_PROXY"true" #quick and dirty hack to make mainsail reverse proxy install, needs polish + unset SET_REVERSE_PROXY && SET_REVERSE_PROXY="true" #quick and dirty hack to make mainsail reverse proxy install, needs polish create_reverse_proxy "mainsail" mainsail_setup test_nginx From f08d6ecdc27fd17628d35a045eda25bde4a2dcea Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sun, 23 Aug 2020 20:48:07 +0200 Subject: [PATCH 27/31] fix: clean up and restructure menus and ui --- kiauh.sh | 478 ++---------------------------------- scripts/ui.sh | 190 -------------- scripts/ui/advanced_menu.sh | 205 ++++++++++++++++ scripts/ui/backup_menu.sh | 71 ++++++ scripts/ui/general_ui.sh | 34 +++ scripts/ui/install_menu.sh | 66 +++++ scripts/ui/main_menu.sh | 79 ++++++ scripts/ui/remove_menu.sh | 76 ++++++ scripts/ui/update_menu.sh | 87 +++++++ 9 files changed, 642 insertions(+), 644 deletions(-) delete mode 100755 scripts/ui.sh create mode 100755 scripts/ui/advanced_menu.sh create mode 100755 scripts/ui/backup_menu.sh create mode 100755 scripts/ui/general_ui.sh create mode 100755 scripts/ui/install_menu.sh create mode 100755 scripts/ui/main_menu.sh create mode 100755 scripts/ui/remove_menu.sh create mode 100755 scripts/ui/update_menu.sh diff --git a/kiauh.sh b/kiauh.sh index 6714d88..f25bfeb 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -10,26 +10,6 @@ red=$(echo -en "\001\033[01;31m\002") cyan=$(echo -en "\001\033[01;36m\002") default=$(echo -en "\001\033[0m\002") -### set some messages -warn_msg(){ - echo -e "${red} $1${default}" -} -status_msg(){ - echo; echo -e "${yellow}###### $1${default}" -} -ok_msg(){ - echo -e "${green}>>>>>> $1${default}" -} -title_msg(){ - echo -e "${cyan}$1${default}" -} -get_date(){ - current_date=$(date +"%Y-%m-%d_%H-%M") -} -print_unkown_cmd(){ - ERROR_MSG=" Sorry i don't know that command!" -} - ### set important directories #klipper KLIPPER_DIR=${HOME}/klipper @@ -40,8 +20,6 @@ KLIPPER_SERVICE2=/etc/default/klipper DWC2FK_DIR=${HOME}/dwc2-for-klipper DWC2_DIR=${HOME}/sdcard/dwc2 WEB_DWC2=${HOME}/klipper/klippy/extras/web_dwc2.py -TORNADO_DIR1=${HOME}/klippy-env/lib/python2.7/site-packages/tornado -TORNADO_DIR2=${HOME}/klippy-env/lib/python2.7/site-packages/tornado-5.1.1.dist-info #mainsail/moonraker MAINSAIL_DIR=${HOME}/mainsail MOONRAKER_DIR=${HOME}/moonraker @@ -69,6 +47,26 @@ BRANCH_MOONRAKER=Arksine/dev-moonraker-testing BRANCH_SCURVE_SMOOTHING=dmbutyugin/scurve-smoothing BRANCH_SCURVE_SHAPING=dmbutyugin/scurve-shaping +### set some messages +warn_msg(){ + echo -e "${red} $1${default}" +} +status_msg(){ + echo; echo -e "${yellow}###### $1${default}" +} +ok_msg(){ + echo -e "${green}>>>>>> $1${default}" +} +title_msg(){ + echo -e "${cyan}$1${default}" +} +get_date(){ + current_date=$(date +"%Y-%m-%d_%H-%M") +} +print_unkown_cmd(){ + ERROR_MSG=" Sorry i don't know that command!" +} + print_msg(){ if [[ "$ERROR_MSG" != "" ]]; then echo -e "${red}" @@ -87,442 +85,14 @@ print_msg(){ } clear_msg(){ - CONFIRM_MSG="" && ERROR_MSG="" -} - -main_menu(){ - print_header - #print KIAUH update msg if update available - if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then - kiauh_update_msg - fi - #check install status - klipper_status - dwc2_status - mainsail_status - octoprint_status - print_branch - print_msg && clear_msg - main_ui - while true; do - echo -e "${cyan}" - read -p "Perform action: " action; echo - echo -e "${default}" - case "$action" in - update) - clear - print_header - update_kiauh - print_msg && clear_msg - main_ui;; - 0) - clear - print_header - ERROR_MSG="Sorry this function is not implemented yet!" - print_msg && clear_msg - main_ui;; - 1) - clear - install_menu - break;; - 2) - clear - update_menu - break;; - 3) - clear - remove_menu - break;; - 4) - clear - advanced_menu - break;; - 5) - clear - backup_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;; - esac - done - clear; main_menu -} - -install_menu(){ - print_header - install_ui - while true; do - echo -e "${cyan}" - read -p "Perform action: " action; echo - echo -e "${default}" - case "$action" in - 1) - clear - print_header - install_klipper - print_msg && clear_msg - install_ui;; - 2) - clear - print_header - install_moonraker - print_msg && clear_msg - install_ui;; - 3) - clear - print_header - install_dwc2 - print_msg && clear_msg - install_ui;; - 4) - clear - print_header - INST_MAINSAIL="true" && install_mainsail - print_msg && clear_msg - install_ui;; - 5) - clear - print_header - install_octoprint - print_msg && clear_msg - install_ui;; - Q|q) - clear; main_menu; break;; - *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - install_ui;; - esac - done - install_menu -} - -update_menu(){ - print_header - #compare versions - ui_print_versions - print_msg && clear_msg - read_bb4u_stat - update_ui - while true; do - echo -e "${cyan}" - read -p "Perform action: " action; echo - echo -e "${default}" - case "$action" in - 0) - clear - print_header - toggle_backups - print_msg && clear_msg - update_ui;; - 1) - clear - print_header - update_klipper && ui_print_versions - print_msg && clear_msg - update_ui;; - 2) - clear - print_header - update_dwc2fk && ui_print_versions - print_msg && clear_msg - update_ui;; - 3) - clear - print_header - update_dwc2 && ui_print_versions - print_msg && clear_msg - update_ui;; - 4) - clear - print_header - update_moonraker && ui_print_versions - print_msg && clear_msg - update_ui;; - 5) - clear - print_header - update_mainsail && ui_print_versions - print_msg && clear_msg - update_ui;; - Q|q) - clear; main_menu; break;; - *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - ui_print_versions - update_ui;; - esac - done - update_menu -} - -remove_menu(){ - print_header - remove_ui - while true; do - echo -e "${cyan}" - read -p "Perform action: " action; echo - echo -e "${default}" - case "$action" in - 1) - clear - print_header - remove_klipper - print_msg && clear_msg - remove_ui;; - 2) - clear - print_header - remove_moonraker - print_msg && clear_msg - remove_ui;; - 3) - clear - print_header - remove_dwc2 - print_msg && clear_msg - remove_ui;; - 4) - clear - print_header - remove_mainsail - print_msg && clear_msg - remove_ui;; - 5) - clear - print_header - remove_octoprint - print_msg && clear_msg - remove_ui;; - 6) - clear - print_header - remove_nginx - print_msg && clear_msg - remove_ui;; - Q|q) - clear; main_menu; break;; - *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - remove_ui;; - esac - done - remove_menu -} - -advanced_menu(){ - print_header - print_msg && clear_msg - read_octoprint_service_status - advanced_ui - while true; do - echo -e "${cyan}" - read -p "Perform action: " action; echo - echo -e "${default}" - case "$action" in - 0) - clear - print_header - toggle_octoprint_service - read_octoprint_service_status - print_msg && clear_msg - advanced_ui;; - 1) - clear - print_header - switch_menu - print_msg && clear_msg - advanced_ui;; - 2) - clear - print_header - load_klipper_state - print_msg && clear_msg - advanced_ui;; - 3) - clear - print_header - build_fw - print_msg && clear_msg - advanced_ui;; - 4) - clear - print_header - flash_routine - print_msg && clear_msg - advanced_ui;; - 5) - clear - print_header - get_printer_usb - print_msg && clear_msg - advanced_ui;; - 6) - clear - print_header - get_printer_usb && write_printer_usb - print_msg && clear_msg - advanced_ui;; - 7) - clear - print_header - create_dwc2fk_cfg - print_msg && clear_msg - advanced_ui;; - 8) - clear - print_header - create_custom_hostname - print_msg && clear_msg - advanced_ui;; - 9) - clear - print_header - remove_branding - print_msg && clear_msg - advanced_ui;; - Q|q) - clear; main_menu; break;; - *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - advanced_ui;; - esac - done - advanced_menu -} - -switch_menu(){ - if [ -d $KLIPPER_DIR ]; then - read_branch - print_msg && clear_msg - switch_ui - while true; do - echo -e "${cyan}" - read -p "Perform action: " action; echo - echo -e "${default}" - case "$action" in - 1) - clear - print_header - switch_to_origin - read_branch - print_msg && clear_msg - switch_ui;; - 2) - clear - print_header - switch_to_scurve_shaping - read_branch - print_msg && clear_msg - switch_ui;; - 3) - clear - print_header - switch_to_scurve_smoothing - read_branch - print_msg && clear_msg - switch_ui;; - 4) - clear - print_header - switch_to_moonraker - read_branch - print_msg && clear_msg - switch_ui;; - Q|q) - clear; advanced_menu; break;; - *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - switch_ui;; - esac - done - else - ERROR_MSG="No Klipper directory found! Download Klipper first!" - fi -} - -#rollback_menu(){ -# load_klipper_state -# print_msg && clear_msg -# advanced_menu -#} - -backup_menu(){ - print_header - print_msg && clear_msg - backup_ui - while true; do - echo -e "${cyan}" - read -p "Perform action: " action; echo - echo -e "${default}" - case "$action" in - 1) - clear - print_header - backup_klipper - print_msg && clear_msg - backup_ui;; - 2) - clear - print_header - backup_dwc2 - print_msg && clear_msg - backup_ui;; - 3) - clear - print_header - backup_mainsail - print_msg && clear_msg - backup_ui;; - 4) - clear - print_header - backup_moonraker - print_msg && clear_msg - backup_ui;; - 5) - clear - print_header - backup_octoprint - print_msg && clear_msg - backup_ui;; - Q|q) - clear; main_menu; break;; - *) - clear - print_header - print_unkown_cmd - print_msg && clear_msg - backup_ui;; - esac - done - backup_menu + unset CONFIRM_MSG + unset ERROR_MSG } ### sourcing all additional scripts SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )" -for script in "${SRCDIR}/kiauh/scripts/"*; do . $script; done +for script in "${SRCDIR}/kiauh/scripts/"*.sh; do . $script; done +for script in "${SRCDIR}/kiauh/scripts/ui/"*.sh; do . $script; done check_euid kiauh_status diff --git a/scripts/ui.sh b/scripts/ui.sh deleted file mode 100755 index f8ea188..0000000 --- a/scripts/ui.sh +++ /dev/null @@ -1,190 +0,0 @@ -### set up some UI stuff - -#ui total width = 57 chars -top_border(){ - echo -e "/=======================================================\ " -} - -bottom_border(){ - echo -e "\=======================================================/" -} - -hr(){ - echo -e "|-------------------------------------------------------|" -} - -quit_footer(){ - hr - echo -e "| ${red}Q) Quit${default} | " - bottom_border - echo -e " KIAUH: $CURR_KIAUH_BRANCH" -} - -print_header(){ - top_border - echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~ [ KIAUH ] ~~~~~~~~~~~~~~~~~") |" - echo -e "| $(title_msg " Klipper Installation And Update Helper ") |" - echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") |" - bottom_border -} - -main_ui(){ - top_border - echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |" - hr - echo -e "| | |" - echo -e "| 1) [Install] | Klipper: $KLIPPER_STATUS|" - echo -e "| 2) [Update] | Branch: ${cyan}$PRINT_BRANCH${default}|" - echo -e "| 3) [Remove] | |" - echo -e "| | DWC2: $DWC2_STATUS|" - echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|" - echo -e "| 5) [Backup] | Octoprint: $OCTOPRINT_STATUS|" - echo -e "| | |" - quit_footer -} - -install_ui(){ - top_border - echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${default} | " - hr - echo -e "| You need this menu usually only for installing | " - 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) [Octoprint] | " - echo -e "| 2) [Moonraker] | | " - quit_footer -} - -update_ui(){ - top_border - echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${default} | " - hr - echo -e "| It is a good idea to check the following website | " - echo -e "| for important software changes to the config file | " - echo -e "| >> BEFORE << updating your klipper installation: | " - echo -e "| | " - echo -e "| ${yellow}https://www.klipper3d.org/Config_Changes.html${default} | " - bottom_border - top_border - echo -e "| 0) $BB4U_STATUS| " - hr - echo -e "| | Local Vers: | Remote Vers: | " - echo -e "| Firmware: | | | " - echo -e "| 1) [Klipper] | $(echo "$LOCAL_COMMIT") | $(echo "$REMOTE_COMMIT") | " - echo -e "| | | | " - echo -e "| Webinterface: |---------------|--------------| " - echo -e "| 2) [DWC2-for-Klipper] | $(echo "$LOCAL_DWC2FK_COMMIT") | $(echo "$REMOTE_DWC2FK_COMMIT") | " - echo -e "| 3) [DWC2 Web UI] | $(echo "$DWC2_LOCAL_VER") | $(echo "$DWC2_REMOTE_VER") | " - echo -e "| |---------------|--------------| " - echo -e "| 4) [Moonraker] | $(echo "$LOCAL_MOONRAKER_COMMIT") | $(echo "$REMOTE_MOONRAKER_COMMIT") | " - echo -e "| 5) [Mainsail] | $(echo "$MAINSAIL_LOCAL_VER") | $(echo "$MAINSAIL_REMOTE_VER") | " - quit_footer -} - -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 "| --> ~/klipper_config | " - 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) [Octoprint] | " - echo -e "| 2) [Moonraker] | | " - echo -e "| | Webserver: | " - echo -e "| | 6) [Nginx] | " - quit_footer -} - -advanced_ui(){ - top_border - echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${default} | " - hr - echo -e "| 0) $OPRINT_SERVICE_STATUS| " - hr - echo -e "| | | " - echo -e "| Klipper: | System: | " - echo -e "| 1) [Switch Version] | 8) [Change hostname] | " - echo -e "| 2) [Rollback] | | " - echo -e "| | Mainsail: | " - echo -e "| Firmware: | 9) [Remove branding] | " - echo -e "| 3) [Build Firmware] | | " - echo -e "| 4) [Flash MCU] | | " - echo -e "| 5) [Get Printer-USB] | | " - echo -e "| 6) [Write Printer-USB] | | " - echo -e "| 7) [Write DWC2 config] | | " - echo -e "| | | " -quit_footer -} - -backup_ui(){ - top_border - echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") | " - hr - echo -e "| ${yellow}Backup location: ~/kiauh-backups${default} | " - hr - echo -e "| Firmware: | " - echo -e "| 1) [Klipper] | " - echo -e "| | " - echo -e "| Webinterface: | " - echo -e "| 2) [DWC2 Web UI] | " - echo -e "| | " - echo -e "| 3) [Mainsail] | " - echo -e "| 4) [Moonraker] | " - echo -e "| | " - echo -e "| 5) [OctoPrint] | " - echo -e "| | " - quit_footer -} - -switch_ui(){ - top_border - echo -e "| $(title_msg "~~~~~~~~~ [ Switch Klipper Branch ] ~~~~~~~~~") |" - bottom_border - echo - echo -e " $(title_msg "Active Branch: ")${green}$GET_BRANCH${default}" - echo - top_border - echo -e "| 1) [--> origin/master] | " - echo -e "| | " - echo -e "| 2) [--> scurve-shaping] | " - echo -e "| 3) [--> scurve-smoothing] | " - echo -e "| | " - echo -e "| 4) [--> moonraker] | " - quit_footer -} - -kiauh_update_msg(){ - top_border - echo -e "| ${yellow}There is a newer version of this script available!${default} | " - echo -e "| ${yellow}Type 'update' if you want to update KIAUH now.${default} | " - bottom_border -} - -rollback_ui(){ - top_border - echo -e "| $(title_msg "~~~~~~~~~~~~~ [ Rollback Menu ] ~~~~~~~~~~~~~") | " - hr - echo -e "| If serious errors occured after updating Klipper, | " - echo -e "| you can use this menu to return to the previously | " - echo -e "| used commit from which you have updated. | " - bottom_border - top_border - echo -e "| Active branch: ${green}$PRINT_BRANCH${default} | " - hr - echo -e "| Currently on commit: | " - echo -e "| $CURR_UI | " - hr - echo -e "| Commit last updated from: | " - echo -e "| $PREV_UI | " - quit_footer -} \ No newline at end of file diff --git a/scripts/ui/advanced_menu.sh b/scripts/ui/advanced_menu.sh new file mode 100755 index 0000000..9508328 --- /dev/null +++ b/scripts/ui/advanced_menu.sh @@ -0,0 +1,205 @@ +advanced_ui(){ + top_border + echo -e "| ${yellow}~~~~~~~~~~~~~ [ Advanced Menu ] ~~~~~~~~~~~~~${default} | " + hr + echo -e "| 0) $OPRINT_SERVICE_STATUS| " + hr + echo -e "| | | " + echo -e "| Klipper: | System: | " + echo -e "| 1) [Switch Version] | 8) [Change hostname] | " + echo -e "| 2) [Rollback] | | " + echo -e "| | Mainsail: | " + echo -e "| Firmware: | 9) [Remove branding] | " + echo -e "| 3) [Build Firmware] | | " + echo -e "| 4) [Flash MCU] | Extensions: | " + echo -e "| 5) [Get Printer-USB] | 10) [Shell Command] | " + echo -e "| 6) [Write Printer-USB] | | " + echo -e "| 7) [Write DWC2 config] | | " + echo -e "| | | " +quit_footer +} + +advanced_menu(){ + print_header + print_msg && clear_msg + read_octoprint_service_status + advanced_ui + while true; do + echo -e "${cyan}" + read -p "Perform action: " action; echo + echo -e "${default}" + case "$action" in + 0) + clear + print_header + toggle_octoprint_service + read_octoprint_service_status + print_msg && clear_msg + advanced_ui;; + 1) + clear + print_header + switch_menu + print_msg && clear_msg + advanced_ui;; + 2) + clear + print_header + load_klipper_state + print_msg && clear_msg + advanced_ui;; + 3) + clear + print_header + build_fw + print_msg && clear_msg + advanced_ui;; + 4) + clear + print_header + flash_routine + print_msg && clear_msg + advanced_ui;; + 5) + clear + print_header + get_printer_usb + print_msg && clear_msg + advanced_ui;; + 6) + clear + print_header + get_printer_usb && write_printer_usb + print_msg && clear_msg + advanced_ui;; + 7) + clear + print_header + create_dwc2fk_cfg + print_msg && clear_msg + advanced_ui;; + 8) + clear + print_header + create_custom_hostname + print_msg && clear_msg + advanced_ui;; + 9) + clear + print_header + remove_branding + print_msg && clear_msg + advanced_ui;; + 10) + clear + print_header + install_extension_shell_command + print_msg && clear_msg + advanced_ui;; + Q|q) + clear; main_menu; break;; + *) + clear + print_header + print_unkown_cmd + print_msg && clear_msg + advanced_ui;; + esac + done + advanced_menu +} + +############################################################# +############################################################# + +switch_ui(){ + top_border + echo -e "| $(title_msg "~~~~~~~~~ [ Switch Klipper Branch ] ~~~~~~~~~") |" + bottom_border + echo + echo -e " $(title_msg "Active Branch: ")${green}$GET_BRANCH${default}" + echo + top_border + echo -e "| 1) [--> origin/master] | " + echo -e "| | " + echo -e "| 2) [--> scurve-shaping] | " + echo -e "| 3) [--> scurve-smoothing] | " + echo -e "| | " + echo -e "| 4) [--> moonraker] | " + quit_footer +} + +switch_menu(){ + if [ -d $KLIPPER_DIR ]; then + read_branch + print_msg && clear_msg + switch_ui + while true; do + echo -e "${cyan}" + read -p "Perform action: " action; echo + echo -e "${default}" + case "$action" in + 1) + clear + print_header + switch_to_origin + read_branch + print_msg && clear_msg + switch_ui;; + 2) + clear + print_header + switch_to_scurve_shaping + read_branch + print_msg && clear_msg + switch_ui;; + 3) + clear + print_header + switch_to_scurve_smoothing + read_branch + print_msg && clear_msg + switch_ui;; + 4) + clear + print_header + switch_to_moonraker + read_branch + print_msg && clear_msg + switch_ui;; + Q|q) + clear; advanced_menu; break;; + *) + clear + print_header + print_unkown_cmd + print_msg && clear_msg + switch_ui;; + esac + done + else + ERROR_MSG="No Klipper directory found! Download Klipper first!" + fi +} + +############################################################# +############################################################# + +rollback_ui(){ + top_border + echo -e "| $(title_msg "~~~~~~~~~~~~~ [ Rollback Menu ] ~~~~~~~~~~~~~") | " + hr + echo -e "| If serious errors occured after updating Klipper, | " + echo -e "| you can use this menu to return to the previously | " + echo -e "| used commit from which you have updated. | " + bottom_border + top_border + echo -e "| Active branch: ${green}$PRINT_BRANCH${default} | " + hr + echo -e "| Currently on commit: | " + echo -e "| $CURR_UI | " + hr + echo -e "| Commit last updated from: | " + echo -e "| $PREV_UI | " + quit_footer +} diff --git a/scripts/ui/backup_menu.sh b/scripts/ui/backup_menu.sh new file mode 100755 index 0000000..5738821 --- /dev/null +++ b/scripts/ui/backup_menu.sh @@ -0,0 +1,71 @@ +backup_ui(){ + top_border + echo -e "| $(title_msg "~~~~~~~~~~~~~~ [ Backup Menu ] ~~~~~~~~~~~~~~") | " + hr + echo -e "| ${yellow}Backup location: ~/kiauh-backups${default} | " + hr + echo -e "| Firmware: | " + echo -e "| 1) [Klipper] | " + echo -e "| | " + echo -e "| Webinterface: | " + echo -e "| 2) [DWC2 Web UI] | " + echo -e "| | " + echo -e "| 3) [Mainsail] | " + echo -e "| 4) [Moonraker] | " + echo -e "| | " + echo -e "| 5) [OctoPrint] | " + echo -e "| | " + quit_footer +} + +backup_menu(){ + print_header + print_msg && clear_msg + backup_ui + while true; do + echo -e "${cyan}" + read -p "Perform action: " action; echo + echo -e "${default}" + case "$action" in + 1) + clear + print_header + backup_klipper + print_msg && clear_msg + backup_ui;; + 2) + clear + print_header + backup_dwc2 + print_msg && clear_msg + backup_ui;; + 3) + clear + print_header + backup_mainsail + print_msg && clear_msg + backup_ui;; + 4) + clear + print_header + backup_moonraker + print_msg && clear_msg + backup_ui;; + 5) + clear + print_header + backup_octoprint + print_msg && clear_msg + backup_ui;; + Q|q) + clear; main_menu; break;; + *) + clear + print_header + print_unkown_cmd + print_msg && clear_msg + backup_ui;; + esac + done + backup_menu +} diff --git a/scripts/ui/general_ui.sh b/scripts/ui/general_ui.sh new file mode 100755 index 0000000..865af8d --- /dev/null +++ b/scripts/ui/general_ui.sh @@ -0,0 +1,34 @@ +#ui total width = 57 chars +top_border(){ + echo -e "/=======================================================\ " +} + +bottom_border(){ + echo -e "\=======================================================/" +} + +hr(){ + echo -e "|-------------------------------------------------------|" +} + +quit_footer(){ + hr + echo -e "| ${red}Q) Quit${default} | " + bottom_border + echo -e " KIAUH: $CURR_KIAUH_BRANCH" +} + +print_header(){ + top_border + echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~ [ KIAUH ] ~~~~~~~~~~~~~~~~~") |" + echo -e "| $(title_msg " Klipper Installation And Update Helper ") |" + echo -e "| $(title_msg "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") |" + bottom_border +} + +kiauh_update_msg(){ + top_border + echo -e "| ${yellow}There is a newer version of this script available!${default} | " + echo -e "| ${yellow}Type 'update' if you want to update KIAUH now.${default} | " + bottom_border +} diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh new file mode 100755 index 0000000..8e0ec75 --- /dev/null +++ b/scripts/ui/install_menu.sh @@ -0,0 +1,66 @@ +install_ui(){ + top_border + echo -e "| ${green}~~~~~~~~~~~ [ Installation Menu ] ~~~~~~~~~~~${default} | " + hr + echo -e "| You need this menu usually only for installing | " + 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) [Octoprint] | " + echo -e "| 2) [Moonraker] | | " + quit_footer +} + +install_menu(){ + print_header + install_ui + while true; do + echo -e "${cyan}" + read -p "Perform action: " action; echo + echo -e "${default}" + case "$action" in + 1) + clear + print_header + install_klipper + print_msg && clear_msg + install_ui;; + 2) + clear + print_header + install_moonraker + print_msg && clear_msg + install_ui;; + 3) + clear + print_header + install_dwc2 + print_msg && clear_msg + install_ui;; + 4) + clear + print_header + INST_MAINSAIL="true" && install_mainsail + print_msg && clear_msg + install_ui;; + 5) + clear + print_header + install_octoprint + print_msg && clear_msg + install_ui;; + Q|q) + clear; main_menu; break;; + *) + clear + print_header + print_unkown_cmd + print_msg && clear_msg + install_ui;; + esac + done + install_menu +} diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh new file mode 100755 index 0000000..07d86c4 --- /dev/null +++ b/scripts/ui/main_menu.sh @@ -0,0 +1,79 @@ +main_ui(){ + top_border + echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |" + hr + echo -e "| | |" + echo -e "| 1) [Install] | Klipper: $KLIPPER_STATUS|" + echo -e "| 2) [Update] | Branch: ${cyan}$PRINT_BRANCH${default}|" + echo -e "| 3) [Remove] | |" + echo -e "| | DWC2: $DWC2_STATUS|" + echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|" + echo -e "| 5) [Backup] | Octoprint: $OCTOPRINT_STATUS|" + echo -e "| | |" + quit_footer +} + +main_menu(){ + print_header + #print KIAUH update msg if update available + if [ "$KIAUH_UPDATE_AVAIL" = "true" ]; then + kiauh_update_msg + fi + #check install status + klipper_status + dwc2_status + mainsail_status + octoprint_status + print_branch + print_msg && clear_msg + main_ui + while true; do + echo -e "${cyan}" + read -p "Perform action: " action; echo + echo -e "${default}" + case "$action" in + update) + clear + print_header + update_kiauh + print_msg && clear_msg + main_ui;; + 0) + clear + print_header + ERROR_MSG="Sorry this function is not implemented yet!" + print_msg && clear_msg + main_ui;; + 1) + clear + install_menu + break;; + 2) + clear + update_menu + break;; + 3) + clear + remove_menu + break;; + 4) + clear + advanced_menu + break;; + 5) + clear + backup_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;; + esac + done + clear; main_menu +} diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh new file mode 100755 index 0000000..f0692b5 --- /dev/null +++ b/scripts/ui/remove_menu.sh @@ -0,0 +1,76 @@ +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 "| --> ~/klipper_config | " + 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) [Octoprint] | " + echo -e "| 2) [Moonraker] | | " + echo -e "| | Webserver: | " + echo -e "| | 6) [Nginx] | " + quit_footer +} + +remove_menu(){ + print_header + remove_ui + while true; do + echo -e "${cyan}" + read -p "Perform action: " action; echo + echo -e "${default}" + case "$action" in + 1) + clear + print_header + remove_klipper + print_msg && clear_msg + remove_ui;; + 2) + clear + print_header + remove_moonraker + print_msg && clear_msg + remove_ui;; + 3) + clear + print_header + remove_dwc2 + print_msg && clear_msg + remove_ui;; + 4) + clear + print_header + remove_mainsail + print_msg && clear_msg + remove_ui;; + 5) + clear + print_header + remove_octoprint + print_msg && clear_msg + remove_ui;; + 6) + clear + print_header + remove_nginx + print_msg && clear_msg + remove_ui;; + Q|q) + clear; main_menu; break;; + *) + clear + print_header + print_unkown_cmd + print_msg && clear_msg + remove_ui;; + esac + done + remove_menu +} diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh new file mode 100755 index 0000000..928311e --- /dev/null +++ b/scripts/ui/update_menu.sh @@ -0,0 +1,87 @@ +update_ui(){ + top_border + echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${default} | " + hr + echo -e "| It is a good idea to check the following website | " + echo -e "| for important software changes to the config file | " + echo -e "| >> BEFORE << updating your klipper installation: | " + echo -e "| | " + echo -e "| ${yellow}https://www.klipper3d.org/Config_Changes.html${default} | " + bottom_border + top_border + echo -e "| 0) $BB4U_STATUS| " + hr + echo -e "| | Local Vers: | Remote Vers: | " + echo -e "| Firmware: | | | " + echo -e "| 1) [Klipper] | $(echo "$LOCAL_COMMIT") | $(echo "$REMOTE_COMMIT") | " + echo -e "| | | | " + echo -e "| Webinterface: |---------------|--------------| " + echo -e "| 2) [DWC2-for-Klipper] | $(echo "$LOCAL_DWC2FK_COMMIT") | $(echo "$REMOTE_DWC2FK_COMMIT") | " + echo -e "| 3) [DWC2 Web UI] | $(echo "$DWC2_LOCAL_VER") | $(echo "$DWC2_REMOTE_VER") | " + echo -e "| |---------------|--------------| " + echo -e "| 4) [Moonraker] | $(echo "$LOCAL_MOONRAKER_COMMIT") | $(echo "$REMOTE_MOONRAKER_COMMIT") | " + echo -e "| 5) [Mainsail] | $(echo "$MAINSAIL_LOCAL_VER") | $(echo "$MAINSAIL_REMOTE_VER") | " + quit_footer +} + +update_menu(){ + print_header + #compare versions + ui_print_versions + print_msg && clear_msg + read_bb4u_stat + update_ui + while true; do + echo -e "${cyan}" + read -p "Perform action: " action; echo + echo -e "${default}" + case "$action" in + 0) + clear + print_header + toggle_backups + print_msg && clear_msg + update_ui;; + 1) + clear + print_header + update_klipper && ui_print_versions + print_msg && clear_msg + update_ui;; + 2) + clear + print_header + update_dwc2fk && ui_print_versions + print_msg && clear_msg + update_ui;; + 3) + clear + print_header + update_dwc2 && ui_print_versions + print_msg && clear_msg + update_ui;; + 4) + clear + print_header + update_moonraker && ui_print_versions + print_msg && clear_msg + update_ui;; + 5) + clear + print_header + update_mainsail && ui_print_versions + print_msg && clear_msg + update_ui;; + Q|q) + clear; main_menu; break;; + *) + clear + print_header + print_unkown_cmd + print_msg && clear_msg + ui_print_versions + update_ui;; + esac + done + update_menu +} From 5a25bd3686319912613621681a4d052d535ba9f4 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Sun, 23 Aug 2020 21:52:18 +0200 Subject: [PATCH 28/31] fix: remove old read branch function --- scripts/status.sh | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/scripts/status.sh b/scripts/status.sh index 6f226cd..a96c79c 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -111,21 +111,6 @@ octoprint_status(){ fi } -#read_branch(){ -# if [ -d $KLIPPER_DIR ] && [ -d $KLIPPER_DIR/.git ]; then -# cd $KLIPPER_DIR -# GET_BRANCH=$(git branch -a | head -1 | cut -d " " -f5 | cut -d ")" -f1) -# #if reading the branch gives an empty string -# #we are on non-detached HEAD state on origin/master -# #and need to set GET_BRANCH to make a non-empty string -# if [ -z "$GET_BRANCH" ]; then -# GET_BRANCH="origin/master" -# fi -# else -# GET_BRANCH="" -# fi -#} - #reading the log for the last branch that got checked out assuming that this is also the currently active branch. read_branch(){ if [ -d $KLIPPER_DIR/.git ]; then From 1b4baad654d7c68480d1439c08df96a28f2273d2 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Mon, 24 Aug 2020 11:48:57 +0200 Subject: [PATCH 29/31] fix: status message --- scripts/backup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index beced5d..2906e1c 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -1,6 +1,6 @@ check_for_backup_dir(){ if [ ! -d $BACKUP_DIR ]; then - status_msg "Create backup directory ..." + status_msg "Create KIAUH backup directory ..." mkdir -p $BACKUP_DIR && ok_msg "Directory created!" fi } From d51062c5aeab4936eb9cd42cc712770588e95801 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Wed, 26 Aug 2020 08:18:18 +0200 Subject: [PATCH 30/31] fix: use new method to locate printer.cfg, rework depending functions --- kiauh.sh | 1 - scripts/functions.sh | 16 ++++- scripts/install_dwc2.sh | 85 ++++++++++++++------------ scripts/install_mainsail.sh | 16 ++--- scripts/install_moonraker.sh | 113 ++++++++++++++++++++++------------- scripts/remove.sh | 14 ++--- 6 files changed, 146 insertions(+), 99 deletions(-) diff --git a/kiauh.sh b/kiauh.sh index f25bfeb..200b427 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -34,7 +34,6 @@ OCTOPRINT_SERVICE2=/etc/default/octoprint #misc INI_FILE=${HOME}/kiauh/kiauh.ini BACKUP_DIR=${HOME}/kiauh-backups -PRINTER_CFG=${HOME}/printer.cfg ### set github repos KLIPPER_REPO=https://github.com/KevinOConnor/klipper.git diff --git a/scripts/functions.sh b/scripts/functions.sh index 7919aa3..713e332 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -11,6 +11,20 @@ check_euid(){ fi } +locate_printer_cfg(){ + if [ -f $KLIPPER_SERVICE2 ]; then + #reads /etc/default/klipper and gets the default printer.cfg location + PRINTER_CFG_LOC=$(grep "KLIPPY_ARGS=" /etc/default/klipper | cut -d" " -f2) + if [ -e $PRINTER_CFG_LOC ]; then + PRINTER_CFG=$(readlink -e $PRINTER_CFG_LOC) + else + PRINTER_CFG="" + fi + else + PRINTER_CFG="" + fi +} + source_ini(){ source ${HOME}/kiauh/kiauh.ini } @@ -316,4 +330,4 @@ remove_branding(){ N|n|No|no) break;; esac done -} \ No newline at end of file +} diff --git a/scripts/install_dwc2.sh b/scripts/install_dwc2.sh index fcc1080..dd1e07c 100755 --- a/scripts/install_dwc2.sh +++ b/scripts/install_dwc2.sh @@ -4,9 +4,7 @@ install_dwc2(){ #ask user for customization get_user_selections_dwc2 #dwc2 main installation - check_for_folder_dwc2 tornado_setup - dwc2fk_setup dwc2_setup #setup config write_printer_cfg_dwc2 @@ -25,10 +23,11 @@ install_dwc2(){ system_check_dwc2(){ status_msg "Initializing DWC2 installation ..." stop_klipper + check_for_folder_dwc2 #check for existing printer.cfg - if [ -e ${HOME}/printer.cfg ]; then + locate_printer_cfg + if [ ! -z $PRINTER_CFG ]; then PRINTER_CFG_FOUND="true" - PRINTER_CFG_LOC="${HOME}/printer.cfg" else PRINTER_CFG_FOUND="false" fi @@ -59,8 +58,8 @@ get_user_selections_dwc2(){ echo -e "| option or error will prevent DWC2 from loading and |" echo -e "| you need to check klippy.log to resolve the error. |" echo -e "| |" - echo -e "| Neither option 1 or 2 of this script will create a |" - echo -e "| fully working printer.cfg for you! |" + echo -e "| ${red}Neither option 1 or 2 of this script will create a |" + echo -e "| fully working printer.cfg for you!${default} |" hr echo -e "| 1) [Create default configuration] |" echo -e "| 2) [Create custom configuration] |" @@ -142,32 +141,40 @@ tornado_setup(){ fi } -dwc2fk_setup(){ +dwc2_setup(){ + #check dependencies + dep=(git wget gzip tar curl) + dependency_check + #get dwc2-for-klipper cd ${HOME} status_msg "Cloning DWC2-for-Klipper repository ..." - git clone $DWC2FK_REPO && ok_msg "DWC2-for-Klipper successfully cloned!" + git clone $DWC2FK_REPO + ok_msg "DWC2-for-Klipper successfully cloned!" #create a web_dwc2.py symlink if not already existing if [ -d $KLIPPER_DIR/klippy/extras ] && [ ! -e $KLIPPER_DIR/klippy/extras/web_dwc2.py ]; then status_msg "Creating web_dwc2.py Symlink ..." - ln -s $DWC2FK_DIR/web_dwc2.py $KLIPPER_DIR/klippy/extras/web_dwc2.py && ok_msg "Symlink created!" + ln -s $DWC2FK_DIR/web_dwc2.py $KLIPPER_DIR/klippy/extras/web_dwc2.py + ok_msg "Symlink created!" fi -} - -dwc2_setup(){ - #check dependencies - dep=(wget gzip tar curl) - dependency_check - #execute operation + #get Duet Web Control GET_DWC2_URL=`curl -s https://api.github.com/repositories/28820678/releases/latest | grep browser_download_url | cut -d'"' -f4` cd $DWC2_DIR/web status_msg "Downloading DWC2 Web UI ..." - wget -q $GET_DWC2_URL && ok_msg "Download complete!" + wget -q $GET_DWC2_URL + ok_msg "Download complete!" status_msg "Unzipping archive ..." - unzip -q -o *.zip && for f_ in $(find . | grep '.gz');do gunzip -f ${f_};done && ok_msg "Done!" - status_msg "Writing version to file ..." - echo $GET_DWC2_URL | cut -d/ -f8 > $DWC2_DIR/web/version && ok_msg "Done!" + unzip -q -o *.zip + for f_ in $(find . | grep '.gz') + do + gunzip -f ${f_} + done + ok_msg "Done!" + status_msg "Writing DWC version to file ..." + echo $GET_DWC2_URL | cut -d/ -f8 > $DWC2_DIR/web/version + ok_msg "Done!" status_msg "Do a little cleanup ..." - rm -rf DuetWebControl-SD.zip && ok_msg "Done!" + rm -rf DuetWebControl-SD.zip + ok_msg "Done!" ok_msg "DWC2 Web UI installed!" } @@ -182,27 +189,31 @@ setup_printer_config_dwc2(){ fi if [ "$SEL_DEF_CFG" = "true" ]; then create_default_dwc2_printer_cfg + locate_printer_cfg fi if [ "$SEL_CUS_CFG" = "true" ]; then #get user input for custom config create_custom_dwc2_printer_cfg + locate_printer_cfg fi } read_printer_cfg_dwc2(){ unset SC_ENTRY SC="#*# <---------------------- SAVE_CONFIG ---------------------->" - if [ ! $(grep '^\[virtual_sdcard\]$' ${HOME}/printer.cfg) ]; then + if [ ! $(grep '^\[virtual_sdcard\]$' $PRINTER_CFG) ]; then VSD="false" fi - if [ ! $(grep '^\[web_dwc2\]$' ${HOME}/printer.cfg) ]; then + if [ ! $(grep '^\[web_dwc2\]$' $PRINTER_CFG) ]; then WEB_DWC2="false" fi #check for a SAVE_CONFIG entry - if [[ $(grep "$SC" ${HOME}/printer.cfg) ]]; then - SC_LINE=$(grep -n "$SC" ${HOME}/printer.cfg | cut -d ":" -f1) + 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 } @@ -224,30 +235,32 @@ write_printer_cfg_dwc2(){ PRE_SC_LINE="$(expr $SC_LINE - 1)a" for entry in "${write_entries[@]}" do - sed -i "$PRE_SC_LINE $entry" ${HOME}/printer.cfg + sed -i "$PRE_SC_LINE $entry" $PRINTER_CFG done fi if [ "$SC_ENTRY" = "false" ]; then - LINE_COUNT="$(wc -l < ${HOME}/printer.cfg)a" + LINE_COUNT="$(wc -l < $PRINTER_CFG)a" for entry in "${write_entries[@]}" do - sed -i "$LINE_COUNT $entry" ${HOME}/printer.cfg + sed -i "$LINE_COUNT $entry" $PRINTER_CFG done fi ok_msg "Done!" } write_custom_printer_cfg_dwc2(){ - if [ "$CONFIRM_CUSTOM_CFG" = "true" ]; then - echo -e "$DWC2_CFG" >> ${HOME}/printer.cfg + #create custom config + if [ "$PRINTER_CFG_FOUND" = "false" ] && [ "$CONFIRM_CUSTOM_CFG" = "true" ]; then + touch $PRINTER_CFG + echo -e "$DWC2_CFG" >> $PRINTER_CFG fi } create_default_dwc2_printer_cfg(){ -#create default config -touch ${HOME}/printer.cfg -cat <> ${HOME}/printer.cfg - + #create default config + if [ "$PRINTER_CFG_FOUND" = "false" ] && [ "$SEL_CUS_CFG" = "true" ]; then + touch $PRINTER_CFG + cat <> $PRINTER_CFG ########################## ### CREATED WITH KIAUH ### ########################## @@ -267,8 +280,8 @@ listen_adress: 0.0.0.0 listen_port: 4750 web_path: dwc2/web ########################## -########################## DEFAULT_DWC2_CFG + fi } ############################################################# @@ -288,7 +301,6 @@ create_custom_dwc2_printer_cfg(){ read -e -p "Web path: " -i "dwc2/web" WEB_PATH echo -e "${default}" DWC2_CFG=$(cat < Yes" + SEL_KLIPPYLOG_SL="true";; + N|n|No|no) + echo -e "###### > No" + SEL_KLIPPYLOG_SL="false";; + esac + break + done + fi + #user selection for moonraker.log symlink if [ "$MOONRAKER_SL_FOUND" = "false" ]; then while true; do echo @@ -142,10 +167,10 @@ get_user_selections_moonraker(){ case "$yn" in Y|y|Yes|yes|"") echo -e "###### > Yes" - ADD_MAINSAIL_MACROS="true";; + ADD_MS_MCAROS="true";; N|n|No|no) echo -e "###### > No" - ADD_MAINSAIL_MACROS="false";; + ADD_MS_MCAROS="false";; esac break done @@ -211,17 +236,14 @@ check_for_folder_moonraker(){ setup_printer_config_mainsail(){ if [ "$PRINTER_CFG_FOUND" = "true" ]; then backup_printer_cfg - if [ "$PRINTER_CFG_LOC" != "${HOME}/klipper_config/printer.cfg" ]; then - status_msg "Moving printer.cfg to ~/klipper_config ..." - mv $PRINTER_CFG_LOC ${HOME}/klipper_config + #create a printer.cfg symlink to make it accessible + #in the mainsail config editor if the printer.cfg is not + #located in klipper_config by default + if [ "$PRINTER_CFG" != "${HOME}/klipper_config/printer.cfg" ] && [ ! -f ${HOME}/klipper_config/printer.cfg ]; then + status_msg "Create printer.cfg symlink ..." + ln -s $PRINTER_CFG ${HOME}/klipper_config ok_msg "Done!" fi - status_msg "Create symlink in home directory ..." - if [ -f ${HOME}/printer.cfg ]; then - mv ${HOME}/printer.cfg ${HOME}/printer_old.cfg - fi - ln -s ${HOME}/klipper_config/printer.cfg ${HOME} - ok_msg "Done!" #check printer.cfg for necessary mainsail entries read_printer_cfg_mainsail write_printer_cfg_mainsail @@ -233,7 +255,7 @@ setup_printer_config_mainsail(){ ok_msg "Done!" fi #copy mainsail_macro.cfg - if [ "$ADD_MAINSAIL_MACROS" = "true" ]; then + if [ "$ADD_MS_MCAROS" = "true" ]; then status_msg "Create mainsail_macros.cfg ..." if [ ! -f ${HOME}/klipper_config/mainsail_macros.cfg ]; then cp ${HOME}/kiauh/resources/mainsail_macros.cfg ${HOME}/klipper_config @@ -246,26 +268,31 @@ setup_printer_config_mainsail(){ read_printer_cfg_mainsail(){ SC="#*# <---------------------- SAVE_CONFIG ---------------------->" - if [ ! $(grep '^\[virtual_sdcard\]$' ${HOME}/klipper_config/printer.cfg) ]; then + if [ ! $(grep '^\[virtual_sdcard\]$' $PRINTER_CFG) ]; then VSD="false" fi - if [ ! $(grep '^\[pause_resume\]$' ${HOME}/klipper_config/printer.cfg) ]; then + if [ ! $(grep '^\[pause_resume\]$' $PRINTER_CFG) ]; then PAUSE_RESUME="false" fi - if [ ! $(grep '^\[display_status\]$' ${HOME}/klipper_config/printer.cfg) ]; then + if [ ! $(grep '^\[display_status\]$' $PRINTER_CFG) ]; then DISPLAY_STATUS="false" fi + if [ ! "$(grep '^\[include klipper_config\/mainsail_macros\.cfg\]$' $PRINTER_CFG)" ]; then + MS_MACRO="false" + fi #check for a SAVE_CONFIG entry - if [[ $(grep "$SC" ${HOME}/klipper_config/printer.cfg) ]]; then - SC_LINE=$(grep -n "$SC" ${HOME}/klipper_config/printer.cfg | cut -d ":" -f1) + 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 } write_printer_cfg_mainsail(){ unset write_entries - if [ "$ADD_MAINSAIL_MACROS" = "true" ]; then + if [ "$MS_MACRO" = "false" ] && [ "$ADD_MS_MCAROS" = "true" ]; then write_entries+=("[include klipper_config/mainsail_macros.cfg]") fi if [ "$PAUSE_RESUME" = "false" ]; then @@ -287,14 +314,14 @@ write_printer_cfg_mainsail(){ PRE_SC_LINE="$(expr $SC_LINE - 1)a" for entry in "${write_entries[@]}" do - sed -i "$PRE_SC_LINE $entry" ${HOME}/klipper_config/printer.cfg + sed -i "$PRE_SC_LINE $entry" $PRINTER_CFG done fi if [ "$SC_ENTRY" = "false" ]; then - LINE_COUNT="$(wc -l < ${HOME}/klipper_config/printer.cfg)a" + LINE_COUNT="$(wc -l < $PRINTER_CFG)a" for entry in "${write_entries[@]}" do - sed -i "$LINE_COUNT $entry" ${HOME}/klipper_config/printer.cfg + sed -i "$LINE_COUNT $entry" $PRINTER_CFG done fi ok_msg "Done!" @@ -358,7 +385,7 @@ write_default_trusted_clients(){ #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 ${cyan}$DEFAULT_IP_RANGE${default} written to moonraker.conf!" + ok_msg "IP range of ● $DEFAULT_IP_RANGE written to moonraker.conf!" } ############################################################# @@ -431,11 +458,17 @@ write_custom_trusted_clients(){ fi } -symlink_moonraker_log(){ - #create a moonraker.log symlink in klipper_config-dir just for convenience - if [ "$SEL_MRLOG_SL" = "true" ]; then +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/moonraker.log + ln -s /tmp/moonraker.log ${HOME}/klipper_config ok_msg "Symlink created!" fi } @@ -454,4 +487,4 @@ test_api(){ else echo; warn_msg "Klipper API not working correctly!"; echo fi -} \ No newline at end of file +} diff --git a/scripts/remove.sh b/scripts/remove.sh index 50392b9..6f9a9f4 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -67,6 +67,7 @@ remove_moonraker(){ ${HOME}/moonraker.conf ${HOME}/moonraker.log ${HOME}/klipper_config/moonraker.log + ${HOME}/klipper_config/klippy.log ${HOME}/.klippy_api_key ${HOME}/.moonraker_api_key ) @@ -89,17 +90,10 @@ remove_moonraker(){ status_msg "Removing moonraker.conf ..." rm -rf ${HOME}/moonraker.conf && ok_msg "File removed!" fi - #remove printer.cfg symlink, copy printer.cfg back into home dir - if [ -L ${HOME}/printer.cfg ]; then - status_msg "Removing printer.cfg symlink ..." - rm -rf ${HOME}/printer.cfg && ok_msg "Symlink removed!" - status_msg "Copy printer.cfg back into '${HOME}' ..." - cp ${HOME}/klipper_config/printer.cfg ${HOME} && ok_msg "File copied!" - fi #remove moonraker.log and symlink - if [[ -L ${HOME}/moonraker.log || -L ${HOME}/klipper_config/moonraker.log || -e /tmp/moonraker.log ]]; then - status_msg "Removing moonraker.log and Symlink ..." - rm -rf ${HOME}/moonraker.log ${HOME}/klipper_config/moonraker.log /tmp/moonraker.log + 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 legacy api key From dba14aadb6dec7b9fe788966e3291bed173147a6 Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Wed, 26 Aug 2020 08:18:59 +0200 Subject: [PATCH 31/31] new function: install shell command extension by Arksine --- docs/Shell Command Extension.md | 46 ++++++++++++++++++ resources/shell_command.py | 83 +++++++++++++++++++++++++++++++++ scripts/functions.sh | 73 +++++++++++++++++++++++++++++ 3 files changed, 202 insertions(+) create mode 100644 docs/Shell Command Extension.md create mode 100755 resources/shell_command.py diff --git a/docs/Shell Command Extension.md b/docs/Shell Command Extension.md new file mode 100644 index 0000000..b3d7bbd --- /dev/null +++ b/docs/Shell Command Extension.md @@ -0,0 +1,46 @@ +# Shell Command Extension + +### Creator of this extension is [Arksine](https://github.com/Arksine). + +This is a brief explanation of how to use the shell command extension for Klipper, which you can install with KIAUH. + +After installing the extension you can execute linux commands or even scripts from within Klipper with custom commands defined in your printer.cfg. + +#### How to configure a shell command: + +```shell +# Runs a linux command or script from within klipper. Note that sudo commands +# that require password authentication are disallowed. All executable scripts +# should include a shebang. +# [shell_command my_shell_cmd] +#command: +# The linux shell command/script to be executed. This parameter must be +# provided +#timeout: 2. +# The timeout in seconds until the command is forcably terminated. Default +# is 2 seconds. +#verbose: True +# If enabled, the command's output will be forwarded to the terminal. Its +# recommended to set this to false for commands that my run in quick +# succession. Default is True. +``` + +Once you have set up a shell command with the given parameters from above in your printer.cfg you can run the command as follows: +`RUN_SHELL_COMMAND CMD=name` + +Example: + +``` +[shell_command hello_world] +command: echo hello world +timeout: 2. +verbose: True +``` + +Execute with: +`RUN_SHELL_COMMAND CMD=hello_world` + +## Warning + +This extension may have a high potential for abuse if not used carefully! Also, depending on the command you execute, high system loads may occur and can cause system instabilities. +Use this extension at your own risk and only if you know what you are doing! diff --git a/resources/shell_command.py b/resources/shell_command.py new file mode 100755 index 0000000..4138172 --- /dev/null +++ b/resources/shell_command.py @@ -0,0 +1,83 @@ +# Run a shell command via gcode +# +# Copyright (C) 2019 Eric Callahan +# +# This file may be distributed under the terms of the GNU GPLv3 license. +import os +import shlex +import subprocess +import logging + +class ShellCommand: + def __init__(self, config): + self.name = config.get_name().split()[-1] + self.printer = config.get_printer() + self.gcode = self.printer.lookup_object('gcode') + cmd = config.get('command') + cmd = os.path.expanduser(cmd) + self.command = shlex.split(cmd) + self.timeout = config.getfloat('timeout', 2., above=0.) + self.verbose = config.getboolean('verbose', True) + self.proc_fd = None + self.partial_output = "" + self.gcode.register_mux_command( + "RUN_SHELL_COMMAND", "CMD", self.name, + self.cmd_RUN_SHELL_COMMAND, + desc=self.cmd_RUN_SHELL_COMMAND_help) + + def _process_output(self, eventime): + if self.proc_fd is None: + return + try: + data = os.read(self.proc_fd, 4096) + except Exception: + pass + data = self.partial_output + data + if '\n' not in data: + self.partial_output = data + return + elif data[-1] != '\n': + split = data.rfind('\n') + 1 + self.partial_output = data[split:] + data = data[:split] + self.gcode.respond_info(data) + + cmd_RUN_SHELL_COMMAND_help = "Run a linux shell command" + def cmd_RUN_SHELL_COMMAND(self, params): + reactor = self.printer.get_reactor() + try: + proc = subprocess.Popen( + self.command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + except Exception: + logging.exception( + "shell_command: Command {%s} failed" % (self.name)) + raise self.gcode.error("Error running command {%s}" % (self.name)) + if self.verbose: + self.proc_fd = proc.stdout.fileno() + self.gcode.respond_info("Running Command {%s}...:" % (self.name)) + hdl = reactor.register_fd(self.proc_fd, self._process_output) + eventtime = reactor.monotonic() + endtime = eventtime + self.timeout + complete = False + while eventtime < endtime: + eventtime = reactor.pause(eventtime + .05) + if proc.poll() is not None: + complete = True + break + if not complete: + proc.terminate() + if self.verbose: + if self.partial_output: + self.gcode.respond_info(self.partial_output) + self.partial_output = "" + if complete: + msg = "Command {%s} finished\n" % (self.name) + else: + msg = "Command {%s} timed out" % (self.name) + self.gcode.respond_info(msg) + reactor.unregister_fd(hdl) + self.proc_fd = None + + +def load_config_prefix(config): + return ShellCommand(config) diff --git a/scripts/functions.sh b/scripts/functions.sh index 713e332..f21f922 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -331,3 +331,76 @@ remove_branding(){ esac done } + +install_extension_shell_command(){ + echo + top_border + echo -e "| You are about to install the shell command extension. |" + echo -e "| Please make sure to read the instructions before you |" + echo -e "| continue and remember that there are potential risks! |" + bottom_border + while true; do + read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn + case "$yn" in + Y|y|Yes|yes|"") + if [ -d $KLIPPER_DIR/klippy/extras ] && [ ! -f $KLIPPER_DIR/klippy/extras/shell_command.py ] ; then + status_msg "Installing shell command extension ..." + stop_klipper + cp ${HOME}/kiauh/resources/shell_command.py $KLIPPER_DIR/klippy/extras + status_msg "Creating example macro ..." + create_shell_command_example + ok_msg "Example macro created!" + ok_msg "Shell command extension installed!" + restart_klipper + else + if [ ! -d $KLIPPER_DIR/klippy/extras ]; then + ERROR_MSG="Folder ~/klipper/klippy/extras not found!" + fi + if [ -f $KLIPPER_DIR/klippy/extras/shell_command.py ]; then + ERROR_MSG="Extension already installed!" + fi + fi + break;; + N|n|No|no) + break;; + esac + done +} + +create_shell_command_example(){ + unset SC_ENTRY + unset write_entries + #check for a SAVE_CONFIG entry + SC="#*# <---------------------- SAVE_CONFIG ---------------------->" + if [[ $(grep "$SC" ${HOME}/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 + #example shell command + write_entries+=("[shell_command hello_world]\ncommand: echo hello world\ntimeout: 2.\nverbose: True") + #example macro + write_entries+=("[gcode_macro HELLO_WORLD]\ngcode:\n RUN_SHELL_COMMAND CMD=hello_world") + if [ "${#write_entries[@]}" != "0" ]; then + write_entries+=("\\\n############################\n##### CREATED BY KIAUH #####\n############################") + write_entries=("############################\n" "${write_entries[@]}") + fi + #execute writing + status_msg "Writing 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 +} \ No newline at end of file