
createServiceFolder()
{
	# Ensure that the root FirstClass Services folder exists before beginning...
	if [ ! -e "$SERVICE_FOLDER" ]; then
		if [ ! -e "$SERVICE_PARENT" ]; then
			sudo mkdir "$SERVICE_PARENT"
			sudo chown root:$MY_GROUP "$SERVICE_PARENT"
		fi
		sudo mkdir "$SERVICE_FOLDER"
	fi
	sudo chown $MY_USER:$MY_GROUP "$SERVICE_FOLDER"
	sudo chmod 770 "$SERVICE_FOLDER"
	sudo chgrp $MY_GROUP "$SERVICE_FOLDER"/* &> /dev/null
	sudo chmod ug+rw,o= "$SERVICE_FOLDER"/* &> /dev/null
}


warnThisIsNotUpgradeInstaller()
{
	echo "WARNING: This installer can upgrade the core server executables, but it does"
	echo "         not include the files necessary to upgrade the FCNS content store."
	echo "         For that, you must run the UPGRADER (available separately),"
	echo "         not this NEW server installer."
	echo -n 'Do you wish to continue, upgrading the executables only (y/n)? [y]'
	read ANSWER
	if [ "$ANSWER" = "y" ] ||  [ "$ANSWER" = "Y" ] ||  [ "$ANSWER" = "" ] ; then
		INSTALL_CS=1
	else
		INSTALL_CS=0
			echo ""
			echo "Nothing to install..."
			cleanup
			exit 1
	fi
}


installCoreServer()
{
    
    
	# Ensure that the root FirstClass volumes folder exists before beginning...
	sudo mkdir -p "$VOLUMES_PATH"
	sudo chown $MY_USER:$MY_GROUP "$VOLUMES_PARENT"
	sudo chown $MY_USER:$MY_GROUP "$VOLUMES_PATH"
	
	echo -n "[`$NOW`] Checking for installed $PRODUCT_BRAND volumes ... "
	if [ -e "$PRIMARY_FCNS" ]; then
		echo "found."
		if [ "$UPGRADE_FCNS" -ne "1" ]; then
			echo "Master volume already exists ... leaving untouched."
		fi
		INSTALL_FCNS=0
	elif [ "$INSTALL_FCNS" -ne "1" ] ; then
		echo "NOT FOUND."
		echo "Warning: There is no $PRODUCT_BRAND Network Store installed, and none in this installer."
	else
		echo "none found."
		if [ -e "$FCNSARCH_TAR" ]; then
			FCNS_TO_INSTALL="$FCNSARCH_TAR"
                elif [ -e "$FCNSOTSM_TAR" ]; then
                        FCNS_TO_INSTALL="$FCNSOTSM_TAR"
		elif [ -e "$FCNSBUS_TAR" ]; then
			if [ -e "$FCNSEDU_TAR" ]; then
				FCNS_TO_INSTALL=""
				while [ -z "$FCNS_TO_INSTALL" ] ; do
					echo "This installer includes both Business and Education Editions of the network store."
					echo -n "Which network store should be installed, Business or Education (B/E)? "
					read ANSWER
					if [ "$ANSWER" = "B" ] ||  [ "$ANSWER" = "b" ] ; then
						FCNS_TO_INSTALL=$FCNSBUS_TAR
					elif [ "$ANSWER" = "E" ] ||  [ "$ANSWER" = "e" ] ; then
						FCNS_TO_INSTALL=$FCNSEDU_TAR
					else
						echo " "
					fi
				done
			else
				FCNS_TO_INSTALL="$FCNSBUS_TAR"
			fi
		else
			FCNS_TO_INSTALL="$FCNSEDU_TAR"
		fi
		echo -n "Installing new volume at \"$PRIMARY_FCNS\" ... "
		if [ ! -d "$PRIMARY_FCNS" ]; then mkdir -p "$PRIMARY_FCNS"; fi
		tar xzf "$FCNS_TO_INSTALL" -C "$PRIMARY_FCNS"
		echo "done."
		VERIFY_PO=1
		#
		
		if [ ! -e "$FCNSARCH_TAR" ]; then
			runInstallerWizard
		fi
		
		if [ ! -e "$VER_TXT" ]; then
			updateVerTxtFile
		fi
		
	fi
	
	if [ -e "$FCSD_PATH" ]; then
		echo "Updating core server executable files under "$SERVICE_FOLDER" ... "
	else
		echo "Installing core server executable files under "$SERVICE_FOLDER" ... "
		#update_sudoersFile
	fi
	if [ ! -e "$SERVICE_FOLDER" ]; then mkdir -p "$SERVICE_FOLDER"; fi
	
	curBuild=`get_build "$FCSD_PATH"`
	if [ "$curBuild" = "" ]; then 
#	if ! [ "$curBuild" -ge 0 ]; then 
		curBuild=$UNKNOWN_VER;
	fi
	curBackup="$FCSD_NAME-$curBuild"
	curRezBackup="$FCSD_NAME-$curBuild.rez"
#	echo if "$curBuild" == "$FCSD_BUILD"
	
	if [ -e "$FCSD_PATH" ]; then
		if [ -e "$SERVICE_FOLDER/$curBackup" ]; then
			echo "  Backup of current $FCSD_NAME ($curBackup) already exists"
		else
			echo "  Renaming current '$FCSD_NAME' to '$curBackup'"
			sudo mv -f "$FCSD_PATH" "$SERVICE_FOLDER/$curBackup"
		fi
	fi
	if [ -e "$FCSDREZ_PATH" ]; then
		if [ -e "$SERVICE_FOLDER/$curRezBackup" ]; then
			echo "  Backup of current $FCSD_NAME.rez ($curRezBackup) already exists"
		else
			echo "  Renaming current '$FCSD_NAME.rez' to '$curRezBackup'"
			sudo mv -f "$FCSDREZ_PATH" "$SERVICE_FOLDER/$curRezBackup"
		fi
	fi
	
	if [ -e "$FCPUTILFC_PATH" ]; then
            tar xz --exclude "$FCPUTIL_NAME.fc" -f "$FCSD_TAR" -C "$SERVICE_FOLDER"
    else
            tar xzf "$FCSD_TAR" -C "$SERVICE_FOLDER"
    fi
	
	chmod ug+x "$SERVICE_FOLDER/fcsctl" "$SERVICE_FOLDER/fcfixvol"
	if [ ! -e "$CTL_FOLDER" ]; then sudo mkdir -p "$CTL_FOLDER"; fi
	sudo mv "$SERVICE_FOLDER/fcsctl" "$CTL_FOLDER"
}

