Debian Codegraph @

pbuilder-createbuildenv

raw
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 . "${BASH_SOURCE%/*}/pbuilder-checkparams"
24
25 if [ -z "$DISTRIBUTION" ]; then
26 DISTRIBUTION=sid
27 fi
28 log.i "Distribution is $DISTRIBUTION."
29
30 if [ "${PBUILDER_DEBUGMODE}" = "yes" ]; then
31 TRAP="echo ignoring trap "
32 else
33 TRAP=trap
34 fi
35
36 # show the current time before doing anything.
37 echobacktime
38
39 # first clean it.
40 cleanbuildplace
41
42 log.i "Building the build environment"
43 mkdir -p "$BUILDPLACE"
44 if [ ! -d "$BUILDPLACE" ]; then
45 log.e "Could not make directory [$BUILDPLACE]"
46 exit 1
47 fi
48
49 $TRAP cleanbuildplace exit
50
51 log.i "running $DEBOOTSTRAP"
52 unset DEBOOTSTRAPSCRIPT
53 if [ -n "$HOOKDIR" ]; then
54 if [ -f "$HOOKDIR/$DISTRIBUTION" ]; then
55 DEBOOTSTRAPSCRIPT=$(readlink -f "$HOOKDIR")"/$DISTRIBUTION"
56 log.i "Applying user distribution dist build script $DEBOOTSTRAPSCRIPT"
57 fi
58 fi
59
60 if which "${DEBOOTSTRAP}"; then
61 : # debootstrap exists
62 else
63 log.e "${DEBOOTSTRAP} does not exist, install or change DEBOOTSTRAP option"
64 exit 1
65 fi
66
67 # use cache for debootstrap
68 if [ -n "$APTCACHE" ] && [ "${DEBOOTSTRAP}" = debootstrap -o "${DEBOOTSTRAP}" = qemu-debootstrap ]; then
69 USE_CACHE="--cache-dir=$APTCACHE"
70 fi
71
72 # FIXME if the end-user passes another --include= to debootstrap in
73 # DEBOOTSTRAPOPTS, it will override the --include=apt one and apt might not be
74 # installed
75 if ! ( "${DEBOOTSTRAP}" \
76 ${ARCHITECTURE:+--arch=$ARCHITECTURE} \
77 --include=apt \
78 ${USE_CACHE:+"$USE_CACHE"} \
79 "${DEBOOTSTRAPOPTS[@]}" \
80 "$DISTRIBUTION" \
81 "$BUILDPLACE" \
82 "$MIRRORSITE" \
83 $DEBOOTSTRAPSCRIPT ) ; then
84 log.e "$DEBOOTSTRAP failed"
85 if [ -f "$BUILDPLACE/debootstrap/debootstrap.log" ]; then
86 log.e "Tail of debootstrap.log:"
87 tail -n 50 "$BUILDPLACE/debootstrap/debootstrap.log"
88 log.e "End of debootstrap.log"
89 else
90 log.e "debootstrap.log not present"
91 fi
92 exit 1
93 fi
94
95 log.i "debootstrap finished"
96
97
98 mkdir -p "${BUILDPLACE}$BUILDDIR"
99
100 copy_local_configuration
101 installaptlines
102 add_additional_aptkeyrings
103 loadhooks
104 executehooks "G"
105
106 log.i "Refreshing the base.tgz "
107 log.i "upgrading packages"
108 mountproc
109 $TRAP umountproc_cleanbuildplace_trap exit sighup
110 $CHROOTEXEC apt-get -q "${APTGETOPT[@]}" update
111
112 install_packages_for_optional_features
113
114 if [ -n "$REMOVEPACKAGES" ]; then remove_packages $REMOVEPACKAGES ; fi
115 recover_aptcache
116 $CHROOTEXEC apt-get -q -y "${APTGETOPT[@]}" "${FORCE_CONFNEW[@]}" dist-upgrade
117 $CHROOTEXEC apt-get -q -y "${APTGETOPT[@]}" install \
118 build-essential \
119 dpkg-dev \
120 $EXTRAPACKAGES
121 save_aptcache
122
123 executehooks "E"
124 umountproc
125 $CHROOTEXEC apt-get clean || true
126 $TRAP cleanbuildplace_trap exit sighup
127
128 # Internal_build_uml is set when --no-targz is set, this code is actually never called from pbuilder-user-mode-linux
129 if [ ! "${INTERNAL_BUILD_UML}" = "yes" ]; then
130 create_basetgz
131 fi
132 if [ "${PRESERVE_BUILDPLACE}" = "yes" ]; then
133 :
134 else
135 :
136 cleanbuildplace
137 fi
138 trap - exit sighup
139 exit 0