Replacing expr usage in initscript for eject boot media with something less error...
authorDaniel Baumann <mail@daniel-baumann.ch>
Mon, 6 May 2013 18:42:55 +0000 (20:42 +0200)
committerDaniel Baumann <mail@daniel-baumann.ch>
Mon, 6 May 2013 18:43:03 +0000 (20:43 +0200)
bin/boot-init.sh

index 83f37bc..3027d28 100755 (executable)
@@ -80,10 +80,17 @@ get_boot_device()
 device_is_USB_flash_drive()
 {
        # remove leading "/dev/" and all trailing numbers from input
-       DEVICE=$(expr substr ${1} 6 3)
+       DEVICE=$(echo ${1} | sed -e 's|/dev/||' -e 's|[0-9].*$||')
 
        # check that device starts with "sd"
-       [ "$(expr substr ${DEVICE} 1 2)" != "sd" ] && return 1
+       case "${DEVICE}" in
+               sd*)
+                       ;;
+
+               *)
+                       return 1
+                       ;;
+       esac
 
        # check that the device is an USB device
        if readlink /sys/block/${DEVICE} | grep -q usb