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