linuxrc: really math only eth in ifconfig output
[grml-terminalserver.git] / linuxrc
diff --git a/linuxrc b/linuxrc
index 85ae3ef..eaa4376 100755 (executable)
--- a/linuxrc
+++ b/linuxrc
@@ -2,7 +2,7 @@
 # Filename: /linuxrc
 # Purpose:  minirt for kernel 2.6 running on grml live-cd
 # Authors:  (c) Klaus Knopper <knoppix@knopper.net>, (c) Michael Prokop <mika@grml.org>
-# Latest change: Mon Sep 18 23:19:53 CEST 2006 [mika]
+# Latest change: Don Nov 16 19:08:07 CET 2006 [mika]
 #######################################################################################
 
 # hardcoded configurable options
@@ -269,7 +269,7 @@ askmodules(){
  c=""
  for m in "$@"; do
   if test -f "/modules/scsi/$m"; then
-   test -z "$c"  && { echo -n "        $m"; c="1"; } || { echo "               $m"; c=""; }
+   test -z "$c"  && { echo -n " $m"; c="1"; } || { echo "               $m"; c=""; }
   fi
  done
  [ -n "$c" ] && echo ""
@@ -509,24 +509,66 @@ esac
 stage=2
 rundebugshell
 # NFS
-if checkbootparam "nfsdir" ; then
-  NFS="$(getbootparam nfsdir)"
-#  if test -z $NFS
-#    then
-#    NFS=192.168.0.1
-#    echo "${CRE}${BLUE}No NFS-server given, assuming default $NFS${NORMAL}"
-#  fi
-  echo "${RED}Debug: NFS = ${NFS}${NORMAL}"
-  log_begin_msg "${CRE} ${GREEN}*${NORMAL} Looking for CD-ROM in: ${MAGENTA}$NFS${NORMAL}"
-  if mountit -t nfs $NFS "-o ro" >/dev/null 2>&1
+for i in $cmdline; do case "$i" in nfsdir=*|NFSDIR=*) eval $i;; esac; done
+[ -n "$nfsdir" ] && NFS="$nfsdir"
+if [ -n "$NFS" ]; then
+  tmp_="$(getbootparam nfsdir)"
+  log_begin_msg "Bootoption NFS found." ; echo "$SUCCESS"
+
+  # put the mylibs into /lib for discover and udhcpc
+  cdir
+
+  # starting hw-detection for network card - currently broken, so don't use it
+  #  echo "Starting hw-detection"
+  #  kernel_version_=`uname -r`
+  #  modules_to_load=$(/static/discover --disable-bus all --enable-bus pci --type network --normalize-whitespace --data-path=linux/module/name --data-version=$kernel_version_ | grep -v '^ $' | uniq)
+  #  echo "trying to load the following network modules:  \"$modules_to_load\""
+
+  KERNELVER=`uname -r`
+  for mod in `find /lib/modules/$KERNELVER/kernel/drivers/net/ -name \*.ko` ; do
+      echo `basename $mod | sed -e 's/\.ko$//'` >> /modules.load
+  done
+  modules_to_load=`cat /modules.load | xargs`
+
+  # FIXME modprobe is buggy from busybox
+  log_begin_msg "Trying to load network driver(s)." ; echo
+  modLoad()
+  {
+    for mod in $@ ; do
+      tmp_="`modprobe -vn $mod 2>/dev/null`"
+      if [ $? -ne 0 ]; then
+         continue
+      fi
+      # be quiet by default, be verbose only with bootoption debuglinuxrc
+      [ -n "$DEBUG" ] && eval "$tmp_" || eval "$tmp_" 1>/dev/null 2>/dev/null
+    done
+  }
+  modLoad "$modules_to_load"
+  rm -f /modules.load
+
+  # loading additional modules
+  modLoad sunrpc lockd af_packet nfs
+
+  for INTERFACE in `ifconfig -a | grep '^eth' | sed 's/\ .*//'` ; do
+      log_begin_msg "Requesting network configuration using udhcp for ${INTERFACE}:" ; echo
+      /static/udhcpc --interface="${INTERFACE}" --foreground --quit --script=/static/udhcp-config.sh
+      # echo "press <enter> to start a system shell and configure your system"
+      # sh
+  done
+
+  # recreate the old dir structures
+  rdir
+  #rm -rf /myusr /mylib
+
+  log_begin_msg "Looking for GRML in: ${MAGENTA}$NFS${NORMAL}" ; echo "$SUCCESS"
+  if mount -t nfs "$NFS" -o "async,ro,nolock" /cdrom #>/dev/null 2>&1
     then
     if test -f /cdrom/$GRML_DIR/$GRML_NAME
       then
