Generate make-fai-nfsroot.conf and nfsroot.conf on-the-fly
authorMichael Prokop <mika@grml.org>
Sun, 20 May 2012 10:48:21 +0000 (12:48 +0200)
committerMichael Prokop <mika@grml.org>
Sun, 20 May 2012 11:38:41 +0000 (13:38 +0200)
FAI 4 uses nfsroot.conf instead of make-fai-nfsroot.conf without
providing any backwards compatibility. :( So while at it rework
the way how make-fai-nfsroot.conf is handled:

* No longer ship /etc/grml/fai/make-fai-nfsroot.conf at all
* Generate nfsroot.conf based on default settings (can be overriden
  by $FAI_DEBOOTSTRAP + $FAI_DEBOOTSTRAP_OPTS) on the fly
* Provide symlink make-fai-nfsroot.conf pointing to nfsroot.conf
  to support old and new FAI versions at the same time
* After execution copy generated nfsroot.conf file to log directory
  and get rid of make-fai-nfsroot.conf and nfsroot.conf in
  $GRML_FAI_CONFIG (/etc/grml/fai/ by default) afterwards

Note: existing make-fai-nfsroot.conf files will be moved
to make-fai-nfsroot.conf.outdated to avoid possible data loss.

Closes: https://github.com/grml/grml-live/issues/4

docs/grml-live.txt
etc/grml/fai/make-fai-nfsroot.conf [deleted file]
etc/grml/grml-live.conf
grml-live

index eb92388..93141d8 100644 (file)
@@ -400,12 +400,6 @@ GRML_FAI_CONFIG=/etc/grml/fai/config - both pointing to a directory shipped by
 grml-live out-of-the-box so you shouldn't have to configure anything in this
 file.
 
-  ${GRML_FAI_CONFIG}/make-fai-nfsroot.conf
-
-This file is used by make-fai-nfsroot(8) only. Usually you don't have to change
-anything inside this file. If you want to modify NFSROOT though you can adjust
-it there.
-
   ${GRML_FAI_CONFIG}/NFSROOT
 
 This file specifies the package list for creating the NFSROOT.
diff --git a/etc/grml/fai/make-fai-nfsroot.conf b/etc/grml/fai/make-fai-nfsroot.conf
deleted file mode 100644 (file)
index e71302d..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-# these variables are only used by make-fai-nfsroot(8)
-# here you can use also variables defined in fai.conf
-
-# directory on the install server where the nfsroot for FAI is
-# created, approx size: 250MB, also defined in bootptab or dhcp.conf
-NFSROOT=/srv/fai/nfsroot
-
-# TFTP root directory
-TFTPROOT=/srv/tftp/fai
-
-# Add a line for mirrorhost and installserver when DNS is not available
-# on the clients. This line(s) will be added to $nfsroot/etc/hosts.
-#NFSROOT_ETC_HOSTS="192.168.1.250 yourinstallserver"
-
-# debootstrap commandline
-FAI_DEBOOTSTRAP="squeeze http://cdn.debian.net/debian"
-
-# which options do you want to use for debootstrap?
-FAI_DEBOOTSTRAP_OPTS="--exclude=info,tasksel,tasksel-data"
-
-# the encrypted (with md5 or crypt) root password on all install clients during
-# installation process; used when log in via ssh; default pw is: fai
-FAI_ROOTPW='$1$kBnWcO.E$djxB128U7dMkrltJHPf6d1'
-
-# location of a identity.pub file; this user can log to the install
-# clients in as root without a password; only useful with FAI_FLAGS="sshd"
-#SSH_IDENTITY=/home/admin/.ssh/identity.pub
-
-# directory of hooks to be sourced at the end of make-fai-nfsroot,
-# i.e they have to be shell scripts.
-#NFSROOT_HOOKS=/etc/fai/nfsroot-hooks/
index ff6fbe0..5381688 100644 (file)
@@ -65,9 +65,6 @@
 # APT_PROXY="http://localhost:3142/"
 
 # Which Debian suite and which mirror do you want to use for debootstrapping?
-# Unless specified the default from /etc/grml/fai/make-fai-nfsroot.conf will be
-# taken. If you specify a value then the file /etc/grml/fai/make-fai-nfsroot.conf
-# will be updated by grml-live on-the-fly.
 # Usage: "<suite> <mirror>"
 # FAI_DEBOOTSTRAP="squeeze http://cdn.debian.net/debian"
 
index 95f0b3e..9f5085b 100755 (executable)
--- a/grml-live
+++ b/grml-live
@@ -183,6 +183,11 @@ bailout() {
     [ -n "${CHROOT_OUTPUT}" -a -d "${CHROOT_OUTPUT}" ] && rm -r "${CHROOT_OUTPUT}"
     eend 0
   fi
+
+  # get rid of automatically generated conffiles
+  rm -f ${GRML_FAI_CONFIG}/nfsroot.conf
+  rm -f ${GRML_FAI_CONFIG}/make-fai-nfsroot.conf
+
   if [ -n "$CHOWN_USER" ]; then
     log "Setting ownership"
     einfo "Setting ownership"
@@ -365,7 +370,6 @@ fi
 [ -n "$GRML_NAME" ]               || GRML_NAME='grml'
 [ -n "$HOSTNAME" ]                || HOSTNAME='grml'
 [ -n "$HYBRID_METHOD" ]           || HYBRID_METHOD='isohybrid'
-[ -n "$NFSROOT_CONF" ]            || NFSROOT_CONF="${GRML_FAI_CONFIG}/make-fai-nfsroot.conf"
 [ -n "$RELEASENAME" ]             || RELEASENAME='grml-live rocks'
 [ -n "$SQUASHFS_EXCLUDES_FILE" ]  || SQUASHFS_EXCLUDES_FILE="${GRML_FAI_CONFIG}/config/grml/squashfs-excludes"
 [ -n "$SUITE" ]                   || SUITE='testing'
@@ -560,9 +564,6 @@ extract_iso
 # }}}
 
 # on-the-fly configuration {{{
-if [ -n "$FAI_DEBOOTSTRAP" ] ; then
-  sed "s#^FAI_DEBOOTSTRAP=.*#FAI_DEBOOTSTRAP=\"$FAI_DEBOOTSTRAP\"#" "$NFSROOT_CONF" | sponge "$NFSROOT_CONF"
-fi
 
 # does this suck? YES!
 # /usr/share/debootstrap/scripts/unstable does not exist, instead use 'sid':
@@ -572,12 +573,6 @@ case $SUITE in
 esac
 export SUITE # make sure it's available in FAI scripts
 
-for file in "$LIVE_CONF" "$LOCAL_CONFIG" "$NFSROOT_CONF" ; do
-    if [ -n "$file" ] ; then
-       sed "s|^FAI_DEBOOTSTRAP=\"[a-z]* |FAI_DEBOOTSTRAP=\"$SUITE |" "$file" | sponge "$file"
-    fi
-done
-
 # validate whether the specified architecture class matches the
 # architecture (option), otherwise installation of kernel will fail
 if echo $CLASSES | grep -qi i386 ; then
@@ -598,11 +593,31 @@ elif echo $CLASSES | grep -qi amd64 ; then
    fi
 fi
 
-if grep -q -- 'FAI_DEBOOTSTRAP_OPTS.*--arch' "$NFSROOT_CONF" ; then
-   sed "s/--arch [a-z0-9]* /--arch $ARCH /" "$NFSROOT_CONF" | sponge "$NFSROOT_CONF"
-else
-   sed "s|^FAI_DEBOOTSTRAP_OPTS=\"\(.*\)|FAI_DEBOOTSTRAP_OPTS=\"--arch $ARCH \1|" "$NFSROOT_CONF" | sponge "$NFSROOT_CONF"
+# generate nfsroot configuration for FAI on the fly
+if [ -z "$FAI_DEBOOTSTRAP" ] ; then
+  FAI_DEBOOTSTRAP="$SUITE http://cdn.debian.net/debian"
 fi
+
+if [ -z "$FAI_DEBOOTSTRAP_OPTS" ] ; then
+  FAI_DEBOOTSTRAP_OPTS="--exclude=info,tasksel,tasksel-data --arch $ARCH"
+fi
+
+# create backup of old (not yet automatically generated) config file
+if [ -f "${GRML_FAI_CONFIG}/make-fai-nfsroot.conf" ] ; then
+  if ! grep -q 'This is an automatically generated file by grml-live' "${GRML_FAI_CONFIG}/make-fai-nfsroot.conf" ; then
+    ewarn "Found old ${GRML_FAI_CONFIG}/make-fai-nfsroot.conf - moving to ${GRML_FAI_CONFIG}/make-fai-nfsroot.conf.outdated"
+    mv "${GRML_FAI_CONFIG}/make-fai-nfsroot.conf" "${GRML_FAI_CONFIG}/make-fai-nfsroot.conf.outdated"
+    eend $?
+  fi
+fi
+
+echo "# This is an automatically generated file by grml-live.
+# Do NOT edit this file, your changes will be lost.
+FAI_DEBOOTSTRAP=\"$FAI_DEBOOTSTRAP\"
+FAI_DEBOOTSTRAP_OPTS=\"$FAI_DEBOOTSTRAP_OPTS\"
+# EOF " > "${GRML_FAI_CONFIG}/nfsroot.conf"
+# support FAI <=3.4.8, versions >=4.0 use nfsroot.conf
+( cd ${GRML_FAI_CONFIG} && ln -sf nfsroot.conf make-fai-nfsroot.conf )
 # }}}
 
 # CHROOT_OUTPUT - execute FAI {{{
@@ -672,6 +687,10 @@ else
       mkdir -p "$LOG_OUTPUT"/fai/
       cp -r "$CHROOT_OUTPUT"/var/log/fai/"$HOSTNAME"/last/* "$LOG_OUTPUT"/fai/
       rm -rf "$CHROOT_OUTPUT"/var/log/fai
+
+      # store copy of autogenerated configuration file
+      cp ${GRML_FAI_CONFIG}/nfsroot.conf "$LOG_OUTPUT"/fai/
+
       # copy fai package list
       cp "$CHROOT_OUTPUT"/var/log/install_packages.list "$LOG_OUTPUT"/fai/
       # fixup owners