#!/bin/bash
#                       /usr/local/bin/syncmacusb
#  http://crystalfaeries.net/posix/bin/syncmacusb
# celeste:crystalfaery 2016-06-28 20:02:15+00:00
# update MacUSB thumbdrive (was Mac formatted vfat, now ext4)
volume=/media/`whoami`/f0b1d79d-87dd-4890-95d2-680a422efea4/

# optional argument is "--dry-run"
let result=0	# default success exit
echo	"`now`	=======	$0	=======	$1	======="								2>>/var/log/syncup.log 1>&2	|| exit 1
if [ $# == 0 ]
then
	:	# no argument is acceptable invocation
else
	if [ "$1" == "--dry-run" ]
	then
		:	# --dry-run is acceptable argument
	else
		echo "$0 does not cognize $1"										2>>/var/log/syncup.log 1>&2
		echo "`now`	-------	$0	-------	$1	-------"						2>>/var/log/syncup.log 1>&2
																			   exit 2
	fi
fi
     mkdir -p			${volume}	|| \
sudo mkdir -p			${volume}
     chown `whoami`:		${volume}	|| \
sudo chown `whoami`:		${volume}
     chmod 770			${volume}	|| \
sudo chmod 770			${volume}
cd				${volume}						2>>/var/log/syncup.log 1>&2	|| exit 3

# DOCUMENTS (MacUSB is slave):
#echo "rsync $1 -auvzH		--exclude-from=${volume}/.exclude.txt ./documents					~"					2>>/var/log/syncup.log 1>&2	|| exit 4
#      rsync $1 -auvzH		--exclude-from=${volume}/.exclude.txt ./documents					~					2>>/var/log/syncup.log 1>&2	|| exit 5
echo "rsync $1 -auvzH --delete	--exclude-from=${volume}/.exclude.txt ~/documents					."					2>>/var/log/syncup.log 1>&2	|| exit 6
      rsync $1 -auvzH --delete	--exclude-from=${volume}/.exclude.txt ~/documents					.					2>>/var/log/syncup.log 1>&2	|| exit 7

#echo "rsync $1 -auvzH          ./Mail						~"					2>>/var/log/syncup.log 1>&2	|| exit 8
#      rsync $1 -auvzH          ./Mail						~					2>>/var/log/syncup.log 1>&2	|| exit 9
echo "rsync $1 -auvzH --delete ~/Mail						."					2>>/var/log/syncup.log 1>&2	|| exit 8
      rsync $1 -auvzH --delete ~/Mail						.					2>>/var/log/syncup.log 1>&2	|| exit 9

# crystalfaeries.net WEBSITE (MacUSB is slave):
echo "rsync $1 -auvzH --delete --exclude-from=${volume}/.exclude.txt \
		/home/www							."					2>>/var/log/syncup.log 1>&2	|| exit 10
      rsync $1 -auvzH --delete --exclude-from=${volume}/.exclude.txt \
		/home/www							.					2>>/var/log/syncup.log 1>&2	|| exit 11
echo "rsync $1 -auvzH --delete --exclude-from=${volume}/.exclude.txt \
		/home/audio/{`whoami`,www}					audio"					2>>/var/log/syncup.log 1>&2	|| exit 12
      rsync $1 -auvzH --delete --exclude-from=${volume}/.exclude.txt \
		/home/audio/{`whoami`,www}					audio					2>>/var/log/syncup.log 1>&2	|| exit 13
echo "rsync $1 -auvzH --delete --exclude-from=${volume}/.exclude.txt \
		/home/video/www							video"					2>>/var/log/syncup.log 1>&2	|| exit 14
      rsync $1 -auvzH --delete --exclude-from=${volume}/.exclude.txt \
		/home/video/www							video					2>>/var/log/syncup.log 1>&2	|| exit 15

# POSIX (MacUSB is slave):
mkdir -p	posix													2>>/var/log/syncup.log 1>&2	|| exit 26
pushd		posix													2>>/var/log/syncup.log 1>&2	|| exit 27
    for item in *
	do
	  echo "rsync $1 -auvzH --delete --exclude-from=${volume}/.exclude.txt \
					--exclude=jargon \
					--exclude=avidemux* \
					--exclude=bitcoin-cli \
					--exclude=bitcoind \
					--exclude=bitcoin-qt \
					--exclude=bitcoin-tx \
					--exclude=cryptocat \
					--exclude=telegram \
					--exclude=telegram-gui \
					--exclude=test_bitcoin \
							/usr/local/$item	."					2>>/var/log/syncup.log 1>&2	|| exit 28
		rsync $1 -auvzH --delete --exclude-from=${volume}/.exclude.txt \
					--exclude=jargon \
					--exclude=avidemux* \
					--exclude=bitcoin-cli \
					--exclude=bitcoind \
					--exclude=bitcoin-qt \
					--exclude=bitcoin-tx \
					--exclude=cryptocat \
					--exclude=telegram \
					--exclude=telegram-gui \
					--exclude=test_bitcoin \
							/usr/local/$item	.					2>>/var/log/syncup.log 1>&2	|| exit 29
	done
popd															2>>/var/log/syncup.log 1>&2	|| exit 30

# BOOKMARKS (bi-directional):
echo "rsync $1 -auvzH       ~/.mozilla/firefox/*.default/bookmarks.html ${volume}/bookmarks"		2>>/var/log/syncup.log 1>&2	|| exit 31
      rsync $1 -auvzH       ~/.mozilla/firefox/*.default/bookmarks.html ${volume}/bookmarks		2>>/var/log/syncup.log 1>&2	|| exit 32
echo "rsync $1 -auvzH ${volume}/bookmarks/bookmarks.html       ~/.mozilla/firefox/*.default"		2>>/var/log/syncup.log 1>&2	|| exit 33
      rsync $1 -auvzH ${volume}/bookmarks/bookmarks.html       ~/.mozilla/firefox/*.default		2>>/var/log/syncup.log 1>&2	|| exit 34

# Log what we DID NOT SYNC based on the EXCLUDE FILE which lives on the USB stick, to keep it from overflowing!
echo	 "EXCLUDED-FROM=${volume}/.exclude.txt:"									2>>/var/log/syncup.log 1>&2	|| exit 35
cat			${volume}/.exclude.txt										2>>/var/log/syncup.log 1>&2	|| exit 36

echo	"`now`	-------	$0	-------	$1	-------"								2>>/var/log/syncup.log 1>&2	|| exit 37
exit $result


syntax highlighted by Code2HTML, v. 0.9.1