Skip to content

Instantly share code, notes, and snippets.

@fpytloun
Last active October 19, 2017 11:14
Show Gist options
  • Save fpytloun/6b6133f3211afe8bb570fe11333dd56b to your computer and use it in GitHub Desktop.
Save fpytloun/6b6133f3211afe8bb570fe11333dd56b to your computer and use it in GitHub Desktop.
Cowbuilder/git-buildpackage wrapper
#!/bin/bash -e
#
# Put something like this into /etc/sudoers:
# Defaults env_reset,env_keep+="DEB* DIST ARCH ADT OS"
# Cmnd_Alias PBUILDER = /usr/sbin/pbuilder, /usr/bin/pdebuild, /usr/bin/debuild-pbuilder, /usr/sbin/cowbuilder, /usr/sbin/chroot, /usr/bin/git-buildpackage
# @adm ALL=(root) NOPASSWD: PBUILDER
#
[ -z "$DEBUG" ] || set -x
# Overridable parameters
export OS=${OS:-$(lsb_release -i|cut -d : -f 2|tr -d '\t'|tr '[:upper:]' '[:lower:]')}
export DIST=${DIST:-$(lsb_release -c|cut -d : -f 2|tr -d '\t'|tr '[:upper:]' '[:lower:]')}
export ARCH=${ARCH:-$(dpkg --print-architecture)}
RESULTS=${RESULTS:-"/var/cache/pbuilder/${OS}-${DIST}-${ARCH}/result"}
# Determine package informations
if [[ "$1" != "update" || "$1" != "create" ]]; then
SOURCE_NAME=$(grep -E '^Source:' debian/control|cut -d : -f 2|tr -d ' ')
VERSION=$(head -1 debian/changelog|grep -Eo '\(.*\)'|tr -d '('|tr -d ')'|cut -d ':' -f 2)
UPSTREAM_VERSION=$(echo ${VERSION}|cut -d '-' -f 1)
EXPORT_DIR=$(grep export-dir debian/gbp.conf 2>/dev/null|cut -d = -f 2|tr -d ' ')
EXPORT_DIR=${EXPORT_DIR:-".."}
fi
build_source_git() {
if [[ "x$(git ls-tree upstream/${UPSTREAM_VERSION} 2>/dev/null || git ls-tree ${UPSTREAM_VERSION} 2>/dev/null)" == "x" ]]; then
if [ -f debian/watch ]; then
echo "[WARN] Upstream branch not found, trying uscan" 1>&2
uscan --download-current-version
fi
fi
gbp buildpackage --git-ignore-new --git-notify=false --git-ignore-branch -S -uc -us
}
build_source_normal() {
if [ -f ../${SOURCE_NAME}_${UPSTREAM_VERSION}.orig.tar.gz ]; then
echo "[INFO] Source tarball exists in parrent directory, skipping uscan"
else
uscan --download-current-version
fi
dpkg-buildpackage -S -nc -uc -us
}
build_source() {
echo "== Building source package"
if [ -d .git ]; then
echo "== Git repository determined, using gbp"
build_source_git
else
build_source_normal
fi
if [ ! -f "${EXPORT_DIR}/${SOURCE_NAME}_${VERSION}.dsc" ]; then
echo "== Source build failed" 1>&2
exit 1
fi
}
build_binary() {
echo "== Building binary package for ${OS} ${DIST}"
sudo cowbuilder --build "${EXPORT_DIR}/${SOURCE_NAME}_${VERSION}.dsc"
if [ ! -f "${RESULTS}/${SOURCE_NAME}_${VERSION}_${ARCH}.changes" ]; then
echo "== Binary build failed" 1>&2
exit 1
fi
}
cowbuilder_update() {
echo "== Updating base for ${OS}-${DIST}-${ARCH}"
sudo cowbuilder --update
}
cowbuilder_create() {
echo "== Create base for ${OS}-${DIST}-${ARCH}"
sudo cowbuilder --create
}
build_sign() {
echo "== Signing changes"
debsign -e $DEBEMAIL "${RESULTS}/${SOURCE_NAME}_${VERSION}_${ARCH}.changes"
}
build_lintian() {
echo "== Running lintian"
lintian --no-tag-display-limit -Ii -E --pedantic --profile="${OS}" "${RESULTS}/${SOURCE_NAME}_${VERSION}_${ARCH}.changes"
}
case $1 in
source)
build_source
;;
binary)
build_binary
;;
sign)
build_sign
;;
lintian)
build_lintian
;;
update)
cowbuilder_update
;;
create)
cowbuilder_create
;;
all|"")
build_source
build_binary
build_sign
build_lintian
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment