Here's an updated patch. This only contains the changes for saving an sbuild 
chroot to tarball now.

Changes for the update scripts are now in bug #590211.

On Saturday 17 October 2009 01:28:18 Andres Mejia wrote:
> Here are all patches again which address your concerns.
> 
> On Thursday 24 September 2009 18:04:05 Roger Leigh wrote:
> > On Sun, Sep 20, 2009 at 01:43:41PM -0400, Andres Mejia wrote:
> > > From: Andres Mejia <and...@andres-desktop.hsd1.va.comcast.net>
> > > Date: Sun, 20 Sep 2009 13:21:02 -0400
> > > Subject: [PATCH 3/5] Allow sbuild-update to support perform apt-get
> > > update, upgrade and distupgrade. This also allows sbuild-update to
> > > perform any two or all three commands at once, useful when using file
> > > type chroots.
> > > 
> > > ---
> > > 
> > >  bin/sbuild-update |  119
> > > 
> > > +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed,
> > > 110 insertions(+), 9 deletions(-)
> > > 
> > > diff --git a/bin/sbuild-update b/bin/sbuild-update
> > > index d6dac48..33dae2a 100755
> > > --- a/bin/sbuild-update
> > > +++ b/bin/sbuild-update
> > > @@ -21,19 +21,98 @@
> > > 
> > >  use strict;
> > >  use warnings;
> > > 
> > > +use Sbuild::ChrootSetup qw(update upgrade distupgrade);
> > > +
> > > +use Sbuild::Conf;
> > > +
> > > +BEGIN {
> > > +    use Exporter ();
> > > +    our (@ISA, @EXPORT);
> > > +
> > > +    @ISA = qw(Exporter Sbuild::Conf);
> > > +
> > > +    @EXPORT = qw();
> > > +}
> > > +
> > > +sub init_allowed_keys {
> > > +    my $self = shift;
> > > +
> > > +    $self->SUPER::init_allowed_keys();
> > > +
> > > +    my %update_keys = (
> > > + 'UPDATE'                                => {
> > > +     DEFAULT => 0
> > > + },
> > > + 'UPGRADE'                               => {
> > > +     DEFAULT => 0
> > > + },
> > > + 'DISTUPGRADE'                           => {
> > > +     DEFAULT => 0
> > > + },
> > > +    );
> > > +
> > > +    $self->set_allowed_keys(\%update_keys);
> > > +}
> > 
> > I think that this is fine.  I would, however, perhaps additionally
> > add configuration keys to sbuild conf immediately after this part
> > in order to allow sensible defaults to be set.  In this case, I
> > would suggest something along the lines of
> > 
> > $apt_update = 1;
> > $apt_upgrade = 0;
> > $apt_distupgrade = 0;
> > 
> > for backward compatibility and the principle of least surprise.
> > 
> > > + "uu" => sub {
> > > +     $self->set_conf('UPDATE', 1);
> > > +     $self->set_conf('UPGRADE', 1);
> > > + },
> > > + "ud" => sub {
> > > +     $self->set_conf('UPDATE', 1);
> > > +     $self->set_conf('DISTUPGRADE', 1);
> > 
> > I'm not totally enamoured by these abbreviations.  It should be
> > possible to simply use --update --distupgrade together.  If you
> > add short options in addition to the long options, -ud will
> > just work without this extra option (upgrade might need to be
> > "-g" making "-ug" the same as "--uu" above).
> > 
> > > From 1205711f9d813c60dca38802a352ed2d78f77836 Mon Sep 17 00:00:00 2001
> > > From: Andres Mejia <and...@andres-desktop.hsd1.va.comcast.net>
> > > Date: Sun, 20 Sep 2009 13:23:26 -0400
> > > Subject: [PATCH 4/5] Have sbuild-upgrade and sbuild-distupgrade run
> > > sbuild-update for their functions instead. diff --git
> > > a/bin/sbuild-distupgrade b/bin/sbuild-distupgrade
> > > +print "$0 is deprecated. Use sbuild-update --dist-upgrade directly
> > > instead.\n"; +system("/usr/bin/sbuild-update", "--dist-upgrade", @ARGV)
> > > == 0 or +    die "Exiting from sbuild-update with exit status $?";
> > 
> > Note: you must use exec() rather than system() here in order to get
> > the error status correctly returned to the shell.  You could also
> > return $? following the system() call, but IMO you should just
> > replace system with exec, and die with an error
> > "Can't run sbuild-update: $?" if it fails.
> > 
> > 
> > Regards,
> > Roger

-- 
Regards,
Andres Mejia
diff --git a/bin/sbuild-createchroot b/bin/sbuild-createchroot
index 985128c..21a5275 100755
--- a/bin/sbuild-createchroot
+++ b/bin/sbuild-createchroot
@@ -72,7 +72,13 @@ sub init_allowed_keys {
 	},
 	'SETUP_ONLY'				=> {
 	    DEFAULT => 0
-	}
+	},
+	'MAKE_SBUILD_TARBALL'				=> {
+	    DEFAULT => ''
+	},
+	'KEEP_SBUILDCHROOT_DIR'			=> {
+	    DEFAULT => 0
+	},
     );
 
     $self->set_allowed_keys(\%createchroot_keys);
