Added tag 0.6.37 for changeset 7ef0a053b7ee
[grml-autoconfig.git] / autoconfig.functions
index ae4edd7..4a9238a 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: Fre Apr 13 12:49:52 CEST 2007 [mika]
+# Latest change: Mon Apr 16 19:32:25 CEST 2007 [mika]
 ################################################################################
 
 # {{{ path, variables, signals, umask, zsh
@@ -277,7 +277,7 @@ config_language(){
           ewarn "Not runnning unicode_start: grml-small with reduced language support detected." ; eend 0
        else
           einfo "Setting up unicode environment."
-          unicode_start ; eend $?
+          unicode_start 2>>$DEBUG ; eend $?
        fi
     fi
  fi
@@ -1065,7 +1065,7 @@ if [ -z "$INSTALLED" ] ; then
           *) continue ;;
           # *) NONEFOUND='1'; continue ;;
         esac
-   
+
         # use a swapfile
         if [ -z "$NOSWAP" ] ; then
            mount -o "$MOUNTOPTS" -t $f $p $m 2>>$DEBUG || continue
@@ -1083,7 +1083,7 @@ if [ -z "$INSTALLED" ] ; then
            fi
            mount -o remount,ro $m 2>>$DEBUG && MOUNTED=1
         fi
-   
+
         # use a image as home
         IMAGE="$(/bin/ls -1d $m/[Gg][Rr][Mm][Ll].[Ii][Mm][Gg] 2>/dev/null)"
         if [ -z "$GRML_IMG" -a -n "$IMAGE" -a -f "$IMAGE" ]; then
@@ -1098,10 +1098,10 @@ if [ -z "$INSTALLED" ] ; then
            fi
         fi
         eend 0
-   
+
         # Umount, if not in use
         [ -n "$MOUNTED" ] && umount -r $m 2>/dev/null
-   
+
       done <<EOT
       $(cat /etc/fstab)
 EOT
@@ -1656,7 +1656,12 @@ sudo -u $fstabuser -i /usr/bin/grml-x $WINDOWMANAGER 1>>$DEBUG
 EOF
    chmod 755 /etc/init.d/xstartup
 
