On Mon, 7 Sep 2009 16:38:58 +0100
Wookey <[email protected]> wrote:

> removes apt-preferences warning,
> defaults arch to build arch if not set

OK.

> errors out if not aptsources or sources URLs are given

I don't think we need to die here, we can make a sensible assumption
and continue.

> errors out if initial update fails

Should be rare with the other changes but accepted anyway.

The manpage change will have to be postponed - the package is in a
string freeze for manpage translation. (That is a larger task than
usual translation so it's not a problem to do another call for the next
release as the support code will be much improved by then. i.e. I'm
using Americo as a guinea pig, thanks Americo. :-) )

The example configuration file is a good idea. Thanks.

>  print "$progname $ourversion using $file\n";
> +
> +# Set some sensible defaults
>  $host = `dpkg-architecture -qDEB_BUILD_ARCH`;
>  chomp ($host);
> +if (not defined $arch) 
> +{
> +     $arch = $host;
> +     print "Defaulting architecture to native: $arch\n;"
> +}
>  $foreign++ if ($host ne $arch);

Accepted.

> +
> +unless (keys %sources and defined @aptsources)

defined is misleading here, needs to be omitted.

The alternative is to put into a scalar context:

if (scalar @aptsources == 0)
(this is an explicit expansion of the shorthand you've used but
'defined' is wrong for an array.)

(Putting @foo into scalar context returns the number of entries in the
array.)

> +     # For a native multistrap could get some defaults out 
> +     # of /etc/apt/ config in this case?

Better than that, if no apt sources are defined, collate all the
existing apt sources and use them. I don't see a need to do this for
native and not do it on not-native - we can't tell from the apt sources
whether they support the requested architecture anyway.

I've borrowed a subroutine from apt-cross - no point making multistrap
depend on apt-cross or libcache-apt-perl. I might move the routine into
a different module eventually and use the same module in both. Depends
on what happens within apt-cross more generally.

> +system ("mkdir -p ${dir}etc/apt/preferences.d/");

Accepted.

> -system ("apt-get $config_str update");
> +print "Getting packages lists:apt-get $config_str update\n";
> +$retval = system ("apt-get $config_str update");
> +die ("apt update failed. Exit value: ".($retval/256)."\n")
> +     if ($retval != 0);

Accepted.

Revised patch attached (using 'svn diff')

-- 


Neil Williams
=============
http://www.data-freedom.org/
http://www.linux.codehelp.co.uk/
http://e-mail.is-not-s.ms/

