Adding casper 1.77+debian-4.
[live-boot-grml.git] / scripts / casper
index 558a29b..f932c65 100644 (file)
@@ -23,6 +23,10 @@ export USERNAME USERFULLNAME HOSTNAME BUILD_SYSTEM
 
 . /scripts/casper-helpers
 
+if [ ! -f /casper.vars ]; then
+    touch /casper.vars
+fi
+
 parse_cmdline ()
 {
     # looking for casper specifics options as kernel parameters
@@ -44,7 +48,7 @@ parse_cmdline ()
                 export NETBOOT=${x#netboot=} ;;
             toram)
                 export TORAM=1 ;;
-            todisk=)
+            todisk=*)
                 export TODISK=${x#todisk=} ;;
             showmounts)
                 export SHOWMOUNTS=1 ;;
@@ -64,6 +68,8 @@ parse_cmdline ()
                 export LIVEMEDIA=${x#bootfrom=} ;;
             live-media=*)
                 export LIVEMEDIA=${x#live-media=} ;;
+            live-media-timeout=*)
+                export LIVEMEDIA_TIMEOUT=${x#live-media-timeout=} ;;
             debian-installer/locale=*)
                 export LOCALE=${x#debian-installer/locale=} ;;
             locale=*)
@@ -141,17 +147,6 @@ mount_images_in_directory() {
     fi
 }
 
-get_fstype() {
-    local FSTYPE
-    local FSSIZE
-    eval $(fstype < $1)
-    if [ "$FSTYPE" != "unknown" ]; then
-        echo $FSTYPE
-        return 0
-    fi
-    /lib/udev/vol_id -t $1 2>/dev/null
-}
-
 is_nice_device() {
     sysfs_path="${1#/sys}"
     if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"; then
@@ -177,7 +172,7 @@ copy_live_to() {
     copytodev="${2}"
     copyto="${copyfrom}_swap"
 
-    size=$(used_fs_size "null" "${copyfrom}")
+    size=$(fs_size "" ${copyfrom} "used")
 
     if [ "${copytodev}" = "ram" ]; then
         # copying to ram:
@@ -189,29 +184,28 @@ copy_live_to() {
     else
         # it should be a writable block device
         if [ -b "${copytodev}" ]; then
-            free_string="space"
-            freespace="$(df -k ${copytodev} | grep -s ${copytodev} | awk '{print $4}')"
-            fstype="$(get_fstype ${devname})"
             dev="${copytodev}"
+            free_string="space"
+            fstype=$(get_fstype "${dev}")
+            freespace=$(fs_size "${dev}")
         else
+            [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device."
             return 1
         fi
     fi
-    if [ ! ${freespace} -lt ${size}  ] ; then
-        [ "$quiet" != "y" ] && log_begin_msg "Not enough free ${free_string} to copy live media in ${copytodev}."
-        [ "$quiet" != "y" ] && log_end_msg
+    if [ "${freespace}" -lt "${size}" ] ; then
+        [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}."
         return 1
     fi
 
     # begin copying..
-    [ "$quiet" != "y" ] && log_begin_msg "Copying live media to ${copytodev}..." 
     mkdir "${copyto}"
+    echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
     mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}"
     cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files
     umount ${copyfrom}
     mount -r -o move ${copyto} ${copyfrom}
     rmdir ${copyto}
-    [ "$quiet" != "y" ] && log_end_msg
     return 0
 }
 
@@ -281,7 +275,7 @@ do_snap_copy ()
     todir="${2}"
     snap_type="${3}"
 
-    #size=$(used_fs_size "${fromdev}")
+    size=$(fs_size "${fromdev}" "" "used")
 
     if [ -b "${fromdev}" ]; then
         # look for free mem
@@ -492,12 +486,19 @@ check_dev ()
 }
 
 find_livefs() {
+    timeout="${1}"
     # first look at the one specified in the command line
     if [ ! -z "${LIVEMEDIA}" ]; then
         if check_dev "null" "${LIVEMEDIA}"; then
             return 0
         fi
     fi
+    # don't start autodetection before timeout has expired
+    if [ -n "${LIVEMEDIA_TIMEOUT}" ]; then
+        if [ "${timeout}" -lt "${LIVEMEDIA_TIMEOUT}" ]; then
+            return 1
+        fi
+    fi
     # or do the scan of block devices
     for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
         devname=$(sys2dev "${sysblock}")
@@ -513,7 +514,7 @@ find_livefs() {
                 fi
             done
         elif [ "${fstype}" = "squashfs" -o \
-                "${fstype}" = "ext3" -o \
+                "${fstype}" = "ext3" -o \
                 "${fstype}" = "ext2" ]; then
             # This is an ugly hack situation, the block device has
             # an image directly on it.  It's hopefully
@@ -566,8 +567,8 @@ mountroot() {
     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
-            livefs_root=$(find_livefs)
-            if [ ! -z "${livefs_root}" ]; then
+            livefs_root=$(find_livefs $i)
+            if [ -n "${livefs_root}" ]; then
                 break
             fi
             sleep 1
@@ -578,10 +579,15 @@ mountroot() {
         panic "Unable to find a medium containing a live file system"
     fi
 
-    if [ ! -z "${TORAM}" ]; then
-        copy_live_to "${livefs_root}" "ram"
-    elif [ ! -z "${TODISK}" ]; then
-        copy_live_to "${livefs_root}" "${TODISK}"
+    if [ -n "${TORAM}" ]; then
+        live_dest="ram"
+    elif [ -n "${TODISK}" ]; then
+        live_dest="${TODISK}"
+    fi
+    if [ -n "${live_dest}" ]; then
+        [ "$quiet" != "y" ] && log_begin_msg "Copying live_media to ${live_dest}"
+        copy_live_to "${livefs_root}" "${live_dest}"
+        [ "$quiet" != "y" ] && log_end_msg
     fi
 
     mount_images_in_directory "${livefs_root}" "${rootmnt}"
@@ -595,6 +601,12 @@ mountroot() {
     run_scripts /scripts/casper-bottom
     [ "$quiet" != "y" ] && log_end_msg
 
+    if [ -f /casper.vars ]; then
+        echo "Casper vars:"
+        cat /casper.vars
+    fi
+
+    echo "Casper Log:"
     exec 1>&6 6>&-
     exec 2>&7 7>&-
     cp casper.log "${rootmnt}/var/log/"