#!/bin/sh
#
# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# ident	"@(#)postinstall_fonts	1.4	07/05/14 SMI"
#

PKGCOND=/usr/bin/pkgcond
is_srngz=99

if [ -x $PKGCOND ]; then
     $PKGCOND -v is_sparse_root_nonglobal_zone > /dev/null 2>&1
     is_srngz=$?
fi

test_writable() {
	if [ $is_srngz -ne 99 ]; then
		$PKGCOND is_path_writable $1 && return $?
	else
		/usr/bin/touch $1/.test.$$ > /dev/null 2>&1
		if [ $? !=  0 ]; then
			return 1
		else
			rm -f  $1/.test.$$ > /dev/null 2>&1
			return 0
		fi
	fi
} 

#
# Modify TTbitmaps/fonts.dir
#

if [ -f /tmp/fonts.dir ]; then
    rm /tmp/fonts.dir
fi

FONTINSTDIR=$BASEDIR/openwin/lib/locale/ja/X11/fonts

if [ -d $FONTINSTDIR/TTbitmaps ]; then
	test_writable $FONTINSTDIR/TTbitmaps > /dev/null 2>&1
	if [ $? = 0 ]; then
	    cd $FONTINSTDIR/TTbitmaps
	    count=`sed -e '1 d' -e '/^HeiseiMin-W3H/ d' ./fonts.dir | wc -l`
	    echo $count > /tmp/fonts.dir
	    sed -e '1 d' -e '/^HeiseiMin-W3H/ d' ./fonts.dir >> /tmp/fonts.dir
	    mv /tmp/fonts.dir fonts.dir
	    chgrp bin fonts.dir
	fi
fi

exit 0