-   sed -i 's#^6:.*#6:2345:respawn:/bin/zsh --login -c "/etc/init.d/xstartup ; /bin/zsh"#' /etc/inittab
+   # adjust inittab for xstartup
+   if grep -q '^6:' /etc/inittab ; then
+      sed -i 's|^6:.*|6:2345:respawn:/bin/zsh --login -c "/etc/init.d/xstartup ; /bin/zsh"|' /etc/inittab
+   else # just append tty6 to inittab if no definition is present:
+      echo '6:2345:respawn:/bin/zsh --login -c "/etc/init.d/xstartup ; /bin/zsh"' >> /etc/inittab
+   fi
 
    /sbin/telinit q ; eend $?
 
 # {{{ grml2hd: automatic installation
 config_grml2hd(){
 
+if stringinstring "BOOT_IMAGE=grml2hd " "$CMDLINE" ; then
+
 if checkbootparam "user" ; then
-  NEWUSER=''
-  NEWUSER="$(getbootparam 'user' 2>>$DEBUG)"
-  sed -i "s/^NEWUSER=.*/NEWUSER=$NEWUSER/" /etc/grml2hd/config || export GRML2HD_FAIL=1
+   NEWUSER=''
+   NEWUSER="$(getbootparam 'user' 2>>$DEBUG)"
+   sed -i "s/^NEWUSER=.*/NEWUSER=$NEWUSER/" /etc/grml2hd/config || export GRML2HD_FAIL=1
 fi
 
 if checkbootparam "filesystem" ; then
-  FILESYSTEM=''
-  FILESYSTEM="$(getbootparam 'filesystem' 2>>$DEBUG)"
-  sed -i "s/^FILESYSTEM=.*/FILESYSTEM=$FILESYSTEM/" /etc/grml2hd/config || export GRML2HD_FAIL=1
+   FILESYSTEM=''
+   FILESYSTEM="$(getbootparam 'filesystem' 2>>$DEBUG)"
+   sed -i "s/^FILESYSTEM=.*/FILESYSTEM=$FILESYSTEM/" /etc/grml2hd/config || export GRML2HD_FAIL=1
 fi
 
 if checkbootparam "partition" ; then
-  PARTITION=''
-  PARTITION="$(getbootparam 'partition' 2>>$DEBUG)"
-  # notice: the following checks whether the given partition is available, if not the skip
-  # execution of grml2hd as it might result in data loss...
-  if [ -r $PARTITION ] ; then
-    sed -i "s#^PARTITION=.*#PARTITION=$PARTITION#" /etc/grml2hd/config || export GRML2HD_FAIL=1
-  else
-    ewarn "Partition $PARTITION does not exist. Skipping execution of grml2hd therefore." ; eend 1
-  fi
+   PARTITION=''
+   PARTITION="$(getbootparam 'partition' 2>>$DEBUG)"
+   # notice: the following checks whether the given partition is available, if not the skip
+   # execution of grml2hd as it might result in data loss...
+   if [ -r $PARTITION ] ; then
+      sed -i "s#^PARTITION=.*#PARTITION=$PARTITION#" /etc/grml2hd/config || export GRML2HD_FAIL=1
+   else
+      ewarn "Partition $PARTITION does not exist. Skipping execution of grml2hd therefore." ; eend 1
+   fi
 fi
 
 if checkbootparam "mbr" ; then
-  BOOT_PARTITION=''
-  BOOT_PARTITION="$(getbootparam 'mbr' 2>>$DEBUG)"
-  sed -i "s#^BOOT_PARTITION=.*#BOOT_PARTITION=$BOOT_PARTITION#" /etc/grml2hd/config || export GRML2HD_FAIL=1
+   BOOT_PARTITION=''
+   BOOT_PARTITION="$(getbootparam 'mbr' 2>>$DEBUG)"
+   sed -i "s#^BOOT_PARTITION=.*#BOOT_PARTITION=$BOOT_PARTITION#" /etc/grml2hd/config || export GRML2HD_FAIL=1
 fi
 
-if stringinstring "BOOT_IMAGE=grml2hd " "$CMDLINE" ; then
-  cat>|/usr/bin/grml2hd_noninteractive<<EOF
+cat>|/usr/bin/grml2hd_noninteractive<<EOF
 #!/bin/sh
 GRML2HD_NONINTERACTIVE='yes' grml2hd
 EOF
-  chmod 755 /usr/bin/grml2hd_noninteractive
-  einfo "Bootparameter grml2hd found. Running automatic installation via grml2hd using /etc/grml2hd/config." && eend 0
-  if [ -z "$GRML2HD_FAIL" ] ; then
-    screen /usr/bin/grml2hd_noninteractive ; einfo "Invoking a shell, just exit to continue booting..." ; /bin/zsh
-  else
-    ewarn "There was an error adjusting /etc/grml2hd/config. Skipping execution of grml2hd for security reasons." ; eend 1
+
+chmod 755 /usr/bin/grml2hd_noninteractive
+einfo "Bootoption grml2hd found. Running automatic installation via grml2hd using /etc/grml2hd/config." && eend 0
+if [ -z "$GRML2HD_FAIL" ] ; then
+   screen /usr/bin/grml2hd_noninteractive ; einfo "Invoking a shell, just exit to continue booting..." ; /bin/zsh
+else
+   ewarn "There was an error adjusting /etc/grml2hd/config. Skipping execution of grml2hd for security reasons." ; eend 1
+fi
+
+fi # if stringinstring "BOOT_IMAGE=grml2hd ...
+}
+# }}}
+
+# {{{ debootstrap: automatic installation
+config_debootstrap(){
+
+if stringinstring "BOOT_IMAGE=debian2hd " "$CMDLINE" ; then
+
+einfo "Bootoption debian2hd found. Setting up environment for automatic installation via grml-debootstrap." ; eend 0
+
+if ! [ -x /usr/sbin/grml-debootstrap ] ; then
+   eindent
+   eerror "Bootoption debian2hd found, but grml-debootstrap is not available." ; eend 1
+   eoutdent
+   exit 1
+fi
+
+if checkbootparam "partition" ; then
+  PARTITION=''
+  PARTITION="$(getbootparam 'partition' 2>>$DEBUG)"
+  # notice: the following checks whether the given partition is available, if not the skip
+  # execution of grml-debootstrap as it might result in data loss...
+  if ! [ -r $PARTITION ] ; then
+     eerror "Partition $PARTITION does not exist. Skipping execution of grml-debootstrap therefore." ; eend 1
   fi
+else
+  eindent
+  eerror "No bootoption partition found, can not continue execution of grml-debootstrap." ; eend 1
+  eoutdent
+  exit 1
+fi
+
+if checkbootparam "grub" ; then
+  GRUB=''
+  GRUB="$(getbootparam 'grub' 2>>$DEBUG)"
 fi
+
+if checkbootparam "groot" ; then
+  GROOT=''
+  GROOT="$(getbootparam 'groot' 2>>$DEBUG)"
+fi
+
+if checkbootparam "release" ; then
+  RELEASE=''
+  RELEASE="$(getbootparam 'release' 2>>$DEBUG)"
+fi
+
+if checkbootparam "mirror" ; then
+  MIRROR=''
+  MIRROR="$(getbootparam 'mirror' 2>>$DEBUG)"
+fi
+
+if checkbootparam "password" ; then
+  PASSWORD=''
+  PASSWORD="$(getbootparam 'password' 2>>$DEBUG)"
+fi
+
+# now check which options are available
+if [ -n "PARTITION" ] ; then
+   PARTITIONCMD="--target $PARTITION"
+else
+   PARTITIONCMD=''
+   ewarn "Partion not set via bootoption. Skipping execution of grml-debootstrap therefore."; eend 1
+fi
+[ -n "$GRUB" ]     && GRUBCMD="--grub $GRUB"               || GRUBCMD=''
+[ -n "$GROOT" ]    && GROOTCMD="--groot $GROOT"            || GROOTCMD=''
+[ -n "$RELEASE" ]  && RELEASECMD="--release $RELEASE"      || RELEASECMD=''
+[ -n "$MIRROR" ]   && MIRRORCMD="--mirror $MIRROR"         || MIRRORCMD=''
+[ -n "$PASSWORD" ] && PASSWORDCMD="--password $PASSWORD" ] || PASSWORDCMD=''
+
+# and finally write script and execute it
+cat>|/usr/bin/grml-debootstrap_noninteractive<<EOF
+#!/bin/sh
+AUTOINSTALL='yes' grml-debootstrap $PARTITIONCMD $GRUBCMD $GROOTCMD $RELEASECMD $MIRRORCMD $PASSWORDCMD
+EOF
+
+chmod 750  /usr/bin/grml-debootstrap_noninteractive
+
+screen /usr/bin/grml-debootstrap_noninteractive
+einfo "Invoking a shell, just exit to continue booting..."
+/bin/zsh
+
+fi # stringinstring "BOOT_IMAGE=debian2hd
 }
 # }}}