libc: make stdio_impl.h an internal libc header
[unleashed/tickless.git] / usr / src / lib / libresolv2 / dns-install
blobd5c17e205d17924424339d4ea3693ecc7d8b9976
1 #!/sbin/sh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
23 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
27 # Install DNS client service
30 . /lib/svc/share/smf_include.sh
31 . /lib/svc/share/net_include.sh
33 SVCCFG=/usr/sbin/svccfg
34 SVCPROP=/usr/bin/svcprop
35 SVCADM=/usr/sbin/svcadm
37 DNS_NWAM_FMRI="svc:/network/physical:nwam"
38 DNS_INSTALL_FMRI=$SMF_FMRI
40 DNS_INSTALL_PG="install_props"
42 DNS_UNDEFINED_STRING_PROP="\"\""
44 dns_install_debug=0
46 unset dns_install_domain dns_install_servers dns_install_search
48 dns_process_install_pg()
50 dns_install_domain=""
51 dns_install_servers=""
52 dns_install_search=""
53 config=0
56 # Retrieve the name server property values.
58 prop=`$SVCPROP -p $DNS_INSTALL_PG/nameserver $DNS_INSTALL_FMRI`
59 if [ $? -eq 0 -a "$prop" != "$NET_INADDR_ANY" ]; then
60 dns_install_servers=$prop
61 config=1
65 # Retrieve the name service domain.
67 prop=`$SVCPROP -p $DNS_INSTALL_PG/domain $DNS_INSTALL_FMRI`
68 if [ $? -eq 0 -a "$prop" != "$DNS_UNDEFINED_STRING_PROP" ]; then
69 dns_install_domain=$prop
70 config=1
74 # Retrieve the search list.
76 prop=`$SVCPROP -p $DNS_INSTALL_PG/search $DNS_INSTALL_FMRI`
77 if [ $? -eq 0 -a "$prop" != "$DNS_UNDEFINED_STRING_PROP" ]; then
78 dns_install_search=$prop
79 config=1
82 [ $config -ne 0 ] || return $SMF_EXIT_OK
85 # Create the resolv.conf file.
87 /usr/bin/touch /etc/resolv.conf.$$
88 if [ $? -ne 0 ]; then
89 net_record_err "Error creating \"/etc/resolv.conf.$$\"" $?
90 return $SMF_EXIT_ERR_FATAL
93 for j in $dns_install_servers
95 server=`echo $j | /usr/bin/sed s/\"//g`
96 echo "nameserver $server" >>/etc/resolv.conf.$$
97 done
99 if [ "$dns_install_domain" != "" ]; then
100 echo "domain $dns_install_domain" >>/etc/resolv.conf.$$
103 if [ "$dns_install_search" != "" ]; then
104 list="search"
105 for j in $dns_install_search
107 domain=`echo $j | /usr/bin/sed s/\"//g`
108 list="$list $domain"
109 done
110 echo $list >>/etc/resolv.conf.$$
113 /usr/bin/mv /etc/resolv.conf.$$ /etc/resolv.conf
114 if [ $? -ne 0 ]; then
115 err=$?
116 msg="Error moving /etc/resolv.conf.$$ to \"/etc/resolv.conf\""
117 net_record_err "$msg" $err
118 return $SMF_EXIT_ERR_FATAL
121 /usr/bin/chmod 644 /etc/resolv.conf
122 if [ $? -ne 0 ]; then
123 err=$?
124 msg="Error setting permissions on \"/etc/resolv.conf\""
125 net_record_err "$msg" $err
126 return $SMF_EXIT_ERR_FATAL
130 # Create the nsswitch.conf file
132 /usr/bin/cp -f /etc/nsswitch.dns /etc/nsswitch.conf
133 if [ $? -ne 0 ]; then
134 err=$?
135 msg="Error copying /etc/nsswitch.dns to \"/etc/nsswitch.conf\""
136 net_record_err "$msg" $err
137 return $SMF_EXIT_ERR_FATAL
140 /usr/bin/chmod 644 /etc/nsswitch.conf
141 if [ $? -ne 0 ]; then
142 err=$?
143 msg="Error setting permissions on \"/etc/nsswitch.conf\""
144 net_record_err "$msg" $err
145 return $SMF_EXIT_ERR_FATAL
148 return $SMF_EXIT_OK
151 dns_process_install()
153 vout=`$SVCCFG -s $DNS_INSTALL_FMRI validate 2>&1`
154 if [ "$vout" != "" ]; then
155 msg="Validation errors in $DNS_INSTALL_FMRI:\n$vout"
156 net_record_err "$msg" 0
157 return $SMF_EXIT_ERR_CONFIG
160 ecode=$SMF_EXIT_OK
161 errs=0
162 cnt=0
163 pg=`$SVCPROP -p $DNS_INSTALL_PG $DNS_INSTALL_FMRI`
164 if [ $? -eq 0 ]; then
165 if service_is_enabled $DNS_NWAM_FMRI; then
166 echo "NWAM enabled. Install static" \
167 "DNS configuration ignored." | smf_console
168 errs=`expr $errs + 1`
169 ecode=$SMF_EXIT_ERR_CONFIG
170 else
171 dns_process_install_pg
172 if [ $? -ne $SMF_EXIT_OK ]; then
173 ecode=$?
174 errs=`expr $errs + 1`
175 else
176 cnt=`expr $cnt + 1`
180 $SVCCFG -s $DNS_INSTALL_FMRI delpg $DNS_INSTALL_PG
181 $SVCCFG -s $DNS_INSTALL_FMRI refresh
184 if [ $dns_install_debug -eq 1 ]; then
185 if [ $errs -ne 0 ]; then
186 echo "$errs errors encountered" \
187 "configuring DNS on behalf of install"
190 if [ $cntf -ne 0 ]; then
191 echo "DNS configured on behalf of install"
195 return $ecode
199 # Script execution starts here.
201 dns_process_install || exit $?
203 $SVCADM disable $DNS_INSTALL_FMRI
204 exit $SMF_EXIT_OK