Print this page
6774 - create-client should take imagepath as optional argument
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/cmd/installadm/create-client.sh
+++ new/usr/src/cmd/installadm/create-client.sh
1 1 #!/bin/sh
2 2 #
3 3 # CDDL HEADER START
4 4 #
5 5 # The contents of this file are subject to the terms of the
6 6 # Common Development and Distribution License (the "License").
7 7 # You may not use this file except in compliance with the License.
8 8 #
9 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 # or http://www.opensolaris.org/os/licensing.
11 11 # See the License for the specific language governing permissions
12 12 # and limitations under the License.
13 13 #
14 14 # When distributing Covered Code, include this CDDL HEADER in each
15 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 # If applicable, add the following below this CDDL HEADER, with the
17 17 # fields enclosed by brackets "[]" replaced with your own identifying
18 18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 19 #
20 20 # CDDL HEADER END
21 21 #
22 22 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 # Use is subject to license terms.
24 24
25 25 #
26 26 # Description:
27 27 # Sets up client data specific for a particular client, in the
28 28 # non-default case. In general, client setup is not required and all
29 29 # clients will boot the default service as tagged in create-service.
30 30 # If it is desired to have a client boot and utilize specific services
31 31 # and manifests, this command is used to do so. The following
32 32 # functionality is provided:
33 33 #
34 34 # 1. Allow for specification of installation service for client to use.
35 35 # This will bypass the service discovery mechanism and use a specific
36 36 # service. The administrator can set up manifiests with that service
37 37 # to serve the clients.
38 38 #
39 39 # 2. For x86, creates a bootfile and /tftpboot entries. The bootfile
40 40 # name is derived from the MAC address.
41 41 # For sparc, create wanboot.conf file in following location:
42 42 #
43 43 # /etc/netboot/<network_address>/<client_id>/wanboot.conf
44 44 #
45 45 # where <client_id>=01<mac_address_without_collons>
46 46 # e.g. 0100144FA2574C
47 47 #
48 48 # 3. Setup the dhcp macro with the server and bootfile information
49 49 # if it doesn't exist.
50 50 #
51 51 # Files potentially changed on server:
52 52 # /tftpboot/ - directory created/populated with pxegrub files and links.
53 53 # /etc/inetd.conf - to turn on tftpboot daemon
54 54 # /etc/netboot/<network number>/<MACID>/wanboot.conf
55 55
56 56 # make sure path is ok
57 57 PATH=/usr/bin:/usr/sbin:/sbin:${PATH}; export PATH
58 58
59 59 # tr may fail in some locales. Hence set the env LANG=C and LC_ALL=C
60 60 TR='env LC_ALL=C LANG=C /bin/tr'
61 61
62 62 # Constants
63 63 #
64 64 SIGHUP=1
65 65 SIGINT=2
66 66 SIGQUIT=3
67 67 SIGTERM=15
68 68
69 69 # Variables
70 70 #
71 71 DHCP_CLIENT_ID=""
72 72 DIRNAME="/usr/lib/installadm"
73 73 INSTALL_TYPE="_OSInstall._tcp"
74 74 Bootdir="/tftpboot"
75 75
76 76 # Settings for client specific properties, to be passed via grub menu
77 77 #
78 78 BARGLIST=""
79 79
80 80 # import common functions
81 81 #
82 82 . ${DIRNAME}/installadm-common
83 83
84 84
85 85 # usage
|
↓ open down ↓ |
85 lines elided |
↑ open up ↑ |
86 86 #
87 87 # Purpose : Print the usage message in the event the user
88 88 # has input illegal command line parameters and
89 89 # then exit
90 90 #
91 91 # Arguments :
92 92 # none
93 93 #
94 94 usage () {
95 95 echo "Usage: $0 [-b <property>=<value>,...]"
96 - echo "\t\t-e <macaddr> -t <imagepath> -n <svcname>"
96 + echo "\t\t-e <macaddr> -n <svcname> [-t <imagepath>]"
97 97
98 98 exit 1
99 99 }
100 100
101 101 abort()
102 102 {
103 103 echo "${myname}: Aborted"
104 104 exit 1
105 105 }
106 106
107 107
108 108 #
109 109 # MAIN - Program
110 110 #
111 111
112 112 myname=`basename $0`
113 113 ID=`id`
114 114 USER=`expr "${ID}" : 'uid=\([^(]*\).*'`
115 115
116 116 unset BOOT_FILE IMAGE_PATH IMAGE_SERVER MAC_ADDR
117 117 unset SERVER SERVICE_NAME
118 118
119 119 trap abort $SIGHUP $SIGINT $SIGQUIT $SIGTERM
120 120
121 121 # Verify user ID before proceeding - must be root
122 122 #
123 123 if [ "${USER}" != "0" ]; then
124 124 echo "You must be root to run $0"
125 125 exit 1
126 126 fi
127 127
128 128
129 129 # Get SERVER info
130 130 #
131 131 SERVER_IP=`get_server_ip`
132 132 if [ -z $SERVER_IP ] ; then
133 133 echo "Failed to get server's IP address."
134 134 exit 1
135 135 fi
136 136
137 137 # Parse the command line options.
138 138 #
139 139 while [ "$1"x != "x" ]; do
140 140 case $1 in
141 141 -e) MAC_ADDR="$2";
142 142 if [ "X$MAC_ADDR" = "X" ]; then
143 143 usage ;
144 144 fi
145 145
146 146 fnum=`echo "${MAC_ADDR}" | awk 'BEGIN { FS = ":" } { print NF } ' `
147 147 if [ $fnum != 6 ]; then
148 148 echo "${myname}: malformed MAC address: $MAC_ADDR"
149 149 exit 1
150 150 fi
151 151
152 152 MAC_ADDR=`expr $MAC_ADDR : '\([0-9a-fA-F][0-9a-fA-F]*\:[0-9a-fA-F][0-9a-fA-F]*\:[0-9a-fA-F][0-9a-fA-F]*\:[0-9a-fA-F][0-9a-fA-F]*\:[0-9a-fA-F][0-9a-fA-F]*\:[0-9a-fA-F][0-9a-fA-F]*\)'`
153 153
154 154 if [ ! "${MAC_ADDR}" ] ; then
155 155 echo "${myname}: malformed MAC address: $2"
156 156 exit 1
157 157 fi
158 158 shift 2;;
159 159 -n) SERVICE_NAME=$2
160 160 if [ ! "$SERVICE_NAME" ]; then
161 161 usage ;
162 162 fi
163 163 shift 2;;
164 164
165 165 # Accept value for -t as either <server:/path> or </path>.
166 166 #
167 167 -t) if [ ! "$2" ]; then
168 168 usage;
|
↓ open down ↓ |
62 lines elided |
↑ open up ↑ |
169 169 fi
170 170 IMAGE_SERVER=`expr $2 : '\(.*\):.*'`
171 171 if [ -n "${IMAGE_SERVER}" ]; then
172 172 IMAGE_PATH=`expr $2 : '.*:\(.*\)'`
173 173 else
174 174 # no server provided, just get path
175 175 IMAGE_PATH=$2
176 176 fi
177 177 if [ ! "$IMAGE_PATH" ]; then
178 178 echo "${myname}: Invalid image pathname"
179 - usage ;
179 + usage ;
180 180 fi
181 181 shift 2;;
182 182 -f) BOOT_FILE=$2
183 183 if [ ! "$BOOT_FILE" ] ; then
184 184 usage ;
185 185 fi
186 186 shift 2;;
187 187
188 188 # -b option is used to introduce changes in a client,
189 189 # e.g. console=ttya
190 190 #
191 191 -b) BARGLIST="$BARGLIST"$2","
192 192 shift 2;;
|
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
193 193
194 194 -*) # -anything else is an unknown argument
195 195 usage ;
196 196 ;;
197 197 *) # all else is spurious
198 198 usage ;
199 199 ;;
200 200 esac
201 201 done
202 202
203 -if [ -z "${MAC_ADDR}" -o -z "${IMAGE_PATH}" -o -z "${SERVICE_NAME}" ]; then
203 +if [ -z "${MAC_ADDR}" -o -z "${SERVICE_NAME}" ]; then
204 204 echo "${myname}: Missing one or more required options."
205 205 usage
206 206 fi
207 207
208 +
209 +# Verify that service corresponding to SERVICE_NAME exists
210 +#
211 +# Check the service exists in SMF
212 +svcprop -p AI${SERVICE_NAME}/image_path \
213 + -c svc:/system/install/server:default 1>/dev/null 2>&1
214 +if [ $? -ne 0 ]; then
215 + echo "${myname}: Service does not exist: ${SERVICE_NAME}"
216 + exit 1
217 +fi
218 +# Check that the service is running
219 +${DIRNAME}/setup-service lookup ${SERVICE_NAME} ${INSTALL_TYPE} local
220 +if [ $? -ne 0 ] ; then
221 + echo "${myname}: Service does not exist: ${SERVICE_NAME}"
222 + exit 1
223 +fi
224 +
225 +
226 +# Determine IMAGE PATH if not provided
227 +#
228 +if [ -z "${IMAGE_PATH}" ]; then
229 + # Find IMAGE PATH from SMF
230 + IMAGE_PATH="`svcprop -p AI${SERVICE_NAME}/image_path \
231 + -c svc:/system/install/server:default 2>/dev/null`"
232 + if [ $? -ne 0 ]; then
233 + echo "${myname}: Image-path record for service" \
234 + "${SERVICE_NAME} is missing."
235 + exit 1
236 + fi
237 +fi
238 +
208 239 # If IMAGE_SERVER is passed in, check that it is equal to the local system
209 240 # since we don't yet support a remote system being the image server.
210 241 #
211 242 if [ -n "${IMAGE_SERVER}" ]; then
212 243 IMAGE_IP=`get_host_ip ${IMAGE_SERVER}`
213 244 if [ -z $IMAGE_IP ] ; then
214 245 echo "${myname}: Failed to get IP address for ${IMAGE_SERVER}"
215 246 exit 1
216 247 fi
217 248
218 249 if [ "${IMAGE_IP}" != "${SERVER_IP}" ]; then
219 250 echo "${myname}: Remote image server is not supported at this time."
220 251 exit 1
221 252 fi
222 253 fi
223 254
224 255 # Verify that IMAGE_PATH is a valid directory
225 256 #
226 257 if [ ! -d ${IMAGE_PATH} ]; then
227 258 echo "${myname}: Install image directory ${IMAGE_PATH} does not exist."
228 259 exit 1
229 260 fi
230 261
231 262 # Verify valid image
232 263 #
233 264 if [ ! -f ${IMAGE_PATH}/solaris.zlib ]; then
234 265 echo "${myname}: ${IMAGE_PATH}/solaris.zlib does not exist. " \
235 266 "The specified image is not an OpenSolaris image."
236 267 exit 1
237 268 fi
238 269
239 270
240 271 # Determine if image is sparc or x86
241 272 #
242 273 IMAGE_TYPE=`get_image_type ${IMAGE_PATH}`
243 274
|
↓ open down ↓ |
26 lines elided |
↑ open up ↑ |
244 275 # For sparc, make sure the user hasn't specified a boot file via
245 276 # the "-f" option. If they have, the BOOT_FILE variable will be set.
246 277 #
247 278 if [ "${IMAGE_TYPE}" = "${SPARC_IMAGE}" ]; then
248 279 if [ "X$BOOT_FILE" != "X" ] ; then
249 280 echo "${myname}: \"-f\" is an invalid option for SPARC"
250 281 exit 1
251 282 fi
252 283 fi
253 284
254 -# Verify that service corresponding to SERVICE_NAME exists
255 -#
256 -${DIRNAME}/setup-service lookup ${SERVICE_NAME} ${INSTALL_TYPE} local
257 -if [ $? -ne 0 ] ; then
258 - echo "${myname}: Service does not exist: ${SERVICE_NAME}"
259 - exit 1
260 -fi
261 -
262 285
263 286 # Convert the Ethernet address to DHCP "default client-ID" form:
264 287 # uppercase hex, preceded by the hardware
265 288 # address type ("01" for ethernet)
266 289 #
267 290 DHCP_CLIENT_ID=01`echo "${MAC_ADDR}" | ${TR} '[a-z]' '[A-Z]' |
268 291 awk -F: '
269 292 {
270 293 for (i = 1; i <= 6 ; i++)
271 294 if (length($i) == 1) {
272 295 printf("0%s", $i)
273 296 } else {
274 297 printf("%s", $i);
275 298 }
276 299 }'`
277 300
278 301
279 302 # Perform x86/sparc specific setup activities
280 303 #
281 304 if [ "${IMAGE_TYPE}" = "${X86_IMAGE}" ]; then
282 305 echo "Setting up X86 client..."
283 306 if [ "${BARGLIST}" = "" ]; then
284 307 # Set to null as a placeholder in the argument list
285 308 BARGLIST="null"
286 309 fi
287 310
288 311 #
289 312 # pass service location as "unknown" - it will be
290 313 # determined later when creating configuration file
291 314 #
292 315 ${DIRNAME}/setup-tftp-links client ${SERVICE_NAME} \
293 316 ${SERVICE_ADDRESS_UNKNOWN} ${IMAGE_PATH} ${DHCP_CLIENT_ID} \
294 317 ${BARGLIST} ${BOOT_FILE}
295 318 status=$?
296 319 if [ $status -ne 0 ]; then
297 320 echo "${myname}: Unable to setup x86 client"
298 321 exit 1
299 322 fi
300 323
301 324 # Set value of DHCP_BOOT_FILE.
302 325 DHCP_BOOT_FILE=${DHCP_CLIENT_ID}
303 326 if [ "X${BOOT_FILE}" != "X" ] ; then
304 327 DHCP_BOOT_FILE=${BOOT_FILE}
305 328 fi
306 329 dhcptype="x86"
307 330 else
308 331 echo "Setting up SPARC client..."
309 332 # For sparc, set value of DHCP_BOOT_FILE and setup wanboot.conf file.
310 333 #
311 334 DHCP_BOOT_FILE="http://${SERVER_IP}:${HTTP_PORT}/${CGIBIN_WANBOOTCGI}"
312 335 ${DIRNAME}/setup-sparc client ${DHCP_CLIENT_ID} ${IMAGE_PATH}
313 336 status=$?
314 337 if [ $status -ne 0 ]; then
315 338 echo "${myname}: Unable to setup SPARC client"
316 339 exit 1
317 340 fi
318 341 dhcptype="sparc"
319 342 fi
320 343
321 344
322 345 # Try to update the DHCP server automatically. If not possible,
323 346 # then tell the user how to define the DHCP macro.
324 347 #
325 348 ${DIRNAME}/setup-dhcp client ${dhcptype} ${SERVER_IP} ${DHCP_CLIENT_ID} \
326 349 ${DHCP_BOOT_FILE}
327 350
328 351 status=$?
329 352
330 353 # Print nothing if setup-dhcp returns non-zero. setup-dhcp takes care of
331 354 # providing instructions for the user in that case.
332 355 #
333 356 if [ $status -eq 0 ]; then
334 357 echo "Enabled network boot by adding a macro named ${DHCP_CLIENT_ID}"
335 358 echo "to DHCP server with:"
336 359 echo " Boot server IP (BootSrvA) : ${SERVER_IP}"
337 360 echo " Boot file (BootFile) : ${DHCP_BOOT_FILE}"
338 361 fi
339 362
340 363 exit 0
|
↓ open down ↓ |
69 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX