add packaging scripts

This commit is contained in:
2026-02-08 14:33:02 +08:00
parent 9b20887cc2
commit 6eb6ff6425
8 changed files with 152 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
Build the deb:
cd bitoj_python/packaging/ubuntu
bash build-deb.sh
Install:
sudo dpkg -i dist/bitoj_0.1.0_all.deb
Service:
sudo service bitoj start|stop|restart
sudo journalctl -u bitoj -f
Logs:
/var/log/bitoj/daemon.log
/var/log/bitoj/judge-*.log
/var/log/bitoj/tester-*.log

View File

@@ -0,0 +1,17 @@
[Unit]
Description=BitOJ Judge Daemon
After=network.target
[Service]
Type=simple
WorkingDirectory=/usr/lib/bitoj
ExecStart=/usr/lib/bitoj/judge-daemon
Restart=on-failure
RestartSec=2
User=root
Group=root
Environment=PYTHONUNBUFFERED=1
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,48 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
PROJECT_ROOT=$(cd "$SCRIPT_DIR/../.." && pwd)
OUT_DIR="$SCRIPT_DIR/dist"
BUILD_DIR="$SCRIPT_DIR/build"
PKG_ROOT="$BUILD_DIR/bitoj"
VERSION="${VERSION:-0.1.0}"
ARCH="${ARCH:-all}"
rm -rf "$BUILD_DIR" "$OUT_DIR"
mkdir -p "$PKG_ROOT/DEBIAN" \
"$PKG_ROOT/usr/lib/bitoj" \
"$PKG_ROOT/etc/bitoj" \
"$PKG_ROOT/lib/systemd/system" \
"$PKG_ROOT/var/lib/bitoj" \
"$PKG_ROOT/var/log/bitoj"
cp "$SCRIPT_DIR/control" "$PKG_ROOT/DEBIAN/control"
cp "$SCRIPT_DIR/postinst" "$PKG_ROOT/DEBIAN/postinst"
cp "$SCRIPT_DIR/prerm" "$PKG_ROOT/DEBIAN/prerm"
cp "$SCRIPT_DIR/postrm" "$PKG_ROOT/DEBIAN/postrm"
chmod 0755 "$PKG_ROOT/DEBIAN/postinst" "$PKG_ROOT/DEBIAN/prerm" "$PKG_ROOT/DEBIAN/postrm"
cp "$SCRIPT_DIR/bitoj.service" "$PKG_ROOT/lib/systemd/system/bitoj.service"
mkdir -p "$PKG_ROOT/usr/lib/tmpfiles.d"
cp "$SCRIPT_DIR/tmpfiles.conf" "$PKG_ROOT/usr/lib/tmpfiles.d/bitoj.conf"
if command -v rsync >/dev/null 2>&1; then
rsync -a --delete --exclude 'packaging/ubuntu' "$PROJECT_ROOT/" "$PKG_ROOT/usr/lib/bitoj/"
else
echo "rsync not found; fallback to cp -a" >&2
cp -a "$PROJECT_ROOT/." "$PKG_ROOT/usr/lib/bitoj/"
rm -rf "$PKG_ROOT/usr/lib/bitoj/packaging/ubuntu"
fi
chmod +x "$PKG_ROOT/usr/lib/bitoj/judge" \
"$PKG_ROOT/usr/lib/bitoj/judge-daemon" \
"$PKG_ROOT/usr/lib/bitoj/judgeold" \
"$PKG_ROOT/usr/lib/bitoj/judge-daemonold" \
"$PKG_ROOT/usr/lib/bitoj/utils/bitoj_adduser"
mkdir -p "$OUT_DIR"
dpkg-deb --build "$PKG_ROOT" "$OUT_DIR/bitoj_${VERSION}_${ARCH}.deb"
echo "Built: $OUT_DIR/bitoj_${VERSION}_${ARCH}.deb"

8
packaging/ubuntu/control Normal file
View File

@@ -0,0 +1,8 @@
Package: bitoj
Version: 0.1.0
Section: utils
Priority: optional
Architecture: all
Depends: python3, gcc, g++, sudo, adduser, bzip2, quota
Maintainer: BitOJ Maintainers <admin@localhost>
Description: BitOJ judge daemon and runtime for Ubuntu

42
packaging/ubuntu/postinst Normal file
View File

@@ -0,0 +1,42 @@
#!/bin/sh
set -e
mkdir -p /etc/bitoj /var/log/bitoj /var/lib/bitoj /usr/lib/bitoj/data
ln -sfn /etc/bitoj /usr/lib/bitoj/conf
ln -sfn /var/log/bitoj /usr/lib/bitoj/log
if [ ! -f /etc/bitoj/conf-default.py ]; then
if [ -f /usr/lib/bitoj/conf-demo.py ]; then
cp /usr/lib/bitoj/conf-demo.py /etc/bitoj/conf-default.py
else
touch /etc/bitoj/conf-default.py
fi
fi
if ! getent group oj >/dev/null 2>&1; then
groupadd --system oj
fi
if ! id -u oj >/dev/null 2>&1; then
useradd --system --no-create-home --gid oj --shell /usr/sbin/nologin oj
fi
if ! id -u ojrun01 >/dev/null 2>&1; then
/usr/lib/bitoj/utils/bitoj_adduser 1 10 || true
fi
chown -R oj:oj /var/lib/bitoj || true
chmod 755 /var/lib/bitoj /var/log/bitoj
if command -v systemctl >/dev/null 2>&1; then
systemctl daemon-reload
if command -v systemd-tmpfiles >/dev/null 2>&1; then
systemd-tmpfiles --create /usr/lib/tmpfiles.d/bitoj.conf || true
fi
systemctl enable bitoj.service >/dev/null 2>&1 || true
systemctl restart bitoj.service >/dev/null 2>&1 || true
fi
exit 0

12
packaging/ubuntu/postrm Normal file
View File

@@ -0,0 +1,12 @@
#!/bin/sh
set -e
if command -v systemctl >/dev/null 2>&1; then
systemctl daemon-reload
fi
if [ "$1" = "purge" ]; then
rm -rf /etc/bitoj
fi
exit 0

8
packaging/ubuntu/prerm Normal file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
set -e
if command -v systemctl >/dev/null 2>&1; then
systemctl stop bitoj.service >/dev/null 2>&1 || true
fi
exit 0

View File

@@ -0,0 +1,2 @@
d /var/log/bitoj 0755 root root -
d /var/lib/bitoj 0755 oj oj -