Support older kernel versions in check for removable usb device
authorMichael Prokop <mika@grml.org>
Tue, 24 Mar 2009 16:41:15 +0000 (17:41 +0100)
committerMichael Prokop <mika@grml.org>
Tue, 24 Mar 2009 16:41:15 +0000 (17:41 +0100)
debian/changelog
grml2usb

index bbd13af..61b0ff9 100644 (file)
@@ -11,8 +11,10 @@ grml2usb (0.9.3) UNRELEASED; urgency=low
   * Mention the Debian package in the error message (thanks to
     Lothar Speil for the bugreport).
   * Mention grml-repository in the docs.
+  * Support older kernel versions in check for removable usb device.
+    (Thanks to Ralf Gross for the report and relevant information.)
 
- -- Michael Prokop <mika@grml.org>  Thu, 12 Mar 2009 23:10:02 +0100
+ -- Michael Prokop <mika@grml.org>  Tue, 24 Mar 2009 17:40:08 +0100
 
 grml2usb (0.9.2) unstable; urgency=low
 
index 3c7bfb3..3e9475e 100755 (executable)
--- a/grml2usb
+++ b/grml2usb
@@ -894,13 +894,18 @@ def check_for_usbdevice(device):
     """
 
     usbdevice = re.match(r'/dev/(.*?)\d*$', device).group(1)
-    usbdevice = os.path.realpath('/sys/class/block/' + usbdevice + '/removable')
-    if os.path.isfile(usbdevice):
-        is_usb = open(usbdevice).readline()
-        if is_usb == "1":
+    # newer systems:
+    usbdev = os.path.realpath('/sys/class/block/' + usbdevice + '/removable')
+    if not os.path.isfile(usbdev):
+       # Ubuntu with kernel 2.6.24 for example:
+       usbdev = os.path.realpath('/sys/block/' + usbdevice + '/removable')
+
+    if os.path.isfile(usbdev):
+        is_usb = open(usbdev).readline()
+        if is_usb.find("1"):
             return 0
-        else:
-            return 1
+
+    return 1
 
 
 def check_for_fat(partition):