Merge branch 'mika/release_0.14.1'
[grml-live.git] / etc / grml / fai / config / hooks / instsoft.GRMLBASE
1 #!/bin/bash
2 # Filename:      /etc/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
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      else # no resolvconf installed in chroot
35        if ! [ -L $target/etc/resolv.conf ] ; then
36          cat /etc/resolv.conf >> $target/etc/resolv.conf
37        else
38          echo "Error: /etc/resolv.conf in chroot should not be a symlink (resolvconf not installed)." >&2
39          exit 1
40        fi
41      fi
42    fi
43
44    if [ -r $target/etc/policy-rc.d.conf ] ; then
45       sed -i "s/EXITSTATUS=.*/EXITSTATUS='101'/" $target/etc/policy-rc.d.conf
46    fi
47
48    # we definitely don't want to fail running fai sofupdate just
49    # because of some well known bugs:
50    [ -d $target/etc/apt/apt.conf.d ] || mkdir $target/etc/apt/apt.conf.d
51    cat > $target/etc/apt/apt.conf.d/10apt-listbugs << EOF
52 // Check all packages whether they has critical bugs before they are installed.
53 // If you don't like it, comment it out.
54 //DPkg::Pre-Install-Pkgs {"/usr/sbin/apt-listbugs apt || exit 10"};
55 //DPkg::Tools::Options::/usr/sbin/apt-listbugs "";
56 //DPkg::Tools::Options::/usr/sbin/apt-listbugs::Version "2";
57 EOF
58
59    # FAI softupdate executes upgrade only with the sources.list being
60    # present in the chroot - so let's do it on our own:
61    if [ -r /etc/grml/fai/apt/sources.list ] ; then
62       if [ -L $target/etc/apt/sources.list ] ; then
63          rm $target/etc/apt/sources.list
64       fi
65
66       # install grml-live's (on the fly adjusted) sources.list config
67       cp /etc/grml/fai/apt/sources.list $target/etc/apt/sources.list.d/grml-live.list
68
69       # when re-running grml-live with the -u option we do not want to use the
70       # sources.list config of the live system but grml-live's config instead,
71       # therefore temporarly move known files and restore them again later on
72       # through /etc/grml/fai/config/scripts/GRMLBASE/33-aptsetup:
73       if [ -r  $target/etc/apt/sources.list.d/grml.list ] ; then
74          mv $target/etc/apt/sources.list.d/grml.list $target/etc/apt/sources.list.d/grml.unused
75       fi
76       if [ -r  $target/etc/apt/sources.list.d/debian.list ] ; then
77          mv $target/etc/apt/sources.list.d/debian.list $target/etc/apt/sources.list.d/debian.unused
78       fi
79    fi
80
81    # run it on our own, as updatebase is used at the wrong stage for our needs,
82    # see /etc/grml/fai/config/hooks/updatebase.GRMLBASE
83    # the apt-get update might return an error if there's for example
84    # a hashsum mismatch on Debian mirror sources, we might want to continue
85    # but should warn the user
86    if ! $ROOTCMD apt-get update ; then
87       echo "Warning: there was an error executing apt-get update, continuing anyway."
88    fi
89
90   # newer aptitude versions won't remove essential packages using
91   # 'aptitude -f -y install file-rc' anymore, therefore force it:
92   $ROOTCMD aptitude -o Aptitude::ProblemResolver::Keep-All-Tier=60000 -f -y install file-rc
93
94    if ! [ -x $target/usr/bin/aptitude ] ; then
95       $ROOTCMD apt-get -y install aptitude
96    fi
97
98    if [ -x $target/usr/bin/aptitude ] ; then
99       if $ROOTCMD aptitude --help | grep -q safe-upgrade ; then
100          APT_LISTCHANGES_FRONTEND=none APT_LISTBUGS_FRONTEND=none $ROOTCMD aptitude -y safe-upgrade
101       else
102          APT_LISTCHANGES_FRONTEND=none APT_LISTBUGS_FRONTEND=none $ROOTCMD aptitude -y upgrade
103       fi
104    else
105       APT_LISTCHANGES_FRONTEND=none APT_LISTBUGS_FRONTEND=none $ROOTCMD apt-get -y upgrade
106    fi
107
108    exit # make sure we don't continue behind the following "fi"
109 fi
110
111 # no softupdate but fresh installation
112 echo "Action $FAI_ACTION of FAI (hooks/instsoft.GRMLBASE) via grml-live running"
113
114 # make sure we have file-rc available before package_config/GRML* is being executed {{{
115 # the apt-get update might return an error if there's for example
116 # a hashsum mismatch on Debian mirror sources, we might want to continue
117 # but should warn the user
118 if ! $ROOTCMD apt-get update ; then
119    echo "Warning: there was an error executing apt-get update, continuing anyway."
120    echo "Warning: there was an error executing apt-get update, continuing anyway." >&2
121 fi
122
123 # newer aptitude versions won't remove essential packages using
124 # 'aptitude -f -y install file-rc' anymore, therefore force it via:
125 $ROOTCMD aptitude -o Aptitude::ProblemResolver::Keep-All-Tier=60000 -f -y install file-rc
126 # }}}
127
128 # get rid of insserv:
129 if $ROOTCMD dpkg --list insserv 2>/dev/null | grep -q '^ii' ; then
130    $ROOTCMD apt-get -y --purge remove insserv
131 fi
132
133 # we definitely don't want to fail running fai dirinstall just
134 # because of some well known bugs:
135 [ -d $target/etc/apt/apt.conf.d ] || mkdir $target/etc/apt/apt.conf.d
136 cat > $target/etc/apt/apt.conf.d/10apt-listbugs << EOF
137 // Check all packages whether they has critical bugs before they are installed.
138 // If you don't like it, comment it out.
139 //DPkg::Pre-Install-Pkgs {"/usr/sbin/apt-listbugs apt || exit 10"};
140 //DPkg::Tools::Options::/usr/sbin/apt-listbugs "";
141 //DPkg::Tools::Options::/usr/sbin/apt-listbugs::Version "2";
142 EOF
143
144 # make sure /dev/MAKEDEV is available:
145 if [ -x "$target"/sbin/MAKEDEV ] && ! [ -r "$target"/dev/MAKEDEV ] ; then
146    ln -s /sbin/MAKEDEV "$target"/dev/MAKEDEV
147 fi
148
149 # we don't need the invoke-rc.d.d diversion (we have grml-policyrcd :)):
150 if [ -L "$target"/usr/sbin/invoke-rc.d ] ; then
151    rm -f "$target"/usr/sbin/invoke-rc.d
152    $ROOTCMD dpkg-divert --package fai --rename --remove /usr/sbin/invoke-rc.d
153 fi
154
155 ## END OF FILE #################################################################
156 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=3