210d27f9c4
CI / test (push) Failing after 12m28s
Debian versions must start with a digit. When called via 'make deb', VERSION is passed from Makefile (git describe output includes 'v' prefix). The strip was previously only done inside the auto-detection branch, so 'make deb' produced invalid versions like 'v2026.07.30-2-g05604a8-1'. Now VERSION= runs after the version is determined, regardless of whether it came from an argument or auto-detection.
118 lines
3.2 KiB
Bash
Executable File
118 lines
3.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# build-deb.sh — Build a .deb package for LlamaLink
|
|
set -euo pipefail
|
|
|
|
VERSION="${1:-}"
|
|
ARCH="${2:-$(dpkg --print-architecture 2>/dev/null || echo "amd64")}"
|
|
|
|
if [[ -z "$VERSION" ]]; then
|
|
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
|
fi
|
|
|
|
VERSION="${VERSION#v}"
|
|
|
|
if ! command -v dpkg-deb &>/dev/null; then
|
|
echo "Error: dpkg-deb not found. Install with: sudo apt install dpkg" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ "$(uname)" != "Linux" ]]; then
|
|
echo "Error: .deb packages can only be built on Linux." >&2
|
|
exit 1
|
|
fi
|
|
|
|
DEB_VERSION="${VERSION}-1"
|
|
BUILD_DIR="dist/deb-build"
|
|
PKG_DIR="${BUILD_DIR}/llamalink-${DEB_VERSION}_${ARCH}"
|
|
|
|
echo "==> Building llamalink_${DEB_VERSION}_${ARCH}.deb"
|
|
|
|
rm -rf "$BUILD_DIR"
|
|
mkdir -p "$PKG_DIR"/{DEBIAN,usr/local/bin,etc/llamalink,etc/systemd/system,opt/llamalink/data,var/log/llamalink}
|
|
|
|
# Binary (must exist)
|
|
if [[ ! -f "bin/llamalink" ]]; then
|
|
echo "Error: bin/llamalink not found. Run 'make build' first." >&2
|
|
exit 1
|
|
fi
|
|
cp bin/llamalink "$PKG_DIR/usr/local/bin/"
|
|
chmod 755 "$PKG_DIR/usr/local/bin/llamalink"
|
|
|
|
# Config template
|
|
cp .env.example "$PKG_DIR/etc/llamalink/env"
|
|
chmod 644 "$PKG_DIR/etc/llamalink/env"
|
|
|
|
# Systemd unit
|
|
cp deploy/llamalink.service "$PKG_DIR/etc/systemd/system/llamalink.service"
|
|
|
|
# DEBIAN/control
|
|
cat > "$PKG_DIR/DEBIAN/control" <<EOF
|
|
Package: llamalink
|
|
Version: ${DEB_VERSION}
|
|
Section: net
|
|
Priority: optional
|
|
Architecture: ${ARCH}
|
|
Maintainer: LlamaLink <hello@llamalink.dev>
|
|
Description: API Gateway for local LLM inference via llama.cpp
|
|
Provides a REST API with API key authentication, rate limiting,
|
|
and multi-model hot-swap for llama.cpp server instances.
|
|
Homepage: https://github.com/llamalink/llamalink
|
|
Depends: libc6
|
|
EOF
|
|
|
|
# DEBIAN/conffiles
|
|
echo "/etc/llamalink/env" > "$PKG_DIR/DEBIAN/conffiles"
|
|
|
|
# DEBIAN/postinst
|
|
cat > "$PKG_DIR/DEBIAN/postinst" <<'POSTINST'
|
|
#!/bin/sh
|
|
set -e
|
|
if [ "$1" = "configure" ]; then
|
|
if ! id llamalink > /dev/null 2>&1; then
|
|
useradd --system --no-create-home --shell /usr/sbin/nologin llamalink 2>/dev/null || true
|
|
fi
|
|
mkdir -p /opt/llamalink/data /var/log/llamalink
|
|
chown llamalink:llamalink /opt/llamalink/data /var/log/llamalink 2>/dev/null || true
|
|
if command -v systemctl >/dev/null 2>&1; then
|
|
systemctl daemon-reload 2>/dev/null || true
|
|
fi
|
|
fi
|
|
POSTINST
|
|
chmod 755 "$PKG_DIR/DEBIAN/postinst"
|
|
|
|
# DEBIAN/prerm
|
|
cat > "$PKG_DIR/DEBIAN/prerm" <<'PRERM'
|
|
#!/bin/sh
|
|
set -e
|
|
if [ "$1" = "remove" ] || [ "$1" = "purge" ]; then
|
|
if command -v systemctl >/dev/null 2>&1; then
|
|
systemctl stop llamalink.service 2>/dev/null || true
|
|
systemctl disable llamalink.service 2>/dev/null || true
|
|
fi
|
|
fi
|
|
PRERM
|
|
chmod 755 "$PKG_DIR/DEBIAN/prerm"
|
|
|
|
# DEBIAN/postrm
|
|
cat > "$PKG_DIR/DEBIAN/postrm" <<'POSTRM'
|
|
#!/bin/sh
|
|
set -e
|
|
if [ "$1" = "purge" ]; then
|
|
rm -rf /opt/llamalink/data /var/log/llamalink
|
|
if id llamalink > /dev/null 2>&1; then
|
|
userdel llamalink 2>/dev/null || true
|
|
fi
|
|
if command -v systemctl >/dev/null 2>&1; then
|
|
systemctl daemon-reload 2>/dev/null || true
|
|
fi
|
|
fi
|
|
POSTRM
|
|
chmod 755 "$PKG_DIR/DEBIAN/postrm"
|
|
|
|
# Build .deb
|
|
mkdir -p dist
|
|
dpkg-deb --build "$PKG_DIR" "dist/llamalink_${DEB_VERSION}_${ARCH}.deb"
|
|
|
|
echo "==> Created dist/llamalink_${DEB_VERSION}_${ARCH}.deb"
|
|
rm -rf "$BUILD_DIR"
|