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