rework resolvconf handling
[grml-live.git] / etc / grml / fai / config / hooks / instsoft.GRMLBASE
1 #!/bin/bash
2 # Filename:      ${GRML_FAI_CONFIG}/hooks/instsoft.GRMLBASE
3 # Purpose:       Grml specific software installation in the chroot, executed after updatebase
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2 or any later version.
7 ################################################################################
8
9 set -u
10 set -e
11
12 # if hooks/updatebase.GRMLBASE fails for whatever reason
13 # and can't skip instsoft.GRMLBASE we have to make sure
14 # we exit here as well
15 if [ -n "$BUILD_ONLY" ] ; then
16    "Exiting hooks/instsoft.GRMLBASE as BUILD_ONLY environment is set."
17    exit 0
18 fi
19
20 if [ "$FAI_ACTION" = "softupdate" ] ; then
21    echo "Action $FAI_ACTION of FAI (hooks/instsoft.GRMLBASE) via grml-live running"
22
23    if [ -r /etc/resolv.conf ] ; then
24      case "$(readlink -f ${target}/etc/resolv.conf)" in
25        /run/*) # resolvconf with /run
26          mkdir -p $target/run/resolvconf
27          cat /etc/resolv.conf >> $target/run/resolvconf/resolv.conf
28          ;;
29        /lib/*) # resolvconf without /run
30          # sanity check to avoid "input file is output file",
31          # see http://bts.grml.org/grml/issue984
32          if ! [ -L $target/etc/resolvconf/run/resolv.conf ] ; then
33            cat /etc/resolv.conf >> $target/etc/resolvconf/run/resolv.conf
34          else
35            echo "Error: /etc/resolvconf/run/resolv.conf in chroot should not be a symlink." >&2
36            echo "       Looks like something is wrong, please fix manually." >&2
37            exit 1
38          fi
39          ;;
40        *) # no resolvconf
41          if ! [ -L $target/etc/resolv.conf ] ; then
42            cat /etc/resolv.conf >> $target/etc/resolv.conf
43          else
44            echo "Error: /etc/resolv.conf in chroot should not be a symlink (resolvconf not installed)." >&2
45            exit 1
46          fi
47          ;;
48      esac
49    fi
50
51    if [ -r $target/etc/policy-rc.d.conf ] ; then
52       sed -i "s/EXITSTATUS=.*/EXITSTATUS='101'/" $target/etc/policy-rc.d.conf
53    fi
54
55    # we definitely don't want to fail running fai sofupdate just
56    # because of some well known bugs:
57    [ -d $target/etc/apt/apt.conf.d ] || mkdir $target/etc/apt/apt.conf.d
58    cat > $target/etc/apt/apt.conf.d/10apt-listbugs << EOF
59 // Check all packages whether they has critical bugs before they are installed.
60 // If you don't like it, comment it out.
61 //DPkg::Pre-Install-Pkgs {"/usr/sbin/apt-listbugs apt || exit 10"};
62 //DPkg::Tools::Options::/usr/sbin/apt-listbugs "";
63 //DPkg::Tools::Options::/usr/sbin/apt-listbugs::Version "2";
64 EOF
65
66    # work around /etc/kernel/postinst.d/zz-update-grub failing
67    # inside openvz environment, see #597084
68    if ! $ROOTCMD dpkg-divert --list | grep -q '/usr/sbin/update-grub' ; then
69      echo "Diverting update-grub executable"
70      $ROOTCMD dpkg-divert --rename --add /usr/sbin/update-grub
71      $ROOTCMD ln -s /bin/true /usr/sbin/update-grub
72    fi
73
74   # newer aptitude versions won't remove essential packages using
75   # 'aptitude -f -y install file-rc' anymore, therefore force it:
76   $ROOTCMD aptitude -o Aptitude::ProblemResolver::Keep-All-Tier=60000 -f -y install file-rc
77
78    if ! $ROOTCMD test -x /usr/bin/aptitude ; then
79       $ROOTCMD apt-get -y install aptitude
80    fi
81
82    # make sure we can upgrade automatically,
83    # even with unsigned repos, but only if user wants it
84    if [ "${FAI_ALLOW_UNSIGNED:-}" = "1" ] ; then
85      APTGET_OPTS="${APTGET_OPTS:-} --allow-unauthenticated"
86      APTITUDE_OPTS="${APTITUDE_OPTS:-} --allow-untrusted"
87    fi
88
89    if $ROOTCMD test -x /usr/bin/aptitude ; then
90       if $ROOTCMD aptitude --help | grep -q safe-upgrade ; then
91          APT_LISTCHANGES_FRONTEND=none APT_LISTBUGS_FRONTEND=none $ROOTCMD aptitude -y $APTITUDE_OPTS safe-upgrade
92       else
93          APT_LISTCHANGES_FRONTEND=none APT_LISTBUGS_FRONTEND=none $ROOTCMD aptitude -y $APTITUDE_OPTS upgrade
94       fi
95    else
96       APT_LISTCHANGES_FRONTEND=none APT_LISTBUGS_FRONTEND=none $ROOTCMD apt-get -y $APTGET_OPTS --force-yes upgrade
97    fi
98
99    exit # make sure we don't continue behind the following "fi"
100 fi
101
102 # no softupdate but fresh installation
103 echo "Action $FAI_ACTION of FAI (hooks/instsoft.GRMLBASE) via grml-live running"
104
105 # make sure we have file-rc available before package_config/GRML* is being executed {{{
106 # the apt-get update might return an error if there's for example
107 # a hashsum mismatch on Debian mirror sources, we might want to continue
108 # but should warn the user
109 if ! $ROOTCMD apt-get update ; then
110    echo "Warning: there was an error executing apt-get update, continuing anyway."
111    echo "Warning: there was an error executing apt-get update, continuing anyway." >&2
112 fi
113
114 # newer aptitude versions won't remove essential packages using
115 # 'aptitude -f -y install file-rc' anymore, therefore force it via:
116 $ROOTCMD aptitude -o Aptitude::ProblemResolver::Keep-All-Tier=60000 -f -y install file-rc
117 # }}}
118
119 # get rid of insserv:
120 if $ROOTCMD dpkg --list insserv 2>/dev/null | grep -q '^ii' ; then
121    $ROOTCMD apt-get -y --purge remove insserv
122 fi
123
124 # we definitely don't want to fail running fai dirinstall just
125 # because of some well known bugs:
126 [ -d $target/etc/apt/apt.conf.d ] || mkdir $target/etc/apt/apt.conf.d
127 cat > $target/etc/apt/apt.conf.d/10apt-listbugs << EOF
128 // Check all packages whether they has critical bugs before they are installed.
129 // If you don't like it, comment it out.
130 //DPkg::Pre-Install-Pkgs {"/usr/sbin/apt-listbugs apt || exit 10"};
131 //DPkg::Tools::Options::/usr/sbin/apt-listbugs "";
132 //DPkg::Tools::Options::/usr/sbin/apt-listbugs::Version "2";
133 EOF
134
135 # make sure /dev/MAKEDEV is available:
136 if [ -x "$target"/sbin/MAKEDEV ] && ! [ -r "$target"/dev/MAKEDEV ] ; then
137    ln -s /sbin/MAKEDEV "$target"/dev/MAKEDEV
138 fi
139
140 # we don't need the invoke-rc.d.d diversion (we have grml-policyrcd :)):
141 if [ -L "$target"/usr/sbin/invoke-rc.d ] ; then
142    rm -f "$target"/usr/sbin/invoke-rc.d
143    $ROOTCMD dpkg-divert --package fai --rename --remove /usr/sbin/invoke-rc.d
144 fi
145
146 ## END OF FILE #################################################################
147 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2