Replace 'modprobe -l' command with modinfo(8) command line
[grml-autoconfig.git] / autoconfig.functions
index 6e0a6b8..012cdf8 100755 (executable)
@@ -40,6 +40,17 @@ if [ -z "$CMDLINE" ]; then
   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' ' ')"
+  modprobe 9p 2>/dev/null || true
+  if grep -q 9p /proc/filesystems ; then
+      local TAG="grml-parameters"
+      if grep -q "$TAG" /sys/bus/virtio/devices/*/mount_tag 2>/dev/null ; then
+          local MOUNTDIR="$(mktemp -d)"
+          mount -t 9p -o trans=virtio,ro "$TAG" "$MOUNTDIR"
+          CMDLINE="$CMDLINE $(cat "$MOUNTDIR"/* 2>/dev/null | tr '\n' ' ')"
+          umount "$MOUNTDIR"
+          rmdir "$MOUNTDIR"
+      fi
+  fi
 fi
 # }}}
 
@@ -215,10 +226,10 @@ config_language(){
  if [ -x /usr/sbin/grml-setlang ] ; then
    # if bootoption lang is used update /etc/default/locale accordingly
    if [ -n "$BOOT_LANGUAGE" ] ; then
-     checkgrmlsmall && /usr/sbin/grml-setlang "POSIX" || /usr/sbin/grml-setlang "$LANGUAGE"
+     /usr/sbin/grml-setlang "$LANGUAGE"
    # otherwise default to lang=en
    else
-     checkgrmlsmall && /usr/sbin/grml-setlang "POSIX" || /usr/sbin/grml-setlang "en"
+     /usr/sbin/grml-setlang "en"
    fi
  fi
 
@@ -237,12 +248,8 @@ config_language(){
  fi
 
  # export it now, so error messages get translated, too
- if checkgrmlsmall ; then
-    export LANG='C' # grml-small does not provide any further locales
- else
-    [ -r /etc/default/locale ] && . /etc/default/locale
-    export LANG LANGUAGE
- fi
+ [ -r /etc/default/locale ] && . /etc/default/locale
+ export LANG LANGUAGE
 
  # configure keyboard layout, read in already set values first:
  [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard
@@ -365,20 +372,20 @@ config_language(){
 
 # {{{ Set hostname
 config_hostname(){
- if checkbootparam 'hostname' ; then
+  if ! checkbootparam 'hostname' ; then
+    return 0
+  fi
+
   HOSTNAME="$(getbootparam 'hostname' 2>>$DEBUG)"
   if [ -z "$HOSTNAME" ] && [ -x /usr/bin/random-hostname ] ; then
-     einfo "Generating random hostname as no hostname was specified."
-     HOSTNAME="$(/usr/bin/random-hostname)"
-     eend $?
+    einfo "Generating random hostname as no hostname was specified."
+    HOSTNAME="$(/usr/bin/random-hostname)"
+    eend $?
   fi
+
   einfo "Setting hostname to $HOSTNAME as requested."
-  grml-hostname $HOSTNAME >>$DEBUG ; RC=$?
-  [ "$RC" = "0" ] && hostname $HOSTNAME
-  eend $RC
- else
-  hostname --file /etc/hostname
- fi
+  grml-hostname $HOSTNAME >>$DEBUG
+  eend $?
 }
 # }}}
 
@@ -1042,7 +1049,7 @@ if checkbootparam 'ssh' ; then
    SSH_PASSWD=''
    SSH_PASSWD="$(getbootparam 'ssh' 2>>$DEBUG)"
    config_userlocal
-   einfo "Bootoption ssh found, trying to set password for user $localuser"
+   einfo "Bootoption ssh found, trying to set password for root and user $localuser"
    [ -z "$localuser" ] && eend 1
    eindent
    if [ -z "$SSH_PASSWD" ] ; then
@@ -1071,20 +1078,21 @@ if checkbootparam 'ssh' ; then
    # finally check if we have a password we can use:
    if [ -n "$SSH_PASSWD" ] ; then
       # chpasswd sucks, seriously.
+      chpass_options=""
       if chpasswd --help 2>&1 | grep -q -- '-m,' ; then
-        echo "$localuser:$SSH_PASSWD" | chpasswd -m
-      else
-        echo "$localuser:$SSH_PASSWD" | chpasswd
+        chpass_options="-m"
       fi
+      echo "$localuser:$SSH_PASSWD" | chpasswd $chpass_options
+      echo "root:$SSH_PASSWD" | chpasswd $chpass_options
    fi
 
-   einfo "Starting secure shell server in background for user $localuser"
+   einfo "Starting secure shell server in background for root and user $localuser"
    /etc/init.d/rmnologin start >>$DEBUG 2>>$DEBUG
    /etc/init.d/ssh start >>$DEBUG 2>>$DEBUG &
    eend $?
 
    eindent
-   ewarn "Warning: please change the password for user $localuser as soon as possible!"
+   ewarn "Warning: please change the password for root and user $localuser as soon as possible!"
    eoutdent
 fi
 }
@@ -1093,6 +1101,7 @@ fi
 # {{{ autostart of x11vnc
 config_vnc(){
 if checkbootparam 'vnc' ; then
+   config_userlocal
    VNC_PASSWD=''
    VNC_PASSWD="$(getbootparam 'vnc' 2>>$DEBUG)"
    einfo "Bootoption vnc found, trying to set password for user $localuser."
@@ -1107,7 +1116,7 @@ if checkbootparam 'vnc' ; then
       elif [ -x /usr/bin/hexdump ] ; then
          VNC_PASSWD="$(dd if=/dev/urandom bs=14 count=1 2>/dev/null | hexdump | awk '{print $3 $4}')"
       elif [ -n "$RANDOM" ] ; then
-         VNC_PASSWD="${USER}${RANDOM}"
+         VNC_PASSWD="${localuser}${RANDOM}"
       else
          VNC_PASSWD=''
          eerror "Empty passphrase and neither pwgen nor hexdump nor \$RANDOM found. Skipping."
@@ -1123,7 +1132,7 @@ if checkbootparam 'vnc' ; then
    # finally check if we have a password we can use:
    if [ -n "$VNC_PASSWD" ] ; then
 
-      VNCDIR="/home/${USER}/.vnc"
+      VNCDIR="/home/${localuser}/.vnc"
       [ -d "$VNCDIR" ] || mkdir "$VNCDIR"
 
       if [ ! -x /usr/bin/x11vnc ] ; then
@@ -1139,7 +1148,7 @@ if checkbootparam 'vnc' ; then
       VNC_CONNECT="$(getbootparam 'vnc_connect' 2>>$DEBUG)"
       einfo "Bootoption vnc_connect found, will start vnc with connect to $VNC_CONNECT."
       #store the options in a file
-      VNCDIR="/home/${USER}/.vnc"
+      VNCDIR="/home/${localuser}/.vnc"
       [ -d "$VNCDIR" ] || mkdir "$VNCDIR"
       echo " --connect $VNC_CONNECT " >> $VNCDIR/options
    fi
@@ -1464,7 +1473,7 @@ if checkbootparam 'startx' && ! echo "$CMDLINE" | grep -q 'startx.*nostartx' ; t
    config_userlocal
  cat>|/etc/init.d/xstartup<<EOF
 #!/bin/sh
-su $localuser -c "/usr/bin/grml-x"
+su $localuser -c "/usr/bin/grml-x ${WINDOWMANAGER}"
 EOF
    chmod 755 /etc/init.d/xstartup
 
@@ -2140,7 +2149,7 @@ fi # checkbootparam "BOOT_IMAGE=debian2hd
 config_virtualbox_shared_folders() {
 if [ -r /proc/acpi/battery/BAT0/info ] && grep -q 'OEM info:.*innotek' /proc/acpi/battery/BAT0/info ; then
   einfo "VirtualBox detected, trying to set up Shared Folders."
-  if ! modprobe -l | grep -q vboxsf.ko ; then
+  if ! modinfo vboxsf &>/dev/null ; then
     ewarn "vboxsf driver not present, not setting up VirtualBox Shared Folders."
     eend 0
   elif ! [ -x /usr/sbin/VBoxService ] ; then
@@ -2188,4 +2197,4 @@ fi
 # }}}
 
 ## END OF FILE #################################################################
-# vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=3
+# vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=2