Files
EasyDNS-Web/scripts/build-deb.sh
T
Mateusz Gruszczyński de13d851a8
Go quality gates / test (push) Waiting to run
v0.1.1
2026-11-30 14:44:28 +01:00

51 lines
2.2 KiB
Bash
Executable File

#!/bin/sh
# Build a standalone EasyDNS UI Debian package; never packages the DNS server.
set -eu
ROOT=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd)
ARCH=${GOARCH:-amd64}
VERSION=${VERSION:-0.1.1}
case "$ARCH" in
amd64|arm64) ;;
*) echo "Unsupported architecture: $ARCH (use amd64 or arm64)" >&2; exit 1 ;;
esac
case "$VERSION" in
*[!a-zA-Z0-9.+~:-]*|'') echo 'Invalid version' >&2; exit 1 ;;
esac
STAGING=$(mktemp -d)
trap 'rm -rf "$STAGING"' EXIT HUP INT TERM
chmod 0755 "$STAGING"
mkdir -p "$STAGING/DEBIAN" "$STAGING/usr/bin" "$STAGING/lib/systemd/system" "$STAGING/etc/easydns-ui" "$ROOT/dist"
cd "$ROOT"
# Each build embeds its own fingerprint into the static asset filenames.
# The package release remains 0.1.1 unless the operator explicitly changes it.
BUILD_ID=${BUILD_ID:-$(date -u +%Y%m%dT%H%M%S)-$(od -An -N8 -tx1 /dev/urandom | tr -d ' \n')}
case "$BUILD_ID" in
''|*[!A-Za-z0-9._-]*) echo 'Invalid BUILD_ID' >&2; exit 1 ;;
esac
GOOS=linux GOARCH="$ARCH" CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X main.version=$VERSION -X git.linuxiarz.pl/gru/EasyDNS-Web/internal/server.BuildID=$BUILD_ID" -o "$STAGING/usr/bin/easydns-ui" ./cmd/easydns-ui
chmod 0755 "$STAGING/usr/bin/easydns-ui"
cp packaging/easydns-ui.service "$STAGING/lib/systemd/system/easydns-ui.service"
cp packaging/easydns-ui.toml "$STAGING/etc/easydns-ui/config.toml"
chmod 0640 "$STAGING/etc/easydns-ui/config.toml"
cp packaging/debian/postinst packaging/debian/prerm packaging/debian/postrm "$STAGING/DEBIAN/"
cat > "$STAGING/DEBIAN/control" <<CONTROL
Package: easydns-ui
Version: $VERSION
Section: admin
Priority: optional
Architecture: $ARCH
Depends: adduser, coreutils, passwd
Maintainer: EasyDNS UI maintainers
Description: EasyDNS standalone OLED administration panel
A Go web UI for an existing EasyDNS server. Uses the server's
generated control.token, a protected TOML token, or Unix socket.
It does not install or replace the Rust DNS service.
CONTROL
cat > "$STAGING/DEBIAN/conffiles" <<CONF
/etc/easydns-ui/config.toml
CONF
# The parent may be non-root while dpkg-deb is available.
OUT="$ROOT/dist/easydns-ui_${VERSION}_${ARCH}.deb"
dpkg-deb --build --root-owner-group "$STAGING" "$OUT" >/dev/null
printf '%s\n' "$OUT"