#!/s/std/bin/perl
# Removeuser.pl: Remove the old user from the list.
#
# Krung Sinapiromsaran, 6 June 2000
# Usage: Removeuser.pl user1 user2 ... usern
#
# Constant variables
#
use InitDaemon;
require 'common.pl';

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

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

sub Updateuser {
    local(@list) = @_;
    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";
       }
    close(OUT);
    foreach $i (@list) {
       $userdir = $DaemonRootdir . $DirSep . $i;
       system("$DaemonBindir\/rm -r $userdir");
    }
}

sub Removeuser {
    local(@list) = @_;
    foreach $i (@list) { delete $users{$i} if $users{$i}; }
}
