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