modules/pkgbuilder/files/puppetagain-build-deb
author Mihai Tabara <mtabara@mozilla.com>
Fri, 26 Aug 2016 20:06:23 +0300
changeset 4255 2d58c6ec75d0
parent 1427 1abfaf3010c6
permissions -rw-r--r--
Bug 1288434 - Add Ship-It credentials in BuildSlaves.py. r=rail

MozReview-Commit-ID: 5xsPoASZEri
#! /bin/sh

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

if [ "${#}" -ne 3 ] || [ ! -d "${3}" ]; then
    echo "USAGE: puppetagain-build-deb distribution arch /path/to/puppet/modules/packages/manifests/foo-debian"
    exit 1
fi

set -e

distribution="${1}"
arch="${2}"
debian_dir=$(readlink -f $3)
mozilla_dir=$(dirname ${debian_dir})
pkg=$(basename ${debian_dir} -debian)

# gather some data..
version=$(parsechangelog ${debian_dir}/changelog | sed -n '/^Version/{s/^[^:]*: //;p}')
# strip the dist version stuff
version=$(echo "${version}" | sed -e 's/-[^-]*$//')
for ext in 'tar.gz' 'tar.bz2'; do
    orig_tarball="${mozilla_dir}/${pkg}_${version}.orig.${ext}"
if [ -f "${orig_tarball}" ]; then
    break
fi
done
if [ ! -f $orig_tarball ]; then
    echo "Please download an orig tarball, e.g., "$(basename ${orig_tarball})" to ${orig_tarball} (extension may vary)"
    exit 1
fi

# check that the base cow exists
basepath="/var/cache/pbuilder/${distribution}-${arch}/"
if [ ! -d "${basepath}" ]; then
    echo "${basepath} does not exist"
    exit 1
fi

build_dir=$(mktemp -d)
trap "rm -rf ${build_dir}" EXIT
cd "${build_dir}"

# set up a source directory arranged the way debuild likes it:
# a tarball, the unpacked version of that tarball, and our debian
# directory inside that unpacked version.

cp "${orig_tarball}" .
tar -axf "${orig_tarball}"
root_name=$(tar -atf "${orig_tarball}" | sed -n 's!/.*$!!;p;q')
cd "${root_name}"
rm -rf debian
cp -r "${debian_dir}" debian

DEST="/tmp/${pkg}-${distribution}-${arch}"
rm -rf "${DEST}"
mkdir -p "${DEST}"

ARCHITECTURE=${arch} bash -x /usr/bin/pdebuild --pbuilder cowbuilder --buildresult ${DEST} --use-pdebuild-internal -- --basepath "${basepath}" --distribution "${distribution}" --architecture "${arch}" 
find "${DEST}"