# Handles configuraing NFS and setting stuff so -*-perl-*-
# __mount_rhs mount the proper NFS volume

$nfsserver = "";
$nfsdir = "";

sub nfs_mount {

    local ( $dont_try );

    if (! $net_up) {
	&make_net_up;
	if (! $net_up) {
	    &rhs_msgbox("Error",
<<EOM
>
The network must be properly configured for an
NFS install to work.
>
EOM
			, 60);
	    return 0;
	}
    }

    if (! &_nfs_config) {
	return 0;
    }

    $dont_try = 0;
    while (1) {
	if (! $dont_try) {
	    if (&_nfs_mount_and_verify) {
		return 1;
	    }
	}
	$dont_try = 0;

	if (! &rhs_menu("Choose",
<<EOM
>
What would you like to try?
>
EOM
			, 60, 4,
			"TCP/IP", "Reconfigure networking",
			"NFS", "Reconfigure NFS",
			"Mount", "Just try the mount again",
			"Quit", "Give up")) {
	    return 0;
	} else {
	    # Do choice
	    if ($dialog_result eq "TCP/IP") {
		&reconfig_net_up;
		if (! $net_up) {
		    &rhs_msgbox("Error",
<<EOM
>
The network must be properly configured for an
NFS install to work.
>
EOM
				, 50);
		    $dont_try = 1;
		}
	    } elsif ($dialog_result eq "NFS") {
		if (! &_nfs_config) {
		    $dont_try = 1;
		}
	    } elsif ($dialog_result eq "Mount") {
		# Do nothing
	    } elsif ($dialog_result eq "Quit") {
		return 0;
	    } else {
		print "Bad dialog_result: $dialog_result\n";
		exit 1;
	    }
	}
    }
}

sub _nfs_mount_and_verify {

    $rhsmountdevice = "$nfsserver:$nfsdir";
    $rhsmountdevicetype = "nfs";

    $hold_on_error = 0;
    $ret = &invoke("mount -t nfs -o ro $rhsmountdevice $rh_mountpath");
    $hold_on_error = 1;
    if ($ret == 0) {
	if (&verify_rhs_files) {
	    if (! $express_install) {
		&rhs_msgbox("Success",
<<EOM
>
The NFS volume was mounted successfully and the Red Hat files
were found.
>
EOM
			    , 50);
	    }
	    return 1;
	} else {
	    &rhs_msgbox("Error",
<<EOM
>
The NFS volume was mounted, but the Red Hat files were not found.
>
EOM
			, 50);
	    &__umount_rhs;
	    &invoke("umount $rh_mountpath");
	    return 0;
	}
    }
    &rhs_msgbox("Error",
<<EOM
>
I was not able to mount the NFS volume $rhsmountdevice.
If this looks correct, you might want to check the server
and see that it is properly exported.
>
If you used a hostname for the NFS server you might try using
an IP address, in case the name is not resolving properly.
>
EOM
		, 60);
    return 0;
}

sub _nfs_config {

    if (! &rhs_inputbox("NFS",
<<EOM
>
Enter the host name (or IP address) of your NFS server.
>
EOM
			, 50, $nfsserver)) {
	return 0;
    }
    $nfsserver = $dialog_result;

    if (! &rhs_inputbox("NFS",
<<EOM
>
Enter the path to the directory you wish to mount from the NFS server.
>
EOM
			, 50, $nfsdir)) {
	return 0;
    }
    $nfsdir = $dialog_result;

    return 1;
}

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