6 # The contents of this file are subject to the terms of the
7 # Common Development and Distribution License (the "License").
8 # You may not use this file except in compliance with the License.
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # pkg2du - convert driver packages to Driver Update (DU) format
34 readonly TMP_DIR
=${TMPDIR:-/tmp}/${PROG##*/}.$$
37 readonly CPIO
=/usr
/bin
/cpio
38 readonly GZIP
=/usr
/bin
/gzip
39 readonly MKISOFS
=/usr
/bin
/mkisofs
40 readonly PATCHADD
=/usr
/sbin
/patchadd
41 readonly PKGTRANS
=/usr
/bin
/pkgtrans
42 readonly ROOT_ARCHIVE
=/usr
/sbin
/root_archive
43 readonly LOFIADM
=/usr
/sbin
/lofiadm
44 readonly MKDIR
=/usr
/bin
/mkdir
45 readonly RM
=/usr
/bin
/rm
46 readonly CP
=/usr
/bin
/cp
47 readonly HEAD
=/usr
/bin
/head
48 readonly SORT
=/usr
/bin
/sort
49 readonly MKBOOTMEDIA
=/usr
/bin
/mkbootmedia
50 readonly PKG2DU
=/usr
/bin
/pkg2du
51 readonly TOUCH
=/usr
/bin
/touch
52 readonly NAWK
=/usr
/bin
/nawk
53 readonly CHMOD
=/usr
/bin
/chmod
54 readonly GREP
=/usr
/bin
/grep
55 readonly LS
=/usr
/bin
/ls
56 readonly LN
=/usr
/bin
/ln
57 readonly SED
=/usr
/bin
/sed
58 readonly CAT
=/usr
/bin
/cat
59 readonly FIND
=/usr
/bin
/find
60 readonly UNAME
=/usr
/bin
/uname
61 readonly MACH
=`$UNAME -p`
64 TEXTDOMAIN
=SUNW_OST_OSCMD
70 gettext "Usage:\n${PROG##*/} -r <release> [-f] [-v] [-d <dir>] [-o <iso>] [-l <label>]\n <pkg> [<pkg> ...]\n"
71 gettext "Options:\n -d <dir>\n Directory where the Driver Update directory should be created.\n"
72 gettext " -o <iso>\n Create a Solaris ISO image of the Driver Update directory.\n"
73 gettext " -f\n If <dir>/DU or <iso> exists, remove it without asking first.\n"
74 gettext " -l <label>\n Label/volume name of the ISO image (if -o option is specified).\n"
75 gettext " -r <release>\n Solaris release number to use. It takes the form of 5.10.\n This option must be specified.\n"
76 gettext " -v\n Verbose. Multiple -v options increase verbosity.\n"
81 function check_prereqs
85 # We must have these utilities.
86 for f
in $GZIP ${ISO:+$MKISOFS} $PKGTRANS
90 gettext "Cannot find required utilty $f"
103 function is_overwrite
108 [[ $FORCE == yes ]] && return 0
112 gettext "$arg already exists. Overwrite it? (y/n) "
115 y
*|Y
*) return 0 ;; # go ahead overwrite
116 n
*|N
*) return 1 ;; # don't overwrite
123 function collect_objs
# <pkg> ...
129 if [[ -f "$obj"/pkginfo
]]
131 PACKAGES
[ ${#PACKAGES[*]} ]=$obj
133 gettext "$obj is not in package format\n"
137 (( fail
)) && return 1
144 typeset distdir tmpdudir pkgs obj statusfile
146 trap '/bin/rm -rf $statusfile $tmpdudir' EXIT
148 # Create DU directory first.
149 distdir
=$ROOTDIR/DU
/sol_
$VERSION/$MACH
150 $MKDIR -p "$distdir/Tools" "$distdir/Product"
152 # to the other UltraSPARC architecture
153 if [[ "$MACH" != "i386" ]]
155 cd $ROOTDIR/DU
/sol_
$VERSION
159 cd $ROOTDIR/DU
/sol_
$VERSION
163 # Unfortunately pkgtrans insists that all packages must be in
164 # <device1> (see pkgtrans(1)). The packages can't have any path
165 # components. So we'll create a temporary directory first and then
166 # symlinks to the specified packages. Then run pkgtrans with
167 # the temporary directory as <device1>.
168 tmpdudir
=$TMP_DIR/mkdu
169 $MKDIR -p "$tmpdudir"
171 for obj
in "${PACKAGES[@]}"
173 # Get rid of trailing /'s, if any.
174 [[ "$obj" == */ ]] && obj
=${obj%%+(/)}
176 # Make sure it's a full pathname.
177 [[ "$obj" != /* ]] && obj
=$ORIGPWD/$obj
179 $LN -s "$obj" "$tmpdudir" ||
exit 1
181 # Remember just the file component.
182 pkgs
[ ${#pkgs[*]} ]=${obj##*/}
185 # Package up packages as compressed data stream.
186 statusfile
=$TMP_DIR/.pkgtrans.status
188 $PKGTRANS -s "$tmpdudir" /dev
/stdout
"${pkgs[@]}"
189 echo $?
> $statusfile
190 $TOUCH $statusfile # make sure file is created
191 } |
$GZIP -9 > "$distdir/Product/pkgs.gz"
193 [[ -s $statusfile && $
(<$statusfile) != 0 ]] && return 1
195 # Create admin file for pkgadd
196 $CAT > "$distdir/Tools/admin" <<"EOF"
210 $CAT > "$distdir/Tools/install.sh" <<"EOF"
212 # install.sh -R <basedir> - install packages to basedir
214 toolsdir
=`dirname $0`
215 tmpfile
=/tmp
/`basename $0`.$$
216 while getopts "R:" arg
222 /usr
/bin
/gzip -c -d "$toolsdir/../Product/pkgs.gz" > $tmpfile &&
223 /usr
/sbin
/pkgadd
-R "$basedir" -d "$tmpfile" -a "$toolsdir/admin" all
225 /bin
/rm -f "$tmpfile"
228 $CHMOD a
+rx
"$distdir/Tools/install.sh"
236 # Skip if no ISO image was specified.
237 [[ -z "$ISO" ]] && return 0
239 # Determine mkisofs' verbose flag depending on $VERBOSE_LEVEL.
240 case $VERBOSE_LEVEL in
243 1) vflag
= # mkisofs' default verboseness
255 (( VERBOSE_LEVEL
)) && gettext "Creating ISO image ..."
257 # Note: the "-log-file >(cat -u >&2)" and "2>/dev/null" below is a
258 # trick to filter out mkisofs's warning message about being
259 # non-conforming to ISO-9660.
260 # We do some funky architecture-specific stuff here so that we can
261 # actually create a bootable media image for UltraSPARC systems
263 ISOARGS_sparc
="-B ... -joliet-long -R -U"
264 ISOARGS_i386
="-d -N -r -relaxed-filenames"
265 if [[ "$MACH" = "i386" ]]
267 ISOARGS
=$ISOARGS_i386
269 ISOARGS
=$ISOARGS_sparc
273 -allow-leading-dots \
275 -ldots -full-iso9660-filenames \
279 -log-file >($CAT -u >&2) \
280 "$ROOTDIR" 2>/dev
/null
296 while getopts ':d:fo:l:r:v' opt
304 if [ ! -z `echo $ISO | $GREP "^/tmp"` ]; then
305 gettext "ISO images will not be created on /tmp.\n"
306 gettext "Please choose a different output location.\n"
314 v
) (( VERBOSE_LEVEL
+= 1 ))
316 :) gettext "Option -$OPTARG missing argument."
320 *) gettext "Option -$OPTARG invalid.\n"
328 # Release number must be specified.
329 if [[ -z "$RELEASE" ]]
331 gettext "Solaris release number must be specified (-r option).\n"
336 # Verify release number. Allow major.minor or major.minor.micro format.
337 if [[ $RELEASE != +([0-9]).
+([0-9])?
(.
+([0-9])) ]]
339 gettext "Invalid release number: $RELEASE\n"
342 VERSION
=$
(echo $RELEASE |
$SED 's/5\./2/')
344 # Either or both of -d or -o option must be specified.
345 if [[ -z "$ROOTDIR" && -z "$ISO" ]]
347 gettext "Either -d or -o option (or both) must be specified.\n"
352 # There must be at least one package.
355 gettext "No package was specified.\n"
360 # Check and collect packages
362 collect_objs
"$@" ||
exit 1
364 # Default label for ISO image
365 LABEL
=${LABEL:-DU sol_$VERSION}
367 check_prereqs
# must be called after $ISO is possibly set
369 # If an ISO image was specified, check its parent directory and get its
374 if [[ "$ISO" = */* ]]
376 ISODIR
=$
(cd "${ISO%/*}" 2>/dev
/null
&& pwd -P)
379 gettext "Can't access parent directory of ISO image\n"
387 # If user specified a media root directory, verify it exists, else use
388 # a temporary directory.
389 if [[ -n "$ROOTDIR" ]]
391 $MKDIR -p "$ROOTDIR";
393 gettext "$ROOTDIR is not a directory.\n"
395 elif [[ ! -w "$ROOTDIR" ]] then
396 gettext "Directory $ROOTDIR is not writable.\n"
399 # If an ISO image path is also specified, make sure it's not under
400 # $ROOTDIR since we're going to take the ISO image of $ROOTDIR.
401 if [[ -n "$ISODIR" ]]
403 realroot
=$
(cd "$ROOTDIR" 2>/dev
/null
&& pwd -P)
404 if [[ "$ISODIR" = "$realroot"?
(/*) ]]
406 gettext "ISO image must not be under Driver Update's parent directory ($realroot)\n"
411 ROOTDIR
=$TMP_DIR/root
414 # If DU directory already exists, ask user permission to remove it unless -f
415 # option was specified.
416 if [[ -d "$ROOTDIR/DU" ]]
418 is_overwrite
"$ROOTDIR/DU" ||
exit 0
419 $RM -rf "$ROOTDIR/DU"
422 # If ISO image already exists, ask user permission to remove it unless -f
423 # option was specified.
426 is_overwrite
"$ISO" ||
exit 0
430 # Create DU directory and the ISO image (if requested).
434 $RM -rf "$ROOTDIR/DU"
435 [[ -n "$ISO" ]] && $RM -f "$ISO"