Append nameservers provided via dns bootoption into initramfs resolv.conf
[live-boot-grml.git] / debian / patches / 26_support_dns_bootoption.patch
1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## 26_support_dns_bootoption.dpatch by Michael Prokop <mika@grml.org>
3 ##
4 ## All lines beginning with `## DP:' are a description of the patch.
5 ## DP: Support dns bootoption. Usage examples: dns=8.8.8.8 / dns=8.8.8.8,1.2.3.4
6
7 @DPATCH@
8 --- a/scripts/live
9 +++ b/scripts/live
10 @@ -77,6 +77,18 @@
11                                 BOOTIF="${x#BOOTIF=}"
12                                 ;;
13  
14 +                       dns=*)
15 +                               DNSSERVER="${ARGUMENT#*=}"
16 +                               if echo "${DNSSERVER}" | grep -q , ; then
17 +                                       DNSSERVER1="${DNSSERVER%,*}"
18 +                                       DNSSERVER2="${DNSSERVER#*,}"
19 +                                       export DNSSERVER1 DNSSERVER2
20 +                               else
21 +                                       DNSSERVER1="$DNSSERVER"
22 +                                       export DNSSERVER1
23 +                               fi
24 +                               unset DNSSERVER
25 +                               ;;
26                         debug)
27                                 DEBUG="Yes"
28                                 export DEBUG
29 @@ -846,7 +858,7 @@
30                                 echo "search ${DNSDOMAIN}" >> /etc/resolv.conf
31                         fi
32  
33 -                       for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1}
34 +                       for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1} ${DNSSERVER1} ${DNSSERVER2}
35                         do
36                                 if [ -n "$i" ] && [ "$i" != 0.0.0.0 ]
37                                 then
38 --- a/scripts/live-bottom/23networking_grml
39 +++ b/scripts/live-bottom/23networking_grml
40 @@ -44,7 +44,12 @@
41  
42  # prepare a new /etc/network/interfaces file (and, possibly, a new /etc/resolv.conf)
43  IFFILE="/root/etc/network/interfaces"
44 -RESOLVCONF="/root/etc/resolv.conf"
45 +if [ -L /root/etc/resolv.conf ] ; then
46 +  # assume we have resolvconf
47 +  RESOLVCONF=/root/etc/resolvconf/resolv.conf.d/base
48 +else
49 +  RESOLVCONF="/root/etc/resolv.conf"
50 +fi
51  
52  # config for loopback networking
53  cat > $IFFILE << EOF
54 @@ -105,3 +110,17 @@
55  
56      echo>> $IFFILE
57  done
58 +
59 +# dns bootoption
60 +if [ -n "$DNSSERVER1" ]
61 +then
62 +       # disable any existing entries
63 +       if [ -r $RESOLVCONF ]
64 +       then
65 +               sed -i 's/nameserver/# nameserver/' $RESOLVCONF
66 +       fi
67 +       for i in $DNSSERVER1 $DNSSERVER2
68 +       do
69 +               echo "nameserver $i" >> $RESOLVCONF
70 +       done
71 +fi