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:
@@ -7,7 +7,12 @@ from dotenv import load_dotenv
|
||||
from flask import Flask, abort, jsonify, redirect, render_template, request, url_for, send_file
|
||||
import io
|
||||
|
||||
load_dotenv()
|
||||
if os.path.isdir("/etc/irc-bot"):
|
||||
load_dotenv("/etc/irc-bot/.env")
|
||||
_LOG_PATH = "/var/log/irc-bot/bot.log"
|
||||
else:
|
||||
load_dotenv()
|
||||
_LOG_PATH = _LOG_PATH
|
||||
|
||||
app = Flask(__name__, template_folder="templates", static_folder="static")
|
||||
app.secret_key = os.getenv("PORTAL_SECRET_KEY", "changeme")
|
||||
@@ -66,7 +71,7 @@ def action_reconnect():
|
||||
@app.route("/action/clear_log", methods=["POST"])
|
||||
def action_clear_log():
|
||||
try:
|
||||
open("logs/bot.log", "w").close()
|
||||
open(_LOG_PATH, "w").close()
|
||||
except Exception:
|
||||
pass
|
||||
return redirect(url_for("logs"))
|
||||
@@ -164,7 +169,7 @@ def bot():
|
||||
@app.route("/logs")
|
||||
def logs():
|
||||
lines = []
|
||||
log_path = "logs/bot.log"
|
||||
log_path = _LOG_PATH
|
||||
if os.path.exists(log_path):
|
||||
with open(log_path, "r", encoding="utf-8", errors="replace") as f:
|
||||
all_lines = f.readlines()
|
||||
@@ -174,7 +179,7 @@ def logs():
|
||||
|
||||
@app.route("/logs/download")
|
||||
def logs_download():
|
||||
log_path = "logs/bot.log"
|
||||
log_path = _LOG_PATH
|
||||
if not os.path.exists(log_path):
|
||||
abort(404)
|
||||
return send_file(log_path, as_attachment=True, download_name="bot.log")
|
||||
@@ -183,7 +188,7 @@ def logs_download():
|
||||
@app.route("/api/logs")
|
||||
def api_logs():
|
||||
lines = []
|
||||
log_path = "logs/bot.log"
|
||||
log_path = _LOG_PATH
|
||||
if os.path.exists(log_path):
|
||||
with open(log_path, "r", encoding="utf-8", errors="replace") as f:
|
||||
lines = f.readlines()[-200:]
|
||||
|
||||
@@ -7,9 +7,14 @@ import sys
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
CONFIG_PATH = "config/config.json"
|
||||
PID_PATH = "data/ircbot.pid"
|
||||
SOCK_PATH = "data/ircbot.sock"
|
||||
if os.path.isdir("/etc/irc-bot"):
|
||||
CONFIG_PATH = "/etc/irc-bot/config.json"
|
||||
PID_PATH = "/var/lib/irc-bot/ircbot.pid"
|
||||
SOCK_PATH = "/var/lib/irc-bot/ircbot.sock"
|
||||
else:
|
||||
CONFIG_PATH = "config/config.json"
|
||||
PID_PATH = "data/ircbot.pid"
|
||||
SOCK_PATH = "data/ircbot.sock"
|
||||
|
||||
|
||||
def load_config() -> dict:
|
||||
|
||||
Reference in New Issue
Block a user