fix: rework klipper webui installers

This commit is contained in:
th33xitus
2020-10-28 20:39:34 +01:00
parent be2734e640
commit b48319e24d
6 changed files with 295 additions and 310 deletions

View File

@@ -8,13 +8,12 @@ install_moonraker(){
moonraker_setup
check_for_folder_moonraker
#setup configs
setup_printer_config_mainsail
setup_printer_config_moonraker
setup_moonraker_conf
#execute customizations
write_custom_trusted_clients
symlinks_moonraker
disable_octoprint
set_hostname
#after install actions
restart_moonraker
restart_klipper
@@ -32,17 +31,9 @@ system_check_moonraker(){
PRINTER_CFG_FOUND="false"
fi
#check for existing klippy.log symlink in /klipper_config
if [ ! -e ${HOME}/klipper_config/klippy.log ]; then
KLIPPY_SL_FOUND="false"
else
KLIPPY_SL_FOUND="true"
fi
[ ! -e ${HOME}/klipper_config/klippy.log ] && KLIPPY_SL_FOUND="false"
#check for existing moonraker.log symlink in /klipper_config
if [ ! -e ${HOME}/klipper_config/moonraker.log ]; then
MOONRAKER_SL_FOUND="false"
else
MOONRAKER_SL_FOUND="true"
fi
[ ! -e ${HOME}/klipper_config/moonraker.log ] && MOONRAKER_SL_FOUND="false"
#check for existing moonraker.conf
if [ ! -f ${HOME}/moonraker.conf ]; then
MOONRAKER_CONF_FOUND="false"
@@ -55,13 +46,9 @@ system_check_moonraker(){
OCTOPRINT_ENABLED="true"
fi
#check if haproxy is installed
if [[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]]; then
HAPROXY_FOUND="true"
fi
[[ $(dpkg-query -f'${Status}' --show haproxy 2>/dev/null) = *\ installed ]] && HAPROXY_FOUND="true"
#check if lighttpd is installed
if [[ $(dpkg-query -f'${Status}' --show lighttpd 2>/dev/null) = *\ installed ]]; then
LIGHTTPD_FOUND="true"
fi
[[ $(dpkg-query -f'${Status}' --show lighttpd 2>/dev/null) = *\ installed ]] && LIGHTTPD_FOUND="true"
}
get_user_selections_moonraker(){
@@ -158,25 +145,6 @@ get_user_selections_moonraker(){
print_msg && clear_msg;;
esac
done
#ask user for mainsail default macros
while true; do
unset ADD_MS_MACROS
echo
read -p "${cyan}###### Add the recommended Mainsail macros? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
echo -e "###### > Yes"
ADD_MS_MACROS="true"
break;;
N|n|No|no)
echo -e "###### > No"
ADD_MS_MACROS="false"
break;;
*)
print_unkown_cmd
print_msg && clear_msg;;
esac
done
#ask user to disable octoprint when such installed service was found
if [ "$OCTOPRINT_ENABLED" = "true" ]; then
unset DISABLE_OPRINT
@@ -274,9 +242,6 @@ moonraker_setup(){
dep=(wget curl unzip dfu-util nginx)
dependency_check
status_msg "Downloading Moonraker ..."
if [ -d $MOONRAKER_DIR ]; then
mv -f $MOONRAKER_DIR ${HOME}/moonraker_bak
fi
cd ${HOME} && git clone $MOONRAKER_REPO
ok_msg "Download complete!"
status_msg "Installing Moonraker ..."
@@ -354,7 +319,7 @@ check_for_folder_moonraker(){
#############################################################
#############################################################
setup_printer_config_mainsail(){
setup_printer_config_moonraker(){
if [ "$PRINTER_CFG_FOUND" = "true" ]; then
backup_printer_cfg
#copy printer.cfg to new location if
@@ -365,34 +330,20 @@ setup_printer_config_mainsail(){
ok_msg "printer.cfg location: '$PRINTER_CFG'"
ok_msg "Done!"
fi
#check printer.cfg for necessary mainsail entries
read_printer_cfg_mainsail
write_printer_cfg_mainsail
#check printer.cfg for necessary moonraker entries
read_printer_cfg "moonraker"
write_printer_cfg
fi
if [ "$SEL_DEF_CFG" = "true" ]; then
status_msg "Creating minimal default printer.cfg ..."
create_default_mainsail_printer_cfg
create_default_moonraker_printer_cfg
ok_msg "printer.cfg location: '$PRINTER_CFG'"
ok_msg "Done!"
fi
#copy mainsail_macro.cfg
if [ "$ADD_MS_MACROS" = "true" ]; then
status_msg "Create mainsail_macros.cfg ..."
if [ ! -f ${HOME}/klipper_config/mainsail_macros.cfg ]; then
cp ${HOME}/kiauh/resources/mainsail_macros.cfg ${HOME}/klipper_config
ok_msg "File created!"
else
warn_msg "File does already exist! Skipping ..."
fi
fi
}
read_printer_cfg_mainsail(){
sc_check(){
SC="#*# <---------------------- SAVE_CONFIG ---------------------->"
[ ! "$(grep '^\[virtual_sdcard\]$' $PRINTER_CFG)" ] && VSD="false"
[ ! "$(grep '^\[pause_resume\]$' $PRINTER_CFG)" ] && PAUSE_RESUME="false"
[ ! "$(grep '^\[display_status\]$' $PRINTER_CFG)" ] && DISPLAY_STATUS="false"
[ ! "$(grep '^\[include mainsail_macros\.cfg\]$' $PRINTER_CFG)" ] && MS_MACRO="false"
#check for a SAVE_CONFIG entry
if [[ $(grep "$SC" $PRINTER_CFG) ]]; then
SC_LINE=$(grep -n "$SC" $PRINTER_CFG | cut -d ":" -f1)
@@ -403,39 +354,39 @@ read_printer_cfg_mainsail(){
fi
}
write_printer_cfg_mainsail(){
read_printer_cfg(){
echo "selected: $1"
echo "pre sc"
sc_check
echo "past sc"
if [ "$1" = "moonraker" ]; then
echo "$1" && echo "moonraker"
[ ! "$(grep '^\[virtual_sdcard\]$' $PRINTER_CFG)" ] && VSD="false"
[ ! "$(grep '^\[pause_resume\]$' $PRINTER_CFG)" ] && PAUSE_RESUME="false"
[ ! "$(grep '^\[display_status\]$' $PRINTER_CFG)" ] && DISPLAY_STATUS="false"
elif [ "$1" = "mainsail" ] || [ "$1" = "fluidd" ]; then
echo "$1" && echo "mainsail/fluidd"
[ ! "$(grep '^\[include webui_macros\.cfg\]$' $PRINTER_CFG)" ] && WEBUI_MACROS="false"
fi
}
write_printer_cfg(){
unset write_entries
if [ "$MS_MACRO" = "false" ] && [ "$ADD_MS_MACROS" = "true" ]; then
write_entries+=("[include mainsail_macros.cfg]")
fi
if [ "$PAUSE_RESUME" = "false" ]; then
write_entries+=("[pause_resume]")
fi
if [ "$DISPLAY_STATUS" = "false" ]; then
write_entries+=("[display_status]")
fi
if [ "$VSD" = "false" ]; then
write_entries+=("[virtual_sdcard]\npath: ~/sdcard")
fi
if [ "${#write_entries[@]}" != "0" ]; then
write_entries+=("\\\n############################\n##### CREATED BY KIAUH #####\n############################")
write_entries=("############################\n" "${write_entries[@]}")
fi
#execute writing
status_msg "Writing to printer.cfg ..."
if [ "$SC_ENTRY" = "true" ]; then
PRE_SC_LINE="$(expr $SC_LINE - 1)a"
for entry in "${write_entries[@]}"
do
sed -i "$PRE_SC_LINE $entry" $PRINTER_CFG
done
fi
if [ "$SC_ENTRY" = "false" ]; then
LINE_COUNT="$(wc -l < $PRINTER_CFG)a"
for entry in "${write_entries[@]}"
do
sed -i "$LINE_COUNT $entry" $PRINTER_CFG
done
[ "$VSD" = "false" ] && write_entries+=("[virtual_sdcard]\npath: ~/sdcard")
[ "$PAUSE_RESUME" = "false" ] && write_entries+=("[pause_resume]")
[ "$DISPLAY_STATUS" = "false" ] && write_entries+=("[display_status]")
[ "$WEBUI_MACROS" = "false" ] && [ "$ADD_WEBUI_MACROS" = "true" ] && write_entries+=("[include webui_macros.cfg]")
[ "${#write_entries[@]}" != "0" ] && write_entries=("##### AUTOCREATED BY KIAUH #####" "${write_entries[@]}")
#write needed entries to kiauh.cfg
for entry in "${write_entries[@]}"; do echo -e "$entry" >> ~/klipper_config/kiauh.cfg; done
#execute writing to printer.cfg
if [ ! "$(grep '^\[include kiauh\.cfg\]$' $PRINTER_CFG)" ]; then
status_msg "Writing [include kiauh.cfg] to printer.cfg ..."
[ "$SC_ENTRY" = "false" ] && echo -e "\n\n[include kiauh.cfg]\c" >> $PRINTER_CFG
if [ "$SC_ENTRY" = "true" ]; then
PRE_SC_LINE="$(expr $SC_LINE - 1)a"
sed -i "$PRE_SC_LINE [include kiauh.cfg]" $PRINTER_CFG
fi
fi
ok_msg "Done!"
}
@@ -479,23 +430,16 @@ setup_moonraker_nginx_cfg(){
#############################################################
#############################################################
create_default_mainsail_printer_cfg(){
create_default_moonraker_printer_cfg(){
#create default config
touch ${HOME}/klipper_config/printer.cfg
cat <<DEFAULT_CFG >> ${HOME}/klipper_config/printer.cfg
##########################
### CREATED WITH KIAUH ###
##########################
### AUTOCREATED WITH KIAUH ###
[virtual_sdcard]
path: ~/sdcard
[pause_resume]
[display_status]
[include mainsail_macros.cfg]
##########################
##########################
DEFAULT_CFG
}