]> git.proxmox.com Git - mirror_frr.git/blobdiff - tools/build-debian-package.sh
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tools / build-debian-package.sh
index 73231f0aecf8d00e9d4222057560ce695aa51f86..d614ba01d9271750bdf1325b323101afefe18f5e 100755 (executable)
@@ -1,40 +1,76 @@
 #!/bin/sh
+# SPDX-License-Identifier: NONE
 #
 # Written by Daniil Baturin, 2018
+# Rewritten by Ondřej Surý, 2020
 # This file is public domain
+set -e
 
-git diff-index --quiet HEAD || echo "Warning: git working directory is not clean!"
+cd "$(dirname "$0")/.."
 
-# Set the defaults
-if [ "$EXTRA_VERSION" = "" ]; then
-    EXTRA_VERSION="-MyDebPkgVersion"
-fi
+#
+# Checking requirements
+#
 
-if [ "$WANT_SNMP" = "" ]; then
-    WANT_SNMP=0
+if [ "$(id -u)" = 0 ]; then
+       echo "Running as root - installing dependencies"
+       apt-get install fakeroot debhelper devscripts git-buildpackage lsb-release
+       mk-build-deps --install debian/control
+       exit 0
 fi
 
-if [ "$WANT_CUMULUS_MODE" = "" ]; then
-    WANT_CUMULUS_MODE=0
-fi
+git diff-index --quiet HEAD || echo "Warning: git working directory is not clean!"
+
+############################
+# Build the Debian package #
+############################
+
+#
+# Now we will construct an "upstream" version out of:
+# 1. version in AC_INIT
+# 2. the unix time from the last commit (HEAD)
+#    (alternatively %Y%m%d%H%M%S could be used here)
+# 4. Debian version (always -1)
+#
+
+UPSTREAM_VERSION=$(sed -ne 's/AC_INIT(\[frr\],\s\[\([^]]*\)\],.*/\1/p' configure.ac | sed -e 's/-\(\(dev\|alpha\|beta\)\d*\)/~\1/')
+LAST_TIMESTAMP=$(git log --format=format:%ad --date=format:%s -1 "HEAD")
+DEBIAN_VERSION="$UPSTREAM_VERSION-$LAST_TIMESTAMP-1"
+DEBIAN_BRANCH=$(git rev-parse --abbrev-ref HEAD)
 
-echo "Preparing the build"
-./bootstrap.sh
-./configure --with-pkg-extra-version=$EXTRA_VERSION
-make dist
+#
+# We add a Debian changelog entry, and use artifical "since commit"
+# so there's not a whole git history in the debian/changelog.
+#
+# The --snapshot option appends ~1.<shorthash> to the debian version, so for the
+# release build, this needs to be replaces with --release
+#
 
-echo "Preparing Debian source package"
-mv debianpkg debian
-make -f debian/rules backports
+echo "Adding new snapshot debian/changelog entry for $DEBIAN_VERSION..."
 
-echo "Unpacking the source to frrpkg/"
-mkdir frrpkg
-cd frrpkg
-tar xf ../frr_*.orig.tar.gz
-cd frr*
-. /etc/os-release
-tar xf ../../frr_*${ID}${VERSION_ID}*.debian.tar.xz
+gbp dch \
+    --debian-branch="$DEBIAN_BRANCH" \
+    --new-version="$DEBIAN_VERSION" \
+    --dch-opt="--force-bad-version" \
+    --since="HEAD~" \
+    --snapshot \
+    --commit \
+    --git-author
+
+echo "Building package..."
+
+#
+# git-buildpackage will use $BUILDER command to just build new binary package
+#
 
-echo "Building the Debian package"
-debuild --no-lintian --set-envvar=WANT_SNMP=$WANT_SNMP --set-envvar=WANT_CUMULUS_MODE=$WANT_CUMULUS_MODE -b -uc -us
+BUILDER="dpkg-buildpackage -uc -us --build=binary --no-check-builddeps --no-pre-clean -sa"
+UPSTREAM_COMPRESSION=xz
 
+gbp buildpackage \
+    --git-export-dir="$WORKDIR" \
+    --git-builder="$BUILDER" \
+    --git-debian-branch="$DEBIAN_BRANCH" \
+    --git-force-create \
+    --git-compression=$UPSTREAM_COMPRESSION \
+    --git-no-pristine-tar \
+    --git-ignore-new