From 679e0cc0aafe3c2955f626905d6acd1b5e89e65b Mon Sep 17 00:00:00 2001 From: Raphael Dannecker Date: Tue, 4 Jun 2024 14:42:10 +0200 Subject: [PATCH] Rework printer setup. Don't remove local printers. Create printerlist.csv for VMs. --- roles/lmn_printer/templates/install-printers.sh.j2 | 13 +++++-------- roles/lmn_vm/files/vm-run | 10 ++++++++++ roles/lmn_vm/files/vm.conf | 2 ++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/roles/lmn_printer/templates/install-printers.sh.j2 b/roles/lmn_printer/templates/install-printers.sh.j2 index 3e6629c..4decc2e 100644 --- a/roles/lmn_printer/templates/install-printers.sh.j2 +++ b/roles/lmn_printer/templates/install-printers.sh.j2 @@ -5,7 +5,7 @@ set -eu printservers="{{ printservers | join(' ') }}" hostgroup="$(id -Gn "${HOSTNAME^^}$")" usergroup="$(id -Gn "${SUDO_USER}")" -installedprinters="$(lpstat -p | cut -f 2 -d" ")" +installedprinters="$(lpstat -v | cut -f 3 -d" " | sed 's/:$//' )" cat < "/lmn/media/${SUDO_USER}/.printerlist.csv" - ## Add all printers needed: for ps in $printservers ; do echo "Checking print server '$ps' for available printers:" - printers="$(lpstat -h "$ps" -U "${SUDO_USER}" -v | sed -E 's/^.+ (\w+): .+$/\1/')" + printers="$(timeout 5 lpstat -h "$ps" -U "${SUDO_USER}" -v | sed -E 's/^.+ (\w+): .+$/\1/')" echo -e "$printers\n" for p in $printers; do if [[ "${hostgroup}" =~ "$p" ]] || [[ "${usergroup}" =~ "$p" ]] ; then @@ -42,7 +40,6 @@ for ps in $printservers ; do "ipp://$ps/printers/$p" \ -m "driverless:ipp://$ps/printers/$p" || echo "Adding queue '$p' failed." fi - echo "$p;ipp://192.168.122.1/printers/$p" >> "/lmn/media/${SUDO_USER}/.printerlist.csv" fi done done diff --git a/roles/lmn_vm/files/vm-run b/roles/lmn_vm/files/vm-run index 5ef6e2a..af6dd29 100755 --- a/roles/lmn_vm/files/vm-run +++ b/roles/lmn_vm/files/vm-run @@ -105,6 +105,15 @@ create_clone() { } +create_printerlist() { + ## Prepare .printerlist.csv + mkdir -p "${VM_MEDIADIR}" + echo "Name;IppURL" > "${VM_MEDIADIR}/.printerlist.csv" + for p in $(lpstat -v | cut -f 3 -d" " | sed 's/:$//'); do + echo "$p;ipp://192.168.122.1/printers/$p" >> "${VM_MEDIADIR}/.printerlist.csv" + done +} + QEMU='qemu:///session' NEWCLONE=0 @@ -221,6 +230,7 @@ if ! virsh --connect="${QEMU}" list | grep "${VM_NAME}-clone"; then virsh --connect=qemu:///session undefine "${VM_NAME}-clone" || echo "${VM_NAME}-clone did not exist" #trap exit_script SIGHUP SIGINT SIGTERM + create_printerlist # start virtiofsd-service [[ "${QEMU}" = 'qemu:///session' ]] && sudo /usr/local/bin/vm-virtiofsd "${VM_NAME}" diff --git a/roles/lmn_vm/files/vm.conf b/roles/lmn_vm/files/vm.conf index 8bd4189..f4a70a9 100644 --- a/roles/lmn_vm/files/vm.conf +++ b/roles/lmn_vm/files/vm.conf @@ -15,3 +15,5 @@ else VM_DIR="/tmp/${UID}/vm" VM_DIR_PERSISTENT="/var/vm/${UID}" fi + +VM_MEDIADIR="/lmn/media/${USER}"