From a5e8e49d51bc93b6c3ec5d6f25ec1d5e7bd4eebb Mon Sep 17 00:00:00 2001 From: "github.com/ib-bsb-br/ib-bsb-br.github.io" Date: Wed, 29 Apr 2026 09:11:22 -0300 Subject: [PATCH] Add automated Android-to-HL-L1222 print server setup script --- README.md | 31 ++++++- scripts/setup_hl_l1222_android_print.sh | 118 ++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 2 deletions(-) create mode 100755 scripts/setup_hl_l1222_android_print.sh diff --git a/README.md b/README.md index 6cde027..588c917 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,30 @@ -```codex_answers - +# Brother HL-L1222-V Android Print Server (Raspberry Pi 4B+ / openSUSE Tumbleweed) + +This repository now provides an executable setup script that configures a Raspberry Pi 4B+ (openSUSE Tumbleweed) as a print server for a USB-connected Brother HL-L1222/HL-L1222-V. + +## What this enables +- Android phones on the **same Wi-Fi network** can print through IPP (Mopria-compatible workflow). +- USB Brother printer is shared by CUPS over the local network. +- Firewall and discovery services are configured for LAN printing. + +## Important Bluetooth note +Android-to-Raspberry-Pi Bluetooth printing into CUPS is generally not reliable/supported in modern Android/CUPS workflows. The script still enables Bluetooth service for optional experimentation, but the production path is **Wi-Fi IPP**. + +## Script +- `scripts/setup_hl_l1222_android_print.sh` + +## Run +```bash +sudo bash scripts/setup_hl_l1222_android_print.sh ``` + +## After script completes +1. Keep printer connected via USB to Raspberry Pi. +2. Connect Android phone to same Wi-Fi as Raspberry Pi. +3. Enable Mopria Print Service (or equivalent Android print service). +4. Add printer with: + - `ipp:///printers/Brother_HL_L1222_V` + +## Notes +- Script uses CUPS `everywhere` model as default for broad compatibility. +- If you have an official Brother HL-L1222-V Linux PPD/driver package, install it and adjust queue model if desired. diff --git a/scripts/setup_hl_l1222_android_print.sh b/scripts/setup_hl_l1222_android_print.sh new file mode 100755 index 0000000..c9535a3 --- /dev/null +++ b/scripts/setup_hl_l1222_android_print.sh @@ -0,0 +1,118 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Setup script: Brother HL-L1222(-V) USB printer on openSUSE Tumbleweed (Raspberry Pi) +# Goal: receive print jobs from Android phones over the same Wi-Fi (IPP/Mopria) via CUPS. +# Note: Bluetooth printing from Android to CUPS is generally unsupported/restricted; script enables +# practical network printing path and optional USB OTG fallback guidance. + +PRINTER_NAME="Brother_HL_L1222_V" +PPD_MODEL="everywhere" + +if [[ ${EUID} -ne 0 ]]; then + echo "Please run as root: sudo bash $0" + exit 1 +fi + +REQ_CMDS=(zypper systemctl lpinfo lpadmin lpstat) +for c in "${REQ_CMDS[@]}"; do + command -v "$c" >/dev/null || { echo "Missing command: $c"; exit 1; } +done + +echo "[1/8] Installing print/network discovery stack..." +zypper --non-interactive refresh +zypper --non-interactive install \ + cups cups-filters ghostscript avahi nss-mdns \ + firewalld ipp-usb bluez bluez-tools + +echo "[2/8] Enabling required services..." +systemctl enable --now cups.service +systemctl enable --now avahi-daemon.service +systemctl enable --now firewalld.service +systemctl enable --now bluetooth.service + +# Ensure cupsd listens on local network for Android clients using IPP/Mopria. +CUPSD_CONF="/etc/cups/cupsd.conf" +if ! grep -q '^Port 631' "$CUPSD_CONF"; then + sed -i 's/^Listen localhost:631/# &/' "$CUPSD_CONF" || true + echo 'Port 631' >> "$CUPSD_CONF" +fi + +if ! grep -q '^Browsing Yes' "$CUPSD_CONF"; then + echo 'Browsing Yes' >> "$CUPSD_CONF" +fi + +if ! grep -q '^DefaultShared Yes' "$CUPSD_CONF"; then + echo 'DefaultShared Yes' >> "$CUPSD_CONF" +fi + +if ! grep -q '^WebInterface Yes' "$CUPSD_CONF"; then + echo 'WebInterface Yes' >> "$CUPSD_CONF" +fi + +if ! grep -q '' "$CUPSD_CONF"; then + cat >> "$CUPSD_CONF" <<'CUPSLOC' + + Order allow,deny + Allow @LOCAL + + + + Order allow,deny + Allow @LOCAL + +CUPSLOC +fi + +echo "[3/8] Opening firewall for IPP + mDNS..." +firewall-cmd --permanent --add-service=ipp || true +firewall-cmd --permanent --add-service=mdns || true +firewall-cmd --reload || true + +echo "[4/8] Detecting USB printer URI..." +USB_URI="$(lpinfo -v | awk '/^direct usb:\/\/Brother\//{print $2; exit}')" +if [[ -z "$USB_URI" ]]; then + echo "No Brother USB URI auto-detected. Available devices:" + lpinfo -v + echo "Connect the printer via USB and re-run this script." + exit 1 +fi + +echo "Detected URI: $USB_URI" + +echo "[5/8] Creating/updating CUPS queue..." +if lpstat -p "$PRINTER_NAME" >/dev/null 2>&1; then + lpadmin -x "$PRINTER_NAME" +fi +lpadmin -p "$PRINTER_NAME" -E -v "$USB_URI" -m "$PPD_MODEL" +lpoptions -d "$PRINTER_NAME" + +# Disable duplex (hardware lacks automatic duplex) +lpadmin -p "$PRINTER_NAME" -o sides=one-sided -o media=A4 + +# Enable sharing explicitly +lpadmin -p "$PRINTER_NAME" -o printer-is-shared=true + +echo "[6/8] Restarting CUPS..." +systemctl restart cups.service + +echo "[7/8] Printing a test page..." +lp -d "$PRINTER_NAME" /usr/share/cups/data/testprint || true + +echo "[8/8] Final status" +lpstat -t + +IP_ADDR="$(hostname -I | awk '{print $1}')" +cat <CUPS Bluetooth printing is typically not supported on modern Android/CUPS stacks. +- Use Wi-Fi IPP/Mopria path above, or USB-OTG direct phone-to-printer where supported by phone/app. +MSG