mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-13 18:44:29 +05:00
103 lines
4.0 KiB
Bash
Executable File
103 lines
4.0 KiB
Bash
Executable File
install_mainsail(){
|
|
if [ "$INST_MAINSAIL" = "true" ]; then
|
|
#check if moonraker is already installed
|
|
check_moonraker
|
|
if [ "$MOONRAKER_SERVICE_FOUND" = "true" ]; then
|
|
#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
|
|
#creating the mainsail nginx cfg
|
|
set_nginx_cfg "mainsail"
|
|
test_nginx "$SET_LISTEN_PORT"
|
|
mainsail_setup && ok_msg "Mainsail installation complete!"; echo
|
|
fi
|
|
fi
|
|
}
|
|
|
|
check_moonraker(){
|
|
status_msg "Checking for Moonraker service ..."
|
|
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ]; then
|
|
ok_msg "Moonraker service found!"; echo
|
|
MOONRAKER_SERVICE_FOUND="true"
|
|
else
|
|
warn_msg "Moonraker service not found!"
|
|
warn_msg "Please install Moonraker first!"; echo
|
|
MOONRAKER_SERVICE_FOUND="false"
|
|
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}"
|
|
[ "$DWC2_ENABLED" = "true" ] && echo -e " ${cyan}● DWC2 - Port: $DWC2_PORT${default}"
|
|
if [ "$FLUIDD_PORT" = "80" ] || [ "$DWC2_PORT" = "80" ] || [ "$OCTOPRINT_PORT" = "80" ]; then
|
|
PORT_80_BLOCKED="true"
|
|
select_mainsail_port
|
|
fi
|
|
else
|
|
DEFAULT_PORT=$(grep listen ${SRCDIR}/kiauh/resources/mainsail_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 |"
|
|
[ "$DWC2_PORT" = "80" ] && echo "| ● DWC2 |"
|
|
blank_line
|
|
echo -e "| Make sure you don't choose a port which was already |"
|
|
echo -e "| assigned to one of the other web interfaces! |"
|
|
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" != "$DWC2_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
|
|
}
|
|
|
|
get_mainsail_ver(){
|
|
MAINSAIL_VERSION=$(curl -s https://api.github.com/repositories/240875926/tags | grep name | cut -d'"' -f4 | cut -d"v" -f2 | head -1)
|
|
}
|
|
|
|
mainsail_dl_url(){
|
|
get_mainsail_ver
|
|
MAINSAIL_URL=https://github.com/meteyou/mainsail/releases/download/v$MAINSAIL_VERSION/mainsail-beta-$MAINSAIL_VERSION.zip
|
|
}
|
|
|
|
mainsail_setup(){
|
|
mainsail_dl_url
|
|
#clean up an existing mainsail folder
|
|
[ -d $MAINSAIL_DIR ] && rm -rf $MAINSAIL_DIR
|
|
#create fresh mainsail folder and download mainsail
|
|
mkdir $MAINSAIL_DIR && cd $MAINSAIL_DIR
|
|
status_msg "Downloading Mainsail v$MAINSAIL_VERSION ..."
|
|
wget -O mainsail.zip $MAINSAIL_URL && status_msg "Extracting archive ..." && unzip -o mainsail.zip && rm mainsail.zip
|
|
### write mainsail version to file for update check reasons
|
|
echo "$MAINSAIL_VERSION" > $MAINSAIL_DIR/version
|
|
echo
|
|
} |