pkg2du.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.
#
#
# pkg2du - convert driver packages to Driver Update (DU) format
#
readonly PROG=$0
# Must-have utilities
# for gettext
export TEXTDOMAIN
function usage
{
gettext "Usage:\n${PROG##*/} -r <release> [-f] [-v] [-d <dir>] [-o <iso>] [-l <label>]\n <pkg> [<pkg> ...]\n"
gettext "Options:\n -d <dir>\n Directory where the Driver Update directory should be created.\n"
gettext " -o <iso>\n Create a Solaris ISO image of the Driver Update directory.\n"
gettext " -f\n If <dir>/DU or <iso> exists, remove it without asking first.\n"
gettext " -r <release>\n Solaris release number to use. It takes the form of 5.10.\n This option must be specified.\n"
gettext " -v\n Verbose. Multiple -v options increase verbosity.\n"
echo;
}
function check_prereqs
{
typeset f
# We must have these utilities.
do
if [[ ! -x "$f" ]]
then
gettext "Cannot find required utilty $f"
exit 1
fi
done
}
function cleanup
{
}
function is_overwrite
{
typeset arg=$1
typeset -l ans
while true
do
read ans
y*|Y*) return 0 ;; # go ahead overwrite
n*|N*) return 1 ;; # don't overwrite
esac
done
echo;
}
function collect_objs # <pkg> ...
{
for obj
do
then
PACKAGES[ ${#PACKAGES[*]} ]=$obj
else
fi
done
return 0
}
function mkdu
{
typeset distdir tmpdudir pkgs obj statusfile
# Create DU directory first.
# Unfortunately pkgtrans insists that all packages must be in
# <device1> (see pkgtrans(1)). The packages can't have any path
# components. So we'll create a temporary directory first and then
# symlinks to the specified packages. Then run pkgtrans with
# the temporary directory as <device1>.
do
# Get rid of trailing /'s, if any.
# Make sure it's a full pathname.
# Remember just the file component.
pkgs[ ${#pkgs[*]} ]=${obj##*/}
done
# Package up packages as compressed data stream.
{
echo $? > $statusfile
$TOUCH $statusfile # make sure file is created
# Create admin file for pkgadd
mail=
# Create install.sh
# install.sh -R <basedir> - install packages to basedir
basedir=/
do
esac
done
status=$?
exit $status
$CHMOD a+rx "$distdir/Tools/install.sh"
}
function mkiso
{
typeset vflag
# Skip if no ISO image was specified.
# Determine mkisofs' verbose flag depending on $VERBOSE_LEVEL.
case $VERBOSE_LEVEL in
;;
1) vflag= # mkisofs' default verboseness
;;
*) vflag=
while ((i > 0))
do
(( i -= 1 ))
done
;;
esac
# trick to filter out mkisofs's warning message about being
# non-conforming to ISO-9660.
-N -l -d -D -r \
-R -J \
$vflag \
}
#
# Main
#
ISO=
while getopts ':d:fo:l:r:v' opt
do
;;
;;
gettext "ISO images will not be created on /tmp.\n"
gettext "Please choose a different output location.\n"
exit 3
fi
;;
;;
;;
;;
exit 1
;;
exit 2
;;
esac
done
shift 'OPTIND - 1'
# Release number must be specified.
if [[ -z "$RELEASE" ]]
then
gettext "Solaris release number must be specified (-r option).\n"
exit 1
fi
# Verify release number. Allow major.minor or major.minor.micro format.
then
exit 1
fi
# Either or both of -d or -o option must be specified.
then
gettext "Either -d or -o option (or both) must be specified.\n"
exit 1
fi
# There must be at least one package.
if (( $# == 0 ))
then
gettext "No package was specified.\n"
exit 1
fi
# Check and collect packages
unset PACKAGES
# Default label for ISO image
check_prereqs # must be called after $ISO is possibly set
# If an ISO image was specified, check its parent directory and get its
# full pathname.
unset ISODIR
if [[ -n "$ISO" ]]
then
if [[ "$ISO" = */* ]]
then
if (( $? ))
then
gettext "Can't access parent directory of ISO image\n"
exit 1
fi
else
ISODIR=$(pwd -P)
fi
fi
# If user specified a media root directory, verify it exists, else use
# a temporary directory.
if [[ -n "$ROOTDIR" ]]
then
if [ $? != 0 ]; then
exit 1
elif [[ ! -w "$ROOTDIR" ]] then
exit 1
fi
# If an ISO image path is also specified, make sure it's not under
# $ROOTDIR since we're going to take the ISO image of $ROOTDIR.
if [[ -n "$ISODIR" ]]
then
then
exit 1
fi
fi
else
fi
# If DU directory already exists, ask user permission to remove it unless -f
# option was specified.
if [[ -d "$ROOTDIR/DU" ]]
then
fi
# If ISO image already exists, ask user permission to remove it unless -f
# option was specified.
if [[ -f "$ISO" ]]
then
fi
# Create DU directory and the ISO image (if requested).
if (( $? ))
then
exit 1
fi
exit 0