Merge remote-tracking branch 'origin/github/pr/145'
[grml-live.git] / etc / grml / fai / config / hooks / updatebase.GRMLBASE
index a501682..6588126 100755 (executable)
@@ -1,57 +1,84 @@
-#!/bin/sh
-# Filename:      /etc/grml/fai/config/hooks/updatebase.GRMLBASE
-# Purpose:       skip task updatebase of FAI when running softupdate
+#!/bin/bash
+# Filename:      ${GRML_FAI_CONFIG}/hooks/updatebase.GRMLBASE
+# Purpose:       Updates the base packages of the system, prepare chroot for instsoft
 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
 # Bug-Reports:   see http://grml.org/bugs/
 # License:       This file is licensed under the GPL v2 or any later version.
 ################################################################################
 
+set -u
+set -e
+. "$GRML_LIVE_CONFIG"
+
+# visualize chroot inside zsh:
+echo grml_chroot > $target/etc/debian_chroot
+
+echo "$HOSTNAME" > $target/etc/hostname
+
+if [ -n "${APT_PROXY:-}" ] ; then
+  cat > $target/etc/apt/apt.conf.d/90grml-apt-proxy.conf <<EOF
+Acquire::http { Proxy "$APT_PROXY"; };
+EOF
+fi
+
 if [ "$FAI_ACTION" = "softupdate" ] ; then
+   echo "Action $FAI_ACTION of FAI (hooks/updatebase.GRMLBASE) via grml-live running"
 
-   ## we want to use our own sources.list:
+   # otherwise we're running 'aptitude update' even on with -b option
    skiptask updatebase
 
-   ## make sure we don't start any daemons - removed
-   ## later on via /etc/grml/fai/config/scripts/GRMLBASE/98-clean-chroot
-   if ! [ -r $target/usr/sbin/policy-rc.d ] ; then
-      cat > $target/usr/sbin/policy-rc.d << EOF
-#!/bin/sh
-# FAI_ACTION=updatebase
-exit 101
-EOF
-      chmod 755 $target/usr/sbin/policy-rc.d
+   ## based on FAI's lib/updatebase:
+   # some packages must access /proc even in chroot environment
+   if ! [ -d $FAI_ROOT/proc/1 ] ; then
+      mount -t proc proc $FAI_ROOT/proc || true
+   fi
+   # some packages must access /sys even in chroot environment
+   if ! [ -d $FAI_ROOT/sys/kernel ] ; then
+      mount -t sysfs sysfs $FAI_ROOT/sys
+   fi
+   # if we are using udev, also mount it into $FAI_ROOT
+   if [ -f /etc/init.d/udev ] ; then
+      mount --bind /dev $FAI_ROOT/dev || true
    fi
 
-   # skip the task if we want to build a new ISO only:
-   [ -n "$BUILD_ONLY" ] && skiptask instsoft || /bin/true
+   if [ -d $FAI_ROOT/run ] ; then
+      mount -t tmpfs tmpfs $FAI_ROOT/run
+      mkdir $FAI_ROOT/run/lock
+   fi
 
-else # no softupdate but updating chroot based on /etc/grml/fai/config/basefiles/*
+   mount -t devpts devpts $FAI_ROOT/dev/pts || true
 
-# install all apt related files
-if [ -r /etc/grml/fai/files/etc/apt ] ; then
-   cp -a /etc/grml/fai/files/etc/apt/* $target/etc/apt/
-   # remove grml-live's sources.list file from chroot:
-   if [ -r $target/etc/apt/important_note.txt ] ; then
-      grep -q GRML_LIVE_SOURCES $target/etc/apt/important_note.txt && rm $target/etc/apt/important_note.txt
+   # skip the task if we want to build a new ISO only,
+   # this means we do NOT update any packages
+   if [ -n "$BUILD_ONLY" ] ; then
+      skiptask instsoft || true
    fi
 fi
 
-# install all present (but at least the grml) gpg keys:
-if [ -r /etc/grml/fai/files/etc/apt/grml.key ] ; then
-   for file in /etc/grml/fai/files/etc/apt/*.key ; do
-      FILE="$(basename $file)"
-      # installed via 'cp -a /etc/grml/fai/files/etc/apt/* $target/etc/apt/' above already
-      # cp $file $target/etc/apt/"$FILE"
-      $ROOTCMD apt-key add /etc/apt/"$FILE"
-   done
-else
-   gpg --keyserver subkeys.pgp.net      --recv-keys F61E2E7CECDEA787 || \
-   gpg --keyserver blackhole.pca.dfn.de --recv-keys F61E2E7CECDEA787
-   gpg --export F61E2E7CECDEA787 > $target/etc/apt/grml.key
-   $ROOTCMD apt-key add /etc/apt/grml.key
+if [ -n "$BOOTSTRAP_ONLY" ] ; then
+  echo "Skipping task configure in hooks/updatebase.GRMLBASE as BOOTSTRAP_ONLY environment is set."
+  skiptask configure
+fi
+
+# work around #632624: udev fails to install on systems with old kernel versions
+if ! [ -e ${target}/etc/udev/kernel-upgrade ] ; then
+  echo "Working around udev package bug, creating /etc/udev/kernel-upgrade"
+  echo "# installed via updatebase.GRMLBASE" > ${target}/etc/udev/kernel-upgrade
 fi
 
+# install all apt related files
+fcopy -i -B -v -r /etc/apt
+
+# install packages from a repository of a specific date
+if [ -n "${WAYBACK_DATE:-}" ] ; then
+  echo "Wayback date '$WAYBACK_DATE' identified, enabling for snapshot.debian.org usage."
+
+  perl -pi -e "s#^(\s+)(deb.* )(.*://ftp.debian.org.*?)\s+([a-z-]+)\s+(.*)\$#\$1\$2 [check-valid-until=no] http://snapshot.debian.org/archive/debian/$WAYBACK_DATE/ \$4 \$5#" \
+    "${target}/etc/apt/sources.list.d/debian.list"
+
+  perl -pi -e "s#^(\s+)(deb.* )(.*://security.debian.org.*?)\s+([a-z-/]+)\s+(.*)\$#\$1\$2 [check-valid-until=no] http://snapshot.debian.org/archive/debian-security/$WAYBACK_DATE/ \$4 \$5#" \
+    "${target}/etc/apt/sources.list.d/debian.list"
 fi
 
 ## END OF FILE #################################################################
-# vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=3
+# vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2