| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
set -e |
| 4 |
set -x |
| 5 |
|
| 6 |
detect_distro () { |
| 7 |
DISTRO_VENDOR=$(lsb_release --id -s | awk '{print tolower($0)}') |
| 8 |
DISTRO_NAME=$(lsb_release -c -s) |
| 9 |
} |
| 10 |
|
| 11 |
|
| 12 |
# Get some version information out of the debian/changelog last entry |
| 13 |
get_deb_version() { |
| 14 |
PKG_NAME=$(dpkg-parsechangelog -SSource) |
| 15 |
DEB_VERS=$(dpkg-parsechangelog -SVersion) |
| 16 |
NO_EPOC=$(echo ${DEB_VERS} | cut -d":" -f2) |
| 17 |
if echo ${DEB_VERS} | grep -q ':' ; then |
| 18 |
EPOC=$(echo ${DEB_VERS} | cut -d":" -f1) |
| 19 |
fi |
| 20 |
UPSTREAM_VERS=$(echo ${NO_EPOC} | cut -d"-" -f1) |
| 21 |
if [ "${DEB_VERS}" = "${UPSTREAM_VERS}" ] ; then IS_NATIVE="yes" ; else IS_NATIVE="no" ; fi |
| 22 |
ORIG=${PKG_NAME}_${UPSTREAM_VERS}.orig.tar.xz |
| 23 |
CHANGE=${PKG_NAME}_${NO_EPOC}_${ARCH}.changes |
| 24 |
PKG_NAME_FIRST_CHAR=$(echo ${PKG_NAME} | awk '{print substr($0,1,1)}') |
| 25 |
} |
| 26 |
|
| 27 |
calc_bpo_version () { |
| 28 |
case ${DISTRO_NAME} in |
| 29 |
jessie) |
| 30 |
BPO_DISTRO_NUM="~bpo8+1" |
| 31 |
;; |
| 32 |
stretch) |
| 33 |
BPO_DISTRO_NUM="~bpo9+1" |
| 34 |
;; |
| 35 |
buster) |
| 36 |
BPO_DISTRO_NUM="~bpo10+1" |
| 37 |
;; |
| 38 |
sid) |
| 39 |
BPO_DISTRO_NUM="" |
| 40 |
;; |
| 41 |
trusty) |
| 42 |
BPO_DISTRO_NUM="~bpo14.04+1" |
| 43 |
;; |
| 44 |
xenial) |
| 45 |
BPO_DISTRO_NUM="~bpo16.04+1" |
| 46 |
;; |
| 47 |
*) |
| 48 |
echo "Distribution not supported!" |
| 49 |
echo "Falling back to no changelog bpo version tag" |
| 50 |
BPO_DISTRO_NUM="" |
| 51 |
;; |
| 52 |
esac |
| 53 |
} |
| 54 |
|
| 55 |
create_orig_tarball () { |
| 56 |
if grep pristine-tar debian/gbp.conf | grep -q -i true ; then |
| 57 |
echo "Nothing special to do with Pristine tar: not generating orig file!" |
| 58 |
else |
| 59 |
if [ "${IS_NATIVE}" = "no" ] ; then |
| 60 |
GENORIG_DEBRULES_TARGET=gen-orig-xz |
| 61 |
if [ -r debian/gbp.conf ] ; then |
| 62 |
COMPRESSION_IN_FILE=$(cat debian/gbp.conf | grep compression | cut -d'=' -f2 | awk '{print $1}') |
| 63 |
if [ "${COMPRESSION_IN_FILE}" = "gz" ] ; then |
| 64 |
GENORIG_DEBRULES_TARGET=gen-orig-gz |
| 65 |
elif [ "${COMPRESSION_IN_FILE}" = "bzip2" ] ; then |
| 66 |
GENORIG_DEBRULES_TARGET=gen-orig-bz2 |
| 67 |
fi |
| 68 |
fi |
| 69 |
./debian/rules ${GENORIG_DEBRULES_TARGET} |
| 70 |
fi |
| 71 |
fi |
| 72 |
} |
| 73 |
|
| 74 |
detect_branch_name () { |
| 75 |
PACKAGING_BRANCH_NAME=$(grep debian-branch debian/gbp.conf | cut -d= -f2 | awk '{print $1}') |
| 76 |
} |
| 77 |
|
| 78 |
build_backport_package () { |
| 79 |
echo "===> Building using git-buildpackage" |
| 80 |
# Edit debian/changelog to show we're building a backport |
| 81 |
LAST_GIT_COMMIT=$(git log | head -n 1 | awk '{print $2}') |
| 82 |
NUM_COMMITS_FROM_LAST_TAG=$(git rev-list --no-merges $(git describe --no-abbrev --candidates=1)..HEAD | wc -l) |
| 83 |
DEBFULLNAME="Jenkins" [email protected] dch --newversion ${DEB_VERS}+${NUM_COMMITS_FROM_LAST_TAG}${BPO_DISTRO_NUM} -b --allow-lower-version -m "Backport rebuilt by Jenkins in OpenStack infra." |
| 84 |
git commit debian/changelog -m "Backport rebuilt by Jenkins in OpenStack infra." |
| 85 |
git checkout -B ${PACKAGING_BRANCH_NAME} |
| 86 |
|
| 87 |
# |
| 88 |
echo "Checking /etc/passwd and /etc/group just to please clarkb" |
| 89 |
cat /etc/group | grep sbuild |
| 90 |
cat /etc/passwd | grep sbuild |
| 91 |
echo "Now attempting to build with sbuild" |
| 92 |
|
| 93 |
# Create ssh key |
| 94 |
if ! [ -e ~/.ssh/id_rsa ] ; then |
| 95 |
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa |
| 96 |
fi |
| 97 |
# Copy it to authorized_keys |
| 98 |
cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys |
| 99 |
cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys2 |
| 100 |
|
| 101 |
# Build the package with gbp buildpackage |
| 102 |
echo "===> Building with gbp buildpackage from ${WORKSPACE}" |
| 103 |
if [ "${IS_NATIVE}" = "no" ] ; then |
| 104 |
SAFLAG=" --force-orig-source" |
| 105 |
else |
| 106 |
SAFLAG="" |
| 107 |
fi |
| 108 |
echo "===> Building with gbp buildpackage from ${WORKSPACE}" |
| 109 |
if ! ssh -o "StrictHostKeyChecking no" localhost "cd ${WORKSPACE} ; gbp buildpackage${SAFLAG}" ; then |
| 110 |
git reset --hard ${LAST_GIT_COMMIT} |
| 111 |
echo "Error building the package with gbp buildpackage: exiting." |
| 112 |
exit 1 |
| 113 |
else |
| 114 |
git reset --hard ${LAST_GIT_COMMIT} |
| 115 |
fi |
| 116 |
} |
| 117 |
|
| 118 |
lintian_test_the_package () { |
| 119 |
echo "===> Starting Lintian check" |
| 120 |
lintian -I -E --pedantic --suppress-tags bad-distribution-in-changes-file --suppress-tags privacy-breach-uses-embedded-file ../build-area/*.changes |
| 121 |
} |
| 122 |
|
| 123 |
prepare_for_upload () { |
| 124 |
# When we switch to zuul v3, we can use this: |
| 125 |
#UPDIR=../uploads |
| 126 |
# Until then, we must stay in the WORKSPACE |
| 127 |
UPDIR=uploads |
| 128 |
|
| 129 |
mkdir -p ${UPDIR}/${LAST_GIT_COMMIT} |
| 130 |
cp ../build-area/* ${UPDIR}/${LAST_GIT_COMMIT} |
| 131 |
rm ${UPDIR}/${LAST_GIT_COMMIT}/*.build |
| 132 |
cp -auxf ../build-area . |
| 133 |
|
| 134 |
lintian -I -E --pedantic --suppress-tags bad-distribution-in-changes-file ../build-area/*.changes |
| 135 |
} |
| 136 |
|
| 137 |
prepare_for_upload () { |
| 138 |
# When we switch to zuul v3, we can use this: |
| 139 |
#UPDIR=../uploads |
| 140 |
# Until then, we must stay in the WORKSPACE |
| 141 |
UPDIR=uploads |
| 142 |
|
| 143 |
mkdir -p ${UPDIR}/${LAST_GIT_COMMIT} |
| 144 |
cp ../build-area/* ${UPDIR}/${LAST_GIT_COMMIT} |
| 145 |
rm ${UPDIR}/${LAST_GIT_COMMIT}/*.build |
| 146 |
cp -auxf ../build-area . |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
# We need this because we don't re-login, and |
| 151 |
# sbuild has just been installed: |
| 152 |
newgrp - sbuild |
| 153 |
# Then we can start... |
| 154 |
detect_distro |
| 155 |
calc_bpo_version |
| 156 |
get_deb_version |
| 157 |
create_orig_tarball |
| 158 |
detect_branch_name |
| 159 |
build_backport_package |
| 160 |
lintian_test_the_package |
| 161 |
prepare_for_upload |