#! /usr/local/bin/perl
############################################################
# Determine manager for group if not supplied
############################################################

# Find out who we are...

sub fs_manager {
    local($us);
    local($team);
    local($manager);
    local($them);

    $us = (getpwuid($>))[0];

    if (defined $ENV{'TEAM_FINISHING_SERVICE'}) {
	$manager = $ENV{'TEAM_FINISHING_SERVICE'};
    } else {
	if (defined $ENV{'TEAM_NAME'}) {
	    $team = $ENV{'TEAM_NAME'};
	} else {
	    chomp($team = `teaminfo $us -v`);
	    if ( $team eq "" ) {
		die "$prog: You ($us) have not been assigned to a team in EQUUS.\n";
	    }
	}

	chomp($manager = `teaminfo $team -fin -v`);
	if ( $manager eq "" ) {
	    die "$prog: Your team ($team) does not have a finishing service.\n";
	}
    }

    ############################################################
    # Must be in manager's group
    ############################################################

    &fs_sharedGroups($us,$manager) || die "$prog: You must be in the same group as $them to run this command\n";

    $manager;
}

############################################################
# reports groups shared between users
############################################################
sub fs_sharedGroups {
    local($us,$them) = @_;
    local(@usg) = split(/\s+/,`groups $us`);
    local(@themg) = split(/\s+/,`groups $them`);
    local(%temp);

    grep($temp{$_}++,@usg);
    grep($temp{$_},@themg);

}



1;
#
