117 lines
3.3 KiB
Bash
Executable File
117 lines
3.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# package.sh - Build Debian package for FeatherDDNS using a Debian container
|
|
#
|
|
# Usage: ./scripts/package.sh [version]
|
|
#
|
|
# Environment Variables:
|
|
# CONTAINER_RUNTIME Container runtime to use (default: podman)
|
|
# VERSION Override package version
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
IMAGE_NAME="featherddns-debian-builder"
|
|
CONTAINER_RUNTIME="${CONTAINER_RUNTIME:-podman}"
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
|
success() { echo -e "${GREEN}[OK]${NC} $1"; }
|
|
error() { echo -e "${RED}[ERROR]${NC} $1" >&2; }
|
|
|
|
# Get version from Makefile or argument
|
|
get_version() {
|
|
grep "^VERSION" "$PROJECT_ROOT/Makefile" 2>/dev/null | head -1 | sed 's/.*:= *//' | tr -d ' '
|
|
}
|
|
|
|
VERSION="${1:-${VERSION:-$(get_version)}}"
|
|
VERSION="${VERSION:-1.0.0}"
|
|
|
|
info "Packaging FeatherDDNS version ${VERSION}"
|
|
|
|
# Check container runtime
|
|
if ! command -v "$CONTAINER_RUNTIME" >/dev/null 2>&1; then
|
|
error "Container runtime '$CONTAINER_RUNTIME' not found"
|
|
info "Install podman or docker, or set CONTAINER_RUNTIME"
|
|
exit 1
|
|
fi
|
|
|
|
info "Using container runtime: $CONTAINER_RUNTIME"
|
|
|
|
# Check binary exists
|
|
if [[ ! -f "$PROJECT_ROOT/bin/FeatherDDNS" ]]; then
|
|
error "Binary not found: bin/FeatherDDNS"
|
|
info "Build first with: make build"
|
|
exit 1
|
|
fi
|
|
|
|
success "Binary found: bin/FeatherDDNS"
|
|
|
|
# Build container image if needed
|
|
info "Checking for debian-builder image..."
|
|
|
|
NEED_BUILD=false
|
|
if ! $CONTAINER_RUNTIME image exists "$IMAGE_NAME" 2>/dev/null; then
|
|
info "Image does not exist, building..."
|
|
NEED_BUILD=true
|
|
else
|
|
DOCKERFILE_TIME=$(stat -c %Y "$PROJECT_ROOT/Dockerfile.debian-builder" 2>/dev/null || echo 0)
|
|
IMAGE_TIME=$($CONTAINER_RUNTIME image inspect "$IMAGE_NAME" --format '{{.Created}}' 2>/dev/null | xargs -I{} date -d {} +%s 2>/dev/null || echo 0)
|
|
if [[ "$DOCKERFILE_TIME" -gt "$IMAGE_TIME" ]]; then
|
|
info "Dockerfile is newer than image, rebuilding..."
|
|
NEED_BUILD=true
|
|
fi
|
|
fi
|
|
|
|
if [[ "$NEED_BUILD" == "true" ]]; then
|
|
if ! $CONTAINER_RUNTIME build -t "$IMAGE_NAME" -f "$PROJECT_ROOT/Dockerfile.debian-builder" "$PROJECT_ROOT"; then
|
|
error "Failed to build debian-builder image"
|
|
exit 1
|
|
fi
|
|
success "debian-builder image built"
|
|
else
|
|
success "debian-builder image is up-to-date"
|
|
fi
|
|
|
|
# Create dist directory
|
|
mkdir -p "$PROJECT_ROOT/dist"
|
|
|
|
# Determine SELinux mount option
|
|
MOUNT_OPT=""
|
|
if command -v getenforce >/dev/null 2>&1 && [[ "$(getenforce 2>/dev/null)" != "Disabled" ]]; then
|
|
MOUNT_OPT=":Z"
|
|
info "SELinux detected, using :Z mount flag"
|
|
fi
|
|
|
|
# Run packaging in container
|
|
info "Running packaging in container..."
|
|
|
|
if ! $CONTAINER_RUNTIME run --rm \
|
|
-v "${PROJECT_ROOT}:/build${MOUNT_OPT}" \
|
|
-e "VERSION=${VERSION}" \
|
|
-w /build \
|
|
"$IMAGE_NAME" \
|
|
/bin/bash -c "./scripts/build-deb.sh"; then
|
|
error "Container packaging failed"
|
|
exit 1
|
|
fi
|
|
|
|
# Verify output
|
|
DEB_FILE=$(find "$PROJECT_ROOT/dist" -name "featherddns_*.deb" -type f 2>/dev/null | head -1)
|
|
|
|
if [[ -n "$DEB_FILE" ]]; then
|
|
success "Package created: $DEB_FILE"
|
|
ls -lh "$DEB_FILE"
|
|
else
|
|
error "Package not found in dist/"
|
|
ls -la "$PROJECT_ROOT/dist/" 2>/dev/null || true
|
|
exit 1
|
|
fi
|
|
|
|
success "Packaging complete!"
|