script: read webui ports from nginx config, write them to kiauh.ini

This commit is contained in:
th33xitus
2021-09-27 22:52:52 +02:00
parent 2a46b00cda
commit fc4fe130cd
3 changed files with 31 additions and 0 deletions

View File

@@ -457,4 +457,5 @@ init_ini(){
if [ ! $(grep -E "^klipper_cfg_loc=" $INI_FILE) ]; then
echo -e "\nklipper_cfg_loc=\c" >> $INI_FILE
fi
fetch_webui_ports
}

View File

@@ -112,6 +112,8 @@ install_webui(){
### install mjpg-streamer
[ "$INSTALL_MJPG" = "true" ] && install_mjpg-streamer
fetch_webui_ports #WIP
### confirm message
CONFIRM_MSG="$IF_NAME1 has been set up!"
print_msg && clear_msg
@@ -327,4 +329,20 @@ fluidd_setup(){
### delete downloaded zip
status_msg "Remove downloaded archive ..."
rm -rf *.zip && ok_msg "Done!"
}
fetch_webui_ports(){
### read listen ports from possible installed interfaces
### and write them to ~/.kiauh.ini
WEBIFS=(mainsail fluidd octoprint dwc2)
for interface in "${WEBIFS[@]}"; do
if [ -f "/etc/nginx/sites-enabled/${interface}" ]; then
if [ ! -n "$(grep -E "${interface}_port" $INI_FILE)" ]; then
port=$(grep -E "listen" /etc/nginx/sites-available/$interface | sed -e 's/^[[:space:]]*//' | sed -e 's/;$//' | cut -d" " -f2)
sed -i '$a'"${interface}_port=${port}" $INI_FILE
fi
else
sed -i "/^${interface}_port/d" $INI_FILE
fi
done
}

View File

@@ -240,6 +240,9 @@ remove_dwc2(){
rm -rf $DWC2_DIR && ok_msg "Directory removed!"
fi
### remove dwc2_port from ~/.kiauh.ini
sed -i "/^dwc2_port=/d" $INI_FILE
CONFIRM_MSG=" DWC2-for-Klipper-Socket was successfully removed!"
}
@@ -273,6 +276,9 @@ remove_mainsail(){
rm -f $log
done
### remove mainsail_port from ~/.kiauh.ini
sed -i "/^mainsail_port=/d" $INI_FILE
CONFIRM_MSG="Mainsail successfully removed!"
}
@@ -303,6 +309,9 @@ remove_fluidd(){
rm -f $log
done
### remove fluidd_port from ~/.kiauh.ini
sed -i "/^fluidd_port=/d" $INI_FILE
CONFIRM_MSG="Fluidd successfully removed!"
}
@@ -345,6 +354,9 @@ remove_octoprint(){
done
fi
### remove octoprint_port from ~/.kiauh.ini
sed -i "/^octoprint_port=/d" $INI_FILE
CONFIRM_MSG=" OctoPrint successfully removed!"
}