#!/usr/bin/perl
# Don't specify a user/password here.
$p4 = "p4 -p 1666";
# Usage:
# requirePW form-in group "perl pw_group.pl %formfile% [group]"
my $formfile = $ARGV[0];
my $group = $ARGV[1];
die "incorrect trigger usage!" if ( !$formfile );
my @result;
open FILE, $formfile or die "couldn't open file: $!";
while ( <FILE> )
{
if ( /^Group:[\s]+([\S]+)/ ) { if ( $group && $1 ne $group ) { exit; } }
if ( !/^[\s]+/ ) { push @result, $_; next; }
if ( !/[\S]/ ) { push @result, $_; next; }
s/[\s]+//g;
$user = $_;
$_ = `$p4 -u $user -P $user -c noemail changes -m1 2>&1`;
if ( !/^Change/ ) { push @result, "\t".$user."\n"; next; }
print "Dropped $user from group due to lack of password.\n";
$dropped = 1;
}
close FILE;
exit if ( !$dropped );
open FILE, '>', $formfile or die "couldn't open file: $!";
foreach( @result )
{
print FILE $_;
}
close FILE;