Use random password if bootoption 'ssh' doesn't have an option.
[grml-autoconfig.git] / autoconfig.functions
index 48d98da..debf31f 100755 (executable)
@@ -4,7 +4,7 @@
 # Authors:       grml-team (grml.org), (c) Klaus Knopper <knopper@knopper.net>, (c) Michael Prokop <mika@grml.org>
 # Bug-Reports:   see http://grml.org/bugs/
 # License:       This file is licensed under the GPL v2.
-# Latest change: Sam Mai 17 22:15:54 CEST 2008 [mika]
+# Latest change: Fre Aug 15 23:06:21 CEST 2008 [mika]
 ################################################################################
 
 # {{{ path, variables, signals, umask, zsh
@@ -128,6 +128,8 @@ config_debug(){
   if [ -n "$BOOTDEBUG" ]; then
      einfo "Starting intermediate shell stage $stage as requested by \"debug\" option."
      if [ grep -q "debug=noscreen" "$CMDLINE" ] ; then
+        einfo "Notice that the shell does not provide job handling: ctrl-z, bg and fg won't work!"
+        einfo "Just exit the shell to continue boot process..."
         /bin/zsh
      else
         eindent
@@ -1240,10 +1242,12 @@ if checkbootparam "nocpu"; then
 else
   # check module dependencies
   cpufreq_check() {
-   if [ -e /lib64 ] ; then
-      [ -e /lib/modules/${KERNEL}/kernel/arch/x86_64/kernel/cpufreq ] || return 1
-   else
-      [ -e /lib/modules/${KERNEL}/kernel/arch/i386/kernel/cpu/cpufreq -o ! -e /lib/modules/${KERNEL}/kernel/drivers/cpufreq ] || return 1
+   if ! [ -e /lib/modules/${KERNEL}/kernel/arch/x86/kernel/cpu/cpufreq ] ; then
+      if [ -e /lib64 ] ; then
+         [ -e /lib/modules/${KERNEL}/kernel/arch/x86_64/kernel/cpufreq ] || return 1
+      else
+         [ -e /lib/modules/${KERNEL}/kernel/arch/i386/kernel/cpu/cpufreq -o ! -e /lib/modules/${KERNEL}/kernel/drivers/cpufreq ] || return 1
+      fi
    fi
   }
 
@@ -1337,20 +1341,42 @@ fi # checkbootparam nocpu
 # {{{ autostart of ssh
 config_ssh(){
 if checkbootparam ssh ; then
-  SSH_PASSWD="$(getbootparam 'ssh' 2>>$DEBUG)"
-  einfo "Bootoption passwd found."
-  if [ -n "$SSH_PASSWD" ] ; then
-    echo "grml:$SSH_PASSWD" | chpasswd -m
-    einfo "Starting secure shell server in background."
-    /etc/init.d/rmnologin start 1>>$DEBUG 2>>$DEBUG
-    /etc/init.d/ssh start 1>>$DEBUG 2>>$DEBUG &
-    eend 0
-  else
-    eerror "No given password for ssh found. Autostart of SSH will not work." ; eend 1
-  fi
-  eindent
-    ewarn "Warning: please change the password for user grml set via bootparameter as soon as possible!"
-  eoutdent
+   SSH_PASSWD=''
+   SSH_PASSWD="$(getbootparam 'ssh' 2>>$DEBUG)"
+   einfo "Bootoption ssh found, trying to set password for user grml."
+   eindent
+   if [ -z "$SSH_PASSWD" ] ; then
+      if [ -x /usr/bin/pwgen ] ; then
+         SSH_PASSWD="$(pwgen -1 8)"
+      elif [ -x /usr/bin/hexdump ] ; then
+         SSH_PASSWD="$(dd if=/dev/urandom bs=14 count=1 2>/dev/null | hexdump | awk '{print $3 $4}')"
+      elif [ -n "$RANDOM" ] ; then
+         SSH_PASSWD="grml${RANDOM}"
+      else
+         SSH_PASSWD=''
+         eerror "Empty passphrase and neither pwgen nor hexdump nor \$RANDOM found. Skipping."
+         eend 1
+      fi
+
+      if [ -n "$SSH_PASSWD" ] ; then
+         ewarn "No given password for ssh found. Using random password: $SSH_PASSWD" ; eend 0
+      fi
+   fi
+   eoutdent
+
+   # finally check if we have a password we can use:
+   if [ -n "$SSH_PASSWD" ] ; then
+      echo "grml:$SSH_PASSWD" | chpasswd -m
+   fi
+
+   einfo 'Starting secure shell server in background.'
+   /etc/init.d/rmnologin start 1>>$DEBUG 2>>$DEBUG
+   /etc/init.d/ssh start 1>>$DEBUG 2>>$DEBUG &
+   eend $?
+
+   eindent
+   ewarn 'Warning: please change the password for user grml as soon as possible!'
+   eoutdent
 fi
 }
 # }}}
@@ -1637,10 +1663,14 @@ config_gpm(){
  if checkbootparam "nogpm"; then
   ewarn "Not starting GPM as requested on boot commandline." ; eend 0
  else
-  einfo "Starting gpm in background."
-#  /etc/init.d/gpm start 1>>$DEBUG &
-  ( while [ ! -e /dev/psaux ]; do sleep 5; done; /etc/init.d/gpm start 1>>$DEBUG ) &
-  eend 0
+   if ! [ -r /dev/input/mice ] ; then
+      eerror "No mouse found - not starting GPM." ; eend 1
+   else
+      einfo "Starting gpm in background."
+      /etc/init.d/gpm start 1>>$DEBUG &
+      # ( while [ ! -e /dev/psaux ]; do sleep 5; done; /etc/init.d/gpm start 1>>$DEBUG ) &
+      eend 0
+   fi
  fi
 }
 # }}}
@@ -1782,13 +1812,13 @@ if checkbootparam noautoconfig || checkbootparam forensic ; then
   ewarn "Skipping running automount of device(s) labeled GRMLCFG as requested." ; eend 0
 else
  if [ -z "$INSTALLED" ] ; then
-  einfo "Searching for device(s) labeled with GRMLCFG." ; eend 0
+  einfo "Searching for device(s) labeled with GRMLCFG. (Disable this via boot option: noautoconfig)" ; eend 0
   eindent
   [ -d /mnt/grml ] || mkdir /mnt/grml
   umount /mnt/grml 1>>$DEBUG 2>&1 # make sure it is not mounted
 # 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. (Disable this via boot option: noautoconfig)"
+     einfo "Floppy device detected. Trying to access floppy disk."
 #     dd if=/dev/fd0 of=/dev/null bs=512 count=1 1>>$DEBUG 2>&1
      if timeout 4 dd if=/dev/fd0 of=/dev/null bs=512 count=1 1>>$DEBUG 2>&1 ; then
         blkid /dev/fd0 1>>$DEBUG 2>&1
@@ -1929,11 +1959,11 @@ if checkbootparam "mypath" ; then
    for i in $(echo $MY_PATH | sed 's/:/\n/g') ; do
        if ! [ -d "$i" ] ; then
           einfo "Creating directory $i"
-          mkdir -d "$i" ; eend $?
+          mkdir -p "$i" ; eend $?
        fi
    done
+   grep -q "${MY_PATH}" /etc/grml/my_path || echo "${MY_PATH}" >> /etc/grml/my_path ; eend $?
    eoutdent
-   echo "$MY_PATH" >> /etc/grml/my_path ; eend $?
 fi
 }
 # }}}