#!/bin/ksh
#
# 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
# or http://www.opensolaris.org/os/licensing.
# 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.
#

# =============================================================================
# =============================================================================
# ai_boot_archive_configure
#
# Additional boot_archive configuration for automated installer images.
# =============================================================================
# =============================================================================

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Main
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Perform special boot archive configuration for automated installer images.
# 
# Args:
#   MFEST_SOCKET: Socket needed to get manifest data via ManifestRead object
#	(not used)
#
#   PKG_IMG_PATH: Package image area (not used)
#
#   TMP_DIR: Temporary directory to contain the boot archive file (not used)
#
#   BA_BUILD: Area where boot archive is put together
#
#   MEDIA_DIR: Area where the media is put (not used)
#
# Note: Although finalizer scripts receive at least the five args above, this
# script uses only BA_BUILD.
#
# Note: This assumes a populated boot archive area exists at BA_BUILD.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Verify argument count
if [ $# != 5 ] ; then
	print -u2 "$0: Requires 5 args:"
	print -u2 "    Reader socket, pkg_image mntpt, tmp dir,"
	print -u2 "    boot archive build area, media area"
	exit 1
fi

# Get commandline args.  First 5 are passed to all finalizer scripts.

# This is the full path to the top of the boot archive 
BA_BUILD=$4
if [ ! -d $BA_BUILD ] ; then
	print -u2 "$0: boot archive build area $BA_BUILD is invalid."
	exit 1
fi

if [ ! -d ${BA_BUILD}/usr/bin -o ! -d ${BA_BUILD}/lib ] ; then
	print -u2 "$0: /usr/bin and/or /lib missing from the boot archive!"
	exit 1
fi

cd ${BA_BUILD}/lib
# The following are needed for vi
ln -s libc.so.1 ../usr/lib
ln -s libgen.so.1 ../usr/lib
ln -s libcurses.so.1 ../usr/lib

exit 0
