#!/bin/sh
#
#       @(#)server_upgrade.sh 1.2 95/06/26 SMI
#
# Copyright (c) 1995 by Sun Microsystems, Inc.
#

print_usage() {
echo `gettext 'usage: server_upgrade -d <installation_medium> [ -p <profile> ]'`
echo
EOF
}

get_root_device() {
origdir=`pwd`
cd /
rootdev=`df . | sed 's,^.*(\([^ )]*\).*,\1,'`
rootdev=`basename $rootdev`
cd $origdir
}

medium=
profile=

while getopts d:p: c
do
	case $c in
	d)	medium=$OPTARG;;
	p)	profile=$OPTARG;;
	\?)	print_usage
		exit 1;;
	esac
done
shift `expr $OPTIND - 1`

if [ "$medium" = "" ] ; then
	print_usage
	exit 1
fi

if [ ! -d $medium ] ; then
	eval echo `gettext 'Error:  Could not access ${medium}.'`
	exit 2
fi

if [ ! -f ${medium}/.cdtoc ] ; then
	eval echo `gettext 'Error:  ${medium} is not in expected format.'`
	exit 3
fi

if [ "$profile" = "" ] ; then
	touch /tmp/prof.$$
	profile=/tmp/prof.$$
fi

get_root_device

/usr/sbin/install.d/pfupgrade -n -o -L / -p $profile -c $medium -r $rootdev
exitcode=$?

rm -f /tmp/prof.$$

exit $exitcode
