#!/bin/sh
#
#
# ident "@(#)wcswap	1.18 10/04/01 SMI"
#
# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
#

# App Server Product Name
AS_PROD_NAME="Sun Java Application Server"

# Apache Tomcat Product Name
TCAT_PROD_NAME="Apache Tomcat Web Server"

# Webconsole product name
WEB_CONSOLE_PROD_NAME="Oracle Java(TM) Web Console"

# option flags, all options have arguments
aflag=0  # admin port
dflag=0  # container directory
iflag=0  # instance name
jflag=0  # jmx port
oflag=0  # java options
pflag=0  # unsecure http port
rflag=0  # restart the server
sflag=0  # secure http port
tflag=0  # container type
uflag=0  # container process owner uid
xflag=0  # debug flag

# Supported container types
APP_SERVER_CONTAINER_TYPE=sjsas
TCAT_CONTAINER_TYPE=tomcat

# config.properties property names that will be updated by wcswap
CFG_CONSOLE_INSTANCE_PROP=console_instance
CFG_CONSOLE_TYPE_PROP=console_type
CFG_CONSOLE_USER_PROP=console_user
CFG_CONSOLE_HTTPS_PROP=console_httpsport
CFG_CONSOLE_HTTP_PROP=console_httpport
CFG_CONTAINER_HOME_PROP=container_home
CFG_CONTAINER_SHARED_PROP=container_shared_lib
CFG_CONTAINER_COMMON_PROP=container_common_lib
CFG_CONTAINER_CLASSPATH_PROP=container_classpath
CFG_CONTAINER_ADMIN_PROP=container_adminport
CFG_CONTAINER_JMX_PROP=container_jmxport
CFG_CONTAINER_JAVA_OPTS_PROP=java_options


# java.options prop name
SERVICE_JAVA_OPTS_PROP=java.options

# the config.properties filename
CONFIG_PROPS=config.properties
SERVICE_PROPS=service.properties

# App server common directories
AS_LIB_DIR=lib


# TCAT server common directories
TCAT_COMMON_LIB_DIR=common/lib
TCAT_SHARED_LIB_DIR=shared/lib

# App server password constants
ADMIN_PASSWORD_PROP="adminpassword"
KEY_PASSWORD_PROP="keypassword"
TRUST_PASSWORD_PROP="trustpassword";
TEMP_PASS_FILE=/tmp/pass.$$
ROOT_PERMS=600

# SMF constants
SERVICE_NAME=system/webconsole

# The default UID
DEFAULT_UID=noaccess

# Under App Server 8.2 EE "asadmin version" returns this string 
# Version = Sun Java System Application Server Enterprise Edition 8.2, and others.
# To determine the verison,
# We will grep for "Version" at the beginning of a line and "Enterprise Edition 8.2"
# at the end.
AS_VERSION_KEY="Version"
AS_REQ_VERSION="Enterprise Edition 8.2"
AS_ADMIN_CMD="bin/asadmin"
AS_ADMIN_VERSION_CMD="version"

##############
# exit codes 
SUCCESS=0
EXIT_NO_TARGET_TYPE=1
EXIT_NO_AS_DIR=2
EXIT_BAD_AS=3
EXIT_BAD_TCAT=4
EXIT_BAD_0S=5
EXIT_NO_WCREMOVE=6
EXIT_NO_SMCWEBSERVER=7
EXIT_NO_REP_PROP=8
EXIT_NO_CFG_PROPS=9
EXIT_NO_EXT_TCAT=10
EXIT_NO_TEMPLATE_FILE=11
EXIT_TEMPLATE_NO_WRITE=12
EXIT_TEMPLATE_NO_OVERWRITE=13
EXIT_NO_INPUT_FILE=14
EXIT_INPUT_NOT_FILE=15
EXIT_INPUT_NO_READ=16
EXIT_NO_SERV_PROPS=17
EXIT_BAD_CONTAINER_TYPE=18
EXIT_BAD_UID=19
EXIT_BAD_PORT=20
EXIT_ASADMIN_NO_EXEC=21
EXIT_AS_BAD_VERSION=22

