summaryrefslogtreecommitdiff
path: root/contrib/openvpn/dhclient-enter-hooks
blob: cb78e2acfb8834433867191764effec9cfb75732 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash

function save_previous() {
  if [ -e $1 -a ! -e $1.predhclient ]; then
    mv $1 $1.predhclient 
  fi
}

function write_resolv_conf() {
  RESOLVCONF=$1
  if [ -n "$new_domain_name" ] || [ -n "$new_domain_name_servers" ]; then
    save_previous $RESOLVCONF
    echo '; generated by /etc/dhclient-enter-hooks' > $RESOLVCONF
    if [ -n "$SEARCH" ]; then
 	echo search $SEARCH >> $RESOLVCONF
    else
	if [ -n "$new_domain_name" ]; then
 	    echo search $new_domain_name >> $RESOLVCONF
 	fi
    fi
    chmod 644 $RESOLVCONF
    for nameserver in $new_domain_name_servers; do
      echo nameserver $nameserver >>$RESOLVCONF
    done
  fi
}

make_resolv_conf() {
  write_resolv_conf /etc/resolv.conf
}