From 1ec269969bd7ab345295b5d2dfcf7e3e3195629b Mon Sep 17 00:00:00 2001 From: th33xitus <> Date: Fri, 11 Sep 2020 11:31:53 +0200 Subject: [PATCH] fix: tweak moonraker/mainsail install process --- scripts/backup.sh | 11 +++++++++++ scripts/install_mainsail.sh | 7 ++++--- scripts/install_moonraker.sh | 35 ++++++++++++++++++----------------- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 2906e1c..8922194 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -16,6 +16,17 @@ backup_printer_cfg(){ fi } +backup_moonraker_conf(){ + check_for_backup_dir + if [ -f ${HOME}/moonraker.conf ]; then + get_date + status_msg "Create backup of moonraker.conf ..." + cp ${HOME}/moonraker.conf $BACKUP_DIR/moonraker.conf."$current_date".backup && ok_msg "Backup complete!" + else + ok_msg "No moonraker.conf found! Skipping backup ..." + fi +} + read_bb4u_stat(){ source_ini if [ ! "$backup_before_update" = "true" ]; then diff --git a/scripts/install_mainsail.sh b/scripts/install_mainsail.sh index d2b4e03..537995f 100755 --- a/scripts/install_mainsail.sh +++ b/scripts/install_mainsail.sh @@ -9,12 +9,13 @@ install_mainsail(){ } test_nginx(){ + HOST_IP=$(hostname -I | cut -d" " -f1) status_msg "Testing Nginx ..." sleep 5 - status_msg "API response from http://localhost/printer/info :" - API_RESPONSE="$(curl -sG4m5 http://localhost/printer/info)" + status_msg "API response from http://$HOST_IP/printer/info :" + API_RESPONSE="$(curl -sG4m5 http://$HOST_IP/printer/info)" echo -e "${cyan}$API_RESPONSE${default}" - if [ $(curl -sG4 "http://localhost/printer/info" | grep '^{"result"' -c) -eq 1 ]; then + if [ $(curl -sG4 "http://$HOST_IP/printer/info" | grep '^{"result"' -c) -eq 1 ]; then echo; ok_msg "Nginx is working correctly!"; echo else echo; warn_msg "Nginx is not working correctly!"; echo diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index 49c5ad4..3a9e8d4 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -432,19 +432,21 @@ setup_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 + write_default_trusted_client 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 + backup_moonraker_conf 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 + FIRST_IP=$(sed -n "$FIRST_IP_LINE"p ${HOME}/moonraker.conf | cut -d" " -f5) + #if [[ ! $FIRST_IP =~ ([0-9].[0-9].[0-9].[0-9]) ]]; then + if [ "$FIRST_IP" = "" ]; then status_msg "Writing trusted clients to config ..." - write_default_trusted_clients + write_default_trusted_client ok_msg "Trusted clients written!" fi fi @@ -474,17 +476,13 @@ path: ~/sdcard DEFAULT_CFG } -write_default_trusted_clients(){ - DEFAULT_IP=$(hostname -I) +write_default_trusted_client(){ + DEFAULT_IP=$(hostname -I | cut -d" " -f1) status_msg "Your devices current IP adress is:\n${cyan}● $DEFAULT_IP ${default}" - #make IP of the device KIAUH is exectuted on as - #default trusted client and expand the IP range from 0 - 255 - DEFAULT_IP_RANGE="$(echo "$DEFAULT_IP" | cut -d"." -f1-3).0/24" - status_msg "Writing the following IP range to moonraker.conf:\n${cyan}● $DEFAULT_IP_RANGE ${default}" - #write the ip range in the first line below "trusted clients" - #example: 192.168.1.0/24 - sed -i "/trusted_clients\:/a \ \ \ \ $DEFAULT_IP_RANGE" ${HOME}/moonraker.conf - ok_msg "IP range of ● $DEFAULT_IP_RANGE written to moonraker.conf!" + #make IP of the device KIAUH is exectuted on as default trusted client + status_msg "Writing the following IP to moonraker.conf:\n${cyan}● $DEFAULT_IP ${default}" + sed -i "/trusted_clients\:/a \ \ \ \ $DEFAULT_IP" ${HOME}/moonraker.conf + ok_msg "IP ● $DEFAULT_IP written to moonraker.conf!" } ############################################################# @@ -587,6 +585,7 @@ handle_haproxy_lighttpd(){ status_msg "Stopping haproxy service ..." sudo /etc/init.d/haproxy stop && ok_msg "Service stopped!" fi + status_msg "Removing haproxy ..." sudo apt-get remove haproxy -y sudo update-rc.d -f haproxy remove ok_msg "Haproxy removed!" @@ -606,6 +605,7 @@ handle_haproxy_lighttpd(){ status_msg "Stopping lighttpd service ..." sudo /etc/init.d/lighttpd stop && ok_msg "Service stopped!" fi + status_msg "Removing lighttpd ..." sudo apt-get remove lighttpd -y sudo update-rc.d -f lighttpd remove ok_msg "Lighttpd removed!" @@ -617,12 +617,13 @@ handle_haproxy_lighttpd(){ ############################################################# test_api(){ + HOST_IP=$(hostname -I | cut -d" " -f1) 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) + status_msg "API response from http://$HOST_IP:7125/printer/info :" + API_RESPONSE=$(curl -sG4m5 http://$HOST_IP:7125/printer/info) echo -e "${cyan}$API_RESPONSE${default}" - if [ $(curl -sG4 "http://localhost:7125/printer/info" | grep '^{"result"' -c) -eq 1 ]; then + if [ $(curl -sG4 "http://$HOST_IP: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