Download location (HTTP):       http://linux.bononline.nl/projects/autofsmanaged/src

Screenshots

Here I describe a way to use autofs and ConsoleKit to create autofs managed mountpoints in the users homedirectory, to access network resources, like Windows shares, and local devices, like USB sticks.

If you would like to contact me, my address is stef at bononline dot nl.

An impression:

After entering the folder Devices, all the connected USB devices appear. These devices are detected at login (looking for already connected USB devices) and when a device is plugged in during a session (with help from udev).
As you can see there are two USB devices. Note that when entering this folder with Dolphin, makes the the devices mounted (Dolhin looks inside a map), what changes the icons for these devices in the "places" toolbar.

The networkfolder contains the services ftp, ssh and smb. The contents of these maps are determined by various scripts. Far most complicated is finding the smb shares an user has access to. Via tools like nbtscan (or nmblookup) and smbclient these resources are found.
All the data is stored in static multi mount maps in such a way, autofs is able to present the user an browseable map containing resources, local and remote.

After entering the SMB map (Windows Network) the workgroup (BONONLINE) appears.

How does it work

This construction uses the ability from ConsoleKit to run scripts when a session is added or removed (or changed).
When a session is added ( = when an user logs in ) automounter maps are created for both remote resources (like Windows shares) and local devices (like USB devices). This results in two autofs managed mountpoints:

$HOME/Connections/Devices

and

$HOME/Connections/Network

In the auto.master file these mountpoints are linked to dynamically created maps. For me as user sbon this looks like:

/home/sbon/Connections/Devices /var/run/autofs/session/auto.local.map.sbon --ghost
/home/sbon/Connections/Network /var/run/autofs/session/auto.network.map.sbon --ghost

The autofs map for the network looks like for example:

"FTP" -fstype=ftpfs \
      /192.168.0.1 ://192.168.0.1
"Windows Network" -fstype=cifs,credentials="/var/run/safe/sbon/latest/mount.smb.cred" \
      "/BONONLINE/ROUTER/sbon" -rw,ip=192.168.0.1 "://ROUTER/sbon" \
      "/BONONLINE/ROUTER/ftp" -rw,ip=192.168.0.1 "://ROUTER/ftp" \
      "/BONONLINE/ROUTER/public" -rw,ip=192.168.0.1 "://ROUTER/public" \
      "/BONONLINE/LFS20060812/sbon" -rw,ip=192.168.0.2 "://LFS20060812/sbon" \
      "/BONONLINE/LFS20060812/bononline" -rw,ip=192.168.0.2 "://LFS20060812/bononline" \
      "/BONONLINE/LFS20060812/video" -rw,ip=192.168.0.2 "://LFS20060812/video" \
      "/BONONLINE/LFS20060812/test" -rw,ip=192.168.0.2 "://LFS20060812/test" \
      "/BONONLINE/LFS20060812/public" -rw,ip=192.168.0.2 "://LFS20060812/public" 
"SSH access" -fstype=sshfs \
      "/192.168.0.1" "://sbon@192.168.0.1:/" \
      "/192.168.0.2" "://sbon@192.168.0.2:/"  

and the autofs map for local devices:

"USB 2 Gig black" -fstype=auto :/dev/sdb1

These maps are created dynamically. To determine the FTP servers for example, the ~/.netrc file is searched for valid hosts.

The SMB (=Windows environment), complete with domains and/or workgroups (here: BONONLINE), servers (here: ROUTER and LFS20060812) and shares are determined by nbtscan and smbclient, very usefull utilities to do lookups.

Futher note that here the filesystems ftpfs and sshfs are used. These do not exist nativly, but I've created the mounthelpers mount.ftpfs and mount.sshfs with the help of FUSE and the FUSE modules CurlFtpFS and SshFS.

The devices map is created by testing all the devices sd* in the /dev directory. With the help of the udevinfo utility, here can determined it's a USB device.
The construction I'm using supports hot- and coldplugging.

Licence

This software and the construction is distributed under the terms of the GNU General Public License. A copy you'll find at the src directory.