#!/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.
#

# =============================================================================
# =============================================================================
# slimcd_post_boot_archive_pkg_image_mod
#
# pkg_image area modifications specific for slim cd, to be made after the
# boot archive is built.
# =============================================================================
# =============================================================================

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Main
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Perform pkg_image area modifications specific for slim cd after the
# boot archive is built.  This finalizer script is to be called after the boot
# archive build is complete.
# 
# Args:
#   MFEST_SOCKET: Socket needed to get manifest data via ManifestRead object
#	(not used)
#
#   PKG_IMG_PATH: Package image area
#
#   TMP_DIR: Temporary directory to contain the boot archive file (not used)
#
#   BA_BUILD: Area where boot archive is put together (not used)
#
#   MEDIA_DIR: Area where the media is put (not used)
#
# Of these automatically-passed variables, only the PKG_IMG_PATH is actually
# used.
#
# Note: This assumes boot archive is built and pkg_image area is intact.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

PKG_IMG_PATH=$2
if [ ! -d ${PKG_IMG_PATH} ] ; then
	print -u2 "$0: Image package area $PKG_IMG_PATH is not valid"
	exit 1
fi

FIND=/usr/bin/find
XARGS=/usr/bin/xargs
RM=/usr/bin/rm

# Remove the icon theme caches
print "Cleaning out icon theme cache"
if [ -d ${PKG_IMG_PATH}/usr ] ; then
	cd ${PKG_IMG_PATH}/usr
	$FIND . -name icon-theme.cache -print| $XARGS $RM
fi

# platform only needs to contain the kernel and boot_archive.
if [ -d ${PKG_IMG_PATH}/platform ] ; then
	cd ${PKG_IMG_PATH}/platform
	$FIND . -type f -a ! \( -name unix -o -name boot_archive \) | $XARGS $RM -f
fi

exit 0
