#!/s/std/bin/perl
# Adduser.pl: Add the new user name into the list of condor submission users
#
# Krung Sinapiromsaran, 6 June 2000
# Usage: Adduser.pl user1 user2 ...
#
# Constant variables
#
use InitDaemon;
require 'common.pl';

%users = ();
$dirmode = '0755';

# ******************
# Program Start here
# ******************
&Usageinfo('Adduser.pl user1 user2 ... usern') unless (@ARGV);
&Readuser;
&Adduser(@ARGV);
&Updateuser;
&Printuser;
1;

sub Updateuser {
    local($i, $userdir, $filename);
    $filename = $DaemonRootdir . $DirSep . $DaemonDatafile;
    open(OUT, ">$filename") || die "Cannot write to $filename $!\n";
       foreach $i (sort keys %users) {
	  print OUT $i, "\n";
	  $userdir = $DaemonRootdir . $DirSep . $i;
          mkdir($userdir, $dirmode) unless (-d $userdir);
	  chmod($dirmode, $userdir);
	  system("$DaemonFsdir\/fs setac $i $i write");
	  system("$DaemonFsdir\/fs setac $i $DaemonAfsuser write");
       }
    close(OUT);
}

sub Adduser {
    local(@list) = @_;
    foreach $i (@list) { $users{$i} = 1 unless $users{$i}; }
}
