mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-13 10:34:28 +05:00
fix: rewrite dwc2 installation
This commit is contained in:
@@ -1,30 +1,134 @@
|
||||
#TODO:
|
||||
# - ask for permission to disable octoprint service
|
||||
|
||||
dwc2_install_routine(){
|
||||
install_dwc2(){
|
||||
if [ -d $KLIPPER_DIR ]; then
|
||||
# check for existing installation
|
||||
if [ -d $DWC2FK_DIR ] && [ -d $DWC2_DIR ]; then
|
||||
ERROR_MSG=" Looks like DWC2 is already installed!\n Skipping..."
|
||||
return
|
||||
fi
|
||||
stop_klipper
|
||||
#disable octoprint service if installed
|
||||
if systemctl is-enabled octoprint.service -q 2>/dev/null; then
|
||||
disable_octoprint_service
|
||||
fi
|
||||
install_tornado
|
||||
install_dwc2fk && dwc2fk_cfg
|
||||
install_dwc2
|
||||
dwc2_reverse_proxy_dialog
|
||||
create_custom_hostname
|
||||
start_klipper
|
||||
system_check_dwc2
|
||||
#ask user for customization
|
||||
get_user_selections_dwc2
|
||||
#dwc2 main installation
|
||||
check_for_folder_dwc2
|
||||
tornado_setup
|
||||
dwc2fk_setup
|
||||
dwc2_setup
|
||||
#setup config
|
||||
write_printer_cfg_dwc2
|
||||
write_custom_printer_cfg_dwc2
|
||||
#execute customizations
|
||||
disable_octoprint
|
||||
create_reverse_proxy "dwc2"
|
||||
set_hostname
|
||||
#after install actions
|
||||
restart_klipper
|
||||
else
|
||||
ERROR_MSG=" Please install Klipper first!\n Skipping..."
|
||||
fi
|
||||
}
|
||||
|
||||
install_tornado(){
|
||||
system_check_dwc2(){
|
||||
status_msg "Initializing DWC2 installation ..."
|
||||
stop_klipper
|
||||
#check for existing printer.cfg
|
||||
if [ -e ${HOME}/printer.cfg ]; then
|
||||
PRINTER_CFG_FOUND="true"
|
||||
PRINTER_CFG_LOC="${HOME}/printer.cfg"
|
||||
else
|
||||
PRINTER_CFG_FOUND="false"
|
||||
fi
|
||||
#check if octoprint is installed
|
||||
if systemctl is-enabled octoprint.service -q 2>/dev/null; then
|
||||
unset OCTOPRINT_ENABLED
|
||||
OCTOPRINT_ENABLED="true"
|
||||
fi
|
||||
}
|
||||
|
||||
get_user_selections_dwc2(){
|
||||
#user selection for printer.cfg
|
||||
if [ "$PRINTER_CFG_FOUND" = "false" ]; then
|
||||
unset SEL_DEF_CFG
|
||||
unset SEL_CUS_CFG
|
||||
while true; do
|
||||
echo
|
||||
top_border
|
||||
echo -e "| ${red}WARNING! - No printer.cfg was found!${default} |"
|
||||
hr
|
||||
echo -e "| You can now either select to create a printer.cfg |"
|
||||
echo -e "| with the default entries (1), customize the settings |"
|
||||
echo -e "| before writing them (2) or you can skip the creation |"
|
||||
echo -e "| of a printer.cfg at all. |"
|
||||
echo -e "| |"
|
||||
echo -e "| Please keep in mind that DWC2 will ONLY load if you |"
|
||||
echo -e "| have a correctly defined printer.cfg. Any missing |"
|
||||
echo -e "| option or error will prevent DWC2 from loading and |"
|
||||
echo -e "| you need to check klippy.log to resolve the error. |"
|
||||
echo -e "| |"
|
||||
echo -e "| Neither option 1 or 2 of this script will create a |"
|
||||
echo -e "| fully working printer.cfg for you! |"
|
||||
hr
|
||||
echo -e "| 1) [Create default configuration] |"
|
||||
echo -e "| 2) [Create custom configuration] |"
|
||||
echo -e "| 3) ${red}[Skip]${default} |"
|
||||
bottom_border
|
||||
read -p "${cyan}###### Please select:${default} " choice
|
||||
case "$choice" in
|
||||
1)
|
||||
echo -e "###### > Create default configuration"
|
||||
SEL_DEF_CFG="true"
|
||||
SEL_CUS_CFG="false"
|
||||
break;;
|
||||
2)
|
||||
echo -e "###### > Create custom configuration"
|
||||
SEL_DEF_CFG="false"
|
||||
SEL_CUS_CFG="true"
|
||||
break;;
|
||||
3)
|
||||
echo -e "###### > Skip"
|
||||
SEL_DEF_CFG="false"
|
||||
SEL_CUS_CFG="false"
|
||||
echo "${red}Skipping ...${default}"; break;;
|
||||
esac
|
||||
break
|
||||
done
|
||||
fi
|
||||
#
|
||||
setup_printer_config_dwc2
|
||||
#ask user to install reverse proxy
|
||||
dwc2_reverse_proxy_dialog
|
||||
#ask to change hostname
|
||||
if [ "$SET_REVERSE_PROXY" = "true" ]; then
|
||||
create_custom_hostname
|
||||
fi
|
||||
#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!"
|
||||
echo -e "You might consider disabling the OctoPrint service,"
|
||||
echo -e "since an active OctoPrint service may lead to unexpected"
|
||||
echo -e "behavior of the DWC2 Webinterface."
|
||||
read -p "${cyan}###### Do you want to disable OctoPrint now? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"")
|
||||
echo -e "###### > Yes"
|
||||
DISABLE_OPRINT="true";;
|
||||
N|n|No|no)
|
||||
echo -e "###### > No"
|
||||
DISABLE_OPRINT="false";;
|
||||
esac
|
||||
break
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
check_for_folder_dwc2(){
|
||||
#check for needed folder
|
||||
if [ ! -d $DWC2_DIR/web ]; then
|
||||
mkdir -p $DWC2_DIR/web
|
||||
fi
|
||||
}
|
||||
|
||||
tornado_setup(){
|
||||
if [ "$(cd $KLIPPY_ENV_DIR/bin/ && $_/pip list 2>/dev/null | grep "tornado" | cut -d" " -f9)" = "5.1.1" ]; then
|
||||
ok_msg "Tornado 5.1.1 is already installed! Continue..."
|
||||
else
|
||||
@@ -37,7 +141,7 @@ install_tornado(){
|
||||
fi
|
||||
}
|
||||
|
||||
install_dwc2fk(){
|
||||
dwc2fk_setup(){
|
||||
cd ${HOME}
|
||||
status_msg "Cloning DWC2-for-Klipper repository ..."
|
||||
git clone $DWC2FK_REPO && ok_msg "DWC2-for-Klipper successfully cloned!"
|
||||
@@ -48,40 +152,111 @@ install_dwc2fk(){
|
||||
fi
|
||||
}
|
||||
|
||||
dwc2fk_cfg(){
|
||||
while true; do
|
||||
echo -e "${cyan}"
|
||||
read -p "###### Do you want to create the config now? (Y/n): " yn
|
||||
echo -e "${default}"
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"") create_dwc2fk_cfg; break;;
|
||||
N|n|No|no) break;;
|
||||
esac
|
||||
done
|
||||
dwc2_setup(){
|
||||
#check dependencies
|
||||
dep=(wget gzip tar curl)
|
||||
dependency_check
|
||||
#execute operation
|
||||
GET_DWC2_URL=`curl -s https://api.github.com/repositories/28820678/releases/latest | grep browser_download_url | cut -d'"' -f4`
|
||||
cd $DWC2_DIR/web
|
||||
status_msg "Downloading DWC2 Web UI ..."
|
||||
wget -q $GET_DWC2_URL && ok_msg "Download complete!"
|
||||
status_msg "Unzipping archive ..."
|
||||
unzip -q -o *.zip && for f_ in $(find . | grep '.gz');do gunzip -f ${f_};done && ok_msg "Done!"
|
||||
status_msg "Writing version to file ..."
|
||||
echo $GET_DWC2_URL | cut -d/ -f8 > $DWC2_DIR/web/version && ok_msg "Done!"
|
||||
status_msg "Do a little cleanup ..."
|
||||
rm -rf DuetWebControl-SD.zip && ok_msg "Done!"
|
||||
ok_msg "DWC2 Web UI installed!"
|
||||
}
|
||||
|
||||
create_dwc2fk_cfg(){
|
||||
echo -e "/=================================================\ "
|
||||
echo -e "| 1) [Default configuration] | "
|
||||
echo -e "| 2) [Custom configuration] | "
|
||||
echo -e "| 3) [Skip] | "
|
||||
echo -e "\=================================================/ "
|
||||
while true; do
|
||||
read -p "Please select: " choice; echo
|
||||
case "$choice" in
|
||||
1) dwc2fk_default_cfg && ok_msg "Config written ..."; break;;
|
||||
2) create_dwc2fk_custom_cfg && ok_msg "Config written ..."; break;;
|
||||
3) echo "Skipping ..."; break;;
|
||||
esac
|
||||
done
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
setup_printer_config_dwc2(){
|
||||
if [ "$PRINTER_CFG_FOUND" = "true" ]; then
|
||||
backup_printer_cfg
|
||||
#check printer.cfg for necessary dwc2 entries
|
||||
read_printer_cfg_dwc2
|
||||
fi
|
||||
if [ "$SEL_DEF_CFG" = "true" ]; then
|
||||
create_default_dwc2_printer_cfg
|
||||
fi
|
||||
if [ "$SEL_CUS_CFG" = "true" ]; then
|
||||
#get user input for custom config
|
||||
create_custom_dwc2_printer_cfg
|
||||
fi
|
||||
}
|
||||
|
||||
dwc2fk_default_cfg(){
|
||||
cat <<DWC2 >> $PRINTER_CFG
|
||||
read_printer_cfg_dwc2(){
|
||||
unset SC_ENTRY
|
||||
SC="#*# <---------------------- SAVE_CONFIG ---------------------->"
|
||||
if [ ! $(grep '^\[virtual_sdcard\]$' ${HOME}/printer.cfg) ]; then
|
||||
VSD="false"
|
||||
fi
|
||||
if [ ! $(grep '^\[web_dwc2\]$' ${HOME}/printer.cfg) ]; then
|
||||
WEB_DWC2="false"
|
||||
fi
|
||||
#check for a SAVE_CONFIG entry
|
||||
if [[ $(grep "$SC" ${HOME}/printer.cfg) ]]; then
|
||||
SC_LINE=$(grep -n "$SC" ${HOME}/printer.cfg | cut -d ":" -f1)
|
||||
PRE_SC_LINE=$(expr $SC_LINE - 1)
|
||||
SC_ENTRY="true"
|
||||
fi
|
||||
}
|
||||
|
||||
write_printer_cfg_dwc2(){
|
||||
unset write_entries
|
||||
if [ "$WEB_DWC2" = "false" ]; then
|
||||
write_entries+=("[web_dwc2]\nprinter_name: my_printer\nlisten_adress: 0.0.0.0\nlisten_port: 4750\nweb_path: dwc2/web")
|
||||
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" ${HOME}/printer.cfg
|
||||
done
|
||||
fi
|
||||
if [ "$SC_ENTRY" = "false" ]; then
|
||||
LINE_COUNT="$(wc -l < ${HOME}/printer.cfg)a"
|
||||
for entry in "${write_entries[@]}"
|
||||
do
|
||||
sed -i "$LINE_COUNT $entry" ${HOME}/printer.cfg
|
||||
done
|
||||
fi
|
||||
ok_msg "Done!"
|
||||
}
|
||||
|
||||
write_custom_printer_cfg_dwc2(){
|
||||
if [ "$CONFIRM_CUSTOM_CFG" = "true" ]; then
|
||||
echo -e "$DWC2_CFG" >> ${HOME}/printer.cfg
|
||||
fi
|
||||
}
|
||||
|
||||
create_default_dwc2_printer_cfg(){
|
||||
#create default config
|
||||
touch ${HOME}/printer.cfg
|
||||
cat <<DEFAULT_DWC2_CFG >> ${HOME}/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
|
||||
|
||||
@@ -92,10 +267,19 @@ listen_port: 4750
|
||||
web_path: dwc2/web
|
||||
##########################
|
||||
##########################
|
||||
DWC2
|
||||
DEFAULT_DWC2_CFG
|
||||
}
|
||||
|
||||
create_dwc2fk_custom_cfg(){
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
create_custom_dwc2_printer_cfg(){
|
||||
echo
|
||||
top_border
|
||||
echo -e "| Please fill in custom values for the following |"
|
||||
echo -e "| configuration options. If you are unsure what to put |"
|
||||
echo -e "| in, keep the pre-entered values. |"
|
||||
bottom_border
|
||||
echo -e "${cyan}"
|
||||
read -e -p "Printer name: " -i "my_printer" PRINTER_NAME
|
||||
read -e -p "Listen adress: " -i "0.0.0.0" LISTEN_ADRESS
|
||||
@@ -122,50 +306,40 @@ DWC2
|
||||
echo "The following lines will be written:"
|
||||
echo -e "$DWC2_CFG"
|
||||
while true; do
|
||||
echo -e "${cyan}"
|
||||
read -p "###### Write now (Y) or start over (n)? (Y/n): " yn
|
||||
echo -e "${default}"
|
||||
echo
|
||||
read -p "${cyan}###### Confirm (Y) or start over (n)? (Y/n):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"") echo -e "$DWC2_CFG" >> $PRINTER_CFG; break;;
|
||||
N|n|No|no) create_dwc2fk_custom_cfg;;
|
||||
Y|y|Yes|yes|"")
|
||||
CONFIRM_CUSTOM_CFG="true"
|
||||
break;;
|
||||
N|n|No|no)
|
||||
CONFIRM_CUSTOM_CFG="false"
|
||||
create_custom_dwc2_printer_cfg
|
||||
break;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
install_dwc2(){
|
||||
#check dependencies
|
||||
dep=(wget gzip tar curl)
|
||||
dependency_check
|
||||
#execute operation
|
||||
GET_DWC2_URL=`curl -s https://api.github.com/repositories/28820678/releases/latest | grep browser_download_url | cut -d'"' -f4`
|
||||
if [ ! -d $DWC2_DIR/web ]; then
|
||||
mkdir -p $DWC2_DIR/web
|
||||
fi
|
||||
cd $DWC2_DIR/web
|
||||
status_msg "Downloading DWC2 Web UI ..."
|
||||
wget -q $GET_DWC2_URL && ok_msg "Download complete!"
|
||||
status_msg "Unzipping archive ..."
|
||||
unzip -q -o *.zip && for f_ in $(find . | grep '.gz');do gunzip -f ${f_};done && ok_msg "Done!"
|
||||
status_msg "Writing version to file ..."
|
||||
echo $GET_DWC2_URL | cut -d/ -f8 > $DWC2_DIR/web/version && ok_msg "Done!"
|
||||
status_msg "Do a little cleanup ..."
|
||||
rm -rf DuetWebControl-SD.zip && ok_msg "Done!"
|
||||
ok_msg "DWC2 Web UI installed!"
|
||||
}
|
||||
#############################################################
|
||||
#############################################################
|
||||
|
||||
dwc2_reverse_proxy_dialog(){
|
||||
unset SET_REVERSE_PROXY
|
||||
echo
|
||||
top_border
|
||||
echo -e "| If you want to have a nicer URL or simply need/want | "
|
||||
echo -e "| DWC2 to run on port 80 (http's default port) you | "
|
||||
echo -e "| can set up a reverse proxy to run DWC2 on port 80. | "
|
||||
bottom_border
|
||||
while true; do
|
||||
echo -e "${cyan}"
|
||||
read -p "###### Do you want to set up a reverse proxy now? (Y/n): " yn
|
||||
echo -e "${default}"
|
||||
read -p "${cyan}###### Do you want to set up a reverse proxy now? (y/N):${default} " yn
|
||||
case "$yn" in
|
||||
Y|y|Yes|yes|"") create_reverse_proxy "dwc2"; break;;
|
||||
N|n|No|no) break;;
|
||||
Y|y|Yes|yes)
|
||||
SET_REVERSE_PROXY="true"
|
||||
break;;
|
||||
N|n|No|no|"")
|
||||
SET_REVERSE_PROXY="false"
|
||||
break;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
Reference in New Issue
Block a user