#!/usr/bin/perl -w

print <<"EOHEAD";
# This file has been automatically generated by gen-wmmountrc utility.
# PLEASE EDIT! See wmmount(1x) for details.

# This configuration file to be saved as /etc/system.wmmount or as ~/.wmmount.

# Commands must appear (without a '#') at the beginning of the line.

# Tell wmmount how to mount and unmount devices.
# '%m' will be replaced with the mountpoint.
# '%n' will be replaced with the name of the mountpoint.
# '%%' will be replaced with '%'.
# Commands are executed directly (not by a shell) for speed.
# These entries may be ommitted (defaults are set automatically).

#mountcmd=/bin/mount %m
#umountcmd=/bin/umount %m

# Tell wmmount what to do when you double-click on the information box.
# This entry may be ommitted.

#opencmd=/usr/bin/X11/xterm -T '%n - %m' -e mc %m
#opencmd=kfmclient exec %m

# Choose fonts for the information box.
# These entries may be ommitted.

#namefont=-*-helvetica-bold-r-*-*-10-*-*-*-*-*-*-*
#usagefont=-*-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*

# List all the icons you want to use.
# The first icon specified gets iconnumber 0.
# Ensure all icons exist and are accessible.
# At least one icon must be specified.

icon /usr/share/wmmount/cdrom.xpm
icon /usr/share/wmmount/floppy.xpm
icon /usr/share/wmmount/zip.xpm
icon /usr/share/wmmount/harddisk.xpm

# Give details of all mountpoints.

#mountpoint /
#name=Linux
#iconnumber=3
#usagedisplay=1
#mountcmd=/bin/mount %m
#umountcmd=/bin/umount %m
#opencmd=kfmclient exec %m 

# Parameters "name", "iconnumber" and "usagedisplay" are required.

# Value of usagedisplay can be
# 0 (none),
# 1 (available),
# 2 (used) or
# 3 (percentage used).

# mountcmd, umountcmd and opencmd are optional and allow the defaults to be
# overridden for particular mountpoints.

EOHEAD
    ;

$, = ' ';		# set output field separator
$\ = "\n";		# set output record separator
$mpoint = `hostname`; chomp($mpoint);
$mpoint = ucfirst $mpoint;

my $FSTAB;
open (FSTAB, "< /etc/fstab") or die "Can't open /etc/fstab: $!";

line: while (<FSTAB>) {
    chop;

    next line if /^(\#|$)/;

    (my $filesystem, my $mountpoint, my $fstype, undef) = split;

    next line if (/^(\#|$)/ || $fstype =~ /(proc|swap)/);

    my $IconNumber = 3;
    my $DisplayType = 1;

    if ($filesystem =~ /fd/ || $mountpoint =~ /floppy/) {
        $IconNumber = 1;
        $DisplayType = 1;
    }

    if ($filesystem =~ /cdrom/ || $mountpoint =~ /cdrom/ || $fstype =~ /iso9660/) {
        $IconNumber = 0;
        $DisplayType = 0;
    }

    if ($filesystem =~ /zip/ || $mountpoint =~ /zip/) {
        $IconNumber = 2;
        $DisplayType = 1;
    }

    print "\nmountpoint $mountpoint";

    if ($mountpoint =~ /^\/$/) {
        print "name=$mpoint";
    } else {
        my @paths = split('/', $mountpoint);
        $mpoint = ucfirst $paths[$#paths];
        print "name=$mpoint";
    }
                  
    print "iconnumber=$IconNumber";
    print "usagedisplay=$DisplayType";
}

close FSTAB;
