On Tue, 6 Jan 2015 12:59:54 +0000 Neil Williams <codeh...@debian.org> wrote:
> On Tue, 06 Jan 2015 13:14:44 +0100
> Johannes Schauer <j.scha...@email.de> wrote:
>
> > multistrap sets the Dir::Etc apt configuration option on the command
> > line.
> >
> > But this has no effect because the config files are read before the
> > commandline is. Thus, apt run by multistrap will parse the host
> > system's apt configuration first.
> >
> > To prevent this, the APT_CONFIG environment variable can be used and
> > pointed at a custom apt configuration in the target directory.
> >
> > Thanks!
>
> This likely explains a number of hard to reproduce bugs which have been
> seen with multistrap in the past (unless apt has recently changed
> behaviour in this regard).

I was bitten by this bug today, and would quite like to see it fixed;
here's a patch that seems to do the right thing, but has been tested
only lightly (this is pretty much the minimal patch that will do the
job, let me know if you prefer doing it another way and I'll see what
I can come up with) If there's anything else I can do to help this bug
get fixed, please let me know.

Thanks!

diff -ur multistrap-2.2.0/multistrap multistrap-2.2.0-hacked/multistrap
--- multistrap-2.2.0/multistrap    2013-07-27 14:56:54.000000000 +0000
+++ multistrap-2.2.0-hacked/multistrap    2015-04-20 16:13:58.860990485 +0000
@@ -36,7 +36,7 @@
  $explicit_suite $allow_recommends %omitdebsrc @dsclist @sectoutput
  %flatfile %important $addimportant @debconf $hookdir %hooks
  $warn_count $use_shortcut @foreignarches $olddpkg $ignorenative
- %foreignpkgs $markauto $default_release /;
+ %foreignpkgs $markauto $default_release $pre_config_str/;

 setlocale(LC_MESSAGES, "");
 textdomain("multistrap");
@@ -329,6 +329,19 @@
         die (_g("Secure Apt handling failed - try without
authentication.")."\n");
     }
 }
+
+$pre_config_str = '';
+$pre_config_str .= "Dir::Etc \"${dir}${etcdir}\";\n";
+$pre_config_str .= "Dir::Etc::Parts \"${dir}${etcdir}apt.conf.d/\";\n";
+$pre_config_str .= "Dir::Etc::PreferencesParts
\"${dir}${etcdir}preferences.d/\";\n";
+
+my $tmp_apt_conf = `mktemp -t multistrap.XXXXXX`;
+chomp ($tmp_apt_conf);
+
+open CONFIG, ">$tmp_apt_conf";
+print CONFIG $pre_config_str;
+close CONFIG;
+
 $config_str = '';
 $config_str .= " -o Apt::Architecture=$arch";
 $config_str .= " -o Dir::Etc::TrustedParts=${dir}${etcdir}trusted.gpg.d";
@@ -351,8 +364,12 @@
 $config_str .= " -o Dir::State=${dir}${libdir}";
 $config_str .= " -o Dir::State::Status=${dir}${dpkgdir}status";
 $config_str .= " -o Dir::Cache=${dir}${cachedir}";
-printf (_g("Getting package lists: apt-get %s update\n"), $config_str);
-$retval = system ("apt-get $config_str update");
+
+my $apt_get = "APT_CONFIG=\"$tmp_apt_conf\" apt-get $config_str";
+my $apt_mark = "APT_CONFIG=\"$tmp_apt_conf\" apt-mark $config_str";
+printf (_g("Getting package lists: %s update\n"), $apt_get);
+
+$retval = system ("$apt_get update");
 $retval >>= 8;
 die (sprintf (_g("apt update failed. Exit value: %d\n"), $retval))
     if ($retval != 0);
@@ -397,9 +414,9 @@
 @s = split (/ /, $str);
 uniq_sort (\@s);
 $str = join (' ', @s);
-print "apt-get -y $config_str install $str\n";
+print "$apt_get -y install $str\n";
 $retval = 0;
-$retval = system ("apt-get -y $config_str install $str");
+$retval = system ("$apt_get -y install $str");
 $retval >>= 8;
 die (sprintf (_g("apt download failed. Exit value: %d\n"),$retval))
     if ($retval != 0);
