feature: initial commit to add installer for Fluidd + rewrite nginx related stuff

This commit is contained in:
th33xitus
2020-10-06 15:03:54 +02:00
parent 9a4ca4114c
commit fe941f4227
18 changed files with 592 additions and 134 deletions

View File

@@ -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

View File

@@ -0,0 +1,6 @@
# /etc/nginx/conf.d/common_vars.conf
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

View File

@@ -0,0 +1,77 @@
# /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;
#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/;
}
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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
@@ -191,7 +191,7 @@ download_dwc2_webui(){
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
wget -O $GET_DWC2_URL
ok_msg "Download complete!"
status_msg "Unzipping archive ..."
unzip -q -o *.zip
@@ -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,10 +305,9 @@ 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
@@ -317,3 +315,43 @@ dwc2_reverse_proxy_dialog(){
esac
done
}
dwc2_port_check(){
if [ "$DWC2_ENABLED" = "false" ]; then
if [ "$SITE_ENABLED" = "true" ]; then
echo "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"
fi
if [ "$PORT_80_BLOCKED" = "true" ]; then
[ "$OCTOPRINT_PORT" = "80" ] && echo "${cyan}OctoPrint${default} already listens on Port 80!"
[ "$MAINSAIL_PORT" = "80" ] && echo "${cyan}Mainsail${default} already listens on Port 80!"
[ "$FLUIDD_PORT" = "80" ] && echo "${cyan}Fluidd${default} already listens on Port 80!"
echo "You need to choose a different Port for DWC2 than the above!"
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(){
while true; do
read -p "${cyan}Please enter a new Port:${default} " NEW_PORT
if [ "$NEW_PORT" != "$MAINSAIL_PORT" ] && [ "$NEW_PORT" != "$OCTOPRINT_PORT" ] && [ "$NEW_PORT" != "$FLUIDD_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
}

75
scripts/install_fluidd.sh Executable file
View File

@@ -0,0 +1,75 @@
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
echo "Detected other enabled Interfaces:"
[ "$MAINSAIL_ENABLED" = "true" ] && echo "${cyan}● Mainsail - Port:$MAINSAIL_PORT${default}"
[ "$DWC2_ENABLED" = "true" ] && echo "${cyan}● DWC2 - Port:$DWC2_PORT${default}"
[ "$OCTOPRINT_ENABLED" = "true" ] && echo "${cyan}● OctoPrint - Port:$OCTOPRINT_PORT${default}"
if [ "$MAINSAIL_PORT" = "80" ] || [ "$DWC2_PORT" = "80" ] || [ "$OCTOPRINT_PORT" = "80" ]; then
PORT_80_BLOCKED="true"
fi
if [ "$PORT_80_BLOCKED" = "true" ]; then
[ "$MAINSAIL_PORT" = "80" ] && echo "${cyan}Mainsail${default} already listens on Port 80!"
[ "$DWC2_PORT" = "80" ] && echo "${cyan}DWC2${default} already listens on Port 80!"
[ "$OCTOPRINT_PORT" = "80" ] && echo "${cyan}OctoPrint${default} already listens on Port 80!"
echo "You need to choose a different Port for Fluidd than the above!"
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(){
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 Mainsail!"
SET_LISTEN_PORT=$NEW_PORT
break
else
echo "That port is already taken! Select a different one!"
fi
done
}
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
}

View File

@@ -1,25 +1,54 @@
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
else
echo; warn_msg "Nginx is not working correctly!"; echo
mainsail_port_check(){
if [ "$MAINSAIL_ENABLED" = "false" ]; then
if [ "$SITE_ENABLED" = "true" ]; then
echo "Detected other enabled Interfaces:"
[ "$FLUIDD_ENABLED" = "true" ] && echo "${cyan}● Fluidd - Port:$FLUIDD_PORT${default}"
[ "$DWC2_ENABLED" = "true" ] && echo "${cyan}● DWC2 - Port:$DWC2_PORT${default}"
[ "$OCTOPRINT_ENABLED" = "true" ] && echo "${cyan}● OctoPrint - Port:$OCTOPRINT_PORT${default}"
if [ "$FLUIDD_PORT" = "80" ] || [ "$DWC2_PORT" = "80" ] || [ "$OCTOPRINT_PORT" = "80" ]; then
PORT_80_BLOCKED="true"
fi
if [ "$PORT_80_BLOCKED" = "true" ]; then
[ "$FLUIDD_PORT" = "80" ] && echo "${cyan}Fluidd${default} already listens on Port 80!"
[ "$DWC2_PORT" = "80" ] && echo "${cyan}DWC2${default} already listens on Port 80!"
[ "$OCTOPRINT_PORT" = "80" ] && echo "${cyan}OctoPrint${default} already listens on Port 80!"
echo "You need to choose a different Port for Mainsail than the above!"
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
SET_NGINX_CFG="false"
fi
}
select_mainsail_port(){
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
}
get_mainsail_ver(){
@@ -28,20 +57,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

View File

@@ -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
}
#############################################################
#############################################################
@@ -661,3 +681,17 @@ test_api(){
echo; warn_msg "Klipper API not working correctly!"; 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
# else
# echo; warn_msg "Nginx is not working correctly!"; echo
# fi
#}

View File

@@ -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,46 @@ octoprint_reverse_proxy_dialog(){
done
}
octoprint_port_check(){
if [ "$OCTOPRINT_ENABLED" = "false" ]; then
if [ "$SITE_ENABLED" = "true" ]; then
echo "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"
fi
if [ "$PORT_80_BLOCKED" = "true" ]; then
[ "$MAINSAIL_PORT" = "80" ] && echo "${cyan}Mainsail${default} already listens on Port 80!"
[ "$FLUIDD_PORT" = "80" ] && echo "${cyan}Fluidd${default} already listens on Port 80!"
[ "$DWC2_PORT" = "80" ] && echo "${cyan}DWC2${default} already listens on Port 80!"
echo "You need to choose a different Port for OctoPrint than the above!"
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(){
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" != "$FLUIDD_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
}
create_config_yaml(){
if [ ! -d $OCTOPRINT_CFG_DIR ]; then
status_msg "Creating config.yaml ..."

View File

@@ -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
#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

View File

@@ -86,6 +86,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 +141,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 +190,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
}
#############################################################
#############################################################

View File

@@ -258,6 +258,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 +326,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 +375,5 @@ ui_print_versions(){
compare_dwc2_versions
compare_moonraker_versions
compare_mainsail_versions
compare_fluidd_versions
}

View File

@@ -7,6 +7,10 @@ bottom_border(){
echo -e "\=======================================================/"
}
blank_line(){
echo -e "| | "
}
hr(){
echo -e "|-------------------------------------------------------|"
}
@@ -29,7 +33,7 @@ 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} | "
echo -e "| | "
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

View File

@@ -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

View File

@@ -32,6 +32,7 @@ main_menu(){
read -p "Perform action: " action; echo
echo -e "${default}"
case "$action" in
8) read_listen_port;;
update)
clear
print_header

View File

@@ -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

View File

@@ -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
}