instsoft.GRMLBASE: do not run explicit apt-get update any longer
[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    # work around /etc/kernel/postinst.d/zz-update-grub failing
64    # inside openvz environment, see #597084
65    if ! $ROOTCMD dpkg-divert --list | grep -q '/usr/sbin/update-grub' ; then
66      echo "Diverting update-grub executable"
67      $ROOTCMD dpkg-divert --rename --add /usr/sbin/update-grub
68      $ROOTCMD ln -s /bin/true /usr/sbin/update-grub
69    fi
70
71   # newer aptitude versions won't remove essential packages using
72   # 'aptitude -f -y install file-rc' anymore, therefore force it:
73   $ROOTCMD aptitude -o Aptitude::ProblemResolver::Keep-All-Tier=60000 -f -y install file-rc
74
75    if ! $ROOTCMD test -x /usr/bin/aptitude ; then
76       $ROOTCMD apt-get -y install aptitude
77    fi
78
79    # make sure we can upgrade automatically,
80    # even with unsigned repos, but only if user wants it
81    if [ "${FAI_ALLOW_UNSIGNED:-}" = "1" ] ; then
82      APTGET_OPTS="${APTGET_OPTS:-} --allow-unauthenticated"
83      APTITUDE_OPTS="${APTITUDE_OPTS:-} --allow-untrusted"
84    fi
85
86    if $ROOTCMD test -x /usr/bin/aptitude ; then
87       if $ROOTCMD aptitude --help | grep -q safe-upgrade ; then
88          APT_LISTCHANGES_FRONTEND=none APT_LISTBUGS_FRONTEND=none $ROOTCMD aptitude -y $APTITUDE_OPTS safe-upgrade
89       else
90          APT_LISTCHANGES_FRONTEND=none APT_LISTBUGS_FRONTEND=none $ROOTCMD aptitude -y $APTITUDE_OPTS upgrade
91       fi
92    else
93       APT_LISTCHANGES_FRONTEND=none APT_LISTBUGS_FRONTEND=none $ROOTCMD apt-get -y $APTGET_OPTS --force-yes upgrade
94    fi
95
96    exit # make sure we don't continue behind the following "fi"
97 fi
98
99 # no softupdate but fresh installation
100 echo "Action $FAI_ACTION of FAI (hooks/instsoft.GRMLBASE) via grml-live running"
101
102 # make sure we have file-rc available before package_config/GRML* is being executed {{{
103 # the apt-get update might return an error if there's for example
104 # a hashsum mismatch on Debian mirror sources, we might want to continue
105 # but should warn the user
106 if ! $ROOTCMD apt-get update ; then
107    echo "Warning: there was an error executing apt-get update, continuing anyway."
108    echo "Warning: there was an error executing apt-get update, continuing anyway." >&2
109 fi
110
111 # newer aptitude versions won't remove essential packages using
112 # 'aptitude -f -y install file-rc' anymore, therefore force it via:
113 $ROOTCMD aptitude -o Aptitude::ProblemResolver::Keep-All-Tier=60000 -f -y install file-rc
114 # }}}
115
116 # get rid of insserv:
117 if $ROOTCMD dpkg --list insserv 2>/dev/null | grep -q '^ii' ; then
118    $ROOTCMD apt-get -y --purge remove insserv
119 fi
120
121 # we definitely don't want to fail running fai dirinstall just
122 # because of some well known bugs:
123 [ -d $target/etc/apt/apt.conf.d ] || mkdir $target/etc/apt/apt.conf.d
124 cat > $target/etc/apt/apt.conf.d/10apt-listbugs << EOF
125 // Check all packages whether they has critical bugs before they are installed.
126 // If you don't like it, comment it out.
127 //DPkg::Pre-Install-Pkgs {"/usr/sbin/apt-listbugs apt || exit 10"};
128 //DPkg::Tools::Options::/usr/sbin/apt-listbugs "";
129 //DPkg::Tools::Options::/usr/sbin/apt-listbugs::Version "2";
130 EOF
131
132 # make sure /dev/MAKEDEV is available:
133 if [ -x "$target"/sbin/MAKEDEV ] && ! [ -r "$target"/dev/MAKEDEV ] ; then
134    ln -s /sbin/MAKEDEV "$target"/dev/MAKEDEV
135 fi
136
137 # we don't need the invoke-rc.d.d diversion (we have grml-policyrcd :)):
138 if [ -L "$target"/usr/sbin/invoke-rc.d ] ; then
139    rm -f "$target"/usr/sbin/invoke-rc.d
140    $ROOTCMD dpkg-divert --package fai --rename --remove /usr/sbin/invoke-rc.d
141 fi
142
143 ## END OF FILE #################################################################
144 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2