#!/usr/bin/perl

use lib qw(/usr/lib/libDrakX);
use standalone;
use network::nfs;
use network::smb;
use MDK::Common::Func qw(if_);

"@ARGV" =~ /-h/ and die "usage: lsnetdrake [-h] [--nfs] [--smb]\n";

my $nfs = !@ARGV || "@ARGV" =~ /-(nfs)/;
my $smb = !@ARGV || "@ARGV" =~ /-(smb)/;

$| = 1;
$ENV{PATH} = "/sbin:/usr/sbin:$ENV{PATH}";

foreach my $class (if_($nfs, network::nfs->new), if_($smb, network::smb->new)) {
    foreach my $server (sort_names($class->find_servers)) {
	foreach (sort_names(eval { $class->find_exports($server) })) {
	    print $class->to_fullstring($_), "\n";
	}
    }
}

sub sort_names { 
    sort { $a->{name} cmp $b->{name} } @_;
}