################################################################################
#
# Usage
#
# Prints usage of this script to the screen.
#
# $1 = Exit code
#
################################################################################
Usage() {

    cat - << EOF

wcswap -t tomcat [-s secure_port] [-p http_port]
        [-a admin_port] [-j jmx_port] [-u username] [-o options] [-h] 

wcswap -t sjsas -d directory [-s secure_port] [-p http_port] [-u username] [-o options] [-h]


where

type         - The web container type; either "tomcat", "sjsas"
directory    - The path to the web server installation directory;
               required if the type is "sjsas"
secure_port  - HTTPS secure port number; default is 6789
http_port    - HTTP unsecure port number; default is 6788
admin_port   - Administration port number; default is 6787
jmx_port     - JMX (AMX interface) port number; default is 6786
username     - User identity under which web server process runs;
                default is "noaccess"
options      - One or more JVM options; quoted and separated by
               whitespace if more than one option 
-h	     - print usage message

EOF

    exit $1

} ## end Usage()


################################################################################
#
# setPrimordialPaths
#
# set up the tomcat os specific Primordial paths: console_home, console_base,
# console_conf, console_log, console_native
#
################################################################################
setPrimordialPaths() {

    # XXX
    # TBD - design in relocation
    #

    # check for supported OS
    OS=`uname -s`
    if [ ! -n "${OS}" ]; then
	echo "Unable to determine operating system."
	exit ${EXIT_BAD_OS}
    fi

    if [ "${OS}" != "SunOS" -a "${OS}" != "Linux" -a "${OS}" != "HP-UX" ]; then
	echo "Not supported on detected OS \"${OS}\"."
	exit ${EXIT_BAD_OS}
    fi

    # Solaris defaults
    if [ "${OS}" = "SunOS" ]; then
	console_home=/usr/share/webconsole
	console_base=/var/webconsole
	console_conf=/etc/webconsole
	console_log=/var/log/webconsole
	console_native=/usr/lib/webconsole
    fi

    # Linux defaults
    if [ "${OS}" = "Linux" -o "${OS}" = "HP-UX" ]; then
	console_home=/opt/sun/webconsole
	console_base=/var/opt/webconsole
	console_conf=/etc/opt/webconsole
	console_log=/var/log/webconsole
	console_native=/opt/sun/webconsole/native
	# default UID for linux is nobody
	DEFAULT_UID=nobody
    fi

    if [ "${OS}" = "SunOS" ]; then
	OS_RELEASE=`uname -r`
	if [ "${OS_RELEASE}" != "5.8" -a "${OS_RELEASE}" != "5.9" ]; then
	    SMF_PRESENT="true"
    fi
fi

} ## setPrimordialPaths

################################################################################
#
# set wcswap defaults
#
# set default property values
#
################################################################################
setDefaults() {

    # wcswap default properties (tomcat defaults)

    WCSWAP_INSTANCE=console
    WCSWAP_TYPE=${TCAT_CONTAINER_TYPE}
    WCSWAP_CONTAINER_DIR=${console_home}/private/container
    WCSWAP_SECURE_PORT=6789
    WCSWAP_HTTP_PORT=6788
    WCSWAP_ADMIN_PORT=6787
    WCSWAP_JMX_PORT=6786
    WCSWAP_CONTAINER_PROCESS_UID=${DEFAULT_UID}
    WCSWAP_JAVA_OPTIONS="-server -Xmx128m -XX:+UseParallelGC -XX:ParallelGCThreads=4"
    FMRI="${SERVICE_NAME}:${WCSWAP_INSTANCE}"

} ## setDefaults

################################################################################
#
# validateUID
#
# ensure the uid given exists
#
# $1 user id
#
################################################################################
validateUID() {
    # place in a meaningful name
    userid=$1
    
    id ${userid} > /dev/null 2>&1

    if [ $? -ne 0 ];then
	echo " "
	echo "The user id ${userid} does not exist"
	echo " "
	Usage ${EXIT_BAD_UID}
    fi
}



################################################################################
#
# validatePort
#
# port given must contain exactly 4 numeric characters
#
# $1 port
#
################################################################################
validatePort() {
    # place in a meaningful name
    portNumber=$1


    echo $portNumber | egrep "^[0-9]+$" > /dev/null 2>&1

    if [ $? -ne 0 ];then
	echo " "
	echo "The port ${portNumber} is invalid."
	echo "A port consists of exclusively numeric characters."
	echo "Example: 6789"
	echo " "
	Usage ${EXIT_BAD_PORT}
    fi
}


