#!/usr/bin/perl

# voldconfig.  (c) 1998 David A. van Leeuwen
# configure /etc/voltab
# $Id: voldconfig,v 1.4 1998/02/15 09:53:30 david Exp $

$|=1;
$VOLTAB = "/etc/voltab";
$FSTAB = "/etc/fstab";

$arg = shift;
$force = $arg eq "--force";

if (-e $VOLTAB) {
    if (!$force) {
	print "  Already existing $VOLTAB found.
  Do you want to reconfigure $VOLTAB anyway? [y/N] ";
	$in=<stdin>;
	if ($in !~ /^[yY]/) {
	    exit (-1);
	}
    }
}

open OUT, ">$VOLTAB" or die "  Sorry, I can't open $VOLTAB\n";

if (-e $FSTAB) {
    open IN, "grep iso9660  $FSTAB |";
    while (<IN>) {
	($device, $mountpoint, $type, $options, $freq, $passno)=split " ";
	print "    Found device $device in $FSTAB, add entry for use with vold? ";
	$in = <stdin>;
	if ($in =~ /^[yY]/) {
	    print OUT "$device\t/cdrom\tiso9660\t$options\t0\t0\n";
	}
    }
} else {
    do {
	print "    What is the device of your CDROM player? ";
	$dev=<stdin>;
	if ($dev !~ m|^/dev/|) {
	    $dev = "/dev/".$in;
	}
	if (! -e $dev) {
	    print "    Sorry, but $dev seems not to exist\n";
	} else {
	    print OUT "$dev\t/cdrom\tiso9660\tnoexec,ro\t0\t0\n";
	}
	print "    Do you want to add more CDROM devices? ";
	$in = <stdin>;
    } while ($in =~ /^[yY]/);
}
close OUT;
print "  $VOLTAB is now configured.\n";

exit 0;

