#!/bin/bash

readonly Script_Name="Physave"

readonly Fillepath____This_Script=$(realpath "${BASH_SOURCE[0]}")
readonly Follpath____This_Script=$(dirname "$Fillepath____This_Script")

# 05:54:15 06/21/2017.
#
#	Fillepath	=	Full Filepath
#	Follpath	=	Full Folderpath


readonly Full_Uncanon_Unreal_Folpath____This_Script=$(dirname "${BASH_SOURCE[0]}")


readonly Original_Working_Dir=$(pwd)


readonly Follpath____Helpers=$(readlink -m "$Follpath____This_Script/../Helpers")

cd "$Follpath____Helpers"

source "Initialize Ramize or Physave"



##############################


cd "$Follpath____Config"

echo "Datetime of last physave: $Retrieved____Datetime_of_Last_Physave"
echo
echo "Standardized____Physave_Path: $Standardized____Physave_Path"
echo " Standardized____Ramize_Path: $Standardized____Ramize_Path"


from_path_for_rsync="$Standardized____Ramize_Path/"
to_path_for_rsync="$Standardized____Physave_Path"

echo
echo "from_path_for_rsync: $from_path_for_rsync"
echo "  to_path_for_rsync: $to_path_for_rsync"

echo
echo
source "$Fillepath____Physave_Rsync"
result_code="$?"

echo
echo
if [ "$result_code" != 0 ]
then
	echo "Physave rsync somehow failed!  Result code: $result_code"
	exit $result_code
fi


echo "Physave rsync succeeded.  Now syncing..."
	
sync
	
result_code="$?"
	
echo
	
if [ "$result_code" != 0 ]
then
	echo "Sync (not rsync) somehow failed!  Result code: $result_code"
	exit $result_code
fi

echo "Sync succeeded.  Now noting date/time of this physave..."



Update_Datetime_of_Last_Physave_to_Now

result_code="$?"



if [ "$result_code" != 0 ]
then
	echo
	echo "Somehow failed to note the date/time of this physave!  Result code: $result_code"
	exit $result_code
fi

echo "$now_datetime"
echo

echo "All done!"

exit 0