#!/usr/bin/perl -w
#
# $Id$
use strict;
my @groups;
# assume passed "standard Unix group format", output in .ini format
# (used by Config::Tiny, etc.)
while (<>) {
next if m/^#/; # OS X has leading comments in groups file...
chomp;
my %group;
( @group{qw(name passwd id)}, my $users ) = split /:/, $_, 4;
$users ||= q{};
$group{members} = [ split ',', $users ];
unless ( exists $group{name}
and defined $group{name}
and exists $group{id}
and defined $group{id} ) {
warn "warning: skipping invalid group entry: line=$.\n";
next;
}
push @groups, \%group;
}
for my $group ( sort { $a->{id} <=> $b->{id} } @groups ) {
print "[$group->{name}]\n";
print " passwd = $group->{passwd}\n"
unless $group->{passwd} =~ m/^\*/
or $group->{passwd} eq 'x';
print " id = $group->{id}\n";
print " members = ", join( ' ', @{ $group->{members} } ), "\n"
if @{ $group->{members} };
print "\n";
}