Adding live-initramfs 1.87.4-1.
[live-boot-grml.git] / scripts / live-helpers
index 8402d93..8f28f3b 100644 (file)
@@ -1,4 +1,4 @@
-## Casper helper functions, used by casper on boot and by casper-snapshot
+## live-initramfs helper functions, used by live-initramfs on boot and by live-snapshot
 
 if [ "${BUILD_SYSTEM}" = "Ubuntu" ]; then
     MP_QUIET="-Q"
@@ -108,11 +108,20 @@ fs_size ()
     echo "${size}"
 }
 
+load_keymap()
+{
+       # Load custom keymap
+       if [ -x /bin/loadkeys -a -r /etc/boottime.kmap.gz ]; then
+               loadkeys /etc/boottime.kmap.gz
+       fi
+}
+
 setup_loop() {
     local fspath=$1
     local module=$2
     local pattern=$3
     local offset=$4
+    local encryption=$5
 
     modprobe ${MP_QUIET} -b "$module"
     udevsettle
@@ -120,10 +129,35 @@ setup_loop() {
     for loopdev in $pattern; do
         if [ "$(cat $loopdev/size)" -eq 0 ]; then
             dev=$(sys2dev "${loopdev}")
-            if [ -n "$offset" ]; then
-                losetup -o "$offset" "$dev" "$fspath"
+            options=''
+            if [ 0 -lt "${offset}" ]; then
+                options="${options} -o ${offset}"
+            fi
+            if [ -z "${encryption}" ]; then
+                losetup ${options} "${dev}" "${fspath}"
             else
-                losetup "$dev" "$fspath"
+                # Loop AES encryption
+                while true; do
+                                            load_keymap
+                    echo -n "Enter passphrase for ${fspath}: " >&6
+                    read -s passphrase
+                    echo "${passphrase}" > /tmp/passphrase
+                    exec 9</tmp/passphrase
+                    /sbin/losetup ${options} -e "${encryption}" -p 9 "${dev}" "${fspath}"
+                    error=$?
+                    exec 9<&-
+                    rm -f /tmp/passphrase
+                    if [ 0 -eq ${error} ]; then
+                        unset error
+                        break
+                    fi
+                    echo -n "Something went wrong... Retry? [YES/no] " >&6
+                    read answer
+                    if [ 'no' = "${answer}" ]; then
+                        unset answer
+                        break
+                    fi
+                done
             fi
             echo "$dev"
             return 0
@@ -170,7 +204,7 @@ find_cow_device() {
 }
 
 find_files()
-# return the first of $filenames found on vfat and ext2 devices
+# return the first of $filenames found on vfat and ext2/ext3 devices
 # FIXME: merge with above function
 {
     filenames="${1}"
@@ -179,7 +213,7 @@ find_files()
         for dev in $(subdevices "${sysblock}"); do
             devname=$(sys2dev "${dev}")
             devfstype="$(get_fstype ${devname})"
-            if [ "${devfstype}" = "vfat" ] ||  [ "${devfstype}" = "ext2" ] ; then # FIXME: all supported block devices should be scanned
+            if [ "${devfstype}" = "vfat" ] ||  [ "${devfstype}" = "ext2" ] || [ "${devfstype}" = "ext3" ]; then # FIXME: all supported block devices should be scanned
                 mkdir -p "${snap_backing}"
                 try_mount "${devname}" "${snap_backing}" "ro"
                 for filename in ${filenames}; do