@@ -425,7 +442,7 @@
 &add_extra_packages;
 system ("cp $configsh $dir/") if ((defined $configsh) and (-f $configsh));
 &handle_source_packages;
-(not defined $tidy) ? system ("apt-get $config_str update") : &tidy_apt;
+(not defined $tidy) ? system ("$apt_get update") : &tidy_apt;
 &guard_lib64($dir);

 # cleanly separate the bootstrap sources from the final apt sources.
@@ -470,9 +487,10 @@
     }
 }
 # altered the sources, so get apt to update.
-(not defined $tidy) ? system ("apt-get $config_str update") : &tidy_apt;
+(not defined $tidy) ? system ("$apt_get update") : &tidy_apt;
 # run second set of hooks
 &run_completion_hooks(sort @{$hooks{'A'}}) if (defined ($hooks{'A'}));
+unlink $tmp_apt_conf;
 if (not defined $warn_count) {
     printf (_g("\nMultistrap system installed successfully in %s.\n"), $dir);
 } else {
@@ -515,8 +533,8 @@
 sub add_extra_packages {
     if (scalar @extrapkgs > 0) {
         $str = join (' ', @extrapkgs);
-        print "apt-get -y $config_str install $str\n";
-        system ("apt-get -y $config_str install $str");
+        print "$apt_get -y install $str\n";
+        system ("$apt_get -y install $str");
         &force_unpack (@extrapkgs) if ($unpack eq "true");
         system ("touch ${dir}${libdir}lists/lock");
         &native if (not defined ($foreign));
@@ -537,7 +555,7 @@
     my @auto = grep {my $pkg = $_; ! grep /$pkg/, @manual} @all;
     printf(ngettext ("Found %d package to mark.\n",
         "Found %d packages to mark.\n", scalar @auto), scalar @auto);
-    system ("apt-mark $config_str auto " . join (" ", sort @auto)) if
(scalar @auto > 0);
+    system ("$apt_mark auto " . join (" ", sort @auto)) if (scalar @auto > 0);
     printf (_g("Marking automatically installed packages completed.\n"));
 }

@@ -889,9 +907,9 @@
     my $olddir = getcwd();
     chdir ($sourcedir);
     if (scalar @dsclist > 0) {
-        print "apt-get -d $config_str source " . join (" ", @dsclist) . "\n";
+        print "$apt_get -d source " . join (" ", @dsclist) . "\n";
         foreach my $srcpkg (@dsclist) {
-            system ("apt-get -d $config_str source $srcpkg");
+            system ("$apt_get -d source $srcpkg");
         }
     }
     chdir ($olddir);
diff -ur multistrap-2.2.0/multistrap multistrap-2.2.0-hacked/multistrap
--- multistrap-2.2.0/multistrap 2013-07-27 14:56:54.000000000 +0000
+++ multistrap-2.2.0-hacked/multistrap  2015-04-20 16:13:58.860990485 +0000
@@ -36,7 +36,7 @@
  $explicit_suite $allow_recommends %omitdebsrc @dsclist @sectoutput
  %flatfile %important $addimportant @debconf $hookdir %hooks
  $warn_count $use_shortcut @foreignarches $olddpkg $ignorenative
- %foreignpkgs $markauto $default_release /;
+ %foreignpkgs $markauto $default_release $pre_config_str/;
 
 setlocale(LC_MESSAGES, "");
 textdomain("multistrap");
@@ -329,6 +329,19 @@
                die (_g("Secure Apt handling failed - try without 
authentication.")."\n");
        }
 }
+
+$pre_config_str = '';
+$pre_config_str .= "Dir::Etc \"${dir}${etcdir}\";\n";
+$pre_config_str .= "Dir::Etc::Parts \"${dir}${etcdir}apt.conf.d/\";\n";
+$pre_config_str .= "Dir::Etc::PreferencesParts 
\"${dir}${etcdir}preferences.d/\";\n";
+
+my $tmp_apt_conf = `mktemp -t multistrap.XXXXXX`;
+chomp ($tmp_apt_conf);
+
+open CONFIG, ">$tmp_apt_conf";
+print CONFIG $pre_config_str;
+close CONFIG;
+
 $config_str = '';
 $config_str .= " -o Apt::Architecture=$arch";
 $config_str .= " -o Dir::Etc::TrustedParts=${dir}${etcdir}trusted.gpg.d";
@@ -351,8 +364,12 @@
 $config_str .= " -o Dir::State=${dir}${libdir}";
 $config_str .= " -o Dir::State::Status=${dir}${dpkgdir}status";
 $config_str .= " -o Dir::Cache=${dir}${cachedir}";
-printf (_g("Getting package lists: apt-get %s update\n"), $config_str);
-$retval = system ("apt-get $config_str update");
+
+my $apt_get = "APT_CONFIG=\"$tmp_apt_conf\" apt-get $config_str";
+my $apt_mark = "APT_CONFIG=\"$tmp_apt_conf\" apt-mark $config_str";
+printf (_g("Getting package lists: %s update\n"), $apt_get);
+
+$retval = system ("$apt_get update");
 $retval >>= 8;
 die (sprintf (_g("apt update failed. Exit value: %d\n"), $retval))
        if ($retval != 0);
@@ -397,9 +414,9 @@
 @s = split (/ /, $str);
 uniq_sort (\@s);
 $str = join (' ', @s);
-print "apt-get -y $config_str install $str\n";
+print "$apt_get -y install $str\n";
 $retval = 0;
-$retval = system ("apt-get -y $config_str install $str");
+$retval = system ("$apt_get -y install $str");
 $retval >>= 8;
 die (sprintf (_g("apt download failed. Exit value: %d\n"),$retval))
        if ($retval != 0);
@@ -425,7 +442,7 @@
 &add_extra_packages;
 system ("cp $configsh $dir/") if ((defined $configsh) and (-f $configsh));
 &handle_source_packages;
-(not defined $tidy) ? system ("apt-get $config_str update") : &tidy_apt;
+(not defined $tidy) ? system ("$apt_get update") : &tidy_apt;
 &guard_lib64($dir);
 
 # cleanly separate the bootstrap sources from the final apt sources.
@@ -470,9 +487,10 @@
        }
 }
 # altered the sources, so get apt to update.
