#!/bin/sh

######################################################################
## File : upgrade_me
## Rev  : 000124
##
## Things this upgrade_me script must do :
##
##	1) Verify architecture / package version match.
##	2) Check for conflicts with installed RPMs. 
##	3) Install its own RPMsi.
##	4) Generate the .installed_rpms file.
##	5) Return status 0 on success.
#######################################################################

if [ -e /etc/build ]; then

	## Replace <MODEL_0|...|MODEL_N> with the model(s) you wish
	## to support installation on.
	##
	## Ex for all current Cobalt MIPS products : 
	## cat /etc/build | grep -E "2700|2799|2800" > /dev/null
	##
	## Ex for only the Qube 2 product :
	## cat /etc/build | grep -E "2800" > /dev/null

	cat /etc/build | grep -E "2700|2799|2800" > /dev/null

	if [ $? != 0 ]; then
		echo "4015 This package is designed for Cobalt MIPS only."
		exit 1
	fi
#else
	## Our machine id file is missing. So we will assume that
	## it is a 1st generation Qube 2700WG.
fi



RPMS=`ls $UPGRADE_DIR/RPMS`

## For each RPM in our pkg file, check for and report
## any potential conflict(s) with RPM(s) already 
## installed on the system. 

for rpm in $RPMS; do
	rpm -U --test $UPGRADE_DIR/RPMS/$rpm --nodeps --force
	if [ $? != 0 ]; then
		echo "4015 Problem verifying package component: $rpm"
		exit 1
	fi
done



## No conflicts detected so install all the RPMs
## within the package and add their names to 
## our installed list. 

echo -n "" > $UPGRADE_DIR/.installed_rpms

## Perform the actual installation.

for rpm in $RPMS; do
	rpm -U $UPGRADE_DIR/RPMS/$rpm --nodeps --force
	if [ $? != 0 ]; then
		echo "4015 Problem installing package component: $rpm"
		exit 1
	else
		echo $rpm >> $UPGRADE_DIR/.installed_rpms
	fi
done


## Signal exited successfully

exit 0
