updatemedia.ksh revision 4f10d6de4eaf8568195df6a921d12810040e03d9
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# updatemedia - modify Solaris media with patches and packages
#
readonly PROG=$0
# Must-have utilities
# for gettext
export TEXTDOMAIN
function usage
{
gettext "Usage:\n${PROG##*/} -d <media-root> [-v] [-l <label>] [-o <iso>]\n <pkg_or_patch> [<pkg_or_patch> ...]\n"
gettext "Options:\n -d <media-root>\n Top-level directory of on-disk image of Solaris installation media.\n This is option must be specified.\n"
gettext " -o <iso>\n Create a Solaris ISO image of <media-root>.\n"
gettext " -v\n Verbose. Multiple -v options increase verbosity.\n"
}
function check_prereqs
{
typeset f
# We must have these utilities.
do
if [[ ! -x "$f" ]]
then
gettext "Cannot find required utility $f\n"
exit 1
fi
done
# root_archive unpack_media calls lofiadm -a, which requires
then
gettext "You do not have enough privileges to run lofiadm -a).\nSee lofiadm(1m) for more information.\n"
exit 1
fi
}
function cleanup
{
}
function unpack_media
{
# Create temp directory to unpack the miniroot.
$MKDIR -p "$UNPACKED_ROOT"
# We need to use the unpackmedia option to correctly apply patches
gettext "Unpacking media ..."
if [ $? != 0 -a ! -d $MEDIA_ROOT/Solaris_10 ]; then
# we _do_ care, because we're not patching a Solaris 10
# update media instance
gettext "\nThere was an error unpacking the media from $MEDIA_ROOT\n"
exit 1
fi
echo;
}
function repack_media
{
gettext "Repacking media ..."
# We need to ensure that we're using the appropriate version
# The onnv version of root_archive differs from the S10 version,
# and this will cause problems on re-packing. So we sneakily
# use the version that we've just unpacked
if [ -d $MEDIA_ROOT/Solaris_10 ]; then
fi
if [ $? != 0 -a ! -d $MEDIA_ROOT/Solaris_10 ]; then
# we _do_ care, because we're not patching a Solaris 10
# update media instance
gettext "\nThere was an error unpacking the media from $MEDIA_ROOT\n"
exit 1
fi
echo;
}
function mkiso
{
typeset vflag
# Skip if no ISO image was specified.
gettext "Creating ISO image ..."
$MKBOOTMEDIA $VERBOSE_OPTS -l "$ISOLABEL" "$MEDIA_ROOT" "$ISO"
echo;
}
function collect_objs # <pkg_or_patch> ...
{
for obj
do
then
PATCHES[ ${#PATCHES[*]} ]=$obj
then
PACKAGES[ ${#PACKAGES[*]} ]=$obj
else
fi
done
return 0
}
function add_pkgs
{
typeset dudir icmd statusfile
(( ${#PACKAGES[*]} == 0 )) && return
# Add a Driver Update directory on the media
echo;
gettext "Adding package(s) to media root."
"${PACKAGES[@]}" || return
# Using the Driver Update above install the packages onto the miniroot.
echo;
gettext "Installing package(s) onto miniroot."
then
# This shouldn't happen, but just in case.
return 1
fi
$RM -f "$statusfile"
{
if (( i=$? ))
then
echo $i > "$statusfile"
fi
# Print certain lines from $icmd, save all in logfile.
/^Installing/ {print}
/^Installation.*successful/ {print}
{print >> logfile}
' || return
return 0
}
function add_patches
{
(( ${#PATCHES[*]} == 0 )) && return
# Patch the miniroot
echo;
gettext "Installing patch(es) onto miniroot."
$RM -f "$statusfile"
{
$PATCHADD -udn -C "$UNPACKED_ROOT" "${PATCHES[@]}"
if (( i=$? ))
then
echo $i > "$statusfile"
fi
# Print certain lines from patchadd, save all in logfile.
/^Patch.*successful/ {print}
{print >> logfile}
' || return
# Remove patch log files to save space when miniroot is repacked.
do
# Get rid of trailing /'s, if any.
# Make sure it's full pathname.
# Remember just the file component.
patches[ ${#patches[*]} ]=${obj##*/}
done
# Package up patches as compressed cpio archive.
echo;
gettext "Adding patch(es) to media root.\n"
$RM -f "$statusfile"
(
cd "$tmpdir"
# fd 9 is used later on for filtering out cpio's
# reporting total blocks to stderr but yet still
# print other error messages.
exec 9>&1
do
if (( i=$? ))
then
echo $i > "$statusfile"
return $i
fi
# Create install.sh
# install.sh -R <basedir> - install patches to basedir
basedir=/
do
esac
done
cd "$patchdir"
$CHMOD a+rx "$distdir/Tools/install.sh"
}
#
# Main
#
ISO=
do
;;
gettext "ISO images will not be created on /tmp.\nPlease choose a different output location.\n"
exit 3
fi
;;
;;
;;
exit 1
;;
exit 2
;;
esac
done
shift 'OPTIND - 1'
collect_objs "$@"
# If there are no packages or patches, then print info and we're done.
if (( ${#PACKAGES[*]} == 0 && ${#PATCHES[*]} == 0 ))
then
gettext "No valid package or patch was specified.\nPackages and patches must be unpacked.\n"
exit 1
fi
# -d option must be specified
then
gettext "No media root (-d option) was specified.\n"
exit 1
fi
check_prereqs # must be called after $ISO is possibly set
# Verify it's a Solaris install media.
SOLARIS_DIR=$($LS -d $MEDIA_ROOT/Solaris* 2>/dev/null)
then
gettext "$MEDIA_ROOT is not valid Solaris install media.\n"
exit 1
fi
# Extract the Solaris release number from the Solaris_* directory and the
# corresponding version number. As defined by the ITU spec, a Solaris release
RELEASE=5.${SOLARIS_DIR##*Solaris_}
# If user didn't specify ISO label, use the Solaris_* dir as label.
${ISOLABEL:=${SOLARIS_DIR##*/}}
# Verify miniroot
then
gettext "No boot/x86.miniroot under media root.\n"
exit 1
fi
# Where to unpack the miniroot.
# Create the ITU directory on the media, if necessary
# The ITU directory might contain multiple driver updates already, each in a
# separate numbered subdirectory. So look for the subdirectory with the
# highest number and we'll add the packages and patches on the next one.
then
COUNTDIR=0
else
fi
unpack_media || exit
then
echo;
gettext "A package or patch installation has failed.\nMessages from pkgadd and patchadd have been saved in $LOGFILE\n"
exit $status
else
fi
print
repack_media || exit