feat: allow mainsail and fluidd stable only installs/updates

Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
th33xitus
2022-04-03 00:57:54 +02:00
parent 0c5f6e24ff
commit 7d7f2150d1
4 changed files with 128 additions and 66 deletions

View File

@@ -14,6 +14,7 @@ set -e
### global variables ### global variables
MAINSAIL_DIR="${HOME}/mainsail" MAINSAIL_DIR="${HOME}/mainsail"
MAINSAIL_REPO_API="https://api.github.com/repos/mainsail-crew/mainsail/releases" MAINSAIL_REPO_API="https://api.github.com/repos/mainsail-crew/mainsail/releases"
MAINSAIL_TAGS="https://api.github.com/repos/mainsail-crew/mainsail/tags"
KLIPPER_CONFIG="${HOME}/klipper_config" KLIPPER_CONFIG="${HOME}/klipper_config"
#===================================================# #===================================================#
@@ -46,7 +47,7 @@ function install_mainsail(){
mainsail_port_check mainsail_port_check
### ask user to install mjpg-streamer ### ask user to install mjpg-streamer
if ! ls /etc/systemd/system/webcamd.service 2>/dev/null 1>&2; then if [ ! -f "/etc/systemd/system/webcamd.service" ]; then
get_user_selection_mjpg-streamer get_user_selection_mjpg-streamer
fi fi
@@ -78,25 +79,24 @@ function install_mainsail(){
} }
function mainsail_setup(){ function mainsail_setup(){
### get mainsail download url local url
MAINSAIL_DL_URL=$(curl -s "${MAINSAIL_REPO_API}" | grep browser_download_url | cut -d'"' -f4 | head -1) url=$(get_mainsail_download_url)
status_msg "Downloading Mainsail ..."
if [ -d "${MAINSAIL_DIR}" ]; then
rm -rf "${MAINSAIL_DIR}"
mkdir "${MAINSAIL_DIR}"
fi
cd "${MAINSAIL_DIR}" && wget "${url}"
ok_msg "Download complete!"
### 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 ..." status_msg "Extracting archive ..."
unzip -q -o *.zip && ok_msg "Done!" unzip -q -o *.zip && ok_msg "Done!"
### delete downloaded zip
status_msg "Remove downloaded archive ..." status_msg "Remove downloaded archive ..."
rm -rf *.zip && ok_msg "Done!" rm -rf *.zip && ok_msg "Done!"
### check for moonraker multi-instance and if multi-instance was found, enable mainsails remoteMode ### 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 if [ "$(moonraker_systemd | wc -w)" -gt 1 ]; then
enable_mainsail_remotemode enable_mainsail_remotemode
fi fi
} }
@@ -173,11 +173,11 @@ function mainsail_status(){
fi fi
done done
if [ "$mcount" == "${#mainsail_data[*]}" ]; then if [ "$mcount" == "${#mainsail_data[*]}" ]; then
MAINSAIL_STATUS="${green}Installed!${default} " MAINSAIL_STATUS="${green}Installed!${white} "
elif [ "$mcount" == 0 ]; then elif [ "$mcount" == 0 ]; then
MAINSAIL_STATUS="${red}Not installed!${default} " MAINSAIL_STATUS="${red}Not installed!${white} "
else else
MAINSAIL_STATUS="${yellow}Incomplete!${default} " MAINSAIL_STATUS="${yellow}Incomplete!${white} "
fi fi
} }
@@ -206,16 +206,16 @@ function compare_mainsail_versions(){
read_local_mainsail_version && read_remote_mainsail_version read_local_mainsail_version && read_remote_mainsail_version
if [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER == $MAINSAIL_REMOTE_VER ]]; then 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 #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_LOCAL_VER="${green}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${white}"
MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${white}"
elif [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER != $MAINSAIL_REMOTE_VER ]]; then elif [[ $MAINSAIL_VER_FOUND = "true" ]] && [[ $MAINSAIL_LOCAL_VER != $MAINSAIL_REMOTE_VER ]]; then
MAINSAIL_LOCAL_VER="${yellow}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${default}" MAINSAIL_LOCAL_VER="${yellow}$(printf "%-12s" "$MAINSAIL_LOCAL_VER")${white}"
MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${white}"
# add mainsail to the update all array for the update all function in the updater # add mainsail to the update all array for the update all function in the updater
MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail) MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail)
else else
MAINSAIL_LOCAL_VER=$NONE MAINSAIL_LOCAL_VER=$NONE
MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${default}" MAINSAIL_REMOTE_VER="${green}$(printf "%-12s" "$MAINSAIL_REMOTE_VER")${white}"
MAINSAIL_UPDATE_AVAIL="false" MAINSAIL_UPDATE_AVAIL="false"
fi fi
} }
@@ -246,12 +246,12 @@ function get_theme_list(){
function ms_theme_ui(){ function ms_theme_ui(){
top_border top_border
echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${default} | " echo -e "| ${red}~~~~~~~~ [ Mainsail Theme Installer ] ~~~~~~~${white} | "
hr hr
echo -e "| ${green}A preview of each Mainsail theme can be found here:${default} | " echo -e "| ${green}A preview of each Mainsail theme can be found here:${white} | "
echo -e "| https://docs.mainsail.xyz/theming/themes | " echo -e "| https://docs.mainsail.xyz/theming/themes | "
blank_line blank_line
echo -e "| ${yellow}Important note:${default} | " echo -e "| ${yellow}Important note:${white} | "
echo -e "| Installing a theme from this menu will overwrite an | " echo -e "| Installing a theme from this menu will overwrite an | "
echo -e "| already installed theme or modified custom.css file! | " echo -e "| already installed theme or modified custom.css file! | "
hr hr
@@ -264,7 +264,7 @@ function ms_theme_ui(){
function ms_theme_menu(){ function ms_theme_menu(){
ms_theme_ui ms_theme_ui
while true; do while true; do
read -p "${cyan}Install theme:${default} " a; echo read -p "${cyan}Install theme:${white} " a; echo
if [ "$a" = "b" ] || [ "$a" = "B" ]; then if [ "$a" = "b" ] || [ "$a" = "B" ]; then
clear && advanced_menu && break clear && advanced_menu && break
elif [ "$a" = "r" ] || [ "$a" = "R" ]; then elif [ "$a" = "r" ] || [ "$a" = "R" ]; then
@@ -298,7 +298,7 @@ function check_select_printer(){
echo -e "| Please select the printer to which you want to | " echo -e "| Please select the printer to which you want to | "
echo -e "| apply the previously selected action. | " echo -e "| apply the previously selected action. | "
bottom_border bottom_border
read -p "${cyan}Select printer:${default} " printer_num read -p "${cyan}Select printer:${white} " printer_num
### rewrite the .theme path matching the selected printer ### rewrite the .theme path matching the selected printer
THEME_PATH="$klipper_cfg_loc/printer_$printer_num" THEME_PATH="$klipper_cfg_loc/printer_$printer_num"
@@ -322,7 +322,7 @@ function ms_theme_install(){
cd "$THEME_PATH" && git clone "$THEME_URL" ".theme" cd "$THEME_PATH" && git clone "$THEME_URL" ".theme"
ok_msg "Theme installation complete!" ok_msg "Theme installation complete!"
[ -n "$4" ] && echo "${yellow}###### Theme Info: $4${default}" [ -n "$4" ] && echo "${yellow}###### Theme Info: $4${white}"
ok_msg "Please remember to delete your browser cache!\n" ok_msg "Please remember to delete your browser cache!\n"
} }
@@ -340,12 +340,34 @@ function ms_theme_delete(){
#=================== HELPERS ====================# #=================== HELPERS ====================#
#================================================# #================================================#
function get_mainsail_download_url() {
local latest_tag latest_url stable_tag stable_url url
tags=$(curl -s "${MAINSAIL_TAGS}" | grep "name" | cut -d'"' -f4)
### latest download url including pre-releases (alpha, beta, rc)
latest_tag=$(echo "${tags}" | head -1)
latest_url="https://github.com/mainsail-crew/mainsail/releases/download/${latest_tag}/mainsail.zip"
### get stable mainsail download url
stable_tag=$(echo "${tags}" | grep -E "^v([0-9]+\.?){3}$" | head -1)
stable_url="https://github.com/mainsail-crew/mainsail/releases/download/${stable_tag}/mainsail.zip"
read_kiauh_ini
if [ "${mainsail_always_install_latest}" == "true" ]; then
url="${latest_url}"
echo "${url}"
else
url="${stable_url}"
echo "${url}"
fi
}
function mainsail_port_check(){ function mainsail_port_check(){
if [ "${MAINSAIL_ENABLED}" = "false" ]; then if [ "${MAINSAIL_ENABLED}" = "false" ]; then
if [ "${SITE_ENABLED}" = "true" ]; then if [ "${SITE_ENABLED}" = "true" ]; then
status_msg "Detected other enabled interfaces:" status_msg "Detected other enabled interfaces:"
[ "${OCTOPRINT_ENABLED}" = "true" ] && echo -e " ${cyan}● OctoPrint - Port: ${OCTOPRINT_PORT}${default}" [ "${OCTOPRINT_ENABLED}" = "true" ] && echo -e " ${cyan}● OctoPrint - Port: ${OCTOPRINT_PORT}${white}"
[ "${FLUIDD_ENABLED}" = "true" ] && echo -e " ${cyan}● Fluidd - Port: ${FLUIDD_PORT}${default}" [ "${FLUIDD_ENABLED}" = "true" ] && echo -e " ${cyan}● Fluidd - Port: ${FLUIDD_PORT}${white}"
if [ "${FLUIDD_PORT}" = "80" ] || [ "${OCTOPRINT_PORT}" = "80" ]; then if [ "${FLUIDD_PORT}" = "80" ] || [ "${OCTOPRINT_PORT}" = "80" ]; then
PORT_80_BLOCKED="true" PORT_80_BLOCKED="true"
select_mainsail_port select_mainsail_port
@@ -364,22 +386,22 @@ function select_mainsail_port(){
if [ "${PORT_80_BLOCKED}" = "true" ]; then if [ "${PORT_80_BLOCKED}" = "true" ]; then
echo echo
top_border top_border
echo -e "| ${red}!!!WARNING!!!${default} |" echo -e "| ${red}!!!WARNING!!!${white} |"
echo -e "| ${red}You need to choose a different port for Mainsail!${default} |" echo -e "| ${red}You need to choose a different port for Mainsail!${white} |"
echo -e "| ${red}The following web interface is listening at port 80:${default} |" echo -e "| ${red}The following web interface is listening at port 80:${white} |"
blank_line blank_line
[ "${OCTOPRINT_PORT}" = "80" ] && echo "| ● OctoPrint |" [ "${OCTOPRINT_PORT}" = "80" ] && echo "| ● OctoPrint |"
[ "${FLUIDD_PORT}" = "80" ] && echo "| ● Fluidd |" [ "${FLUIDD_PORT}" = "80" ] && echo "| ● Fluidd |"
blank_line blank_line
echo -e "| Make sure you don't choose a port which was already |" 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 "| assigned to one of the other webinterfaces and do ${red}NOT${white} |"
echo -e "| use ports in the range of 4750 or above! |" echo -e "| use ports in the range of 4750 or above! |"
blank_line blank_line
echo -e "| Be aware: there is ${red}NO${default} sanity check for the following |" echo -e "| Be aware: there is ${red}NO${white} sanity check for the following |"
echo -e "| input. So make sure to choose a valid port! |" echo -e "| input. So make sure to choose a valid port! |"
bottom_border bottom_border
while true; do while true; do
read -p "${cyan}Please enter a new Port:${default} " NEW_PORT read -p "${cyan}Please enter a new Port:${white} " NEW_PORT
if [ "${NEW_PORT}" != "${FLUIDD_PORT}" ] && [ "${NEW_PORT}" != "${OCTOPRINT_PORT}" ]; then if [ "${NEW_PORT}" != "${FLUIDD_PORT}" ] && [ "${NEW_PORT}" != "${OCTOPRINT_PORT}" ]; then
echo "Setting port ${NEW_PORT} for Mainsail!" echo "Setting port ${NEW_PORT} for Mainsail!"
SET_LISTEN_PORT=${NEW_PORT} SET_LISTEN_PORT=${NEW_PORT}

View File

@@ -63,14 +63,13 @@ do_action(){
clear && print_header clear && print_header
### $1 is the action the user wants to fire ### $1 is the action the user wants to fire
$1 $1
print_msg && clear_msg # print_msg && clear_msg
### $2 is the menu the user usually gets directed back to after an action is completed ### $2 is the menu the user usually gets directed back to after an action is completed
$2 $2
} }
deny_action(){ deny_action(){
clear && print_header clear && print_header
print_unkown_cmd print_error "Invalid command!"
print_msg && clear_msg
$1 $1
} }

View File

@@ -11,47 +11,85 @@
set -e set -e
settings_ui(){ ### global variables
source_kiauh_ini INI_FILE="${HOME}/.kiauh.ini"
top_border KLIPPER_CONFIG="${HOME}/klipper_config"
echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") | "
hr function settings_ui() {
echo -e "| ${red}Caution:${white} | " read_kiauh_ini
echo -e "| When you change the config folder, be aware that ALL | " local custom_cfg_loc="${custom_klipper_cfg_loc}"
echo -e "| Klipper and Moonraker services will be STOPPED, | " local ms_pre_rls="${mainsail_always_install_latest}"
echo -e "| reconfigured and then restarted again. | " local fl_pre_rls="${fluidd_always_install_latest}"
blank_line
echo -e "| ${red}DO NOT change the folder during printing!${white} | " if [ -z "${custom_cfg_loc}" ]; then
hr custom_cfg_loc="${cyan}${KLIPPER_CONFIG}${white}"
blank_line
echo -e "| ${cyan}● Current Klipper config folder:${white} | "
printf "|%-55s|\n" " $klipper_cfg_loc"
blank_line
hr
if [ -z $klipper_cfg_loc ]; then
echo -e "| ${red}N/A) Install Klipper with KIAUH first to unlock!${white} | "
else else
echo -e "| 1) Change config folder | " custom_cfg_loc="${cyan}${custom_cfg_loc}${white}"
fi fi
back_footer if [ "${ms_pre_rls}" == "false" ]; then
ms_pre_rls="${red}${ms_pre_rls}${white}"
else
ms_pre_rls="${green}${ms_pre_rls}${white}"
fi
if [ "${fl_pre_rls}" == "false" ]; then
fl_pre_rls="${red}${fl_pre_rls}${white}"
else
fl_pre_rls="${green}${fl_pre_rls}${white}"
fi
top_border
echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") |"
hr
echo -e "| Klipper: |"
printf "| Config folder: %-49s|\n" "${custom_cfg_loc}"
blank_line
echo -e "| Klipper Webinterface: |"
printf "| 1) Install Mainsail latest: %-38s|\n" "${ms_pre_rls}"
printf "| 2) Install Fluidd latest: %-38s|\n" "${fl_pre_rls}"
hr
blank_line
back_help_footer
} }
settings_menu(){ settings_menu(){
do_action "" "settings_ui" do_action "" "settings_ui"
while true; do while true; do
read -p "${cyan}Perform action:${white} " action; echo read -p "${cyan}Perform action:${white} " action; echo
case "$action" in case "${action}" in
1) 1)
if [ ! -z $klipper_cfg_loc ]; then switch_mainsail && settings_menu;;
do_action "change_klipper_cfg_path" "settings_ui" 2)
else switch_fluidd && settings_menu;;
deny_action "settings_ui"
fi;;
B|b) B|b)
clear; main_menu; break;; clear
main_menu
break;;
*) *)
deny_action "settings_ui";; deny_action "settings_ui";;
esac esac
done done
settings_ui }
function switch_mainsail() {
read_kiauh_ini
local state="${mainsail_always_install_latest}"
if [ "${state}" == "false" ]; then
sed -i '/mainsail_always_install_latest=/s/false/true/' "${INI_FILE}"
log_info "mainsail_always_install_latest changed (false -> true) "
else
sed -i '/mainsail_always_install_latest=/s/true/false/' "${INI_FILE}"
log_info "mainsail_always_install_latest changed (true -> false) "
fi
}
function switch_fluidd() {
read_kiauh_ini
local state="${fluidd_always_install_latest}"
if [ "${state}" == "false" ]; then
sed -i '/fluidd_always_install_latest=/s/false/true/' "${INI_FILE}"
log_info "fluidd_always_install_latest changed (false -> true) "
else
sed -i '/fluidd_always_install_latest=/s/true/false/' "${INI_FILE}"
log_info "fluidd_always_install_latest changed (true -> false) "
fi
} }

View File

@@ -146,6 +146,9 @@ function init_ini(){
if ! grep -Eq "^mainsail_always_install_latest=" "${INI_FILE}"; then if ! grep -Eq "^mainsail_always_install_latest=" "${INI_FILE}"; then
echo -e "\nmainsail_always_install_latest=false\c" >> "${INI_FILE}" echo -e "\nmainsail_always_install_latest=false\c" >> "${INI_FILE}"
fi fi
if ! grep -Eq "^fluidd_always_install_latest=" "${INI_FILE}"; then
echo -e "\nfluidd_always_install_latest=false\c" >> "${INI_FILE}"
fi
fetch_webui_ports fetch_webui_ports
} }