fix: littel rework for dwc2 installer etc.

This commit is contained in:
th33xitus
2020-11-13 20:48:57 +01:00
parent 065786fea7
commit 3fd9f95da3
3 changed files with 99 additions and 198 deletions

View File

@@ -22,6 +22,7 @@ locate_printer_cfg(){
PRINTER_CFG=$(while [ "$i" != "$KLIPPY_ARGS_COUNT" ]; do grep -E "(\/[A-Za-z0-9\_-]+)+\/printer\.cfg" /etc/default/klipper | cut -d" " -f"$i"; i=$(( $i + 1 )); done | grep "printer.cfg") PRINTER_CFG=$(while [ "$i" != "$KLIPPY_ARGS_COUNT" ]; do grep -E "(\/[A-Za-z0-9\_-]+)+\/printer\.cfg" /etc/default/klipper | cut -d" " -f"$i"; i=$(( $i + 1 )); done | grep "printer.cfg")
ok_msg "printer.cfg location: '$PRINTER_CFG'" ok_msg "printer.cfg location: '$PRINTER_CFG'"
elif [ -e $KLIPPER_SERVICE3 ]; then elif [ -e $KLIPPER_SERVICE3 ]; then
status_msg "Locating printer.cfg via $KLIPPER_SERVICE3 ..."
#reads /etc/systemd/system/klipper.service and gets the default printer.cfg location #reads /etc/systemd/system/klipper.service and gets the default printer.cfg location
KLIPPY_ARGS_LINE="$(grep "ExecStart=" /etc/systemd/system/klipper.service)" KLIPPY_ARGS_LINE="$(grep "ExecStart=" /etc/systemd/system/klipper.service)"
KLIPPY_ARGS_COUNT="$(grep -o " " <<< "$KLIPPY_ARGS_LINE" | wc -l)" KLIPPY_ARGS_COUNT="$(grep -o " " <<< "$KLIPPY_ARGS_LINE" | wc -l)"
@@ -260,29 +261,55 @@ install_gcode_shell_command(){
restart_klipper restart_klipper
} }
create_minimal_cfg(){
#create a minimal default config for either moonraker or dwc2
if [ "$SEL_DEF_CFG" = "true" ]; then
cat <<- EOF >> $PRINTER_CFG
[mcu]
serial: </dev/serial/by-id/your-mcu>
[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100
[virtual_sdcard]
path: ~/sdcard
[pause_resume]
[display_status]
EOF
fi
}
read_printer_cfg(){ read_printer_cfg(){
KIAUH_CFG=$(echo $PRINTER_CFG | sed 's/printer/kiauh/') KIAUH_CFG=$(echo $PRINTER_CFG | sed 's/printer/kiauh/')
if [ "$1" = "gcode_shell_command" ]; then [ ! -f $KIAUH_CFG ] && KIAUH_CFG_FOUND="false" || KIAUH_CFG_FOUND="true"
[ ! -f $KIAUH_CFG ] && KIAUH_CFG_FOUND="false" || KIAUH_CFG_FOUND="true" if [ -f $PRINTER_CFG ]; then
elif [ "$1" = "moonraker" ]; then if [ "$1" = "moonraker" ]; then
[ ! -f $KIAUH_CFG ] && KIAUH_CFG_FOUND="false" || KIAUH_CFG_FOUND="true" [ ! "$(grep '^\[virtual_sdcard\]$' $PRINTER_CFG)" ] && VSD="false" && EDIT_CFG="true"
[ ! "$(grep '^\[virtual_sdcard\]$' $PRINTER_CFG)" ] && VSD="false" [ ! "$(grep '^\[pause_resume\]$' $PRINTER_CFG)" ] && PAUSE_RESUME="false" && EDIT_CFG="true"
[ ! "$(grep '^\[pause_resume\]$' $PRINTER_CFG)" ] && PAUSE_RESUME="false" [ ! "$(grep '^\[display_status\]$' $PRINTER_CFG)" ] && DISPLAY_STATUS="false" && EDIT_CFG="true"
[ ! "$(grep '^\[display_status\]$' $PRINTER_CFG)" ] && DISPLAY_STATUS="false" elif [ "$1" = "mainsail" ] || [ "$1" = "fluidd" ]; then
elif [ "$1" = "mainsail" ] || [ "$1" = "fluidd" ]; then [ ! "$(grep '^\[include webui_macros\.cfg\]$' $PRINTER_CFG)" ] && WEBUI_MACROS="false" && EDIT_CFG="true"
[ ! -f $KIAUH_CFG ] && KIAUH_CFG_FOUND="false" || KIAUH_CFG_FOUND="true" elif [ "$1" = "dwc2" ]; then
[ ! "$(grep '^\[include webui_macros\.cfg\]$' $PRINTER_CFG)" ] && WEBUI_MACROS="false" [ ! "$(grep '^\[virtual_sdcard\]$' $PRINTER_CFG)" ] && VSD="false" && EDIT_CFG="true"
fi
fi fi
} }
write_printer_cfg(){ write_printer_cfg(){
#backup printer.cfg if edits will be written
[ "$EDIT_CFG" = "true" ] && backup_printer_cfg
#create kiauh.cfg if its needed and doesn't exist #create kiauh.cfg if its needed and doesn't exist
if [ "$KIAUH_CFG_FOUND" = "false" ]; then if [ "$KIAUH_CFG_FOUND" = "false" ] && [ "$EDIT_CFG" = "true" ]; then
status_msg "Creating kiauh.cfg ..." status_msg "Creating kiauh.cfg ..."
echo -e "##### AUTOCREATED BY KIAUH #####" > $KIAUH_CFG echo -e "##### AUTOCREATED BY KIAUH #####" > $KIAUH_CFG
fi fi
#write each entry to kiauh.cfg if it doesn't exist #write each entry to kiauh.cfg if it doesn't exist
#Moonraker related config options #Moonraker/DWC2 related config options
if [ "$VSD" = "false" ] && [[ ! $(grep '^\[virtual_sdcard\]$' $KIAUH_CFG) ]]; then if [ "$VSD" = "false" ] && [[ ! $(grep '^\[virtual_sdcard\]$' $KIAUH_CFG) ]]; then
echo -e "\n[virtual_sdcard]\npath: ~/sdcard" >> $KIAUH_CFG echo -e "\n[virtual_sdcard]\npath: ~/sdcard" >> $KIAUH_CFG
fi fi
@@ -309,9 +336,9 @@ write_printer_cfg(){
EOF EOF
fi fi
#including the kiauh.cfg into printer.cfg if not already done #including the kiauh.cfg into printer.cfg if not already done
if [ ! "$(grep '^\[include kiauh\.cfg\]$' $PRINTER_CFG)" ]; then if [ ! "$(grep '^\[include kiauh\.cfg\]$' $PRINTER_CFG)" ] && [ "$EDIT_CFG" = "true" ]; then
status_msg "Writing [include kiauh.cfg] to printer.cfg ..." status_msg "Writing [include kiauh.cfg] to printer.cfg ..."
sed -i '1 i ##### AUTOCREATED BY KIAUH #####\n[include kiauh.cfg]\n################################' $PRINTER_CFG sed -i '1 i ##### AUTOCREATED BY KIAUH #####\n[include kiauh.cfg]' $PRINTER_CFG
fi fi
ok_msg "Done!" ok_msg "Done!"
} }

View File

@@ -10,7 +10,7 @@ install_dwc2(){
stop_klipper stop_klipper
dwc2_setup dwc2_setup
#setup config #setup config
write_printer_cfg_dwc2 setup_printer_config_dwc2
#execute customizations #execute customizations
disable_octoprint disable_octoprint
set_nginx_cfg "dwc2" set_nginx_cfg "dwc2"
@@ -24,10 +24,9 @@ install_dwc2(){
system_check_dwc2(){ system_check_dwc2(){
status_msg "Initializing DWC2 installation ..." status_msg "Initializing DWC2 installation ..."
check_for_folder_dwc2
#check for existing printer.cfg #check for existing printer.cfg
locate_printer_cfg locate_printer_cfg
if [ ! -z $PRINTER_CFG ]; then if [ -f $PRINTER_CFG ]; then
PRINTER_CFG_FOUND="true" PRINTER_CFG_FOUND="true"
else else
PRINTER_CFG_FOUND="false" PRINTER_CFG_FOUND="false"
@@ -40,31 +39,30 @@ system_check_dwc2(){
get_user_selections_dwc2(){ get_user_selections_dwc2(){
#let user choose to install systemd or init.d service #let user choose to install systemd or init.d service
unset INST_SYSTEMD
unset INST_INITD
while true; do while true; do
echo echo
top_border top_border
echo -e "| Do you want to install dwc2-for-klipper-socket as |" echo -e "| Do you want to install dwc2-for-klipper-socket as |"
echo -e "| 1) Init.d Service |" echo -e "| 1) Init.d Service (default) |"
echo -e "| 2) Systemd Service |" echo -e "| 2) Systemd Service |"
hr hr
echo -e "| Please use the appropriate option for your chosen |" echo -e "| Please use the appropriate option for your chosen |"
echo -e "| Linux distribution. If you are unsure what to select, |" echo -e "| Linux distribution. If you are unsure what to select, |"
echo -e "| please do a research before. |" echo -e "| please do a research before. |"
hr hr
echo -e "| If you are using Raspberry Pi OS, either option 1 or |" echo -e "| If you run Raspberry Pi OS, both options will work. |"
echo -e "| 2 will work. |"
bottom_border bottom_border
read -p "${cyan}###### Please choose:${default} " action read -p "${cyan}###### Please choose:${default} " action
case "$action" in case "$action" in
1) 1|"")
INST_INITD="true" echo -e "###### > 1) Init.d"
INST_SYSTEMD="false" INST_DWC2_INITD="true"
INST_DWC2_SYSTEMD="false"
break;; break;;
2) 2)
INST_INITD="false" echo -e "###### > 1) Systemd"
INST_SYSTEMD="true" INST_DWC2_INITD="false"
INST_DWC2_SYSTEMD="true"
break;; break;;
*) *)
print_unkown_cmd print_unkown_cmd
@@ -73,7 +71,6 @@ get_user_selections_dwc2(){
done done
#user selection for printer.cfg #user selection for printer.cfg
if [ "$PRINTER_CFG_FOUND" = "false" ]; then if [ "$PRINTER_CFG_FOUND" = "false" ]; then
unset SEL_DEF_CFG
while true; do while true; do
echo echo
top_border top_border
@@ -101,15 +98,12 @@ get_user_selections_dwc2(){
esac esac
done done
fi fi
#
setup_printer_config_dwc2
#ask user to install reverse proxy #ask user to install reverse proxy
dwc2_reverse_proxy_dialog dwc2_reverse_proxy_dialog
#ask to change hostname #ask to change hostname
[ "$SET_NGINX_CFG" = "true" ] && create_custom_hostname [ "$SET_NGINX_CFG" = "true" ] && create_custom_hostname
#ask user to disable octoprint when such installed service was found #ask user to disable octoprint when such installed service was found
if [ "$OCTOPRINT_ENABLED" = "true" ]; then if [ "$OCTOPRINT_ENABLED" = "true" ]; then
unset DISABLE_OPRINT
while true; do while true; do
echo echo
warn_msg "OctoPrint service found!" warn_msg "OctoPrint service found!"
@@ -138,60 +132,37 @@ get_user_selections_dwc2(){
############################################################# #############################################################
############################################################# #############################################################
check_for_folder_dwc2(){
#check for needed folder
if [ ! -d $DWC2_DIR ]; then
mkdir -p $DWC2_DIR
fi
}
dwc2_setup(){ dwc2_setup(){
#check dependencies #check dependencies
dep=(git wget gzip tar curl) dep=(git wget gzip tar curl)
dependency_check dependency_check
#get dwc2-for-klipper #get dwc2-for-klipper
cd ${HOME}
status_msg "Cloning DWC2-for-Klipper-Socket repository ..." status_msg "Cloning DWC2-for-Klipper-Socket repository ..."
git clone $DWC2FK_REPO cd ${HOME} && git clone $DWC2FK_REPO
ok_msg "DWC2-for-Klipper successfully cloned!" ok_msg "DWC2-for-Klipper successfully cloned!"
#copy installers from kiauh srcdir to dwc-for-klipper-socket #copy installers from kiauh srcdir to dwc-for-klipper-socket
status_msg "Copy installers to $DWC2FK_DIR" status_msg "Copy installers to $DWC2FK_DIR"
cp -r ${SRCDIR}/kiauh/scripts/dwc2-for-klipper-socket-installer $DWC2FK_DIR/scripts cp -r ${SRCDIR}/kiauh/scripts/dwc2-for-klipper-socket-installer $DWC2FK_DIR/scripts
ok_msg "Done!" ok_msg "Done!"
status_msg "Starting service-installer ..." status_msg "Starting service-installer ..."
if [ "$INST_INITD" = "true" ] && [ "$INST_SYSTEMD" = "false" ]; then if [ "$INST_DWC2_INITD" = "true" ]; then
$DWC2FK_DIR/scripts/install-octopi.sh $DWC2FK_DIR/scripts/install-octopi.sh
elif [ "$INST_INITD" = "false" ] && [ "$INST_SYSTEMD" = "true" ]; then elif [ "$INST_DWC2_SYSTEMD" = "true" ]; then
$DWC2FK_DIR/scripts/install-debian.sh $DWC2FK_DIR/scripts/install-debian.sh
fi fi
ok_msg "Service installed!" ok_msg "Service installed!"
#patch /etc/default/klipper to append the uds argument #patch /etc/default/klipper to append the uds argument
patch_klipper_sysfile_dwc2 patch_klipper_sysfile "dwc2"
#download Duet Web Control #download Duet Web Control
download_dwc2_webui download_dwc2_webui
} }
patch_klipper_sysfile_dwc2(){
status_msg "Checking /etc/default/klipper for necessary entries ..."
#patching new UDS argument to /etc/default/klipper
if ! grep -q -- "-a /tmp/klippy_uds" $KLIPPER_SERVICE2; then
status_msg "Patching unix domain socket to /etc/default/klipper ..."
#append the new argument to /tmp/klippy.log argument
sudo sed -i "/KLIPPY_ARGS/s/\.log/\.log -a \/tmp\/klippy_uds/" $KLIPPER_SERVICE2
ok_msg "Patching done!"
else
ok_msg "No patching needed!"
fi
ok_msg "Check complete!"
echo
}
download_dwc2_webui(){ download_dwc2_webui(){
#get Duet Web Control #get Duet Web Control
GET_DWC2_URL=$(curl -s https://api.github.com/repositories/28820678/releases/latest | grep browser_download_url | cut -d'"' -f4) GET_DWC2_URL=$(curl -s https://api.github.com/repositories/28820678/releases/latest | grep browser_download_url | cut -d'"' -f4)
cd $DWC2_DIR
status_msg "Downloading DWC2 Web UI ..." status_msg "Downloading DWC2 Web UI ..."
wget $GET_DWC2_URL [ ! -d $DWC2_DIR ] && mkdir -p $DWC2_DIR
cd $DWC2_DIR && wget $GET_DWC2_URL
ok_msg "Download complete!" ok_msg "Download complete!"
status_msg "Unzipping archive ..." status_msg "Unzipping archive ..."
unzip -q -o *.zip unzip -q -o *.zip
@@ -214,80 +185,14 @@ download_dwc2_webui(){
setup_printer_config_dwc2(){ setup_printer_config_dwc2(){
if [ "$PRINTER_CFG_FOUND" = "true" ]; then if [ "$PRINTER_CFG_FOUND" = "true" ]; then
backup_printer_cfg
#check printer.cfg for necessary dwc2 entries #check printer.cfg for necessary dwc2 entries
read_printer_cfg_dwc2 read_printer_cfg "dwc2" && write_printer_cfg
fi fi
if [ "$SEL_DEF_CFG" = "true" ]; then if [ "$SEL_DEF_CFG" = "true" ]; then
create_default_dwc2_printer_cfg status_msg "Creating minimal default printer.cfg ..."
locate_printer_cfg create_minimal_cfg
fi ok_msg "printer.cfg location: '$PRINTER_CFG'"
} ok_msg "Done!"
read_printer_cfg_dwc2(){
unset SC_ENTRY
SC="#*# <---------------------- SAVE_CONFIG ---------------------->"
if [ ! $(grep '^\[virtual_sdcard\]$' $PRINTER_CFG) ]; then
VSD="false"
fi
#check for a SAVE_CONFIG entry
if [[ $(grep "$SC" $PRINTER_CFG) ]]; then
SC_LINE=$(grep -n "$SC" $PRINTER_CFG | cut -d ":" -f1)
PRE_SC_LINE=$(expr $SC_LINE - 1)
SC_ENTRY="true"
else
SC_ENTRY="false"
fi
}
write_printer_cfg_dwc2(){
unset write_entries
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
fi
ok_msg "Done!"
}
create_default_dwc2_printer_cfg(){
#create default config
if [ "$PRINTER_CFG_FOUND" = "false" ] && [ "$SEL_DEF_CFG" = "true" ]; then
touch $PRINTER_CFG
cat <<DEFAULT_DWC2_CFG >> $PRINTER_CFG
##########################
### CREATED WITH KIAUH ###
##########################
[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100
[virtual_sdcard]
path: ~/sdcard
##########################
DEFAULT_DWC2_CFG
fi fi
} }

View File

@@ -58,7 +58,6 @@ system_check_moonraker(){
get_user_selections_moonraker(){ get_user_selections_moonraker(){
#user selection for printer.cfg #user selection for printer.cfg
if [ "$PRINTER_CFG_FOUND" = "false" ]; then if [ "$PRINTER_CFG_FOUND" = "false" ]; then
unset SEL_DEF_CFG
while true; do while true; do
echo echo
top_border top_border
@@ -196,10 +195,6 @@ get_user_selections_moonraker(){
echo -e "| ${red}3) Skip this step (not recommended)${default} |" echo -e "| ${red}3) Skip this step (not recommended)${default} |"
bottom_border bottom_border
read -p "${cyan}###### Please choose:${default} " action read -p "${cyan}###### Please choose:${default} " action
unset REMOVE_HAPROXY
unset REMOVE_LIGHTTPD
unset DISABLE_HAPROXY
unset DISABLE_LIGHTTPD
case "$action" in case "$action" in
1) 1)
echo -e "###### > Remove packages" echo -e "###### > Remove packages"
@@ -255,7 +250,7 @@ moonraker_setup(){
#backup a possible existing printer.cfg at the old location #backup a possible existing printer.cfg at the old location
#and before patching in the new location #and before patching in the new location
backup_printer_cfg backup_printer_cfg
patch_klipper_sysfile patch_klipper_sysfile "moonraker"
#re-run printer.cfg location function to read the new path for the printer.cfg #re-run printer.cfg location function to read the new path for the printer.cfg
locate_printer_cfg locate_printer_cfg
echo; ok_msg "Moonraker successfully installed!" echo; ok_msg "Moonraker successfully installed!"
@@ -265,37 +260,45 @@ patch_klipper_sysfile(){
if [ -e $KLIPPER_SERVICE2 ]; then if [ -e $KLIPPER_SERVICE2 ]; then
status_msg "Checking /etc/default/klipper for necessary entries ..." status_msg "Checking /etc/default/klipper for necessary entries ..."
#patching new printer.cfg location to /etc/default/klipper #patching new printer.cfg location to /etc/default/klipper
if ! grep -q "/klipper_config/printer.cfg" $KLIPPER_SERVICE2; then if [ "$1" = "moonraker" ]; then
status_msg "Patching new printer.cfg location to /etc/default/klipper ..." if ! grep -q "/klipper_config/printer.cfg" $KLIPPER_SERVICE2; then
sudo sed -i "/KLIPPY_ARGS=/ s|$PRINTER_CFG|/home/${USER}/klipper_config/printer.cfg|" $KLIPPER_SERVICE2 status_msg "Patching new printer.cfg location to /etc/default/klipper ..."
ok_msg "New location is: '/home/${USER}/klipper_config/printer.cfg'" sudo sed -i "/KLIPPY_ARGS=/ s|$PRINTER_CFG|/home/${USER}/klipper_config/printer.cfg|" $KLIPPER_SERVICE2
ok_msg "New location is: '/home/${USER}/klipper_config/printer.cfg'"
fi
fi fi
#patching new UDS argument to /etc/default/klipper #patching new UDS argument to /etc/default/klipper
if ! grep -q -- "-a /tmp/klippy_uds" $KLIPPER_SERVICE2; then if [ "$1" = "moonraker" ] || [ "$1" = "dwc2" ]; then
status_msg "Patching unix domain socket to /etc/default/klipper ..." if ! grep -q -- "-a /tmp/klippy_uds" $KLIPPER_SERVICE2; then
#append the new argument to /tmp/klippy.log argument status_msg "Patching unix domain socket to /etc/default/klipper ..."
sudo sed -i "/KLIPPY_ARGS/s/\.log/\.log -a \/tmp\/klippy_uds/" $KLIPPER_SERVICE2 #append the new argument to /tmp/klippy.log argument
ok_msg "Patching done!" sudo sed -i "/KLIPPY_ARGS/s/\.log/\.log -a \/tmp\/klippy_uds/" $KLIPPER_SERVICE2
ok_msg "Patching done!"
fi
fi fi
fi fi
if [ -e $KLIPPER_SERVICE3 ]; then if [ -e $KLIPPER_SERVICE3 ]; then
status_msg "Checking /etc/systemd/system/klipper.service for necessary entries ..." status_msg "Checking /etc/systemd/system/klipper.service for necessary entries ..."
#patching new printer.cfg location to /etc/systemd/system/klipper.service #patching new printer.cfg location to /etc/systemd/system/klipper.service
if ! grep -q "/klipper_config/printer.cfg" $KLIPPER_SERVICE3; then if [ "$1" = "moonraker" ]; then
status_msg "Patching new printer.cfg location to /etc/systemd/system/klipper.service ..." if ! grep -q "/klipper_config/printer.cfg" $KLIPPER_SERVICE3; then
sudo sed -i "/ExecStart=/ s|$PRINTER_CFG|/home/${USER}/klipper_config/printer.cfg|" $KLIPPER_SERVICE3 status_msg "Patching new printer.cfg location to /etc/systemd/system/klipper.service ..."
ok_msg "New location is: '/home/${USER}/klipper_config/printer.cfg'" sudo sed -i "/ExecStart=/ s|$PRINTER_CFG|/home/${USER}/klipper_config/printer.cfg|" $KLIPPER_SERVICE3
#set variable if file got edited ok_msg "New location is: '/home/${USER}/klipper_config/printer.cfg'"
SERVICE_FILE_PATCHED="true" #set variable if file got edited
SERVICE_FILE_PATCHED="true"
fi
fi fi
#patching new UDS argument to /etc/systemd/system/klipper.service #patching new UDS argument to /etc/systemd/system/klipper.service
if ! grep -q -- "-a /tmp/klippy_uds" $KLIPPER_SERVICE3; then if [ "$1" = "moonraker" ] || [ "$1" = "dwc2" ]; then
status_msg "Patching unix domain socket to /etc/systemd/system/klipper.service ..." if ! grep -q -- "-a /tmp/klippy_uds" $KLIPPER_SERVICE3; then
#append the new argument to /tmp/klippy.log argument status_msg "Patching unix domain socket to /etc/systemd/system/klipper.service ..."
sudo sed -i "/ExecStart/s/\.log/\.log -a \/tmp\/klippy_uds/" $KLIPPER_SERVICE3 #append the new argument to /tmp/klippy.log argument
ok_msg "Patching done!" sudo sed -i "/ExecStart/s/\.log/\.log -a \/tmp\/klippy_uds/" $KLIPPER_SERVICE3
#set variable if file got edited ok_msg "Patching done!"
SERVICE_FILE_PATCHED="true" #set variable if file got edited
SERVICE_FILE_PATCHED="true"
fi
fi fi
#reloading the units is only needed when the service file was patched. #reloading the units is only needed when the service file was patched.
[ "$SERVICE_FILE_PATCHED" = "true" ] && status_msg "Reloading unit ..." && sudo systemctl daemon-reload [ "$SERVICE_FILE_PATCHED" = "true" ] && status_msg "Reloading unit ..." && sudo systemctl daemon-reload
@@ -324,9 +327,7 @@ check_for_folder_moonraker(){
setup_printer_config_moonraker(){ setup_printer_config_moonraker(){
if [ "$PRINTER_CFG_FOUND" = "true" ]; then if [ "$PRINTER_CFG_FOUND" = "true" ]; then
backup_printer_cfg #copy printer.cfg to new location if there is no printer.cfg at the new location already
#copy printer.cfg to new location if
#there is no printer.cfg at the new location already
if [ -f ${HOME}/printer.cfg ] && [ ! -f ${HOME}/klipper_config/printer.cfg ]; then if [ -f ${HOME}/printer.cfg ] && [ ! -f ${HOME}/klipper_config/printer.cfg ]; then
status_msg "Copy printer.cfg to new location ..." status_msg "Copy printer.cfg to new location ..."
cp ${HOME}/printer.cfg $PRINTER_CFG cp ${HOME}/printer.cfg $PRINTER_CFG
@@ -334,12 +335,11 @@ setup_printer_config_moonraker(){
ok_msg "Done!" ok_msg "Done!"
fi fi
#check printer.cfg for necessary moonraker entries #check printer.cfg for necessary moonraker entries
read_printer_cfg "moonraker" read_printer_cfg "moonraker" && write_printer_cfg
write_printer_cfg
fi fi
if [ "$SEL_DEF_CFG" = "true" ]; then if [ "$SEL_DEF_CFG" = "true" ]; then
status_msg "Creating minimal default printer.cfg ..." status_msg "Creating minimal default printer.cfg ..."
create_default_moonraker_printer_cfg create_minimal_cfg
ok_msg "printer.cfg location: '$PRINTER_CFG'" ok_msg "printer.cfg location: '$PRINTER_CFG'"
ok_msg "Done!" ok_msg "Done!"
fi fi
@@ -357,7 +357,6 @@ setup_moonraker_conf(){
#check for at least one trusted client in an already existing moonraker.conf #check for at least one trusted client in an already existing moonraker.conf
#in no entry is found, write default trusted client #in no entry is found, write default trusted client
if [ "$MOONRAKER_CONF_FOUND" = "true" ]; then if [ "$MOONRAKER_CONF_FOUND" = "true" ]; then
backup_moonraker_conf
if grep "trusted_clients:" ${HOME}/moonraker.conf -q; then if grep "trusted_clients:" ${HOME}/moonraker.conf -q; then
TC_LINE=$(grep -n "trusted_clients:" ${HOME}/moonraker.conf | cut -d ":" -f1) TC_LINE=$(grep -n "trusted_clients:" ${HOME}/moonraker.conf | cut -d ":" -f1)
FIRST_IP_LINE=$(expr $TC_LINE + 1) FIRST_IP_LINE=$(expr $TC_LINE + 1)
@@ -365,7 +364,7 @@ setup_moonraker_conf(){
#if [[ ! $FIRST_IP =~ ([0-9].[0-9].[0-9].[0-9]) ]]; then #if [[ ! $FIRST_IP =~ ([0-9].[0-9].[0-9].[0-9]) ]]; then
if [ "$FIRST_IP" = "" ]; then if [ "$FIRST_IP" = "" ]; then
status_msg "Writing trusted clients to config ..." status_msg "Writing trusted clients to config ..."
write_default_trusted_clients backup_moonraker_conf && write_default_trusted_clients
ok_msg "Trusted clients written!" ok_msg "Trusted clients written!"
fi fi
fi fi
@@ -384,19 +383,6 @@ setup_moonraker_nginx_cfg(){
############################################################# #############################################################
############################################################# #############################################################
create_default_moonraker_printer_cfg(){
#create default config
touch ${HOME}/klipper_config/printer.cfg
cat <<DEFAULT_CFG >> ${HOME}/klipper_config/printer.cfg
### AUTOCREATED WITH KIAUH ###
[virtual_sdcard]
path: ~/sdcard
[pause_resume]
[display_status]
DEFAULT_CFG
}
write_default_trusted_clients(){ write_default_trusted_clients(){
DEFAULT_IP=$(hostname -I) DEFAULT_IP=$(hostname -I)
status_msg "Your devices current IP adress is:\n${cyan}$DEFAULT_IP ${default}" status_msg "Your devices current IP adress is:\n${cyan}$DEFAULT_IP ${default}"
@@ -538,20 +524,3 @@ handle_haproxy_lighttpd(){
fi fi
fi fi
} }
#############################################################
#############################################################
#test_api(){
# HOST_IP=$(hostname -I | cut -d" " -f1)
# status_msg "Testing API ..."
# status_msg "Please wait ..."
# sleep 15
# status_msg "API response from http://"$HOST_IP":7125/printer/info :"
# echo -e "${cyan}$(curl -s "http://"$HOST_IP":7125/printer/info")${default}"
# if [ $(curl -s "http://"$HOST_IP":7125/printer/info" | grep '^{"result"' -c) -eq 1 ]; then
# echo; ok_msg "Klipper API is working correctly!"; echo
# else
# echo; warn_msg "Klipper API not working correctly!"; echo
# fi
#}