Add Debian .deb package support
- debian/control, changelog, conffiles — package metadata - debian/postinst — creates irc-bot system user, installs Python venv, symlinks runtime dirs, enables systemd services - debian/prerm/postrm — clean stop/uninstall with purge support - debian/systemd/ — hardened systemd units for bot and portal - build_deb.sh — assembles and builds the .deb via dpkg-deb - Path resolver in irc_client.py, memory.py, config_manager.py, portal/app.py: uses /etc/irc-bot + /var/lib/irc-bot when installed as .deb, relative paths otherwise (Docker/venv unchanged) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,16 +18,27 @@ from pathlib import Path
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
# ── Path resolution: deb install vs Docker/venv ────────────────────────────
|
||||
# If /etc/irc-bot exists we're running from a .deb package install.
|
||||
if os.path.isdir("/etc/irc-bot"):
|
||||
_CONFIG_BASE = "/etc/irc-bot"
|
||||
_DATA_BASE = "/var/lib/irc-bot"
|
||||
_LOG_BASE = "/var/log/irc-bot"
|
||||
load_dotenv("/etc/irc-bot/.env")
|
||||
else:
|
||||
_CONFIG_BASE = "config"
|
||||
_DATA_BASE = "data"
|
||||
_LOG_BASE = "logs"
|
||||
load_dotenv()
|
||||
|
||||
os.makedirs(_LOG_BASE, exist_ok=True)
|
||||
os.makedirs(_DATA_BASE, exist_ok=True)
|
||||
os.makedirs(_CONFIG_BASE, exist_ok=True)
|
||||
|
||||
# ── Logging ────────────────────────────────────────────────────────────────
|
||||
|
||||
os.makedirs("logs", exist_ok=True)
|
||||
os.makedirs("data", exist_ok=True)
|
||||
os.makedirs("config", exist_ok=True)
|
||||
|
||||
handler = logging.handlers.RotatingFileHandler(
|
||||
"logs/bot.log", maxBytes=5 * 1024 * 1024, backupCount=3, encoding="utf-8"
|
||||
os.path.join(_LOG_BASE, "bot.log"), maxBytes=5 * 1024 * 1024, backupCount=3, encoding="utf-8"
|
||||
)
|
||||
handler.setFormatter(
|
||||
logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
|
||||
@@ -43,9 +54,9 @@ from bot.message_handler import handle_privmsg
|
||||
|
||||
# ── Config ─────────────────────────────────────────────────────────────────
|
||||
|
||||
CONFIG_PATH = "config/config.json"
|
||||
PID_PATH = "data/ircbot.pid"
|
||||
SOCK_PATH = "data/ircbot.sock"
|
||||
CONFIG_PATH = os.path.join(_CONFIG_BASE, "config.json")
|
||||
PID_PATH = os.path.join(_DATA_BASE, "ircbot.pid")
|
||||
SOCK_PATH = os.path.join(_DATA_BASE, "ircbot.sock")
|
||||
|
||||
_config: dict = {}
|
||||
_config_lock = threading.Lock()
|
||||
|
||||
@@ -5,7 +5,11 @@ import re
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
HISTORY_DIR = "data/history"
|
||||
HISTORY_DIR = (
|
||||
"/var/lib/irc-bot/history"
|
||||
if os.path.isdir("/var/lib/irc-bot")
|
||||
else "data/history"
|
||||
)
|
||||
|
||||
|
||||
def _sanitize_channel(channel: str) -> str:
|
||||
|
||||
Reference in New Issue
Block a user