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(){
unset PRINTER_CFG
status_msg "Locating printer.cfg"
if [ -f $KLIPPER_SERVICE2 ]; then
#reads /etc/default/klipper and gets the default printer.cfg location
PRINTER_CFG_LOC=$(grep "KLIPPY_ARGS=" /etc/default/klipper | cut -d" " -f2)
if [ -e $PRINTER_CFG_LOC ]; then
PRINTER_CFG=$(readlink -e $PRINTER_CFG_LOC)
else
PRINTER_CFG=""
fi
KLIPPY_ARGS_LINE="$(grep "KLIPPY_ARGS=" /etc/default/klipper)"
KLIPPY_ARGS_COUNT="$(grep -o " " <<< "$KLIPPY_ARGS_LINE" | wc -l)"
i=1
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 found in: '$PRINTER_CFG'"
else
PRINTER_CFG=""
warn_msg "Couldn't locate printer.cfg - File not found!"
fi
}