add octoprint reverse proxy

This commit is contained in:
th33xitus
2020-07-19 22:38:21 +02:00
parent 28d7a4aeda
commit 8ffdf12a4a
3 changed files with 86 additions and 5 deletions

View File

@@ -78,6 +78,13 @@ restart_octoprint(){
fi
}
restart_nginx(){
if [ -e /etc/init.d/nginx ]; then
status_msg "Restarting Nginx Service ..."
sudo /etc/init.d/nginx restart && sleep 2 && ok_msg "Nginx Service restarted!"
fi
}
dep_check(){
for package in "${dep[@]}"
do
@@ -261,12 +268,10 @@ create_custom_hostname(){
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 "| This option is completely optional and can also be |"
echo -e "| done at a later point in time if you are unsure. |"
echo -e "| |"
echo -e "| Example: If you set the hostname to 'my-printer' |"
echo -e "| you can open Mainsail by browsing to: |"
echo -e "| http://my-printer.local |"
echo -e "| you can open Mainsail/Octoprint by |"
echo -e "| browsing to: http://my-printer.local |"
bottom_border
while true; do
echo -e "${cyan}"
@@ -323,7 +328,7 @@ set_hostname(){
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 "You need to reboot your machine for changes to take effect!"
ok_msg "Remember to reboot your machine for the changes to take effect!"
break
else
warn_msg "'$NEW_HOSTNAME' is not a valid hostname!"

View File

@@ -6,6 +6,7 @@ octoprint_install_routine(){
add_groups
configure_autostart
add_reboot_permission
octoprint_reverse_proxy_dialog
load_server
}
@@ -108,6 +109,41 @@ add_reboot_permission(){
sleep 2
}
octoprint_reverse_proxy_dialog(){
top_border
echo -e "| If you want to have nicer URLs or simply need | "
echo -e "| OctoPrint to run on port 80 (http's default port) | "
echo -e "| due to some network restrictions, you can set up a | "
echo -e "| reverse proxy instead of configuring OctoPrint to | "
echo -e "| run on port 80. | "
bottom_border
while true; do
echo -e "${cyan}"
read -p "###### Do you want to set up a reverse proxy now? (Y/n): " yn
echo -e "${default}"
case "$yn" in
Y|y|Yes|yes|"") octoprint_reverse_proxy; break;;
N|n|No|no) break;;
esac
done
}
octoprint_reverse_proxy(){
if ! [[ $(dpkg-query -f'${Status}' --show nginx 2>/dev/null) = *\ installed ]]; then
sudo apt-get install nginx -y
fi
cat ${HOME}/kiauh/resources/octoprint_nginx.cfg > ${HOME}/kiauh/resources/octoprint
sudo mv ${HOME}/kiauh/resources/octoprint /etc/nginx/sites-available/octoprint
if [ -e /etc/nginx/sites-enabled/default ]; then
sudo rm /etc/nginx/sites-enabled/default
fi
if [ ! -e /etc/nginx/sites-enabled/octoprint ]; then
sudo ln -s /etc/nginx/sites-available/octoprint /etc/nginx/sites-enabled/
fi
restart_nginx
create_custom_hostname
}
load_server(){
start_octoprint
#create an octoprint.log symlink in home-dir just for convenience