################################################################################
#
# validateAS
#
# Cursory checks in an attempt to validate an App Server install
#
################################################################################
validateAS() {

    # was the dflag specified, did we get an argument?
    if [ ${dflag} -eq 0 -o "${WCSWAP_CONTAINER_DIR}" = "" ]; then
	echo "${AS_PROD_NAME} install directory must be defined."
	echo "Please provide ${AS_PROD_NAME} install location"
	echo "with the -d option."
	echo ""
	Usage ${EXIT_NO_AS_DIR}
    fi

    # is it a directory?
    if [ ! -d ${WCSWAP_CONTAINER_DIR} ]; then
	echo "The container location ${WCSWAP_CONTAINER_DIR} is not a"
	echo "valid ${AS_PROD_NAME} installation location."
	echo 
	Usage ${EXIT_BAD_AS}
    fi

    #
    # Check for AS 8.2 EE, the string returned is not a public
    # interface but it is th best we have.
    #
    AS_CMD=${WCSWAP_CONTAINER_DIR}/${AS_ADMIN_CMD}
    if [ -x ${AS_CMD} ]; then
	# run the version command and look for the required version strin
	# Under App Server 8.2 EE "asadmin version" returns this string 
	# Version = Sun Java System Application Server Enterprise Edition 8.2, and others.
	# To determine the verison,
	# We will grep for "Version" at the beginning of a line and "Enterprise Edition 8.2"
	# at the end.
        ${AS_CMD} ${AS_ADMIN_VERSION_CMD} | grep "^${AS_VERSION_KEY}" | grep "${AS_REQ_VERSION}" > /dev/null 2>&1
        if [ $? -ne 0 ]; then
	    echo ""
	    echo "${WCSWAP_CONTAINER_DIR} points to an unsupported version of ${AS_PROD_NAME}."
	    echo ""
	    echo "Run the wcswap command with the -d option pointing to"
	    echo "a ${AS_PROD_NAME} ${AS_REQ_VERSION} installation."
	    echo ""
	    exit ${EXIT_AS_BAD_VERSION}
        fi
    else
	# not executable, exit
	echo "The command ${AS_CMD} is not executable."
	echo ""
	echo "Add execute permissions to ${AS_CMD} and rerun wcswap."
	exit ${EXIT_ASADMIN_NO_EXEC}

    fi
    
    # if CFG_CONTAINER_CLASSPATH_VAL is empty call buildASProps
    if [ ! -n "${CFG_CONTAINER_CLASSPATH_VAL}" ]; then
	buildASProps
    fi

    # class path jars are separated by a :, for needs a space
    tempJars=`echo ${CFG_CONTAINER_CLASSPATH_VAL} | sed 's@:@ @g'`
    # make sure all jars are accounted for
    for jar in ${tempJars}; do
	# if we are missing a jar exit
	if [ ! -f ${jar} ]; then
	    echo "The ${AS_PROD_NAME} installation at ${WCSWAP_CONTAINER_DIR}"
	    echo "does not appear to be a valid installation."
	    echo "At least one library, ${jar}, is missing."
	    exit ${EXIT_BAD_AS}
	fi
    done



} ## validateAS

################################################################################
#
# validateTCAT
#
# Cursory checks in an attempt to validate a tomcat container
#
################################################################################
validateTCAT() {

    # is it a directory?
    if [ ! -d ${WCSWAP_CONTAINER_DIR} ]; then
	echo "The container location ${WCSWAP_CONTAINER_DIR} is not a"
	echo "valid ${TCAT_PROD_NAME} installation location."
	echo 
	Usage ${EXIT_BAD_TCAT}

    fi
} ## validateTCAT

