Print this page
XXX Remove nawk(1)


 120 # update_resolv()
 121 # Go through /etc/resolv.conf and replace any existing domain or
 122 # nameserver entries with new ones derived from DHCP.  Note that
 123 # it is important to preserve order of domain entries vs. search
 124 # entries; the search entries are reserved for administrator
 125 # customization and if placed after the domain entry will override
 126 # it.  See resolv.conf(4).
 127 #
 128 # The first arg should be the dns servers string, the second
 129 # should be the dns domain.
 130 #
 131 update_resolv ()
 132 {
 133         dnsservers=$1
 134         dnsdomain=$2
 135 
 136         if [ ! -f /etc/resolv.conf ]; then
 137                 /usr/bin/touch /etc/resolv.conf
 138         fi
 139         export dnsservers dnsdomain
 140         /usr/bin/nawk </etc/resolv.conf >/tmp/resolv.conf.$$ '
 141                 function writedomain() {
 142                         if (updated == 0) {
 143                                 # Use only first domain, not a search list
 144                                 split(ENVIRON["dnsdomain"], d)
 145                                 if(length(d[1]) != 0)
 146                                         printf("domain %s\n", d[1])
 147                         }
 148                         ++updated
 149                 }
 150                 $1 == "domain" { writedomain(); next }
 151                 $1 != "nameserver" { print $0 }
 152                 END {
 153                         writedomain()
 154                         n = split(ENVIRON["dnsservers"], s)
 155                         for (i = 1; i <= n; ++i)
 156                                 printf("nameserver %s\n", s[i])
 157                 }'
 158         unset dnsservers dnsdomain
 159         mv_file /tmp/resolv.conf.$$ /etc/resolv.conf 644
 160 }


 202 # Remove any lines with the "# Added by DHCP" tag from /etc/nsswitch.conf;
 203 # also uncomment hosts and ipnodes entries which were previously commented
 204 # out by this script.
 205 #
 206 cleanup_nss ()
 207 {
 208         /usr/bin/sed \
 209             -e '/# Added by DHCP$/d' \
 210             -e 's/^\(#hosts:\)\(.*[^#]\)\(#.*\)$/hosts: \2/' \
 211             -e 's/^\(#ipnodes:\)\(.*[^#]\)\(#.*\)$/ipnodes: \2/' \
 212             /etc/nsswitch.conf >/tmp/nsswitch.conf.$$
 213 
 214         mv_file /tmp/nsswitch.conf.$$ /etc/nsswitch.conf 644
 215 }
 216 
 217 #
 218 # Remove any lines with the "# Added by DHCP" tag from /etc/inet/hosts.
 219 #
 220 cleanup_hosts ()
 221 {
 222         /usr/bin/nawk '{
 223                 if (index($0, "# Added by DHCP") == 0 ||
 224                     $1 == "127.0.0.1" || $1 == "::1") {
 225                         print $0
 226                 }
 227         }' /etc/inet/hosts > /tmp/hosts.$$
 228         mv_file /tmp/hosts.$$ /etc/inet/hosts 444
 229 }
 230 
 231 #
 232 # If our network configuration strategy is DHCP, check for DNS
 233 # configuration parameters obtained from the DHCP server.
 234 #
 235 # Script execution starts here.
 236 #
 237 smf_netstrategy
 238 
 239 if [ "$_INIT_NET_STRATEGY" = "dhcp" ]; then
 240         dnsservers=`get_dhcp_var DNSserv`
 241         dnsdomain=`get_dhcp_var DNSdmain`
 242 else




 120 # update_resolv()
 121 # Go through /etc/resolv.conf and replace any existing domain or
 122 # nameserver entries with new ones derived from DHCP.  Note that
 123 # it is important to preserve order of domain entries vs. search
 124 # entries; the search entries are reserved for administrator
 125 # customization and if placed after the domain entry will override
 126 # it.  See resolv.conf(4).
 127 #
 128 # The first arg should be the dns servers string, the second
 129 # should be the dns domain.
 130 #
 131 update_resolv ()
 132 {
 133         dnsservers=$1
 134         dnsdomain=$2
 135 
 136         if [ ! -f /etc/resolv.conf ]; then
 137                 /usr/bin/touch /etc/resolv.conf
 138         fi
 139         export dnsservers dnsdomain
 140         /usr/xpg4/bin/awk </etc/resolv.conf >/tmp/resolv.conf.$$ '
 141                 function writedomain() {
 142                         if (updated == 0) {
 143                                 # Use only first domain, not a search list
 144                                 split(ENVIRON["dnsdomain"], d)
 145                                 if(length(d[1]) != 0)
 146                                         printf("domain %s\n", d[1])
 147                         }
 148                         ++updated
 149                 }
 150                 $1 == "domain" { writedomain(); next }
 151                 $1 != "nameserver" { print $0 }
 152                 END {
 153                         writedomain()
 154                         n = split(ENVIRON["dnsservers"], s)
 155                         for (i = 1; i <= n; ++i)
 156                                 printf("nameserver %s\n", s[i])
 157                 }'
 158         unset dnsservers dnsdomain
 159         mv_file /tmp/resolv.conf.$$ /etc/resolv.conf 644
 160 }


 202 # Remove any lines with the "# Added by DHCP" tag from /etc/nsswitch.conf;
 203 # also uncomment hosts and ipnodes entries which were previously commented
 204 # out by this script.
 205 #
 206 cleanup_nss ()
 207 {
 208         /usr/bin/sed \
 209             -e '/# Added by DHCP$/d' \
 210             -e 's/^\(#hosts:\)\(.*[^#]\)\(#.*\)$/hosts: \2/' \
 211             -e 's/^\(#ipnodes:\)\(.*[^#]\)\(#.*\)$/ipnodes: \2/' \
 212             /etc/nsswitch.conf >/tmp/nsswitch.conf.$$
 213 
 214         mv_file /tmp/nsswitch.conf.$$ /etc/nsswitch.conf 644
 215 }
 216 
 217 #
 218 # Remove any lines with the "# Added by DHCP" tag from /etc/inet/hosts.
 219 #
 220 cleanup_hosts ()
 221 {
 222         /usr/xpg4/bin/awk '{
 223                 if (index($0, "# Added by DHCP") == 0 ||
 224                     $1 == "127.0.0.1" || $1 == "::1") {
 225                         print $0
 226                 }
 227         }' /etc/inet/hosts > /tmp/hosts.$$
 228         mv_file /tmp/hosts.$$ /etc/inet/hosts 444
 229 }
 230 
 231 #
 232 # If our network configuration strategy is DHCP, check for DNS
 233 # configuration parameters obtained from the DHCP server.
 234 #
 235 # Script execution starts here.
 236 #
 237 smf_netstrategy
 238 
 239 if [ "$_INIT_NET_STRATEGY" = "dhcp" ]; then
 240         dnsservers=`get_dhcp_var DNSserv`
 241         dnsdomain=`get_dhcp_var DNSdmain`
 242 else