diff --git a/README.md b/README.md index 9f7b556..16ef0bd 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,24 @@ # KIAUH - Klipper Installation And Update Helper -### ( This script is always work in progress! ) - ![main_menu](https://github.com/th33xitus/kiauh/blob/master/resources/screenshots/main.png) --- -## Disclaimer: Usage of this script happens at your own risk! - -This script is "only" a helping hand for you to get set up in a fast and most comfortable way. - -**This does not mean, it will relieve you of using brain.exe!** +## 📢 Disclaimer: Usage of this script happens at your own risk! +This script is "only" a helping hand for you to get set up in a fast and most comfortable way.\ +**This does not mean, it will relieve you of using brain.exe! 🧠**\ Feel free to give it a try if you want. If you have suggestions or encounter any problems, please report them. --- -## Instructions: +## 🛠️ Instructions: -For downloading this script it is best to have git already installed. -If you haven't, please run `sudo apt-get install git -y` to install git first. You will need it anyways! +For downloading this script it is best to have git already installed.\ +If you haven't, please run `sudo apt-get install git -y` to install git first.\ +You will need it anyways! -After git is installed, use the following commands in the given order to download and execute the script. +After git is installed, use the following commands in the given order to download and execute the script: ```shell cd ~ @@ -31,23 +28,21 @@ chmod +x kiauh.sh scripts/* ./kiauh.sh ``` -## Additional Instructions: +### Additional Instructions: -If you need some more detailed instructions on how to install Klipper and Mainsail with KIAUH, check out this website: - -[Installing Klipper and Mainsail](https://3dp.tumbleweedlabs.com/firmware/klipper-firmware/installing-klipper-and-mainsail-on-your-raspberry-pi) - -Credits for these instructions go to [@tumbleweedlabs](https://github.com/tumbleweedlabs). +If you need some more detailed instructions on how to install Klipper and Mainsail with KIAUH, check out this website:\ +[Installing Klipper and Mainsail](https://3dp.tumbleweedlabs.com/firmware/klipper-firmware/installing-klipper-and-mainsail-on-your-raspberry-pi)\ +Credits for these instructions go to [@tumbleweedlabs](https://github.com/tumbleweedlabs).\ Feel free to check out his work. --- -## Functions and Features: +## 🧰 Functions and Features: ### Core Functions: - **Installing** of the Klipper Firmware to your Raspberry Pi or other Linux Distribution which makes use of init.d. -- **Installing** of several different web interfaces such as Duet Web Control, Mainsail or OctoPrint including their dependencies. +- **Installing** of several different web interfaces such as Duet Web Control, Mainsail, Fluidd or OctoPrint including their dependencies. - **Installing** of the Moonraker API - **Updating** of all the listed installations above excluding OctoPrint. For updating OctoPrint, please use the OctoPrint interface! - **Removing** of all the listed installations above. @@ -65,7 +60,7 @@ For a list of additional features and their descriptions please see: --- -## Notes: +## 📝 Notes: - Important changes to the script will be listed in the [Changelog](https://github.com/th33xitus/kiauh/blob/master/docs/changelog.md) - Tested only on Raspbian Buster Lite @@ -75,41 +70,63 @@ For a list of additional features and their descriptions please see: --- -### For more information or instructions, please check out the appropriate repositories listed below: +## 🛈 Sources & Further Information -Klipper by [KevinOConnor](https://github.com/KevinOConnor) : - -- https://github.com/KevinOConnor/klipper - -Klipper S-Curve fork by [dmbutyugin](https://github.com/dmbutyugin) : - -- https://github.com/dmbutyugin/klipper/tree/scurve-smoothing -- https://github.com/dmbutyugin/klipper/tree/scurve-shaping - -Moonraker by [Arksine](https://github.com/Arksine) : - -- https://github.com/Arksine/moonraker - -Mainsail Webinterface by [meteyou](https://github.com/meteyou) : - -- https://github.com/meteyou/mainsail - -Duet Web Control by [Duet3D](https://github.com/Duet3D) : - -- https://github.com/Duet3D/DuetWebControl - -DWC2-for-Klipper-Socket by [Stephan3](https://github.com/Stephan3) : - -- https://github.com/Stephan3/dwc2-for-klipper-socket - -OctoPrint Webinterface by [OctoPrint](https://github.com/OctoPrint) : - -- https://octoprint.org -- https://github.com/OctoPrint/OctoPrint +For more information or instructions, please check out the appropriate repositories listed below: --- -## Q&A +**⛵Klipper** by [KevinOConnor](https://github.com/KevinOConnor) : + +https://github.com/KevinOConnor/klipper + +--- + +**⛵Klipper S-Curve fork** by [dmbutyugin](https://github.com/dmbutyugin) : + +https://github.com/dmbutyugin/klipper/tree/scurve-smoothing\ +https://github.com/dmbutyugin/klipper/tree/scurve-shaping + +--- + +**🌙Moonraker** by [Arksine](https://github.com/Arksine) : + +https://github.com/Arksine/moonraker + +--- + +**💨Mainsail Webinterface** by [meteyou](https://github.com/meteyou) : + +https://github.com/meteyou/mainsail + +--- + +**🌊Fluidd Webinterface** by [cadriel](https://github.com/cadriel) : + +https://github.com/cadriel/fluidd + +--- + +**🕸️Duet Web Control** by [Duet3D](https://github.com/Duet3D) : + +https://github.com/Duet3D/DuetWebControl + +--- + +**🕸️DWC2-for-Klipper-Socket** by [Stephan3](https://github.com/Stephan3) : + +https://github.com/Stephan3/dwc2-for-klipper-socket + +--- + +**🐙OctoPrint Webinterface** by [OctoPrint](https://github.com/OctoPrint) : + +https://octoprint.org\ +https://github.com/OctoPrint/OctoPrint + +--- + +## ❓ FAQ **_Q: Can i use this script to install multiple instancec of Klipper on the same Pi? (Multisession?)_** diff --git a/kiauh.sh b/kiauh.sh index ccc9bc9..194f157 100755 --- a/kiauh.sh +++ b/kiauh.sh @@ -4,11 +4,11 @@ set -e ### set some variables ERROR_MSG="" -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") +green=$(echo -en "\e[92m") +yellow=$(echo -en "\e[93m") +red=$(echo -en "\e[91m") +cyan=$(echo -en "\e[96m") +default=$(echo -en "\e[97m") ### set important directories #klipper @@ -16,16 +16,23 @@ KLIPPER_DIR=${HOME}/klipper KLIPPY_ENV_DIR=${HOME}/klippy-env KLIPPER_SERVICE1=/etc/init.d/klipper KLIPPER_SERVICE2=/etc/default/klipper -#dwc2 -DWC2FK_DIR=${HOME}/dwc2-for-klipper-socket -DWC_ENV_DIR=${HOME}/dwc-env -DWC2_DIR=${HOME}/sdcard/web -#mainsail/moonraker -MAINSAIL_DIR=${HOME}/mainsail +#nginx +NGINX_SA=/etc/nginx/sites-available +NGINX_SE=/etc/nginx/sites-enabled +NGINX_CONFD=/etc/nginx/conf.d +#moonraker MOONRAKER_DIR=${HOME}/moonraker MOONRAKER_ENV_DIR=${HOME}/moonraker-env MOONRAKER_SERVICE1=/etc/init.d/moonraker MOONRAKER_SERVICE2=/etc/default/moonraker +#mainsail +MAINSAIL_DIR=${HOME}/mainsail +#fluidd +FLUIDD_DIR=${HOME}/fluidd +#dwc2 +DWC2FK_DIR=${HOME}/dwc2-for-klipper-socket +DWC_ENV_DIR=${HOME}/dwc-env +DWC2_DIR=${HOME}/sdcard/web #octoprint OCTOPRINT_DIR=${HOME}/OctoPrint OCTOPRINT_CFG_DIR=${HOME}/.octoprint diff --git a/resources/common_vars_nginx.cfg b/resources/common_vars_nginx.cfg new file mode 100644 index 0000000..9c3f85e --- /dev/null +++ b/resources/common_vars_nginx.cfg @@ -0,0 +1,6 @@ +# /etc/nginx/conf.d/common_vars.conf + +map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} \ No newline at end of file diff --git a/resources/fluidd_nginx.cfg b/resources/fluidd_nginx.cfg new file mode 100644 index 0000000..36adf37 --- /dev/null +++ b/resources/fluidd_nginx.cfg @@ -0,0 +1,87 @@ +# /etc/nginx/sites-available/fluidd + +server { + listen 80; + listen [::]:80; + + access_log /var/log/nginx/fluidd-access.log; + error_log /var/log/nginx/fluidd-error.log; + + #disable this section on smaller hardware like a pi zero + gzip on; + gzip_vary on; + gzip_proxied any; + gzip_proxied expired no-cache no-store private auth; + gzip_comp_level 4; + gzip_buffers 16 8k; + gzip_http_version 1.1; + gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/json application/xml; + + #web_path from fluidd static files + root /home/pi/fluidd; + + index index.html; + server_name _; + + #max upload size for gcodes + client_max_body_size 200M; + + location / { + try_files $uri $uri/ /index.html; + } + + location /printer { + proxy_pass http://apiserver/printer; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Scheme $scheme; + } + + location /api { + proxy_pass http://apiserver/api; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Scheme $scheme; + } + + location /access { + proxy_pass http://apiserver/access; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Scheme $scheme; + } + + location /websocket { + proxy_pass http://apiserver/websocket; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_read_timeout 86400; + } + + location /machine { + proxy_pass http://apiserver/machine; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Scheme $scheme; + } + + location /server { + proxy_pass http://apiserver/server; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Scheme $scheme; + } + + location /webcam/ { + proxy_pass http://mjpgstreamer/; + } +} \ No newline at end of file diff --git a/resources/mainsail_nginx.cfg b/resources/mainsail_nginx.cfg index 8d54ca3..4a3e93f 100644 --- a/resources/mainsail_nginx.cfg +++ b/resources/mainsail_nginx.cfg @@ -1,19 +1,4 @@ -map $http_upgrade $connection_upgrade { - default upgrade; - '' close; -} - -upstream apiserver { - #edit your api port here - ip_hash; - server 127.0.0.1:7125; -} - -upstream mjpgstreamer { - #edit your webcam port here - ip_hash; - server 127.0.0.1:8081; -} +# /etc/nginx/sites-available/mainsail server { listen 80; @@ -22,6 +7,16 @@ server { access_log /var/log/nginx/mainsail-access.log; error_log /var/log/nginx/mainsail-error.log; + #disable this section on smaller hardware like a pi zero + gzip on; + gzip_vary on; + gzip_proxied any; + gzip_proxied expired no-cache no-store private auth; + gzip_comp_level 4; + gzip_buffers 16 8k; + gzip_http_version 1.1; + gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/json application/xml; + #web_path from mainsail static files root /home/pi/mainsail; diff --git a/resources/moonraker_nginx.cfg b/resources/moonraker_nginx.cfg new file mode 100644 index 0000000..c868181 --- /dev/null +++ b/resources/moonraker_nginx.cfg @@ -0,0 +1,13 @@ +# /etc/nginx/conf.d/upstreams.conf + +upstream apiserver { + #edit your api port here + ip_hash; + server 127.0.0.1:7125; +} + +upstream mjpgstreamer { + #edit your webcam port here + ip_hash; + server 127.0.0.1:8081; +} \ No newline at end of file diff --git a/resources/screenshots/advanced.png b/resources/screenshots/advanced.png deleted file mode 100644 index a63d7fc..0000000 Binary files a/resources/screenshots/advanced.png and /dev/null differ diff --git a/resources/screenshots/main.png b/resources/screenshots/main.png index 993b06c..ac71eb7 100644 Binary files a/resources/screenshots/main.png and b/resources/screenshots/main.png differ diff --git a/resources/screenshots/remove.png b/resources/screenshots/remove.png deleted file mode 100644 index cf1f665..0000000 Binary files a/resources/screenshots/remove.png and /dev/null differ diff --git a/resources/screenshots/update.png b/resources/screenshots/update.png deleted file mode 100644 index 7ef3767..0000000 Binary files a/resources/screenshots/update.png and /dev/null differ diff --git a/scripts/install_dwc2.sh b/scripts/install_dwc2.sh index 789a4d4..17e299d 100755 --- a/scripts/install_dwc2.sh +++ b/scripts/install_dwc2.sh @@ -1,6 +1,9 @@ install_dwc2(){ if [ -d $KLIPPER_DIR ]; then system_check_dwc2 + #check for other enabled web interfaces + unset SET_LISTEN_PORT + detect_enabled_sites #ask user for customization get_user_selections_dwc2 #dwc2 main installation @@ -10,7 +13,7 @@ install_dwc2(){ write_printer_cfg_dwc2 #execute customizations disable_octoprint - create_reverse_proxy "dwc2" + set_nginx_cfg "dwc2" set_hostname #after install actions restart_klipper @@ -31,7 +34,6 @@ system_check_dwc2(){ fi #check if octoprint is installed if systemctl is-enabled octoprint.service -q 2>/dev/null; then - unset OCTOPRINT_ENABLED OCTOPRINT_ENABLED="true" fi } @@ -104,9 +106,7 @@ get_user_selections_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 + [ "$SET_NGINX_CFG" = "true" ] && create_custom_hostname #ask user to disable octoprint when such installed service was found if [ "$OCTOPRINT_ENABLED" = "true" ]; then unset DISABLE_OPRINT @@ -188,7 +188,7 @@ patch_klipper_sysfile_dwc2(){ download_dwc2_webui(){ #get Duet Web Control - GET_DWC2_URL=`curl -s https://api.github.com/repositories/28820678/releases/latest | grep browser_download_url | cut -d'"' -f4` + GET_DWC2_URL=$(curl -s https://api.github.com/repositories/28820678/releases/latest | grep browser_download_url | cut -d'"' -f4) cd $DWC2_DIR status_msg "Downloading DWC2 Web UI ..." wget $GET_DWC2_URL @@ -295,7 +295,6 @@ DEFAULT_DWC2_CFG ############################################################# 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 | " @@ -306,14 +305,65 @@ dwc2_reverse_proxy_dialog(){ read -p "${cyan}###### Do you want to set up a reverse proxy now? (y/N):${default} " yn case "$yn" in Y|y|Yes|yes) - SET_REVERSE_PROXY="true" + dwc2_port_check break;; N|n|No|no|"") - SET_REVERSE_PROXY="false" break;; *) print_unkown_cmd print_msg && clear_msg;; esac done +} + +dwc2_port_check(){ + if [ "$DWC2_ENABLED" = "false" ]; then + if [ "$SITE_ENABLED" = "true" ]; then + status_msg "Detected other enabled interfaces:" + [ "$OCTOPRINT_ENABLED" = "true" ] && echo " ${cyan}● OctoPrint - Port:$OCTOPRINT_PORT${default}" + [ "$MAINSAIL_ENABLED" = "true" ] && echo " ${cyan}● Mainsail - Port:$MAINSAIL_PORT${default}" + [ "$FLUIDD_ENABLED" = "true" ] && echo " ${cyan}● Fluidd - Port:$FLUIDD_PORT${default}" + if [ "$MAINSAIL_PORT" = "80" ] || [ "$OCTOPRINT_PORT" = "80" ] || [ "$FLUIDD_PORT" = "80" ]; then + PORT_80_BLOCKED="true" + select_dwc2_port + fi + else + DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/dwc2_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) + SET_LISTEN_PORT=$DEFAULT_PORT + fi + SET_NGINX_CFG="true" + else + SET_NGINX_CFG="false" + fi +} + +select_dwc2_port(){ + if [ "$PORT_80_BLOCKED" = "true" ]; then + echo + top_border + echo -e "| ${red}!!!WARNING!!!${default} |" + echo -e "| ${red}You need to choose a different port for DWC2!${default} |" + echo -e "| ${red}The following web interface is listening at port 80:${default} |" + blank_line + [ "$OCTOPRINT_PORT" = "80" ] && echo "| ● OctoPrint |" + [ "$MAINSAIL_PORT" = "80" ] && echo "| ● Mainsail |" + [ "$FLUIDD_PORT" = "80" ] && echo "| ● Fluidd |" + blank_line + echo -e "| Make sure you don't choose a port which was already |" + echo -e "| assigned to one of the other web interfaces! |" + blank_line + echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |" + echo -e "| input. So make sure to choose a valid port! |" + bottom_border + while true; do + read -p "${cyan}Please enter a new Port:${default} " NEW_PORT + if [ "$NEW_PORT" != "$MAINSAIL_PORT" ] && [ "$NEW_PORT" != "$FLUIDD_PORT" ] && [ "$NEW_PORT" != "$OCTOPRINT_PORT" ]; then + echo "Setting port $NEW_PORT for DWC2!" + SET_LISTEN_PORT=$NEW_PORT + break + else + echo "That port is already taken! Select a different one!" + fi + done + fi } \ No newline at end of file diff --git a/scripts/install_fluidd.sh b/scripts/install_fluidd.sh new file mode 100755 index 0000000..5df8e08 --- /dev/null +++ b/scripts/install_fluidd.sh @@ -0,0 +1,87 @@ +install_fluidd(){ + if [ "$INST_FLUIDD" = "true" ]; then + unset SET_LISTEN_PORT + #check for other enabled web interfaces + detect_enabled_sites + #check if another site already listens to port 80 + fluidd_port_check + #creating the fluidd nginx cfg + set_nginx_cfg "fluidd" + fluidd_setup && ok_msg "Fluidd installation complete!"; echo + fi +} + +fluidd_port_check(){ + if [ "$FLUIDD_ENABLED" = "false" ]; then + if [ "$SITE_ENABLED" = "true" ]; then + status_msg "Detected other enabled interfaces:" + [ "$OCTOPRINT_ENABLED" = "true" ] && echo " ${cyan}● OctoPrint - Port: $OCTOPRINT_PORT${default}" + [ "$MAINSAIL_ENABLED" = "true" ] && echo " ${cyan}● Mainsail - Port: $MAINSAIL_PORT${default}" + [ "$DWC2_ENABLED" = "true" ] && echo " ${cyan}● DWC2 - Port: $DWC2_PORT${default}" + if [ "$MAINSAIL_PORT" = "80" ] || [ "$DWC2_PORT" = "80" ] || [ "$OCTOPRINT_PORT" = "80" ]; then + PORT_80_BLOCKED="true" + select_fluidd_port + fi + else + DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/fluidd_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) + SET_LISTEN_PORT=$DEFAULT_PORT + fi + SET_NGINX_CFG="true" + else + SET_NGINX_CFG="false" + fi +} + +select_fluidd_port(){ + if [ "$PORT_80_BLOCKED" = "true" ]; then + echo + top_border + echo -e "| ${red}!!!WARNING!!!${default} |" + echo -e "| ${red}You need to choose a different port for Fluidd!${default} |" + echo -e "| ${red}The following web interface is listening at port 80:${default} |" + blank_line + [ "$OCTOPRINT_PORT" = "80" ] && echo "| ● OctoPrint |" + [ "$MAINSAIL_PORT" = "80" ] && echo "| ● Mainsail |" + [ "$DWC2_PORT" = "80" ] && echo "| ● DWC2 |" + blank_line + echo -e "| Make sure you don't choose a port which was already |" + echo -e "| assigned to one of the other web interfaces! |" + blank_line + echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |" + echo -e "| input. So make sure to choose a valid port! |" + bottom_border + while true; do + read -p "${cyan}Please enter a new Port:${default} " NEW_PORT + if [ "$NEW_PORT" != "$MAINSAIL_PORT" ] && [ "$NEW_PORT" != "$DWC2_PORT" ] && [ "$NEW_PORT" != "$OCTOPRINT_PORT" ]; then + echo "Setting port $NEW_PORT for Fluidd!" + SET_LISTEN_PORT=$NEW_PORT + break + else + echo "That port is already taken! Select a different one!" + fi + done + fi +} + +get_fluidd_ver(){ + FLUIDD_VERSION=$(curl -s https://api.github.com/repositories/295836951/tags | grep name | cut -d'"' -f4 | cut -d"v" -f2 | head -1) +} + +fluidd_dl_url(){ + get_fluidd_ver + FLUIDD_URL=https://github.com/cadriel/fluidd/releases/download/v$FLUIDD_VERSION/fluidd_v$FLUIDD_VERSION.zip +} + +fluidd_setup(){ + fluidd_dl_url + #clean up an existing fluidd folder + [ -d $FLUIDD_DIR ] && rm -rf $FLUIDD_DIR + #create fresh fluidd folder and download fluidd + mkdir $FLUIDD_DIR + cd $FLUIDD_DIR + status_msg "Downloading Fluidd $FLUIDD_VERSION ..." + wget -O fluidd.zip $FLUIDD_URL && status_msg "Extracting archive ..." && unzip -o fluidd.zip && rm fluidd.zip + ### write fluidd version to file for update check reasons + echo "$FLUIDD_VERSION" > $FLUIDD_DIR/version + echo +} \ No newline at end of file diff --git a/scripts/install_mainsail.sh b/scripts/install_mainsail.sh index 537995f..a65ba1e 100755 --- a/scripts/install_mainsail.sh +++ b/scripts/install_mainsail.sh @@ -1,24 +1,65 @@ install_mainsail(){ if [ "$INST_MAINSAIL" = "true" ]; then - 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 - ok_msg "Mainsail installation complete!"; echo + unset SET_LISTEN_PORT + #check for other enabled web interfaces + detect_enabled_sites + #check if another site already listens to port 80 + mainsail_port_check + #creating the mainsail nginx cfg + set_nginx_cfg "mainsail" + mainsail_setup && ok_msg "Mainsail installation complete!"; echo fi } -test_nginx(){ - HOST_IP=$(hostname -I | cut -d" " -f1) - status_msg "Testing Nginx ..." - sleep 5 - 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://$HOST_IP/printer/info" | grep '^{"result"' -c) -eq 1 ]; then - echo; ok_msg "Nginx is working correctly!"; echo +mainsail_port_check(){ + if [ "$MAINSAIL_ENABLED" = "false" ]; then + if [ "$SITE_ENABLED" = "true" ]; then + status_msg "Detected other enabled interfaces:" + [ "$OCTOPRINT_ENABLED" = "true" ] && echo -e " ${cyan}● OctoPrint - Port: $OCTOPRINT_PORT${default}" + [ "$FLUIDD_ENABLED" = "true" ] && echo -e " ${cyan}● Fluidd - Port: $FLUIDD_PORT${default}" + [ "$DWC2_ENABLED" = "true" ] && echo -e " ${cyan}● DWC2 - Port: $DWC2_PORT${default}" + if [ "$FLUIDD_PORT" = "80" ] || [ "$DWC2_PORT" = "80" ] || [ "$OCTOPRINT_PORT" = "80" ]; then + PORT_80_BLOCKED="true" + select_mainsail_port + fi + else + DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/mainsail_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) + SET_LISTEN_PORT=$DEFAULT_PORT + fi + SET_NGINX_CFG="true" else - echo; warn_msg "Nginx is not working correctly!"; echo + SET_NGINX_CFG="false" + fi +} + +select_mainsail_port(){ + if [ "$PORT_80_BLOCKED" = "true" ]; then + echo + top_border + echo -e "| ${red}!!!WARNING!!!${default} |" + echo -e "| ${red}You need to choose a different port for Mainsail!${default} |" + echo -e "| ${red}The following web interface is listening at port 80:${default} |" + blank_line + [ "$OCTOPRINT_PORT" = "80" ] && echo "| ● OctoPrint |" + [ "$FLUIDD_PORT" = "80" ] && echo "| ● Fluidd |" + [ "$DWC2_PORT" = "80" ] && echo "| ● DWC2 |" + blank_line + echo -e "| Make sure you don't choose a port which was already |" + echo -e "| assigned to one of the other web interfaces! |" + blank_line + echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |" + echo -e "| input. So make sure to choose a valid port! |" + bottom_border + while true; do + read -p "${cyan}Please enter a new Port:${default} " NEW_PORT + if [ "$NEW_PORT" != "$FLUIDD_PORT" ] && [ "$NEW_PORT" != "$DWC2_PORT" ] && [ "$NEW_PORT" != "$OCTOPRINT_PORT" ]; then + echo "Setting port $NEW_PORT for Mainsail!" + SET_LISTEN_PORT=$NEW_PORT + break + else + echo "That port is already taken! Select a different one!" + fi + done fi } @@ -28,20 +69,17 @@ get_mainsail_ver(){ mainsail_dl_url(){ get_mainsail_ver - MAINSAIL_URL=https://github.com/meteyou/mainsail/releases/download/v"$MAINSAIL_VERSION"/mainsail-beta-"$MAINSAIL_VERSION".zip + MAINSAIL_URL=https://github.com/meteyou/mainsail/releases/download/v$MAINSAIL_VERSION/mainsail-beta-$MAINSAIL_VERSION.zip } mainsail_setup(){ mainsail_dl_url #clean up an existing mainsail folder - if [ -d $MAINSAIL_DIR ]; then - rm -rf $MAINSAIL_DIR - fi + [ -d $MAINSAIL_DIR ] && rm -rf $MAINSAIL_DIR #create fresh mainsail folder and download mainsail - mkdir $MAINSAIL_DIR - cd $MAINSAIL_DIR + mkdir $MAINSAIL_DIR && cd $MAINSAIL_DIR status_msg "Downloading Mainsail v$MAINSAIL_VERSION ..." - wget -q -O mainsail.zip $MAINSAIL_URL && status_msg "Extracting archive ..." && unzip -o mainsail.zip && rm mainsail.zip + wget -O mainsail.zip $MAINSAIL_URL && status_msg "Extracting archive ..." && unzip -o mainsail.zip && rm mainsail.zip ### write mainsail version to file for update check reasons echo "$MAINSAIL_VERSION" > $MAINSAIL_DIR/version echo diff --git a/scripts/install_moonraker.sh b/scripts/install_moonraker.sh index bc54555..8296e7d 100755 --- a/scripts/install_moonraker.sh +++ b/scripts/install_moonraker.sh @@ -19,7 +19,9 @@ install_moonraker(){ restart_moonraker restart_klipper test_api - install_mainsail + #test_nginx + #install_mainsail + #install_fluidd } system_check_moonraker(){ @@ -67,35 +69,42 @@ system_check_moonraker(){ 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" - break;; - N|n|No|no) - echo -e "###### > No" - INST_MAINSAIL="false" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done - #ask to change hostname if mainsail should be installed as well - if [ "$INST_MAINSAIL" = "true" ]; then - create_custom_hostname - fi + #while true; do + # echo + # top_border + # echo -e "| Install the Moonraker API only? |" + # blank_line + # echo -e "| You can choose to install Moonraker and one of the |" + # echo -e "| following web interfaces: |" + # echo -e "| 1) Mainsail |" + # echo -e "| 2) Fluidd |" + # hr + # echo -e "| If you want to install a web interface later, just |" + # echo -e "| press 'ENTER' to continue the Moonraker installation. |" + # bottom_border + # read -p "${cyan}Please choose:${default} " selection + # case "$selection" in + # "") + # echo -e "###### > Moonraker only" + # INST_NOUI="true" + # break;; + # 1) + # echo -e "###### > Moonraker + Mainsail" + # INST_MAINSAIL="true" + # break;; + # 2) + # echo -e "###### > Moonraker + Fluidd" + # INST_FLUIDD="true" + # break;; + # *) + # print_unkown_cmd + # print_msg && clear_msg;; + # esac + #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 unset SEL_DEF_CFG @@ -252,7 +261,7 @@ get_user_selections_moonraker(){ echo -e "| |" echo -e "| 1) Remove packages (recommend) |" echo -e "| 2) Disable only (may cause issues) |" - echo -e "| ${red}3) Skip this step (not recommend)${default} |" + echo -e "| ${red}3) Skip this step (not recommended)${default} |" bottom_border read -p "${cyan}###### Please choose:${default} " action unset REMOVE_HAPROXY @@ -312,6 +321,8 @@ moonraker_setup(){ ok_msg "Download complete!" status_msg "Installing Moonraker ..." $MOONRAKER_DIR/scripts/install-moonraker.sh + #copy moonraker configuration for nginx to /etc/nginx/conf.d + setup_moonraker_nginx_cfg #backup a possible existing printer.cfg at the old location #and before patching in the new location backup_printer_cfg @@ -480,6 +491,15 @@ setup_moonraker_conf(){ fi } +setup_moonraker_nginx_cfg(){ + if [ ! -f $NGINX_CONFD/upstreams.conf ]; then + sudo cp ${SRCDIR}/kiauh/resources/moonraker_nginx.cfg $NGINX_CONFD/upstreams.conf + fi + if [ ! -f $NGINX_CONFD/common_vars.conf ]; then + sudo cp ${SRCDIR}/kiauh/resources/common_vars_nginx.cfg $NGINX_CONFD/common_vars.conf + fi +} + ############################################################# ############################################################# @@ -651,13 +671,22 @@ handle_haproxy_lighttpd(){ test_api(){ HOST_IP=$(hostname -I | cut -d" " -f1) status_msg "Testing API ..." - sleep 5 - 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://$HOST_IP:7125/printer/info" | grep '^{"result"' -c) -eq 1 ]; then + status_msg "Please wait ..." + sleep 15 + status_msg "API response from http://"$HOST_IP":7125/printer/info :" + echo -e "${cyan}$(curl -s "http://"$HOST_IP":7125/printer/info")${default}" + if [ $(curl -s "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 fi -} + status_msg "Testing Nginx ..." + status_msg "Please wait ..." + status_msg "API response from http://"$HOST_IP"/printer/info :" + echo -e "${cyan}$(curl -s "http://"$HOST_IP"/printer/info")${default}" + if [ $(curl -s "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 + fi +} \ No newline at end of file diff --git a/scripts/install_octoprint.sh b/scripts/install_octoprint.sh index 0df8495..273a129 100755 --- a/scripts/install_octoprint.sh +++ b/scripts/install_octoprint.sh @@ -1,4 +1,7 @@ install_octoprint(){ + #check for other enabled web interfaces + unset SET_LISTEN_PORT + detect_enabled_sites #ask user for customization get_user_selections_octoprint #octoprint main installation @@ -9,7 +12,7 @@ install_octoprint(){ add_reboot_permission create_config_yaml #execute customizations - create_reverse_proxy "octoprint" + set_nginx_cfg "octoprint" set_hostname #after install actions load_octoprint_server @@ -20,9 +23,7 @@ get_user_selections_octoprint(){ #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 + [ "$SET_NGINX_CFG" = "true" ] && create_custom_hostname status_msg "Installation will start now! Please wait ..." } @@ -113,7 +114,6 @@ 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 | " @@ -128,10 +128,9 @@ octoprint_reverse_proxy_dialog(){ echo -e "${default}" case "$yn" in Y|y|Yes|yes) - SET_REVERSE_PROXY="true" + octoprint_port_check break;; N|n|No|no|"") - SET_REVERSE_PROXY="false" break;; *) print_unkown_cmd @@ -140,6 +139,58 @@ octoprint_reverse_proxy_dialog(){ done } +octoprint_port_check(){ + if [ "$OCTOPRINT_ENABLED" = "false" ]; then + if [ "$SITE_ENABLED" = "true" ]; then + status_msg "Detected other enabled interfaces:" + [ "$MAINSAIL_ENABLED" = "true" ] && echo " ${cyan}● Mainsail - Port:$MAINSAIL_PORT${default}" + [ "$FLUIDD_ENABLED" = "true" ] && echo " ${cyan}● Fluidd - Port:$FLUIDD_PORT${default}" + [ "$DWC2_ENABLED" = "true" ] && echo " ${cyan}● DWC2 - Port:$DWC2_PORT${default}" + if [ "$MAINSAIL_PORT" = "80" ] || [ "$DWC2_PORT" = "80" ] || [ "$FLUIDD_PORT" = "80" ]; then + PORT_80_BLOCKED="true" + select_octoprint_port + fi + else + DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/octoprint_nginx.cfg | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) + SET_LISTEN_PORT=$DEFAULT_PORT + fi + SET_NGINX_CFG="true" + else + SET_NGINX_CFG="false" + fi +} + +select_octoprint_port(){ + if [ "$PORT_80_BLOCKED" = "true" ]; then + echo + top_border + echo -e "| ${red}!!!WARNING!!!${default} |" + echo -e "| ${red}You need to choose a different port for OctoPrint!${default} |" + echo -e "| ${red}The following web interface is listening at port 80:${default} |" + blank_line + [ "$MAINSAIL_PORT" = "80" ] && echo "| ● Mainsail |" + [ "$FLUIDD_PORT" = "80" ] && echo "| ● Fluidd |" + [ "$DWC2_PORT" = "80" ] && echo "| ● DWC2 |" + blank_line + echo -e "| Make sure you don't choose a port which was already |" + echo -e "| assigned to one of the other web interfaces! |" + blank_line + echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |" + echo -e "| input. So make sure to choose a valid port! |" + bottom_border + while true; do + read -p "${cyan}Please enter a new Port:${default} " NEW_PORT + if [ "$NEW_PORT" != "$MAINSAIL_PORT" ] && [ "$NEW_PORT" != "$FLUIDD_PORT" ] && [ "$NEW_PORT" != "$DWC2_PORT" ]; then + echo "Setting port $NEW_PORT for OctoPrint!" + SET_LISTEN_PORT=$NEW_PORT + break + else + echo "That port is already taken! Select a different one!" + fi + done + fi +} + create_config_yaml(){ if [ ! -d $OCTOPRINT_CFG_DIR ]; then status_msg "Creating config.yaml ..." diff --git a/scripts/set_reverse_proxy.sh b/scripts/network_functions.sh similarity index 58% rename from scripts/set_reverse_proxy.sh rename to scripts/network_functions.sh index f024801..4d72664 100755 --- a/scripts/set_reverse_proxy.sh +++ b/scripts/network_functions.sh @@ -1,29 +1,81 @@ -create_reverse_proxy(){ - if [ "$SET_REVERSE_PROXY" = "true" ]; then +set_nginx_cfg(){ + if [ "$SET_NGINX_CFG" = "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 + #copy content from resources to the respective nginx config file + cat ${SRCDIR}/kiauh/resources/$1_nginx.cfg > ${SRCDIR}/kiauh/resources/$1 + ##edit the nginx config file before moving it + if [ "$SET_LISTEN_PORT" != "$DEFAULT_PORT" ]; then + status_msg "Configuring port for $1 ..." + #set listen port ipv4 + sed -i "s/listen\s[0-9]*;/listen $SET_LISTEN_PORT;/" ${SRCDIR}/kiauh/resources/$1 + #set listen port ipv6 + sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:$SET_LISTEN_PORT;/" ${SRCDIR}/kiauh/resources/$1 + fi + #set correct user + if [ "$1" = "mainsail" ] || [ "$1" = "fluidd" ]; then + sudo sed -i "/root/s/pi/${USER}/" ${SRCDIR}/kiauh/resources/$1 + fi + #moving the config file into correct directory + sudo mv ${SRCDIR}/kiauh/resources/$1 /etc/nginx/sites-available/$1 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/ + if [ "$SET_LISTEN_PORT" != "" ]; then + ok_msg "$1 listening on port $SET_LISTEN_PORT!" + else + ok_msg "$1 listening on def-port $DEFAULT_PORT!" fi + #remove nginx default config + [ -e /etc/nginx/sites-enabled/default ] && sudo rm /etc/nginx/sites-enabled/default + #create symlink for own sites + [ ! -e /etc/nginx/sites-enabled/$1 ] && sudo ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled/ restart_nginx fi } +read_listen_port(){ + LISTEN_PORT=$(grep listen /etc/nginx/sites-enabled/$1 | head -1 | sed 's/^\s*//' | cut -d" " -f2 | cut -d";" -f1) +} + +detect_enabled_sites(){ + #check if there is another UI config already installed + #and reads the port they are listening on + if [ -e /etc/nginx/sites-enabled/mainsail ]; then + SITE_ENABLED="true" && MAINSAIL_ENABLED="true" + read_listen_port "mainsail" + MAINSAIL_PORT=$LISTEN_PORT + #echo "debug: Mainsail listens on port: $MAINSAIL_PORT" + else + MAINSAIL_ENABLED="false" + fi + if [ -e /etc/nginx/sites-enabled/fluidd ]; then + SITE_ENABLED="true" && FLUIDD_ENABLED="true" + read_listen_port "fluidd" + FLUIDD_PORT=$LISTEN_PORT + #echo "debug: Fluidd listens on port: $FLUIDD_PORT" + else + FLUIDD_ENABLED="false" + fi + if [ -e /etc/nginx/sites-enabled/dwc2 ]; then + SITE_ENABLED="true" && DWC2_ENABLED="true" + read_listen_port "dwc2" + DWC2_PORT=$LISTEN_PORT + #echo "debug: DWC2 listens on port: $DWC2_PORT" + else + DWC2_ENABLED="false" + fi + if [ -e /etc/nginx/sites-enabled/octoprint ]; then + SITE_ENABLED="true" && OCTOPRINT_ENABLED="true" + read_listen_port "octoprint" + OCTOPRINT_PORT=$LISTEN_PORT + #echo "debug: OctoPrint listens on port: $OCTOPRINT_PORT" + else + OCTOPRINT_ENABLED="false" + fi +} + create_custom_hostname(){ echo top_border diff --git a/scripts/remove.sh b/scripts/remove.sh index 489be4f..e91622c 100755 --- a/scripts/remove.sh +++ b/scripts/remove.sh @@ -38,6 +38,8 @@ remove_dwc2(){ $DWC2FK_DIR $DWC_ENV_DIR $DWC2_DIR + /etc/nginx/sites-available/dwc2 + /etc/nginx/sites-enabled/dwc2 ) print_error "DWC2-for-Klipper-Socket &\n DWC2 Web UI" && data_count=() if [ "$ERROR_MSG" = "" ]; then @@ -73,6 +75,16 @@ remove_dwc2(){ status_msg "Removing DWC2 directory ..." rm -rf $DWC2_DIR && ok_msg "Directory removed!" fi + #remove dwc2 config for nginx + if [ -e /etc/nginx/sites-available/dwc2 ]; then + status_msg "Removing DWC2 configuration for Nginx ..." + sudo rm /etc/nginx/sites-available/dwc2 && ok_msg "File removed!" + fi + #remove dwc2 symlink for nginx + if [ -L /etc/nginx/sites-enabled/dwc2 ]; then + status_msg "Removing DWC2 Symlink for Nginx ..." + sudo rm /etc/nginx/sites-enabled/dwc2 && ok_msg "File removed!" + fi CONFIRM_MSG=" DWC2-for-Klipper-Socket & DWC2 successfully removed!" fi } @@ -86,6 +98,8 @@ remove_moonraker(){ $MOONRAKER_SERVICE2 $MOONRAKER_DIR $MOONRAKER_ENV_DIR + $NGINX_CONFD/upstreams.conf + $NGINX_CONFD/common_vars.conf ${HOME}/moonraker.conf ${HOME}/moonraker.log ${HOME}/klipper_config/moonraker.log @@ -139,6 +153,11 @@ remove_moonraker(){ rm -rf ${HOME}/moonraker.log ${HOME}/klipper_config/moonraker.log ${HOME}/klipper_config/klippy.log /tmp/moonraker.log ok_msg "Files removed!" fi + #remove moonraker nginx config + if [[ -e $NGINX_CONFD/upstreams.conf || -e $NGINX_CONFD/common_vars.conf ]]; then + status_msg "Removing Moonraker NGINX configuration ..." + sudo rm -f $NGINX_CONFD/upstreams.conf $NGINX_CONFD/common_vars.conf && ok_msg "Moonraker NGINX configuration removed!" + fi #remove legacy api key if [ -e ${HOME}/.klippy_api_key ]; then status_msg "Removing legacy API Key ..." @@ -183,6 +202,33 @@ remove_mainsail(){ fi } +remove_fluidd(){ + data_arr=( + $fluidd_DIR + /etc/nginx/sites-available/fluidd + /etc/nginx/sites-enabled/fluidd + ) + print_error "Fluidd" && data_count=() + if [ "$ERROR_MSG" = "" ]; then + #remove fluidd dir + if [ -d $FLUIDD_DIR ]; then + status_msg "Removing Fluidd directory ..." + rm -rf $FLUIDD_DIR && ok_msg "Directory removed!" + fi + #remove fluidd config for nginx + if [ -e /etc/nginx/sites-available/fluidd ]; then + status_msg "Removing Fluidd configuration for Nginx ..." + sudo rm /etc/nginx/sites-available/fluidd && ok_msg "File removed!" + fi + #remove fluidd symlink for nginx + if [ -L /etc/nginx/sites-enabled/fluidd ]; then + status_msg "Removing Fluidd Symlink for Nginx ..." + sudo rm /etc/nginx/sites-enabled/fluidd && ok_msg "File removed!" + fi + CONFIRM_MSG="Fluidd successfully removed!" + fi +} + ############################################################# ############################################################# @@ -216,6 +262,16 @@ remove_octoprint(){ status_msg "Removing octoprint.log Symlink ..." rm -rf ${HOME}/octoprint.log && ok_msg "Symlink removed!" fi + #remove octoprint config for nginx + if [ -e /etc/nginx/sites-available/octoprint ]; then + status_msg "Removing OctoPrint configuration for Nginx ..." + sudo rm /etc/nginx/sites-available/octoprint && ok_msg "File removed!" + fi + #remove octoprint symlink for nginx + if [ -L /etc/nginx/sites-enabled/octoprint ]; then + status_msg "Removing OctoPrint Symlink for Nginx ..." + sudo rm /etc/nginx/sites-enabled/octoprint && ok_msg "File removed!" + fi CONFIRM_MSG=" OctoPrint successfully removed!" fi } diff --git a/scripts/status.sh b/scripts/status.sh index 8f79f4b..f9e3d60 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -57,15 +57,38 @@ dwc2_status(){ fi } +moonraker_status(){ + mrcount=0 + moonraker_data=( + $MOONRAKER_SERVICE1 + $MOONRAKER_SERVICE2 + $MOONRAKER_DIR + $MOONRAKER_ENV_DIR + $NGINX_CONFD/upstreams.conf + $NGINX_CONFD/common_vars.conf + ) + #count+1 for each found data-item from array + for mrd in "${moonraker_data[@]}" + do + if [ -e $mrd ]; then + mrcount=$(expr $mrcount + 1) + fi + done + if [ "$mrcount" == "${#moonraker_data[*]}" ]; then + MOONRAKER_STATUS="${green}Installed!${default} " + elif [ "$mrcount" == 0 ]; then + MOONRAKER_STATUS="${red}Not installed!${default} " + else + MOONRAKER_STATUS="${yellow}Incomplete!${default} " + fi +} + mainsail_status(){ mcount=0 mainsail_data=( - $MOONRAKER_SERVICE1 - $MOONRAKER_SERVICE2 $MAINSAIL_DIR - $MOONRAKER_ENV_DIR - /etc/nginx/sites-available/mainsail - /etc/nginx/sites-enabled/mainsail + $NGINX_SA/mainsail + $NGINX_SE/mainsail ) #count+1 for each found data-item from array for md in "${mainsail_data[@]}" @@ -83,6 +106,29 @@ mainsail_status(){ fi } +fluidd_status(){ + fcount=0 + fluidd_data=( + $FLUIDD_DIR + $NGINX_SA/fluidd + $NGINX_SE/fluidd + ) + #count+1 for each found data-item from array + for fd in "${fluidd_data[@]}" + do + if [ -e $fd ]; then + fcount=$(expr $fcount + 1) + fi + done + if [ "$fcount" == "${#fluidd_data[*]}" ]; then + FLUIDD_STATUS="${green}Installed!${default} " + elif [ "$fcount" == 0 ]; then + FLUIDD_STATUS="${red}Not installed!${default} " + else + FLUIDD_STATUS="${yellow}Incomplete!${default} " + fi +} + octoprint_status(){ ocount=0 octoprint_data=( @@ -258,6 +304,35 @@ compare_dwc2_versions(){ ############################################################# ############################################################# +read_moonraker_versions(){ + if [ -d $MOONRAKER_DIR ] && [ -d $MOONRAKER_DIR/.git ]; then + cd $MOONRAKER_DIR + git fetch origin master -q + LOCAL_MOONRAKER_COMMIT=$(git rev-parse --short=8 HEAD) + REMOTE_MOONRAKER_COMMIT=$(git rev-parse --short=8 origin/master) + else + LOCAL_MOONRAKER_COMMIT="${red}--------${default}" + REMOTE_MOONRAKER_COMMIT="${red}--------${default}" + fi +} + +compare_moonraker_versions(){ + unset MOONRAKER_UPDATE_AVAIL + read_moonraker_versions + #echo "Local: $LOCAL_MOONRAKER_COMMIT" + #echo "Remote: $REMOTE_MOONRAKER_COMMIT" + if [ "$LOCAL_MOONRAKER_COMMIT" != "$REMOTE_MOONRAKER_COMMIT" ]; then + LOCAL_MOONRAKER_COMMIT="${yellow}$LOCAL_MOONRAKER_COMMIT${default}" + REMOTE_MOONRAKER_COMMIT="${green}$REMOTE_MOONRAKER_COMMIT${default}" + MOONRAKER_UPDATE_AVAIL="true" + update_arr+=(update_moonraker) + else + LOCAL_MOONRAKER_COMMIT="${green}$LOCAL_MOONRAKER_COMMIT${default}" + REMOTE_MOONRAKER_COMMIT="${green}$REMOTE_MOONRAKER_COMMIT${default}" + MOONRAKER_UPDATE_AVAIL="false" + fi +} + read_local_mainsail_version(){ unset MAINSAIL_IS_INSTALLED if [ -e $MAINSAIL_DIR/version ]; then @@ -297,35 +372,48 @@ compare_mainsail_versions(){ fi } -read_moonraker_versions(){ - if [ -d $MOONRAKER_DIR ] && [ -d $MOONRAKER_DIR/.git ]; then - cd $MOONRAKER_DIR - git fetch origin master -q - LOCAL_MOONRAKER_COMMIT=$(git rev-parse --short=8 HEAD) - REMOTE_MOONRAKER_COMMIT=$(git rev-parse --short=8 origin/master) +read_local_fluidd_version(){ + unset FLUIDD_IS_INSTALLED + if [ -e $FLUIDD_DIR/version ]; then + FLUIDD_LOCAL_VER=$(head -n 1 $FLUIDD_DIR/version) + FLUIDD_IS_INSTALLED="true" else - LOCAL_MOONRAKER_COMMIT="${red}--------${default}" - REMOTE_MOONRAKER_COMMIT="${red}--------${default}" + FLUIDD_LOCAL_VER="${red}-----${default}" + FLUIDD_IS_INSTALLED="false" fi } -compare_moonraker_versions(){ - unset MOONRAKER_UPDATE_AVAIL - read_moonraker_versions - #echo "Local: $LOCAL_MOONRAKER_COMMIT" - #echo "Remote: $REMOTE_MOONRAKER_COMMIT" - if [ "$LOCAL_MOONRAKER_COMMIT" != "$REMOTE_MOONRAKER_COMMIT" ]; then - LOCAL_MOONRAKER_COMMIT="${yellow}$LOCAL_MOONRAKER_COMMIT${default}" - REMOTE_MOONRAKER_COMMIT="${green}$REMOTE_MOONRAKER_COMMIT${default}" - MOONRAKER_UPDATE_AVAIL="true" - update_arr+=(update_moonraker) +read_remote_fluidd_version(){ + #remote checks don't work without curl installed! + if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then + FLUIDD_REMOTE_VER="${red}-----${default}" else - LOCAL_MOONRAKER_COMMIT="${green}$LOCAL_MOONRAKER_COMMIT${default}" - REMOTE_MOONRAKER_COMMIT="${green}$REMOTE_MOONRAKER_COMMIT${default}" - MOONRAKER_UPDATE_AVAIL="false" + get_fluidd_ver + FLUIDD_REMOTE_VER=$FLUIDD_VERSION fi } +compare_fluidd_versions(){ + unset FLUIDD_UPDATE_AVAIL + read_local_fluidd_version + read_remote_fluidd_version + #echo "Local: $FLUIDD_LOCAL_VER" + #echo "Remote: $FLUIDD_REMOTE_VER" + if [ "$FLUIDD_LOCAL_VER" != "$FLUIDD_REMOTE_VER" ] && [ "$FLUIDD_IS_INSTALLED" = "true" ]; then + FLUIDD_LOCAL_VER="${yellow}$FLUIDD_LOCAL_VER${default}" + FLUIDD_REMOTE_VER="${green}$FLUIDD_REMOTE_VER${default}" + FLUIDD_UPDATE_AVAIL="true" + update_arr+=(update_fluidd) + else + FLUIDD_LOCAL_VER="${green}$FLUIDD_LOCAL_VER${default}" + FLUIDD_REMOTE_VER="${green}$FLUIDD_REMOTE_VER${default}" + FLUIDD_UPDATE_AVAIL="false" + fi +} + +############################################################# +############################################################# + ui_print_versions(){ unset update_arr compare_klipper_versions @@ -333,4 +421,5 @@ ui_print_versions(){ compare_dwc2_versions compare_moonraker_versions compare_mainsail_versions + compare_fluidd_versions } diff --git a/scripts/ui/general_ui.sh b/scripts/ui/general_ui.sh index 1867a44..f9aa137 100755 --- a/scripts/ui/general_ui.sh +++ b/scripts/ui/general_ui.sh @@ -7,6 +7,10 @@ bottom_border(){ echo -e "\=======================================================/" } +blank_line(){ + echo -e "| | " +} + hr(){ echo -e "|-------------------------------------------------------|" } @@ -29,5 +33,8 @@ 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} | " + blank_line + echo -e "| ${yellow}Check out the KIAUH changelog for important changes${default} | " + echo -e "| ${yellow}either to the script or the installable components!${default} | " bottom_border } diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index 8e0ec75..3b0352a 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -9,8 +9,8 @@ install_ui(){ 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 "| Klipper API: | 5) [Fluidd] | " + echo -e "| 2) [Moonraker] | 6) [Octoprint] | " quit_footer } @@ -47,6 +47,12 @@ install_menu(){ print_msg && clear_msg install_ui;; 5) + clear + print_header + INST_FLUIDD="true" && install_fluidd + print_msg && clear_msg + install_ui;; + 6) clear print_header install_octoprint diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh index 07d86c4..c3280ec 100755 --- a/scripts/ui/main_menu.sh +++ b/scripts/ui/main_menu.sh @@ -6,9 +6,12 @@ main_ui(){ 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 "| | Moonraker: $MOONRAKER_STATUS|" + echo -e "| 4) [Advanced] | |" + echo -e "| 5) [Backup] | DWC2: $DWC2_STATUS|" + echo -e "| | Fluidd: $FLUIDD_STATUS|" + echo -e "| | Mainsail: $MAINSAIL_STATUS|" + echo -e "| | Octoprint: $OCTOPRINT_STATUS|" echo -e "| | |" quit_footer } @@ -21,7 +24,9 @@ main_menu(){ fi #check install status klipper_status + moonraker_status dwc2_status + fluidd_status mainsail_status octoprint_status print_branch @@ -32,6 +37,7 @@ main_menu(){ read -p "Perform action: " action; echo echo -e "${default}" case "$action" in + 8) read_listen_port;; update) clear print_header diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh index f0692b5..efa91bb 100755 --- a/scripts/ui/remove_menu.sh +++ b/scripts/ui/remove_menu.sh @@ -11,10 +11,11 @@ remove_ui(){ 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 "| Klipper API: | 5) [Fluidd] | " + echo -e "| 2) [Moonraker] | 6) [Octoprint] | " + echo -e "| | | " echo -e "| | Webserver: | " - echo -e "| | 6) [Nginx] | " + echo -e "| | 7) [Nginx] | " quit_footer } @@ -53,10 +54,16 @@ remove_menu(){ 5) clear print_header - remove_octoprint + remove_fluidd print_msg && clear_msg remove_ui;; 6) + clear + print_header + remove_octoprint + print_msg && clear_msg + remove_ui;; + 7) clear print_header remove_nginx diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh index 9834a3b..629da4e 100755 --- a/scripts/ui/update_menu.sh +++ b/scripts/ui/update_menu.sh @@ -21,6 +21,7 @@ update_ui(){ 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") | " + echo -e "| 6) [Fluidd] | $(echo "$FLUIDD_LOCAL_VER") | $(echo "$FLUIDD_REMOTE_VER") | " quit_footer }