testsAndMisc/linux_configuration/scripts/single_use/utils/check_brother_printer.sh
Krzysztof kuhy Rudnicki 42a66a1419 refactor(linux_configuration/scripts): split all scripts into single_use/ and periodic_background/
- Move all linux_configuration scripts into two semantic categories:
  - single_use/: scripts run once manually (fresh install, fixes, setup)
  - periodic_background/: scripts run by systemd timers or daemons
- Preserve existing subdirectory structure within each category
- Fix lib/common.sh source paths for new directory depths
- Fix CONFIG_DIR depth in setup_periodic_system.sh and check_and_enable_services.sh
- Update all references in tests, fresh-install/main.sh, nix modules, and docs
- Fix check_polling_antipatterns.sh false positives (||, regex |, case patterns, jq strings)
- Fix pre-existing mypy exclusion path and type annotations for moved tools/ directory
- Rewrite check_polling_antipatterns.sh using awk (no bash regex loops); add require_serial: true
2026-05-15 00:32:35 +02:00

49 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Check Brother laser printer consumable/maintenance status.
# Thin wrapper that ensures dependencies are present, then runs the
# Python implementation in ~/testsAndMisc/python_pkg/brother_printer.
#
# Usage:
# ./check_brother_printer.sh # auto-detect USB or network
# ./check_brother_printer.sh <printer_ip> # force network/SNMP mode
set -euo pipefail
PYTHON_PKG_DIR="${HOME}/testsAndMisc/python_pkg"
BROTHER_MODULE="brother_printer"
# ── Ensure dependencies ─────────────────────────────────────────────
check_dependency() {
local cmd="$1" pkg="$2"
if ! command -v "$cmd" &>/dev/null; then
echo "Installing $pkg..."
sudo pacman -S --noconfirm --needed "$pkg"
fi
}
check_dependency python3 python
check_dependency lsusb usbutils
# net-snmp is optional (only needed for network mode)
if [[ -n "${1:-}" ]] && ! command -v snmpwalk &>/dev/null; then
echo "Installing net-snmp (needed for network mode)..."
sudo pacman -S --noconfirm --needed net-snmp
fi
# ── Verify the Python module exists ──────────────────────────────────
if [[ ! -f "${PYTHON_PKG_DIR}/${BROTHER_MODULE}/check_brother_printer.py" ]]; then
echo "Error: Python module not found at ${PYTHON_PKG_DIR}/${BROTHER_MODULE}/" >&2
exit 1
fi
# ── Run (with sudo for USB access) ──────────────────────────────────
if [[ $EUID -ne 0 ]]; then
exec sudo bash -c "cd '$PYTHON_PKG_DIR' && python3 -m '$BROTHER_MODULE' $*"
fi
cd "$PYTHON_PKG_DIR"
exec python3 -m "$BROTHER_MODULE" "$@"