mirror of
https://github.com/kuhyx/scripts.git
synced 2026-07-04 13:23:07 +02:00
feat: brother printer checker
This commit is contained in:
parent
16e5a47321
commit
449a01420a
@ -45,6 +45,15 @@ BROWSER_PATTERNS = frozenset([
|
||||
"opera",
|
||||
"microsoft-edge",
|
||||
"ungoogled-chromium",
|
||||
"thorium",
|
||||
])
|
||||
|
||||
# Electron apps that should NOT be treated as browsers
|
||||
# These use Chromium under the hood but are not web browsers
|
||||
ELECTRON_IGNORE = frozenset([
|
||||
"electron",
|
||||
"code", # VS Code
|
||||
"chrome_crashpad", # Crashpad handler used by all Electron apps
|
||||
])
|
||||
|
||||
# Patterns to ignore (browser helpers that aren't the main browser)
|
||||
@ -52,6 +61,7 @@ IGNORE_PATTERNS = frozenset([
|
||||
"crashhandler",
|
||||
"update",
|
||||
"helper",
|
||||
"crashpad",
|
||||
])
|
||||
|
||||
|
||||
@ -115,13 +125,14 @@ def is_steam_running(processes: Set[str]) -> bool:
|
||||
def is_browser_running(processes: Set[str]) -> bool:
|
||||
"""Check if any browser is running."""
|
||||
for proc in processes:
|
||||
# Skip ignored patterns
|
||||
# Skip Electron apps and ignored patterns
|
||||
if proc in ELECTRON_IGNORE:
|
||||
continue
|
||||
if any(ign in proc for ign in IGNORE_PATTERNS):
|
||||
continue
|
||||
# Check browser patterns
|
||||
for pattern in BROWSER_PATTERNS:
|
||||
if pattern in proc:
|
||||
return True
|
||||
# Use exact match to avoid false positives from Electron apps
|
||||
if proc in BROWSER_PATTERNS:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
||||
@ -56,5 +56,4 @@ youtube
|
||||
# Chrome/Chromium variants
|
||||
google-chrome
|
||||
chromium
|
||||
ungoogled-chromium
|
||||
thorium
|
||||
ungoogled-chromium
|
||||
@ -1,4 +1,5 @@
|
||||
# Exact package names that should bypass the block even if matching a keyword.
|
||||
thorium-browser-bin
|
||||
minizip
|
||||
miniupnpc
|
||||
haskell-generically
|
||||
|
||||
48
scripts/utils/check_brother_printer.sh
Executable file
48
scripts/utils/check_brother_printer.sh
Executable file
@ -0,0 +1,48 @@
|
||||
#!/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" "$@"
|
||||
Loading…
Reference in New Issue
Block a user