From ab8421b2f26d186998c733a9666272ba0fc74c51 Mon Sep 17 00:00:00 2001 From: Daniel Pavel Date: Sun, 7 Jul 2013 22:07:31 +0200 Subject: [PATCH] simplified (again) the deb build script This time also check for consistency of .orig archives. --- packaging/build_deb.sh | 95 ++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 41 deletions(-) diff --git a/packaging/build_deb.sh b/packaging/build_deb.sh index 06804ac2..1b102318 100755 --- a/packaging/build_deb.sh +++ b/packaging/build_deb.sh @@ -3,12 +3,20 @@ set -e if test "$DEBSIGN_KEYID"; then + # only build a source package, and sign it + DPKG_BUILPACKAGE_OPTS="-sa -S -k$DEBSIGN_KEYID" + BUILDER_ROLE='Uploaders' test "$DEBEMAIL" test "$DEBFULLNAME" + DEBCHANGE_OPTIONS="$@" else + # build an unsigned binary package + DPKG_BUILPACKAGE_OPTS="-b -us -uc" + BUILDER_ROLE='Changed-By' export DEBFULLNAME="$(/usr/bin/getent passwd "$USER" | \ /usr/bin/cut --delimiter=: --fields=5 | /usr/bin/cut --delimiter=, --fields=1)" export DEBEMAIL="${EMAIL:-$USER@$(/bin/hostname --long)}" + DEBCHANGE_OPTIONS="--fromdirname" fi export DEBMAIL="$DEBEMAIL" @@ -18,53 +26,71 @@ DISTRIBUTION=${DISTRIBUTION:-UNRELEASED} cd "$(dirname "$0")/.." DEBIAN_FILES="$PWD/packaging/debian" DEBIAN_FILES_VENDOR="$PWD/packaging/$DEBCHANGE_VENDOR" -DIST_TARGET="$PWD/dist/$DEBCHANGE_VENDOR" +DIST_DIR="$PWD/dist" # -# build a python sdist package, then unpack and create .orig and source dir +# Build a python sdist package, then unpack and create .orig and source dir. # -VERSION="$(python2.7 setup.py --version)" -FULLNAME="$(python2.7 setup.py --fullname)" +P_NAME="$(python2.7 setup.py --name)" +P_VERSION="$(python2.7 setup.py --version)" +SDIST_FILE="$DIST_DIR/$P_NAME-$P_VERSION.tar.gz" +ORIG_FILE="$DIST_DIR/${P_NAME}_${P_VERSION}.orig.tar.gz" -export TMPDIR="${TMPDIR:-/tmp}/debbuild-$FULLNAME-$USER" -BUILD_DIR="$TMPDIR/$DEBCHANGE_VENDOR-$DISTRIBUTION" -/bin/rm --force --recursive "$BUILD_DIR" -/bin/mkdir --parents --mode=0700 "$BUILD_DIR" -python2.7 setup.py sdist --dist-dir="$BUILD_DIR" --formats=gztar --quiet +BUILD_DIR="$DIST_DIR/$P_NAME-$P_VERSION" +if test -d "$BUILD_DIR"; then + echo "*** $BUILD_DIR already exists, is it a leftover from previous builds? Aborting." + exit 1 +fi -ORIG_FILE="$BUILD_DIR/solaar_$VERSION.orig.tar.gz" -/bin/mv "$BUILD_DIR/$FULLNAME.tar.gz" "$ORIG_FILE" -/bin/tar --extract --gunzip --file "$ORIG_FILE" --directory "$BUILD_DIR" +export TMPDIR="$(/bin/mktemp --directory --tmpdir debbuild-$P_NAME-$P_VERSION-$USER-XXXXXX)" -cd "$BUILD_DIR/$FULLNAME" -unset BUILD_DIR VERSION FULLNAME ORIG_FILE +python2.7 setup.py sdist --formats=gztar --quiet +/bin/tar --extract --gunzip --file "$SDIST_FILE" --directory "$DIST_DIR" +test -d "$BUILD_DIR" + +# If the orig file already exists for this version, check that no source +# changes occured. +if test -r "$ORIG_FILE"; then + ORIG_SOURCES="$TMPDIR/$P_NAME-$P_VERSION" + DIFF_OUTPUT="$TMPDIR/orig-diff-$P_VERSION" + /bin/tar --extract --gunzip --file "$ORIG_FILE" --directory "$TMPDIR" + /usr/bin/diff --recursive --minimal --unified \ + "$ORIG_SOURCES" "$BUILD_DIR" >"$DIFF_OUTPUT" || true + # either way, the sdist archive is no longer useful + /bin/rm --force "$SDIST_FILE" + if test -s "$DIFF_OUTPUT"; then + /bin/rm --force --recursive "$BUILD_DIR" + echo '*** Current sbuild differs from existing .orig archive. Aborting.' + cat "$DIFF_OUTPUT" + exit 1 + fi + unset ORIG_SOURCES DIFF_OUTPUT +else + /bin/mv "$SDIST_FILE" "$ORIG_FILE" +fi + +unset P_NAME P_VERSION SDIST_FILE ORIG_FILE # # preparing to build the package # +cd "$BUILD_DIR" + /bin/cp --archive --target-directory=. "$DEBIAN_FILES" -if test "$DEBSIGN_KEYID"; then - BUILDER_MAIL="$(echo "$DEBEMAIL" | /bin/sed --expression='s/+[a-z]*@/@/')" - MAINT_MAIL="$(/bin/grep '^Maintainer: ' debian/control | /usr/bin/cut --delimiter=' ' --fields=2)" - echo "maintainer $MAINT_MAIL, builder $BUILDER_MAIL" - # test "$MAINT_MAIL" = "$BUILDER_MAIL" && - # /bin/sed --in-place --expression="s/^Maintainer: .*$/Maintainer: $DEBFULLNAME <$DEBEMAIL>/" debian/control -else - /bin/sed --in-place --file=- debian/control <<-CONTROL - /^Maintainer:/ a\ - Changed-By: $DEBFULLNAME <$DEBEMAIL> - CONTROL -fi +/bin/sed --in-place --file=- debian/control <<-CONTROL + /^Maintainer:/ a\ + $BUILDER_ROLE: $DEBFULLNAME <$DEBEMAIL> + CONTROL /usr/bin/debchange \ --vendor "$DEBCHANGE_VENDOR" \ --distribution "$DISTRIBUTION" \ --force-save-on-release \ --auto-nmu \ - $@ + $DEBCHANGE_OPTIONS if test "$DEBCHANGE_VENDOR" = debian; then # if this is the main (Debian) build, update the source changelog @@ -74,23 +100,10 @@ else /bin/cp --archive --target-directory=debian/ "$DEBIAN_FILES_VENDOR"/* || true fi -if test "$DEBSIGN_KEYID"; then - # only build a source package, and sign it - DPKG_BUILPACKAGE_OPTS="-sa -S -k$DEBSIGN_KEYID" -else - # build an unsigned binary package - DPKG_BUILPACKAGE_OPTS="-b -us -uc" -fi /usr/bin/debuild \ --lintian --tgz-check \ --preserve-envvar=DISPLAY \ $DPKG_BUILPACKAGE_OPTS \ --lintian-opts --profile "$DEBCHANGE_VENDOR" -# -# place the resulting files in $DIST_TARGET -# - -/bin/mkdir --parents "$DIST_TARGET" -/bin/cp --archive --backup=numbered --target-directory="$DIST_TARGET" ../solaar_$VERSION* -/bin/cp --archive --backup=numbered --target-directory="$DIST_TARGET" ../solaar-*_$VERSION* || true +/bin/rm --force --recursive "$BUILD_DIR"