98-clean-chroot: check existence of updatedb binary via $ROOTCMD.
[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      if [ -d $target/etc/resolvconf/run ] ; then # resolvconf without /run
25        # sanity check to avoid "input file is output file",
26        # see http://bts.grml.org/grml/issue984
27        if ! [ -L $target/etc/resolvconf/run/resolv.conf ] ; then
28          cat /etc/resolv.conf >> $target/etc/resolvconf/run/resolv.conf
29        else
30          echo "Error: /etc/resolvconf/run/resolv.conf in chroot should not be a symlink." >&2
31          echo "       Looks like something is wrong, please fix manually." >&2
32          exit 1
33        fi
34      elif [ -L $target/etc/resolvconf/run ] ; then # resolvconf with /run
35        # /etc/resolvconf/run symlinks to /run/resolvconf
36        mkdir -p $target/run/resolvconf
37        cat /etc/resolv.conf >> $target/run/resolvconf/resolv.conf
38      else # no resolvconf installed in chroot
39        if ! [ -L $target/etc/resolv.conf ] ; then
40          cat /etc/resolv.conf >> $target/etc/resolv.conf
41        else
42          echo "Error: /etc/resolv.conf in chroot should not be a symlink (resolvconf not installed)." >&2
43          exit 1
44        fi
45      fi
46    fi
47
48    if [ -r $target/etc/policy-rc.d.conf ] ; then
49       sed -i "s/EXITSTATUS=.*/EXITSTATUS='101'/" $target/etc/policy-rc.d.conf
50    fi
51
52    # we definitely don't want to fail running fai sofupdate just
53    # because of some well known bugs:
54    [ -d $target/etc/apt/apt.conf.d ] || mkdir $target/etc/apt/apt.conf.d
55    cat > $target/etc/apt/apt.conf.d/10apt-listbugs << EOF
56 // Check all packages whether they has critical bugs before they are installed.
57 // If you don't like it, comment it out.
58 //DPkg::Pre-Install-Pkgs {"/usr/sbin/apt-listbugs apt || exit 10"};
59 //DPkg::Tools::Options::/usr/sbin/apt-listbugs "";
60 //DPkg::Tools::Options::/usr/sbin/apt-listbugs::Version "2";
61 EOF
62
63    # run it on our own, as updatebase is used at the wrong stage for our needs,
64    # see ${GRML_FAI_CONFIG}/hooks/updatebase.GRMLBASE
65    # the apt-get update might return an error if there's for example
66    # a hashsum mismatch on Debian mirror sources, we might want to continue
67    # but should warn the user
68    if ! $ROOTCMD apt-get update ; then
69       echo "Warning: there was an error executing apt-get update, continuing anyway."
70    fi
71
72    # work around /etc/kernel/postinst.d/zz-update-grub failing
73    # inside openvz environment, see #597084
74    if ! $ROOTCMD dpkg-divert --list | grep -q '/usr/sbin/update-grub' ; then
75      echo "Diverting update-grub executable"
76      $ROOTCMD dpkg-divert --rename --add /usr/sbin/update-grub
77      $ROOTCMD ln -s /bin/true /usr/sbin/update-grub
78    fi
79
80   # newer aptitude versions won't remove essential packages using
81   # 'aptitude -f -y install file-rc' anymore, therefore force it:
82   $ROOTCMD aptitude -o Aptitude::ProblemResolver::Keep-All-Tier=60000 -f -y install file-rc
83
84    if ! [ -x $target/usr/bin/aptitude ] ; then
85       $ROOTCMD apt-get -y install aptitude
86    fi
87
88    if [ -x $target/usr/bin/aptitude ] ; then
89       if $ROOTCMD aptitude --help | grep -q safe-upgrade ; then
90          APT_LISTCHANGES_FRONTEND=none APT_LISTBUGS_FRONTEND=none $ROOTCMD aptitude -y safe-upgrade
91       else
92          APT_LISTCHANGES_FRONTEND=none APT_LISTBUGS_FRONTEND=none $ROOTCMD aptitude -y upgrade
93       fi
94    else
95       APT_LISTCHANGES_FRONTEND=none APT_LISTBUGS_FRONTEND=none $ROOTCMD apt-get -y upgrade
96    fi
97
98    exit # make sure we don't continue behind the following "fi"
99 fi
100
101 # no softupdate but fresh installation
102 echo "Action $FAI_ACTION of FAI (hooks/instsoft.GRMLBASE) via grml-live running"
103
104 # make sure we have file-rc available before package_config/GRML* is being executed {{{
105 # the apt-get update might return an error if there's for example
106 # a hashsum mismatch on Debian mirror sources, we might want to continue
107 # but should warn the user
108 if ! $ROOTCMD apt-get update ; then
109    echo "Warning: there was an error executing apt-get update, continuing anyway."
110    echo "Warning: there was an error executing apt-get update, continuing anyway." >&2
111 fi
112
113 # newer aptitude versions won't remove essential packages using
114 # 'aptitude -f -y install file-rc' anymore, therefore force it via:
115 $ROOTCMD aptitude -o Aptitude::ProblemResolver::Keep-All-Tier=60000 -f -y install file-rc
116 # }}}
117
118 # get rid of insserv:
119 if $ROOTCMD dpkg --list insserv 2>/dev/null | grep -q '^ii' ; then
120    $ROOTCMD apt-get -y --purge remove insserv
121 fi
122
123 # we definitely don't want to fail running fai dirinstall just
124 # because of some well known bugs:
125 [ -d $target/etc/apt/apt.conf.d ] || mkdir $target/etc/apt/apt.conf.d
126 cat > $target/etc/apt/apt.conf.d/10apt-listbugs << EOF
127 // Check all packages whether they has critical bugs before they are installed.
128 // If you don't like it, comment it out.
129 //DPkg::Pre-Install-Pkgs {"/usr/sbin/apt-listbugs apt || exit 10"};
130 //DPkg::Tools::Options::/usr/sbin/apt-listbugs "";
131 //DPkg::Tools::Options::/usr/sbin/apt-listbugs::Version "2";
132 EOF
133
134 # make sure /dev/MAKEDEV is available:
135 if [ -x "$target"/sbin/MAKEDEV ] && ! [ -r "$target"/dev/MAKEDEV ] ; then
136    ln -s /sbin/MAKEDEV "$target"/dev/MAKEDEV
137 fi
138
139 # we don't need the invoke-rc.d.d diversion (we have grml-policyrcd :)):
140 if [ -L "$target"/usr/sbin/invoke-rc.d ] ; then
141    rm -f "$target"/usr/sbin/invoke-rc.d
142    $ROOTCMD dpkg-divert --package fai --rename --remove /usr/sbin/invoke-rc.d
143 fi
144
145 ## END OF FILE #################################################################
146 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2