On Sunday 20 September 2009 12:19:29 Roger Leigh wrote:
> On Thu, Sep 17, 2009 at 09:43:19PM -0400, Andres Mejia wrote:
> > Here's another patch to ensure symlinks are not installed when creating
> > file type chroots with sbuild-createchroot. Again, this should be applied
> > after all other patches are applied.
> >
> > I can also supply all patches again in the order they should be applied
> > if it's desired.
> 
> That would be really helpful, thanks.  Not having internet access at
> home yet means it's hard to keep track of things when you have to
> cart your git repos and saved mails around on a USB key.
> 
> Thanks,
> Roger
> 

Ok. Here are all patches again for supporting building chroot tarballs, in 
order, and updated to be applied straight into the master branch.

-- 
Regards,
Andres
From 23ff8de5c98a331ab6eafb525e0a23586eee0a3c Mon Sep 17 00:00:00 2001
From: Andres Mejia <[email protected]>
Date: Sun, 20 Sep 2009 13:18:02 -0400
Subject: [PATCH 1/5] Allow sbuild-createchroot to support making a tarball of a chroot.

---
 bin/sbuild-createchroot |   77 ++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 63 insertions(+), 14 deletions(-)

diff --git a/bin/sbuild-createchroot b/bin/sbuild-createchroot
index a255149..8c0ba3f 100755
--- a/bin/sbuild-createchroot
+++ b/bin/sbuild-createchroot
@@ -72,7 +72,13 @@ sub init_allowed_keys {
 	},
 	'SETUP_ONLY'				=> {
 	    DEFAULT => 0
-	}
+	},
+	'MAKE_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-tarball=s" => sub {
+	    $self->set_conf('MAKE_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;
 
 sub add_items ($@);
 sub makedir ($$);
@@ -245,16 +258,24 @@ 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";
 
-if (-d "/etc/schroot/chroot.d") {
-    # TODO: Don't hardcode path
-    my $SCHROOT_CONF =
-	new File::Temp( TEMPLATE => "$chrootname.XXXXXX",
-			DIR => "/etc/schroot/chroot.d",
-			UNLINK => 0)
-	or die "Can't open schroot configuration file: $!\n";
-
-    my $arch = $conf->get('ARCH');
-    print $SCHROOT_CONF <<"EOF";
+# Determine the schroot chroot configuration to use.
+my $config_entry;
+my $arch = $conf->get('ARCH');
+if ($conf->get('MAKE_TARBALL')) {
+    my $tgz_file = $conf->get('MAKE_TARBALL');
+    $config_entry = <<"EOF";
+[$chrootname]
+type=file
+description=Debian $suite/$arch autobuilder
+file=$tgz_file
+priority=3
+groups=root,sbuild
+root-groups=root,sbuild
+run-setup-scripts=true
+run-exec-scripts=true
+EOF
+} else {
+    $config_entry = <<"EOF";
 [$chrootname]
 type=directory
 description=Debian $suite/$arch autobuilder
@@ -265,6 +286,17 @@ root-groups=root,sbuild
 run-setup-scripts=true
 run-exec-scripts=true
 EOF
+}
+
+if (-d "/etc/schroot/chroot.d") {
+    # TODO: Don't hardcode path
+    my $SCHROOT_CONF =
+	new File::Temp( TEMPLATE => "$chrootname.XXXXXX",
+			DIR => "/etc/schroot/chroot.d",
+			UNLINK => 0)
+	or die "Can't open schroot configuration file: $!\n";
+
+    print $SCHROOT_CONF "$config_entry";
 
     my ($personality, $personality_message);
     # Detect whether personality might be needed.
@@ -310,14 +342,15 @@ if (-l $chrootlink) {
     print STDERR "E: Can't remove $chrootlink: not a symbolic link\n";
 }
 
-if (! -f $chrootlink) {
+if ((! -f $chrootlink) && (! $conf->get('MAKE_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: \n"
+    print "W: Failed to symlink $target to $chrootlink: \n" unless
+	defined $conf->get('MAKE_TARBALL');
 }
 
 if ($conf->get('ARCH') eq $conf->get('HOST_ARCH')) {
@@ -351,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_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_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";
 
-- 
1.6.4.3

From a429d0b42c73127e96f5d49d9ea307a343a3b5e9 Mon Sep 17 00:00:00 2001
From: Andres Mejia <[email protected]>
Date: Sun, 20 Sep 2009 13:19:32 -0400
Subject: [PATCH 2/5] Update man page for sbuild-createchroot.

---
 man/sbuild-createchroot.8.in |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/man/sbuild-createchroot.8.in b/man/sbuild-createchroot.8.in
index 7d0e32f..d8a3bdd 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\-tarball=\fIFILE\fP ]
+.RB [ "\-\-keep\-sbuildchroot\-dir" ]
 .B SUITE TARGET-DIRECTORY DEBIAN-MIRROR-URI
 .RB [ SCRIPT ]
 .SH DESCRIPTION
@@ -104,6 +106,13 @@ Download signatures for retrieved \fIRelease\fP files and check them against
 \fIkeyring-file\fP.  By default \fI/etc/apt/trusted.gpg\fP is used.  Set to an
 empty string to disable signature checking.
 .TP
+.BR \-\-make\-tarball=\fIFILE\fP
+Create a file type chroot 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.
+.TP
 .B SUITE
 The distribution to bootstrap (e.g. \[oq]sarge\[cq], \[oq]etch\[cq],
 \[oq]lenny\[cq], \[oq]sid\[cq]).  A complete list may be found in
@@ -126,12 +135,24 @@ 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.
 .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 file type sid (unstable) chroot 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\-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
-- 
1.6.4.3

From 954c12b6d7982c1d4de74b8c2f17f3b2a8e4fcd6 Mon Sep 17 00:00:00 2001
From: Andres Mejia <[email protected]>
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);
+
+package Conf;
+
+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);
+}
+
+package Options;
+
+use Sbuild::OptionsBase;
+use Sbuild::Conf;
+
+BEGIN {
+    use Exporter ();
+    our (@ISA, @EXPORT);
+
+    @ISA = qw(Exporter Sbuild::OptionsBase);
+
+    @EXPORT = qw();
+}
+
+sub set_options {
+    my $self = shift;
+
+    $self->add_options(
+	"update" => sub {
+	    $self->set_conf('UPDATE', 1);
+	},
+	"upgrade" => sub {
+	    $self->set_conf('UPGRADE', 1);
+	},
+	"dist-upgrade" => sub {
+	    $self->set_conf('DISTUPGRADE', 1);
+	},
+	"uu" => sub {
+	    $self->set_conf('UPDATE', 1);
+	    $self->set_conf('UPGRADE', 1);
+	},
+	"ud" => sub {
+	    $self->set_conf('UPDATE', 1);
+	    $self->set_conf('DISTUPGRADE', 1);
+	});
+}
+
+package main;
+
 use Getopt::Long;
 use Sbuild qw(help_text version_text usage_error);
 use Sbuild::Utility qw(setup cleanup);
-use Sbuild::ChrootSetup qw(update);
-use Sbuild::Conf;
-use Sbuild::OptionsBase;
 
-my $conf = Sbuild::Conf->new();
+my $conf = Conf->new();
 exit 1 if !defined($conf);
-my $options = Sbuild::OptionsBase->new($conf, "sbuild-update", "1");
+my $options = Options->new($conf, "sbuild-update", "1");
 exit 1 if !defined($options);
 $conf->check_group_membership();
 
+if ( ! $conf->get('UPDATE') && ! $conf->get('UPGRADE') &&
+    ! $conf->get('DISTUPGRADE') ) {
+    my $msg = "$0 will perform apt-get command 'update' now, however this ";
+    $msg .= "may change at a later revision.\n";
+    print "$msg";
+    $conf->set('UPDATE', 1);
+}
+
 usage_error("sbuild-update", "Incorrect number of options") if (@ARGV < 1);
 
 foreach (@ARGV) {
@@ -42,12 +121,34 @@ foreach (@ARGV) {
 
     my $session = setup($ARGV[0], $conf) or die "Chroot setup failed";
 
-    my $status = update($session, $conf);
-    $status >>= 8;
+    if ($conf->get('UPDATE')) {
+	print "Performing update.\n";
+	my $status = update($session, $conf);
+	$status >>= 8;
+	if ($status) {
+	    die "Exiting from update with status $status.\n";
+	}
+    }
 
-    cleanup($conf);
+    if ($conf->get('UPGRADE')) {
+	print "Performing upgrade.\n";
+	my $status = upgrade($session, $conf);
+	$status >>= 8;
+	if ($status) {
+	    die "Exiting from upgrade with status $status.\n";
+	}
+    }
 
-    exit $status if ($status);
+    if ($conf->get('DISTUPGRADE')) {
+	print "Performing dist-upgrade.\n";
+	my $status = distupgrade($session, $conf);
+	$status >>= 8;
+	if ($status) {
+	    die "Exiting from distupgrade with status $status.\n";
+	}
+    }
+
+    cleanup($conf);
 }
 
 exit 0;
-- 
1.6.4.3

From 1205711f9d813c60dca38802a352ed2d78f77836 Mon Sep 17 00:00:00 2001
From: Andres Mejia <[email protected]>
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.

---
 bin/sbuild-distupgrade |   33 +++------------------------------
 bin/sbuild-upgrade     |   33 +++------------------------------
 2 files changed, 6 insertions(+), 60 deletions(-)

diff --git a/bin/sbuild-distupgrade b/bin/sbuild-distupgrade
index 5e8cad7..183aa7d 100755
--- a/bin/sbuild-distupgrade
+++ b/bin/sbuild-distupgrade
@@ -21,33 +21,6 @@
 use strict;
 use warnings;
 
-use Getopt::Long;
-use Sbuild qw(help_text version_text usage_error);
-use Sbuild::Utility qw(setup cleanup);
-use Sbuild::ChrootSetup qw(distupgrade);
-use Sbuild::Conf;
-use Sbuild::OptionsBase;
-
-my $conf = Sbuild::Conf->new();
-exit 1 if !defined($conf);
-my $options = Sbuild::OptionsBase->new($conf, "sbuild-distupgrade", "1");
-exit 1 if !defined($options);
-$conf->check_group_membership();
-
-usage_error("sbuild-distupgrade", "Incorrect number of options") if (@ARGV < 1);
-
-foreach (@ARGV) {
-
-    my $chroot = Sbuild::Utility::get_dist($_);
-
-    my $session = setup($_, $conf) or die "Chroot setup failed for $chroot chroot";
-
-    my $status = distupgrade($session, $conf);
-    $status >>= 8;
-
-    cleanup($conf);
-
-    exit $status if ($status);
-}
-
-exit 0;
+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 $?";
diff --git a/bin/sbuild-upgrade b/bin/sbuild-upgrade
index 9017ad7..7de5db8 100755
--- a/bin/sbuild-upgrade
+++ b/bin/sbuild-upgrade
@@ -21,33 +21,6 @@
 use strict;
 use warnings;
 
-use Getopt::Long;
-use Sbuild qw(help_text version_text usage_error);
-use Sbuild::Utility qw(setup cleanup);
-use Sbuild::ChrootSetup qw(upgrade);
-use Sbuild::Conf;
-use Sbuild::OptionsBase;
-
-my $conf = Sbuild::Conf->new();
-exit 1 if !defined($conf);
-my $options = Sbuild::OptionsBase->new($conf, "sbuild-upgrade", "1");
-exit 1 if !defined($options);
-$conf->check_group_membership();
-
-usage_error("sbuild-upgrade", "Incorrect number of options") if (@ARGV < 1);
-
-foreach (@ARGV) {
-
-    my $chroot = Sbuild::Utility::get_dist($_);
-
-    my $session = setup($_, $conf) or die "Chroot setup failed for $chroot chroot";
-
-    my $status = upgrade($session, $conf);
-    $status >>= 8;
-
-    cleanup($conf);
-
-    exit $status if ($status);
-}
-
-exit 0;
+print "$0 is deprecated. Use sbuild-update --upgrade directly instead.\n";
+system("/usr/bin/sbuild-update", "--upgrade", @ARGV) == 0 or
+    die "Exiting from sbuild-update with exit status $?";
-- 
1.6.4.3

From 23a824df4e85db51c4f7dc84f0dae92f1e136802 Mon Sep 17 00:00:00 2001
From: Andres Mejia <[email protected]>
Date: Sun, 20 Sep 2009 13:24:58 -0400
Subject: [PATCH 5/5] Update man page for sbuild-update.

---
 man/sbuild-update.1.in |   53 ++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 42 insertions(+), 11 deletions(-)

diff --git a/man/sbuild-update.1.in b/man/sbuild-update.1.in
index b0af9f3..805a919 100644
--- a/man/sbuild-update.1.in
+++ b/man/sbuild-update.1.in
@@ -18,18 +18,26 @@
 sbuild\-update \- update and upgrade an sbuild chroot with apt-get
 .SH SYNOPSIS
 .BR sbuild\-update
-.RB [ \-h \[or] \-\-help " \[or] " \-V \[or] \-\-version ]
+.BR [ \-h \[or] \-\-help ] " " [ \-V \[or] \-\-version ]
+\-\-update \-\-upgrade \-\-dist\-upgrade \-\-uu \-\-ud
 .BR CHROOT1 " [" CHROOT2 " [" CHROOT\f[BI]n\fP... ]]
-.BR sbuild\-upgrade
-.RB [ \-h \[or] \-\-help " \[or] " \-V \[or] \-\-version ]
+.br
+.BR (DEPRECATED) " " sbuild\-upgrade
+.BR [ \-h \[or] \-\-help ] " " [ \-V \[or] \-\-version ]
 .BR CHROOT1 " [" CHROOT2 " [" CHROOT\f[BI]n\fP... ]]
