root/current/host/trunk/emdebian-tools/trunk/pbuilder/embootstrap

Revision 5275, 10.9 kB (checked in by codehelp, 3 days ago)

pbuilder/embootstrap : finally drop pkgdetails after testing with
Emdebian Grip sandbox

  • Property svn:executable set to *
Line 
1#!/bin/bash
2set -e
3
4#  embootstrap -- create a bootstrap for emdebian builds
5#
6#  Note that this script controls tarballs for empdebuild and emsandbox
7#  pass --cross to set an emsandbox tarball.
8#
9#  Copyright (C) 2007-2008  Neil Williams <codehelp@debian.org>
10#
11#  This package is free software; you can redistribute it and/or modify
12#  it under the terms of the GNU General Public License as published by
13#  the Free Software Foundation; either version 3 of the License, or
14#  (at your option) any later version.
15#
16#  This program is distributed in the hope that it will be useful,
17#  but WITHOUT ANY WARRANTY; without even the implied warranty of
18#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19#  GNU General Public License for more details.
20#
21#  You should have received a copy of the GNU General Public License
22#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
23#
24
25CWD=`pwd`
26
27# test for sudo
28# make sure sudo is in use.
29# bash cannot seem to do this when set -e is enabled
30# because grep returns non-zero on a non-match
31# so I use perl. :-)
32ISSUDOSET=`perl -e '$e=\`printenv\`; ($e =~ /SUDO_USER/) ? print "yes" : print "no";'`
33if [ $ISSUDOSET = "no" ] ; then
34        echo "embootstrap needs to be run under sudo."
35        exit 2
36fi
37
38. /usr/lib/pbuilder/pbuilder-modules
39. /usr/lib/pbuilder/pbuilder-buildpackage-funcs
40. /usr/lib/emdebian-tools/empbuilderlib
41
42# move to our own function file later.
43
44# Need support for create (this script), update (unpack base.tgz) and login
45# (sudo chroot /bin/sh) as well as the final empdebuild (emsource,emdebuild)
46# in a separate script.
47
48# Currently, this script needs user intervention to build the chroot:
49# emsetup asks for confirmation and apt-get install wants GnuPG verification.
50
51# This script will concentrate only on creating and updating the chroot.
52# Parameters.
53# WORK=location of this script.
54# MIRROR=the Debian primary mirror that will replace the default debootstrap mirror
55# (ftp.debian.org is not a primary and only supports 2 architectures).
56# TODO: needs command line options to set the rest of these parameters.
57
58# Note --oknodo will cause failures, see #426877
59
60WORK=$CWD
61
62get_work_dir
63BUILDPLACE=$WORKDIR
64BASETGZ="$BUILDPLACE/emdebian.tgz"
65BASETGZ=`echo $BASETGZ | tr -s \/`
66BUILDPLACE="$BUILDPLACE/pbuilder"
67# tidy up // to /
68BUILDPLACE=`echo $BUILDPLACE | tr -s \/`
69MIRROR=
70# don't die if the user has set 'None' for the dpkg-cross default.
71get_default_arch
72
73BUILDPLACE="${WORKDIR}/pbuilder/build"
74if [ -d $BUILDPLACE ]; then
75        rm -rf $BUILDPLACE/*
76fi
77if [ ! -d $BUILDPLACE ]; then
78        mkdir -p $BUILDPLACE
79fi
80BASETGZ="${WORKDIR}/emdebian.tgz"
81SUITE=unstable
82CROSS=x
83MACHINE=x
84VARIANT=x
85MACHINEPATH="${WORKDIR}/machine/"
86USEDEVPTS="yes"
87USEPROC="yes"
88
89while [ -n "$1" ]; do
90case "$1" in
91        -a|--arch)
92                shift
93                ARCH=$1
94                # chomp the argument to --arch
95                shift
96        ;;
97        --testing|testing)
98                shift;
99                BASETGZ="${WORKDIR}/emdebian-testing.tgz"
100                SUITE=testing
101                echo "Creating an embootstrap testing chroot"
102        ;;
103        # only for emsandbox support, empdebuild does not pass -S
104        -S|--suite)
105                shift
106                SUITE=$1
107                shift
108        ;;
109        --cross|cross)
110                shift;
111                BASETGZ="${WORKDIR}/emdebian-$ARCH.tgz"
112                CROSS=$ARCH
113                echo "Creating an embootstrap $ARCH chroot"
114        ;;
115        --script)
116                shift
117                CMD_SCRIPT=$1
118                if [ ! -f $CMD_SCRIPT ]; then
119                        echo "Cannot find suite script '$CMD_SCRIPT'."
120                        exit;
121                fi
122                echo "Using $CMD_SCRIPT"
123                shift
124        ;;
125        --machine-path)
126                shift
127                MACHINEPATH=$1
128                shift
129        ;;
130        --machine)
131                shift
132                MACHINE=$1
133                VARIANT=default
134                if [ ! -d "${MACHINEPATH}/$MACHINE" ]; then
135                        echo "Cannot find '${MACHINEPATH}/$MACHINE'."
136                        exit
137                fi
138                shift
139        ;;
140        --variant)
141                shift
142                VARIANT=$1
143                if [ ! $MACHINE ]; then
144                        echo "Variant specified without a machine."
145                        exit
146                fi
147                if [ ! -d "${MACHINEPATH}/$MACHINE/$VARIANT" ]; then
148                        echo "Cannot find '${MACHINEPATH}/$MACHINE/$VARIANT'."
149                        exit
150                fi
151                shift
152        ;;
153        *)
154                echo "Unrecognised option: $1"
155        exit;
156        ;;
157esac
158done
159
160if [ "$ARCH" = "None.\n" ]; then
161        echo $ARCH
162        echo Use the --arch option or dpkg-reconfigure dpkg-cross
163        exit
164fi
165
166# include packages.conf if --machine used.
167if [ "$MACHINE" != "x" -a "$VARIANT" != "x" -a $CROSS -a $CROSS = $ARCH ]; then
168        # sets INCLUDE, SCRIPT, MIRROR etc.
169        if [ -f ${MACHINEPATH}/$MACHINE/$VARIANT/packages.conf ]; then
170                . ${MACHINEPATH}/$MACHINE/$VARIANT/packages.conf
171        fi
172        echo "Using $MACHINE:$VARIANT"
173        if [ $TARBALL_NAME ]; then
174                echo "  -> creating ${WORKDIR}/${TARBALL_NAME}"
175                BASETGZ="${WORKDIR}/${TARBALL_NAME}"
176        fi
177fi
178
179checkarch
180HOST_ARCH=`dpkg-architecture -qDEB_HOST_ARCH`
181
182# let the command line override the packages.conf
183if [ ! $SCRIPT ]; then
184        SCRIPT=$CMD_SCRIPT
185fi
186
187# if neither command line nor packages.conf have a script set, use default.
188if [ ! $SCRIPT ]; then
189        SCRIPT="/usr/share/emdebian-tools/emdebian.crossd"
190fi
191
192if [ $CROSS -a $CROSS = $ARCH ]; then
193        echo "Building $ARCH chroot on $HOST_ARCH to install $ARCH packages."
194else
195        echo "Building $HOST_ARCH chroot on $HOST_ARCH to cross-build $ARCH packages."
196fi
197if [ -f ${BASETGZ} ]; then
198        echo "${BASETGZ} already exists! Aborting . . ."
199        exit 1;
200fi
201echo "Checking for a user writeable tree in $BUILDPLACE"
202check_dirs
203echo " -> running debootstrap"
204export LANG=C
205export LC_ALL=C
206# debootstrap 1.0.7 has moved
207WORK="/usr/share/debootstrap/"
208# handle old versions of debootstrap so that we can migrate into testing.
209if [ -f "/usr/lib/debootstrap/functions" ]; then
210        WORK="/usr/lib/debootstrap/";
211fi
212FOREIGN=
213INC=
214if [ $CROSS -a $CROSS = $ARCH ]; then
215        echo "  -> cross detected, using foreign."
216        FOREIGN="--foreign"
217        if [ ! $MIRROR ]; then
218                MIRROR="http://buildd.emdebian.org/emdebian/"
219        fi
220        if [ ! $PROXY ]; then
221                PROXY="http://buildd.emdebian.org/emdebian/"
222        fi
223        if [ $INCLUDE ]; then
224                INC="--include=$INCLUDE"
225        fi
226        # if SUITE is empty in packages.conf, reset the default
227        if [ ! $SUITE ]; then
228                SUITE=unstable
229        fi
230        BUILDD=$SCRIPT
231        if [ ! -f ${WORKDIR}/stamp-debootstrap ]; then
232                echo "DEBOOTSTRAP_DIR=$WORK debootstrap $INC --verbose $FOREIGN --arch ${ARCH} $SUITE $BUILDPLACE $MIRROR $BUILDD"
233                DEBOOTSTRAP_DIR=$WORK debootstrap ${INC} --verbose $FOREIGN --arch ${ARCH} $SUITE $BUILDPLACE $PROXY $BUILDD
234                echo " -> debootstrap stage complete"
235                echo " -> Checking for machine:variant hooks"
236                # hooks
237                if [ $INC ]; then
238                        echo "${INC}" >> $BUILDPLACE/debootstrap/machineincludes
239                fi
240                if [ -f ${MACHINEPATH}/$MACHINE/$VARIANT/setup.sh ]; then
241                        if [ ! -z "$EXTRA" ]; then
242                                if [ -e $EXTRA ]; then
243                                        cp $EXTRA $BUILDPLACE/
244                                fi
245                        fi
246                        echo " -> Running $MACHINE/$VARIANT/setup.sh $BUILDPLACE $ARCH"
247                        sh ${MACHINEPATH}/$MACHINE/$VARIANT/setup.sh $BUILDPLACE $ARCH
248                fi
249                if [ -f ${MACHINEPATH}/$MACHINE/$VARIANT/config.sh ]; then
250                        echo " -> Copying config.sh for $MACHINE:$VARIANT into tarball"
251                        mkdir -p $BUILDPLACE/machine/
252                        cp ${MACHINEPATH}/$MACHINE/$VARIANT/config.sh $BUILDPLACE/machine/
253                fi
254                touch ${WORKDIR}/stamp-debootstrap
255        fi # end of $CROSS
256else # else if not $CROSS
257        # TODO this should be configurable - emdebian-tools will add a primary later.
258        # copy or use the ~/.apt-cross/sources.foo. files.
259        if [ ! $MIRROR ]; then
260                URL=`perl -e "use Emdebian::Tools; use Config::Auto; print &get_primary;"`
261                if [ ! -z "$URL" ]; then
262                        MIRROR="http://${URL}/debian"
263                fi
264        fi
265        if [ ! $MIRROR ]; then
266                MIRROR="http://ftp.fr.debian.org/debian/"
267        fi
268        BUILDD=/usr/share/emdebian-tools/emdebian.buildd
269        if [ ! -f ${WORKDIR}/stamp-debootstrap ]; then
270                echo "DEBOOTSTRAP_DIR=$WORK debootstrap --verbose $SUITE $BUILDPLACE $MIRROR $BUILDD"
271                DEBOOTSTRAP_DIR=$WORK debootstrap --verbose $SUITE $BUILDPLACE $MIRROR $BUILDD
272                touch ${WORKDIR}/stamp-debootstrap
273        fi
274fi
275mkdir -p "$BUILDPLACE/tmp/buildd"
276
277copy_host_configuration
278
279# emdebian-tools will be reconfigured later.
280# ensure src is available if not emsandbox
281echo "  -> Installing apt-lines for $MIRROR"
282mkdir -p "$BUILDPLACE/etc/apt/sources.list.d/"
283rm -f "$BUILDPLACE"/etc/apt/sources.list
284if [ $CROSS -a $CROSS = $ARCH ]; then
285        cat >> "$BUILDPLACE"/etc/apt/sources.list.d/emdebian.sources.list << EOF
286#emdebian target repository : default source list
287# created by emsandbox
288deb $MIRROR $SUITE main
289#deb-src $MIRROR $SUITE main
290EOF
291else
292        cat >> "$BUILDPLACE"/etc/apt/sources.list << EOF
293deb $MIRROR $SUITE main
294deb-src $MIRROR $SUITE main
295EOF
296fi
297
298if [ $CROSS -a $CROSS = $ARCH ]; then
299        # copy our secure apt key into the chroot for apt-key
300        cp /usr/share/emdebian-tools/0x97BB3B58.txt $BUILDPLACE/
301        # copy in our install helper
302        cp /usr/share/emdebian-tools/emsecondstage $BUILDPLACE/
303        # only executable by root to allow debootstrap to work properly.
304        chmod 744 $BUILDPLACE/emsecondstage
305        rm -f $BUILDPLACE/debootstrap/debootstrap.log
306        # empty if using unpack but should still exist.
307        save_aptcache
308else
309        echo "Refreshing the base.tgz "
310        echo " -> upgrading packages"
311        mountproc
312        chroot $BUILDPLACE /usr/bin/apt-get update
313        recover_aptcache
314        chroot $BUILDPLACE /usr/bin/apt-get -y --force-yes dist-upgrade
315        echo " -> adding the Emdebian repository key"
316        chroot $BUILDPLACE mkdir -p /home/$SUDO_USER/.gnupg
317        chroot $BUILDPLACE mkdir -p /home/$SUDO_USER/.dpkg-cross
318        if [ -f /home/$SUDO_USER/.devscripts ]; then
319                cp /home/$SUDO_USER/.devscripts $BUILDPLACE/home/$SUDO_USER/.devscripts
320        fi
321        cp /usr/share/emdebian-tools/0x97BB3B58.txt $BUILDPLACE/
322        chroot $BUILDPLACE apt-key add 0x97BB3B58.txt
323        if [ -f 0x97BB3B58.txt ]; then
324                rm 0x97BB3B58.txt
325        fi
326        echo "   -> updating /etc/hosts"
327        cp /etc/hosts $BUILDPLACE/etc/hosts
328        # emdebian.buildd installs emdebian-tools which sets up apt for the emdebian repository
329        echo "   -> updating the apt cache"
330        chroot "$BUILDPLACE" /usr/bin/apt-get update
331        # upgrade emdebian-tools and apt-cross before running emsetup
332        echo "   -> upgrading emdebian-tools and apt-cross"
333        chroot "$BUILDPLACE" /usr/bin/apt-get -y --force-yes dist-upgrade
334        echo "   -> updating apt-cross cache"
335        DPKG_CROSS="/home/$SUDO_USER/.dpkg-cross"
336        if [ ! -f $DPKG_CROSS/apt.conf-${SUITE} ]; then
337                chroot $BUILDPLACE /usr/bin/apt-cross -a $ARCH -S $SUITE -u
338        else
339                echo "     -> copying existing apt-cross cache"
340                cp $DPKG_CROSS/apt.conf-$SUITE $BUILDPLACE/$DPKG_CROSS/
341                cp $DPKG_CROSS/sources.$SUITE $BUILDPLACE/$DPKG_CROSS/
342                cp $DPKG_CROSS/status-$SUITE $BUILDPLACE/$DPKG_CROSS/
343                cp -r $DPKG_CROSS/$SUITE $BUILDPLACE/$DPKG_CROSS/
344        fi
345        echo "   -> running emsetup"
346        if chroot "$BUILDPLACE" /usr/bin/emsetup -v -a $ARCH --yes; then
347                :
348                else
349                        echo "  -> emsetup failed"
350                        if [ "${LOGIN_AFTER_FAIL}" = "yes" ]; then
351                                echo "   -> Logging into the chroot"
352                                echo "   -> Build directory: /trunk/$SVN"
353                                echobacktime
354                                chroot $BUILDPLACE /bin/sh
355                                save_aptcache
356                                echo "  -> emsetup failed"
357                                chroot $BUILDPLACE /usr/bin/apt-get clean
358                                umountproc
359                                create_emdebiantgz
360                                cleanbuildplace
361                                rm ${WORKDIR}/stamp-debootstrap
362                                exit 1;
363                        fi
364                        save_aptcache
365                        umountproc
366                        chroot $BUILDPLACE /usr/bin/apt-get clean
367                        create_emdebiantgz
368                        cleanbuildplace
369                        rm ${WORKDIR}/stamp-debootstrap
370                        echobacktime
371                        echo "  -> emsetup failed: exiting with an error!"
372                        echo " Try --login-after-fail"
373                        exit 1;
374                fi
375        umountproc
376        save_aptcache
377        chroot $BUILDPLACE /usr/bin/apt-get clean
378fi
379
380create_emdebiantgz
381cleanbuildplace
382rm ${WORKDIR}/stamp-debootstrap
Note: See TracBrowser for help on using the browser.