1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#!/usr/bin/perl
=pod
=head1 Name
emprunecross - Identify cross dependencies installed by dpkg-cross
=head1 Copyright and Licence
Copyright (C) 2007 Neil Williams <codehelp@debian.org>
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 <http://www.gnu.org/licenses/>.
=cut
use File::Basename;
use Debian::DpkgCross;
use Emdebian::Tools;
use Term::ANSIColor qw(:constants);
use strict;
use warnings;
use vars qw/ $arch %chain %prune $target_gnu_type $suite $list $status
$success @cross %chain $crosslist $progname $string $cmd $dryrun
$our_version $unpacked /;
$dryrun = 0;
$progname = basename($0);
$our_version = &tools_version();
&read_config();
$arch = &get_architecture();
sub usageversion {
print(STDERR <<END)
$progname version $our_version
Usage:
$progname [-n|--dry-run|--simulate] [-a|--arch ARCH]
$progname -?|-h|--help|--version
Commands:
-n|--dry-run|--simulate: Do a dry-run, do not change anything.
-a|--arch ARCH: Set architecture (default: defined by dpkg-cross)
-?|-h|--help: Print this usage message and exit
--version: Print this usage message and exit
END
|| die "$0: failed to write usage: $!\n";
exit 0;
}
while( @ARGV ) {
$_= shift( @ARGV );
last if m/^--$/;
if (!/^-/) {
unshift(@ARGV,$_);
last;
}
elsif (/^(-\?|-h|--help|--version)$/) {
&usageversion();
exit( 0 );
}
elsif (/^(-n|--dry-run|--simulate)$/) {
$dryrun++;
}
elsif (/^(-a|--arch)$/) {
$arch = shift(@ARGV);
}
else {
die RED, "$progname: Unknown option $_.", RESET, "\n";
}
}
$target_gnu_type = &check_arch($arch);
die (RED, "\n$progname: Cannot determine the architecture to check.", RESET, "\n\n")
if ((not defined $arch)||($arch eq "")||(not defined $target_gnu_type));
$suite = &get_targetsuite;
$list = &prepare_checklist($arch, $target_gnu_type);
$status = 'install ok installed';
$unpacked = 'install ok unpacked';
$success = "";
$string = " ";
%chain=();
foreach my $res (sort @$list)
{
$success = `dpkg-query -W -f='\${Package} \${Status}' $res 2>/dev/null`;
$string = "$res $status";
$chain{$res}++ if ($success eq $string);
}
$crosslist = `dpkg-query -W -f='\${Package} \${Status}\n' \'*-$arch-cross\'`;
@cross = split(/\n/, $crosslist);
foreach my $c (@cross)
{
next if (($c !~ / $status$/) and ($c !~ / $unpacked/));
$c =~ s/ $status$//;
$c =~ s/ $unpacked//;
chomp($c);
next if (defined $chain{$c});
next if ($c =~ /^libc6.*$arch-cross/);
$prune{$c}++;
}
if (scalar keys %prune > 0)
{
my $plural = (scalar keys %prune == 1) ? "package" : "packages";
print RED, "Removing $plural\n", RESET;
if ($dryrun > 0)
{
$cmd = join("\n", sort keys %prune);
print "$cmd\n";
exit(0);
}
$cmd = join(" ", sort keys %prune);
system ("sudo dpkg -P $cmd");
}
=head1 Description
Removes or just prints the complete list of packages that have been
installed by dpkg-cross (whether using dpkg-cross directly or via
apt-cross or emdebian-tools) for the selected architecture or dpkg-cross
default architecture.
This functionality cannot just be merged into apt-cross because that would
remove cross packages used by the Emdebian toolchain.
=head1 Commands and options
-a|--arch
Override the dpkg-cross default architecture.
-n|--dry-run|--simulate
Only print the list, do not call 'sudo dpkg -P'
=cut
|