Merge branch 'dev-2.0'

This commit is contained in:
th33xitus
2020-09-01 14:28:40 +02:00
4 changed files with 297 additions and 213 deletions

View File

@@ -12,16 +12,18 @@ check_euid(){
} }
locate_printer_cfg(){ locate_printer_cfg(){
unset PRINTER_CFG
status_msg "Locating printer.cfg via /etc/default/klipper ..."
if [ -f $KLIPPER_SERVICE2 ]; then if [ -f $KLIPPER_SERVICE2 ]; then
#reads /etc/default/klipper and gets the default printer.cfg location #reads /etc/default/klipper and gets the default printer.cfg location
PRINTER_CFG_LOC=$(grep "KLIPPY_ARGS=" /etc/default/klipper | cut -d" " -f2) KLIPPY_ARGS_LINE="$(grep "KLIPPY_ARGS=" /etc/default/klipper)"
if [ -e $PRINTER_CFG_LOC ]; then KLIPPY_ARGS_COUNT="$(grep -o " " <<< "$KLIPPY_ARGS_LINE" | wc -l)"
PRINTER_CFG=$(readlink -e $PRINTER_CFG_LOC) i=1
else 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="" ok_msg "printer.cfg location: '$PRINTER_CFG'"
fi
else else
PRINTER_CFG="" PRINTER_CFG=""
warn_msg "Couldn't locate printer.cfg - File not found!"
fi fi
} }
@@ -187,150 +189,39 @@ print_error(){
fi fi
} }
build_fw(){ #remove_branding(){
if [ -d $KLIPPER_DIR ]; then # echo
cd $KLIPPER_DIR && make menuconfig # top_border
status_msg "Building Firmware ..." # echo -e "| This action will remove the Voron brandings from |"
make clean && make && ok_msg "Firmware built!" # echo -e "| your Mainsail installation. You have to perform |"
else # echo -e "| this action again, everytime you updated Mainsail. |"
warn_msg "Can not build Firmware without a Klipper directory!" # bottom_border
fi # while true; do
} # read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn
# case "$yn" in
### grab the printers id # Y|y|Yes|yes|"")
get_printer_usb(){ # cd $MAINSAIL_DIR/css
warn_msg "Make sure your printer is the only USB device connected!" # FILE=$(find -name "app.*.css" | cut -d"/" -f2)
while true; do # status_msg "Patching file '$FILE' ..."
echo -e "${cyan}" # cp -n $KLIPPER_DIR/docs/img/klipper-logo-small.png $MAINSAIL_DIR/img/
read -p "###### Press any key to continue ... " yn # #write extra lines to app.css
echo -e "${default}" # echo >> "$FILE"
case "$yn" in # cat < ${HOME}/kiauh/resources/app.css >> "$FILE"
*) break;; # ok_msg "File '$FILE' patched!"
esac # status_msg "Setting new Favicon ..."
done # #backup old favicon
status_msg "Identifying the correct USB port ..." # cp -n $MAINSAIL_DIR/favicon.ico $MAINSAIL_DIR/voron_favicon.ico
sleep 3 # cp ${HOME}/kiauh/resources/favicon.ico $MAINSAIL_DIR/favicon.ico
if [ -e /dev/serial/by-id/* ]; then # ok_msg "Icon set!"
if [ -e /dev/serial/by-id/* ]; then # echo
PRINTER_USB=$(ls /dev/serial/by-id/*) # ok_msg "Brandings removed!"
status_msg "The ID of your printer is:" # ok_msg "Clear browser cache and reload Mainsail (F5)!"
title_msg "$PRINTER_USB" # echo
echo # break;;
else # N|n|No|no) break;;
warn_msg "Could not retrieve ID!" # esac
echo # done
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(){
echo
top_border
echo -e "| This action will remove the Voron brandings from |"
echo -e "| your Mainsail installation. You have to perform |"
echo -e "| this action again, everytime you updated Mainsail. |"
bottom_border
while true; do
read -p "${cyan}###### Do you want to continue? (Y/n):${default} " yn
case "$yn" in
Y|y|Yes|yes|"")
cd $MAINSAIL_DIR/css
FILE=$(find -name "app.*.css" | cut -d"/" -f2)
status_msg "Patching file '$FILE' ..."
cp -n $KLIPPER_DIR/docs/img/klipper-logo-small.png $MAINSAIL_DIR/img/
#write extra lines to app.css
echo >> "$FILE"
cat < ${HOME}/kiauh/resources/app.css >> "$FILE"
ok_msg "File '$FILE' patched!"
status_msg "Setting new Favicon ..."
#backup old favicon
cp -n $MAINSAIL_DIR/favicon.ico $MAINSAIL_DIR/voron_favicon.ico
cp ${HOME}/kiauh/resources/favicon.ico $MAINSAIL_DIR/favicon.ico
ok_msg "Icon set!"
echo
ok_msg "Brandings removed!"
ok_msg "Clear browser cache and reload Mainsail (F5)!"
echo
break;;
N|n|No|no) break;;
esac
done
}
install_extension_shell_command(){ install_extension_shell_command(){
echo echo

View File

@@ -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
echo -e "${cyan}"
read -p "###### Do you want to flash your MCU now? (Y/n): " yn
echo -e "${default}"
case "$yn" in case "$yn" in
Y|y|Yes|yes|"") build_fw && flash_routine; break;; Y|y|Yes|yes|"")
N|n|No|no) break;; echo -e "###### > Yes"
BUILD_FIRMWARE="true"
break;;
N|n|No|no)
echo -e "###### > No"
BUILD_FIRMWARE="false"
break;;
esac esac
done 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
} }

View File

@@ -162,15 +162,16 @@ get_user_selections_moonraker(){
done done
#ask user for mainsail default macros #ask user for mainsail default macros
while true; do while true; do
unset ADD_MS_MACROS
echo echo
read -p "${cyan}###### Add the recommended Mainsail macros? (Y/n):${default} " read -p "${cyan}###### Add the recommended Mainsail macros? (Y/n):${default} " yn
case "$yn" in case "$yn" in
Y|y|Yes|yes|"") Y|y|Yes|yes|"")
echo -e "###### > Yes" echo -e "###### > Yes"
ADD_MS_MCAROS="true";; ADD_MS_MACROS="true";;
N|n|No|no) N|n|No|no)
echo -e "###### > No" echo -e "###### > No"
ADD_MS_MCAROS="false";; ADD_MS_MACROS="false";;
esac esac
break break
done done
@@ -212,6 +213,25 @@ moonraker_setup(){
ok_msg "Download complete!" ok_msg "Download complete!"
status_msg "Installing Moonraker ..." status_msg "Installing Moonraker ..."
$MOONRAKER_DIR/scripts/install-moonraker.sh $MOONRAKER_DIR/scripts/install-moonraker.sh
#backup a possible existing printer.cfg at the old location
#and before patching in the new location
backup_printer_cfg
#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|" /etc/default/klipper
ok_msg "New location is: '/home/${USER}/klipper_config/printer.cfg'"
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!"
fi
#re-run printer.cfg location function to read the new path for the printer.cfg
locate_printer_cfg
echo
ok_msg "Moonraker successfully installed!" ok_msg "Moonraker successfully installed!"
} }
@@ -236,12 +256,12 @@ check_for_folder_moonraker(){
setup_printer_config_mainsail(){ setup_printer_config_mainsail(){
if [ "$PRINTER_CFG_FOUND" = "true" ]; then if [ "$PRINTER_CFG_FOUND" = "true" ]; then
backup_printer_cfg backup_printer_cfg
#create a printer.cfg symlink to make it accessible #copy printer.cfg to new location if
#in the mainsail config editor if the printer.cfg is not #there is no printer.cfg at the new location already
#located in klipper_config by default if [ -f ${HOME}/printer.cfg ] && [ ! -f ${HOME}/klipper_config/printer.cfg ]; then
if [ "$PRINTER_CFG" != "${HOME}/klipper_config/printer.cfg" ] && [ ! -f ${HOME}/klipper_config/printer.cfg ]; then status_msg "Copy printer.cfg to new location ..."
status_msg "Create printer.cfg symlink ..." cp ${HOME}/printer.cfg $PRINTER_CFG
ln -s $PRINTER_CFG ${HOME}/klipper_config ok_msg "printer.cfg location: '$PRINTER_CFG'"
ok_msg "Done!" ok_msg "Done!"
fi fi
#check printer.cfg for necessary mainsail entries #check printer.cfg for necessary mainsail entries
@@ -249,13 +269,13 @@ setup_printer_config_mainsail(){
write_printer_cfg_mainsail write_printer_cfg_mainsail
fi fi
if [ "$SEL_DEF_CFG" = "true" ]; then if [ "$SEL_DEF_CFG" = "true" ]; then
status_msg "Creating minimal default printer.cfg ..."
create_default_mainsail_printer_cfg create_default_mainsail_printer_cfg
status_msg "Create symlink in home directory ..." ok_msg "printer.cfg location: '$PRINTER_CFG'"
ln -s ${HOME}/klipper_config/printer.cfg ${HOME}
ok_msg "Done!" ok_msg "Done!"
fi fi
#copy mainsail_macro.cfg #copy mainsail_macro.cfg
if [ "$ADD_MS_MCAROS" = "true" ]; then if [ "$ADD_MS_MACROS" = "true" ]; then
status_msg "Create mainsail_macros.cfg ..." status_msg "Create mainsail_macros.cfg ..."
if [ ! -f ${HOME}/klipper_config/mainsail_macros.cfg ]; then if [ ! -f ${HOME}/klipper_config/mainsail_macros.cfg ]; then
cp ${HOME}/kiauh/resources/mainsail_macros.cfg ${HOME}/klipper_config cp ${HOME}/kiauh/resources/mainsail_macros.cfg ${HOME}/klipper_config
@@ -277,7 +297,7 @@ read_printer_cfg_mainsail(){
if [ ! $(grep '^\[display_status\]$' $PRINTER_CFG) ]; then if [ ! $(grep '^\[display_status\]$' $PRINTER_CFG) ]; then
DISPLAY_STATUS="false" DISPLAY_STATUS="false"
fi fi
if [ ! "$(grep '^\[include klipper_config\/mainsail_macros\.cfg\]$' $PRINTER_CFG)" ]; then if [ ! "$(grep '^\[include mainsail_macros\.cfg\]$' $PRINTER_CFG)" ]; then
MS_MACRO="false" MS_MACRO="false"
fi fi
#check for a SAVE_CONFIG entry #check for a SAVE_CONFIG entry
@@ -292,8 +312,8 @@ read_printer_cfg_mainsail(){
write_printer_cfg_mainsail(){ write_printer_cfg_mainsail(){
unset write_entries unset write_entries
if [ "$MS_MACRO" = "false" ] && [ "$ADD_MS_MCAROS" = "true" ]; then if [ "$MS_MACRO" = "false" ] && [ "$ADD_MS_MACROS" = "true" ]; then
write_entries+=("[include klipper_config/mainsail_macros.cfg]") write_entries+=("[include mainsail_macros.cfg]")
fi fi
if [ "$PAUSE_RESUME" = "false" ]; then if [ "$PAUSE_RESUME" = "false" ]; then
write_entries+=("[pause_resume]") write_entries+=("[pause_resume]")

View File

@@ -6,15 +6,13 @@ advanced_ui(){
hr hr
echo -e "| | | " echo -e "| | | "
echo -e "| Klipper: | System: | " echo -e "| Klipper: | System: | "
echo -e "| 1) [Switch Version] | 8) [Change hostname] | " echo -e "| 1) [Switch Version] | 6) [Change hostname] | "
echo -e "| 2) [Rollback] | | " echo -e "| 2) [Rollback] | | "
echo -e "| | Mainsail: | " echo -e "| | Extensions: | "
echo -e "| Firmware: | 9) [Remove branding] | " echo -e "| Firmware: | 7) [Shell Command] | "
echo -e "| 3) [Build Firmware] | | " echo -e "| 3) [Build only] | | "
echo -e "| 4) [Flash MCU] | Extensions: | " echo -e "| 4) [Build + Flash MCU] | | "
echo -e "| 5) [Get Printer-USB] | 10) [Shell Command] | " echo -e "| 5) [Get Printer-USB] | | "
echo -e "| 6) [Write Printer-USB] | | "
echo -e "| 7) [Write DWC2 config] | | "
echo -e "| | | " echo -e "| | | "
quit_footer quit_footer
} }
@@ -51,13 +49,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)
@@ -67,30 +71,18 @@ advanced_menu(){
print_msg && clear_msg print_msg && clear_msg
advanced_ui;; advanced_ui;;
6) 6)
clear
print_header
get_printer_usb && write_printer_usb
print_msg && clear_msg
advanced_ui;;
7)
clear
print_header
create_dwc2fk_cfg
print_msg && clear_msg
advanced_ui;;
8)
clear clear
print_header print_header
create_custom_hostname create_custom_hostname
print_msg && clear_msg print_msg && clear_msg
advanced_ui;; advanced_ui;;
9) #7)
clear # clear
print_header # print_header
remove_branding # remove_branding
print_msg && clear_msg # print_msg && clear_msg
advanced_ui;; # advanced_ui;;
10) 7)
clear clear
print_header print_header
install_extension_shell_command install_extension_shell_command