lx_install.ksh revision edfa49ff6d1bd39465e21e3b28aee863e91c5e3f
#
# 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 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
export PATH
umask 022
# Setup i18n output
TEXTDOMAIN="SUNW_OST_OSCMD"
export TEXTDOMAIN
# Log passed arguments to file descriptor 2
log()
{
}
#
# Send the provided printf()-style arguments to the screen and to the
# logfile.
#
{
typeset fmt="$1"
shift
}
# Print and log provided text if the shell variable "verbose_mode" is set
verbose()
{
[[ -n $verbose_mode ]] && echo "$@"
}
cmd_full=\
root_full=$(gettext "Zonepath root %s exists and contains data; remove or move aside prior to install.")
# Check if commands passed in exist and are executable.
{
if [[ ! -f $cmd ]]; then
fi
if [[ ! -x $cmd ]]; then
fi
done
}
# Post process as tarball-installed zone for use by BrandZ.
{
typeset rootdir="$1"
return 1
fi
}
# Clean up on interrupt
{
exit $int_code
}
#
# Output the usage message.
#
# This is done this way due to limitations in the way gettext strings are
# extracted from shell scripts and processed. Use of this somewhat awkward
# syntax allows us to produce longer lines of text than otherwise would be
# possible without wrapping lines across more than one line of code.
#
usage()
{
echo
echo
echo
echo
echo " + core"
echo " + server"
echo " + desktop"
echo " + development"
echo " + all"
echo
echo
echo "========"
fmt -80
echo
echo " # zoneadm -z myzone install"
echo
fmt -80
echo
echo
echo
echo
echo
echo " # zoneadm -z myzone install -d /export/centos_3.8/isos all"
echo
echo
echo " # zoneadm -z myzone install -v -d /tmp/linux_full.tar.gz"
echo
echo
fmt -80
echo
echo " # zoneadm -z myzone install -d /tmp/linux_full.tar.gz -s"
echo
exit $int_code
}
#
# The main body of the script starts here.
#
# This script should never be called directly by a user but rather should
# only be called by zoneadm to install a BrandZ Linux zone.
#
#
#
# ZONE_SUBPROC_OK
# ===============
# Installation was successful
#
# ZONE_SUBPROC_USAGE
# ==================
# Improper arguments were passed, so print a usage message before exiting
#
# ZONE_SUBPROC_NOTCOMPLETE
# ========================
# Installation did not complete, but another installation attempt can be
# made without an uninstall
#
# ZONE_SUBPROC_FATAL
# ==================
# Installation failed and an uninstall will be required before another
# install can be attempted
#
#
# An unspecified exit or interrupt should exit with ZONE_SUBPROC_NOTCOMPLETE,
# meaning a user will not need to do an uninstall before attempting another
# install.
#
trap trap_cleanup INT
# If we weren't passed at least two arguments, exit now.
#
# This script is always started with a full path so we can extract the
# brand directory name here.
#
zonename="$1"
zoneroot="$2"
install_root="$zoneroot/root"
shift; shift # remove zonename and zoneroot from arguments array
unset gtaropts
unset install_opts
unset install_src
unset msg
unset silent_mode
unset verbose_mode
while getopts "d:hsvX" opt
do
h) usage;;
s) silent_mode=1;;
v) verbose_mode=1;;
d) install_src="$OPTARG" ;;
X) install_opts="$install_opts -x" ;;
*) usage;;
esac
done
shift OPTIND-1
# Providing more than one passed argument generates a usage message
if [[ $# -gt 1 ]]; then
screenlog " \"%s\"" "$@"
screenlog ""
fi
# Validate any free-form arguments
"$1" != "development" && "$1" != "all" ]]; then
screenlog ""
fi
# The install can't be both verbose AND silent...
if [[ -n $silent_mode && -n $verbose_mode ]]; then
screenlog "$both_modes" "zoneadm install"
screenlog ""
fi
#
# Validate that we're running on a i686-compatible CPU; abort the zone
# installation now if we're not.
#
#
# All x86 processors in CPUID families 6 or 15 should be i686-compatible,
# assuming third party processor vendors follow AMD and Intel's lead.
#
if [[ "$procinfo" != *" x86 "* ]] ||
screenlog "$unsupported_cpu" "i686"
exit $int_code
fi
if [[ -n $install_src ]]; then
#
# Validate $install_src.
#
# If install_src is a directory, assume it contains ISO images to
# install from, otherwise treat the argument as if it points to a tar
# ball file.
#
exit $int_code
fi
if [[ ! -a "$install_src" ]]; then
exit $int_code
fi
if [[ ! -r "$install_src" ]]; then
exit $int_code
fi
#
# If install_src is a block device, a directory, a possible device
# created via lofiadm(1M), or the directory used by a standard volume
# management daemon, pass it on to the secondary install script.
#
# Otherwise, validate the passed filename to prepare for a tar ball
# install.
#
if [[ ! -b "$install_src" && ! -d "$install_src" &&
"$install_src" != /media/* ]]; then
if [[ ! -f "$install_src" ]]; then
exit $int_code
fi
if [[ "$filetype" = "gzip" ]]; then
verbose "\"$install_src\": \"gzip\" archive"
gtaropts="-xz"
elif [[ "$filetype" = "bzip2" ]]; then
verbose "\"$install_src\": \"bzip2\" archive"
gtaropts="-xj"
elif [[ "$filetype" = "compressed" ]]; then
verbose "\"$install_src\": Lempel-Ziv" \
"compressed (\".Z\") archive."
gtaropts="-xZ"
elif [[ "$filetype" = "USTAR" ]]; then
verbose "\"$install_src\":" \
"uncompressed (\"tar\") archive."
gtaropts="-x"
else
exit $int_code
fi
fi
fi
#
# Start silent operation and pass the flag to prepare pass the flag to
# the ISO installer, if needed.
#
if [[ -n $silent_mode ]]
then
fi
#
# If verbose mode was specified, pass the verbose flag to lx_distro_install
# for ISO or disc installations and to gtar for tarball-based installs.
#
if [[ -n $verbose_mode ]]
then
fi
if [[ ! -d "$install_root" ]]
then
exit $int_code
fi
fi
#
# Check for a non-empty root.
#
cnt=`ls $install_root | wc -l`
exit $int_code
fi
if [[ ! -d "$logdir" ]]
then
exit $int_code
fi
fi
if ! > $logfile; then
exit $int_code
fi
# Redirect stderr to the log file to automatically log any error messages
exec 2>>"$logfile"
#
# From here on out, an unspecified exit or interrupt should exit with
# ZONE_SUBPROC_FATAL, meaning a user will need to do an uninstall before
# attempting another install, as we've modified the directories we were going
# to install to in some way.
#
if [[ -n $gtaropts ]]; then
echo
echo
log "Error: extraction from tar archive failed."
else
if ! [[ -d "${install_root}/bin" &&
-d "${install_root}/sbin" ]]; then
log "Error: improper or incomplete tar archive."
else
#
# Emit the same code from here whether we're
# interrupted or exiting normally.
#
int_code=$?
fi
fi
else
fi
else
#
# Emit the same code from here whether we're interrupted or exiting
# normally.
#
int_code=$?
fi
screenlog ""
screenlog ""
#
# Only make a reference to the log file if one will exist after
# zoneadm exits.
#
exit $int_code
fi
#
# After the install completes, we've likely moved a new copy of the logfile into
# place atop the logfile we WERE writing to, so if we don't reopen the logfile
# here the shell will continue writing to the old logfile's inode, meaning we
# would lose all log information from this point on.
#
exec 2>>"$logfile"
screenlog ""
screenlog ""
echo " \"$logfile\""
echo
exit $ZONE_SUBPROC_OK