#!/bin/ash

# your mount folder path
MOUNT_PATH='/volume1/gdrive'
PLEXDRIVE_PATH='/volume1/work/.plexdrive'
TMP_PATH=$PLEXDRIVE_PATH'/cache'

echo $TMP_PATH
#----------------------------
# unmount script
# run # /your_path/plexdrive.sh unmount
# ex) # /volume1/work/.plexdrive/plexdrive-mount.sh unmount
if [ $1 ] && [ $1 = "unmount" ] 
then
	echo '>> unmounting'
	umount $MOUNT_PATH
	fusermount -uz $MOUNT_PATH
	exit
fi



#----------------------------
# crontab mount script
# run # /your_path/plexdrive.sh
# ex) # /volume1/work/.plexdrive/plexdrive-mount.sh
MOUNTTYPE=`cat /proc/mounts | grep $MOUNT_PATH | awk '{print $3}'`
echo $MOUNTTYPE


if [ $MOUNTTYPE ] && [ $MOUNTTYPE = "fuse" ]
then
	echo '>> aleady mounted'
else
	echo '>> mounting'
	
	umount $MOUNT_PATH
	fusermount -uz $MOUNT_PATH
	$PLEXDRIVE_PATH/plexdrive $MOUNT_PATH \
		-o allow_other,allow_non_empty_mount \
		--gid=100 \
		--clear-chunk-max-size=50G \
		--chunk-size=10M \
		--speed-limit=7M \
		--refresh-interval=1m \
		-c $PLEXDRIVE_PATH \
		-t $TMP_PATH \
		-v 2 &

	echo '>> sleep 5..'
	sleep 5
	
	echo '>> ls'
	ls $MOUNT_PATH
	
	echo '>> end'
fi
exit
