Unconditionally reset resolv.conf in chroot
authorChristian Hofstaedtler <ch@grml.org>
Mon, 26 Dec 2011 16:59:26 +0000 (17:59 +0100)
committerUlrich Dangel <mru@grml.org>
Mon, 26 Dec 2011 22:02:09 +0000 (23:02 +0100)
etc/grml/fai/config/hooks/instsoft.GRMLBASE
etc/grml/fai/config/scripts/GRMLBASE/98-clean-chroot

index 51a0e77..a3c3d2f 100755 (executable)
@@ -20,33 +20,10 @@ fi
 if [ "$FAI_ACTION" = "softupdate" ] ; then
    echo "Action $FAI_ACTION of FAI (hooks/instsoft.GRMLBASE) via grml-live running"
 
-   if [ -r /etc/resolv.conf ] ; then
-     case "$(chroot $target readlink -f /etc/resolv.conf)" in
-       /run/*) # resolvconf with /run
-         mkdir -p $target/run/resolvconf
-         cat /etc/resolv.conf >> $target/run/resolvconf/resolv.conf
-         ;;
-       /lib/*) # resolvconf without /run
-         # sanity check to avoid "input file is output file",
-         # see http://bts.grml.org/grml/issue984
-         if ! [ -L $target/etc/resolvconf/run/resolv.conf ] ; then
-           cat /etc/resolv.conf >> $target/etc/resolvconf/run/resolv.conf
-         else
-           echo "Error: /etc/resolvconf/run/resolv.conf in chroot should not be a symlink." >&2
-           echo "       Looks like something is wrong, please fix manually." >&2
-           exit 1
-         fi
-         ;;
-       *) # no resolvconf
-         if ! [ -L $target/etc/resolv.conf ] ; then
-           cat /etc/resolv.conf >> $target/etc/resolv.conf
-         else
-           echo "Error: /etc/resolv.conf in chroot should not be a symlink (resolvconf not installed)." >&2
-           exit 1
-         fi
-         ;;
-     esac
-   fi
+   # /etc/resolv.conf is usually a symlink, pointing out of the chroot.
+   # Make it a file with known contents.
+   rm -f "${target}"/etc/resolv.conf
+   cat /etc/resolv.conf >> "$target"/etc/resolv.conf
 
    if [ -r $target/etc/policy-rc.d.conf ] ; then
       sed -i "s/EXITSTATUS=.*/EXITSTATUS='101'/" $target/etc/policy-rc.d.conf
index 712ef68..d36013c 100755 (executable)
@@ -188,23 +188,21 @@ if ! [ -d $target/etc/resolvconf ] ; then
   echo "Warning: resolvconf not installed"
 else
   echo "Setting up resolvconf"
-  if [ -L $target/etc/resolvconf/run ] ; then # resolvconf with /run
-    # /etc/resolvconf/run symlinks to /run/resolvconf
-    RESOLV_CONF=/run/resolvconf/
-  else # no /run present
-    RESOLV_CONF=/etc/resolvconf/run/
-  fi
-
-  rm -rf   ${target}/${RESOLV_CONF}
-  mkdir -p ${target}/${RESOLV_CONF}
+  if [ ! -L $target/etc/resolvconf/run ] ; then # resolvconf without symlink?!
+    RESOLV_CONF=/etc/resolvconf/run
+    rm -rf   ${target}/${RESOLV_CONF}
+    mkdir -p ${target}/${RESOLV_CONF}
 
-  touch ${target}/${RESOLV_CONF}/enable-updates
-  mkdir ${target}/${RESOLV_CONF}/interface
+    touch ${target}/${RESOLV_CONF}/enable-updates
+    mkdir ${target}/${RESOLV_CONF}/interface
 
-  cat > ${target}/${RESOLV_CONF}/resolv.conf << EOF
+    cat > ${target}/${RESOLV_CONF}/resolv.conf << EOF
 # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
 #     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
 EOF
+  fi
+  rm -f ${target}/etc/resolv.conf
+  $ROOTCMD ln -s /etc/resolvconf/run/resolv.conf /etc/resolv.conf
 fi
 
 if ! $ROOTCMD test -x /usr/bin/updatedb ; then