Adding upstream version 1.157.3.
[live-boot-grml.git] / scripts / live-helpers
index f6b8b8b..d5ad29f 100644 (file)
@@ -6,10 +6,19 @@ then
        export PATH="${PATH}:/usr/lib/klibc/bin"
 fi
 
+# handle upgrade path from old udev (using udevinfo) to
+# recent versions of udev (using udevadm info)
+if [ -x /sbin/udevadm ]
+then
+       udevinfo='/sbin/udevadm info'
+else
+       udevinfo='udevinfo'
+fi
+
 sys2dev ()
 {
        sysdev=${1#/sys}
-       echo "/dev/$(udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
+       echo "/dev/$($udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
 }
 
 subdevices ()
@@ -77,7 +86,7 @@ get_fstype ()
            return
        fi
 
-       eval $(fstype ${1} 2>/dev/null)
+       eval $(fstype ${1} 2>/dev/null)
 
        if [ "${FSTYPE}" != "unknown" ]
        then
@@ -95,7 +104,7 @@ where_is_mounted ()
        if grep -q "^${device} " /proc/mounts
        then
                # return the first found
-               grep "^${device} " /proc/mounts | cut -f2 -d ' '
+               grep -m1 "^${device} " /proc/mounts | cut -f2 -d ' '
        fi
 }
 
@@ -206,7 +215,7 @@ setup_loop ()
                        dev=$(sys2dev "${loopdev}")
                        options=''
 
-                       if [ -n ${readonly} ]
+                       if [ -n "${readonly}" ]
                        then
                                if losetup --help 2>&1 | grep -q -- "-r\b"
                                then
@@ -299,6 +308,13 @@ find_cow_device ()
        cow_backing="/${pers_label}-backing"
        black_listed_devices="${2}"
 
+       if [ -z "${PERSISTENT_PATH}" ]
+       then
+               pers_fpath=${cow_backing}/${pers_label}
+       else
+               pers_fpath=${cow_backing}/${PERSISTENT_PATH}/${pers_label}
+       fi
+
        for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram | grep -v fd)
        do
                for dev in $(subdevices "${sysblock}")
@@ -311,30 +327,60 @@ find_cow_device ()
                                break
                        fi
 
+                       # Checking for a luks device
+                       if [ "${PERSISTENT}" = "cryptsetup" ] && [ -e /sbin/cryptsetup ] && /sbin/cryptsetup isLuks ${devname}
+                       then
+                               while true
+                               do
+                                       load_keymap
+
+                                       /lib/cryptsetup/askpass "Enter passphrase for ${pers_label} on ${devname}: " | /sbin/cryptsetup -T 1 luksOpen ${devname} $(basename ${devname}) --key-file=-
+                                       error=${?}
+
+                                       devname="/dev/mapper/$(basename ${devname})"
+
+                                       if [ 0 -eq ${error} ]
+                                       then
+                                               unset error
+                                               break
+                                       fi
+
+                                       echo
+                                       echo -n "There was an error decrypting ${devname} ... Retry? [Y/n] " >&6
+                                       read answer
+
+                                       if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
+                                       then
+                                               unset answer
+                                               break
+                                       fi
+                               done
+                       fi
+
                        if [ "$(/lib/udev/vol_id -l ${devname} 2>/dev/null)" = "${pers_label}" ]
                        then
                                echo "${devname}"
-                               return
+                               return 0
                        fi
 
                        if [ "${PERSISTENT}" = "nofiles" ]
                        then
                                # do not mount the device to find for image files
                                # just skip this
-                               break
+                               continue
                        fi
 
                        case "$(get_fstype ${devname})" in
-                               vfat|ext2|ext3|jffs2)
+                               vfat|ext2|ext3|ext4|jffs2)
                                        mkdir -p "${cow_backing}"
                                        if ! try_mount "${devname}" "${cow_backing}" "rw"
                                        then
                                                break
                                        fi
 
-                                       if [ -f "${cow_backing}/${pers_label}" ]
+                                       if [ -f "${pers_fpath}" ]
                                        then
-                                               echo $(setup_loop "${cow_backing}/${pers_label}" "loop" "/sys/block/loop*")
+                                               echo $(setup_loop "${pers_fpath}" "loop" "/sys/block/loop*")
                                                return 0
                                        else
                                                umount ${cow_backing}
@@ -345,6 +391,7 @@ find_cow_device ()
                        esac
                done
        done
+       return 1
 }
 
 find_files ()