Repository navigation
Prefer IPP Everywhere when adding network printers #13630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: quattro
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| #!/bin/bash | ||
|
|
||
| # omarchy:summary=Add a network printer with the driverless IPP Everywhere profile | ||
| # omarchy:group=setup | ||
| # omarchy:name=printer | ||
| # omarchy:args=[name] [ipp-uri] | ||
| # omarchy:examples=omarchy setup printer | omarchy setup printer Office ipp://192.168.1.50/ipp/print | ||
| # omarchy:requires-sudo=true | ||
|
|
||
| # Brand PPDs (Epson ESC/P-R, etc.) route jobs through cups-filters' universal / | ||
| # pdftopdf chain and often fail on modern AirPrint / IPP Everywhere printers | ||
| # (#13023). The everywhere model talks IPP directly and skips that filter path. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| usage() { | ||
| echo "Usage: omarchy-setup-printer [name] [ipp-uri]" >&2 | ||
| echo " With no args, lists driverless printers and prompts for one." >&2 | ||
| } | ||
|
|
||
| # driverless list lines look like: | ||
| # driverless:ipp://EPSON._ipp._tcp.local/ipp/print "Epson ..." "Epson ... IPP Everywhere" "" | ||
| driverless_entries() { | ||
| LC_ALL=C driverless list 2>/dev/null | awk ' | ||
| /^driverless:/ { | ||
| uri = $1 | ||
| sub(/^driverless:/, "", uri) | ||
| name = $0 | ||
| sub(/^[^"]*"/, "", name) | ||
| sub(/".*/, "", name) | ||
| if (name == "") name = uri | ||
| printf "%s\t%s\n", name, uri | ||
| } | ||
| ' | ||
| } | ||
|
|
||
| add_everywhere_queue() { | ||
| local name=$1 uri=$2 | ||
|
|
||
| [[ -n $name && -n $uri ]] || { | ||
| echo "omarchy-setup-printer: name and IPP URI are required" >&2 | ||
| return 1 | ||
| } | ||
|
|
||
| case $uri in | ||
| ipp://* | ipps://*) ;; | ||
| *) | ||
| echo "omarchy-setup-printer: URI must be ipp:// or ipps:// (got $uri)" >&2 | ||
| return 1 | ||
| ;; | ||
| esac | ||
|
|
||
| # Sanitize the CUPS queue name: letters, digits, dash, underscore only. | ||
| local queue | ||
| queue=$(printf '%s' "$name" | tr -c 'A-Za-z0-9_-' '_') | ||
| [[ -n $queue ]] || queue=printer | ||
|
|
||
| echo "Adding $queue via IPP Everywhere ($uri)" | ||
| sudo lpadmin -p "$queue" -E -v "$uri" -m everywhere | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If a discovered printer advertises a description that becomes the name of an existing queue, this call changes that queue’s destination instead of creating a new one. A printer on the LAN could thereby receive future jobs intended for the existing queue. The wizard selects a sole discovered printer without prompting; check for a name collision before changing the destination. How this was verified: The advertised description becomes the queue name, and the selected URI reaches |
||
| sudo lpadmin -p "$queue" -o printer-error-policy=retry-job | ||
|
Comment on lines
+57
to
+58
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| echo "Printer $queue is ready. Prefer this over brand model drivers in Print Settings." | ||
| } | ||
|
|
||
| if [[ ${1:-} == "-h" || ${1:-} == "--help" ]]; then | ||
| usage | ||
| exit 0 | ||
| fi | ||
|
|
||
| if ((${#@} == 2)); then | ||
| add_everywhere_queue "$1" "$2" | ||
| exit 0 | ||
| fi | ||
|
|
||
| if ((${#@} != 0)); then | ||
| usage | ||
| exit 1 | ||
| fi | ||
|
|
||
| mapfile -t entries < <(driverless_entries) | ||
|
|
||
| if ((${#entries[@]} == 0)); then | ||
| echo "No driverless IPP printers were found on the network." | ||
| echo "Check that the printer is on, avahi-daemon is running, and try:" | ||
| echo " omarchy setup printer Office ipp://192.168.1.50/ipp/print" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Driverless printers (IPP Everywhere):" | ||
| i=1 | ||
| declare -a names uris | ||
| for entry in "${entries[@]}"; do | ||
| names+=("${entry%%$'\t'*}") | ||
| uris+=("${entry#*$'\t'}") | ||
| printf ' %d) %s\n %s\n' "$i" "${names[-1]}" "${uris[-1]}" | ||
| i=$((i + 1)) | ||
| done | ||
|
|
||
| if ((${#entries[@]} == 1)); then | ||
| choice=1 | ||
| echo "Only one printer found; using it." | ||
| else | ||
| read -r -p "Choose printer [1-${#entries[@]}]: " choice | ||
| fi | ||
|
|
||
| if ! [[ $choice =~ ^[0-9]+$ ]] || ((choice < 1 || choice > ${#entries[@]})); then | ||
| echo "omarchy-setup-printer: invalid choice" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| idx=$((choice - 1)) | ||
| add_everywhere_queue "${names[$idx]}" "${uris[$idx]}" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" | ||
|
|
||
| setup_printer="$ROOT/bin/omarchy-setup-printer" | ||
| faq="$ROOT/manual/46-faq.md" | ||
| cups_browsed="$ROOT/etc/cups/cups-browsed.conf" | ||
| menu="$ROOT/default/omarchy/omarchy-menu.jsonc" | ||
|
|
||
| rg -q 'omarchy:summary=Add a network printer with the driverless IPP Everywhere profile' "$setup_printer" || | ||
| fail "setup-printer advertises IPP Everywhere" | ||
| rg -q 'lpadmin -p "\$queue" -E -v "\$uri" -m everywhere' "$setup_printer" || | ||
| fail "setup-printer creates queues with the everywhere model" | ||
| rg -q 'driverless list' "$setup_printer" || | ||
| fail "setup-printer discovers printers through driverless" | ||
| pass "setup-printer prefers IPP Everywhere for network printers" | ||
|
|
||
| rg -qxF 'CreateIPPPrinterQueues Driverless' "$cups_browsed" || | ||
| fail "cups-browsed policy stays limited to driverless IPP queues" | ||
| pass "cups-browsed policy stays limited to driverless IPP queues" | ||
|
|
||
| rg -q 'omarchy setup printer' "$faq" || | ||
| fail "FAQ documents the IPP Everywhere setup command" | ||
| rg -q 'universal.*/pdftopdf|pdftopdf' "$faq" || | ||
| fail "FAQ warns against universal/pdftopdf brand drivers" | ||
| pass "FAQ prefers IPP Everywhere over brand PPDs" | ||
|
|
||
| rg -q 'omarchy-setup-printer' "$menu" || | ||
| fail "Setup menu exposes the printer wizard" | ||
| pass "Setup menu exposes the printer wizard" | ||
|
|
||
| tmp_dir=$(mktemp -d) | ||
| trap 'rm -rf "$tmp_dir"' EXIT | ||
|
|
||
| mkdir -p "$tmp_dir/bin" | ||
| cat >"$tmp_dir/bin/driverless" <<'SH' | ||
| #!/bin/bash | ||
| if [[ ${1:-} == "list" ]]; then | ||
| printf '%s\n' 'driverless:ipp://EPSON._ipp._tcp.local/ipp/print "EPSON ET-2850" "EPSON ET-2850 IPP Everywhere" ""' | ||
| fi | ||
| exit 0 | ||
| SH | ||
| cat >"$tmp_dir/bin/sudo" <<'SH' | ||
| #!/bin/bash | ||
| # Record the privileged command and run it from PATH so lpadmin is mocked. | ||
| printf '%s\n' "$*" >>"$LPADMIN_LOG" | ||
| exec "$@" | ||
| SH | ||
| cat >"$tmp_dir/bin/lpadmin" <<'SH' | ||
| #!/bin/bash | ||
| printf 'lpadmin %s\n' "$*" >>"$LPADMIN_LOG" | ||
| exit 0 | ||
| SH | ||
| chmod +x "$tmp_dir/bin/driverless" "$tmp_dir/bin/sudo" "$tmp_dir/bin/lpadmin" | ||
|
|
||
| LPADMIN_LOG="$tmp_dir/lpadmin.log" | ||
| : >"$LPADMIN_LOG" | ||
| PATH="$tmp_dir/bin:$PATH" LPADMIN_LOG="$LPADMIN_LOG" \ | ||
| "$setup_printer" Office 'ipp://192.168.1.50/ipp/print' | ||
|
|
||
| grep -qx 'lpadmin -p Office -E -v ipp://192.168.1.50/ipp/print -m everywhere' "$LPADMIN_LOG" || | ||
| fail "direct URI path creates an Everywhere queue" "$(cat "$LPADMIN_LOG")" | ||
| grep -qx 'lpadmin -p Office -o printer-error-policy=retry-job' "$LPADMIN_LOG" || | ||
| fail "direct URI path sets a retry error policy" "$(cat "$LPADMIN_LOG")" | ||
| pass "direct URI path creates an Everywhere queue" | ||
|
|
||
| : >"$LPADMIN_LOG" | ||
| PATH="$tmp_dir/bin:$PATH" LPADMIN_LOG="$LPADMIN_LOG" \ | ||
| "$setup_printer" </dev/null | ||
|
|
||
| grep -q 'lpadmin -p EPSON_ET-2850 -E -v ipp://EPSON._ipp._tcp.local/ipp/print -m everywhere' "$LPADMIN_LOG" || | ||
| fail "discovered printer is added with Everywhere" "$(cat "$LPADMIN_LOG")" | ||
| pass "discovered printer is added with Everywhere" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please parse the actual
driverless listformat: upstream prints"driverless:ipp://..." en "Epson" "Epson ..., driverless, ..." ..., including quotes around the first field, so^driverless:matches none of its rows. running this command against that fixture reports no printers and exits 1; please cover a real quoted discovery line and extract the unquoted uri before passing it to lpadmin.