pbuilder-createbuildenv 3.81 KB
Newer Older
1
#! /bin/bash
dancer's avatar
dancer committed
2
#   pbuilder -- personal Debian package builder
3 4
#   Copyright © 2001-2007 Junichi Uekawa <dancer@debian.org>
#               2015      Mattia Rizzolo <mattia@debian.org>
dancer's avatar
dancer committed
5 6 7 8 9 10 11 12 13 14 15 16 17
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
dancer's avatar
dancer committed
18
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19
###############################################################################
dancer's avatar
dancer committed
20

21
set -e 
dancer's avatar
dancer committed
22

23
. "${BASH_SOURCE%/*}/pbuilder-checkparams"
24

dancer's avatar
dancer committed
25
if [ -z "$DISTRIBUTION" ]; then
26
    DISTRIBUTION=sid
dancer's avatar
dancer committed
27
fi
28
log.i "Distribution is $DISTRIBUTION."
dancer's avatar
dancer committed
29

30
if [ "${PBUILDER_DEBUGMODE}" = "yes" ]; then
31 32 33 34 35
    TRAP="echo ignoring trap "
else
    TRAP=trap
fi

36 37 38
# show the current time before doing anything.
echobacktime

39
# first clean it.
40
cleanbuildplace
dancer's avatar
dancer committed
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 47
    exit 1
fi
dancer's avatar
dancer committed
48

49
$TRAP cleanbuildplace exit
50

51
log.i "running $DEBOOTSTRAP"
52
unset DEBOOTSTRAPSCRIPT
dancer's avatar
dancer committed
53 54
if [ -n "$HOOKDIR" ]; then
    if [ -f "$HOOKDIR/$DISTRIBUTION" ]; then
dancer's avatar
dancer committed
55
	DEBOOTSTRAPSCRIPT=$(readlink -f "$HOOKDIR")"/$DISTRIBUTION"
56
	log.i "Applying user distribution dist build script $DEBOOTSTRAPSCRIPT"
dancer's avatar
dancer committed
57 58
    fi
fi
dancer's avatar
dancer committed
59

60 61 62
if which "${DEBOOTSTRAP}"; then
    : # debootstrap exists
else
63
    log.e "${DEBOOTSTRAP} does not exist, install or change DEBOOTSTRAP option"
64 65 66
    exit 1
fi

67
# use cache for debootstrap
68
if [ -n "$APTCACHE" ] && [ "${DEBOOTSTRAP}" = debootstrap -o "${DEBOOTSTRAP}" = qemu-debootstrap ]; then
69 70 71
    USE_CACHE="--cache-dir=$APTCACHE"
fi

72 73 74
# FIXME if the end-user passes another --include= to debootstrap in
# DEBOOTSTRAPOPTS, it will override the --include=apt one and apt might not be
# installed
Gabriele Giacone's avatar
Gabriele Giacone committed
75
if ! ( "${DEBOOTSTRAP}" \
76
    ${ARCHITECTURE:+--arch=$ARCHITECTURE} \
77
    --include=apt \
78
    ${USE_CACHE:+"$USE_CACHE"} \
79
    "${DEBOOTSTRAPOPTS[@]}" \
80
    "$DISTRIBUTION" \
Gabriele Giacone's avatar
Gabriele Giacone committed
81
    "$BUILDPLACE" \
82
    "$MIRRORSITE" \
83
    $DEBOOTSTRAPSCRIPT ) ; then
84
    log.e "$DEBOOTSTRAP failed"
85 86 87 88 89 90 91
    if [ -f "$BUILDPLACE/debootstrap/debootstrap.log" ]; then
        log.e "Tail of debootstrap.log:"
        tail -n 50 "$BUILDPLACE/debootstrap/debootstrap.log"
        log.e "End of debootstrap.log"
    else
        log.e "debootstrap.log not present"
    fi
dancer's avatar
dancer committed
92
    exit 1
dancer's avatar
dancer committed
93 94
fi

95
log.i "debootstrap finished"
dancer's avatar
dancer committed
96

97

98
mkdir -p "${BUILDPLACE}$BUILDDIR"
99

100
copy_local_configuration
dancer's avatar
dancer committed
101
installaptlines
102
add_additional_aptkeyrings
103
loadhooks
104 105
executehooks "G"

106 107
log.i "Refreshing the base.tgz "
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 117
$CHROOTEXEC apt-get -q -y "${APTGETOPT[@]}" "${FORCE_CONFNEW[@]}" dist-upgrade
$CHROOTEXEC apt-get -q -y "${APTGETOPT[@]}" install \
118 119 120
    build-essential \
    dpkg-dev \
    $EXTRAPACKAGES
dancer's avatar
dancer committed
121
save_aptcache
122

dancer's avatar
dancer committed
123
executehooks "E"
124
umountproc
125
$CHROOTEXEC apt-get clean || true
126
$TRAP cleanbuildplace_trap exit sighup
127

128 129 130 131
# Internal_build_uml is set when --no-targz is set, this code is actually never called from pbuilder-user-mode-linux
if [ ! "${INTERNAL_BUILD_UML}" = "yes" ]; then
    create_basetgz
fi
dancer's avatar
dancer committed
132
if [ "${PRESERVE_BUILDPLACE}" = "yes" ]; then
133 134
    :
else
135
    :
136
    cleanbuildplace
dancer's avatar
dancer committed
137
fi
138
trap - exit sighup
139
exit 0