22
22
#######################################################################
26
if [ $(id -u) != 0 ]; then
27
echo "You need to run this command as root"
32
echo "$0 <suite> <target-dir> <debian-mirror-url>"
33
echo " E.g. $0 sarge /path/to/chroot http://http.us.debian.org/debian"
41
/usr/sbin/debootstrap \
43
--include=fakeroot,build-essential \
44
"$SUITE" "$TARGET" "$MIRROR"
46
cat <<EOF >"$TARGET/etc/apt/sources.list"
48
deb $MIRROR/ $SUITE main contrib non-free
49
deb-src $MIRROR/ $SUITE main contrib non-free
53
echo "I: Configured APT sources.list:"
54
echo "────────────────────────────────────────────────────────────────────────"
55
cat "$TARGET/etc/apt/sources.list"
56
echo "────────────────────────────────────────────────────────────────────────"
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
────────────────────────────────────────────────────────────────────────
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);
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.
52
# Only add if not already used, to eliminate duplicates.
53
foreach (split (/,/,$items)) {
54
$ret .= "$_," if (!defined($values{$_}));
57
# Remove trailing comma.
63
our $bootstrap_arch = $arch;
67
our $components = 'main';
69
our $resolve_deps = 1;
70
our $keep_debootstrap_dir = 0;
73
# Default to using the system keyring
74
if (!defined($keyring) && -f '/etc/apt/trusted.gpg') {
75
$keyring='/etc/apt/trusted.gpg';
79
"h|help" => sub { help_text("8", "sbuild-createchroot"); },
80
"V|version" => sub {version_text("sbuild-createchroot"); },
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");
94
$include = add_items($include, "fakeroot", "build-essential");
96
usage_error("sbuild-createchroot",
97
"Incorrect number of options") if (@ARGV <3 || @ARGV >4);
100
my $target = $ARGV[1];
101
my $mirror = $ARGV[2];
104
$script = $ARGV[3] if $#ARGV == 3;
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));
113
my @args = ("--arch=$bootstrap_arch",
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;
127
print "I: Running debootstrap " . join(' ',@args) . "\n";
130
# Run debootstrap with specified options.
131
!system("/usr/sbin/debootstrap", @args) or die "E: Error running debootstrap";
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";
140
# Display /etc/hosts.
141
print "I: Configured /etc/hosts:\n";
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";
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";
158
# Write out schroot chroot configuration.
159
my $chrootname = "${suite}-${bootstrap_arch}-sbuild";
161
# TODO: Don't hardcode path
163
new File::Temp( TEMPLATE => "$chrootname.XXXXXX",
164
DIR => "/etc/schroot/chroot.d",
166
or die "Can't open schroot configuration file: $!\n";
168
print $SCHROOT_CONF <<"EOF";
65
description=Debian $SUITE autobuilder
171
description=Debian $suite/$bootstrap_arch autobuilder
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.
179
# Needed to display file below.
180
$SCHROOT_CONF->flush();
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";