#!/bin/ksh
#
# If MU93xx is updated: This script will be run after the update
#
# ATTENTION! Be sure that no CR LF is in the script (only LF is allowed)!
#            Else it will not run!


# Switch the lines if you want to test with another file
MetainfoRoot=/HBpersistence/SWDL
# MetainfoRoot=.

Source=`grep 'Source = ' $MetainfoRoot/update.txt`

case $Source in
	"Source = CD")
		echo We got the source CD
		sourcePath=/fs/cd0
		;;
	"Source = SD1")
		echo We got the source SD1
		sourcePath=/fs/sd0
		;;
	"Source = SD2")
		echo We got the source SD2
		sourcePath=/fs/sd1
		;;
	"Source = USB")
		echo We got the source USB
		sourcePath=/fs/usb0
		;;
	*)
		echo Source is unknown $Source
		exit;
		;;
esac

ReleasePath=`grep 'ReleasePath = ' $MetainfoRoot/update.txt`

case $ReleasePath in
	"ReleasePath = ")
		echo Empty release path
		;;
	"ReleasePath = ./"*)
		echo Relative release path $ReleasePath
		sourcePath=$sourcePath${ReleasePath##"ReleasePath = ."}
		;;
	*)
		echo Absolute release path $ReleasePath
		sourcePath=$ReleasePath
		;;
esac

SubDir=`grep 'UseSubDir = ' $MetainfoRoot/update.txt`

case $SubDir in
	"UseSubDir = "*)
		echo SubDir $SubDir
		sourcePath=$sourcePath/${SubDir##"UseSubDir = "}
		;;
	*)
		echo No subdir
		;;
esac

MUName=`grep [[]MU9.*=DONE /HBpersistence/SWDL/update.txt`
if [[ $MUName == "" ]]; then
   MUName=`grep [[]MU9.*=NO /HBpersistence/SWDL/update.txt`
fi

MUName=${MUName##"["}
MUName=${MUName%%\\*}
echo MUName: $MUName

if [[ $MUName == "MU9307" ]]; then
   MUName=MU9308
fi

if [[ $MUName == "MU9303" ]]; then
   MUName=MU9304
fi

if [[ -a $sourcePath/$MUName/tools/sqlite.xml ]] ; then
	echo sqlite.xml found. Start override current settings
	cp $sourcePath/$MUName/tools/sqlite.xml /HBpersistence
else	
   echo $sourcePath/$MUName/tools/sqlite.xml does not exist
fi


echo scriptOK > /tmp/SWDLScript.Result
