#!/usr/bin/perl -w use strict; # $Id: usb_mass_storage_automount,v 1.3 2003/09/28 02:01:16 adamm Exp $ # This script is '/etc/hotplug/usb/leica' because I have a Leica camera # Original idea from http://www.buberel.org/linux/usb-automounter.php # # requires a row in /etc/hotplug/usb.usermap as described in above URL. ex: # leica 0x03 0x04da 0x2373 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000 # 0x03 = Ensure correct device by matching the Vendor and Product ID # 0x04da = part of PRODUCT from debugging /etc/hotplug/usb.agent # 0x2373 = part of PRODUCT from debugging /etc/hotplug/usb.agent # The leica's PRODUCT (see URL) looks like: 4da/2373/10 # (the last number, "10" is the device ID, and is not used) our $USERNAME = 'adamm'; our $MOUNTPOINT = '/mnt/usb'; use File::Basename; use IO::File; use Sys::Syslog; sub logInfo ($) { syslog('info', "*INFO* $_[0]") } sub logError ($) { syslog('err', "*ERROR* $_[0]") } sub dieNice ($) { logError($_[0]); cleanExit(1); } sub cleanExit (;$) { logInfo('exiting'); exit($_[0] || 0); } openlog(basename($0),'cons,pid'); logInfo("starting"); dieNice("ACTION env var not set!") unless $ENV{ACTION}; if ( $ENV{ACTION} eq "remove" ) { logInfo('action is "remove", nothing to do.'); cleanExit(); } if ( $ENV{ACTION} ne "add" ) { dieNice("unexpected value '$ENV{ACTION}' for ACTION env var"); } dieNice('REMOVER env var not set!') unless $ENV{REMOVER}; my $remover_script = < $ENV{REMOVER}" or dieNice("error writing remover '$ENV{REMOVER}' $!"); print $remover_fh $remover_script; $remover_fh->close; chmod 0755, $ENV{REMOVER} or dieNice("chmod failed. $!"); logInfo("created and chmod()ed '$ENV{REMOVER}' to auto-umount device"); my $status = `su - -c 'mount $MOUNTPOINT' $USERNAME`; logError("mount status: $status ... ($?)") if $? != 0; cleanExit();