Index: debian/multistrap.install
===================================================================
--- debian/multistrap.install	(revision 6616)
+++ debian/multistrap.install	(working copy)
@@ -1,4 +1,5 @@
 em_multistrap ./usr/sbin/
 multistrap ./usr/sbin/
 doc/multistrap/man/* ./usr/share/man/
+examples/multistrap-example.conf ./usr/share/doc/multistrap/examples/
 bash/multistrap ./etc/bash_completion.d/
Index: em_multistrap
===================================================================
--- em_multistrap	(revision 6598)
+++ em_multistrap	(working copy)
@@ -26,9 +26,9 @@
  $dir $include $arch $foreign $suite $url $unpack $sourcedir
  @e $sourcesname $libdir $dpkgdir @debootstrap %suites $mirror $etcdir
  $repo @dirs @touch %sources $section %keys $host $key $value $type
- $file $config $tidy $noauth $keyring %keyrings /;
+ $file $config $tidy $noauth $keyring %keyrings $deflist /;
 $progname = basename($0);
-$ourversion = "0.0.6";
+$ourversion = "0.0.7";
 $unpack = "true";
 
 while( @ARGV ) {
@@ -112,9 +112,30 @@
 	}
 }
 print "$progname $ourversion using $file\n";
+
+# Set some sensible defaults
 $host = `dpkg-architecture -qDEB_BUILD_ARCH`;
 chomp ($host);
+if (not defined $arch) 
+{
+	$arch = $host;
+	print "Defaulting architecture to native: $arch\n;"
+}
+else
+{
+	print "Using foreign architecture: $arch\n;"
+}
 $foreign++ if ($host ne $arch);
+
+unless (keys %sources and @aptsources)
+{
+	my $msg = "No sources defined for a foreign multistrap\n".
+	"Using your existing apt sources. To use different sources,\n".
+	"and list them with aptsources= in '$file'.";
+	warn ("$progname: $msg\n");
+	$deflist = prepare_sources_list();
+}
+
 print "$progname building '$arch' multistrap on '$host'\n";
 $cachedir = "var/cache/apt/"; # archives
 $libdir = "var/lib/apt/";     # lists
@@ -122,10 +143,13 @@
 $dpkgdir = "var/lib/dpkg/";   # state
 
 mkdir ("$dir") if (not -d "$dir");
-system ("mkdir -p ${dir}${cachedir}");
-system ("mkdir -p ${dir}${libdir}");
-system ("mkdir -p ${dir}${dpkgdir}");
-system ("mkdir -p ${dir}etc/apt/sources.list.d/");
+system ("mkdir -p ${dir}${cachedir}") if (not -d "${dir}${cachedir}");
+system ("mkdir -p ${dir}${libdir}") if (not -d "${dir}${libdir}");
+system ("mkdir -p ${dir}${dpkgdir}") if (not -d "${dir}${dpkgdir}");
+system ("mkdir -p ${dir}etc/apt/sources.list.d/")
+	if (not -d "${dir}etc/apt/sources.list.d/");
+system ("mkdir -p ${dir}etc/apt/preferences.d/")
+	if (not -d "${dir}etc/apt/preferences.d/");
 @dirs = qw/ alternatives info parts updates/;
 @touch = qw/ diversions statoverride status lock/;
 foreach my $dpkgd (@dirs) {
@@ -173,10 +197,17 @@
 }
 foreach my $aptsrc (@aptsources)
 {
-	if (-d "${dir}etc/apt/")
+	if (defined $deflist)
 	{
 		open (SOURCES, ">>${dir}etc/apt/sources.list.d/multistrap.sources.list") 
 			or die "Cannot open sources list $!";
+		print SOURCES $deflist;
+		close SOURCES;
+	}
+	elsif (-d "${dir}etc/apt/")
+	{
+		open (SOURCES, ">>${dir}etc/apt/sources.list.d/multistrap.sources.list") 
+			or die "Cannot open sources list $!";
 		$mirror = $sources{$aptsrc};
 		$suite = $suites{$aptsrc};
 		print SOURCES<<END;
@@ -214,9 +245,12 @@
 $sourcesname = "sources.list.d/multistrap.sources.list";
 $config_str .= " -o Dir::Etc::SourceList=${dir}${etcdir}$sourcesname";
 $config_str .= " -o Dir::State=${dir}${libdir}";
-$config_str .= " -o Dir::State::Status=${dir}${dpkgdir}/status";
+$config_str .= " -o Dir::State::Status=${dir}${dpkgdir}status";
 $config_str .= " -o Dir::Cache=${dir}${cachedir}";
-system ("apt-get $config_str update");
+print "Getting packages lists:apt-get $config_str update\n";
+$retval = system ("apt-get $config_str update");
+die ("apt update failed. Exit value: ".($retval/256)."\n")
+	if ($retval != 0);
 $str = join (' ', values %packages) . " ";
 chomp($str);
 $str .= join (' ', values %keyrings) . " "; 
@@ -439,6 +473,34 @@
 	return \...@debs;
 }
 
+# inherited from apt-cross
+sub prepare_sources_list
+{
+	my @source_list=();
+	# collate all available/configured sources into one list
+	if (-e "/etc/apt/sources.list") {
+		open (SOURCES, "/etc/apt/sources.list") or die "cannot open apt sources list. $!";
+		@source_list = <SOURCES>;
+		close (SOURCES);
+	}
+	if (-d "/etc/apt/sources.list.d/") {
+		opendir (FILES, "/etc/apt/sources.list.d/")
+			|| die "cannot open apt sources.list directory $!";
+		my @files = grep(!/^\.\.?$/, readdir FILES);
+		foreach my $f (@files) {
+			next if ($f =~ /\.ucf-old$/);
+			open (SOURCES, "/etc/apt/sources.list.d/$f") or
+				die "cannot open /etc/apt/sources.list.d/$f $!";
+			while(<SOURCES>) {
+				push @source_list, $_;
+			}
+			close (SOURCES);
+		}
+		closedir (FILES);
+	}
+	return \...@source_list;
+}
+
 sub usageversion {
 	print(STDERR <<END)
 $progname version $ourversion
Index: examples/multistrap-example.conf
===================================================================
--- examples/multistrap-example.conf	(revision 0)
+++ examples/multistrap-example.conf	(revision 0)
@@ -0,0 +1,25 @@
+# Example multistrap configuration file
+# to create a plain lenny debootstrap for amd64
+
+[General]
+arch=amd64
+directory=/tmp/multistrap/
+# same as --tidy-up option if set to true
+cleanup=true
+# same as --no-auth option if set to true
+# keyring packages listed in each debootstrap will
+# still be installed.
+noauth=false
+# extract all downloaded archives (default is true)
+unpack=true
+# the order of sections is not important.
+# the debootstrap option determines which repository
+# is used to calculate the list of Priority: required packages.
+debootstrap=Debian
+aptsources=Debian
+
+[Debian]      
+packages=      
+source=http://ftp.uk.debian.org/debian      
+keyring=debian-archive-keyring      
+suite=lenny 

Attachment: pgpZ9JbGFmXwt.pgp
Description: PGP signature

Reply via email to