49 lines
1.1 KiB
Bash
Executable File
49 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# CUPS filter for TA 3505ci - injects department code into PostScript stream.
|
|
# Uses bash+awk only, no Python dependency.
|
|
|
|
if [ $# -lt 5 ]; then
|
|
echo "Usage: kyofilter job-id user title copies options [file]" >&2
|
|
exit 1
|
|
fi
|
|
|
|
OPTIONS="${5:-}"
|
|
INFILE="${6:-}"
|
|
|
|
# Extract department code: KmManagment=MGxxxxx -> xxxxx
|
|
CODE=""
|
|
for OPT in $OPTIONS; do
|
|
if [[ "$OPT" =~ ^KmManagment=MG([0-9]+)$ ]]; then
|
|
CODE="${BASH_REMATCH[1]}"
|
|
break
|
|
fi
|
|
done
|
|
|
|
# Pure passthrough when no code selected
|
|
if [ -z "$CODE" ]; then
|
|
if [ -n "$INFILE" ]; then
|
|
cat "$INFILE"
|
|
else
|
|
cat
|
|
fi
|
|
exit 0
|
|
fi
|
|
|
|
# Inject PostScript command before %%EndSetup (fallback: before %%Page:)
|
|
INJECT="($CODE) statusdict /setmanagementnumber get exec"
|
|
INPUT="${INFILE:--}"
|
|
|
|
awk -v inject="$INJECT" '
|
|
BEGIN { injected = 0 }
|
|
!injected && /^%%EndSetup/ {
|
|
print inject
|
|
injected = 1
|
|
}
|
|
!injected && /^%%Page:/ {
|
|
print inject
|
|
injected = 1
|
|
}
|
|
{ print }
|
|
END { if (!injected) print "kyofilter: WARNING: no injection point found" > "/dev/stderr" }
|
|
' "$INPUT"
|