#!/bin/sh
#
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident	"@(#)checkinstall.initd	1.3	08/01/11 SMI"
#
# checkinstall.initd
#
# Before we begin installing new files, we need to save the existing files
# if the administrator has modified them since their original installation.
# To do this, we find 'e' and 'l' entries in the pkgmap, convert their
# relative "etc/" prefix to /etc, and pipe these files to a while loop.
# For every file that is piped, call pkgchk(1M) with '-q' and '-p' options
# with the package name to which this file belongs. For each file which
# already exists and whose contents do not match the size or checksum
# saved in the package database, pkgchk(1M) returns an error code which
# is not '0'. In such a case, capture the name of the file into
# MODIFIED_AFTER_INSTALLED. variable. This variable is written to the file
# provided as an argument to the script, in the form of an environment
# variable setting. Said file later gets sourced by the pkgadd command for
# use in our class action script.

case "$ARCH" in
	sparc.sun4m)	EXT=.m;;
	sparc.sun4u)	EXT=.u;;
	i386.i86pc)	EXT=.i;;
	*)		EXT="";;
esac

PKGMAP=$INST_DATADIR/$PKG$EXT/pkgmap
MODIFIED_AFTER_INSTALLED=""

if [ "$UPDATE" = yes ]; then
	MODIFIED_AFTER_INSTALLED=` \
	  awk '($2 == "e" || $2 == "l") && $3 == "initd" {print $4}' $PKGMAP | \
	  sed -e 's:^etc/:/etc/:' -e 's/=.*$//' | \
	  while read filename; do
		pkgchk -R ${PKG_INSTALL_ROOT:-/} -q -p "$filename" $PKG > /dev/null 2>&1
		if  [ $? -ne 0 ]; then
			echo "$filename"
		fi
	  done`
fi

echo MODIFIED_AFTER_INSTALLED=\"${MODIFIED_AFTER_INSTALLED}\" >> $1
exit 0
