aboutsummaryrefslogtreecommitdiffhomepage
path: root/git-pbuilder
blob: 50443c7f42fd470c07bf90324c72082565e14e3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/sh
# $Id: git-pbuilder,v 1.16 2010-09-01 21:30:33 eagle Exp $
#
# git-pbuilder -- Wrapper around pbuilder for git-buildpackage
#
# Written by Russ Allbery <rra@stanford.edu>
# Based on the example in the git-buildpackage documentation
# Copyright 2008, 2009, 2010 Board of Trustees, Leland Stanford Jr. University
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of Stanford University not be used in
# advertising or publicity pertaining to distribution of the software without
# specific, written prior permission.  Stanford University makes no
# representations about the suitability of this software for any purpose.  It
# is provided "as is" without express or implied warranty.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

set -e

# The root directory where different cowbuilder --basepath directories are
# found.  git-pbuilder expects them to be named base-<dist>.cow.
COWBUILDER_BASE=/var/cache/pbuilder

# Make sure we have the necessary tools
if [ ! -x /usr/sbin/cowbuilder ]; then
    echo "Cowbuilder not found; you need to install the cowbuilder package" >&2
    exit 1
fi

# Set DIST based on the name we were invoked as.  This allows people to create
# symlinks like git-pbuilder-lenny pointing to git-pbuilder and auto-detecting
# the distribution from that.
if [ -z "$DIST" ] ; then
    DIST=${0#*git-pbuilder-}
    case $DIST in
    *git-pbuilder*) DIST= ;;
    esac
fi
if [ -n "$DIST" ] ; then
    if [ -n "$ARCH" ] ; then
        echo "Building for distribution $DIST, architecture $ARCH"
    else
        echo "Building for distribution $DIST"
    fi
fi

# If DIST is set, use base-$DIST.cow.  If DIST is not set, the sid chroot may
# be either base.cow or base-sid.cow.  Try both.  If ARCH is set, use
# base-$DIST-$ARCH.cow.
OPTIONS=
if [ -z "$DIST" ] ; then
    DIST=sid
fi
if [ -n "$ARCH" ] ; then
    BASE="$COWBUILDER_BASE/base-$DIST-$ARCH.cow"
    OPTIONS="--architecture $ARCH"
elif [ "$DIST" = 'sid' ] ; then
    if [ -d "$COWBUILDER_BASE/base-sid.cow" ] ; then
        BASE="$COWBUILDER_BASE/base-sid.cow"
    else
        BASE="$COWBUILDER_BASE/base.cow"
    fi
else
    BASE="$COWBUILDER_BASE/base-$DIST.cow"
fi

# Make sure the base directory exists.
if [ ! -d "$BASE" ] && [ "$1" != "create" ]; then
    echo "Base directory $BASE does not exist" >&2
    exit 1
fi

# Set --debian-etch-workaround if DIST is etch.  Assume that everything else
# is new enough that it will be fine.
if [ "$DIST" = 'etch' ] || [ "$DIST" = 'ebo' ] ; then
    OPTIONS="$OPTIONS --debian-etch-workaround"
fi

# If the first argument to the script is update, create, or login, run
# cowbuilder with the corresponding option under sudo rather than proceeding.
case $1 in
update|create|login)
    action="$1"
    shift
    sudo cowbuilder --"$action" --basepath "$BASE" --dist "$DIST" $OPTIONS "$@"
    exit $?
    ;;
*)
    if [ -z "$GBP_BUILD_DIR" ]; then
        echo "WARNING: not invoked by git-buildpackage." >&2
    fi
    ;;
esac

# Now we can finally run pdebuild.  The quoting here is tricky, but this
# seems to pass everything through properly.
pdebuild --buildresult .. --pbuilder cowbuilder \
    --debbuildopts "-i'(?:^|/)\\.git(attributes)?(?:\$|/.*\$)' -I.git $*" \
    -- --basepath "$BASE" $OPTIONS
