## Casper helper functions, used by casper on boot and by casper-snapshot
-if [ "${BUILD_SYSTEM}" == "Ubuntu" ]; then
+if [ "${BUILD_SYSTEM}" = "Ubuntu" ]; then
MP_QUIET="-Q"
-else
+elif [ "${BUILD_SYSTEM}" = "Debian" ]; then
MP_QUIET="-q"
+else
+ MP_QUIET=""
fi
if [ ! -x "/bin/fstype" ]; then
local fspath=$1
local module=$2
local pattern=$3
+ local offset=$4
+ local encryption=$5
- modprobe "${MP_QUIET}" -b "$module"
+ modprobe ${MP_QUIET} -b "$module"
udevsettle
for loopdev in $pattern; do
if [ "$(cat $loopdev/size)" -eq 0 ]; then
dev=$(sys2dev "${loopdev}")
- losetup "$dev" "$fspath"
+ options=''
+ if [ 0 -lt "${offset}" ]; then
+ options="${options} -o ${offset}"
+ fi
+ if [ -z "${encryption}" ]; then
+ losetup ${options} "${dev}" "${fspath}"
+ else
+ # Loop AES encryption
+ while true; do
+ 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
fi