153 lines
3.7 KiB
Bash
Executable File
153 lines
3.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# build-deb.sh - Build Debian package for FeatherDDNS (runs inside container)
|
|
set -e
|
|
|
|
VERSION="${VERSION:-1.0.0}"
|
|
ARCH="amd64"
|
|
PACKAGE_NAME="featherddns"
|
|
MAINTAINER="Steven Tracey <steven@nevets.tech>"
|
|
HOMEPAGE="https://git.nevets.tech/Steven/FeatherDDNS"
|
|
|
|
BUILD_DIR="build/${PACKAGE_NAME}_${VERSION}_${ARCH}"
|
|
|
|
echo "Building ${PACKAGE_NAME} version ${VERSION}..."
|
|
|
|
# Clean and create build directory
|
|
rm -rf "$BUILD_DIR"
|
|
mkdir -p "$BUILD_DIR/DEBIAN"
|
|
mkdir -p "$BUILD_DIR/usr/bin"
|
|
mkdir -p "$BUILD_DIR/etc/featherddns"
|
|
mkdir -p "$BUILD_DIR/lib/systemd/system"
|
|
|
|
# Copy and strip binary
|
|
echo "Copying binary..."
|
|
cp "bin/FeatherDDNS" "$BUILD_DIR/usr/bin/featherddns"
|
|
strip "$BUILD_DIR/usr/bin/featherddns"
|
|
chmod 755 "$BUILD_DIR/usr/bin/featherddns"
|
|
|
|
# Copy config if exists
|
|
if [ -f "config.json.example" ]; then
|
|
echo "Copying configuration..."
|
|
cp "config.json.example" "$BUILD_DIR/etc/featherddns/config.json"
|
|
chmod 644 "$BUILD_DIR/etc/featherddns/config.json"
|
|
fi
|
|
|
|
# Copy systemd service if exists
|
|
if [ -f "featherddns.service" ]; then
|
|
echo "Copying systemd service..."
|
|
cp "featherddns.service" "$BUILD_DIR/lib/systemd/system/"
|
|
chmod 644 "$BUILD_DIR/lib/systemd/system/featherddns.service"
|
|
fi
|
|
|
|
# Create control file
|
|
cat > "$BUILD_DIR/DEBIAN/control" <<EOF
|
|
Package: ${PACKAGE_NAME}
|
|
Version: ${VERSION}
|
|
Section: net
|
|
Priority: optional
|
|
Architecture: ${ARCH}
|
|
Maintainer: ${MAINTAINER}
|
|
Depends: libc6
|
|
Homepage: ${HOMEPAGE}
|
|
Description: FeatherDDNS - Lightweight Dynamic DNS Server
|
|
A lightweight dynamic DNS server for updating DNS records
|
|
via HTTP API requests.
|
|
EOF
|
|
|
|
# Create conffiles if config exists
|
|
if [ -f "$BUILD_DIR/etc/featherddns/config.json" ]; then
|
|
cat > "$BUILD_DIR/DEBIAN/conffiles" <<EOF
|
|
/etc/featherddns/config.json
|
|
EOF
|
|
chmod 644 "$BUILD_DIR/DEBIAN/conffiles"
|
|
fi
|
|
|
|
# Create postinst script
|
|
cat > "$BUILD_DIR/DEBIAN/postinst" <<'EOF'
|
|
#!/bin/bash
|
|
set -e
|
|
|
|
case "$1" in
|
|
configure)
|
|
# Create featherddns user if it doesn't exist
|
|
if ! getent passwd featherddns > /dev/null; then
|
|
useradd --system --home-dir /var/lib/featherddns --shell /bin/false featherddns
|
|
fi
|
|
|
|
# Create directories
|
|
mkdir -p /var/lib/featherddns
|
|
mkdir -p /var/log/featherddns
|
|
chown featherddns:featherddns /var/lib/featherddns
|
|
chown featherddns:featherddns /var/log/featherddns
|
|
|
|
# Reload systemd
|
|
if [ -d /run/systemd/system ]; then
|
|
systemctl daemon-reload >/dev/null || true
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
exit 0
|
|
EOF
|
|
chmod 755 "$BUILD_DIR/DEBIAN/postinst"
|
|
|
|
# Create prerm script
|
|
cat > "$BUILD_DIR/DEBIAN/prerm" <<'EOF'
|
|
#!/bin/bash
|
|
set -e
|
|
|
|
case "$1" in
|
|
remove|upgrade)
|
|
if [ -d /run/systemd/system ]; then
|
|
systemctl stop featherddns.service >/dev/null 2>&1 || true
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
exit 0
|
|
EOF
|
|
chmod 755 "$BUILD_DIR/DEBIAN/prerm"
|
|
|
|
# Create postrm script
|
|
cat > "$BUILD_DIR/DEBIAN/postrm" <<'EOF'
|
|
#!/bin/bash
|
|
set -e
|
|
|
|
case "$1" in
|
|
remove)
|
|
if [ -d /run/systemd/system ]; then
|
|
systemctl daemon-reload >/dev/null || true
|
|
fi
|
|
;;
|
|
purge)
|
|
rm -rf /etc/featherddns
|
|
rm -rf /var/lib/featherddns
|
|
rm -rf /var/log/featherddns
|
|
if [ -d /run/systemd/system ]; then
|
|
systemctl daemon-reload >/dev/null || true
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
exit 0
|
|
EOF
|
|
chmod 755 "$BUILD_DIR/DEBIAN/postrm"
|
|
|
|
# Build the package
|
|
echo "Building package..."
|
|
dpkg-deb --build --root-owner-group "$BUILD_DIR"
|
|
|
|
# Move to dist directory
|
|
mkdir -p dist
|
|
mv "${BUILD_DIR}.deb" "dist/"
|
|
|
|
echo "Package built: dist/${PACKAGE_NAME}_${VERSION}_${ARCH}.deb"
|
|
|
|
# Run lintian check
|
|
if command -v lintian > /dev/null 2>&1; then
|
|
echo "Running lintian check..."
|
|
lintian "dist/${PACKAGE_NAME}_${VERSION}_${ARCH}.deb" || true
|
|
fi
|
|
|
|
echo "Done!"
|