-      log_begin_msg "Accessing grml CD-ROM at ${MAGENTA}${NFS}${NORMAL}" ; echo "     $SUCCESS"
+      log_begin_msg "Accessing grml CDROM at ${MAGENTA}$NFS${NORMAL}" ; echo "$SUCCESS"
       FOUND_GRML="$NFS"
       break
     fi
-    umount /cdrom
   fi
 fi
 
@@ -576,7 +618,7 @@ remount_grml()
     [ -n "$SOURCE2" ] && umount $SOURCE2  # umount possible loop-device
     mount_grml $TARGET
   else
-    echo "${CRE} ${RED}Warning: Changing to $TARGET failed.${NORMAL}"
+    log_failure_msg "Warning: Changing to $TARGET failed."
     return 1
   fi
 
@@ -613,7 +655,7 @@ boot_from()
   fi
   if [ $? -ne 0 ]; then
      [ -n "$LOOP_SOURCE" ] && /bin/umount $LOOP_SOURCE
-     echo -n "${CRE} ${RED}Accessing grml CD-ROM failed. ${MAGENTA}$TARGET_DEV${RED} is not mountable.${NORMAL}"
+     log_failure_msg "Accessing grml CD-ROM failed. ${MAGENTA}$TARGET_DEV${NORMAL} is not mountable."
      sleep 2
      return 1
   fi
@@ -621,7 +663,7 @@ boot_from()
   if [ -f $TARGET/$GRML_DIR/$GRML_NAME ]; then
     log_begin_msg "Accessing grml CD-ROM at ${MAGENTA}$TARGET_DEV${NORMAL}." ; echo "  $SUCCESS"
   else
-    echo -n "${CRE} ${RED}Accessing grml CD-ROM failed. Could not find $GRML_DIR/$GRML_NAME on ${MAGENTA}$TARGET_DEV${RED}.${NORMAL}"
+    log_failure_msg "Accessing grml CD-ROM failed. Could not find $GRML_DIR/$GRML_NAME on ${MAGENTA}$TARGET_DEV${RED}.${NORMAL}"
     [ -n "$LOOP_SOURCE" ] && /bin/umount $LOOP_SOURCE
     umount $TARGET
     sleep 2
@@ -664,7 +706,7 @@ copy_to()
        fi
       done
       if test -z "$MOUNTED"; then
-        echo -n "${CRE} ${RED}Copying grml CD-ROM failed. ${MAGENTA}$TARGET_DEV_DESC${RED} is not mountable.${NORMAL}"
+        log_failure_msg "Copying grml CD-ROM failed. ${MAGENTA}$TARGET_DEV_DESC${NORMAL} is not mountable."
         sleep 2
         return 1
       fi
@@ -682,7 +724,7 @@ copy_to()
 
   if [ $FOUNDSPACE -lt $SIZE ]
   then
-    echo -n "${CRE} ${RED}Copying grml CD-ROM failed. Not enough free space on ${MAGENTA}${TARGET_DEV_DESC}${RED}. Found: ${MAGENTA}${FOUNDSPACE}k${RED} Need: ${MAGENTA}${SIZE}k${RED} ${NORMAL}"
+    log_failure_msg "Copying grml CD-ROM failed. Not enough free space on ${MAGENTA}${TARGET_DEV_DESC}${NORMAL}. Found: ${MAGENTA}${FOUNDSPACE}k${NORMAL} Need: ${MAGENTA}${SIZE}k${NORMAL}"
     sleep 2
     umount $TARGET
     return 1
@@ -690,7 +732,8 @@ copy_to()
 
   # do the real copy
 
