chiark / gitweb /
path_id: fix invalid character class
[elogind.git] / extras / path_id
index 8391f2e58619bbe11729ab192b5db6228cbda8ca..44fc4820b54cbebe7fb171591de35551bf3b7aa8 100755 (executable)
@@ -1,19 +1,22 @@
 #!/bin/sh
 #!/bin/sh
-#set -x
 
 
-# this script should provide the shortest possible unique hardware path 
-# to a block device
+# provide the shortest possible unique hardware path to a block device
+# for the udev persistent disk device naming scheme
 #
 #
+# Copyright (C) 2005 SUSE Linux Products GmbH
+# Author:
+#      Hannes Reinecke <hare@suse.de>
+#
+#      This program is free software; you can redistribute it and/or modify it
+#      under the terms of the GNU General Public License as published by the
+#      Free Software Foundation version 2 of the License.
+#
+# to be called from a udev rule to return the name for a symlink
+#      DEVPATH=/block/sda/sda3 path_id
+#      path_id <devpath>
 
 
-# Horrible script. Handle with extreme care.
-
-# to be called from udev
-# DEVPATH=/block/sda/sda3 $0  (or similar)
-# $0 /block/sda
-# $0 /sys/block/sda
-
-# example for all:
-# for i in `find /sys/block -name dev` ;do DEVPATH="`echo $i | sed -e 's@^/sys\|/dev@@g'`" $0 ; done
+# example for all block devices on a system:
+#      for i in `find /sys/block -name dev` ;do DEVPATH="`echo $i | sed -e 's@^/sys\|/dev@@g'`" path_id ; done
 
 # examples:
 # SCSI cdrom
 
 # examples:
 # SCSI cdrom
@@ -55,9 +58,7 @@
 # then firewire sbp2
 # then the rest
 
 # then firewire sbp2
 # then the rest
 
-PATH=/lib/klibc/bin #/usr:/usr/sbin:/usr/bin:/sbin:/bin
 SYSFS=/sys
 SYSFS=/sys
-export PATH
 RESULT=1
 CDROM=
 TYPE=
 RESULT=1
 CDROM=
 TYPE=
@@ -234,6 +235,11 @@ handle_block_scsi () {
                adapter="`echo $controller_dev |  sed -e 's@/[^/]\{1,\}$@@;s@^.*/@@;s@^.*:@@'`"
                bus="gc"
                ;;
                adapter="`echo $controller_dev |  sed -e 's@/[^/]\{1,\}$@@;s@^.*/@@;s@^.*:@@'`"
                bus="gc"
                ;;
+               # PARISC devices
+               *parisc*)
+               adapter="${controler_dev##*/}"
+               bus=parisc;
+               ;;
                *)
                adapter="${controller_dev##*/}"
                bus="pci"
                *)
                adapter="${controller_dev##*/}"
                bus="pci"
@@ -269,7 +275,7 @@ handle_block_usb_storage () {
        # usb-storage devs have a serial number, hopefully unique
        serial=
        if [ -f $controller_dev/../serial ] ; then
        # usb-storage devs have a serial number, hopefully unique
        serial=
        if [ -f $controller_dev/../serial ] ; then
-               serial="`sed -e 's@^[ -]\{1,\}\|[ -]\{1,\}$@@g;s@[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_0123456789]@@g' < $controller_dev/../serial`"
+               serial="`sed -e 's@^[ -]\{1,\}\|[ -]\{1,\}$@@g;s@[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789-]@@g' < $controller_dev/../serial`"
                : serial XXX_${serial}_XXX
                d="usb-$serial"
                serial="`echo $serial | sed -e 's@[ 0]\{1,\}@@g'`"
                : serial XXX_${serial}_XXX
                d="usb-$serial"
                serial="`echo $serial | sed -e 's@[ 0]\{1,\}@@g'`"
@@ -279,10 +285,10 @@ handle_block_usb_storage () {
                # has eventually binary junk in vpd
                identifier=
                if [ -f $controller_dev/../product ] ; then
                # has eventually binary junk in vpd
                identifier=
                if [ -f $controller_dev/../product ] ; then
-               product="`sed -e 's@^[ -]\{1,\}\|[ -]\{1,\}$@@g;s@[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_0123456789]@@g' < $controller_dev/../product`"
+               product="`sed -e 's@^[ -]\{1,\}\|[ -]\{1,\}$@@g;s@[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789-]@@g' < $controller_dev/../product`"
                fi
                if [ -f $controller_dev/../manufacturer ] ; then
                fi
                if [ -f $controller_dev/../manufacturer ] ; then
-               manufacturer="`sed -e 's@^[ -]\{1,\}\|[ -]\{1,\}$@@g;s@[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_0123456789]@@g' < $controller_dev/../manufacturer`"
+               manufacturer="`sed -e 's@^[ -]\{1,\}\|[ -]\{1,\}$@@g;s@[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789-]@@g' < $controller_dev/../manufacturer`"
                fi
                if [ -z "$product" -o -z "$manufacturer" ] ; then
                        read idvendor < $controller_dev/../idVendor
                fi
                if [ -z "$product" -o -z "$manufacturer" ] ; then
                        read idvendor < $controller_dev/../idVendor