| 1 |
#! /bin/bash |
| 2 |
# pbuilder -- personal Debian package builder |
| 3 |
# Copyright © 2001-2007 Junichi Uekawa <[email protected]> |
| 4 |
# 2015 Mattia Rizzolo <[email protected]> |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation; either version 2 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program; if not, write to the Free Software |
| 18 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 |
############################################################################### |
| 20 |
|
| 21 |
set -e |
| 22 |
|
| 23 |
export PBUILDER_OPERATION="pdebuild" |
| 24 |
export PBCURRENTCOMMANDLINEOPERATION="pdebuild" |
| 25 |
. /usr/lib/pbuilder/pdebuild-checkparams |
| 26 |
. /usr/lib/pbuilder/pbuilder-buildpackage-funcs |
| 27 |
|
| 28 |
while ! test -d ./debian -o "$(pwd)" = "/" ; do |
| 29 |
cd ..; |
| 30 |
done |
| 31 |
|
| 32 |
if test ! -d ./debian; then |
| 33 |
log.e "Cannot find ./debian dir" |
| 34 |
exit 1 |
| 35 |
fi; |
| 36 |
|
| 37 |
PKG_SOURCENAME=$(dpkg-parsechangelog -S Source) |
| 38 |
PKG_VERSION=$(dpkg-parsechangelog -S Version|sed 's/.*://') |
| 39 |
ARCHITECTURE="${ARCHITECTURE:-$(dpkg-architecture -qDEB_HOST_ARCH)}" |
| 40 |
CHANGES="${PKG_SOURCENAME}_${PKG_VERSION}_${ARCHITECTURE}.changes" |
| 41 |
SOURCE_CHANGES="${PKG_SOURCENAME}_${PKG_VERSION}_source.changes" |
| 42 |
DSC="${PKG_SOURCENAME}_${PKG_VERSION}.dsc" |
| 43 |
|
| 44 |
if [ -z "${PBUILDER_BUILD_LOGFILE}" ]; then |
| 45 |
PBUILDER_BUILD_LOGFILE="../${PKG_SOURCENAME}_${PKG_VERSION}_${ARCHITECTURE}.build" |
| 46 |
exec > >(tee "${PBUILDER_BUILD_LOGFILE}") 2>&1 |
| 47 |
fi |
| 48 |
|
| 49 |
|
| 50 |
BUILDRESULTUID=$(id -u) |
| 51 |
BUILDRESULTGID=$(id -g) |
| 52 |
export BUILDRESULTUID BUILDRESULTGID |
| 53 |
|
| 54 |
if [ "${USE_PDEBUILD_INTERNAL}" = 'yes' ]; then |
| 55 |
PBINTERNALOPTS=() |
| 56 |
if [ "${SOURCE_ONLY_CHANGES:-no}" = "yes" ]; then |
| 57 |
PBINTERNALOPTS+=(--source-only-changes) |
| 58 |
fi |
| 59 |
${PBUILDERROOTCMD} \ |
| 60 |
${PDEBUILD_PBUILDER} \ |
| 61 |
--execute \ |
| 62 |
${EXTRA_CONFIGFILE[@]/#/--configfile } \ |
| 63 |
--bindmounts "$(readlink -f ..)" \ |
| 64 |
"$@" \ |
| 65 |
-- \ |
| 66 |
/usr/lib/pbuilder/pdebuild-internal \ |
| 67 |
"${PWD}" \ |
| 68 |
"${PBINTERNALOPTS[@]}" \ |
| 69 |
--debbuildopts "" \ |
| 70 |
--debbuildopts "${DEBBUILDOPTS}" \ |
| 71 |
--uid "${BUILDRESULTUID}" \ |
| 72 |
--gid "${BUILDRESULTGID}" \ |
| 73 |
--pbuildersatisfydepends "$PBUILDERSATISFYDEPENDSCMD" |
| 74 |
if [ -d "${BUILDRESULT}" ]; then |
| 75 |
if [ "${SOURCE_ONLY_CHANGES:-no}" = yes ]; then |
| 76 |
FILES=$( { get822files "changes" "../$CHANGES" && get822files "changes" "../$SOURCE_CHANGES" ; } | sort -u) |
| 77 |
else |
| 78 |
FILES=$(get822files "changes" "../$CHANGES") |
| 79 |
fi |
| 80 |
log.d "Files to copy: $FILES" |
| 81 |
while read -r FILE; do |
| 82 |
if [ -f "$FILE" ]; then |
| 83 |
conditional_cp_a "$FILE" "$BUILDRESULT" |
| 84 |
else |
| 85 |
log.w "Expected file $FILE not found, skipping." |
| 86 |
fi |
| 87 |
done <<< "$FILES" |
| 88 |
for files in "${ADDITIONAL_BUILDRESULTS[@]}"; do |
| 89 |
log.i "Trying to save additional result ${files}" |
| 90 |
conditional_cp_a "${files}" "${BUILDRESULT}" || true |
| 91 |
done |
| 92 |
else |
| 93 |
log.e "BUILDRESULT=[$BUILDRESULT] is not a directory." |
| 94 |
exit 1 |
| 95 |
fi |
| 96 |
else |
| 97 |
if ! dpkg-checkbuilddeps -B ; then |
| 98 |
log.w "Unmet build-dependency in source" |
| 99 |
fi |
| 100 |
# get_changes_options/get_source_options single-quote each element, so an |
| 101 |
# eval is needed to reverse that. |
| 102 |
SOURCE_OPTIONS=$(get_source_options) |
| 103 |
eval dpkg-source ${SOURCE_OPTIONS} --before-build . |
| 104 |
if should_clean_source; then |
| 105 |
"${BUILDSOURCEROOTCMD}" debian/rules clean |
| 106 |
fi |
| 107 |
eval dpkg-source ${SOURCE_OPTIONS} -b . |
| 108 |
if ! [ "../${DSC}" -ef "${BUILDRESULT}/${DSC}" ]; then |
| 109 |
log.i "Generating source changes file for original dsc" |
| 110 |
eval dpkg-genchanges -S $(get_changes_options) > "../${SOURCE_CHANGES}" |
| 111 |
else |
| 112 |
log.i "Generated dsc will be overwritten by build result; not generating changes file" |
| 113 |
fi |
| 114 |
eval dpkg-source ${SOURCE_OPTIONS} --after-build . |
| 115 |
${PBUILDERROOTCMD} \ |
| 116 |
${PDEBUILD_PBUILDER} \ |
| 117 |
--build \ |
| 118 |
${EXTRA_CONFIGFILE[@]/#/--configfile } \ |
| 119 |
--buildresult "${BUILDRESULT}" \ |
| 120 |
--debbuildopts "" \ |
| 121 |
--debbuildopts "${DEBBUILDOPTS}" \ |
| 122 |
"$@" \ |
| 123 |
../"${PKG_SOURCENAME}_${PKG_VERSION}".dsc |
| 124 |
fi |
| 125 |
|
| 126 |
# do signing with optional key specifier |
| 127 |
if [ "${AUTO_DEBSIGN}" = "yes" ]; then |
| 128 |
unset DEBSIGN_PARAM || true |
| 129 |
declare -a DEBSIGN_PARAM |
| 130 |
if [ -n "${DEBSIGN_KEYID}" ]; then |
| 131 |
DEBSIGN_PARAM[${#DEBSIGN_PARAM[@]}]="-k${DEBSIGN_KEYID}" |
| 132 |
fi |
| 133 |
DEBSIGN_PARAM[${#DEBSIGN_PARAM[@]}]="--no-re-sign" |
| 134 |
DEBSIGN_PARAM[${#DEBSIGN_PARAM[@]}]="--" |
| 135 |
for file in "$BUILDRESULT/$CHANGES" "$BUILDRESULT/$SOURCE_CHANGES"; do |
| 136 |
if [ -f "$file" ]; then |
| 137 |
DEBSIGN_PARAM[${#DEBSIGN_PARAM[@]}]="$file" |
| 138 |
found=yes |
| 139 |
fi |
| 140 |
done |
| 141 |
if [ -z "${found:-}" ]; then |
| 142 |
log.e "No .changes file(s) can be found; debsign not done." |
| 143 |
exit 1 |
| 144 |
fi |
| 145 |
debsign "${DEBSIGN_PARAM[@]}" |
| 146 |
fi |