#!/bin/bash
#                 /usr/local/bin/mountmuse
# http://crystalfaeries.net/posix/bin/mountmuse
# celeste:crystalfaery 2014-09-13 05:48:30+00:00
# Host muse has a pair of RAIDs, one each for audio and video,
# and a dedicated disk for backups (/var/cache/rsnapshot),
# which other hosts remote mount via sshfs.
# NOTE:	We clone *all* our own local audio and video to the RAIDs
# NOTE:	the rsnapshot process requires root level access permissions,
#	therefore the rsnapshot volume must be mounted as root,
#	which therefore, via sshfs, leaves it invisible to non root users,
#	(e.g. the 'df' command run by regular user does not show it).
#	Regular users can still recover files from backups via:
#	rsync -auvzH muse:/var/cache/rsnapshot/hourly.0/.sync/`hostname`/home/`whoami`/myfile ~
#	or do their own sshfs mount as themself to some mount point.

case `hostname` in
muse)
	echo "$0: You do not really want to do this on muse." 1>&2
	exit	-1
	;;
tomril)
	# the rsnapshot target for all hosts:
	sudo sshfs muse:/var/cache/rsnapshot /var/cache/rsnapshot
	# mirror the audio RAID:
	rsync -auvzH 	muse:/home/audio/{.??,}*	     /home/audio	|| echo "`hostname`: $?"
	rsync -auvzH 	     /home/audio/{.??,}*	muse:/home/audio	|| echo "`hostname`: $?"
	sshfs -o nonempty				muse:/home/audio     /home/audio	|| echo "`hostname`: $?"
	# mirror the video RAID:
	rsync -auvzH 	muse:/home/video/{.??,}*	     /home/video	|| echo "`hostname`: $?"
	rsync -auvzH 	     /home/video/{.??,}*	muse:/home/video	|| echo "`hostname`: $?"
	sshfs -o nonempty				muse:/home/video     /home/video	|| echo "`hostname`: $?"
	;;
pixy)
	# the rsnapshot target for all hosts:
	sudo sshfs muse:/var/cache/rsnapshot /var/cache/rsnapshot
	# migrate to audio RAID:
#	rsync -auvzH 	muse:/home/audio/{.??,}*	     /home/audio
	rsync -auvzH	     /home/audio/{.??,}*	muse:/home/audio \
	|| echo "`hostname`: $?"
	sshfs -o nonempty				muse:/home/audio     /home/audio	|| echo "`hostname`: $?"
	# migrate to video RAID:
#	rsync -auvzH muse:/home/video/{.??,}*	     /home/video
	rsync -auvzH	  /home/video/{.??,}*	muse:/home/video
	sshfs -o nonempty			muse:/home/video	     /home/video	|| echo "`hostname`: $?"
	;;
*)
	echo "If you really want to do this on `hostname` then edit $0" 1>&2
	exit	0
	;;
esac


syntax highlighted by Code2HTML, v. 0.9.1