-  echo "${CRE} ${GREEN}Copying grml CD-ROM to ${MAGENTA}$TARGET_DEV_DESC${GREEN}... Please be patient. ${NORMAL}"
+  log_begin_msg "Copying grml CD-ROM to ${TARGET_DEV_DESC}... Please be patient."
+  echo
   if [ -z "$use_cp" -a -x /usr/bin/rsync ]
   then
     # first cp the small files
@@ -699,17 +742,24 @@ copy_to()
     [ -f $TARGET/$GRML_DIR/$GRML_NAME ] && /bin/rm -f $TARGET/$GRML_DIR/$GRML_NAME
     /usr/bin/rsync -a --progress --include="$GRML_DIR/$GRML_NAME" --include="$GRML_DIR/" --exclude="*" $COPY $TARGET # Copy grml to $TARGET
     #/usr/bin/rsync -avP $COPY $TARGET # Copy grml to $TARGET
+    # make sure to support directories from http://grml.org/config/
+    for dir in scripts bootparams config debs ; do
+        if [ -d "/cdrom/$dir" ] ; then
+           log_begin_msg "Customization directory $dir found, copying to $TARGET"
+           cp -a /cdrom/$dir $TARGET/ && echo "$SUCCESS" || echo "$FAILED"
+        fi
+    done
   else
     /bin/cp -a -f $COPY $TARGET # Copy grml to $TARGET
   fi
   if [ $? -ne 0 ]
   then
-    echo -n "${CRE} ${RED}Copying grml CD-ROM failed. ${MAGENTA}$TARGET_DEV_DESC${RED} possibly has not enough space left.${NORMAL}"
+    log_failure_msg "Copying grml CD-ROM failed. ${MAGENTA}$TARGET_DEV_DESC${NORMAL} possibly has not enough space left."
     sleep 2
     return 1
   fi
   # remount r/o
-  /bin/mount -n -o remount,ro $TARGET
+  /bin/mount -n -o remount,ro $TARGET 1>/dev/null 2>&1
   remount_grml
 }
 
@@ -737,16 +787,16 @@ if  test -n "$DO_REMOUNT" -a -n "$FOUND_GRML" ; then
 
   # first copy_to, then boot_from
   if [ -n "$COPYTO" ]; then
-   copy_to $COPYTO && REAL_TARGET="$TARGET"
+     copy_to $COPYTO && REAL_TARGET="$TARGET"
   fi
   if [ -n "$BOOTFROM" ]; then
-    boot_from
-    if [ "$?" -eq "0" ]; then
-      # set new source / target paths
-      REAL_TARGET="$TARGET"
-      SOURCE2="$LOOP_SOURCE"
-      SOURCE="/cdrom2"
-      TARGET="/cdrom3"
+     boot_from
+     if [ "$?" -eq "0" ]; then
+        # set new source / target paths
+        REAL_TARGET="$TARGET"
+        SOURCE2="$LOOP_SOURCE"
+        SOURCE="/cdrom2"
+        TARGET="/cdrom3"
     fi
   fi
 fi
@@ -781,10 +831,9 @@ export PATH
 # From here, we should have all essential commands available.
 hash -r
 
-# Did we remount the source media ?
-if  test -n "$REAL_TARGET";
-then
-   /bin/mount -n --move $REAL_TARGET /cdrom # move it back and go on to normal boot
+# Did we remount the source media?
+if  test -n "$REAL_TARGET"; then
+  /bin/mount -n --move $REAL_TARGET /cdrom # move it back and go on to normal boot
 fi
 
 # Clean up /etc/mtab (and - just in case - make a nice entry for looped ISO)
@@ -843,7 +892,6 @@ if test -n "$UNIONFS" && /bin/mount -t unionfs -o noatime${SECURE},dirs=/ramdisk
    ln -snf /UNIONFS/$i /$i
   fi
  done
- #echo "${GREEN}done${NORMAL}"
  echo "                 $SUCCESS"
  log_begin_msg "Merging read-only system with read-writeable /ramdisk."
  for i in $(cd /UNIONFS; echo *); do # Create links for new stuff on /UNIONFS
@@ -904,7 +952,7 @@ rm -f /linuxrc
 exit 0
 
 else
echo "${CRE}${RED}Can't find grml filesystem, sorry.${NORMAL}"
log_failure_msg "Error: Can't find grml filesystem, sorry."
  echo "
 Are you booting via USB or firewire?
 ====================================