################################################################################
#
# buildASProps
#
# Build App Server properties that are derived from the App Server install dir
#
################################################################################
buildASProps() {

    # command line provided or defaults
    CFG_CONSOLE_INSTANCE_VAL=${WCSWAP_INSTANCE}

    CFG_CONSOLE_TYPE_VAL=${WCSWAP_TYPE}
    CFG_CONSOLE_USER_VAL=${WCSWAP_CONTAINER_PROCESS_UID}
    CFG_CONSOLE_HTTPS_VAL=${WCSWAP_SECURE_PORT}
    CFG_CONSOLE_HTTP_VAL=${WCSWAP_HTTP_PORT}

    # container specific
    CFG_CONTAINER_HOME_VAL=${WCSWAP_CONTAINER_DIR}
    CFG_CONTAINER_SHARED_VAL=${WCSWAP_CONTAINER_DIR}/${AS_LIB_DIR}
    CFG_CONTAINER_COMMON_VAL=${WCSWAP_CONTAINER_DIR}/${AS_LIB_DIR}
    CFG_CONTAINER_CLASSPATH_VAL="${WCSWAP_CONTAINER_DIR}/${AS_LIB_DIR}/jmxremote_optional.jar:${WCSWAP_CONTAINER_DIR}/${AS_LIB_DIR}/appserv-rt.jar:${WCSWAP_CONTAINER_DIR}/${AS_LIB_DIR}/appserv-admin.jar:${WCSWAP_CONTAINER_DIR}/${AS_LIB_DIR}/j2ee.jar"
    CFG_CONTAINER_ADMIN_VAL=${WCSWAP_ADMIN_PORT}
    CFG_CONTAINER_JMX_VAL=${WCSWAP_JMX_PORT}
    # override default if -o specified
    if [ ${oflag} -eq 1 ]; then
	CFG_CONTAINER_JAVA_OPTS_VAL=${WCSWAP_JAVA_OPTIONS}
    else
	CFG_CONTAINER_JAVA_OPTS_VAL="-server -Xmx512m -XX:NewRatio=2 -XX:+UseParallelGC -XX:ParallelGCThreads=4"
    fi

} ## buildASProps

################################################################################
#
# buildTCATProps
#
# Build Tomcat specific properties
#
################################################################################
buildTCATProps() {

    # config.properties property values
    CFG_CONSOLE_INSTANCE_VAL=${WCSWAP_INSTANCE}
    CFG_CONSOLE_TYPE_VAL=${WCSWAP_TYPE}
    CFG_CONSOLE_USER_VAL=${WCSWAP_CONTAINER_PROCESS_UID}
    CFG_CONSOLE_HTTPS_VAL=${WCSWAP_SECURE_PORT}
    CFG_CONSOLE_HTTP_VAL=${WCSWAP_HTTP_PORT}

    # container specific
    CFG_CONTAINER_HOME_VAL=${WCSWAP_CONTAINER_DIR}
    CFG_CONTAINER_SHARED_VAL=${WCSWAP_CONTAINER_DIR}/${TCAT_SHARED_LIB_DIR}
    CFG_CONTAINER_COMMON_VAL=${WCSWAP_CONTAINER_DIR}/${TCAT_COMMON_LIB_DIR}
    CFG_CONTAINER_CLASSPATH_VAL=""
    CFG_CONTAINER_ADMIN_VAL=${WCSWAP_ADMIN_PORT}
    CFG_CONTAINER_JMX_VAL=${WCSWAP_JMX_PORT}
    CFG_CONTAINER_JAVA_OPTS_VAL=${WCSWAP_JAVA_OPTIONS}

} ## buildTCATProps

