#!/bin/sh

# Preserve configuration files (Source listing 4)

BASE=/a export BASE

CFGDIR=/etc/appname
OLDCFG=/etc/appname-oldcfg
NEWCFG=/etc/appname-newcfg

case $1 in
"beg")
	# We've avoiding using /a as a mount point for peace
	# of mind, even though it isn't in use at this point
	# of the jumpstart operation
	BASE=/mnt

	mount /dev/dsk/c0t0d0s0 $BASE >/dev/null 2>&1
	if [ $? -ne 0 ]; then
		echo "Filesystem mount failed"
		exit 1;
	fi

	if [ -d $BASE/$CFGDIR ]; then 
		echo "Preserving configuration files for application"
		mkdir $BASE/$OLDCFG
		mv $BASE/$CFGDIR/* $BASE/$OLFCFG
	fi
	umount $BASE
	;;

"fin")
	BASE=/a
	if [ -d $BASE/$OLDCFG  && -d $BASE/$CFGDIR ]; then
		echo "Recovering old application configuration"
		mkdir $BASE/$NEWCFG
		mv $BASE/$CFGDIR/* $BASE/$NEWCFG
		mv $BASE/$OLDCFG/* $BASE/$CFGDIR
		rmdir $BASE/$OLDCFG
	fi
	;;
*)
	echo "Usage $0 [begin|finish]"
	exit 2
	;;
esac
