~ubuntu-branches/ubuntu/jaunty/sbuild/jaunty

« back to all changes in this revision

Viewing changes to bin/sbuild-createchroot

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2008-08-03 09:59:51 UTC
  • mfrom: (8.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080803095951-q7yt3oskxwsn2uvn
Tags: 0.57.5-1ubuntu1
* Merge from debian unstable, remaining changes:
 + Sbuild.pm: 
  - If we're trying to compare versions against a provided package, 
    always return "not satisfied", forcing an install attempt.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
 
1
#!/usr/bin/perl
2
2
#
3
3
# Run debootstrap and add a few other files needed to create a working
4
4
# sbuild chroot.
5
5
# Copyright © 2004 Francesco P. Lovergine <frankie@debian.org>.
6
 
# Copyright © 2007 Roger Leigh <rleigh@debian.org>.
 
6
# Copyright © 2007-2008 Roger Leigh <rleigh@debian.org>.
7
7
#
8
8
# This program is free software: you can redistribute it and/or modify
9
9
# it under the terms of the GNU General Public License as published by
21
21
#
22
22
#######################################################################
23
23
 
24
 
set -e
25
 
 
26
 
if [ $(id -u) != 0 ]; then
27
 
    echo "You need to run this command as root"
28
 
    exit 2
29
 
fi
30
 
 
31
 
if [ $# -ne 3 ]; then
32
 
    echo "$0 <suite> <target-dir> <debian-mirror-url>"
33
 
    echo "      E.g. $0 sarge /path/to/chroot http://http.us.debian.org/debian"
34
 
    exit 1
35
 
fi
36
 
 
37
 
SUITE=$1
38
 
TARGET=$2
39
 
MIRROR=$3
40
 
 
41
 
/usr/sbin/debootstrap \
42
 
    --variant=buildd \
43
 
    --include=fakeroot,build-essential \
44
 
    "$SUITE" "$TARGET" "$MIRROR"
45
 
 
46
 
cat <<EOF >"$TARGET/etc/apt/sources.list"
47
 
# $SUITE
48
 
deb $MIRROR/ $SUITE main contrib non-free
49
 
deb-src $MIRROR/ $SUITE main contrib non-free
50
 
 
51
 
EOF
52
 
 
53
 
echo "I: Configured APT sources.list:"
54
 
echo "────────────────────────────────────────────────────────────────────────"
55
 
cat "$TARGET/etc/apt/sources.list"
56
 
echo "────────────────────────────────────────────────────────────────────────"
57
 
 
58
 
cat <<EOF
59
 
I: Please add any additional APT sources to $TARGET/etc/apt/sources.list
60
 
I: Successfully set up $SUITE chroot.
61
 
I: Please add the following entry to /etc/schroot/schroot.conf:
62
 
────────────────────────────────────────────────────────────────────────
63
 
[$SUITE-sbuild]
 
24
use strict;
 
25
use warnings;
 
26
 
 
27
use POSIX;
 
28
use Getopt::Long qw(:config no_ignore_case auto_abbrev gnu_getopt);
 
29
use Sbuild::Sysconfig qw($arch $hostname);
 
30
use Sbuild qw(dump_file help_text version_text usage_error);
 
31
use File::Temp ();
 
32
 
 
33
package main;
 
34
 
 
35
sub add_items ($@);
 
36
sub dump_file ($);
 
37
 
 
38
# Add items to the start of a comma-separated list, and remove the
 
39
# items from later in the list if they were already in the list.
 
40
sub add_items ($@) {
 
41
    my $items = shift;
 
42
    my @add = @_;
 
43
 
 
44
    my $ret = '';
 
45
    my %values;
 
46
 
 
47
    foreach (@_) {
 
48
        $values{$_} = '';
 
49
        $ret .= "$_,"
 
50
    }
 
51
 
 
52
    # Only add if not already used, to eliminate duplicates.
 
53
    foreach (split (/,/,$items)) {
 
54
        $ret .= "$_," if (!defined($values{$_}));
 
55
    }
 
56
 
 
57
    # Remove trailing comma.
 
58
    $ret =~ s/,$//;
 
59
 
 
60
    return $ret;
 
61
}
 
62
 
 
63
our $bootstrap_arch = $arch;
 
64
our $foreign = 0;
 
65
our $include = '';
 
66
our $exclude = '';
 
67
our $components = 'main';
 
68
our $keyring = '';
 
69
our $resolve_deps = 1;
 
70
our $keep_debootstrap_dir = 0;
 
71
our $verbose = 0;
 
72
 
 
73
# Default to using the system keyring
 
74
if (!defined($keyring) && -f '/etc/apt/trusted.gpg') {
 
75
    $keyring='/etc/apt/trusted.gpg';
 
76
}
 
77
 
 
78
GetOptions (
 
79
    "h|help" => sub { help_text("8", "sbuild-createchroot"); },
 
80
    "V|version" => sub {version_text("sbuild-createchroot"); },
 
81
 
 
82
    "foreign" => \$foreign,
 
83
    "resolve-deps" => sub { $resolve_deps = 1; },
 
84
    "no-resolve-deps" => sub { $resolve_deps = 0; },
 
85
    "keep-debootstrap-dir" => \$keep_debootstrap_dir,
 
86
    "arch" => \$bootstrap_arch,
 
87
    "verbose" => \$verbose,
 
88
    "exclude=s" => \$exclude,
 
89
    "include=s" => \$include,
 
90
    "components=s" => \$components,
 
91
    "keyring=s" => \$keyring)
 
92
or usage_error("sbuild-createchroot", "Error parsing command-line options");
 
93
 
 
94
$include = add_items($include, "fakeroot", "build-essential");
 
95
 
 
96
usage_error("sbuild-createchroot",
 
97
            "Incorrect number of options") if (@ARGV <3 || @ARGV >4);
 
98
 
 
99
my $suite = $ARGV[0];
 
100
my $target = $ARGV[1];
 
101
my $mirror = $ARGV[2];
 
102
my $script = undef;
 
103
 
 
104
$script = $ARGV[3] if $#ARGV == 3;
 
105
 
 
106
if ($verbose) {
 
107
    print "I: SUITE: $suite\n";
 
108
    print "I: TARGET: $target\n";
 
109
    print "I: MIRROR: $mirror\n";
 
110
    print "I: SCRIPT: $script\n" if (defined($script));
 
111
}
 
112
 
 
113
my @args = ("--arch=$bootstrap_arch",
 
114
            "--variant=buildd");
 
115
push @args, "--verbose" if $verbose;
 
116
push @args, "--foreign" if $foreign;
 
117
push @args, "--keep-debootstrap-dir" if $keep_debootstrap_dir;
 
118
push @args, "--include=$include" if $include;
 
119
push @args, "--exclude=$exclude" if $exclude;
 
120
push @args, "--components=$components" if $components;
 
121
push @args, "--keyring=$keyring" if $keyring;
 
122
push @args, $resolve_deps ? "--resolve-deps" : "--no-resolve-deps";
 
123
push @args, "$suite", "$target", "$mirror";
 
124
push @args, "$script" if $script;
 
125
 
 
126
if ($verbose) {
 
127
    print "I: Running debootstrap " . join(' ',@args) . "\n";
 
128
}
 
129
 
 
130
# Run debootstrap with specified options.
 
131
!system("/usr/sbin/debootstrap", @args) or die "E: Error running debootstrap";
 
132
 
 
133
# Set up minimal /etc/hosts.
 
134
my $hosts = "${target}/etc/hosts";
 
135
open(HOSTS, ">$hosts")
 
136
    or die "Can't open $hosts for writing";
 
137
print HOSTS "127.0.0.1 $hostname localhost";
 
138
close HOSTS or die "Can't close $hosts";
 
139
 
 
140
# Display /etc/hosts.
 
141
print "I: Configured /etc/hosts:\n";
 
142
dump_file("$hosts");
 
143
 
 
144
# Set up minimal /etc/apt/sources.list
 
145
my $sources = "${target}/etc/apt/sources.list";
 
146
my $comps = join(' ',split(/,/,$components));
 
147
open(SOURCES, ">$sources")
 
148
    or die "Can't open $sources for writing";
 
149
print SOURCES "deb $mirror $suite $comps\n";
 
150
print SOURCES "deb-src $mirror $suite $comps\n";
 
151
close SOURCES or die "Can't close $sources";
 
152
 
 
153
# Display /etc/apt/sources.list.
 
154
print "I: Configured APT /etc/apt/sources.list:\n";
 
155
dump_file("${target}/etc/apt/sources.list");
 
156
print "I: Please add any additional APT sources to ${target}/etc/apt/sources.list\n";
 
157
 
 
158
# Write out schroot chroot configuration.
 
159
my $chrootname = "${suite}-${bootstrap_arch}-sbuild";
 
160
 
 
161
# TODO: Don't hardcode path
 
162
my $SCHROOT_CONF =
 
163
    new File::Temp( TEMPLATE => "$chrootname.XXXXXX",
 
164
                    DIR => "/etc/schroot/chroot.d",
 
165
                    UNLINK => 0)
 
166
    or die "Can't open schroot configuration file: $!\n";
 
167
 
 
168
print $SCHROOT_CONF <<"EOF";
 
169
[$chrootname]
64
170
type=directory
65
 
description=Debian $SUITE autobuilder
66
 
location=$TARGET
 
171
description=Debian $suite/$bootstrap_arch autobuilder
 
172
location=$target
67
173
priority=3
68
174
groups=root,sbuild
69
175
root-groups=root,sbuild
70
176
run-setup-scripts=true
71
177
run-exec-scripts=true
72
 
────────────────────────────────────────────────────────────────────────
73
 
I: Run the add_sbuild_user script to add new sbuild users.
74
178
EOF
75
 
 
76
 
exit 0
 
179
    # Needed to display file below.
 
180
    $SCHROOT_CONF->flush();
 
181
 
 
182
# Display schroot configuration.
 
183
print "I: schroot chroot configuration written to $SCHROOT_CONF.\n";
 
184
dump_file("$SCHROOT_CONF");
 
185
print "I: Please rename and modify this file as required.\n";
 
186
print "I: Successfully set up $suite chroot.\n";
 
187
print "I: Run sbuild-adduser to add new sbuild users.\n";
 
188
 
 
189
exit 0;