2
# Copyright (C) 2012-2013 Canonical
7
# This program is free software; you can redistribute it and/or modify it under
8
# the terms of the GNU General Public License as published by the Free Software
9
# Foundation; version 3.
11
# This program is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16
# You should have received a copy of the GNU General Public License along with
17
# this program; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
# go to the working directory
42
# set home directory to real HOME for signing the source packaging
47
echo "$0: Enable building a source package inside a chroot
49
Usage: $0 WORKDIR --uid=UID --gid=GID --gnupg-parentdir=DIR --gnupg-keyid=KEYID --distro-version=version_from_distro [--ppa ppa_name]
50
All parameters below are mandatory:
51
- WORKDIR is the current package source directory (in tree)
52
- uid is the uid owning the current source tree (used so that root don't own the new created files)
53
- gid is the gid owning the current source tree (used so that root don't own the new created files)
54
- gnupg-parentdir is the directory containing the .gnupg/ directory. Certainly $HOME for you.
55
- gnupg-keyid is the keyid with which signing the source package.
56
- distro-version is the latest version published to the distro
57
- ppa is the optional ppa to add to the chroot
60
Note that WORKDIR and gnupg-keyid should be bindmounted into the chroot.
61
This will create a signed source package using bzr bd -S, after installing all build-deps, ran into the WORKDIR, with the correct permission.
64
Example on how to run it with pbuilder (cowbuilder can be used with exactly the same parameters, replace pbuilder with cowbuilder):"'
66
$ pbuilder --execute --distribution TARGET_DIST --bindmounts ${PWD} --bindmounts ${HOME} -- '$0' ${PWD} --gnupg-parentdir ${HOME} --uid $(id -u) --gid $(id -g) --gnupg-keyid E4AC208E'
83
echo "E: Unknown option [$1] was specified "
92
if [ -z "$CHROOT_HOME" ] || [ -z "$CHROOT_UID" ] || [ -z "$CHROOT_GID" ] || [ -z "KEYID" ] || [ -z "DISTRO_VERSION" ] ; then
93
echo "Every parameters is mandatory to run $0. Use --help for more info."
101
apt-get -yq --force-yes dist-upgrade
103
# this isn't needed (you should install them in the chroot), but easier for debugging
104
apt-get install pbuilder bzr-builddeb libwww-perl -yq --force-yes
106
# add the optional ppa and update from it
107
if [ -n "$PPA" ]; then
108
apt-get -yq --force-yes install software-properties-common
109
add-apt-repository -y ppa:$PPA
114
. /usr/lib/pbuilder/pdebuild-checkparams
115
export PBCURRENTCOMMANDLINEOPERATION="pdebuild"
116
"$PBUILDERSATISFYDEPENDSCMD"-classic --force-version --continue-fail
118
# create the user similar to that used outside.
120
# Tries to execute $@ $loop times with a delay of $delay between retries
125
while [ $loop -gt 0 ]; do
133
# Workaround a bug where /etc/group or /etc/passwd are locked when several
134
# jobs run in parallel (LP: #1155510)
135
cmd_retry_exec groupadd -g $CHROOT_GID -o pbgroup
136
cmd_retry_exec useradd -g pbgroup -u $CHROOT_UID -d "${HOME}" -o pbuser
138
# build the source in split mode
139
if [ "$KEYID" == "testkey" ]; then
140
CMD="bzr bd -S -- -us -uc -d -v$DISTRO_VERSION"
142
CMD="bzr bd -S -- -k$KEYID -d -v$DISTRO_VERSION"
144
echo "Creating source with $CMD"
145
echo "$CMD" | su -p pbuser;