#!/usr/bin/perl -w
#
# $Id$
# Copyright B. Cornec 2005-2014
# Provided under the GPL v2
#
# Get all links from a file
#
use strict;
use Data::Dumper;
use MondoRescue::File;
# For pbdebug
use ProjectBuilder::Base;

=pod

=head1 NAME

mr-read-all-link keeps track of all the links of a file and display them

=head1 DESCRIPTION

mr-read-all-link keeps track of all the links of a file and display them, by analyzing the path under which the file is located and mentioning all links that are encountered so that all the required content for a chroot environment are given back correctly.

=head1 SYNOPSIS

mr-read-all-link /path/to/file ...

=head1 ARGUMENTS

=over 4

=item B</path/to/file> 

This is the path of the binary file and for which we want its links to be included

=back

=head1 WEB SITES

The main Web site of the project is available at L<http://www.mondorescue.org>. Bug reports should be filled using the trac instance of the project at L<http://trac.mondorescue.org/>.

=head1 USER MAILING LIST

For community exchanges around MondoRescue please use the list L<http://sourceforge.net/mailarchive/forum.php?forum_name=mondo-devel>

=head1 AUTHORS

The MondoRescue team lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.

=head1 COPYRIGHT

MondoRescue is distributed under the GPL v2.0 license or later,
described in the file C<COPYING> included with the distribution.

=cut

$pbdebug = 2 if ((defined $ARGV[0]) && ($ARGV[0] eq "-v"));

my $file = mr_file_read_all_link(@ARGV) if (defined $ARGV[0]);
my %h;

#print Dumper($file);

foreach my $f (sort keys %$file) {
	print "$f\n" if ($pbdebug >= 1);
	print "--\n" if ($pbdebug >= 1);
	#print Dumper($f);
	foreach my $l (sort keys %{$file->{$f}}) {
		print "==" if ($pbdebug >= 1);
		print "$l\n" if ($pbdebug >= 1);
		$h{$l} = 1;
	}
	print "--\n" if ($pbdebug >= 1);
}

foreach my $l (sort keys %h) {
	print "$l\n";
}
