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:
5
debian/changelog
vendored
Normal file
5
debian/changelog
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
irc-bot (1.0.0) stable; urgency=low
|
||||
|
||||
* Initial release.
|
||||
|
||||
-- tocmo0nlord <tocmo0nlord@activeblue.net> Thu, 17 Apr 2026 00:00:00 +0000
|
||||
2
debian/conffiles
vendored
Normal file
2
debian/conffiles
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/etc/irc-bot/config.json
|
||||
/etc/irc-bot/.env
|
||||
15
debian/control
vendored
Normal file
15
debian/control
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
Package: irc-bot
|
||||
Version: 1.0.0
|
||||
Section: net
|
||||
Priority: optional
|
||||
Architecture: all
|
||||
Installed-Size: 0
|
||||
Depends: python3 (>= 3.11), python3-pip, python3-venv, adduser
|
||||
Recommends: sqlite3
|
||||
Maintainer: tocmo0nlord <tocmo0nlord@activeblue.net>
|
||||
Description: Active Blue IRC LLM Bot
|
||||
An IRC bot that connects to a ZNC bouncer, joins configured channels,
|
||||
and responds to users via a locally hosted Ollama LLM. Includes a
|
||||
Flask-based web admin portal for live configuration. Conversation
|
||||
history is persisted per user per channel in SQLite.
|
||||
Homepage: http://192.168.1.64:3000/tocmo0nlord/irc-bot
|
||||
64
debian/postinst
vendored
Normal file
64
debian/postinst
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
APP_DIR=/opt/irc-bot
|
||||
DATA_DIR=/var/lib/irc-bot
|
||||
LOG_DIR=/var/log/irc-bot
|
||||
CONF_DIR=/etc/irc-bot
|
||||
USER=irc-bot
|
||||
GROUP=irc-bot
|
||||
|
||||
case "$1" in
|
||||
configure)
|
||||
# Create system user/group if they don't exist
|
||||
if ! getent group "$GROUP" > /dev/null 2>&1; then
|
||||
addgroup --system "$GROUP"
|
||||
fi
|
||||
if ! getent passwd "$USER" > /dev/null 2>&1; then
|
||||
adduser --system --ingroup "$GROUP" --no-create-home \
|
||||
--home "$DATA_DIR" --shell /usr/sbin/nologin "$USER"
|
||||
fi
|
||||
|
||||
# Runtime directories
|
||||
install -d -m 750 -o "$USER" -g "$GROUP" "$DATA_DIR"
|
||||
install -d -m 750 -o "$USER" -g "$GROUP" "$DATA_DIR/history"
|
||||
install -d -m 750 -o "$USER" -g "$GROUP" "$LOG_DIR"
|
||||
|
||||
# Config directory — preserve existing .env if present
|
||||
install -d -m 750 -o "$USER" -g "$GROUP" "$CONF_DIR"
|
||||
if [ ! -f "$CONF_DIR/.env" ]; then
|
||||
cp "$APP_DIR/.env.example" "$CONF_DIR/.env"
|
||||
chown "$USER:$GROUP" "$CONF_DIR/.env"
|
||||
chmod 640 "$CONF_DIR/.env"
|
||||
echo ""
|
||||
echo " ┌─────────────────────────────────────────────────────┐"
|
||||
echo " │ irc-bot: edit /etc/irc-bot/.env before starting │"
|
||||
echo " │ Set ZNC_USER, ZNC_PASSWORD, ZNC_NETWORK at minimum │"
|
||||
echo " └─────────────────────────────────────────────────────┘"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Symlink runtime directories into app dir so relative paths work
|
||||
ln -sfn "$DATA_DIR" "$APP_DIR/data"
|
||||
ln -sfn "$LOG_DIR" "$APP_DIR/logs"
|
||||
ln -sfn "$CONF_DIR" "$APP_DIR/config"
|
||||
|
||||
# Install Python venv with dependencies
|
||||
if [ ! -d "$APP_DIR/venv" ]; then
|
||||
echo "irc-bot: creating Python venv and installing dependencies..."
|
||||
python3 -m venv "$APP_DIR/venv"
|
||||
"$APP_DIR/venv/bin/pip" install --quiet --no-cache-dir -r "$APP_DIR/requirements.txt"
|
||||
chown -R "$USER:$GROUP" "$APP_DIR/venv"
|
||||
fi
|
||||
|
||||
# Enable and start systemd services
|
||||
if [ -d /run/systemd/system ]; then
|
||||
systemctl daemon-reload
|
||||
systemctl enable irc-bot.service irc-bot-portal.service
|
||||
echo "irc-bot: services enabled. Start with:"
|
||||
echo " systemctl start irc-bot irc-bot-portal"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
25
debian/postrm
vendored
Normal file
25
debian/postrm
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
case "$1" in
|
||||
purge)
|
||||
# Remove data, logs, config only on purge (not plain remove)
|
||||
rm -rf /var/lib/irc-bot /var/log/irc-bot /etc/irc-bot
|
||||
# Remove system user
|
||||
if getent passwd irc-bot > /dev/null 2>&1; then
|
||||
deluser --system irc-bot 2>/dev/null || true
|
||||
fi
|
||||
if getent group irc-bot > /dev/null 2>&1; then
|
||||
delgroup --system irc-bot 2>/dev/null || true
|
||||
fi
|
||||
if [ -d /run/systemd/system ]; then
|
||||
systemctl daemon-reload
|
||||
fi
|
||||
;;
|
||||
remove)
|
||||
# Remove the venv on plain remove (can be rebuilt on reinstall)
|
||||
rm -rf /opt/irc-bot/venv
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
14
debian/prerm
vendored
Normal file
14
debian/prerm
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
case "$1" in
|
||||
remove|upgrade|deconfigure)
|
||||
if [ -d /run/systemd/system ]; then
|
||||
systemctl stop irc-bot-portal.service 2>/dev/null || true
|
||||
systemctl stop irc-bot.service 2>/dev/null || true
|
||||
systemctl disable irc-bot.service irc-bot-portal.service 2>/dev/null || true
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
27
debian/systemd/irc-bot-portal.service
vendored
Normal file
27
debian/systemd/irc-bot-portal.service
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
[Unit]
|
||||
Description=Active Blue IRC Bot Web Portal
|
||||
Documentation=http://192.168.1.64:3000/tocmo0nlord/irc-bot
|
||||
After=network-online.target irc-bot.service
|
||||
Wants=network-online.target
|
||||
BindsTo=irc-bot.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=irc-bot
|
||||
Group=irc-bot
|
||||
WorkingDirectory=/opt/irc-bot
|
||||
Environment="PYTHONPATH=/opt/irc-bot"
|
||||
EnvironmentFile=/etc/irc-bot/.env
|
||||
ExecStart=/opt/irc-bot/venv/bin/python -m portal.app
|
||||
Restart=on-failure
|
||||
RestartSec=10
|
||||
StandardOutput=append:/var/log/irc-bot/portal.log
|
||||
StandardError=append:/var/log/irc-bot/portal.log
|
||||
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectSystem=full
|
||||
ReadWritePaths=/etc/irc-bot /var/lib/irc-bot /var/log/irc-bot
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
27
debian/systemd/irc-bot.service
vendored
Normal file
27
debian/systemd/irc-bot.service
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
[Unit]
|
||||
Description=Active Blue IRC LLM Bot
|
||||
Documentation=http://192.168.1.64:3000/tocmo0nlord/irc-bot
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=irc-bot
|
||||
Group=irc-bot
|
||||
WorkingDirectory=/opt/irc-bot
|
||||
Environment="PYTHONPATH=/opt/irc-bot"
|
||||
EnvironmentFile=/etc/irc-bot/.env
|
||||
ExecStart=/opt/irc-bot/venv/bin/python -m bot.irc_client
|
||||
Restart=on-failure
|
||||
RestartSec=10
|
||||
StandardOutput=append:/var/log/irc-bot/bot.log
|
||||
StandardError=append:/var/log/irc-bot/bot.log
|
||||
|
||||
# Hardening
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectSystem=full
|
||||
ReadWritePaths=/etc/irc-bot /var/lib/irc-bot /var/log/irc-bot
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in New Issue
Block a user