Avoid duplicate printer names

This commit is contained in:
Elizabeth Cray 2024-08-08 09:36:39 -04:00
parent 874e9d0871
commit 6d046cd394

View File

@ -1,10 +1,8 @@
#!/bin/bash
# TODO: Add Crowsnest Support
# TODO: Avoid duplicate printer names
# TODO: Dry run
# TODO: Printer Directory Page in NGINX
# TODO: Fix PolicyKit issues "klippy_uds_address"
# Handle arguments
ARG_HELP=0
@ -53,6 +51,14 @@ if [[ "$ARG_HELP" == 1 ]]; then
echo.Rainbow "-p/--port Specify printer port (skips popup)"
exit 0
fi
if [[ "$ARG_NAME" != 0 ]]; then
if [ -d $HOME/$ARG_NAME ]; then
echo.Red "UNABLE TO COMPLY: Printer name already exists"
exit 1
fi
fi
# Pull Klipper
git submodule update --init --recursive
@ -70,11 +76,21 @@ fi
PRINTER_NAME=""
if [[ "$ARG_NAME" == 0 ]]; then
NAME_NOT_VALID=true
DISPLAY_MSG="Name This Printer"
while $NAME_NOT_VALID ; do
PRINTER_NAME=$(dialog --backtitle 'drwho@hackers.town' --inputbox 'Name This Printer' 8 40 "${PRINTER_NAME}" 3>&1 1>&2 2>&3)
PRINTER_NAME=$(dialog --backtitle 'drwho@hackers.town' --inputbox "$DISPLAY_MSG" 8 40 "${PRINTER_NAME}" 3>&1 1>&2 2>&3)
if [[ $PRINTER_NAME =~ ^[a-zA-Z0-9_-]+$ ]]; then
NAME_NOT_VALID=false
fi
if [ -d $HOME/$PRINTER_NAME ]; then
DISPLAY_MSG="Printer name already exists"
NAME_NOT_VALID=true
fi
if [[ "$PRINTER_NAME" == "" ]]; then
echo ""
echo.Yellow "Cancelled or no input, closing script"
exit 4
fi
done
else
echo.ICyan "Using passed printer name: $ARG_NAME"