Easymount v 1, a couple of scripts replacing some system mount binairies, 
enabling easy mounting of removable (or other) media by mortal users on NetBSD

CopyLeft 2005 Bastiaan Welmers, bastiaan at welmers.net

------------------

This package includes some scripts that replace /sbin/mount, /sbin/umount and
/usr/bin/eject.
Original files will be renamed as respectively /sbin/mount_general, 
/sbin/umount_root and /usr/bin/reject_root

Because there are only shell scripts, this package is completely
platform-independent.

The scripts will do the following:

- check wheter the user, calling /sbin/mount etc. is root or not

- when root, just forward to originally /sbin/mount_general etc.

- when not root, forward to "/usr/pkg/bin/sudo /sbin/mount"

Sudo need to be configured to enable some mount and umount (and eventually 
reject) commands running as root.
Disable password prompting if you want to mount from file managers like
KDE, ROX-filer or  nautilus. An example to accomplish this can be found
in sudoers.easymount, where every user from the group 'users' can run a couple
of mount commands for CD drives and USB sticks etc.

Additionally to the replacing scripts, easymount also includes a /sbin/mount_auto
script, that makes it possible to use the "auto" fs option in /etc/fstab (like in 
linux). When mounting a fstab entry with fs set to "auto", /sbin/mount_auto will 
run and the file system of the media will be autodetected.
Autodetection works just simple as following:
- first, mount_msdos is tried, when failed;
- mount_ext2fs is tried, when failed;
- mount_general is tried
When all fail, mount_auto returns with an error and the output of the last 
mount(mount_general) is outputted.

When mounting msdos file systems, the file system will be mounted with the 
special  uid option. This makes the user id of all the files in the mounted 
msdos file  system be set to the user that initiated the `sudo mount` command.
When no sudo user is found, uid will be set to the user running the mount_auto 
script.

In order to work properly, /etc/fstab needs to be filled with potential removable
media entries, matching these lines in the sudoers file. See an example how to 
do this in fstab.easymount

At last you need to create the mount points, if not already done.

Of course, sudo needs to be installed, (as pkgsrc package)
However, when sudo is not found (ie when /usr/pkg partition is not mounted) 
mounting still works and the scripts will skip the sudo work and just forward 
to the original command.

To install the scripts properly, please run install.sh.

When set up properly, you should be able to do as mortal user:

- run from commandline "mount /MOUNTPOINT" to mount a just-inserted
  device;
- run from commandline "umount /MOUNTPOINT" to unmount the device for removal;
- run from commandline "eject /MOUNTPOINT" to unmount and eject the device;
- run from commandline "eject /dev/device" to eject a non-mounted device;
- do the same with graphical user interfaces like KDE, Gnome or ROX-filer.

FAQ:

Q. Why not just using amd (the BSD automounter daemon) to accomplish this?
A. Three reasons: 
   1. amd cannot instruct mount_msdos to mount fat file systems with
      the right uid option. So mounted msdos file systems will be 
      read-only to the user or read-write to all.
   2. I also could not find a way to let amd auto-detect the fs of the media.
   3. amd seems not to be stable enough to mount removable media.
      When you accidently cd to a mount point for a floppy, and there's no 
      floppy present in the station, amd will lock up and can't even be 
      unlocked without rebooting the whole system.
      
Q. Why not putting these scripts in /usr/local/sbin and leave the core OS binairies 
   alone?
A. Because some gui file managers always use /sbin/mount etc. and so these will
   not work when the replacing scripts are put in /usr/local/sbin. Additionally,
   the system needs to be set up that /usr/local/sbin is put before /sbin in the PATH
   environment variable.
   
Q. Does this also work with other BSDs like FreeBSD or OpenBSD?
A. Probably, but then you have to replace /usr/pkg by /usr/local in every script and
   since I only use NetBSD, I don't now if there are other potential problems.

When you disagree with any concept or have other suggestions, feel free to contact me:
bastiaan at welmers.net
