2018-10-01 20:38:44 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Written by Daniil Baturin, 2018
|
2020-09-27 12:18:21 +02:00
|
|
|
# Rewritten by Ondřej Surý, 2020
|
2018-10-01 20:38:44 +02:00
|
|
|
# This file is public domain
|
2018-12-14 22:51:37 +01:00
|
|
|
set -e
|
2018-10-01 20:38:44 +02:00
|
|
|
|
2020-09-27 13:17:57 +02:00
|
|
|
BASEDIR="$(realpath -e "$(dirname "$(dirname "$0")")")"
|
|
|
|
cd "$BASEDIR"
|
|
|
|
|
|
|
|
#
|
|
|
|
# Directory where the git-buildpackage does the work
|
|
|
|
#
|
|
|
|
WORKDIR=$(mktemp -d /tmp/debwork-XXXXXXXX) || exit 1
|
|
|
|
trap '( rm -rf "$WORKDIR" )' EXIT
|
|
|
|
|
|
|
|
#
|
|
|
|
# Checking requirements
|
|
|
|
#
|
2018-10-01 20:38:44 +02:00
|
|
|
|
2020-09-27 11:08:13 +02:00
|
|
|
if [ "$(id -u)" = 0 ]; then
|
2018-12-14 22:51:37 +01:00
|
|
|
echo "Running as root - installing dependencies"
|
2020-09-27 13:17:57 +02:00
|
|
|
apt-get install fakeroot debhelper devscripts git-buildpackage lsb-release
|
2018-12-14 22:51:37 +01:00
|
|
|
mk-build-deps --install debian/control
|
|
|
|
exit 0
|
2018-10-01 20:38:44 +02:00
|
|
|
fi
|
|
|
|
|
2020-09-27 11:08:13 +02:00
|
|
|
git diff-index --quiet HEAD || { echo "ERROR: git working directory is not clean!" ; exit 1; }
|
2018-10-01 20:38:44 +02:00
|
|
|
|
2020-09-27 13:17:57 +02:00
|
|
|
#
|
|
|
|
# We switch to a separate branch to not mangle the actual branch, this is
|
|
|
|
# not needed in the CI
|
|
|
|
#
|
|
|
|
|
|
|
|
CLONEDIR="$WORKDIR/$(basename "$BASEDIR")"
|
|
|
|
|
|
|
|
echo "Creating shallow clone from $BASEDIR to $CLONEDIR..."
|
2018-10-01 20:38:44 +02:00
|
|
|
|
2020-09-27 13:17:57 +02:00
|
|
|
git clone --depth=2 "file://$BASEDIR" "$CLONEDIR"
|
|
|
|
cd "$CLONEDIR"
|
2020-09-27 11:08:13 +02:00
|
|
|
|
2020-09-27 13:17:57 +02:00
|
|
|
####################################
|
|
|
|
# Build the Debian package sources #
|
|
|
|
####################################
|
|
|
|
|
|
|
|
#
|
|
|
|
# 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)
|
|
|
|
#
|
2020-09-27 11:08:13 +02:00
|
|
|
|
|
|
|
UPSTREAM_VERSION=$(sed -ne 's/AC_INIT(\[frr\],\s\[\([^]]*\)\],.*/\1/p' configure.ac | sed -e 's/-\(\(dev\|alpha\|beta\)\d*\)/~\1/')
|
2020-09-27 13:17:57 +02:00
|
|
|
LAST_TIMESTAMP=$(git log --format=format:%ad --date=format:%s -1 "HEAD")
|
|
|
|
DEBIAN_VERSION="$UPSTREAM_VERSION-$LAST_TIMESTAMP-1"
|
2021-02-11 20:44:09 +01:00
|
|
|
DEBIAN_BRANCH=$(git branch --show-current)
|
2020-09-27 11:08:13 +02:00
|
|
|
|
2020-09-27 13:17:57 +02:00
|
|
|
#
|
|
|
|
# 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 "Adding new snapshot debian/changelog entry for $DEBIAN_VERSION..."
|
2020-09-27 11:08:13 +02:00
|
|
|
|
|
|
|
gbp dch \
|
2021-02-11 20:44:09 +01:00
|
|
|
--debian-branch="$DEBIAN_BRANCH" \
|
|
|
|
--new-version="$DEBIAN_VERSION" \
|
2020-09-27 13:17:57 +02:00
|
|
|
--dch-opt="--force-bad-version" \
|
|
|
|
--since="HEAD~" \
|
2020-09-27 11:08:13 +02:00
|
|
|
--snapshot \
|
|
|
|
--commit
|
|
|
|
|
2020-09-27 13:17:57 +02:00
|
|
|
echo "Building package..."
|
|
|
|
|
|
|
|
#
|
|
|
|
# git-buildpackage will use $BUILDER command to just build new source package
|
|
|
|
#
|
|
|
|
|
|
|
|
BUILDER="dpkg-buildpackage -uc -us --build=source --no-check-builddeps --no-pre-clean -sa"
|
|
|
|
UPSTREAM_COMPRESSION=xz
|
2020-09-27 11:08:13 +02:00
|
|
|
|
|
|
|
gbp buildpackage \
|
2020-09-27 13:17:57 +02:00
|
|
|
--git-export-dir="$WORKDIR" \
|
|
|
|
--git-builder="$BUILDER" \
|
2021-02-11 20:44:09 +01:00
|
|
|
--git-debian-branch="$DEBIAN_BRANCH" \
|
2020-09-27 11:08:13 +02:00
|
|
|
--git-force-create \
|
2020-09-27 13:17:57 +02:00
|
|
|
--git-compression=$UPSTREAM_COMPRESSION \
|
2020-09-27 11:08:13 +02:00
|
|
|
--git-no-pristine-tar
|
|
|
|
|
2020-09-27 13:17:57 +02:00
|
|
|
DEB_SOURCE="$(dpkg-parsechangelog -SSource)"
|
|
|
|
DEB_VERSION="$(dpkg-parsechangelog -SVersion)"
|
|
|
|
DEB_VERSION_UPSTREAM_REVISION="$(echo "${DEB_VERSION}" | sed -e 's/^[0-9]*://')"
|
|
|
|
DEB_VERSION_UPSTREAM="$(echo "${DEB_VERSION_UPSTREAM_REVISION}" | sed -e 's/-[^-]*$//')"
|
|
|
|
|
|
|
|
#
|
|
|
|
# Now the source package has been built and it is stored in following files:
|
|
|
|
#
|
|
|
|
|
|
|
|
echo "Running lintian on the source package"
|
|
|
|
|
|
|
|
lintian "${WORKDIR}/${DEB_SOURCE}_${DEB_VERSION_UPSTREAM_REVISION}_source.changes"
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Backporting part #
|
|
|
|
####################
|
2020-09-27 11:08:13 +02:00
|
|
|
|
2020-09-27 13:17:57 +02:00
|
|
|
#
|
|
|
|
# Now we determine what should be the suffix for the system we are backporting
|
|
|
|
# for.
|
|
|
|
#
|
2020-09-27 11:08:13 +02:00
|
|
|
|
2020-09-27 13:17:57 +02:00
|
|
|
DIST=$(lsb_release --codename --short)
|
|
|
|
PATCH=${PATCH:-1}
|
|
|
|
|
|
|
|
case "$DIST" in
|
2021-02-11 20:53:43 +01:00
|
|
|
jessie) EXTRA_VERSION="deb8u${PATCH}" ;;
|
|
|
|
stretch) EXTRA_VERSION="deb9u${PATCH}" ;;
|
|
|
|
buster) EXTRA_VERSION="deb10u${PATCH}" ;;
|
|
|
|
bullseye) EXTRA_VERSION="deb11u${PATCH}" ;;
|
|
|
|
sid) EXTRA_VERSION="sid+${PATCH}" ;;
|
|
|
|
xenial) EXTRA_VERSION="ubuntu16.04+${PATCH}" ;;
|
|
|
|
bionic) EXTRA_VERSION="ubuntu16.04+${PATCH}" ;;
|
|
|
|
focal) EXTRA_VERSION="ubuntu20.04+${PATCH}" ;;
|
|
|
|
groovy) EXTRA_VERSION="ubuntu20.10+${PATCH}" ;;
|
2020-09-27 13:17:57 +02:00
|
|
|
*) echo "Unknown distribution '$DIST'" ; exit 1 ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
#
|
|
|
|
# Now the actual backport, we:
|
|
|
|
#
|
|
|
|
# 1. Unpack the sources
|
|
|
|
# 2. Append the EXTRA_VERSION
|
|
|
|
# 3. Use debuild to build the package (don't sign
|
|
|
|
#
|
|
|
|
|
|
|
|
(cd "$WORKDIR" && dpkg-source -x "${DEB_SOURCE}_${DEB_VERSION_UPSTREAM_REVISION}.dsc")
|
|
|
|
(cd "$WORKDIR/${DEB_SOURCE}-${DEB_VERSION_UPSTREAM}/" && dch -b -m -t -l "~$EXTRA_VERSION" "No change backport build for $DIST")
|
|
|
|
(cd "$WORKDIR/${DEB_SOURCE}-${DEB_VERSION_UPSTREAM}/" && debuild -uc -us)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Copy back the result
|
|
|
|
#
|
2020-09-27 11:08:13 +02:00
|
|
|
|
2020-09-27 13:17:57 +02:00
|
|
|
cp -a "$WORKDIR"/*.build "$WORKDIR"/*.buildinfo "$WORKDIR"/*.changes "$WORKDIR"/*.dsc "$WORKDIR"/*.deb "$WORKDIR"/*.debian.* "$WORKDIR"/*.orig.tar.* "${BASEDIR}/"
|