#!/usr/bin/perl -T -I/h/COE/lib 

#- the -w flag gives a "Use of unitialized value in substr" error in Coe.lib

use strict;
use Coe;

my $VERSION="1.1.4.1";

my $scope="local";
my $arg1;
my @p;
my $gid="10100";
my $gid1="10100";
my $OSFILE;


$arg1=cleanString(shift,1);
if ("$arg1" eq "-s" || "$arg1" eq "--scope") {
	$scope=cleanString(shift,1);
}

if ("$scope" eq "global" || "$scope" eq "g") {
	$scope="global";
	$gid=15000;
} else {
	$gid=10100;
}

$OSFILE=readFile("/etc/group");
while (<$OSFILE>) {
	@p=split(":");
	if ("$scope" eq "global" && $p[2]>15000 && $p[2]<19999) {
		if ($p[2]>$gid){$gid=$p[2];}
	} elsif ($p[2]>10100 && $p[2]<15000) {
		if ($p[2]>$gid){$gid=$p[2];}
	}
}
close $OSFILE;

$gid=$gid+1;
$gid1=cleanString($gid,0);
print "$gid1\n";