Run blkid under timeout command as well when accessing floppy device
[grml-autoconfig.git] / autoconfig.functions
index 2a3dd66..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
@@ -690,40 +691,44 @@ config_fix_passwd(){
 # {{{ CD Checker
 config_testcd(){
 if checkbootparam 'testcd' ; then
-   einfo "Checking CD data integrity as requested by '${WHITE}testcd${NORMAL}' boot option."
+  einfo "Checking CD data integrity as requested by '${WHITE}testcd${NORMAL}' boot option."
+  eindent
 
-   ERROR=0
-   FOUND_FILE=0
+  local ERROR=true
+  local FOUND_FILE=false
+  local logfile='/tmp/md5sum.log'
 
-   rm -f /tmp/md5sum.log
-   for md5 in $(find "${LIVECD_PATH}" -name md5sums) ; do
-      einfo "Checking files against $md5, this may take a while..."
+  rm -f "$logfile"
 
-      FOUND_FILE=1
-      ( cd $(dirname "$md5") && md5sum -c $(basename "$md5") ; RC=$?)  |& tee -a /tmp/md5sum.log
+  for md5 in $(find "${LIVECD_PATH}" -name md5sums) ; do
+    einfo "Checking files against $md5, this may take a while..."
 
-      if [ $RC -ne 0 ] ; then
-         ERROR=1
-      fi
-   done
+    FOUND_FILE=true
+    OLD_PWD=$(pwd)
+    cd $(dirname "$md5")
+    md5sum -c $(basename "$md5") |& tee -a "${logfile}"
+    if [ $pipestatus[1] -eq 0 ] ; then
+      ERROR=false
+    fi
+    cd "${OLD_PWD}"
+  done
 
-   if [ $FOUND_FILE -eq 0 ] ; then
-      echo "${RED} *** Error: Could not find md5sum file.                           ***"
-      return
-   fi
+  if ! $FOUND_FILE ; then
+    eerror 'Error: Could not find md5sum file' ; eend 1
+    return
+  fi
 
-   if [ "$ERROR" -eq 0 ]; then
-      einfo "Everything looks OK" ; eend 0
-   else
-      eerror 'Checksum failed for theses files:' ; eend 1
-      egrep -v '(^md5sum:|OK$)' /tmp/md5sum.log
-      eerror 'Data on the grml medium is possibly incomplete/damaged or...'
-      eerror '... RAM of your computer is broken.' ; eend 1
-      einfon "Hit return to continue, or press the reset button to quit."
-     read a
-   fi
+  if ! $ERROR ; then
+    einfo "Everything looks OK" ; eend 0
+  else
+    eerror 'Checksum failed for theses files:' ; eend 1
+    egrep -v '(^md5sum:|OK$)' "${logfile}"
+    eerror 'Data on the medium is possibly incomplete/damaged or RAM of your system is broken.' ; eend 1
+    einfon "Hit return to continue, or press the power button to shut down system."
+    read a
+  fi
 
-   eend 0
+  eoutdent
 fi
 }
 # }}}
@@ -1117,6 +1122,22 @@ if checkbootparam 'ssh' ; then
    eoutdent
 fi
 }
+
+# }}}
+
+# {{{ display hostkeys of SSH server
+config_display_ssh_fingerprints() {
+  if ! ls /etc/ssh/ssh_host_\*_key >/dev/null 2>&1 ; then
+    return 0 # no SSH host keys present
+  fi
+
+  einfo "SSH key fingerprints:"
+  for file in /etc/ssh/ssh_host_*_key ; do
+    einfon
+    ssh-keygen -l -f $file
+  done | column -t
+  eend $?
+}
 # }}}
 
 # {{{ autostart of x11vnc
@@ -1469,6 +1490,7 @@ config_stats() {
  fi
 }
 # }}}
+
 # {{{ fix/workaround for unionfs
 fix_unionfs(){
   if [ -z "$INSTALLED" ]; then
@@ -1549,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
@@ -1562,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}')
@@ -1587,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
@@ -1610,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
@@ -1682,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
@@ -2060,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 $?