#!/bin/sh

PKG_DIR=/var/sadm/pkg
PKGS="SUNWsbuA"
TMPFILE=/tmp/pkginfo
#
# first check the version is ok
# if it's ok then don't do anything
#
for P in $PKGS
do
	VERSION=`/usr/bin/grep VERSION= $PKG_DIR/$P/pkginfo | \
	/usr/bin/awk -F= '{print $2}'`
	if [ "X$VERSION" = "Xnfs1.0_fcs" ]; then
		exit
	else
		echo "$VERSION" > $PKG_DIR/$P/save/.version
	fi
done

#
# need to change the VERSION to the correct format for this patch to work.
#
for P in $PKGS
do
	/usr/bin/sed -e 's/VERSION..*$/VERSION=nfs1.0_fcs/' \
	$PKG_DIR/$P/pkginfo > $TMPFILE && /usr/bin/mv $TMPFILE $PKG_DIR/$P/
done

# fix ufsdump

/usr/bin/mv /usr/lib/fs/ufs/ufsdump /usr/lib/fs/ufs/ufsdump.netranfs
cat >> /usr/lib/fs/ufs/ufsdump << EOF
#!/bin/sh
                
# we don't want prestoserve to be running while
# ufsdump is being run.

/etc/init.d/prestoserve stop > /dev/null 2>&1

/usr/lib/fs/ufs/ufsdump.netranfs "\$@"
result=\$?

/etc/init.d/prestoserve start > /dev/null 2>&1

# we want to return the exit code of "ufsdump"
exit \$result
EOF
/usr/bin/chmod 6555 /usr/lib/fs/ufs/ufsdump
/usr/bin/chgrp tty /usr/lib/fs/ufs/ufsdump

# Patch the incore value

/usr/bin/adb -w -k /dev/ksyms /dev/mem <<_EOF >/tmp/adbout.$$
debug_panic?W 1
debug_panic?X
_EOF

# Patch the on disk value
#

/usr/bin/adb -w /platform/sun4u/kernel/unix <<_EOF >>/tmp/adbout.$$
debug_panic?W 1
debug_panic?X
_EOF

# add entry to /etc/system

grep debug_panic /etc/system
if [ $? -ne 0 ]
then
	echo "set debug_panic=1" >> /etc/system
	echo "Patched /etc/system"
fi
exit 0
