#!/bin/sh
#
# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident	"@(#)checkinstall.initd	1.2	05/06/30 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 them pipe them into pkgchk.  For
# each file which already exists and whose contents do not match the size or
# checksum saved in the package database, we get (^ = start of line):
#
#	^ERROR: /etc/init.d/somefile
#	^    file size <104780> expected <181> actual
# 	^    file cksum <56515> expected <14331> actual
#
# We grep for ERROR: followed by a single non-whitespace token, then strip
# the leading '^ERROR: ', leaving us a name of a modified file that we
# capture in the 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;;
	sparc.sun4v)	EXT=.v;;
	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/=.*$//' | \
	  pkgchk -R ${PKG_INSTALL_ROOT:-/} -q -i /dev/stdin $PKG 2>&1 | \
	  grep '^ERROR: [^ 	]*$' | sed 's/^ERROR: //' `
fi

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