	
	
# Takes a filename passed as an argument, and uses it to set
# ArchiveFileName=<name><Version>.<ext>
# eg. fcds.rez may result in ArchiveFileName=fcds (11.0 Build 7).rez
setArchiveFileName()
{
	
	install_fn="$*"
	if [ "`echo $install_fn | grep '\.'`" = "" ]; then
		#Filename has no extension
		ArchiveFileName="$install_fn-$curBuild"
	else
		tempExt="`echo $install_fn | cut -d . -f 2`"	
		tempName="`echo $install_fn | cut -d . -f 1`"
		ArchiveFileName="$tempName-$curBuild.$tempExt"
	fi
}   

	
# Installs file whose name is passed as an argument into the $InstallDirectory path
# Sets chown to value stored in $user $MY_GROUP
# Sets chmod to value stored in $mode
# Files must be located in path $MY_FILES
# If updating a file the current file gets archived to: $FILE_ARCHIVE_FOLDER
# Archives old files by including the current application's version info in the archived name
installFile()
{
	FileName="$1"
	FilePath="$InstallDirectory/$FileName"
	
	if [ -f "$MY_TEMP_FILES/$FileName" ]; then
		echo "$MY_SEPERATOR"
		echo -n "Installing '$InstallDirectory/$FileName' file."
		if [ -f "$FilePath" ]; then
			updating=1
		else
			updating=0
		fi
		
		if [ "$updating" = "1" ]; then
			if [ ! -d "$FILE_ARCHIVE_FOLDER" ]; then
							 sudo mkdir -p "$FILE_ARCHIVE_FOLDER"
							 sudo chown "$MY_USER:$MY_GROUP" "$FILE_ARCHIVE_FOLDER"
							 sudo chmod 770 "$FILE_ARCHIVE_FOLDER"
							fi

			setArchiveFileName "$FileName"
			echo
			echo -n "    -Archiving current '$FileName' file to '$FILE_ARCHIVE_FOLDER/$ArchiveFileName'."
						sudo mv -f "$FilePath" "$FILE_ARCHIVE_FOLDER/$ArchiveFileName" 
			echo "...Done."
			echo -n "    -Installing '$FileName' file."
		fi
		
		sudo mv -f "$MY_TEMP_FILES/$FileName" "$FilePath"
		sudo chown "$user:$MY_GROUP" "$FilePath"
		sudo chmod "$mode" "$FilePath"
		
		echo "...Done."
		#echo "_____"
		#echo

		return 0;
	else
		echo "ERROR: File '$FileName' not found in '$MY_TEMP_FILES' directory."
		echo
		return 1;
	fi
}
