Skip to content

Commit 85ce88c

Browse files
committed
Add bin/install-printer.sh for Rongta RP326 CUPS setup
Installs CUPS and required print filter packages, configures CUPS to listen on the local subnet (not just localhost), and registers a named printer queue using the Rongta Printer80.ppd driver. Requires PRINTER_HOST (device network address) and PRINTER_NAME (CUPS queue name) to be set; validates both before proceeding. All CUPS config changes are idempotent. Made-with: Cursor
1 parent e682e8d commit 85ce88c

1 file changed

Lines changed: 113 additions & 0 deletions

File tree

bin/install-printer.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/sh
2+
#
3+
# install-printer.sh
4+
# Install CUPS and configure the s2-receipt printer (Rongta RP326).
5+
#
6+
# Prerequisites:
7+
# PRINTER_HOST - network hostname or IP address of the Rongta RP326 device
8+
# PRINTER_NAME - CUPS queue name for the printer (e.g. s2-receipt)
9+
# Rongta driver - must be installed before running this script;
10+
# it provides /usr/share/ppd/rongta/Printer80.ppd
11+
12+
PPD=/usr/share/ppd/rongta/Printer80.ppd
13+
14+
# ── Check prerequisites ────────────────────────────────────────────────────────
15+
err=0
16+
17+
if [ -z "$PRINTER_HOST" ]; then
18+
echo "Error: PRINTER_HOST is not set." >&2
19+
echo " Set it to the hostname or IP address of the Rongta RP326 device." >&2
20+
echo " Example: PRINTER_HOST=192.168.1.100" >&2
21+
err=1
22+
fi
23+
24+
if [ -z "$PRINTER_NAME" ]; then
25+
echo "Error: PRINTER_NAME is not set." >&2
26+
echo " Set it to the desired CUPS queue name for the printer." >&2
27+
echo " Example: PRINTER_NAME=s2-receipt" >&2
28+
err=1
29+
fi
30+
31+
if [ "$err" -ne 0 ]; then
32+
echo "" >&2
33+
echo "The Rongta RP326 printer driver must also be installed first." >&2
34+
echo "It should provide: $PPD" >&2
35+
exit 1
36+
fi
37+
38+
# ── Install packages ───────────────────────────────────────────────────────────
39+
echo "==> Installing CUPS and print filter packages..."
40+
sudo apt-get install -y \
41+
cups \
42+
libcupsimage2 \
43+
cups-filters \
44+
cups-pdf \
45+
ghostscript \
46+
poppler-utils \
47+
qpdf \
48+
imagemagick
49+
50+
# ── Check PPD ─────────────────────────────────────────────────────────────────
51+
if [ ! -f "$PPD" ]; then
52+
echo "Error: Rongta PPD not found at $PPD" >&2
53+
echo "Install the Rongta RP326 driver package and re-run this script." >&2
54+
exit 1
55+
fi
56+
57+
# ── Configure CUPS for local network access ───────────────────────────────────
58+
echo "==> Configuring CUPS..."
59+
60+
CUPSD_CONF=/etc/cups/cupsd.conf
61+
62+
# Ensure CUPS listens on all interfaces, not just localhost.
63+
# Explicit grep check makes this safely re-runnable.
64+
if sudo grep -q '^Listen localhost:631$' "$CUPSD_CONF"; then
65+
sudo sed -i 's/^Listen localhost:631$/Port 631/' "$CUPSD_CONF"
66+
echo " Changed Listen localhost:631 -> Port 631"
67+
else
68+
echo " Port 631 already set, skipping"
69+
fi
70+
71+
# Add Allow @LOCAL after every "Order allow,deny" line so subnet clients
72+
# can browse and print. The grep anchors to actual directives (leading
73+
# whitespace, not a comment #) so a commented-out example line won't
74+
# falsely satisfy the check.
75+
if ! sudo grep -q '^[[:space:]]*Allow @LOCAL' "$CUPSD_CONF"; then
76+
sudo sed -i '/Order allow,deny/a\ Allow @LOCAL' "$CUPSD_CONF"
77+
echo " Added Allow @LOCAL to Location blocks"
78+
else
79+
echo " Allow @LOCAL already present, skipping"
80+
fi
81+
82+
# Advertise shared printers via DNS-SD so clients can discover them.
83+
# cupsctl is idempotent.
84+
sudo cupsctl --share-printers
85+
86+
sudo systemctl enable --now cups
87+
sudo systemctl restart cups
88+
echo "CUPS configured (listening on subnet, printer sharing enabled)."
89+
90+
# ── Install the printer queue ─────────────────────────────────────────────────
91+
echo "==> Installing printer queue '$PRINTER_NAME' -> $PRINTER_HOST ..."
92+
93+
# Remove any existing queue with the same name so this is idempotent.
94+
sudo lpadmin -x "$PRINTER_NAME" 2>/dev/null || true
95+
96+
# Add the printer. Port 9100 is the standard raw/JetDirect socket used
97+
# by Rongta and most thermal network printers.
98+
sudo lpadmin \
99+
-p "$PRINTER_NAME" \
100+
-E \
101+
-v "socket://${PRINTER_HOST}:9100" \
102+
-P "$PPD" \
103+
-D "Rongta RP326 Receipt Printer" \
104+
-L "s2"
105+
106+
# Make it the system default.
107+
sudo lpoptions -d "$PRINTER_NAME"
108+
109+
echo "Printer '$PRINTER_NAME' installed and set as default."
110+
echo ""
111+
echo "Test with: echo 'Test print' | lpr -P $PRINTER_NAME"
112+
echo "Status: lpstat -p $PRINTER_NAME"
113+
echo "CUPS UI: http://$(hostname -I | awk '{print $1}'):631"

0 commit comments

Comments
 (0)