################################################################################
#
# swapContainer
#
# remove the old container domain, supporitng files, update config.properties
# 
#
################################################################################
swapContainer() {

    # build path to replace prop
    REP_PROP=${console_home}/private/bin/replaceProp

    # make sure it is there and executable
    if [ ! -x  ${REP_PROP} ]; then
	echo "${REP_PROP} does not exist or is not executable"
	exit ${EXIT_NO_REP_PROP}
    fi

    # build path to the config.properties files
    PROPS_PATH=${console_conf}/${CFG_CONSOLE_INSTANCE_VAL}/${CONFIG_PROPS}

    # build path to the service.properties files
    SERV_PATH=${console_conf}/${CFG_CONSOLE_INSTANCE_VAL}/${SERVICE_PROPS}

    # we never create config.properties, 
    if [ ! -f ${PROPS_PATH} ]; then
	echo "${PROPS_PATH} does not exist."
	exit ${EXIT_NO_CFG_PROPS}
    fi

    # if we can't write to config.properties error
    if [ ! -w ${PROPS_PATH} ]; then
	echo "${PROPS_PATH}  is not writeable."
	exit ${EXIT_NO_CFG_PROPS}
    fi

    # destroy the existing domain
    destroyDomain

    # Update required properties in config.properties
    ${REP_PROP} -p ${CFG_CONTAINER_HOME_PROP} \
	-v ${CFG_CONTAINER_HOME_VAL} -f ${PROPS_PATH}
    
    ${REP_PROP} -p ${CFG_CONTAINER_CLASSPATH_PROP} \
	-v "${CFG_CONTAINER_CLASSPATH_VAL}" -f ${PROPS_PATH}

    ${REP_PROP} -p ${CFG_CONTAINER_SHARED_PROP} \
	-v ${CFG_CONTAINER_SHARED_VAL} -f ${PROPS_PATH}

    ${REP_PROP} -p ${CFG_CONTAINER_COMMON_PROP} \
	-v ${CFG_CONTAINER_COMMON_VAL} -f ${PROPS_PATH}


    ${REP_PROP} -p ${CFG_CONTAINER_ADMIN_PROP} \
	    -v ${CFG_CONTAINER_ADMIN_VAL} -f ${PROPS_PATH}

    ${REP_PROP} -p ${CFG_CONTAINER_JMX_PROP} \
	-v ${CFG_CONTAINER_JMX_VAL} -f ${PROPS_PATH}

    ${REP_PROP} -p ${CFG_CONTAINER_JAVA_OPTS_PROP} \
	-v "${CFG_CONTAINER_JAVA_OPTS_VAL}"  -f ${PROPS_PATH}

    if [ ${tflag} -eq 1 ]; then
	${REP_PROP} -p ${CFG_CONSOLE_TYPE_PROP} \
	    -v ${CFG_CONSOLE_TYPE_VAL} -f ${PROPS_PATH}
    fi

    if [ ${uflag} -eq 1 ]; then
	${REP_PROP} -p ${CFG_CONSOLE_USER_PROP} \
	    -v ${CFG_CONSOLE_USER_VAL} -f ${PROPS_PATH}
    fi

    if [ ${sflag} -eq 1 ]; then
	${REP_PROP} -p ${CFG_CONSOLE_HTTPS_PROP} \
	    -v ${CFG_CONSOLE_HTTPS_VAL} -f ${PROPS_PATH}
    fi

    if [ ${pflag} -eq 1 ]; then
	${REP_PROP} -p ${CFG_CONSOLE_HTTP_PROP} \
	    -v ${CFG_CONSOLE_HTTP_VAL} -f ${PROPS_PATH}
    fi



    # if service.properties exists we
    # need to clear out the java options
    if [ -f ${SERV_PATH} ]; then
	if [ -w ${SERV_PATH} ]; then
	    # When swapping the container we clear out any user
	    # defined options in java.options
	    ${REP_PROP} -p ${SERVICE_JAVA_OPTS_PROP} \
		-v "" -f ${SERV_PATH}
	else 
	    # if we can't write to service.properties we have an error
	    echo "${SERV_PATH}  is not writeable."
	    exit ${EXIT_NO_SERV_PROPS}
	fi
    fi
    
} ## swapContainer

################################################################################
#
# destroy domain
# removes the existing console domain
#
################################################################################
destroyDomain() {

    WCREMOVE=${console_home}/private/bin/wcremove

    # destroy the domain, this also stops the console
    if [ -x  ${WCREMOVE} ]; then
        ${WCREMOVE} -i ${WCSWAP_INSTANCE}
    else
	echo "${WCREMOVE} does not exist or is not executable"
	exit ${EXIT_NO_WCREMOVE}
    fi

} ## destroyDomain

################################################################################
#
# stopConsole
# stop a running console
#
################################################################################
stopConsole() {

    SMCWEBSERVER=${console_home}/bin/smcwebserver

    # destroy the domain
    if [ -x  ${SMCWEBSERVER} ]; then
	# get status
        status=`${SMCWEBSERVER} status -p | awk -F= '{print $2}'`
	if [ "${status}" = "yes" ]; then
	    # stop the server
	    ${SMCWEBSERVER} stop
	fi
    else
	echo "${SMCWEBSERVER} does not exist or is not executable"
	exit ${EXIT_NO_SMCWEBSERVER}
    fi

} ## stopConsole

################################################################################
#
# startConsole
# start a stopped console
#
################################################################################
startConsole() {

    SMCWEBSERVER=${console_home}/bin/smcwebserver

    # start the console
    if [ -x  ${SMCWEBSERVER} ]; then
	# get status
        status=`${SMCWEBSERVER} status -p | awk -F= '{print $2}'`
	if [ "${status}" != "yes" ]; then
	    # start the server
	    ${SMCWEBSERVER} start
	fi
    else
	echo "${SMCWEBSERVER} does not exist or is not executable"
	exit ${EXIT_NO_SMCWEBSERVER}
    fi

} ## startConsole

