# Mounts RHS stuff, either from CD or over NFS -*-perl-*-

# Only mount_rhs() and unmount_rhs() are interactive

# Entry point: mount_rhs()
#   unmounts rhs stuff if it is mounted (ask first)
#   ask NFS or CD
#   NFS: if net not configed, config it
#        ask for details and try mount
#   CD: probe
# if fails, try again

##
## Variables
##

# $rh_mountpath is point at which to mount the device
# $rpppath is the path from $rh_mountpath to the rpp directory,
#     which is used to verify that this is indeed RHS stuff

$rh_mountpath = "/image";
$rpppath = "rpps";

# This is, "CD", "NFS"
$rh_mounttype = "";

$rh_mountdevice = "";
$rh_mountdevicetype = "";

##
## Functions
##

sub mount_rhs {

    local ($try_again, $ret);

    if ($rh_available) {                 # we're probably testing stuff
	return 1;
    }
    ## Now get to the real stuff
    if (! &rhs_menu("Base Install",
<<EOM
>
From where are you mounting the Red Hat distribution?
>
EOM
		    , 70, 2,
		    "CD", "CD-ROM Installation",
		    "NFS", "Network Installation" )) {
	return 0;
    }

    $rh_mounttype = $dialog_result;
    if ($rh_mounttype eq "NFS") {
	$ret = &nfs_mount;
    } elsif ($rh_mounttype eq "CD") {
	$ret = &probe_rhs_cdrom;
    } else {
	# NOTREACHED !!
	# Bad install style if we get here
	print "mount_rhs(): Bad install style $rh_mounttype\n";
	exit 1;
    }

    if (! $ret) {
	&rhs_msgbox("Error",
<<EOM
>
Without access to the Red Hat Linux files the
install can not continue!  Sorry.
>
EOM
		    , 50);
	return 0;
    }

    return 1;
}

sub unmount_rhs {

    if (! $rh_mounted) {
	&rhs_msgbox("Error",
<<EOM
>
The Red Hat stuff does not appear to be mounted.
>
EOM
		    , 60);
	return 1;
    }

    if (&__umount_rhs != 0) {
	&rhs_msgbox("Error",
<<EOM
>
There was an error unmounting the Red Hat stuff.
Perhaps it was not really mounted.
>
EOM
		    , 60);
	return 0;
    }
    
    if (! $express_install) {
	&rhs_msgbox("Success",
<<EOM
>
Red Hat stuff unmounted successfully.
>
EOM
		    , 60);
    }

    return 1;
}

sub verify_rhs_files {
    return -d "$rh_mountpath/RedHat";
}

sub finish_cd {

    if ($rh_mounttype eq "CD") {
	open(FD, ">>$fsmount/etc/fstab");

	print FD
<<EOM

#
# Red Hat CD-ROM
#
EOM
    ;
    
	printf(FD "%-30s %-15s %-6s %s\n", $rh_mountdevice, "/mnt/cdrom", "iso9660", "ro,noauto");
	close FD;


	symlink($rh_mountdevice, "$fsmount/dev/cdrom");
    }

    return 1;
}

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

