Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions bin/omarchy-setup-printer
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:/ {

Copy link
Copy Markdown
Contributor

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 list format: 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.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security Existing queues can be redirected

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 lpadmin -p ... -v without a collision check.

sudo lpadmin -p "$queue" -o printer-error-policy=retry-job
Comment on lines +57 to +58

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Failed policy leaves partial queue

If the second lpadmin call fails, the first has already created and enabled the queue. The command then exits with an error, but leaves a queue without the intended error policy. Apply the policy during creation or clean up a partially configured queue.

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]}"
1 change: 1 addition & 0 deletions default/omarchy/omarchy-menu.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
"setup.config.hyprsunset": {"icon":"","label":"Hyprsunset","action":"omarchy-launch-config-editor ~/.config/hypr/hyprsunset.conf && omarchy-restart-hyprsunset"},
"setup.config.xcompose": {"icon":"󰞅","label":"XCompose","action":"omarchy-launch-config-editor ~/.XCompose && omarchy-restart-xcompose"},
"setup.direct-boot": {"icon":"","label":"Direct Boot","action":"omarchy-launch-floating-terminal-with-presentation omarchy-setup-direct-boot"},
"setup.printer": {"icon":"󰐪","label":"Printer","action":"omarchy-launch-floating-terminal-with-presentation omarchy-setup-printer"},
"setup.reset": {"icon":"󰑓","label":"Reset Computer","when":"[[ $(findmnt -no FSTYPE /) == btrfs ]]","action":"omarchy-launch-floating-terminal-with-presentation omarchy-system-factory-reset"},

// Install
Expand Down
2 changes: 2 additions & 0 deletions etc/cups/cups-browsed.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ CacheDir /var/cache/cups-browsed

# Auto-create queues only for modern driverless IPP printers. Remote queues
# exported by another CUPS server can still be added manually when needed.
# Brand PPDs that drag jobs through universal/pdftopdf are intentionally out of
# scope here — omarchy-setup-printer and Print Settings should use Everywhere.
CreateIPPPrinterQueues Driverless
CreateRemoteCUPSPrinterQueues No
10 changes: 8 additions & 2 deletions manual/46-faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ The plain open source Chromium build doesn't ship with the OAuth credentials tha

### How do I add a printer?

Printing is set up and running out of the box, and you add each printer yourself from _Print Settings_ in the app launcher (`Super + Space`).
Printing is set up and running out of the box. For a modern network printer (AirPrint / IPP Everywhere), prefer the driverless path:

Choose _Add_, and give it a moment to look: a printer plugged in over USB, and most network printers, are found for you. If yours isn't in the list, pick _Network Printer > Internet Printing Protocol (ipp)_ and enter its address — the printer's own display or its web page will tell you what that is, usually something like `192.168.1.50` with a queue of `ipp/print`. _Forward_ then offers a driver, where a modern printer works best on the driverless _IPP Everywhere_ profile and an older one wants the model's own driver.
```
omarchy setup printer
```

That discovers IPP printers on the LAN and adds them with the _IPP Everywhere_ profile, which talks to the printer directly. Brand model drivers (Epson ESC/P-R and friends) route jobs through cups-filters' `universal` / `pdftopdf` chain and often fail with "filter failed" on those same printers — skip them when _Forward_ offers a choice.

You can still use _Print Settings_ in the app launcher (`Super + Space`): choose _Add_, pick the printer (or _Network Printer > Internet Printing Protocol (ipp)_ with an address like `192.168.1.50` and queue `ipp/print`), then on the driver step pick _IPP Everywhere_ / _driverless_, not the brand PPD.

Right-click a printer and choose _Set as Default_ to pick which one your apps reach for first, and _Properties_ to set paper size, duplex and quality.

Expand Down
75 changes: 75 additions & 0 deletions test/shell.d/cups-ipp-everywhere-test.sh
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"