-(not defined $tidy) ? system ("apt-get $config_str update") : &tidy_apt;
+(not defined $tidy) ? system ("$apt_get update") : &tidy_apt;
 # run second set of hooks
 &run_completion_hooks(sort @{$hooks{'A'}}) if (defined ($hooks{'A'}));
+unlink $tmp_apt_conf;
 if (not defined $warn_count) {
        printf (_g("\nMultistrap system installed successfully in %s.\n"), 
$dir);
 } else {
@@ -515,8 +533,8 @@
 sub add_extra_packages {
        if (scalar @extrapkgs > 0) {
                $str = join (' ', @extrapkgs);
-               print "apt-get -y $config_str install $str\n";
-               system ("apt-get -y $config_str install $str");
+               print "$apt_get -y install $str\n";
+               system ("$apt_get -y install $str");
                &force_unpack (@extrapkgs) if ($unpack eq "true");
                system ("touch ${dir}${libdir}lists/lock");
                &native if (not defined ($foreign));
@@ -537,7 +555,7 @@
        my @auto = grep {my $pkg = $_; ! grep /$pkg/, @manual} @all;
        printf(ngettext ("Found %d package to mark.\n",
                "Found %d packages to mark.\n", scalar @auto), scalar @auto);
-       system ("apt-mark $config_str auto " . join (" ", sort @auto)) if 
(scalar @auto > 0);
+       system ("$apt_mark auto " . join (" ", sort @auto)) if (scalar @auto > 
0);
        printf (_g("Marking automatically installed packages completed.\n"));
 }
 
@@ -889,9 +907,9 @@
        my $olddir = getcwd();
        chdir ($sourcedir);
        if (scalar @dsclist > 0) {
-               print "apt-get -d $config_str source " . join (" ", @dsclist) . 
"\n";
+               print "$apt_get -d source " . join (" ", @dsclist) . "\n";
                foreach my $srcpkg (@dsclist) {
-                       system ("apt-get -d $config_str source $srcpkg");
+                       system ("$apt_get -d source $srcpkg");
                }
        }
        chdir ($olddir);

Reply via email to