refactor(nginx.sh): improve handling of conflicting packages

Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
th33xitus
2022-05-27 11:52:44 +02:00
parent 64a6ba462a
commit f9d2671930
4 changed files with 76 additions and 73 deletions

View File

@@ -25,12 +25,8 @@ function install_fluidd() {
### checking dependencies ### checking dependencies
local dep=(wget nginx) local dep=(wget nginx)
dependency_check "${dep[@]}" dependency_check "${dep[@]}"
### check if moonraker is already installed ### detect conflicting Haproxy and Apache2 installations
system_check_webui detect_conflicting_packages
### ask user how to handle Haproxy, Apache2 if found
process_services_dialog
### process possible disruptive services
process_disruptive_services
status_msg "Initializing Fluidd installation ..." status_msg "Initializing Fluidd installation ..."
### first, we create a backup of the full klipper_config dir - safety first! ### first, we create a backup of the full klipper_config dir - safety first!

View File

@@ -25,12 +25,8 @@ function install_mainsail() {
### checking dependencies ### checking dependencies
local dep=(wget nginx) local dep=(wget nginx)
dependency_check "${dep[@]}" dependency_check "${dep[@]}"
### check if moonraker is already installed ### detect conflicting Haproxy and Apache2 installations
system_check_webui detect_conflicting_packages
### ask user how to handle Haproxy, Apache2 if found
process_services_dialog
### process possible disruptive services
process_disruptive_services
status_msg "Initializing Mainsail installation ..." status_msg "Initializing Mainsail installation ..."
### first, we create a backup of the full klipper_config dir - safety first! ### first, we create a backup of the full klipper_config dir - safety first!

View File

@@ -150,68 +150,93 @@ function match_nginx_configs() {
[[ ${require_service_restart} == "true" ]] && sudo systemctl restart nginx.service [[ ${require_service_restart} == "true" ]] && sudo systemctl restart nginx.service
} }
function process_disruptive_services() { function remove_conflicting_packages() {
#handle haproxy service local apache=${1} haproxy=${2}
if [[ ${DISABLE_HAPROXY} == "true" || ${REMOVE_HAPROXY} == "true" ]]; then
if systemctl is-active haproxy -q; then
status_msg "Stopping haproxy service ..."
sudo systemctl stop haproxy && ok_msg "Service stopped!"
fi
### disable haproxy ### disable services before removing them
if [[ ${DISABLE_HAPROXY} == "true" ]]; then disable_conflicting_packages "${apache}" "${haproxy}"
status_msg "Disabling haproxy ..."
sudo systemctl disable haproxy && ok_msg "Haproxy service disabled!"
### remove haproxy if [[ ${apache} == "true" ]]; then
if [[ ${REMOVE_HAPROXY} == "true" ]]; then status_msg "Removing Apache2 from system ..."
status_msg "Removing haproxy ..." if sudo apt-get remove apache2 -y && sudo update-rc.d -f apache2 remove; then
sudo apt-get remove haproxy -y && sudo update-rc.d -f haproxy remove && ok_msg "Haproxy removed!" ok_msg "Apache2 removed!"
fi else
error_msg "Removing Apache2 from system failed!"
fi fi
fi fi
### handle apache2 service if [[ ${haproxy} == "true" ]]; then
if [[ ${DISABLE_APACHE2} == "true" || ${REMOVE_APACHE2} == "true" ]]; then status_msg "Removing haproxy ..."
if systemctl is-active apache2 -q; then if sudo apt-get remove haproxy -y && sudo update-rc.d -f haproxy remove; then
status_msg "Stopping apache2 service ..." ok_msg "Haproxy removed!"
sudo systemctl stop apache2 && ok_msg "Service stopped!" else
fi error_msg "Removing Haproxy from system failed!"
### disable apache2
if [[ ${DISABLE_APACHE2} == "true" ]]; then
status_msg "Disabling apache2 service ..."
sudo systemctl disable apache2 && ok_msg "Apache2 service disabled!"
### remove apache2
if [[ ${REMOVE_APACHE2} == "true" ]]; then
status_msg "Removing apache2 ..."
sudo apt-get remove apache2 -y && sudo update-rc.d -f apache2 remove && ok_msg "Apache2 removed!"
fi
fi fi
fi fi
} }
function process_services_dialog() { function disable_conflicting_packages() {
local apache=${1} haproxy=${2}
if [[ ${apache} == "true" ]]; then
status_msg "Stopping Apache2 service ..."
if systemctl is-active apache2 -q; then
sudo systemctl stop apache2 && ok_msg "Service stopped!"
else
warn_msg "Apache2 service not active!"
fi
status_msg "Disabling Apache2 service ..."
if sudo systemctl disable apache2; then
ok_msg "Apache2 service disabled!"
else
error_msg "Disabling Apache2 service failed!"
fi
fi
if [[ ${haproxy} == "true" ]]; then
status_msg "Stopping Haproxy service ..."
if systemctl is-active haproxy -q; then
sudo systemctl stop haproxy && ok_msg "Service stopped!"
else
warn_msg "Haproxy service not active!"
fi
status_msg "Disabling Haproxy service ..."
if sudo systemctl disable haproxy; then
ok_msg "Haproxy service disabled!"
else
error_msg "Disabling Haproxy service failed!"
fi
fi
}
function detect_conflicting_packages() {
local apache="false" haproxy="false"
### check system for an installed apache2 service
[[ $(dpkg-query -f'${Status}' --show apache2 2>/dev/null) = *\ installed ]] && apache="true"
### check system for an installed haproxy service
[[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]] && haproxy="true"
#notify user about haproxy or apache2 services found and possible issues #notify user about haproxy or apache2 services found and possible issues
if [[ ${HAPROXY_FOUND} == "true" || ${APACHE2_FOUND} == "true" ]]; then if [[ ${haproxy} == "false" && ${apache} == "false" ]]; then
return
else
while true; do while true; do
echo echo
top_border top_border
echo -e "| ${red}Possibly disruptive/incompatible services found!${white} |" echo -e "| ${red}Conflicting package installations found:${white} |"
hr [[ ${apache} == "true" ]] && \
if [[ ${HAPROXY_FOUND} == "true" ]]; then echo -e "| ${red}● apache2${white} |"
echo -e "| ● haproxy |" [[ ${haproxy} == "true" ]] && \
fi echo -e "| ${red}● haproxy${white} |"
if [[ ${APACHE2_FOUND} == "true" ]]; then blank_line
echo -e "| ● apache2 |"
fi
hr
echo -e "| Having those packages installed can lead to unwanted |" echo -e "| Having those packages installed can lead to unwanted |"
echo -e "| behaviour. It's recommended to remove those packages. |" echo -e "| behaviour. It's recommended to remove those packages. |"
echo -e "| |" echo -e "| |"
echo -e "| 1) Remove packages (recommend) |" echo -e "| 1) Remove packages (recommend) |"
echo -e "| 2) Disable only (may cause issues) |" echo -e "| 2) Disable only (may still cause issues) |"
echo -e "| ${red}3) Skip this step (not recommended)${white} |" echo -e "| ${red}3) Skip this step (not recommended)${white} |"
bottom_border bottom_border
@@ -220,13 +245,11 @@ function process_services_dialog() {
case "${action}" in case "${action}" in
1) 1)
echo -e "###### > Remove packages" echo -e "###### > Remove packages"
REMOVE_HAPROXY="true" remove_conflicting_packages "${apache}" "${haproxy}"
REMOVE_APACHE2="true"
break;; break;;
2) 2)
echo -e "###### > Disable only" echo -e "###### > Disable only"
DISABLE_HAPROXY="true" disable_conflicting_packages "${apache}" "${haproxy}"
DISABLE_APACHE2="true"
break;; break;;
3) 3)
echo -e "###### > Skip" echo -e "###### > Skip"

View File

@@ -446,18 +446,6 @@ function dependency_check() {
fi fi
} }
function system_check_webui() {
### check system for an installed haproxy service
if [[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]]; then
HAPROXY_FOUND="true"
fi
### check system for an installed apache2 service
if [[ $(dpkg-query -f'${Status}' --show apache2 2>/dev/null) = *\ installed ]]; then
APACHE2_FOUND="true"
fi
}
function fetch_webui_ports() { function fetch_webui_ports() {
local port interfaces=("mainsail" "fluidd" "octoprint") local port interfaces=("mainsail" "fluidd" "octoprint")