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