mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-15 19:44:29 +05:00
fix: bigger refactoring of the klipper webui installer
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
check_moonraker(){
|
check_moonraker(){
|
||||||
status_msg "Checking for Moonraker service ..."
|
status_msg "Checking for Moonraker service ..."
|
||||||
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ]; then
|
if [ "$(systemctl list-units --full -all -t service --no-legend | grep -F "moonraker.service")" ] || [ "$(systemctl list-units --full -all -t service --no-legend | grep -E "moonraker-[[:digit:]].service")" ]; then
|
||||||
ok_msg "Moonraker service found!"; echo
|
ok_msg "Moonraker service found!"; echo
|
||||||
MOONRAKER_SERVICE_FOUND="true"
|
MOONRAKER_SERVICE_FOUND="true"
|
||||||
else
|
else
|
||||||
@@ -10,86 +10,104 @@ check_moonraker(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
get_user_selection_webui(){
|
# get_user_selection_webui(){
|
||||||
#ask user for webui default macros
|
# #ask user for webui default macros
|
||||||
while true; do
|
# while true; do
|
||||||
unset ADD_WEBUI_MACROS
|
# unset ADD_WEBUI_MACROS
|
||||||
echo
|
# echo
|
||||||
top_border
|
# top_border
|
||||||
echo -e "| It is recommended to have some important macros to |"
|
# echo -e "| It is recommended to have some important macros to |"
|
||||||
echo -e "| have full functionality of the web interface. |"
|
# echo -e "| have full functionality of the web interface. |"
|
||||||
blank_line
|
# blank_line
|
||||||
echo -e "| If you do not have such macros, you can choose to |"
|
# echo -e "| If you do not have such macros, you can choose to |"
|
||||||
echo -e "| install the suggested default macros now. |"
|
# echo -e "| install the suggested default macros now. |"
|
||||||
bottom_border
|
# bottom_border
|
||||||
read -p "${cyan}###### Add the recommended macros? (Y/n):${default} " yn
|
# read -p "${cyan}###### Add the recommended macros? (Y/n):${default} " yn
|
||||||
case "$yn" in
|
# case "$yn" in
|
||||||
Y|y|Yes|yes|"")
|
# Y|y|Yes|yes|"")
|
||||||
echo -e "###### > Yes"
|
# echo -e "###### > Yes"
|
||||||
ADD_WEBUI_MACROS="true"
|
# ADD_WEBUI_MACROS="true"
|
||||||
break;;
|
# break;;
|
||||||
N|n|No|no)
|
# N|n|No|no)
|
||||||
echo -e "###### > No"
|
# echo -e "###### > No"
|
||||||
ADD_WEBUI_MACROS="false"
|
# ADD_WEBUI_MACROS="false"
|
||||||
break;;
|
# break;;
|
||||||
*)
|
# *)
|
||||||
print_unkown_cmd
|
# print_unkown_cmd
|
||||||
print_msg && clear_msg;;
|
# print_msg && clear_msg;;
|
||||||
esac
|
# esac
|
||||||
done
|
# done
|
||||||
}
|
# }
|
||||||
|
|
||||||
install_mainsail(){
|
install_mainsail(){
|
||||||
get_user_selection_webui
|
###! outdated dialog, see comment below regarding webui macros
|
||||||
#check if moonraker is already installed
|
#get_user_selection_webui
|
||||||
|
|
||||||
|
### check if moonraker is already installed
|
||||||
check_moonraker
|
check_moonraker
|
||||||
|
|
||||||
if [ "$MOONRAKER_SERVICE_FOUND" = "true" ]; then
|
if [ "$MOONRAKER_SERVICE_FOUND" = "true" ]; then
|
||||||
#check for other enabled web interfaces
|
### check for other enabled web interfaces
|
||||||
unset SET_LISTEN_PORT
|
unset SET_LISTEN_PORT
|
||||||
detect_enabled_sites
|
detect_enabled_sites
|
||||||
#check if another site already listens to port 80
|
|
||||||
|
### check if another site already listens to port 80
|
||||||
mainsail_port_check
|
mainsail_port_check
|
||||||
#creating the mainsail nginx cfg
|
|
||||||
|
### creating the mainsail nginx cfg
|
||||||
set_nginx_cfg "mainsail"
|
set_nginx_cfg "mainsail"
|
||||||
#test_nginx "$SET_LISTEN_PORT"
|
|
||||||
locate_printer_cfg && read_printer_cfg "mainsail"
|
###! outdated way of locating the printer.cfg. need a new way to install the webui-macros
|
||||||
install_webui_macros
|
###! especially for multi instances, therefore disabling this function for now...
|
||||||
|
#locate_printer_cfg && read_printer_cfg "mainsail"
|
||||||
|
#install_webui_macros
|
||||||
|
|
||||||
|
### install mainsail
|
||||||
mainsail_setup
|
mainsail_setup
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
install_fluidd(){
|
install_fluidd(){
|
||||||
get_user_selection_webui
|
###! outdated dialog, see comment below regarding webui macros
|
||||||
#check if moonraker is already installed
|
#get_user_selection_webui
|
||||||
|
|
||||||
|
### check if moonraker is already installed
|
||||||
check_moonraker
|
check_moonraker
|
||||||
|
|
||||||
if [ "$MOONRAKER_SERVICE_FOUND" = "true" ]; then
|
if [ "$MOONRAKER_SERVICE_FOUND" = "true" ]; then
|
||||||
#check for other enabled web interfaces
|
### check for other enabled web interfaces
|
||||||
unset SET_LISTEN_PORT
|
unset SET_LISTEN_PORT
|
||||||
detect_enabled_sites
|
detect_enabled_sites
|
||||||
#check if another site already listens to port 80
|
|
||||||
|
### check if another site already listens to port 80
|
||||||
fluidd_port_check
|
fluidd_port_check
|
||||||
#creating the fluidd nginx cfg
|
|
||||||
|
### creating the fluidd nginx cfg
|
||||||
set_nginx_cfg "fluidd"
|
set_nginx_cfg "fluidd"
|
||||||
#test_nginx "$SET_LISTEN_PORT"
|
|
||||||
locate_printer_cfg && read_printer_cfg "fluidd"
|
###! outdated way of locating the printer.cfg. need a new way to install the webui-macros
|
||||||
install_webui_macros
|
###! especially for multi instances, therefore disabling this function for now...
|
||||||
|
#locate_printer_cfg && read_printer_cfg "fluidd"
|
||||||
|
#install_webui_macros
|
||||||
|
|
||||||
|
### install fluidd
|
||||||
fluidd_setup
|
fluidd_setup
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
install_webui_macros(){
|
# install_webui_macros(){
|
||||||
#copy webui_macros.cfg
|
# #copy webui_macros.cfg
|
||||||
if [ "$ADD_WEBUI_MACROS" = "true" ]; then
|
# if [ "$ADD_WEBUI_MACROS" = "true" ]; then
|
||||||
status_msg "Create webui_macros.cfg ..."
|
# status_msg "Create webui_macros.cfg ..."
|
||||||
if [ ! -f ${HOME}/klipper_config/webui_macros.cfg ]; then
|
# if [ ! -f ${HOME}/klipper_config/webui_macros.cfg ]; then
|
||||||
cp ${HOME}/kiauh/resources/webui_macros.cfg ${HOME}/klipper_config
|
# cp ${HOME}/kiauh/resources/webui_macros.cfg ${HOME}/klipper_config
|
||||||
ok_msg "File created!"
|
# ok_msg "File created!"
|
||||||
else
|
# else
|
||||||
warn_msg "File already exists! Skipping ..."
|
# warn_msg "File already exists! Skipping ..."
|
||||||
fi
|
# fi
|
||||||
fi
|
# fi
|
||||||
write_printer_cfg
|
# write_printer_cfg
|
||||||
}
|
# }
|
||||||
|
|
||||||
mainsail_port_check(){
|
mainsail_port_check(){
|
||||||
if [ "$MAINSAIL_ENABLED" = "false" ]; then
|
if [ "$MAINSAIL_ENABLED" = "false" ]; then
|
||||||
@@ -204,75 +222,82 @@ get_fluidd_ver(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
mainsail_setup(){
|
mainsail_setup(){
|
||||||
#get mainsail download url
|
### get mainsail download url
|
||||||
MAINSAIL_DL_URL=$(curl -s https://api.github.com/repositories/240875926/releases | grep browser_download_url | cut -d'"' -f4 | head -1)
|
MAINSAIL_DL_URL=$(curl -s https://api.github.com/repositories/240875926/releases | grep browser_download_url | cut -d'"' -f4 | head -1)
|
||||||
#clean up an existing mainsail folder
|
|
||||||
|
### remove existing and create fresh mainsail folder, then download mainsail
|
||||||
[ -d $MAINSAIL_DIR ] && rm -rf $MAINSAIL_DIR
|
[ -d $MAINSAIL_DIR ] && rm -rf $MAINSAIL_DIR
|
||||||
#create fresh mainsail folder and download mainsail
|
|
||||||
mkdir $MAINSAIL_DIR && cd $MAINSAIL_DIR
|
mkdir $MAINSAIL_DIR && cd $MAINSAIL_DIR
|
||||||
status_msg "Downloading Mainsail $MAINSAIL_VERSION ..."
|
status_msg "Downloading Mainsail $MAINSAIL_VERSION ..."
|
||||||
wget $MAINSAIL_DL_URL && ok_msg "Download complete!"
|
wget $MAINSAIL_DL_URL && ok_msg "Download complete!"
|
||||||
#extract archive
|
|
||||||
|
### 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
|
|
||||||
|
### delete downloaded zip
|
||||||
status_msg "Remove downloaded archive ..."
|
status_msg "Remove downloaded archive ..."
|
||||||
rm -rf *.zip && ok_msg "Done!" && ok_msg "Mainsail installation complete!"
|
rm -rf *.zip && ok_msg "Done!" && ok_msg "Mainsail installation complete!"
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
fluidd_setup(){
|
fluidd_setup(){
|
||||||
#get fluidd download url
|
### get fluidd download url
|
||||||
FLUIDD_DL_URL=$(curl -s https://api.github.com/repositories/295836951/releases/latest | grep browser_download_url | cut -d'"' -f4)
|
FLUIDD_DL_URL=$(curl -s https://api.github.com/repositories/295836951/releases/latest | grep browser_download_url | cut -d'"' -f4)
|
||||||
#clean up an existing fluidd folder
|
|
||||||
|
### remove existing and create fresh fluidd folder, then download fluidd
|
||||||
[ -d $FLUIDD_DIR ] && rm -rf $FLUIDD_DIR
|
[ -d $FLUIDD_DIR ] && rm -rf $FLUIDD_DIR
|
||||||
#create fresh fluidd folder and download fluidd
|
|
||||||
mkdir $FLUIDD_DIR && cd $FLUIDD_DIR
|
mkdir $FLUIDD_DIR && cd $FLUIDD_DIR
|
||||||
status_msg "Downloading Fluidd $FLUIDD_VERSION ..."
|
status_msg "Downloading Fluidd $FLUIDD_VERSION ..."
|
||||||
wget $FLUIDD_DL_URL && ok_msg "Download complete!"
|
wget $FLUIDD_DL_URL && ok_msg "Download complete!"
|
||||||
#extract archive
|
|
||||||
|
### extract archive
|
||||||
status_msg "Extracting archive ..."
|
status_msg "Extracting archive ..."
|
||||||
unzip -q -o *.zip && ok_msg "Done!"
|
unzip -q -o *.zip && ok_msg "Done!"
|
||||||
#patch moonraker.conf to apply cors domains if needed
|
|
||||||
backup_moonraker_conf
|
###! this will be difficult to achieve for multi instances, so i will disable those functions for now....
|
||||||
patch_moonraker
|
###! will be probably easier to tell the user to simply re-install moonraker, those entries will be there then.
|
||||||
#delete downloaded zip
|
### patch moonraker.conf to apply cors domains if needed
|
||||||
|
#backup_moonraker_conf
|
||||||
|
#patch_moonraker
|
||||||
|
|
||||||
|
### delete downloaded zip
|
||||||
status_msg "Remove downloaded archive ..."
|
status_msg "Remove downloaded archive ..."
|
||||||
rm -rf *.zip && ok_msg "Done!" && ok_msg "Fluidd installation complete!"
|
rm -rf *.zip && ok_msg "Done!" && ok_msg "Fluidd installation complete!"
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
patch_moonraker(){
|
# patch_moonraker(){
|
||||||
status_msg "Patching moonraker.conf ..."
|
# status_msg "Patching moonraker.conf ..."
|
||||||
mr_conf=${HOME}/moonraker.conf
|
# mr_conf=${HOME}/moonraker.conf
|
||||||
# remove the now deprecated enable_cors option from moonraker.conf if it still exists
|
# # remove the now deprecated enable_cors option from moonraker.conf if it still exists
|
||||||
if [ "$(grep "^enable_cors:" $mr_conf)" ]; then
|
# if [ "$(grep "^enable_cors:" $mr_conf)" ]; then
|
||||||
line="$(grep -n "^enable_cors:" ~/moonraker.conf | cut -d":" -f1)d"
|
# line="$(grep -n "^enable_cors:" ~/moonraker.conf | cut -d":" -f1)d"
|
||||||
sed -i "$line" $mr_conf && mr_restart="true"
|
# sed -i "$line" $mr_conf && mr_restart="true"
|
||||||
fi
|
# fi
|
||||||
# looking for a cors_domain entry in moonraker.conf
|
# # looking for a cors_domain entry in moonraker.conf
|
||||||
if [ ! "$(grep "^cors_domains:$" $mr_conf)" ]; then
|
# if [ ! "$(grep "^cors_domains:$" $mr_conf)" ]; then
|
||||||
#find trusted_clients line number and subtract one, to insert cors_domains later
|
# #find trusted_clients line number and subtract one, to insert cors_domains later
|
||||||
line="$(grep -n "^trusted_clients:$" $mr_conf | cut -d":" -f1)i"
|
# line="$(grep -n "^trusted_clients:$" $mr_conf | cut -d":" -f1)i"
|
||||||
sed -i "$line cors_domains:" $mr_conf && mr_restart="true"
|
# sed -i "$line cors_domains:" $mr_conf && mr_restart="true"
|
||||||
fi
|
# fi
|
||||||
if [ "$(grep "^cors_domains:$" $mr_conf)" ]; then
|
# if [ "$(grep "^cors_domains:$" $mr_conf)" ]; then
|
||||||
hostname=$(hostname -I | cut -d" " -f1)
|
# hostname=$(hostname -I | cut -d" " -f1)
|
||||||
url1="\ \ \ \ http://*.local"
|
# url1="\ \ \ \ http://*.local"
|
||||||
url2="\ \ \ \ http://app.fluidd.xyz"
|
# url2="\ \ \ \ http://app.fluidd.xyz"
|
||||||
url3="\ \ \ \ https://app.fluidd.xyz"
|
# url3="\ \ \ \ https://app.fluidd.xyz"
|
||||||
url4="\ \ \ \ http://$hostname:*"
|
# url4="\ \ \ \ http://$hostname:*"
|
||||||
#find cors_domains line number and add one, to insert urls later
|
# #find cors_domains line number and add one, to insert urls later
|
||||||
line="$(expr $(grep -n "cors_domains:" $mr_conf | cut -d":" -f1) + 1)i"
|
# line="$(expr $(grep -n "cors_domains:" $mr_conf | cut -d":" -f1) + 1)i"
|
||||||
[ ! "$(grep -E '^\s+http:\/\/\*\.local$' $mr_conf)" ] && sed -i "$line $url1" $mr_conf && mr_restart="true"
|
# [ ! "$(grep -E '^\s+http:\/\/\*\.local$' $mr_conf)" ] && sed -i "$line $url1" $mr_conf && mr_restart="true"
|
||||||
[ ! "$(grep -E '^\s+http:\/\/app\.fluidd\.xyz$' $mr_conf)" ] && sed -i "$line $url2" $mr_conf && mr_restart="true"
|
# [ ! "$(grep -E '^\s+http:\/\/app\.fluidd\.xyz$' $mr_conf)" ] && sed -i "$line $url2" $mr_conf && mr_restart="true"
|
||||||
[ ! "$(grep -E '^\s+https:\/\/app\.fluidd\.xyz$' $mr_conf)" ] && sed -i "$line $url3" $mr_conf && mr_restart="true"
|
# [ ! "$(grep -E '^\s+https:\/\/app\.fluidd\.xyz$' $mr_conf)" ] && sed -i "$line $url3" $mr_conf && mr_restart="true"
|
||||||
[ ! "$(grep -E '^\s+http:\/\/([0-9]{1,3}\.){3}[0-9]{1,3}' $mr_conf)" ] && sed -i "$line $url4" $mr_conf && mr_restart="true"
|
# [ ! "$(grep -E '^\s+http:\/\/([0-9]{1,3}\.){3}[0-9]{1,3}' $mr_conf)" ] && sed -i "$line $url4" $mr_conf && mr_restart="true"
|
||||||
fi
|
# fi
|
||||||
#restart moonraker service if mr_restart was set to true
|
# #restart moonraker service if mr_restart was set to true
|
||||||
if [[ $mr_restart == "true" ]]; then
|
# if [[ $mr_restart == "true" ]]; then
|
||||||
ok_msg "Patching done!" && restart_moonraker
|
# ok_msg "Patching done!" && restart_moonraker
|
||||||
else
|
# else
|
||||||
ok_msg "No patching was needed!"
|
# ok_msg "No patching was needed!"
|
||||||
fi
|
# fi
|
||||||
}
|
# }
|
||||||
|
|||||||
Reference in New Issue
Block a user