mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-14 11:04:29 +05:00
fix: rework klipper installation routine
This commit is contained in:
@@ -187,117 +187,6 @@ print_error(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
build_fw(){
|
|
||||||
if [ -d $KLIPPER_DIR ]; then
|
|
||||||
cd $KLIPPER_DIR && make menuconfig
|
|
||||||
status_msg "Building Firmware ..."
|
|
||||||
make clean && make && ok_msg "Firmware built!"
|
|
||||||
else
|
|
||||||
warn_msg "Can not build Firmware without a Klipper directory!"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
### grab the printers id
|
|
||||||
get_printer_usb(){
|
|
||||||
warn_msg "Make sure your printer is the only USB device connected!"
|
|
||||||
while true; do
|
|
||||||
echo -e "${cyan}"
|
|
||||||
read -p "###### Press any key to continue ... " yn
|
|
||||||
echo -e "${default}"
|
|
||||||
case "$yn" in
|
|
||||||
*) break;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
status_msg "Identifying the correct USB port ..."
|
|
||||||
sleep 3
|
|
||||||
if [ -e /dev/serial/by-id/* ]; then
|
|
||||||
if [ -e /dev/serial/by-id/* ]; then
|
|
||||||
PRINTER_USB=$(ls /dev/serial/by-id/*)
|
|
||||||
status_msg "The ID of your printer is:"
|
|
||||||
title_msg "$PRINTER_USB"
|
|
||||||
echo
|
|
||||||
else
|
|
||||||
warn_msg "Could not retrieve ID!"
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
elif [ -e /dev/serial/by-path/* ]; then
|
|
||||||
if [ -e /dev/serial/by-path/* ]; then
|
|
||||||
PRINTER_USB=$(ls /dev/serial/by-path/*)
|
|
||||||
status_msg "The path of your printer is:"
|
|
||||||
title_msg "$PRINTER_USB"
|
|
||||||
echo
|
|
||||||
else
|
|
||||||
warn_msg "Could not retrieve path!"
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
warn_msg "Printer not plugged in or not detectable!"
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
write_printer_usb(){
|
|
||||||
while true; do
|
|
||||||
echo -e "${cyan}"
|
|
||||||
read -p "###### Do you want to write the ID to your printer.cfg? (Y/n): " yn
|
|
||||||
echo -e "${default}"
|
|
||||||
case "$yn" in
|
|
||||||
Y|y|Yes|yes|"")
|
|
||||||
backup_printer_cfg
|
|
||||||
cat <<PRINTERUSB >> $PRINTER_CFG
|
|
||||||
|
|
||||||
##########################
|
|
||||||
### CREATED WITH KIAUH ###
|
|
||||||
##########################
|
|
||||||
[mcu]
|
|
||||||
serial: $PRINTER_USB
|
|
||||||
##########################
|
|
||||||
##########################
|
|
||||||
PRINTERUSB
|
|
||||||
echo
|
|
||||||
ok_msg "Config written!"
|
|
||||||
break;;
|
|
||||||
N|n|No|no) break;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
flash_routine(){
|
|
||||||
echo -e "/=================================================\ "
|
|
||||||
echo -e "| ${red}~~~~~~~~~~~ [ ATTENTION! ] ~~~~~~~~~~~~${default} |"
|
|
||||||
echo -e "| Flashing a Smoothie based board for the first |"
|
|
||||||
echo -e "| time with this script will certainly fail. |"
|
|
||||||
echo -e "| This applies to boards like the BTT SKR V1.3 or |"
|
|
||||||
echo -e "| the newer SKR V1.4 (Turbo). You have to copy |"
|
|
||||||
echo -e "| the firmware file to the microSD card manually |"
|
|
||||||
echo -e "| and rename it to 'firmware.bin'. |"
|
|
||||||
echo -e "| |"
|
|
||||||
echo -e "| You find the file in: ~/klipper/out/klipper.bin |"
|
|
||||||
echo -e "\=================================================/ "
|
|
||||||
echo
|
|
||||||
while true; do
|
|
||||||
echo -e "${cyan}"
|
|
||||||
read -p "###### Do you want to continue? (Y/n): " yn
|
|
||||||
echo -e "${default}"
|
|
||||||
case "$yn" in
|
|
||||||
Y|y|Yes|yes|"")
|
|
||||||
get_printer_usb && flash_mcu && write_printer_usb; break;;
|
|
||||||
N|n|No|no) break;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
flash_mcu(){
|
|
||||||
stop_klipper
|
|
||||||
if ! make flash FLASH_DEVICE="$PRINTER_USB" ; then
|
|
||||||
warn_msg "Flashing failed!"
|
|
||||||
warn_msg "Please read the log above!"
|
|
||||||
else
|
|
||||||
ok_msg "Flashing successfull!"
|
|
||||||
fi
|
|
||||||
start_klipper
|
|
||||||
}
|
|
||||||
|
|
||||||
remove_branding(){
|
remove_branding(){
|
||||||
echo
|
echo
|
||||||
top_border
|
top_border
|
||||||
|
|||||||
@@ -1,29 +1,210 @@
|
|||||||
install_klipper(){
|
install_klipper(){
|
||||||
if [ -e /etc/init.d/klipper ] && [ -e /etc/default/klipper ]; then
|
if [ -e /etc/init.d/klipper ] && [ -e /etc/default/klipper ]; then
|
||||||
ERROR_MSG=" Looks like Klipper is already installed!\n Skipping ..."
|
ERROR_MSG="Looks like Klipper is already installed!"
|
||||||
else
|
else
|
||||||
#check for dependencies
|
get_user_selections_klipper
|
||||||
dep=(git)
|
klipper_setup
|
||||||
dependency_check
|
build_fw
|
||||||
#execute operation
|
flash_mcu
|
||||||
cd ${HOME}
|
write_printer_usb
|
||||||
status_msg "Cloning Klipper repository ..."
|
fi
|
||||||
git clone $KLIPPER_REPO && ok_msg "Klipper successfully cloned!"
|
}
|
||||||
status_msg "Installing Klipper Service ..."
|
|
||||||
$KLIPPER_DIR/scripts/install-octopi.sh && sleep 2 && ok_msg "Klipper installation complete!"
|
get_user_selections_klipper(){
|
||||||
#create a klippy.log symlink in home-dir just for convenience
|
status_msg "Initializing Klipper installation ..."
|
||||||
if [ ! -e ${HOME}/klippy.log ]; then
|
#ask user for building firmware
|
||||||
status_msg "Creating klippy.log Symlink ..."
|
while true; do
|
||||||
ln -s /tmp/klippy.log ${HOME}/klippy.log && ok_msg "Symlink created!"
|
echo
|
||||||
fi
|
read -p "${cyan}###### Do you want to build the Firmware? (Y/n):${default} " yn
|
||||||
while true; do
|
case "$yn" in
|
||||||
echo -e "${cyan}"
|
Y|y|Yes|yes|"")
|
||||||
read -p "###### Do you want to flash your MCU now? (Y/n): " yn
|
echo -e "###### > Yes"
|
||||||
echo -e "${default}"
|
BUILD_FIRMWARE="true"
|
||||||
case "$yn" in
|
break;;
|
||||||
Y|y|Yes|yes|"") build_fw && flash_routine; break;;
|
N|n|No|no)
|
||||||
N|n|No|no) break;;
|
echo -e "###### > No"
|
||||||
esac
|
BUILD_FIRMWARE="false"
|
||||||
done
|
break;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
#ask user for flashing mcu
|
||||||
|
while true; do
|
||||||
|
echo
|
||||||
|
read -p "${cyan}###### Do you want to flash your MCU? (Y/n):${default} " yn
|
||||||
|
case "$yn" in
|
||||||
|
Y|y|Yes|yes|"")
|
||||||
|
echo -e "###### > Yes"
|
||||||
|
FLASH_FIRMWARE="true"
|
||||||
|
flash_routine
|
||||||
|
break;;
|
||||||
|
N|n|No|no)
|
||||||
|
echo -e "###### > No"
|
||||||
|
FLASH_FIRMWARE="false"
|
||||||
|
break;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
klipper_setup(){
|
||||||
|
#check for dependencies
|
||||||
|
dep=(git)
|
||||||
|
dependency_check
|
||||||
|
#execute operation
|
||||||
|
cd ${HOME}
|
||||||
|
status_msg "Cloning Klipper repository ..."
|
||||||
|
git clone $KLIPPER_REPO
|
||||||
|
ok_msg "Klipper successfully cloned!"
|
||||||
|
status_msg "Installing Klipper Service ..."
|
||||||
|
$KLIPPER_DIR/scripts/install-octopi.sh
|
||||||
|
ok_msg "Klipper installation complete!"
|
||||||
|
#create a klippy.log symlink in home-dir just for convenience
|
||||||
|
if [ ! -e ${HOME}/klippy.log ]; then
|
||||||
|
status_msg "Creating klippy.log Symlink ..."
|
||||||
|
ln -s /tmp/klippy.log ${HOME}/klippy.log
|
||||||
|
ok_msg "Symlink created!"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
flash_routine(){
|
||||||
|
if [ "$FLASH_FIRMWARE" = "true" ]; then
|
||||||
|
echo
|
||||||
|
top_border
|
||||||
|
echo -e "| ${red}~~~~~~~~~~~ [ ATTENTION! ] ~~~~~~~~~~~~${default} |"
|
||||||
|
hr
|
||||||
|
echo -e "| Flashing a Smoothie based board with this script will |"
|
||||||
|
echo -e "| certainly fail. This applies to boards like the BTT |"
|
||||||
|
echo -e "| SKR V1.3 or SKR V1.4(Turbo). You have to copy the |"
|
||||||
|
echo -e "| firmware file to the microSD card manually and rename |"
|
||||||
|
echo -e "| it to 'firmware.bin'. |"
|
||||||
|
hr
|
||||||
|
echo -e "| You can find the file in: ~/klipper/out/klipper.bin |"
|
||||||
|
bottom_border
|
||||||
|
while true; do
|
||||||
|
read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn
|
||||||
|
case "$yn" in
|
||||||
|
Y|y|Yes|yes|"")
|
||||||
|
echo -e "###### > Yes"
|
||||||
|
CONFIRM_FLASHING="true"
|
||||||
|
CONFIRM_WRITE_PRINTER_USB="true"
|
||||||
|
get_printer_usb
|
||||||
|
break;;
|
||||||
|
N|n|No|no)
|
||||||
|
echo -e "###### > No"
|
||||||
|
CONFIRM_FLASHING="false"
|
||||||
|
CONFIRM_WRITE_PRINTER_USB="false"
|
||||||
|
break;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
flash_mcu(){
|
||||||
|
if [ "$CONFIRM_FLASHING" = "true" ] && [ ! -z "$PRINTER_USB" ]; then
|
||||||
|
stop_klipper
|
||||||
|
if ! make flash FLASH_DEVICE="$PRINTER_USB" ; then
|
||||||
|
warn_msg "Flashing failed!"
|
||||||
|
warn_msg "Please read the console output above!"
|
||||||
|
else
|
||||||
|
ok_msg "Flashing successfull!"
|
||||||
|
fi
|
||||||
|
start_klipper
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
build_fw(){
|
||||||
|
if [ "$BUILD_FIRMWARE" = "true" ]; then
|
||||||
|
if [ -d $KLIPPER_DIR ]; then
|
||||||
|
cd $KLIPPER_DIR
|
||||||
|
status_msg "Initializing Firmware Setup ..."
|
||||||
|
make menuconfig
|
||||||
|
status_msg "Building Firmware ..."
|
||||||
|
make clean && make && ok_msg "Firmware built!"
|
||||||
|
else
|
||||||
|
warn_msg "Can not build Firmware without a Klipper directory!"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
### grab the printers id
|
||||||
|
get_printer_usb(){
|
||||||
|
echo
|
||||||
|
top_border
|
||||||
|
echo -e "| Please make sure your printer is connected to the Pi! |"
|
||||||
|
echo -e "| If the printer is not connected yet, connect it now. |"
|
||||||
|
hr
|
||||||
|
echo -e "| Also make sure, that it is the only USB device |"
|
||||||
|
echo -e "| connected at for now! Otherwise this step may fail! |"
|
||||||
|
bottom_border
|
||||||
|
while true; do
|
||||||
|
echo -e "${cyan}"
|
||||||
|
read -p "###### Press any key to continue ... " yn
|
||||||
|
echo -e "${default}"
|
||||||
|
case "$yn" in
|
||||||
|
*)
|
||||||
|
CONFIRM_PRINTER_USB="true"
|
||||||
|
break;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
status_msg "Identifying the correct USB port ..."
|
||||||
|
sleep 2
|
||||||
|
unset PRINTER_USB
|
||||||
|
if [ -e /dev/serial/by-id/* ]; then
|
||||||
|
if [ -e /dev/serial/by-id/* ]; then
|
||||||
|
PRINTER_USB=$(ls /dev/serial/by-id/*)
|
||||||
|
status_msg "The ID of your printer is:"
|
||||||
|
title_msg "$PRINTER_USB"
|
||||||
|
else
|
||||||
|
warn_msg "Could not retrieve ID!"
|
||||||
|
fi
|
||||||
|
elif [ -e /dev/serial/by-path/* ]; then
|
||||||
|
if [ -e /dev/serial/by-path/* ]; then
|
||||||
|
PRINTER_USB=$(ls /dev/serial/by-path/*)
|
||||||
|
status_msg "The path of your printer is:"
|
||||||
|
title_msg "$PRINTER_USB"
|
||||||
|
else
|
||||||
|
warn_msg "Could not retrieve path!"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
warn_msg "Printer not plugged in or not detectable!"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
write_printer_usb(){
|
||||||
|
locate_printer_cfg
|
||||||
|
if [ ! -z "$PRINTER_CFG" ] && [ "$CONFIRM_WRITE_PRINTER_USB" = "true" ]; then
|
||||||
|
SERIAL_OLD=$(grep "serial" $PRINTER_CFG | tail -1 | cut -d" " -f2)
|
||||||
|
SERIAL_NEW=$PRINTER_USB
|
||||||
|
if [ "$SERIAL_OLD" != "$SERIAL_NEW" ]; then
|
||||||
|
unset write_entries
|
||||||
|
backup_printer_cfg
|
||||||
|
write_entries+=("[mcu]\nserial: $SERIAL_NEW")
|
||||||
|
write_entries+=("\\\n############################\n##### CREATED BY KIAUH #####\n############################")
|
||||||
|
write_entries=("############################\n" "${write_entries[@]}")
|
||||||
|
#check for a SAVE_CONFIG entry
|
||||||
|
SC="#*# <---------------------- SAVE_CONFIG ---------------------->"
|
||||||
|
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
|
||||||
|
status_msg "Writing printer ID/path 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!"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -10,8 +10,8 @@ advanced_ui(){
|
|||||||
echo -e "| 2) [Rollback] | | "
|
echo -e "| 2) [Rollback] | | "
|
||||||
echo -e "| | Mainsail: | "
|
echo -e "| | Mainsail: | "
|
||||||
echo -e "| Firmware: | 9) [Remove branding] | "
|
echo -e "| Firmware: | 9) [Remove branding] | "
|
||||||
echo -e "| 3) [Build Firmware] | | "
|
echo -e "| 3) [Build only] | | "
|
||||||
echo -e "| 4) [Flash MCU] | Extensions: | "
|
echo -e "| 4) [Build + Flash MCU] | Extensions: | "
|
||||||
echo -e "| 5) [Get Printer-USB] | 10) [Shell Command] | "
|
echo -e "| 5) [Get Printer-USB] | 10) [Shell Command] | "
|
||||||
echo -e "| 6) [Write Printer-USB] | | "
|
echo -e "| 6) [Write Printer-USB] | | "
|
||||||
echo -e "| 7) [Write DWC2 config] | | "
|
echo -e "| 7) [Write DWC2 config] | | "
|
||||||
@@ -51,13 +51,19 @@ advanced_menu(){
|
|||||||
3)
|
3)
|
||||||
clear
|
clear
|
||||||
print_header
|
print_header
|
||||||
|
unset BUILD_FIRMWARE && BUILD_FIRMWARE="true"
|
||||||
build_fw
|
build_fw
|
||||||
print_msg && clear_msg
|
print_msg && clear_msg
|
||||||
advanced_ui;;
|
advanced_ui;;
|
||||||
4)
|
4)
|
||||||
clear
|
clear
|
||||||
print_header
|
print_header
|
||||||
|
unset FLASH_FIRMWARE && FLASH_FIRMWARE="true"
|
||||||
flash_routine
|
flash_routine
|
||||||
|
unset BUILD_FIRMWARE && BUILD_FIRMWARE="true"
|
||||||
|
build_fw
|
||||||
|
unset CONFIRM_FLASHING && CONFIRM_FLASHING="true"
|
||||||
|
flash_mcu
|
||||||
print_msg && clear_msg
|
print_msg && clear_msg
|
||||||
advanced_ui;;
|
advanced_ui;;
|
||||||
5)
|
5)
|
||||||
|
|||||||
Reference in New Issue
Block a user