# add users -*-perl-*-

sub root_password {

    local ( $pid );

    &rhs_msgbox("Root Password",
<<EOM
>
You will now enter a password for the root user (super-user).
If you forget this password, you must re-install the system!
>
EOM
		, 60);

    if (! $rh_testing) {
	system("cp -f $fsmount/etc/passwd /etc");
	symlink("$fsmount/etc/npasswd.conf", "/etc/npasswd.conf");
	# clear the screen - it looks better that way"
	print "[H[J";
	system("passwd");
	system("cp -f /etc/passwd $fsmount/etc");
    }

#    if ($pid = fork) {
#	waitpid($pid, 0);
#    } else {
#	chroot $fsmount;
#	system("passwd");
#	exit 0;
#    }
    
    return 1;
}

sub add_users {

    local ( $prompt, $username, $pid, $command );

    $prompt = 
<<EOM
>
Do you want to create a user account?
>
EOM
    ;

    while (1) {
	if (! &rhs_yesno("Create User", $prompt, 50)) {
	    return 1;
	}
	$prompt =
<<EOM
>
Do you want to create another user account?
>
EOM
    ;

	if (! &rhs_inputbox("User Name",
<<EOM
>
Enter a name for the user account, up to 8 characters.
>
EOM
			    , 60, "")) {
	    return 1;
	}

	$username = $dialog_result;

	if (&rhs_yesno("Home Directory",
<<EOM
>
If your home directories will be mounted via NFS, you can
skip this step. Otherwise, create a home directory.
>
Do you want to create a home directory for $username?
>
EOM
		       , 60)) {
	    $command = "adduser $username";
	} else {
	    $command = "adduser $username NOHOME";
	}

	&rhs_infobox("Create User",
<<EOM
>
Creating user account...
>
EOM
		     , 60);

	if ($pid = fork) {
	    waitpid($pid, 0);
	} else {
	    if (! $rh_testing) {
		chroot $fsmount;
		open(SAVEOUT, ">&STDOUT");
		open(SAVEERR, ">&STDERR");
		open(STDOUT, ">/dev/null");
		open(STDERR, ">/dev/null");
		system($command);
		open(STDOUT, ">&SAVEOUT");
		open(STDERR, ">&SAVEERR");
	    }

	    exit 0;
	}
    }
}


###########################
1;
