fix: rework locate_printer_cfg function

This commit is contained in:
th33xitus
2020-09-01 13:51:51 +02:00
parent bae0c1f0fd
commit 9ec63be673

View File

@@ -12,16 +12,18 @@ check_euid(){
} }
locate_printer_cfg(){ locate_printer_cfg(){
unset PRINTER_CFG
status_msg "Locating printer.cfg"
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 found in: '$PRINTER_CFG'"
fi
else else
PRINTER_CFG="" PRINTER_CFG=""
warn_msg "Couldn't locate printer.cfg - File not found!"
fi fi
} }