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")
ok_msg "printer.cfg location: '$PRINTER_CFG'"
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
KLIPPY_ARGS_LINE="$(grep "ExecStart=" /etc/systemd/system/klipper.service)"
KLIPPY_ARGS_COUNT="$(grep -o " " <<< "$KLIPPY_ARGS_LINE" | wc -l)"
@@ -260,29 +261,55 @@ install_gcode_shell_command(){
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(){
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"
elif [ "$1" = "moonraker" ]; then
[ ! -f $KIAUH_CFG ] && KIAUH_CFG_FOUND="false" || KIAUH_CFG_FOUND="true"
[ ! "$(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
[ ! -f $KIAUH_CFG ] && KIAUH_CFG_FOUND="false" || KIAUH_CFG_FOUND="true"
[ ! "$(grep '^\[include webui_macros\.cfg\]$' $PRINTER_CFG)" ] && WEBUI_MACROS="false"
[ ! -f $KIAUH_CFG ] && KIAUH_CFG_FOUND="false" || KIAUH_CFG_FOUND="true"
if [ -f $PRINTER_CFG ]; then
if [ "$1" = "moonraker" ]; then
[ ! "$(grep '^\[virtual_sdcard\]$' $PRINTER_CFG)" ] && VSD="false" && EDIT_CFG="true"
[ ! "$(grep '^\[pause_resume\]$' $PRINTER_CFG)" ] && PAUSE_RESUME="false" && EDIT_CFG="true"
[ ! "$(grep '^\[display_status\]$' $PRINTER_CFG)" ] && DISPLAY_STATUS="false" && EDIT_CFG="true"
elif [ "$1" = "mainsail" ] || [ "$1" = "fluidd" ]; then
[ ! "$(grep '^\[include webui_macros\.cfg\]$' $PRINTER_CFG)" ] && WEBUI_MACROS="false" && EDIT_CFG="true"
elif [ "$1" = "dwc2" ]; then
[ ! "$(grep '^\[virtual_sdcard\]$' $PRINTER_CFG)" ] && VSD="false" && EDIT_CFG="true"
fi
fi
}
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
if [ "$KIAUH_CFG_FOUND" = "false" ]; then
if [ "$KIAUH_CFG_FOUND" = "false" ] && [ "$EDIT_CFG" = "true" ]; then
status_msg "Creating kiauh.cfg ..."
echo -e "##### AUTOCREATED BY KIAUH #####" > $KIAUH_CFG
fi
#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
echo -e "\n[virtual_sdcard]\npath: ~/sdcard" >> $KIAUH_CFG
fi
@@ -309,9 +336,9 @@ write_printer_cfg(){
EOF
fi
#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 ..."
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
ok_msg "Done!"
}

View File

@@ -10,7 +10,7 @@ install_dwc2(){
stop_klipper
dwc2_setup
#setup config
write_printer_cfg_dwc2
setup_printer_config_dwc2
#execute customizations
disable_octoprint
set_nginx_cfg "dwc2"
@@ -24,10 +24,9 @@ install_dwc2(){
system_check_dwc2(){
status_msg "Initializing DWC2 installation ..."
check_for_folder_dwc2
#check for existing printer.cfg
locate_printer_cfg
if [ ! -z $PRINTER_CFG ]; then
if [ -f $PRINTER_CFG ]; then
PRINTER_CFG_FOUND="true"
else
PRINTER_CFG_FOUND="false"
@@ -40,31 +39,30 @@ system_check_dwc2(){
get_user_selections_dwc2(){
#let user choose to install systemd or init.d service
unset INST_SYSTEMD
unset INST_INITD
while true; do
echo
top_border
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 |"
hr
echo -e "| Please use the appropriate option for your chosen |"
echo -e "| Linux distribution. If you are unsure what to select, |"
echo -e "| please do a research before. |"
hr
echo -e "| If you are using Raspberry Pi OS, either option 1 or |"
echo -e "| 2 will work. |"
echo -e "| If you run Raspberry Pi OS, both options will work. |"
bottom_border
read -p "${cyan}###### Please choose:${default} " action
case "$action" in
1)
INST_INITD="true"
INST_SYSTEMD="false"
1|"")
echo -e "###### > 1) Init.d"
INST_DWC2_INITD="true"
INST_DWC2_SYSTEMD="false"
break;;
2)
INST_INITD="false"
INST_SYSTEMD="true"
echo -e "###### > 1) Systemd"
INST_DWC2_INITD="false"
INST_DWC2_SYSTEMD="true"
break;;
*)
print_unkown_cmd
@@ -73,7 +71,6 @@ get_user_selections_dwc2(){
done
#user selection for printer.cfg
if [ "$PRINTER_CFG_FOUND" = "false" ]; then
unset SEL_DEF_CFG
while true; do
echo
top_border
@@ -101,15 +98,12 @@ get_user_selections_dwc2(){
esac
done
fi
#
setup_printer_config_dwc2
#ask user to install reverse proxy
dwc2_reverse_proxy_dialog
#ask to change hostname
[ "$SET_NGINX_CFG" = "true" ] && create_custom_hostname
#ask user to disable octoprint when such installed service was found
if [ "$OCTOPRINT_ENABLED" = "true" ]; then
unset DISABLE_OPRINT
while true; do
echo
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(){
#check dependencies
dep=(git wget gzip tar curl)
dependency_check
#get dwc2-for-klipper
cd ${HOME}
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!"
#copy installers from kiauh srcdir to dwc-for-klipper-socket
status_msg "Copy installers to $DWC2FK_DIR"
cp -r ${SRCDIR}/kiauh/scripts/dwc2-for-klipper-socket-installer $DWC2FK_DIR/scripts
ok_msg "Done!"
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
elif [ "$INST_INITD" = "false" ] && [ "$INST_SYSTEMD" = "true" ]; then
elif [ "$INST_DWC2_SYSTEMD" = "true" ]; then
$DWC2FK_DIR/scripts/install-debian.sh
fi
ok_msg "Service installed!"
#patch /etc/default/klipper to append the uds argument
patch_klipper_sysfile_dwc2
patch_klipper_sysfile "dwc2"
#download Duet Web Control
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(){
#get Duet Web Control
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 ..."
wget $GET_DWC2_URL
[ ! -d $DWC2_DIR ] && mkdir -p $DWC2_DIR
cd $DWC2_DIR && wget $GET_DWC2_URL
ok_msg "Download complete!"
status_msg "Unzipping archive ..."
unzip -q -o *.zip
@@ -214,80 +185,14 @@ download_dwc2_webui(){
setup_printer_config_dwc2(){
if [ "$PRINTER_CFG_FOUND" = "true" ]; then
backup_printer_cfg
#check printer.cfg for necessary dwc2 entries
read_printer_cfg_dwc2
read_printer_cfg "dwc2" && write_printer_cfg
fi
if [ "$SEL_DEF_CFG" = "true" ]; then
create_default_dwc2_printer_cfg
locate_printer_cfg
fi
}
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
status_msg "Creating minimal default printer.cfg ..."
create_minimal_cfg
ok_msg "printer.cfg location: '$PRINTER_CFG'"
ok_msg "Done!"
fi
}

View File

@@ -58,7 +58,6 @@ system_check_moonraker(){
get_user_selections_moonraker(){
#user selection for printer.cfg
if [ "$PRINTER_CFG_FOUND" = "false" ]; then
unset SEL_DEF_CFG
while true; do
echo
top_border
@@ -196,10 +195,6 @@ get_user_selections_moonraker(){
echo -e "| ${red}3) Skip this step (not recommended)${default} |"
bottom_border
read -p "${cyan}###### Please choose:${default} " action
unset REMOVE_HAPROXY
unset REMOVE_LIGHTTPD
unset DISABLE_HAPROXY
unset DISABLE_LIGHTTPD
case "$action" in
1)
echo -e "###### > Remove packages"
@@ -255,7 +250,7 @@ moonraker_setup(){
#backup a possible existing printer.cfg at the old location
#and before patching in the new location
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
locate_printer_cfg
echo; ok_msg "Moonraker successfully installed!"
@@ -265,37 +260,45 @@ patch_klipper_sysfile(){
if [ -e $KLIPPER_SERVICE2 ]; then
status_msg "Checking /etc/default/klipper for necessary entries ..."
#patching new printer.cfg location to /etc/default/klipper
if ! grep -q "/klipper_config/printer.cfg" $KLIPPER_SERVICE2; then
status_msg "Patching new printer.cfg location to /etc/default/klipper ..."
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'"
if [ "$1" = "moonraker" ]; then
if ! grep -q "/klipper_config/printer.cfg" $KLIPPER_SERVICE2; then
status_msg "Patching new printer.cfg location to /etc/default/klipper ..."
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
#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!"
if [ "$1" = "moonraker" ] || [ "$1" = "dwc2" ]; then
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!"
fi
fi
fi
if [ -e $KLIPPER_SERVICE3 ]; then
status_msg "Checking /etc/systemd/system/klipper.service for necessary entries ..."
#patching new printer.cfg location to /etc/systemd/system/klipper.service
if ! grep -q "/klipper_config/printer.cfg" $KLIPPER_SERVICE3; then
status_msg "Patching new printer.cfg location to /etc/systemd/system/klipper.service ..."
sudo sed -i "/ExecStart=/ s|$PRINTER_CFG|/home/${USER}/klipper_config/printer.cfg|" $KLIPPER_SERVICE3
ok_msg "New location is: '/home/${USER}/klipper_config/printer.cfg'"
#set variable if file got edited
SERVICE_FILE_PATCHED="true"
if [ "$1" = "moonraker" ]; then
if ! grep -q "/klipper_config/printer.cfg" $KLIPPER_SERVICE3; then
status_msg "Patching new printer.cfg location to /etc/systemd/system/klipper.service ..."
sudo sed -i "/ExecStart=/ s|$PRINTER_CFG|/home/${USER}/klipper_config/printer.cfg|" $KLIPPER_SERVICE3
ok_msg "New location is: '/home/${USER}/klipper_config/printer.cfg'"
#set variable if file got edited
SERVICE_FILE_PATCHED="true"
fi
fi
#patching new UDS argument to /etc/systemd/system/klipper.service
if ! grep -q -- "-a /tmp/klippy_uds" $KLIPPER_SERVICE3; then
status_msg "Patching unix domain socket to /etc/systemd/system/klipper.service ..."
#append the new argument to /tmp/klippy.log argument
sudo sed -i "/ExecStart/s/\.log/\.log -a \/tmp\/klippy_uds/" $KLIPPER_SERVICE3
ok_msg "Patching done!"
#set variable if file got edited
SERVICE_FILE_PATCHED="true"
if [ "$1" = "moonraker" ] || [ "$1" = "dwc2" ]; then
if ! grep -q -- "-a /tmp/klippy_uds" $KLIPPER_SERVICE3; then
status_msg "Patching unix domain socket to /etc/systemd/system/klipper.service ..."
#append the new argument to /tmp/klippy.log argument
sudo sed -i "/ExecStart/s/\.log/\.log -a \/tmp\/klippy_uds/" $KLIPPER_SERVICE3
ok_msg "Patching done!"
#set variable if file got edited
SERVICE_FILE_PATCHED="true"
fi
fi
#reloading the units is only needed when the service file was patched.
[ "$SERVICE_FILE_PATCHED" = "true" ] && status_msg "Reloading unit ..." && sudo systemctl daemon-reload
@@ -324,9 +327,7 @@ check_for_folder_moonraker(){
setup_printer_config_moonraker(){
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
status_msg "Copy printer.cfg to new location ..."
cp ${HOME}/printer.cfg $PRINTER_CFG
@@ -334,12 +335,11 @@ setup_printer_config_moonraker(){
ok_msg "Done!"
fi
#check printer.cfg for necessary moonraker entries
read_printer_cfg "moonraker"
write_printer_cfg
read_printer_cfg "moonraker" && write_printer_cfg
fi
if [ "$SEL_DEF_CFG" = "true" ]; then
status_msg "Creating minimal default printer.cfg ..."
create_default_moonraker_printer_cfg
create_minimal_cfg
ok_msg "printer.cfg location: '$PRINTER_CFG'"
ok_msg "Done!"
fi
@@ -357,7 +357,6 @@ setup_moonraker_conf(){
#check for at least one trusted client in an already existing moonraker.conf
#in no entry is found, write default trusted client
if [ "$MOONRAKER_CONF_FOUND" = "true" ]; then
backup_moonraker_conf
if grep "trusted_clients:" ${HOME}/moonraker.conf -q; then
TC_LINE=$(grep -n "trusted_clients:" ${HOME}/moonraker.conf | cut -d ":" -f1)
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" = "" ]; then
status_msg "Writing trusted clients to config ..."
write_default_trusted_clients
backup_moonraker_conf && write_default_trusted_clients
ok_msg "Trusted clients written!"
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(){
DEFAULT_IP=$(hostname -I)
status_msg "Your devices current IP adress is:\n${cyan}$DEFAULT_IP ${default}"
@@ -537,21 +523,4 @@ handle_haproxy_lighttpd(){
ok_msg "Lighttpd removed!"
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
#}
}