address resolvconf issues when using netboot which were raised on the ml
[live-boot-grml.git] / debian / patches / support-resolvconf-in-the-squashfs.patch
1 From 5fff70167b23195380c1e18dd9ac785641ab9f3e Mon Sep 17 00:00:00 2001
2 From: Evgeni Golov <evgeni@grml.org>
3 Date: Tue, 25 Mar 2014 08:38:58 +0100
4 Subject: [PATCH 2/2] support resolvconf in the squashfs
5
6 when resolvconf is used in the squashfs, /etc/resolv.conf is a symlink
7 to the generated version. depending on the size of the squashfs, the
8 moon phase and the charge of the flux capacitor, we sometimes try to
9 write to /etc/resolv.conf while it still points to nirvana, as resolvconf
10 did not generate it yet.
11
12 instead of being racy and writing to a file which will be regenerated
13 anyways, let's detect resolvconf and write to its base file instead.
14
15 initial detection idea by Mika Prokop <mika@grml.org>
16 ---
17  components/9990-main.sh    | 12 +++++++++---
18  components/9990-netbase.sh | 15 ++++++++++-----
19  2 files changed, 19 insertions(+), 8 deletions(-)
20
21 diff --git a/components/9990-main.sh b/components/9990-main.sh
22 index 83f087f..85b8a1d 100755
23 --- a/components/9990-main.sh
24 +++ b/components/9990-main.sh
25 @@ -178,10 +178,16 @@ Live ()
26                 fi
27         fi
28  
29 -       if [ -f /etc/resolv.conf ] && [ ! -s ${rootmnt}/etc/resolv.conf ]
30 +       if [ -L /root/etc/resolv.conf ] ; then
31 +               # assume we have resolvconf
32 +               DNSFILE="${rootmnt}/etc/resolvconf/resolv.conf.d/base"
33 +       else
34 +               DNSFILE="${rootmnt}/etc/resolv.conf"
35 +       fi
36 +       if [ -f /etc/resolv.conf ] && [ ! -s ${DNSFILE} ]
37         then
38 -               log_begin_msg "Copying /etc/resolv.conf to ${rootmnt}/etc/resolv.conf"
39 -               cp -v /etc/resolv.conf ${rootmnt}/etc/resolv.conf
40 +               log_begin_msg "Copying /etc/resolv.conf to ${DNSFILE}"
41 +               cp -v /etc/resolv.conf ${DNSFILE}
42                 log_end_msg
43         fi
44  
45 diff --git a/components/9990-netbase.sh b/components/9990-netbase.sh
46 index af3522f..a32a47b 100755
47 --- a/components/9990-netbase.sh
48 +++ b/components/9990-netbase.sh
49 @@ -16,7 +16,12 @@ Netbase ()
50         log_begin_msg "Preconfiguring networking"
51  
52         IFFILE="/root/etc/network/interfaces"
53 -       DNSFILE="/root/etc/resolv.conf"
54 +       if [ -L /root/etc/resolv.conf ] ; then
55 +               # assume we have resolvconf
56 +               DNSFILE="/root/etc/resolvconf/resolv.conf.d/base"
57 +       else
58 +               DNSFILE="/root/etc/resolv.conf"
59 +       fi
60  
61         if [ "${STATICIP}" = "frommedia" ] && [ -e "${IFFILE}" ]
62         then
63 @@ -102,7 +107,7 @@ EOF
64                         done
65                 fi
66  
67 -               if [ ! -f /root/etc/resolv.conf ] || [ -z "$(cat /root/etc/resolv.conf)" ]
68 +               if [ ! -f "${DNSFILE}" ] || [ -z "$(cat ${DNSFILE})" ]
69                 then
70                         if [ -f /netboot.config ]
71                         then
72 @@ -112,7 +117,7 @@ EOF
73                                 rc_search=$(cat netboot.config | awk '/domain/ { print $3 }')
74                                 rc_server0="$(cat netboot.config | awk '/dns0/ { print $5 }')"
75  
76 -cat > /root/etc/resolv.conf << EOF
77 +cat > $DNSFILE << EOF
78  search ${rc_search}
79  domain ${rc_search}
80  nameserver ${rc_server0}
81 @@ -122,10 +127,10 @@ EOF
82  
83                                 if [ "${rc_server1}" != "0.0.0.0" ]
84                                 then
85 -                                       echo "nameserver ${rc_server1}" >> /root/etc/resolv.conf
86 +                                       echo "nameserver ${rc_server1}" >> $DNSFILE
87                                 fi
88  
89 -                               cat /root/etc/resolv.conf >> /root/var/log/netboot.config
90 +                               cat $DNSFILE >> /root/var/log/netboot.config
91                         fi
92                 fi
93         fi
94 -- 
95 1.9.1
96