Run blkid under timeout command as well when accessing floppy device
[grml-autoconfig.git] / autoconfig.functions
index 06265e8..cacd5b9 100755 (executable)
@@ -15,8 +15,10 @@ umask 022
 
 # old linuxrc version:
 [ -d /cdrom ]      && export LIVECD_PATH=/cdrom
-# new initramfs layout:
+# initramfs layout until around December 2012:
 [ -d /live/image ] && export LIVECD_PATH=/live/image
+# initramfs layout since around December 2012:
+[ -d /lib/live/mount/medium ] && export LIVECD_PATH=/lib/live/mount/medium
 
 # Ignore these signals in non-interactive mode: INT, TERM, SEGV
 [ -z "$PS1" ] && trap "" 2 3 11
@@ -38,13 +40,12 @@ if [ -z "$CMDLINE" ]; then
   # if CMDLINE was set from the outside, we're debugging.
   # otherwise, take CMDLINE from Kernel and config files.
   CMDLINE="$(cat /proc/cmdline)"
-  [ -d /cdrom/bootparams/ ]      && CMDLINE="$CMDLINE $(cat /cdrom/bootparams/* | tr '\n' ' ')"
-  [ -d /live/image/bootparams/ ] && CMDLINE="$CMDLINE $(cat /live/image/bootparams/* | tr '\n' ' ')"
+  [ -d ${LIVECD_PATH}/bootparams/ ] && CMDLINE="$CMDLINE $(cat ${LIVECD_PATH}/bootparams/* | tr '\n' ' ')"
   modprobe 9p 2>/dev/null || true
   if grep -q 9p /proc/filesystems ; then
-      local TAG="grml-parameters"
+      TAG="grml-parameters"
       if grep -q "$TAG" /sys/bus/virtio/devices/*/mount_tag 2>/dev/null ; then
-          local MOUNTDIR="$(mktemp -d)"
+          MOUNTDIR="$(mktemp -d)"
           mount -t 9p -o trans=virtio,ro "$TAG" "$MOUNTDIR"
           CMDLINE="$CMDLINE $(cat "$MOUNTDIR"/* 2>/dev/null | tr '\n' ' ')"
           umount "$MOUNTDIR"
@@ -500,10 +501,10 @@ config_time(){
 
 # {{{ print kernel info
 config_kernel(){
-  if $VIRTUAL ; then
-    einfo "Running Linux Kernel $KERNEL $VMWARE" ; eend 0
-  else
+  if $VIRTUAL && [ -n "$VIRTUAL_ENV" ] ; then
     einfo "Running Linux Kernel $KERNEL inside $VIRTUAL_ENV" ; eend 0
+  else
+    einfo "Running Linux Kernel $KERNEL" ; eend 0
   fi
 
   if [ -r /proc/cpuinfo ] ; then
@@ -1126,7 +1127,7 @@ fi
 
 # {{{ display hostkeys of SSH server
 config_display_ssh_fingerprints() {
-  if ! find /etc/ssh/ -name ssh_host_\*_key >/dev/null 2>&1 ; then
+  if ! ls /etc/ssh/ssh_host_\*_key >/dev/null 2>&1 ; then
     return 0 # no SSH host keys present
   fi
 
@@ -1570,6 +1571,7 @@ DCSMP="/mnt/grml"
 GRMLCFG="$(getbootparam 'autoconfig' 2>>$DEBUG)"
 [ -n "$GRMLCFG" ] || GRMLCFG="GRMLCFG"
 if checkbootparam 'noautoconfig' || checkbootparam 'forensic' ; then
+  DCSDIR="${LIVECD_PATH}" # set default so it works for "scripts" boot option as expected
   ewarn "Skipping running automount of device(s) labeled $GRMLCFG as requested." ; eend 0
 else
   if [ -z "$INSTALLED" ] ; then
@@ -1583,9 +1585,9 @@ else
       eindent
       # We do need the following fix so floppy disk is available to blkid in any case :-/
       if [ -r /dev/fd0 ] ; then
-        einfo "Floppy device detected. Trying to access floppy disk."
+        einfo "Floppy device detected. Trying to access floppy disk (this might take a few seconds)."
         if timeout 4 dd if=/dev/fd0 of=/dev/null bs=512 count=1 >>$DEBUG 2>&1 ; then
-           blkid /dev/fd0 >>$DEBUG 2>&1
+           timeout 4 blkid /dev/fd0 >>$DEBUG 2>&1
         fi
       fi
       DCSDEVICE=$(blkid -t LABEL=$GRMLCFG | head -1 | awk -F: '{print $1}')
@@ -1608,7 +1610,7 @@ else
 
     # if not specified/present then assume default:
     if [ -z "$DCSDEVICE" ]; then
-      DCSDIR="/live/image"
+      DCSDIR="${LIVECD_PATH}"
     else
       eindent
       einfo "debs, config, scripts are read from $DCSDEVICE." ; eend 0
@@ -1631,7 +1633,7 @@ else
   fi
 fi
 
-if [ -n "$DCSDIR" -a "$DCSDIR" != "/live/image" ] ; then
+if [ -n "$DCSDIR" -a "$DCSDIR" != "${LIVECD_PATH}" ] ; then
   einfo "Debs, config, scripts (if present) will be read from $DCSDIR." ; eend 0
 elif checkbootparam 'debs' || checkbootparam 'config' || checkbootparam 'scripts'; then
   einfo "Debs, config, scripts will be read from the live image directly." ; eend 0
@@ -1703,7 +1705,7 @@ if checkbootparam 'scripts' || [ "$DCSMP" = "/mnt/grmlcfg" ]; then
        sh -c $SCRIPTS
      elif [ -d "$SCRIPTS" ]; then
        einfo "Bootparameter scripts found. Trying to execute from directory ${SCRIPTS}:"
-       run-parts $SCRIPTS
+       run-parts --regex '.*' $SCRIPTS
      else
        einfo "Bootparameter scripts found. Trying to execute ${SCRIPTS}:"
        sh -c $SCRIPTS
@@ -2081,7 +2083,7 @@ config_tohd()
 
      if mount -o rw "$TARGET" "$MOUNTDIR" ; then
         einfo "Copyring live system to $TARGET - this might take a while"
-        rsync -a --progress /live/image/live $MOUNTDIR
+        rsync -a --progress ${LIVECD_PATH}/live $MOUNTDIR
         sync
         umount "$MOUNTDIR"
         eend $?