Nut Could Not Load Keys.txt < Ultra HD >
ERROR: keys.txt not found in current directory (/app/). Searched also: ~/.config/nut/keys.txt, /etc/nut/keys.txt. To fix: - Create keys.txt (one key per line) - Or set KEYS_PATH=/path/to/keys.txt - Or run: nut --gen-keys-template > keys.txt import os, sys from pathlib import Path def load_keys_file(): paths_to_try = [ os.environ.get("KEYS_PATH"), Path.cwd() / "keys.txt", Path.home() / ".config/nut/keys.txt", Path("/etc/nut/keys.txt") ] for path in paths_to_try: if path and Path(path).exists(): try: with open(path, "r") as f: keys = [line.strip() for line in f if line.strip()] if keys: return keys else: print(f"Warning: {path} is empty", file=sys.stderr) except PermissionError: print(f"Error: {path} not readable", file=sys.stderr) # Final failure print("FATAL: Could not load keys from any location.", file=sys.stderr) print("Use --help-keys for setup instructions.", file=sys.stderr) sys.exit(2) 5. Bonus Feature: --check-keys flag Runs only the key loading logic and reports success/failure without running main program – useful for scripting and debugging.