#!/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 camer
+a
# 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 = <<EndOfRemover;
#!/bin/sh
logger -p user.info -t leicaRemover -i "trying umount -f $MOUNTPOINT"
umount -f $MOUNTPOINT
logger -p user.info -t leicaRemover -i "umount returned \$?"
EndOfRemover
my $remover_fh = new IO::File "> $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();
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.