diff --git a/scripts/install_klipper_webui.sh b/scripts/install_klipper_webui.sh deleted file mode 100755 index 1d102e7..0000000 --- a/scripts/install_klipper_webui.sh +++ /dev/null @@ -1,612 +0,0 @@ -#!/bin/bash - -#=======================================================================# -# Copyright (C) 2020 - 2022 Dominik Willner # -# # -# This file is part of KIAUH - Klipper Installation And Update Helper # -# https://github.com/th33xitus/kiauh # -# # -# This file may be distributed under the terms of the GNU GPLv3 license # -#=======================================================================# - -set -e - -MAINSAIL_REPO_API="https://api.github.com/repos/mainsail-crew/mainsail/releases" -FLUIDD_REPO_API="https://api.github.com/repos/fluidd-core/fluidd/releases" - -system_check_webui(){ - ### check system for installed moonraker service - if ls /etc/systemd/system/moonraker.service 2>/dev/null 1>&2 || ls /etc/systemd/system | grep -q -E "moonraker-[[:digit:]]+.service"; then - moonraker_chk_ok="true" - else - moonraker_chk_ok="false" - fi - - ### check system for an installed and enabled octoprint service - if sudo systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then - OCTOPRINT_ENABLED="true" - fi - - ### 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 lighttpd service - if [[ $(dpkg-query -f'${Status}' --show lighttpd 2>/dev/null) = *\ installed ]]; then - LIGHTTPD_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 -} - -get_user_selection_mjpg-streamer(){ - while true; do - unset INSTALL_MJPG - echo - top_border - echo -e "| Install MJGP-Streamer for webcam support? |" - bottom_border - read -p "${cyan}###### Install MJPG-Streamer? (Y/n):${default} " yn - case "${yn}" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - INSTALL_MJPG="true" - break;; - N|n|No|no) - echo -e "###### > No" - INSTALL_MJPG="false" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done -} - -get_user_selection_kiauh_macros(){ - #ask user for webui default macros - while true; do - unset ADD_KIAUH_MACROS - echo - top_border - echo -e "| It is recommended to have some important macros set |" - echo -e "| up in your printer configuration to have $1|" - echo -e "| fully functional and working. |" - blank_line - echo -e "| Those macros are: |" - echo -e "| ${cyan}● [gcode_macro PAUSE]${default} |" - echo -e "| ${cyan}● [gcode_macro RESUME]${default} |" - echo -e "| ${cyan}● [gcode_macro CANCEL_PRINT]${default} |" - blank_line - echo -e "| If you already have these macros in your config file |" - echo -e "| you can skip this step and choose 'no'. |" - echo -e "| Otherwise you should consider to answer with 'yes' to |" - echo -e "| add the recommended example macros to your config. |" - bottom_border - read -p "${cyan}###### Add the recommended macros? (Y/n):${default} " yn - case "${yn}" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - ADD_KIAUH_MACROS="true" - break;; - N|n|No|no) - echo -e "###### > No" - ADD_KIAUH_MACROS="false" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done -} - -install_webui(){ - source_kiauh_ini - ### checking dependencies - dep=(nginx) - dependency_check - ### check if moonraker is already installed - system_check_webui - ### ask user how to handle OctoPrint, Haproxy, Lighttpd, Apache2 if found - process_octoprint_dialog - process_services_dialog - ### process possible disruptive services - process_disruptive_services - - [ "$1" == "mainsail" ] && IF_NAME1="Mainsail" && IF_NAME2="Mainsail " - [ "$1" == "fluidd" ] && IF_NAME1="Fluidd" && IF_NAME2="Fluidd " - - ### exit mainsail/fluidd setup if moonraker not found - if [ "${moonraker_chk_ok}" = "false" ]; then - ERROR_MSG="Moonraker service not found!\n Please install Moonraker first!" - print_msg && clear_msg && return 0 - fi - - status_msg "Initializing ${IF_NAME1} installation ..." - ### check for other enabled web interfaces - unset SET_LISTEN_PORT - detect_enabled_sites - - ### check if another site already listens to port 80 - "${1}"_port_check - - ### ask user to install mjpg-streamer - if ! ls /etc/systemd/system/webcamd.service 2>/dev/null 1>&2; then - get_user_selection_mjpg-streamer - fi - - ### ask user to install the recommended webinterface macros - if ! ls "${klipper_cfg_loc}"/kiauh_macros.cfg 2>/dev/null 1>&2 || ! ls "${klipper_cfg_loc}"/printer_*/kiauh_macros.cfg 2>/dev/null 1>&2; then - get_user_selection_kiauh_macros "${IF_NAME2}" - fi - ### create /etc/nginx/conf.d/upstreams.conf - set_upstream_nginx_cfg - ### create /etc/nginx/sites-available/ - set_nginx_cfg "${1}" - - ### symlink nginx log - symlink_webui_nginx_log "${1}" - - ### copy the kiauh_macros.cfg to the config location - install_kiauh_macros - - ### install mainsail/fluidd - "${1}"_setup - - ### 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 -} - -symlink_webui_nginx_log(){ - LPATH="${HOME}/klipper_logs" - UI_ACCESS_LOG="/var/log/nginx/${1}-access.log" - UI_ERROR_LOG="/var/log/nginx/${1}-error.log" - [ ! -d "${LPATH}" ] && mkdir -p "${LPATH}" - if [ -f "${UI_ACCESS_LOG}" ] && [ ! -L "${LPATH}/${1}-access.log" ]; then - status_msg "Creating symlink for ${UI_ACCESS_LOG} ..." - ln -s "${UI_ACCESS_LOG}" "${LPATH}" - ok_msg "OK!" - fi - if [ -f "${UI_ERROR_LOG}" ] && [ ! -L "${LPATH}/${1}-error.log" ]; then - status_msg "Creating symlink for ${UI_ERROR_LOG} ..." - ln -s "${UI_ERROR_LOG}" "${LPATH}" - ok_msg "OK!" - fi -} - -install_kiauh_macros(){ - source_kiauh_ini - ### copy kiauh_macros.cfg - if [ "${ADD_KIAUH_MACROS}" = "true" ]; then - ### create a backup of the config folder - backup_klipper_config_dir - ### handle multi printer.cfg - if ls "${klipper_cfg_loc}"/printer_* 2>/dev/null 1>&2; then - for config in $(find ${klipper_cfg_loc}/printer_*/printer.cfg); do - path=$(echo "${config}" | rev | cut -d"/" -f2- | rev) - if [ ! -f "${path}/kiauh_macros.cfg" ]; then - ### copy kiauh_macros.cfg to config location - status_msg "Creating macro config file ..." - cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "${path}" - ### write the include to the very first line of the printer.cfg - sed -i "1 i [include kiauh_macros.cfg]" "${path}/printer.cfg" - ok_msg "${path}/kiauh_macros.cfg created!" - fi - done - ### handle single printer.cfg - elif [ -f "${klipper_cfg_loc}/printer.cfg" ] && [ ! -f "${klipper_cfg_loc}/kiauh_macros.cfg" ]; then - ### copy kiauh_macros.cfg to config location - status_msg "Creating macro config file ..." - cp "${SRCDIR}/kiauh/resources/kiauh_macros.cfg" "${klipper_cfg_loc}" - ### write the include to the very first line of the printer.cfg - sed -i "1 i [include kiauh_macros.cfg]" "${klipper_cfg_loc}/printer.cfg" - ok_msg "${klipper_cfg_loc}/kiauh_macros.cfg created!" - fi - ### restart klipper service to parse the modified printer.cfg - do_action_service "restart" "klipper" - fi -} - -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}" - if [ "${FLUIDD_PORT}" = "80" ] || [ "${OCTOPRINT_PORT}" = "80" ]; then - PORT_80_BLOCKED="true" - select_mainsail_port - fi - else - DEFAULT_PORT=$(grep listen "${SRCDIR}/kiauh/resources/klipper_webui_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 -} - -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}" - if [ "${MAINSAIL_PORT}" = "80" ] || [ "${OCTOPRINT_PORT}" = "80" ]; then - PORT_80_BLOCKED="true" - select_fluidd_port - fi - else - DEFAULT_PORT=$(grep listen "${SRCDIR}/kiauh/resources/klipper_webui_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(){ - 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 |" - blank_line - echo -e "| Make sure you don't choose a port which was already |" - echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${default} |" - echo -e "| use ports in the range of 4750 or above! |" - 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}" != "${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 -} - -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 |" - blank_line - echo -e "| Make sure you don't choose a port which was already |" - echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${default} |" - echo -e "| use ports in the range of 4750 or above! |" - 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}" != "${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_mainsail_ver(){ - MAINSAIL_VERSION=$(curl -s "${MAINSAIL_REPO_API}" | grep tag_name | cut -d'"' -f4 | head -1) -} - -get_fluidd_ver(){ - FLUIDD_VERSION=$(curl -s "${FLUIDD_REPO_API}" | grep tag_name | cut -d'"' -f4 | head -1) -} - -mainsail_setup(){ - ### get mainsail download url - MAINSAIL_DL_URL=$(curl -s "${MAINSAIL_REPO_API}" | grep browser_download_url | cut -d'"' -f4 | head -1) - - ### remove existing and create fresh mainsail folder, then download mainsail - [ -d "${MAINSAIL_DIR}" ] && rm -rf "${MAINSAIL_DIR}" - mkdir "${MAINSAIL_DIR}" && cd "${MAINSAIL_DIR}" - status_msg "Downloading Mainsail ${MAINSAIL_VERSION} ..." - wget "${MAINSAIL_DL_URL}" && ok_msg "Download complete!" - - ### extract archive - status_msg "Extracting archive ..." - unzip -q -o *.zip && ok_msg "Done!" - - ### delete downloaded zip - status_msg "Remove downloaded archive ..." - rm -rf *.zip && ok_msg "Done!" - - ### check for moonraker multi-instance and if multi-instance was found, enable mainsails remoteMode - if [ $(ls /etc/systemd/system/moonraker* | grep -E "moonraker(-[[:digit:]]+)?\.service" | wc -l) -gt 1 ]; then - enable_mainsail_remotemode - fi -} - -enable_mainsail_remotemode(){ - rm -f "${MAINSAIL_DIR}/config.json" - echo -e "{\n \"remoteMode\":true\n}" >> "${MAINSAIL_DIR}/config.json" -} - -fluidd_setup(){ - ### get fluidd download url - FLUIDD_DL_URL=$(curl -s "${FLUIDD_REPO_API}" | grep browser_download_url | cut -d'"' -f4 | head -1) - - ### remove existing and create fresh fluidd folder, then download fluidd - [ -d "${FLUIDD_DIR}" ] && rm -rf "${FLUIDD_DIR}" - mkdir "${FLUIDD_DIR}" && cd "${FLUIDD_DIR}" - status_msg "Downloading Fluidd ${FLUIDD_VERSION} ..." - wget "${FLUIDD_DL_URL}" && ok_msg "Download complete!" - - ### extract archive - status_msg "Extracting archive ..." - unzip -q -o *.zip && ok_msg "Done!" - - ### delete downloaded zip - status_msg "Remove downloaded archive ..." - rm -rf *.zip && ok_msg "Done!" -} - -set_upstream_nginx_cfg(){ - get_date - ### backup existing nginx configs - [ ! -d "${BACKUP_DIR}/nginx_cfg" ] && mkdir -p "${BACKUP_DIR}/nginx_cfg" - [ -f "${NGINX_CONFD}/upstreams.conf" ] && sudo mv "${NGINX_CONFD}/upstreams.conf" "${BACKUP_DIR}/nginx_cfg/${current_date}_upstreams.conf" - [ -f "${NGINX_CONFD}/common_vars.conf" ] && sudo mv "${NGINX_CONFD}/common_vars.conf" "${BACKUP_DIR}/nginx_cfg/${current_date}_common_vars.conf" - ### transfer ownership of backed up files from root to ${USER} - for log in $(ls "$BACKUP_DIR/nginx_cfg"); do - sudo chown "${USER}" "${BACKUP_DIR}/nginx_cfg/$log" - done - ### copy nginx configs to target destination - if [ ! -f "${NGINX_CONFD}/upstreams.conf" ]; then - sudo cp "${SRCDIR}/kiauh/resources/upstreams.conf" "${NGINX_CONFD}" - fi - if [ ! -f "${NGINX_CONFD}/common_vars.conf" ]; then - sudo cp "${SRCDIR}/kiauh/resources/common_vars.conf" "${NGINX_CONFD}" - fi -} - -fetch_webui_ports(){ - ### read listen ports from possible installed interfaces - ### and write them to ~/.kiauh.ini - WEBIFS=(mainsail fluidd octoprint) - for interface in "${WEBIFS[@]}"; do - if [ -f "/etc/nginx/sites-available/${interface}" ]; then - port=$(grep -E "listen" "/etc/nginx/sites-available/${interface}" | head -1 | sed 's/^\s*//' | sed 's/;$//' | cut -d" " -f2) - if [ ! -n "$(grep -E "${interface}_port" "${INI_FILE}")" ]; then - sed -i '$a'"${interface}_port=${port}" "${INI_FILE}" - else - sed -i "/^${interface}_port/d" "${INI_FILE}" - sed -i '$a'"${interface}_port=${port}" "${INI_FILE}" - fi - else - sed -i "/^${interface}_port/d" "${INI_FILE}" - fi - done -} - -match_nginx_configs(){ - ### reinstall nginx configs if the amount of upstreams don't match anymore - source_kiauh_ini - cfg_updated="false" - mainsail_nginx_cfg="/etc/nginx/sites-available/mainsail" - fluidd_nginx_cfg="/etc/nginx/sites-available/fluidd" - upstreams_webcams=$(grep -E "mjpgstreamer" /etc/nginx/conf.d/upstreams.conf | wc -l) - status_msg "Checking validity of NGINX configurations ..." - if [ -e "${mainsail_nginx_cfg}" ]; then - mainsail_webcams=$(grep -E "mjpgstreamer" "${mainsail_nginx_cfg}" | wc -l) - fi - if [ -e "${fluidd_nginx_cfg}" ]; then - fluidd_webcams=$(grep -E "mjpgstreamer" "${fluidd_nginx_cfg}" | wc -l) - fi - ### check for outdated upstreams.conf - if [[ "${upstreams_webcams}" -lt "${mainsail_webcams}" ]] || [[ "${upstreams_webcams}" -lt "${fluidd_webcams}" ]]; then - status_msg "Outdated upstreams.conf found! Updating ..." - sudo rm -f "${NGINX_CONFD}/upstreams.conf" - sudo rm -f "${NGINX_CONFD}/common_vars.conf" - set_upstream_nginx_cfg - cfg_updated="true" - fi - ### check for outdated mainsail config - if [ -e "${mainsail_nginx_cfg}" ]; then - if [[ "${upstreams_webcams}" -gt "${mainsail_webcams}" ]]; then - status_msg "Outdated Mainsail config found! Updating ..." - sudo rm -f "${mainsail_nginx_cfg}" - sudo cp "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" "${mainsail_nginx_cfg}" - sudo sed -i "s/<>/mainsail/g" "${mainsail_nginx_cfg}" - sudo sed -i "/root/s/pi/${USER}/" "${mainsail_nginx_cfg}" - sudo sed -i "s/listen\s[0-9]*;/listen ${mainsail_port};/" "${mainsail_nginx_cfg}" - sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${mainsail_port};/" "${mainsail_nginx_cfg}" - cfg_updated="true" && ok_msg "Done!" - fi - fi - ### check for outdated fluidd config - if [ -e "${fluidd_nginx_cfg}" ]; then - if [[ "${upstreams_webcams}" -gt "${fluidd_webcams}" ]]; then - status_msg "Outdated Fluidd config found! Updating ..." - sudo rm -f "${fluidd_nginx_cfg}" - sudo cp "${SRCDIR}/kiauh/resources/klipper_webui_nginx.cfg" "${fluidd_nginx_cfg}" - sudo sed -i "s/<>/fluidd/g" "${fluidd_nginx_cfg}" - sudo sed -i "/root/s/pi/${USER}/" "${fluidd_nginx_cfg}" - sudo sed -i "s/listen\s[0-9]*;/listen ${fluidd_port};/" "${fluidd_nginx_cfg}" - sudo sed -i "s/listen\s\[\:*\]\:[0-9]*;/listen \[::\]\:${fluidd_port};/" "${fluidd_nginx_cfg}" - cfg_updated="true" && ok_msg "Done!" - fi - fi - ### only restart nginx if configs were updated - if [ "${cfg_updated}" == "true" ]; then - restart_nginx && unset cfg_updated - fi -} - -process_octoprint_dialog(){ - #ask user to disable octoprint when its service was found - if [ "${OCTOPRINT_ENABLED}" = "true" ]; then - while true; do - echo - top_border - echo -e "| ${red}!!! WARNING - OctoPrint service found !!!${default} |" - hr - echo -e "| You might consider disabling the OctoPrint service, |" - echo -e "| since an active OctoPrint service may lead to unex- |" - echo -e "| pected behavior of the Klipper Webinterfaces. |" - bottom_border - read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn - case "${yn}" in - Y|y|Yes|yes|"") - echo -e "###### > Yes" - status_msg "Stopping OctoPrint ..." - do_action_service "stop" "octoprint" && ok_msg "OctoPrint service stopped!" - status_msg "Disabling OctoPrint ..." - do_action_service "disable" "octoprint" && ok_msg "OctoPrint service disabled!" - break;; - N|n|No|no) - echo -e "###### > No" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done - fi -} - -process_disruptive_services(){ - #handle haproxy service - 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 - if [ "${DISABLE_HAPROXY}" = "true" ]; then - status_msg "Disabling haproxy ..." - sudo systemctl disable haproxy && ok_msg "Haproxy service disabled!" - - ### remove haproxy - if [ "${REMOVE_HAPROXY}" = "true" ]; then - status_msg "Removing haproxy ..." - sudo apt-get remove haproxy -y && sudo update-rc.d -f haproxy remove && ok_msg "Haproxy removed!" - fi - fi - fi - - ### handle lighttpd service - if [ "${DISABLE_LIGHTTPD}" = "true" ] || [ "${REMOVE_LIGHTTPD}" = "true" ]; then - if systemctl is-active lighttpd -q; then - status_msg "Stopping lighttpd service ..." - sudo systemctl stop lighttpd && ok_msg "Service stopped!" - fi - - ### disable lighttpd - if [ "${DISABLE_LIGHTTPD}" = "true" ]; then - status_msg "Disabling lighttpd ..." - sudo systemctl disable lighttpd && ok_msg "Lighttpd service disabled!" - - ### remove lighttpd - if [ "${REMOVE_LIGHTTPD}" = "true" ]; then - status_msg "Removing lighttpd ..." - sudo apt-get remove lighttpd -y && sudo update-rc.d -f lighttpd remove && ok_msg "Lighttpd removed!" - fi - fi - fi - - ### handle apache2 service - if [ "${DISABLE_APACHE2}" = "true" ] || [ "${REMOVE_APACHE2}" = "true" ]; then - if systemctl is-active apache2 -q; then - status_msg "Stopping apache2 service ..." - sudo systemctl stop apache2 && ok_msg "Service stopped!" - fi - - ### disable lighttpd - if [ "${DISABLE_APACHE2}" = "true" ]; then - status_msg "Disabling lighttpd ..." - sudo systemctl disable apache2 && ok_msg "Apache2 service disabled!" - - ### remove lighttpd - 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 -} - -process_services_dialog(){ - #notify user about haproxy or lighttpd services found and possible issues - if [ "${HAPROXY_FOUND}" = "true" ] || [ "${LIGHTTPD_FOUND}" = "true" ] || [ "${APACHE2_FOUND}" = "true" ]; then - while true; do - echo - top_border - echo -e "| ${red}Possibly disruptive/incompatible services found!${default} |" - hr - if [ "${HAPROXY_FOUND}" = "true" ]; then - echo -e "| ● haproxy |" - fi - if [ "${LIGHTTPD_FOUND}" = "true" ]; then - echo -e "| ● lighttpd |" - fi - if [ "${APACHE2_FOUND}" = "true" ]; then - echo -e "| ● apache2 |" - fi - hr - echo -e "| Having those packages installed can lead to unwanted |" - echo -e "| behaviour. It is recommend to remove those packages. |" - echo -e "| |" - echo -e "| 1) Remove packages (recommend) |" - echo -e "| 2) Disable only (may cause issues) |" - echo -e "| ${red}3) Skip this step (not recommended)${default} |" - bottom_border - read -p "${cyan}###### Please choose:${default} " action - case "${action}" in - 1) - echo -e "###### > Remove packages" - REMOVE_HAPROXY="true" - REMOVE_LIGHTTPD="true" - REMOVE_APACHE2="true" - break;; - 2) - echo -e "###### > Disable only" - DISABLE_HAPROXY="true" - DISABLE_LIGHTTPD="true" - DISABLE_APACHE2="true" - break;; - 3) - echo -e "###### > Skip" - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - done - fi -} diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh new file mode 100644 index 0000000..b58757e --- /dev/null +++ b/scripts/mainsail.sh @@ -0,0 +1,397 @@ +#!/bin/bash + +#=======================================================================# +# Copyright (C) 2020 - 2022 Dominik Willner # +# # +# This file is part of KIAUH - Klipper Installation And Update Helper # +# https://github.com/th33xitus/kiauh # +# # +# This file may be distributed under the terms of the GNU GPLv3 license # +#=======================================================================# + +set -e + +### global variables +MAINSAIL_DIR="${HOME}/mainsail" +MAINSAIL_REPO_API="https://api.github.com/repos/mainsail-crew/mainsail/releases" +KLIPPER_CONFIG="${HOME}/klipper_config" + +#===================================================# +#================= INSTALL MAINSAIL ================# +#===================================================# + +function install_mainsail(){ + ### exit early if moonraker not found + if [ -z "$(moonraker_systemd)" ]; then + local error="Moonraker service not found!\n Please install Moonraker first!" + print_error "${error}" && return + fi + ### checking dependencies + local dep=(nginx) + dependency_check "${dep[@]}" + ### check if moonraker is already installed + system_check_webui + ### ask user how to handle OctoPrint, Haproxy, Lighttpd, Apache2 if found + process_octoprint_dialog + process_services_dialog + ### process possible disruptive services + process_disruptive_services + + status_msg "Initializing Mainsail installation ..." + ### check for other enabled web interfaces + unset SET_LISTEN_PORT + detect_enabled_sites + + ### check if another site already listens to port 80 + mainsail_port_check + + ### ask user to install mjpg-streamer + if ! ls /etc/systemd/system/webcamd.service 2>/dev/null 1>&2; then + get_user_selection_mjpg-streamer + fi + + ### ask user to install the recommended webinterface macros + if ! ls "${KLIPPER_CONFIG}/kiauh_macros.cfg" 2>/dev/null 1>&2 || ! ls "${KLIPPER_CONFIG}"/printer_*/kiauh_macros.cfg 2>/dev/null 1>&2; then + get_user_selection_kiauh_macros "Mainsail " + fi + ### create /etc/nginx/conf.d/upstreams.conf + set_upstream_nginx_cfg + ### create /etc/nginx/sites-available/ + set_nginx_cfg "mainsail" + + ### symlink nginx log + symlink_webui_nginx_log "mainsail" + + ### copy the kiauh_macros.cfg to the config location + install_kiauh_macros + + ### install mainsail/fluidd + mainsail_setup + + ### install mjpg-streamer + [ "${INSTALL_MJPG}" = "true" ] && install_mjpg-streamer + + fetch_webui_ports #WIP + + ### confirm message + print_confirm "Mainsail has been set up!" +} + +function mainsail_setup(){ + ### get mainsail download url + MAINSAIL_DL_URL=$(curl -s "${MAINSAIL_REPO_API}" | grep browser_download_url | cut -d'"' -f4 | head -1) + + ### remove existing and create fresh mainsail folder, then download mainsail + [ -d "${MAINSAIL_DIR}" ] && rm -rf "${MAINSAIL_DIR}" + mkdir "${MAINSAIL_DIR}" && cd "${MAINSAIL_DIR}" + status_msg "Downloading Mainsail ${MAINSAIL_VERSION} ..." + wget "${MAINSAIL_DL_URL}" && ok_msg "Download complete!" + + ### extract archive + status_msg "Extracting archive ..." + unzip -q -o *.zip && ok_msg "Done!" + + ### delete downloaded zip + status_msg "Remove downloaded archive ..." + rm -rf *.zip && ok_msg "Done!" + + ### check for moonraker multi-instance and if multi-instance was found, enable mainsails remoteMode + if [ $(ls /etc/systemd/system/moonraker* | grep -E "moonraker(-[[:digit:]]+)?\.service" | wc -l) -gt 1 ]; then + enable_mainsail_remotemode + fi +} + +#===================================================# +#================= REMOVE MAINSAIL =================# +#===================================================# + +function remove_mainsail(){ + ### remove mainsail dir + if [ -d "${MAINSAIL_DIR}" ]; then + status_msg "Removing Mainsail directory ..." + rm -rf "${MAINSAIL_DIR}" && ok_msg "Directory removed!" + fi + + ### remove mainsail config for nginx + if [ -e "/etc/nginx/sites-available/mainsail" ]; then + status_msg "Removing Mainsail configuration for Nginx ..." + sudo rm "/etc/nginx/sites-available/mainsail" && ok_msg "File removed!" + fi + + ### remove mainsail symlink for nginx + if [ -L "/etc/nginx/sites-enabled/mainsail" ]; then + status_msg "Removing Mainsail Symlink for Nginx ..." + sudo rm "/etc/nginx/sites-enabled/mainsail" && ok_msg "File removed!" + fi + + ### remove mainsail nginx logs and log symlinks + for log in $(find /var/log/nginx -name "mainsail*"); do + sudo rm -f "${log}" + done + for log in $(find ${HOME}/klipper_logs -name "mainsail*"); do + rm -f "${log}" + done + + ### remove mainsail_port from ~/.kiauh.ini + sed -i "/^mainsail_port=/d" "${INI_FILE}" + + print_confirm "Mainsail successfully removed!" +} + +#===================================================# +#================= UPDATE MAINSAIL =================# +#===================================================# + +function update_mainsail(){ + bb4u "mainsail" + status_msg "Updating Mainsail ..." + mainsail_setup + match_nginx_configs + symlink_webui_nginx_log "mainsail" +} + +#===================================================# +#================= MAINSAIL STATUS =================# +#===================================================# + +function get_mainsail_ver(){ + MAINSAIL_VERSION=$(curl -s "${MAINSAIL_REPO_API}" | grep tag_name | cut -d'"' -f4 | head -1) +} + +function mainsail_status(){ + mcount=0 + mainsail_data=( + $MAINSAIL_DIR + $NGINX_SA/mainsail + $NGINX_SE/mainsail + ) + #count+1 for each found data-item from array + for md in "${mainsail_data[@]}" + do + if [ -e $md ]; then + mcount=$(expr $mcount + 1) + fi + done + if [ "$mcount" == "${#mainsail_data[*]}" ]; then + MAINSAIL_STATUS="${green}Installed!${default} " + elif [ "$mcount" == 0 ]; then + MAINSAIL_STATUS="${red}Not installed!${default} " + else + MAINSAIL_STATUS="${yellow}Incomplete!${default} " + fi +} + +function read_local_mainsail_version(){ + unset MAINSAIL_VER_FOUND + if [ -e "${MAINSAIL_DIR}/.version" ]; then + MAINSAIL_VER_FOUND="true" + MAINSAIL_LOCAL_VER=$(head -n 1 "${MAINSAIL_DIR}/.version") + else + MAINSAIL_VER_FOUND="false" && unset MAINSAIL_LOCAL_VER + fi +} + +function read_remote_mainsail_version(){ + #remote checks don't work without curl installed! + if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then + MAINSAIL_REMOTE_VER=$NONE + else + get_mainsail_ver + MAINSAIL_REMOTE_VER=$MAINSAIL_VERSION + fi +} + +function compare_mainsail_versions(){ + unset MAINSAIL_UPDATE_AVAIL + read_local_mainsail_version && read_remote_mainsail_version + if [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER == $MAINSAIL_REMOTE_VER ]]; then + #printf fits the string for displaying it in the ui to a total char length of 12 + MAINSAIL_LOCAL_VER="${green}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${default}" + MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" + elif [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER != $MAINSAIL_REMOTE_VER ]]; then + MAINSAIL_LOCAL_VER="${yellow}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${default}" + MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" + # add mainsail to the update all array for the update all function in the updater + MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail) + else + MAINSAIL_LOCAL_VER=$NONE + MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" + MAINSAIL_UPDATE_AVAIL="false" + fi +} + +#================================================# +#=========== MAINSAIL THEME INSTALLER ===========# +#================================================# + +function get_theme_list(){ + theme_csv_url="https://raw.githubusercontent.com/mainsail-crew/docs/master/_data/themes.csv" + theme_csv=$(curl -s -L $theme_csv_url) + unset t_name + unset t_note + unset t_auth + unset t_url + i=0 + while IFS="," read -r col1 col2 col3 col4; do + t_name+=("$col1") + t_note+=("$col2") + t_auth+=("$col3") + t_url+=("$col4") + if [ ! "$col1" == "name" ]; then + printf "| $i) %-50s|\n" "[$col1]" + fi + i=$((i+1)) + done <<< "$theme_csv" +} + +function ms_theme_ui(){ + top_border + echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${default} | " + hr + echo -e "| ${green}A preview of each Mainsail theme can be found here:${default} | " + echo -e "| https://docs.mainsail.xyz/theming/themes | " + blank_line + echo -e "| ${yellow}Important note:${default} | " + echo -e "| Installing a theme from this menu will overwrite an | " + echo -e "| already installed theme or modified custom.css file! | " + hr + get_theme_list # dynamically generate the themelist from a csv file + echo -e "| | " + echo -e "| R) [Remove Theme] | " + back_footer +} + +function ms_theme_menu(){ + ms_theme_ui + while true; do + read -p "${cyan}Install theme:${default} " a; echo + if [ "$a" = "b" ] || [ "$a" = "B" ]; then + clear && advanced_menu && break + elif [ "$a" = "r" ] || [ "$a" = "R" ]; then + ms_theme_delete + ms_theme_menu + elif [ "$a" -le ${#t_url[@]} ]; then + ms_theme_install "${t_auth[$a]}" "${t_url[$a]}" "${t_name[$a]}" "${t_note[$a]}" + ms_theme_menu + else + clear && print_header + ERROR_MSG="Invalid command!" && print_msg && clear_msg + ms_theme_menu + fi + done + ms_theme_menu +} + +function check_select_printer(){ + unset printer_num + + ### get klipper cfg loc and set default .theme folder loc + check_klipper_cfg_path + THEME_PATH="$klipper_cfg_loc" + + ### check if there is more than one moonraker instance and if yes + ### ask the user to select the printer he wants to install/remove the theme + MR_SERVICE_COUNT=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/moonraker(-[^0])?[0-9]*.service" | wc -l) + if [[ $MR_SERVICE_COUNT -gt 1 ]]; then + top_border + echo -e "| More than one printer was found on this system! | " + echo -e "| Please select the printer to which you want to | " + echo -e "| apply the previously selected action. | " + bottom_border + read -p "${cyan}Select printer:${default} " printer_num + + ### rewrite the .theme path matching the selected printer + THEME_PATH="$klipper_cfg_loc/printer_$printer_num" + fi + + ### create the cfg folder if there is none yet + [ ! -d "$THEME_PATH" ] && mkdir -p "$THEME_PATH" +} + +function ms_theme_install(){ + THEME_URL="https://github.com/$1/$2" + + ### check and select printer if there is more than 1 + check_select_printer + + ### download all files + status_msg "Installing $3 ..." + status_msg "Please wait ..." + + [ -d "$THEME_PATH/.theme" ] && rm -rf "$THEME_PATH/.theme" + cd "$THEME_PATH" && git clone "$THEME_URL" ".theme" + + ok_msg "Theme installation complete!" + [ -n "$4" ] && echo "${yellow}###### Theme Info: $4${default}" + ok_msg "Please remember to delete your browser cache!\n" +} + +function ms_theme_delete(){ + check_select_printer + if [ -d "$THEME_PATH/.theme" ]; then + status_msg "Removing Theme ..." + rm -rf "$THEME_PATH/.theme" && ok_msg "Theme removed!\n" + else + status_msg "No Theme installed!\n" + fi +} + +#================================================# +#=================== HELPERS ====================# +#================================================# + +function 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}" + if [ "${FLUIDD_PORT}" = "80" ] || [ "${OCTOPRINT_PORT}" = "80" ]; then + PORT_80_BLOCKED="true" + select_mainsail_port + fi + else + DEFAULT_PORT=$(grep listen "${SRCDIR}/kiauh/resources/klipper_webui_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 +} + +function 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 |" + blank_line + echo -e "| Make sure you don't choose a port which was already |" + echo -e "| assigned to one of the other webinterfaces and do ${red}NOT${default} |" + echo -e "| use ports in the range of 4750 or above! |" + 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}" != "${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 +} + +function enable_mainsail_remotemode(){ + rm -f "${MAINSAIL_DIR}/config.json" + echo -e "{\n \"remoteMode\":true\n}" >> "${MAINSAIL_DIR}/config.json" +} \ No newline at end of file diff --git a/scripts/ms_theme_installer.sh b/scripts/ms_theme_installer.sh deleted file mode 100755 index 0346366..0000000 --- a/scripts/ms_theme_installer.sh +++ /dev/null @@ -1,114 +0,0 @@ -### base variables -SYSTEMDDIR="/etc/systemd/system" - -get_theme_list(){ - theme_csv_url="https://raw.githubusercontent.com/mainsail-crew/docs/master/_data/themes.csv" - theme_csv=$(curl -s -L $theme_csv_url) - unset t_name - unset t_note - unset t_auth - unset t_url - i=0 - while IFS="," read -r col1 col2 col3 col4; do - t_name+=("$col1") - t_note+=("$col2") - t_auth+=("$col3") - t_url+=("$col4") - if [ ! "$col1" == "name" ]; then - printf "| $i) %-50s|\n" "[$col1]" - fi - i=$((i+1)) - done <<< "$theme_csv" -} - -ms_theme_ui(){ - top_border - echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${default} | " - hr - echo -e "| ${green}A preview of each Mainsail theme can be found here:${default} | " - echo -e "| https://docs.mainsail.xyz/theming/themes | " - blank_line - echo -e "| ${yellow}Important note:${default} | " - echo -e "| Installing a theme from this menu will overwrite an | " - echo -e "| already installed theme or modified custom.css file! | " - hr - get_theme_list # dynamically generate the themelist from a csv file - echo -e "| | " - echo -e "| R) [Remove Theme] | " - back_footer -} - -ms_theme_menu(){ - ms_theme_ui - while true; do - read -p "${cyan}Install theme:${default} " a; echo - if [ "$a" = "b" ] || [ "$a" = "B" ]; then - clear && advanced_menu && break - elif [ "$a" = "r" ] || [ "$a" = "R" ]; then - ms_theme_delete - ms_theme_menu - elif [ "$a" -le ${#t_url[@]} ]; then - ms_theme_install "${t_auth[$a]}" "${t_url[$a]}" "${t_name[$a]}" "${t_note[$a]}" - ms_theme_menu - else - clear && print_header - ERROR_MSG="Invalid command!" && print_msg && clear_msg - ms_theme_menu - fi - done - ms_theme_menu -} - -check_select_printer(){ - unset printer_num - - ### get klipper cfg loc and set default .theme folder loc - check_klipper_cfg_path - THEME_PATH="$klipper_cfg_loc" - - ### check if there is more than one moonraker instance and if yes - ### ask the user to select the printer he wants to install/remove the theme - MR_SERVICE_COUNT=$(find "$SYSTEMDDIR" -regextype posix-extended -regex "$SYSTEMDDIR/moonraker(-[^0])?[0-9]*.service" | wc -l) - if [[ $MR_SERVICE_COUNT -gt 1 ]]; then - top_border - echo -e "| More than one printer was found on this system! | " - echo -e "| Please select the printer to which you want to | " - echo -e "| apply the previously selected action. | " - bottom_border - read -p "${cyan}Select printer:${default} " printer_num - - ### rewrite the .theme path matching the selected printer - THEME_PATH="$klipper_cfg_loc/printer_$printer_num" - fi - - ### create the cfg folder if there is none yet - [ ! -d "$THEME_PATH" ] && mkdir -p "$THEME_PATH" -} - -ms_theme_install(){ - THEME_URL="https://github.com/$1/$2" - - ### check and select printer if there is more than 1 - check_select_printer - - ### download all files - status_msg "Installing $3 ..." - status_msg "Please wait ..." - - [ -d "$THEME_PATH/.theme" ] && rm -rf "$THEME_PATH/.theme" - cd "$THEME_PATH" && git clone "$THEME_URL" ".theme" - - ok_msg "Theme installation complete!" - [ -n "$4" ] && echo "${yellow}###### Theme Info: $4${default}" - ok_msg "Please remember to delete your browser cache!\n" -} - -ms_theme_delete(){ - check_select_printer - if [ -d "$THEME_PATH/.theme" ]; then - status_msg "Removing Theme ..." - rm -rf "$THEME_PATH/.theme" && ok_msg "Theme removed!\n" - else - status_msg "No Theme installed!\n" - fi -} diff --git a/scripts/remove.sh b/scripts/remove.sh deleted file mode 100755 index 6e8fa6c..0000000 --- a/scripts/remove.sh +++ /dev/null @@ -1,89 +0,0 @@ -### base variables -SYSTEMDDIR="/etc/systemd/system" - -############################################################# -############################################################# - -remove_mainsail(){ - ### remove mainsail dir - if [ -d $MAINSAIL_DIR ]; then - status_msg "Removing Mainsail directory ..." - rm -rf $MAINSAIL_DIR && ok_msg "Directory removed!" - fi - - ### remove mainsail config for nginx - if [ -e /etc/nginx/sites-available/mainsail ]; then - status_msg "Removing Mainsail configuration for Nginx ..." - sudo rm /etc/nginx/sites-available/mainsail && ok_msg "File removed!" - fi - - ### remove mainsail symlink for nginx - if [ -L /etc/nginx/sites-enabled/mainsail ]; then - status_msg "Removing Mainsail Symlink for Nginx ..." - sudo rm /etc/nginx/sites-enabled/mainsail && ok_msg "File removed!" - fi - - ### remove mainsail nginx logs and log symlinks - for log in $(find /var/log/nginx -name "mainsail*"); do - sudo rm -f $log - done - for log in $(find ${HOME}/klipper_logs -name "mainsail*"); do - rm -f $log - done - - ### remove mainsail_port from ~/.kiauh.ini - sed -i "/^mainsail_port=/d" $INI_FILE - - CONFIRM_MSG="Mainsail successfully removed!" -} - -remove_fluidd(){ - ### 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 - - ### remove mainsail nginx logs and log symlinks - for log in $(find /var/log/nginx -name "fluidd*"); do - sudo rm -f $log - done - for log in $(find ${HOME}/klipper_logs -name "fluidd*"); do - rm -f $log - done - - ### remove fluidd_port from ~/.kiauh.ini - sed -i "/^fluidd_port=/d" $INI_FILE - - CONFIRM_MSG="Fluidd successfully removed!" -} - - -############################################################# -############################################################# - -remove_nginx(){ - if ls /lib/systemd/system/nginx.service 2>/dev/null 1>&2; then - status_msg "Stopping Nginx service ..." - sudo systemctl stop nginx && sudo systemctl disable nginx - ok_msg "Service stopped and disabled!" - status_msg "Purging Nginx from system ..." - sudo apt-get purge nginx nginx-common -y - sudo update-rc.d -f nginx remove - CONFIRM_MSG=" Nginx successfully removed!" - else - ERROR_MSG=" Looks like Nginx was already removed!\n Skipping..." - fi -} diff --git a/scripts/status.sh b/scripts/status.sh index 5048cef..c3a1fad 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -22,130 +22,6 @@ check_system_updates(){ fi } -mainsail_status(){ - mcount=0 - mainsail_data=( - $MAINSAIL_DIR - $NGINX_SA/mainsail - $NGINX_SE/mainsail - ) - #count+1 for each found data-item from array - for md in "${mainsail_data[@]}" - do - if [ -e $md ]; then - mcount=$(expr $mcount + 1) - fi - done - if [ "$mcount" == "${#mainsail_data[*]}" ]; then - MAINSAIL_STATUS="${green}Installed!${default} " - elif [ "$mcount" == 0 ]; then - MAINSAIL_STATUS="${red}Not installed!${default} " - else - MAINSAIL_STATUS="${yellow}Incomplete!${default} " - 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 -} - -read_local_mainsail_version(){ - unset MAINSAIL_VER_FOUND - if [ -e $MAINSAIL_DIR/.version ]; then - MAINSAIL_VER_FOUND="true" - MAINSAIL_LOCAL_VER=$(head -n 1 $MAINSAIL_DIR/.version) - else - MAINSAIL_VER_FOUND="false" && unset MAINSAIL_LOCAL_VER - fi -} - -read_remote_mainsail_version(){ - #remote checks don't work without curl installed! - if [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]]; then - MAINSAIL_REMOTE_VER=$NONE - else - get_mainsail_ver - MAINSAIL_REMOTE_VER=$MAINSAIL_VERSION - fi -} - -compare_mainsail_versions(){ - unset MAINSAIL_UPDATE_AVAIL - read_local_mainsail_version && read_remote_mainsail_version - if [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER == $MAINSAIL_REMOTE_VER ]]; then - #printf fits the string for displaying it in the ui to a total char length of 12 - MAINSAIL_LOCAL_VER="${green}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${default}" - MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" - elif [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER != $MAINSAIL_REMOTE_VER ]]; then - MAINSAIL_LOCAL_VER="${yellow}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${default}" - MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" - # add mainsail to the update all array for the update all function in the updater - MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail) - else - MAINSAIL_LOCAL_VER=$NONE - MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" - MAINSAIL_UPDATE_AVAIL="false" - fi -} - -read_local_fluidd_version(){ - unset FLUIDD_VER_FOUND - if [ -e $FLUIDD_DIR/.version ]; then - FLUIDD_VER_FOUND="true" - FLUIDD_LOCAL_VER=$(head -n 1 $FLUIDD_DIR/.version) - else - FLUIDD_VER_FOUND="false" && unset FLUIDD_LOCAL_VER - fi -} - -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=$NONE - else - get_fluidd_ver - FLUIDD_REMOTE_VER=$FLUIDD_VERSION - fi -} - -compare_fluidd_versions(){ - unset FLUIDD_UPDATE_AVAIL - read_local_fluidd_version && read_remote_fluidd_version - if [[ $FLUIDD_VER_FOUND = "true" ]] && [[ $FLUIDD_LOCAL_VER == $FLUIDD_REMOTE_VER ]]; then - #printf fits the string for displaying it in the ui to a total char length of 12 - FLUIDD_LOCAL_VER="${green}$(printf "%-12s" "$FLUIDD_LOCAL_VER")${default}" - FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}" - elif [[ $FLUIDD_VER_FOUND = "true" ]] && [[ $FLUIDD_LOCAL_VER != $FLUIDD_REMOTE_VER ]]; then - FLUIDD_LOCAL_VER="${yellow}$(printf "%-12s" "$FLUIDD_LOCAL_VER")${default}" - FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}" - # add fluidd to the update all array for the update all function in the updater - FLUIDD_UPDATE_AVAIL="true" && update_arr+=(update_fluidd) - else - FLUIDD_LOCAL_VER=$NONE - FLUIDD_REMOTE_VER="${green}$(printf "%-12s" "$FLUIDD_REMOTE_VER")${default}" - FLUIDD_UPDATE_AVAIL="false" - fi -} - ############################################################# ############################################################# diff --git a/scripts/update.sh b/scripts/update.sh index b08c83e..b6828fe 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -110,22 +110,6 @@ update_log_paths(){ shopt -u extglob # disable extended globbing } -update_mainsail(){ - bb4u "mainsail" - status_msg "Updating Mainsail ..." - mainsail_setup - match_nginx_configs - symlink_webui_nginx_log "mainsail" -} - -update_fluidd(){ - bb4u "fluidd" - status_msg "Updating Fluidd ..." - fluidd_setup - match_nginx_configs - symlink_webui_nginx_log "fluidd" -} - update_system(){ status_msg "Updating System ..." sudo apt-get update --allow-releaseinfo-change && sudo apt-get upgrade -y