@@ -125,6 +131,12 @@ sub set_options {
 	},
 	"setup-only" => sub {
 	    $self->set_conf('SETUP_ONLY', 1);
+	},
+	"make-sbuild-tarball=s" => sub {
+	    $self->set_conf('MAKE_SBUILD_TARBALL', $_[1]);
+	},
+	"keep-sbuildchroot-dir" => sub {
+	    $self->set_conf('KEEP_SBUILDCHROOT_DIR', 1);
 	});
 }
 
@@ -135,8 +147,9 @@ use Getopt::Long qw(:config no_ignore_case auto_abbrev gnu_getopt);
 use Sbuild qw(dump_file help_text version_text usage_error check_packages);
 use Sbuild::ChrootPlain;
 use Sbuild::Sysconfig;
-use File::Path qw(mkpath);
+use File::Path qw(mkpath rmtree);
 use File::Temp ();
+use File::Copy;
 use Cwd qw(abs_path);
 
 sub add_items ($@);
@@ -249,6 +262,31 @@ print "I: Please add any additional APT sources to ${target}/etc/apt/sources.lis
 # Write out schroot chroot configuration.
 my $chrootname = "${suite}-" . $conf->get('ARCH') . "-sbuild";
 
+# Determine the schroot chroot configuration to use.
+my $config_entry;
+my $arch = $conf->get('ARCH');
+if ($conf->get('MAKE_SBUILD_TARBALL')) {
+    my $tgz_file = $conf->get('MAKE_SBUILD_TARBALL');
+    $config_entry = <<"EOF";
+[$chrootname]
+type=file
+description=Debian $suite/$arch autobuilder
+file=$tgz_file
+priority=3
+groups=root,sbuild
+root-groups=root,sbuild
+EOF
+} else {
+    $config_entry = <<"EOF";
+[$chrootname]
+type=directory
+description=Debian $suite/$arch autobuilder
+directory=$target
+groups=root,sbuild
+root-groups=root,sbuild
+EOF
+}
+
 if (-d "/etc/schroot/chroot.d") {
     # TODO: Don't hardcode path
     my $SCHROOT_CONF =
@@ -257,15 +295,7 @@ if (-d "/etc/schroot/chroot.d") {
 			UNLINK => 0)
 	or die "Can't open schroot configuration file: $!\n";
 
-    my $arch = $conf->get('ARCH');
-    print $SCHROOT_CONF <<"EOF";
-[$chrootname]
-type=directory
-description=Debian $suite/$arch autobuilder
-directory=$target
-groups=root,sbuild
-root-groups=root,sbuild
-EOF
+    print $SCHROOT_CONF "$config_entry";
 
     my ($personality, $personality_message);
     # Detect whether personality might be needed.
@@ -312,14 +342,15 @@ if (-l $chrootlink) {
     $chrootlink = undef;
 }
 
-if (defined $chrootlink) {
+if ((defined $chrootlink) && (! $conf->get('MAKE_SBUILD_TARBALL'))) {
     if (symlink($target, $chrootlink)) {
 	print "I: sudo chroot configuration linked as $Sbuild::Sysconfig::paths{'SBUILD_SYSCONF_DIR'}/chroot/$chrootname.\n";
     } else {
 	print STDERR "E: Failed to symlink $target to $chrootlink: $!\n";
     }
 } else {
-    print "W: Failed to symlink $target to $chrootlink: file already exists\n";
+    print "W: Failed to symlink $target to $chrootlink: file already exists\n"
+	unless defined $conf->get('MAKE_SBUILD_TARBALL');
 }
 
 if ($conf->get('ARCH') eq $conf->get('HOST_ARCH')) {
@@ -353,6 +384,22 @@ if ($conf->get('ARCH') eq $conf->get('HOST_ARCH')) {
     print "I: Run \"sbuild-checkpackages --set\" to set reference package list.\n";
 }
 
+# This block makes the tarball chroot if one has been requested and delete
+# the sbuild chroot directory created, unless it's been requested to keep the
+# directory.
+if ($conf->get('MAKE_SBUILD_TARBALL')) {
+    my ($tmpfh, $tmpfile) = File::Temp->tempfile( "tgz.XXXXXX" );
+    system("/bin/tar", "-czf", "$tmpfile", "-C", "$target",
+	"./") == 0 or die "Could not create chroot tarball: $?\n";
+    move("$tmpfile", $conf->get('MAKE_SBUILD_TARBALL'));
+    if (! $conf->get('KEEP_SBUILDCHROOT_DIR')) {
+	rmtree("$target");
+	print "I: chroot $target has been removed.\n";
+    } else {
+	print "I: chroot $target has been kept.\n";
+    }
+}
+
 print "I: Successfully set up $suite chroot.\n";
 print "I: Run \"sbuild-adduser\" to add new sbuild users.\n";
 
diff --git a/man/sbuild-createchroot.8.in b/man/sbuild-createchroot.8.in
index cf80de0..283430e 100644
--- a/man/sbuild-createchroot.8.in
+++ b/man/sbuild-createchroot.8.in
@@ -29,6 +29,8 @@ sbuild\-createchroot \- create sbuild chroot
 .RB [ "\-\-components=\fIcomponent1[,component2,[componentn]]\fP" ]
 .RB [ "\-\-keyring=\fIkeyring-file\fP" ]
 .RB [ "\-\-setup\-only" ]
+.RB [ "\-\-make\-sbuild\-tarball=\fIFILE\fP" ]
+.RB [ "\-\-keep\-sbuildchroot\-dir" ]
 .B SUITE TARGET-DIRECTORY DEBIAN-MIRROR-URI
 .RB [ SCRIPT ]
 .PP
@@ -141,13 +143,34 @@ debootstrap script to run.  Not typically required.
 Don't run debootstrap.  Only perform the setup tasks on an already existing
 chroot.  This is useful for converting an existing chroot for use with sbuild
 which has already been created using a tool such as debootstrap.
+.TP
+.BR \-\-make\-sbuild\-tarball=\fIFILE\fP
+Create a bootstrapped file type chroot ready for use with sbuild and save it as
+\fIFILE\fP.
+.TP
+.BR \-\-keep\-sbuildchroot\-dir
+Don't delete the directory used for creating a file type chroot. This option
+does nothing if not creating a file type chroot.
 .SH EXAMPLES
-To create a sid (unstable) chroot in \fI/srv/chroot/unstable\fP using the
-\fIftp.uk.debian.org\fP Debian mirror:
+To create a plain type sid (unstable) chroot in \fI/srv/chroot/unstable\fP using
+the \fIftp.uk.debian.org\fP Debian mirror:
 .PP
 \f[CR]% \f[CB]sudo sbuild\-createchroot sid /srv/chroot/unstable \fP\fP\\
 .br
 \f[CB]    http://ftp.uk.debian.org/debian\fP\[CR]
+.PP
+To create a bootstrapped file type sid (unstable) chroot ready for use with
+sbuild and saved in \fI/var/cache/sbuild/sbuild.tar.gz\fP using the
+\fIftp.uk.debian.org\fP Debian mirror and using a temporary directory as the
+target:
+.PP
+\f[CR]% \f[CB]sudo sbuild\-createchroot \fP\fP\\
+.br
+    \-\-make\-sbuild\-tarball=/var/cache/sbuild/sbuild.tar.gz \fP\fP\\
+.br
+    sid `mktemp \-d` \fP\fP\\
+.br
+\f[CB]    http://ftp.uk.debian.org/debian\fP\[CR]
 .SH HISTORY
 sbuild\-createchroot was previously known as \fBbuildd.chroot\fP.
 buildd.chroot performed exactly the same tasks, but additionally created a

Reply via email to