modified version of jenkins debian glue (https://github.com/mika/jenkins-debian-glue) for devuan
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
6.4 KiB

#!/bin/sh
set -x
set -u
if [ -r /etc/jenkins/debian_glue ] ; then
. /etc/jenkins/debian_glue
fi
if [ -z "${JOB_NAME:-}" ] ; then
echo "No JOB_NAME defined, please run it in jenkins." >&2
exit 1
fi
if [ -z "${architecture:-}" ] ; then
echo "No architecture defined, please run it with matrix configuration using architecture." >&2
exit 1
fi
# make sure we don't leave files for next run
bailout() {
if [ -n "${sources:-}" ]; then
echo "*** Removing sources file. ***"
rm -f "${sources}/"*
fi
[ -n "${1:-}" ] && EXIT="${1}" || EXIT=0
[ -n "${2:-}" ] && echo "$2" >&2
exit $EXIT
}
trap bailout 1 2 3 3 6 9 14 15
PACKAGE=${JOB_NAME%-binaries*}
BINARY_PACKAGE=${PACKAGE%-test*}
if [ -z "${PACKAGE:-}" ] ; then
echo "Error: could not identify Debian package name based on job name ${JOB_NAME:-}." >&2
bailout 1
fi
# remove results from previous (possibly failed) runs
cd "${WORKSPACE}"
rm -f *.deb *.changes *.dsc *.tar.gz
echo "===== Building binary package $BINARY_PACKAGE ====="
if [ -n "${1:-}" ] ; then
REPOS="$1"
echo "*** Using supplied repository name $REPOS ***"
else
REPOS="${JOB_NAME%-binaries*}"
if [ -z "${distribution:-}" ]; then
echo "*** No repository supplied, using repository name $REPOS ***"
else
REPOS="${REPOS}-${distribution}"
echo "*** No repository supplied but distribution has been set, using repository name $REPOS ***"
fi
fi
if [ -n "${sources:-}" ]; then
sourcefile=$(echo "${sources}/"*.dsc)
if [ "$sourcefile" = 'sources/*.dsc' ] ; then
echo "Error: no sourcefile (*.dsc) found. Exiting." >&2
bailout 1
fi
case "$sourcefile" in
*\ *) echo "Error: Found multiple source files (*.dsc)." >&2
bailout 1
;;
esac
p="$(basename $sourcefile .dsc)"
newest_version="${p#*_}"
else
sources="unset"
echo "*** Identifying newest package version ***"
newest_version="0"
for file in "${HUDSON_HOME}/userContent/${PACKAGE}-source/"*.dsc ; do
p="$(basename $file .dsc)"
if [ "$p" = '*' ] ; then
echo "No source package found (forgot to deploy via source job?)" >&2
bailout 1
fi
cur_version="${p#*_}"
if dpkg --compare-versions "${cur_version}" gt "${newest_version}" ; then
newest_version="${cur_version}"
else
base_version="${cur_version}"
fi
done
echo "*** Found package version $newest_version ***"
sourcefile="${HUDSON_HOME}/userContent/${PACKAGE}-source/${BINARY_PACKAGE}"_*"${newest_version}".dsc
fi
echo "*** Using $sourcefile (version: ${newest_version}) [sources: $sources]"
if [ -z "${distribution:-}" ]; then
echo "*** No distribution set, not setting base.cow for cowbuilder. ***"
cwb=''
else
echo "*** Using cowbuilder base for distribution ${distribution} ***"
cwb="-${distribution}"
fi
echo "*** cowbuilder build phase for arch $architecture ***"
mkdir -p "$WORKSPACE"/binaries/
case "$architecture" in
# -B -> binary-only build, limited to architecture dependent packages
i386)
linux32 sudo cowbuilder --buildresult "$WORKSPACE"/binaries/ \
--build $sourcefile \
--basepath /var/cache/pbuilder/base${cwb}32.cow --debbuildopts -B
[ $? -eq 0 ] || bailout 1 "Failed to build with cowbuilder."
;;
# -b -> binary-only build, no source files are to be built and/or distributed
amd64|all)
sudo cowbuilder --buildresult "$WORKSPACE"/binaries/ \
--build $sourcefile \
--basepath /var/cache/pbuilder/base${cwb}.cow --debbuildopts -b
[ $? -eq 0 ] || bailout 1 "Failed to build with cowbuilder."
;;
*)
echo "Unsupported architecture: $architecture" >&2
bailout 1
;;
esac
reprepro_wrapper() {
echo "*** Removing previous versions from repository ***"
for p in $(dcmd "${WORKSPACE}/binaries/"*"${newest_version}_${architecture}.changes") ; do
file="$(basename $p)"
binpackage="${file%%_*}"
binary_list="${binary_list:-} ${binpackage}"
# note: "removesrc" would remove foreign arch files (of different builds)
case "$file" in
*_all.deb)
echo "*** Architecture all package found, removing from all architectures. ***"
sudo reprepro -v -b /srv/repository --waitforlock 1000 remove "${REPOS}" "${binpackage}"
;;
*)
sudo reprepro -v -b /srv/repository --waitforlock 1000 --architecture \
"$architecture" remove "${REPOS}" "${binpackage}" || true
sudo reprepro -v -b /srv/repository --waitforlock 1000 --architecture \
all remove "${REPOS}" "${binpackage}" || true
;;
esac
done
for p in $(sudo reprepro -v -b /srv/repository --waitforlock 1000 listmatched $PACKAGE '*' | awk '{print $2}' | sort -u); do
echo "$binary_list" | grep -q "$p" || missing_packages="${missing_packages:-} $p"
done
if echo "${missing_packages:-}" | grep -q '[a-z0-9]' ; then
echo "*** Binary package(s) found, missing in build version: ${missing_packages:-} ***"
for p in $missing_packages ; do
echo "Removing $p from $REPOS to avoid out-of-date data ***"
sudo reprepro -v -b /srv/repository --waitforlock 1000 remove "${REPOS}" "${p}"
done
fi
archall=false
case $architecture in
all) archall=true
architecture='*' # support as file expansion in reprepro cmdline
;;
esac
echo "*** Including binary packages in repository $REPOS ***"
sudo reprepro -v -b /srv/repository --waitforlock 1000 --ignore=wrongdistribution \
include "${REPOS}" "${WORKSPACE}/binaries/"*"${newest_version}"_${architecture}.changes
[ $? -eq 0 ] || bailout 1 "Failed to include binary package in $REPOS repository."
# include the source package only in *one* architecture, being amd64
echo "*** Including source package in repository $REPOS ***"
if [ "$architecture" = "amd64" ] || $archall ; then
RC=0
if ! sudo reprepro -v -b /srv/repository --waitforlock 1000 --ignore=wrongdistribution \
includedsc "${REPOS}" ${sourcefile} ; then
RC=1
# iff section/priority is empty then reprepro will complain
# about "No section and no priority for" and error out in the
# cmdline above, therefore we retry with -S and -P being set
sudo reprepro -v -S unstable -P extra -b /srv/repository --waitforlock 1000 \
--ignore=wrongdistribution \
includedsc "${REPOS}" ${sourcefile}
RC=$?
fi
[ $RC -eq 0 ] || bailout 1 "Failed to include source package in $REPOS repository."
fi
}
if [ "${REMOTE_REPOS:-}" = "true" ] ; then
echo "REMOTE_REPOS is set, ignoring request to generate local repository."
else
reprepro_wrapper
fi
echo "*** Moving binaries files to workspace. ***"
mv "${WORKSPACE}/binaries/"* "${WORKSPACE}/"
bailout 0