-.BR sbuild\-distupdate
-.RB [ \-h \[or] \-\-help " \[or] " \-V \[or] \-\-version ]
+.br
+.BR (DEPRECATED) " " sbuild\-distupgrade
+.BR [ \-h \[or] \-\-help ] " " [ \-V \[or] \-\-version ]
 .BR CHROOT1 " [" CHROOT2 " [" CHROOT\f[BI]n\fP... ]]
 .SH DESCRIPTION
-\fBsbuild\-update\fR runs \f[CB]apt\-get update\fP inside the specified chroot.
-\fBsbuild\-upgrade\fR and \fBsbuild\-distupgrade\fR run \f[CB]apt\-get
-upgrade\fP and \f[CB]apt\-get dist-upgrade\fP, respectively.
+\fBsbuild\-update\fR runs \f[CB]apt\-get\fP inside the specified chroot
+performing \f[CB]update\fP, \f[CB]upgrade\fP, and/or \f[CB]dist\-upgrade\fP
+depending on the options specified on the command line.
+.PP
+\fBsbuild\-upgrade\fR and \fBsbuild\-distupgrade\fR are deprecated. They now
+simply run \fBsbuild\-update\fR with the appropriate option (either
+\f[CB]\-\-upgrade\fP or \f[CB]\-\-dist\-upgrade\fP) along with whatever
+arguments were passed in the scripts.
 .SH OPTIONS
 .SS Actions
 .TP
