| 1 |
#! /bin/bash |
| 2 |
# pbuilder -- personal Debian package builder |
| 3 |
# Copyright © 2003-2009 Junichi Uekawa <[email protected]> |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 2 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program; if not, write to the Free Software |
| 17 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 |
############################################################################### |
| 19 |
|
| 20 |
# invoke this as |
| 21 |
# pbuilder execute pdebuild-internal --bindmount "${pwd}/.." "$1" |
| 22 |
# does not support --buildresult, but should that be required ? |
| 23 |
# |
| 24 |
# Risk: May corrupt your files depending on how user-mode-linux works, if used inside UML. |
| 25 |
# Will take longer if your package does not successfully run 'debian/rules clean' |
| 26 |
# |
| 27 |
|
| 28 |
# This script is running inside chroot under 'pbuilder execute' as root. |
| 29 |
|
| 30 |
set -e |
| 31 |
|
| 32 |
# I am probably running as root; make sure I have pbuilder installed here. |
| 33 |
# passwd is needed as well because of useradd and groupadd calls. |
| 34 |
apt-get install -q -y "${APTGETOPT[@]}" pbuilder passwd |
| 35 |
|
| 36 |
# I'm not going to have the same LOGNAME as outside, I'm root. |
| 37 |
export LOGNAME=root |
| 38 |
|
| 39 |
cd "$1" |
| 40 |
shift; |
| 41 |
|
| 42 |
# dummy function that does enough, real one is defined elsewhere. |
| 43 |
# We don't deal with LOGLEVEL here, though. |
| 44 |
# We can't just source the modules and use log.{i,w,e} since we don't know if |
| 45 |
# the pbuilder version inside the chroot is new enough. |
| 46 |
function log() { |
| 47 |
echo "$*" |
| 48 |
} |
| 49 |
|
| 50 |
while [ -n "$1" ]; do |
| 51 |
case "$1" in |
| 52 |
--debbuildopts) |
| 53 |
# append to DEBBUILDOPTS or reset to empty if $2 isn't set |
| 54 |
DEBBUILDOPTS="${2:+${DEBBUILDOPTS:+$DEBBUILDOPTS }$2}"; |
| 55 |
log "I: Setting DEBBUILDOPTS=$DEBBUILDOPTS" |
| 56 |
shift; shift; |
| 57 |
;; |
| 58 |
--source-only-changes) |
| 59 |
SOURCE_ONLY_CHANGES=yes |
| 60 |
shift |
| 61 |
;; |
| 62 |
--uid) |
| 63 |
BUILDRESULTUID=$2 |
| 64 |
shift; shift; |
| 65 |
;; |
| 66 |
--gid) |
| 67 |
BUILDRESULTGID=$2 |
| 68 |
shift; shift; |
| 69 |
;; |
| 70 |
--pbuildersatisfydepends) |
| 71 |
PBUILDERSATISFYDEPENDSCMD=$2 |
| 72 |
shift; shift; |
| 73 |
;; |
| 74 |
--debug) |
| 75 |
PBUILDER_DEBUGMODE=yes |
| 76 |
set -x |
| 77 |
shift; |
| 78 |
;; |
| 79 |
--*) |
| 80 |
log "E: Unknown option [$1] was specified " |
| 81 |
exit 1; |
| 82 |
;; |
| 83 |
*) |
| 84 |
break; |
| 85 |
;; |
| 86 |
esac |
| 87 |
done |
| 88 |
|
| 89 |
# Calling pbuilder-runhooks; we try to fix up enough to fool |
| 90 |
# pbuilder-runhooks. The following source call depends on |
| 91 |
# pbuilder-runhook inside the chroot, which might be different from |
| 92 |
# the version outside the chroot. |
| 93 |
. /usr/lib/pbuilder/pbuilder-runhooks |
| 94 |
# fool pbuilder-runhooks to use / as buildplace, since I am already |
| 95 |
# inside chroot. |
| 96 |
BUILDPLACE=/ |
| 97 |
# chroot command will just chroot to /, which will effectively chdir |
| 98 |
# to / and nothing else. |
| 99 |
CHROOTEXEC="chroot $BUILDPLACE " |
| 100 |
# make HOOKDIR contain something if there is a hook, to fool HOOKDIR |
| 101 |
# check inside pbuilder-runhooks that there is HOOKDIR |
| 102 |
# configuration. We don't call loadhooks or unloadhooks ourselves, |
| 103 |
# pbuilder execute will do that for you, so we should be okay. |
| 104 |
# TODO: handle when --hookdir was not initially specified. |
| 105 |
if [ -d "/$hookdir" ]; then |
| 106 |
HOOKDIR="/$hookdir" |
| 107 |
fi |
| 108 |
|
| 109 |
executehooks "D" |
| 110 |
export PBUILDER_OPERATION="pdebuild" |
| 111 |
export PBCURRENTCOMMANDLINEOPERATION="pdebuild" |
| 112 |
"$PBUILDERSATISFYDEPENDSCMD" |
| 113 |
apt-get install -q -y "${APTGETOPT[@]}" fakeroot |
| 114 |
|
| 115 |
|
| 116 |
# set home directory to .. |
| 117 |
export HOME=$(readlink -f $(pwd)/../) |
| 118 |
if [ -z "${HOME}" ]; then |
| 119 |
echo "E: Failed to obtain reasonable HOME from pwd" |
| 120 |
fi |
| 121 |
|
| 122 |
# create the user similar to that used outside. |
| 123 |
# TODO: what about id -G output? if other groups than the designated |
| 124 |
# is used, we're stuffed. |
| 125 |
groupadd -g "${BUILDRESULTGID}" -o pbgroup |
| 126 |
useradd -g pbgroup -u "${BUILDRESULTUID}" -d "${HOME}" -o pbuser |
| 127 |
|
| 128 |
executehooks "A" |
| 129 |
|
| 130 |
# do build with that user. |
| 131 |
# $DEBBUILDOPTS is expanded here, but split inside the su, to ensure the |
| 132 |
# options are de-quoted (and de-escaped) like pbuilder-buildpackage. |
| 133 |
export DEBBUILDOPTS |
| 134 |
CMD="env PATH=$PATH dpkg-buildpackage -rfakeroot -us -uc $DEBBUILDOPTS" |
| 135 |
if [ "${SOURCE_ONLY_CHANGES:-no}" = "yes" ]; then |
| 136 |
PKG_SOURCENAME=$(dpkg-parsechangelog -S Source) |
| 137 |
PKG_VERSION=$(dpkg-parsechangelog -S Version|sed 's/.*://') |
| 138 |
SOURCE_CHANGES="${PKG_SOURCENAME}_${PKG_VERSION}_source.changes" |
| 139 |
CMD="$CMD && env PATH=$PATH dpkg-genchanges -S $(get_changes_options) > ../$SOURCE_CHANGES" |
| 140 |
fi |
| 141 |
echo "I: Running $CMD" |
| 142 |
# This command should be ran with current directory as bind-mounted |
| 143 |
# package source directory |
| 144 |
if echo "$CMD" | \ |
| 145 |
su -p pbuser; |
| 146 |
then |
| 147 |
# build was successful |
| 148 |
: |
| 149 |
else |
| 150 |
executehooks "C" |
| 151 |
exit 1 |
| 152 |
fi |
| 153 |
|
| 154 |
executehooks "B" |