#!/usr/bin/perl -w

use strict;
use warnings;
use Getopt::Long;
use File::Basename;
use Pod::Usage;
use ALTLinux::ACL;

my $verbose=0;
my $help=0;
my $resolve_group=0;
my $nvr_mode;

my $result = GetOptions (
    @ALTLinux::ACL::LONGOPT,
    "help"  => \$help,
    'quiet'=> sub {$verbose=0},
    "verbose+"  => \$verbose,
    "nvr"  => \$nvr_mode,
);

if ($help or not @ARGV or @ARGV>1) {
    pod2usage();
}

my $acl = ALTLinux::ACL->new();

sub print_acl {
    my $name=basename(shift);
    $name=~s/-[^-]+-[^-]+$// if $nvr_mode;
    my @acl_list=$acl->acl($name);
    unless (@acl_list) {
	warn "$name: the package has no acl\n";
	push @acl_list, '@nobody';
    }
    print join(' ',@acl_list),"\n";
}

map {&print_acl($_)} @ARGV;


=head1	NAME

altlinux-acl-get-acl - print altlinux acl of the given name(s).

=head1	SYNOPSIS

B<altlinux-acl-get-acl>
[B<-h|--help>]
[B<-q|--quiet>]
[B<-v|--verbose>]
[B<--nvr>]
I<name> [...]

=head1	DESCRIPTION

B<altlinux-acl-get-acl>
Prints altlinux acl of the given name.
If the acl is not found, prints @nobody.


=head1	OPTIONS

=over

=item	B<-h, --help>

Display this help and exit.

=item	B<--nvr>

NVR mode. In this mode, the input is not a srpm name, but
is expected to look like name-version-release.something,
like foo-1.0-alt1, foo-1.0-alt1.log, foo-1.0-alt1.noarch,
foo-1.0-alt1.noarch.patch.

=item	B<-v, --verbose>, B<-q, --quiet>

Verbosity level. Multiple -v increase the verbosity level, -q sets it to 0.

=back

=head1	AUTHOR

Written by Igor Vlasenko <viy@altlinux.org>.

=head1	COPYING

Copyright (c) 2009-2023 Igor Vlasenko, ALT Linux Team.

This 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 2 of the License, or (at your option) any later version.

=cut