@@ -38,6 +46,22 @@ Display this manual.
 .TP
 .BR \-V ", " \-\-version
 Print version information.
+.TP
+.BR \-\-update
+Perform an \f[CB]apt\-get update\fP.
+.TP
+.BR \-\-upgrade
+Perform an \f[CB]apt\-get upgrade\fP.
+.TP
+.BR \-\-dist\-upgrade
+Perform an \f[CB]apt\-get dist\-upgrade\fP.
+.TP
+.BR \-\-uu
+Shorthand to perform an \f[CB]apt\-get update\fP and \f[CB]apt\-get upgrade\fP.
+.TP
+.BR \-\-ud
+Shorthand to perform an \f[CB]apt\-get update\fP and \f[CB]apt\-get
+dist\-upgrade\fP.
 .SS Chroot selection
 .TP
 .B CHROOT
@@ -48,8 +72,16 @@ and \[oq]experimental\[cq], respectively.
 .SH EXAMPLES
 To update the \fIunstable\fP chroot:
 .PP
-\f[CR]% \f[CB]sbuild\-update unstable\fP\fP
-.br
+\f[CR]% \f[CB]sbuild\-update \-\-update unstable\fP\fP
+.PP
+To upgrade the \fIunstable\fP chroot:
+.PP
+\f[CR]% \f[CB]sbuild\-update \-\-upgrade unstable\fP\fP
+.PP
+To use the shorthand \f[CB]\-\-ud\fP to update and dist-upgrade the
+\fIunstable\fP chroot:
+.PP
+\f[CR]% \f[CB]sbuild\-update \-\-ud unstable\fP\fP
 .SH AUTHORS
 .nf
 Roger Leigh.
@@ -61,7 +93,6 @@ Copyright \[co] 2006\[en]2009 Roger Leigh <[email protected]>.
 .SH "SEE ALSO"
 .BR sbuild (1),
 .BR sbuild\-apt (1),
-.BR sbuild\-upgrade (1).
 .\"#
 .\"# The following sets edit modes for GNU EMACS
 .\"# Local Variables:
-- 
1.6.4.3

Reply via email to