Check for existence of $target/etc/apt/important_note.txt before operating on it
[grml-live.git] / etc / grml / fai / config / hooks / instsoft.GRMLBASE
1 #!/bin/sh
2 # Filename:      /etc/grml/fai/config/hooks/instsoft.GRML
3 # Purpose:       grml specific Debian installation in the chroot
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 # visualize chroot inside zsh:
13 echo grml_chroot > $target/etc/debian_chroot
14
15 HOSTNAME=''
16 [ -r /etc/grml/grml-live.conf ]  && . /etc/grml/grml-live.conf
17 [ -r /etc/grml/grml-live.local ] && . /etc/grml/grml-live.local
18 [ -n "$HOSTNAME" ] || HOSTNAME=grml
19 echo "$HOSTNAME" > $target/etc/hostname
20
21 if [ "$FAI_ACTION" = "softupdate" ] ; then
22    echo "Softupdate of FAI via grml-live running"
23
24    if [ -r /etc/resolv.conf ] ; then
25       if [ -r $target/etc/resolvconf/run/resolv.conf ] ; then
26          cat /etc/resolv.conf >> $target/etc/resolvconf/run/resolv.conf
27       else
28          cat /etc/resolv.conf >> $target/etc/resolv.conf
29       fi
30    fi
31
32    if [ -r $target/etc/policy-rc.d.conf ] ; then
33       sed -i "s/EXITSTATUS=.*/EXITSTATUS='101'/" $target/etc/policy-rc.d.conf
34    fi
35
36    # we definitely don't want to fail running fai sofupdate just
37    # because of some well known bugs:
38    [ -d $target/etc/apt/apt.conf.d ] || mkdir $target/etc/apt/apt.conf.d
39    cat > $target/etc/apt/apt.conf.d/10apt-listbugs << EOF
40 // Check all packages whether they has critical bugs before they are installed.
41 // If you don't like it, comment it out.
42 //DPkg::Pre-Install-Pkgs {"/usr/sbin/apt-listbugs apt || exit 10"};
43 //DPkg::Tools::Options::/usr/sbin/apt-listbugs "";
44 //DPkg::Tools::Options::/usr/sbin/apt-listbugs::Version "2";
45 EOF
46
47    # make sure we can handle kernel upgrades:
48    if [ -r $target/etc/kernel-img.conf ] ; then
49       if ! grep -q "silent_modules = Yes" $target/etc/kernel-img.conf ; then
50          echo "silent_modules = Yes" >> $target/etc/kernel-img.conf
51       fi
52    fi
53
54    # FAI softupdate executes upgrade only with the sources.list being
55    # present in the chroot :-/ - so let's do it on our own:
56    if [ -r /etc/grml/fai/apt/sources.list ] ; then
57       if [ -L $target/etc/apt/sources.list ] ; then
58          rm $target/etc/apt/sources.list
59       fi
60       cp /etc/grml/fai/apt/sources.list $target/etc/apt/sources.list.d/grml-live.list
61    fi
62
63    # run it on our own, as updatebase is used at the wrong stage for our needs,
64    # see /etc/grml/fai/config/hooks/updatebase.GRMLBASE
65    $ROOTCMD apt-get update
66    if ! [ -x $target/usr/bin/aptitude ] ; then
67       $ROOTCMD apt-get -y install aptitude
68    fi
69
70    if [ -x $target/usr/bin/aptitude ] ; then
71       if $ROOTCMD aptitude --help | grep -q safe-upgrade ; then
72          APT_LISTCHANGES_FRONTEND=none APT_LISTBUGS_FRONTEND=none $ROOTCMD aptitude -y safe-upgrade
73       else
74          APT_LISTCHANGES_FRONTEND=none APT_LISTBUGS_FRONTEND=none $ROOTCMD aptitude -y upgrade
75       fi
76    else
77       APT_LISTCHANGES_FRONTEND=none APT_LISTBUGS_FRONTEND=none $ROOTCMD apt-get -y upgrade
78    fi
79
80 else # no softupdate but fresh installation
81
82 # install all apt related files
83 if [ -r /etc/grml/fai/files/etc/apt ] ; then
84    cp -a /etc/grml/fai/files/etc/apt/* $target/etc/apt/
85    # remove grml-live's sources.list file from chroot:
86    if [ -r $target/etc/apt/important_note.txt ] ; then
87       grep -q GRML_LIVE_SOURCES $target/etc/apt/important_note.txt && rm $target/etc/apt/important_note.txt
88    fi
89 fi
90
91 # install all present (but at least the grml) gpg keys:
92 if [ -r /etc/grml/fai/files/etc/apt/grml.key ] ; then
93    for file in /etc/grml/fai/files/etc/apt/*.key ; do
94       FILE="$(basename $file)"
95       # installed via 'cp -a /etc/grml/fai/files/etc/apt/* $target/etc/apt/' above already
96       # cp $file $target/etc/apt/"$FILE"
97       $ROOTCMD apt-key add /etc/apt/"$FILE"
98    done
99 else
100    gpg --keyserver subkeys.pgp.net      --recv-keys F61E2E7CECDEA787 || \
101    gpg --keyserver blackhole.pca.dfn.de --recv-keys F61E2E7CECDEA787
102    gpg --export F61E2E7CECDEA787 > $target/etc/apt/grml.key
103    $ROOTCMD apt-key add /etc/apt/grml.key
104 fi
105
106 # make sure the file exists
107 [ -e $target/etc/apt/apt.conf ] || touch $target/etc/apt/apt.conf
108
109 # work around http://trac.lighttpd.net/trac/ticket/657
110 if ! grep -q 'Acquire::http::Pipeline-Depth.*0' $target/etc/apt/apt.conf ; then
111    echo "Acquire::http::Pipeline-Depth 0; // added by grml-live" >> $target/etc/apt/apt.conf
112 fi
113
114 # Recommends just pull in way tooooo much packages, so disable it:
115 if ! grep -q 'APT::Install-Recommends.*false' $target/etc/apt/apt.conf ; then
116    echo "APT::Install-Recommends false; // added by grml-live"   >> $target/etc/apt/apt.conf
117 fi
118
119 # Notice: deprecated with aptitude (0.4.11-1):
120 if ! grep -q 'Aptitude::Recommends-Important.*false' $target/etc/apt/apt.conf ; then
121    echo "Aptitude::Recommends-Important false; // added by grml-live" >> $target/etc/apt/apt.conf
122 fi
123
124 # make sure we have file-rc available before
125 # package_config/GRML is being executed:
126 $ROOTCMD apt-get update
127 $ROOTCMD aptitude -f -y install file-rc
128
129 # we definitely don't want to fail running fai dirinstall just
130 # because of some well known bugs:
131 [ -d $target/etc/apt/apt.conf.d ] || mkdir $target/etc/apt/apt.conf.d
132 cat > $target/etc/apt/apt.conf.d/10apt-listbugs << EOF
133 // Check all packages whether they has critical bugs before they are installed.
134 // If you don't like it, comment it out.
135 //DPkg::Pre-Install-Pkgs {"/usr/sbin/apt-listbugs apt || exit 10"};
136 //DPkg::Tools::Options::/usr/sbin/apt-listbugs "";
137 //DPkg::Tools::Options::/usr/sbin/apt-listbugs::Version "2";
138 EOF
139
140 # make sure /dev/MAKEDEV is available:
141 if [ -x "$target"/sbin/MAKEDEV ] && ! [ -r "$target"/dev/MAKEDEV ] ; then
142    ln -s /sbin/MAKEDEV "$target"/dev/MAKEDEV
143 fi
144
145 # we don't need the invoke-rc.d.d diversion (we have grml-policyrcd :)):
146 if [ -L "$target"/usr/sbin/invoke-rc.d ] ; then
147    rm -f "$target"/usr/sbin/invoke-rc.d
148    $ROOTCMD dpkg-divert --package fai --rename --remove /usr/sbin/invoke-rc.d
149 fi
150
151 fi # end of FAI_ACTION = softupdate
152
153 ## END OF FILE #################################################################
154 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=3