################################################################################
#
# clearSMF take the server out of maintenace mode if s10
#
################################################################################
clearSMF() {
    # if SMF_PRESENT is defined, non zero length, we have to deal with SMF
    if [ -n "${SMF_PRESENT}" ]; then
	svcadm clear ${FMRI}
    fi
} # clearSMF

################
# MAIN
################

# user must be root
USERID=`id | sed -e 's/uid=\([0-9]*\).*/\1/'`
if [ $USERID -ne 0 ]; then
    echo "You must be the system's root user to manage the server." 1>&2
    exit 1
fi

# set the OS specific default console_* paths
setPrimordialPaths

# set wcswap default values
setDefaults

# Gather the command line options
while getopts "a:d:i:j:o:p:s:t:u:xrh\?" c
do
    case $c in
	"a") aflag=1
	     WCSWAP_ADMIN_PORT=${OPTARG}
	     ;;
	"d") dflag=1
	     WCSWAP_CONTAINER_DIR=${OPTARG}
	     ;;
	"i") iflag=1
	     WCSWAP_INSTANCE=${OPTARG}
	     ;;
	"j") jflag=1
	     WCSWAP_JMX_PORT=${OPTARG}
	     ;;
	"o") oflag=1
	     WCSWAP_JAVA_OPTIONS=${OPTARG}
	     ;;
	"p") pflag=1
	     WCSWAP_HTTP_PORT=${OPTARG}
	     ;;
	"r") rflag=1
	     ;;
	"s") sflag=1
	     WCSWAP_SECURE_PORT=${OPTARG}
	     ;;
	"t") tflag=1
	     WCSWAP_TYPE=${OPTARG}
	     ;;
	"u") uflag=1
	     WCSWAP_CONTAINER_PROCESS_UID=${OPTARG}
	     ;;
	"x") xflag=1
	     ;;
	"h") Usage 0
	     ;;
	\?)  Usage 0
	     ;;
    esac
done

# type flag is mandatory
if [ ${tflag} -eq 0 ]; then
    echo "Target container type must be defined."
    echo "Please specify target container type with the -t option"
    echo ""
    Usage ${EXIT_NO_TARGET_TYPE}
fi

# validate UID
if [ -n "${WCSWAP_CONTAINER_PROCESS_UID}" ];then
    validateUID ${WCSWAP_CONTAINER_PROCESS_UID}
fi

# validate http port
if [ -n "$WCSWAP_HTTP_PORT}" ];then
    validatePort ${WCSWAP_HTTP_PORT}
fi

# validate admin port
if [ -n "${WCSWAP_ADMIN_PORT}" ];then
    validatePort ${WCSWAP_ADMIN_PORT}
fi

# validate secure port
if [ -n "${WCSWAP_SECURE_PORT}" ];then
    validatePort ${WCSWAP_SECURE_PORT}
fi

# validate jmx port
if [ -n "${WCSWAP_JMX_PORT}" ];then
    validatePort ${WCSWAP_JMX_PORT}
fi

# SJSAS container type
if [ "${WCSWAP_TYPE}" = "${APP_SERVER_CONTAINER_TYPE}" ]; then
    # validate directory provided by -d option as an App Server install
    validateAS 

    # build appserver property values
    buildASProps

elif [ "${WCSWAP_TYPE}" = "${TCAT_CONTAINER_TYPE}" ]; then

    # external tomcat containers not supported
    if [ ${dflag} -eq 1 ]; then
	echo "External Apache Tomcat containers are not supported in this release."
	exit ${NO_EXT_TCAT}
    fi

    # build appserver property values
    buildTCATProps
else
    echo "Container type must be ${TCAT_CONTAINER_TYPE} or ${APP_SERVER_CONTAINER_TYPE}"
    Usage ${EXIT_BAD_CONTAINER_TYPE}

fi

# swap!
swapContainer

# do we need to clear SMF S10 +
clearSMF
    
# restart if requested
if [ ${rflag} -eq 1 ]; then
    startConsole
fi

exit ${SUCCESS}
