diff --git a/bash/multistrap b/bash/multistrap new file mode 100644 index 0000000..fd95251 --- /dev/null +++ b/bash/multistrap @@ -0,0 +1,44 @@ +# bash completion support +# +# Copyright (C) 2009 Neil Williams +# +# This package is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +_get_dpkg_cross_list() +{ + grep Choices: /var/lib/dpkg/info/dpkg-cross.templates \ + | cut -d':' -f2 | sed -e 's/None, //' | sed -e 's/,//g' +} + +_em_multistrap() +{ + local cur prev opts cmds help machine arch quiet + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + help="-h -? --help --version " + arch="-a --arch " + opts="-f --file" + machine="" + case "$prev" in + -@(a|-arch)) + COMPREPLY=( $( _get_dpkg_cross_list $cur ) ) + ;; + *) + COMPREPLY=( $(compgen -W "${arch}${help}${opts}${machine}${cmds}" -- ${cur}) ) + ;; + esac +} +complete -F _em_multistrap -o default em_multistrap diff --git a/em_multistrap b/em_multistrap index 49cae98..9a39c3f 100755 --- a/em_multistrap +++ b/em_multistrap @@ -22,12 +22,13 @@ use Parse::Debian::Packages; use strict; use vars qw/ $progname $ourversion %scripts $dstrap $script $extra @archives $deb $cachedir $config_str %packages $retval $str $retries - $dir $include $arch $foreign $suite $url $forceunpack $option %options + $dir $include $arch $foreign $suite $url $unpack $option %options @e $sourcesname $libdir $dpkgdir @debootstrap %suites $mirror $etcdir $repo @dirs @touch %sources $section %keys $host $key $value $type $file $config $tidy /; $progname = basename($0); -$ourversion = "0.0.3"; +$ourversion = "0.0.4"; +$unpack = "true"; while( @ARGV ) { $_= shift( @ARGV ); @@ -77,9 +78,13 @@ foreach $section (sort keys %keys) if ($section eq "general") { $arch = $keys{$section}{'arch'} if (not defined $arch); - $retries = $keys{$section}{'retries'}; $dir = $keys{$section}{'directory'} if (not defined $dir); - $forceunpack = lc($keys{$section}{'forceunpack'}); + # support the original value but replace by new value. + $unpack = lc($keys{$section}{'unpack'}) + if (defined $keys{$section}{'forceunpack'}); + $unpack = lc($keys{$section}{'unpack'}) + if (defined $keys{$section}{'unpack'}); + $tidy++ if (defined $keys{$section}{'cleanup'}); @debootstrap = split(' ', lc($keys{$section}{'debootstrap'})); } else @@ -88,16 +93,12 @@ foreach $section (sort keys %keys) $packages{$section}=$keys{$section}{'packages'}; $suites{$section}=$keys{$section}{'suite'}; $scripts{$section}=$keys{$section}{'script'}; - $options{$section}=$keys{$section}{'options'}; } } print "$progname $ourversion using $file\n"; $host = `dpkg-architecture -qDEB_BUILD_ARCH`; chomp ($host); -die ("$progname is not currently able to support native operation.\n") - if ($host eq $arch); -# don't let debootstrap do second-stage -$foreign = "--foreign"; # always set +$foreign++ if ($host ne $arch); $cachedir = "var/cache/apt/"; # archives $libdir = "var/lib/apt/"; # lists $etcdir = "etc/apt/"; # sources @@ -179,38 +180,11 @@ $retval = system ("apt-get -y $config_str install $str"); die ("apt download failed. Exit value: ".($retval/256)."\n") if ($retval != 0); -foreach $dstrap (@debootstrap) -{ - $url = $sources{$dstrap}; - $suite = $suites{$dstrap}; - $script = $scripts{$dstrap}; - $option = $options{$dstrap}; - $extra = $packages{$dstrap}; - $include = ''; - if (($extra ne '') and ($option !~ /no-resolve-deps/)) - { - @e = split(' ', $extra); - $include = "--include "; - $include .= join (',', @e); - } - &write_script ($dstrap); - $str = "/usr/sbin/debootstrap $option $include --arch $arch $foreign"; - $str .= " --keep-debootstrap-dir $suite $dir $url $script"; - print "$str\n"; - $retval = system ($str); - while ($retval != 0 and $retries > 0) - { - print "Problem - trying again, $retries left. ".($retval/250)."\n$!\n"; - sleep 1; - $retval = system ("$str"); - $retries--; - } -} - -&force_unpack if ($forceunpack eq "true"); +&force_unpack if ($unpack eq "true"); system ("touch ${dir}${libdir}lists/lock"); (not defined $tidy) ? system ("apt-get $config_str update") : &tidy_apt; system ("rm -rf ${dir}debootstrap"); +&native if (not defined ($foreign)); print "\nMultistrap system installed successfully in $dir.\n\n"; exit 0; @@ -353,7 +327,7 @@ sub tidy_apt next unless ($file =~ /\.bin$/); unlink ("${dir}${cachedir}$file"); } - if ($forceunpack eq "true") + if ($unpack eq "true") { opendir (DEBS, "${dir}${cachedir}/archives/") or die ("Cannot read apt archives directory/.\n"); @@ -368,6 +342,13 @@ sub tidy_apt } } +# if native arch, do a few tasks just because we can and probably should. +sub native +{ + print "I: Native mode - configuring unpacked packages . . .\n"; + system ("sudo chroot $dir dpkg --configure -a"); +} + sub get_required_debs { # emulate required="$(get_debs Priority: required)" @@ -380,11 +361,8 @@ sub get_required_debs or die ("Cannot open ${dir}${libdir}lists/ directory. $!\n"); my @lists=grep(/_Packages$/, readdir (PKGS)); closedir (PKGS); - # only read Packages files from the debootstrap entries where - # options do not include --no-resolve-deps foreach my $strap (@debootstrap) { - next if ($options{$strap} =~ /no-resolve-deps/); my $s = lc($strap); foreach my $l (@lists) { @@ -405,34 +383,6 @@ sub get_required_debs return \@debs; } -sub write_script -{ - ($dstrap) = @_; - $extra = $packages{$dstrap}; - $script = $scripts{$dstrap}; - return if ($script eq ''); - open (SCRIPT, ">$script") or die ("Cannot open $script. $!\n"); - print SCRIPT<