if [ -n "`ls ../*_source.changes`" ] ; then
    rm ../*_source.changes
fi
exit 0

# Documentation.  Use a hack to hide this from the shell.  Because of the
# above exit line, this should never be executed.
DOCS=<<__END_OF_DOCS__

=head1 NAME

git-pbuilder - Wrapper around pbuilder for git-buildpackage

=head1 SYNOPSIS

DIST=I<distribution> ARCH=I<architecture> B<git-pbuilder> I<debbuild-options>

DIST=I<distribution> ARCH=I<architecture> \
    B<git-pbuilder> (update | create | login) I<cowbuilder-options>

=head1 DESCRIPTION

B<git-pbuilder> is a wrapper around B<pdebuild> intended for use by
B<git-buildpackage>.  It configures B<pdebuild> to use B<cowbuilder>,
passes appropriate options to B<debbuild>, and sets the base path for
B<cowbuilder> based on the environment variable DIST and, if set, the
environment variable ARCH.

By default, B<git-pbuilder> assumes the target distribution is C<sid>, the
same architecture as the B<cowbuilder> default, and uses
F</var/cache/pbuilder/base-sid.cow> if it exists.  If it doesn't,
F</var/cache/pbuilder/base.cow> is tried.  If DIST is set, its value is
the target distribution and F</var/cache/pbuilder/base-I<dist>.cow> is
used instead.  If DIST is C<etch> or C<ebo>, B<--debian-etch-workaround>
is also passed to B<cowbuilder>.  If ARCH is set, its value is the target
architecture and F</var/cache/pbuilder/base-I<dist>-I<arch>.cow> is used,
with I<dist> being set to C<sid> if DIST was not set.

If B<git-pbuilder> is invoked via a name that starts with
C<git-pbuilder->, the part after the last hyphen is taken to be the
distribution (although the environment variable overrides this).  One can
therefore create symlinks like C<git-pbuilder-lenny> pointing to
B<git-pbuilder> and use that name when wanting to use a distribution of
C<lenny>.

Any arguments are passed as-is to B<dpkg-buildpackage> via the
B<--debbuildopts> option to B<pdebuild>.

Normally, one does not run this script directly.  Instead, it's used as
the builder script for B<git-buildpackage>.  To configure
B<git-buildpackage> to use it, add a stanza like:

    [DEFAULT]
    builder = /path/to/git-pbuilder

in your F<gbp.conf> file (which can be F<.gbp.conf> in your home directory
or at the top level of the repository, or F<gbp.conf> in the F<.git>
directory).  DIST is read as an environment variable so that you can set
it before running B<git-buildpackage> without having to worry about
passing parameters through B<git-buildpackage>.

Alternately, B<git-pbuilder> may be called with an argument of C<update>,
C<create>, or C<login>.  In this case, it calls B<cowbuilder> using
B<sudo> and passes the corresponding command to B<cowbuilder>, using the
same logic as above to determine the base directory and distribution.  Any
additional arguments to B<git-pbuilder> are passed along to B<cowbuilder>.

=head1 ENVIRONMENT

=over 4

=item DIST

Sets the target distribution.  This is used primarily to determine the
base path for B<cowbuilder>, but it's also used to determine whether to
pass B<--debian-etch-workaround> to B<cowbuilder>.

=back

=head1 FILES

=over 4

=item /var/cache/pbuilder/base-sid.cow

=item /var/cache/pbuilder/base.cow

The default C<cowbuilder --basepath> directories, searched for in that
order, if DIST is not set.

=item /var/cache/pbuilder/base-$DIST.cow

The C<cowbuilder --basepath> directory used if DIST is set.

=back

=head1 SEE ALSO

cowbuilder(8), dpkg-buildpackage(1), git-buildpackage(1), pdebuild(1),
sudo(8)

The latest version of this script is available from
L<http://www.eyrie.org/~eagle/software/scripts/>.

=head1 AUTHOR

Russ Allbery <rra@stanford.edu>

=cut

__END_OF_DOCS__