#!/bin/sh
# chmod 755 /usr/syno/etc.defaults/rc.d/S99ZZZ_CustomPhotostation.sh
# mount/bind some folders on startup and umount them on shutdown/reboot (http://www.synology-wiki.de/index.php/Mount_Bind)
# Write to system log, event ids in /usr/syno/synosdk/texts/enu/events (http://forum.synology.com/enu/viewtopic.php?f=27&t=6396)
mountit()
{
	# $1 mount what, $2 mount where
	if [[ $(grep -c "${2}" /proc/mounts) -gt 0 ]] ; then
		/usr/syno/bin/synologset1  sys err 0x11800000 "$0: "$2" exists"
	else
		/bin/mkdir -p "$2"
		/bin/mount -o bind "$1" "$2"
		/usr/syno/bin/synologset1  sys info 0x11800000 "$0: Mounted "$1" to "$2""
	fi
	return
}
umountit()
{
	# $1 umount what
	/bin/umount $1 && /bin/rmdir "$1" && /usr/syno/bin/synologset1  sys info 0x11800000 "$0: Unmounted "$1""
	return
}

case $1 in
start)
	mountit	/volume1/photoCommon /volume1/photo/Common
	mountit /volume1/photoBob /volume1/photo/Bob
	mountit /volume1/photoAlice /volume1/photo/Alice
	;;
stop)
	umountit /volume1/photo/Common
	umountit /volume1/photo/Bob
	umountit /volume1/photo/Alice
	;;
*)
	echo "Usage: $0 [start|stop]"
	;;
esac
