Update resolv.conf handling to properly support /run (see issue984).
[grml-live.git] / etc / grml / fai / config / scripts / GRMLBASE / 96-apt-listbugs
1 #!/bin/bash
2 # Filename:      /etc/grml/fai/config/scripts/GRMLBASE/96-apt-listbugs
3 # Purpose:       retreive list of bugreports of installed packages inside 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 -e
10
11 if [ -r $target/etc/apt/apt.conf.d/10apt-listbugs ] ; then
12    if [ -x $target/usr/sbin/apt-listbugs ] ; then
13       sed -i 's#//DPkg::#DPkg::#' $target/etc/apt/apt.conf.d/10apt-listbugs
14    fi
15 fi
16
17 if ifclass RELEASE ; then
18
19   HOSTNAME=''
20   [ -r /etc/grml/grml-live.conf ]  && . /etc/grml/grml-live.conf
21   [ -r /etc/grml/grml-live.local ] && . /etc/grml/grml-live.local
22   [ -n "$HOSTNAME" ] || HOSTNAME=grml
23
24   if [ -r /etc/resolv.conf ] ; then
25     if [ -d $target/etc/resolvconf/run ] ; then # resolvconf without /run
26       # sanity check to avoid "input file is output file",
27       # see http://bts.grml.org/grml/issue984
28       if ! [ -L $target/etc/resolvconf/run/resolv.conf ] ; then
29         cat /etc/resolv.conf >> $target/etc/resolvconf/run/resolv.conf
30       else
31         echo "Error: /etc/resolvconf/run/resolv.conf in chroot should not be a symlink." >&2
32         echo "       Looks like something is wrong, please fix manually." >&2
33         exit 1
34       fi
35     elif [ -L $target/etc/resolvconf/run ] ; then # resolvconf with /run
36       # /etc/resolvconf/run symlinks to /run/resolvconf
37       mkdir -p $target/run/resolvconf
38       cat /etc/resolv.conf >> $target/run/resolvconf/resolv.conf
39     else # no resolvconf installed in chroot
40       if ! [ -L $target/etc/resolv.conf ] ; then
41         cat /etc/resolv.conf >> $target/etc/resolv.conf
42       else
43         echo "Error: /etc/resolv.conf in chroot should not be a symlink (resolvconf not installed)." >&2
44         exit 1
45       fi
46     fi
47   fi
48
49   if [ -x $target/usr/sbin/apt-listbugs -a -x $target/usr/bin/apt-show-source ] && \
50      [ -x $target/etc/apt/grml/listbugs ] ; then
51      for severity in critical grave serious ; do
52          SEVERITY=$severity $ROOTCMD /etc/apt/grml/listbugs > \
53          /var/log/fai/$HOSTNAME/last/bugs.${severity} || true # make sure it does not fail
54      done
55   fi
56
57 fi
58
59 ## END OF FILE #################################################################