Adding casper 1.81+debian-2.
[live-boot-grml.git] / scripts / casper
index 8cfc0df..545942e 100644 (file)
@@ -14,7 +14,7 @@ home_snapshot_label="home-sn"
 USERNAME="casper"
 USERFULLNAME="Live session user"
 HOSTNAME="live"
-BUILD_SYSTEM="Debian"
+BUILD_SYSTEM="Custom"
 
 mkdir -p $mountpoint
 
@@ -71,8 +71,12 @@ parse_cmdline ()
                 export CASPERGETTY=1 ;;
             bootfrom=*|live-media=*)
                 export LIVEMEDIA=${x#*=} ;;
+            live-media-encryption=*|encryption=*)
+                export LIVEMEDIA_ENCRYPTION=${x#*=} ;;
             live-media-timeout=*)
                 export LIVEMEDIA_TIMEOUT=${x#live-media-timeout=} ;;
+            live-media-offset=*)
+                export LIVEMEDIA_OFFSET=${x#live-media-offset=} ;;
             locale=*|debian-installer/locale=*)
                 export LOCALE=${x#*=} ;;
             keyb=*|kbd-chooser/method=*)
@@ -85,6 +89,8 @@ parse_cmdline ()
                 export KVARIANT=${x#*=} ;;
             kmodel=*|console-setup/modelcode=*)
                 export KMODEL=${x#*=} ;;
+            module=*)
+                export MODULE=${x#module=} ;;
             preseed/file=*|file=*)
                 export LOCATION="${x#*=}" ;;
             */*=*)
@@ -93,7 +99,7 @@ parse_cmdline ()
                 PRESEEDS="${PRESEEDS}\"${question}=${value}\" "
                 ;;
             console=*)
-                export DEFCONSOLE=$(sed -e 's%.*console=%console=%' /proc/cmdline) ;;
+                export DEFCONSOLE="${x#*=}" ;;
         esac
     done
 
@@ -107,6 +113,10 @@ parse_cmdline ()
             export NETBOOT
         fi
     fi
+
+    if [ -z "${MODULE}" ]; then
+        MODULE=order
+    fi
 }
 
 is_casper_path() {
@@ -124,7 +134,7 @@ is_casper_path() {
 get_backing_device() {
     case "$1" in
         *.squashfs|*.ext2)
-            echo $(setup_loop "$1" "loop" "/sys/block/loop*")
+            echo $(setup_loop "$1" "loop" "/sys/block/loop*" '0' "${LIVEMEDIA_ENCRYPTION}")
             ;;
         *.dir)
             echo "directory"
@@ -165,8 +175,7 @@ is_nice_device() {
     return 1
 }
 
-is_supported_fs ()
-{
+is_supported_fs () {
     # FIXME: do something better like the scan of supported filesystems
     fstype="${1}"
     case ${fstype} in
@@ -224,7 +233,7 @@ do_netmount() {
 
     modprobe "${MP_QUIET}" af_packet # For DHCP
 
-    ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf
+    ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf | tee /netboot.config
 
     if [ "${NFSROOT}" = "auto" ]; then
         NFSROOT=${ROOTSERVER}:${ROOTPATH}
@@ -396,34 +405,52 @@ setup_unionfs() {
     # Let's just mount the read-only file systems first
     rofsstring=""
     rofslist=""
-    if [ "${NETBOOT}" == "nfs" ] ; then
+    if [ "${NETBOOT}" = "nfs" ] ; then
         roopt="nfsro" # go aroung a bug in nfs-unionfs locking
     else
         roopt="ro"
     fi
 
+    # Read image names from ${MODULE}.lst if it exists
+    if [ -e "${image_directory}/${MODULE}.lst" ]; then
+        for image in $(cat "${image_directory}/${MODULE}.lst"); do
+            image_string="${image_string} ${image_directory}/${image}";
+        done
+    else
+        # If ${MODULE}.lst does not exist, create a list of images
+        for image_type in "ext2" "squashfs" "dir"; do
+            for image in "${image_directory}"/*."${image_type}"; do
+               if [ -e "${image}" ]; then
+                   image_string="${image_string} ${image}";
+               fi
+            done
+        done
+        # Now sort the list
+        image_string=$(echo ${image_string} | sed -e 's/ /\n/g' | sort )
+    fi
+
     mkdir -p "${croot}"
-    for image_type in "ext2" "squashfs" "dir" ; do
-        for image in "${image_directory}"/*."${image_type}"; do
-            imagename=$(basename "${image}")
-            if [ -d "${image}" ]; then
-                # it is a plain directory: do nothing
-                rofsstring="${image}=${roopt}:${rofsstring}"
-                rofslist="${image} ${rofslist}"
-            elif [ -f "${image}" ]; then
-                backdev=$(get_backing_device "$image")
-                fstype=$(get_fstype "${backdev}")
-                if [ "${fstype}" = "unknown" ]; then
-                    panic "Unknown file system type on ${backdev} (${image})"
-                fi
-                mkdir -p "${croot}/${imagename}"
-                mount -t "${fstype}" -o ro "${backdev}" "${croot}/${imagename}" || panic "Can not mount $backdev ($image) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=${roopt}:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
+    for image in ${image_string}; do
+        imagename=$(basename "${image}")
+        if [ -d "${image}" ]; then
+            # it is a plain directory: do nothing
+            rofsstring="${image}=${roopt}:${rofsstring}"
+            rofslist="${image} ${rofslist}"
+        elif [ -f "${image}" ]; then
+            backdev=$(get_backing_device "$image")
+            fstype=$(get_fstype "${backdev}")
+            if [ "${fstype}" = "unknown" ]; then
+                panic "Unknown file system type on ${backdev} (${image})"
             fi
-        done
+            mkdir -p "${croot}/${imagename}"
+            mount -t "${fstype}" -o ro "${backdev}" "${croot}/${imagename}" || panic "Can not mount $backdev ($image) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=${roopt}:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
+        fi
     done
+
     rofsstring=${rofsstring%:}
 
     mkdir -p /cow
+
     cowdevice="tmpfs"
     cow_fstype="tmpfs"
 
@@ -482,6 +509,12 @@ check_dev ()
     if [ -z "${devname}" ]; then
         devname=$(sys2dev "${sysdev}")
     fi
+
+    if [ -n "${LIVEMEDIA_OFFSET}" ]; then
+        loopdevname=$(setup_loop "${devname}" "loop" "/sys/block/loop*" "${LIVEMEDIA_OFFSET}" '')
+        devname="${loopdevname}" 
+    fi
+
     fstype=$(get_fstype "${devname}")
     if is_supported_fs ${fstype}; then
         mount -t ${fstype} -o ro "${devname}" $mountpoint || continue
@@ -492,6 +525,10 @@ check_dev ()
             umount $mountpoint
         fi
     fi
+
+    if [ -n "${LIVEMEDIA_OFFSET}" ]; then
+        losetup -d "${loopdevname}"
+    fi
     return 1
 }
 
@@ -576,7 +613,7 @@ mountroot() {
         fi
     else
         # Scan local devices for the image
-        for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
+        for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do
             livefs_root=$(find_livefs $i)
             if [ -n "${livefs_root}" ]; then
                 break
@@ -589,15 +626,15 @@ mountroot() {
         panic "Unable to find a medium containing a live file system"
     fi
 
-    if [ -n "${TORAM}" ]; then
+    if [ "${TORAM}" ]; then
         live_dest="ram"
-    elif [ -n "${TODISK}" ]; then
+    elif [ "${TODISK}" ]; then
         live_dest="${TODISK}"
     fi
-    if [ -n "${live_dest}" ]; then
-        [ "$quiet" != "y" ] && log_begin_msg "Copying live_media to ${live_dest}"
+    if [ "${live_dest}" ]; then
+        log_begin_msg "Copying live_media to ${live_dest}"
         copy_live_to "${livefs_root}" "${live_dest}"
-        [ "$quiet" != "y" ] && log_end_msg
+        log_end_msg
     fi
 
     mount_images_in_directory "${livefs_root}" "${rootmnt}"