My usb_storage script.

Sergey Kuznetsov skuznets-WRMZ5ucGVl4BXFe83j6qeQ at public.gmane.org
Wed Apr 14 15:36:02 UTC 2004


Hi all,

I promised TLUGers to to send my hotplug USB storage script.

Here we go. It works like charm for me for both digital camera and
USB key.

/etc//hotplug/usb.usermap:
# usb module         match_flags idVendor idProduct bcdDevice_lo 
bcdDevice_hibDeviceClass bDeviceSubClass bDeviceProtocol bInterfaceClass 
bInterfaceSubClass bInterfaceProtocol driver_info
storage       0x0000      0x0000   0x0000    0x0000       0x0000       0x00         
0x00   0x00            0x08            0x06               0x00            
0x00000000

/etc/hotplug/usb/storage:

#!/usr/bin/perl
BEGIN {
        $ENV{PATH} = "$ENV{PATH}:/opt/kde/bin:/usr/X11/bin:/usr/lib/qt/bin";
        $ENV{QTDIR} = "/usr/lib/qt";
        $ENV{LD_LIBRARY_PATH} = "/usr/X11/lib:/usr/lib/qt:/opt/kde/lib";
}

    open LOG, ">>/tools/usbaction.log" or exit 0;

    print LOG "=============== " . scalar(localtime()) . " ===============\n";
    foreach $key ( keys %ENV )
    {
        print LOG "$key = $ENV{$key}\n";
    }

    if ( $ENV{ACTION} eq "add" )
    {
        open PROC, "/proc/partitions" and
        do
        {
            $lines = join "", <PROC>;
            print LOG $lines;
            close PROC;
        };

        if ( $lines =~ /sda\n/sogi )
        {
            print LOG "Found sda\n";
            if ( $lines =~ /(sda\d+)\n/sogi )
            {
                print LOG "Found $1. Mounting..\n";
                system "mount -t vfat -o sync,dirsync /dev/$1 /mnt/hd";
                $path = "/mnt/hd";
                print LOG "Path is $path\n";
            }
            else
            {
                print LOG "Mounting /mnt/camera\n";
                system "mount -t vfat -o sync,dirsync /dev/sda /mnt/camera";
                $path = "/mnt/camera/dcim";
            }

            system "xauth merge ~root/.Xauthority";
            system "konqueror --display :0.0 $path 1>/dev/null 2>/dev/null &";

            system "mkdir -p /var/run/usb";
            open OUT, ">$ENV{REMOVER}" or exit 0;
            print OUT "#!/usr/bin/bash\n\numount -f -l $path\n";
            close OUT;
            system "chmod a+x $ENV{REMOVER}";
        }
    }
    close LOG;

    exit 1;

-- 
All the Best!
Sergey Kuznetsov
==================
Senior software developer
Blueprint Initiative
Samuel Lunenfeld Research Institute
Mount Sinai Hospital
522 University Ave.
9 floor
Toronto, Canada
Phone #: +1(416)596-8505 x 6343
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list