grml-reboot: detect virtual machines + assume noprompt for them, add imvirt to Depends
[grml-etc.git] / etc / init.d / grml-reboot
index c5e737c..c90fa8c 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 # Filename:      grml-reboot
 # Purpose:       reboot grml system
 # Authors:       grml-team (grml.org)
@@ -14,7 +14,8 @@ export PATH=/sbin:/bin:/usr/bin:/usr/sbin
 cd /
 
 # Clean input/output
-exec >/dev/console 2>&1 </dev/console
+CONSOLE=/dev/console
+[ -c "$CONSOLE" ] && exec >"$CONSOLE" 2>&1 <"$CONSOLE"
 
 # default variables
 INSTALLED=false
@@ -48,14 +49,14 @@ if ! $INSTALLED ; then
    DEVICE=""
    if [ -n "$CDROM" ] ; then
      DEVICE="${CDROM##/dev/}"
-     DEVICE="${DEVICE%%[0-9]*}"
+     [ -d /sys/block/${DEVICE} ] || DEVICE="${DEVICE%%[0-9]*}"
 
      if [ -n "$DEVICE" ] ; then
        # is it a removable device?
        [ "$(cat /sys/block/${DEVICE}/removable 2>/dev/null)" = "1" ] && REMOVABLE=true
        # is it a usb device?
        readlink /sys/block/${DEVICE} 2>/dev/null | grep -q '/usb' && USB_DEVICE=true
-       $USB_DEVICE && USB_INFO="$(cat /sys/block/${DEVICE}/device/model 2>/dev/null)"
+       $USB_DEVICE && USB_INFO=" ($(cat /sys/block/${DEVICE}/device/model 2>/dev/null))"
      fi
    fi
 fi
@@ -78,8 +79,8 @@ case "$0" in
 esac
 
 mysleep() {
-  for i in $(seq 1 40) ; do
-    usleep 75000
+  for i in $(seq 1 30) ; do
+    sleep 0.1
     echo -n "$1.${NORMAL}"
   done
   echo ""
@@ -148,6 +149,12 @@ esac
 [ -r /etc/noprompt ] && NOPROMPT=true
 [ -r /etc/noeject ]  && NOPROMPT=true && NOEJECT=true
 
+if [ "$(/usr/bin/imvirt 2>/dev/null)" != "Physical" ] ; then
+  log_begin_msg "System seems to be a virtual machine, assuming noprompt as default."
+  NOPROMPT=true
+  log_end_msg 0
+fi
+
 # Turn on autoeject of CD-ROMs
 if $NOEJECT ; then
    for dev in /proc/sys/dev/cdrom*/lock;      do [ -f "$dev" ] && echo 0 > "$dev"; done