#!/bin/bash

set -eux

if [ -d /media/dstromberg/3B7C-9D2D/Music ]
then
	dest_dir=/media/dstromberg/3B7C-9D2D/Music
elif [ -d /mnt/phone-sdcard/Music ]
then
    dest_dir=/mnt/phone-sdcard/Music
else
	echo "$0: Could not find music mount, and sshfs no longer works" 1>&2
    # echo "Perhaps mount it with sshfs -p 22122 user@192.168.0.15:/ /mnt/S7"\?
	exit 1
fi

if [ -d ~/sound/Phone-Music ]
then
    source_dir=~/sound/Phone-Music
elif [ -d /mymount/sound/Phone-Music ]
then
    source_dir=/mymount/sound/Phone-Music
else
    echo "$0: Could not find Phone-Music directory" 1>&2
    exit 1
fi

cd "$source_dir"

# I don't know why this wasn't working, but it wasn't.
# It would try to transfer every file, but when I looked
# for changes, none were getting made!
#rsync \
#	-rv \
#	--size-only \
#    --ignore-times \
#	--delete \
#	--progress \
#	--stats \
#	. /mnt/S4/extSdCard/Music/

# So I wrote this little python script that copies based on
# presence/absence and file lengths.
    #--source ~/Sound/Minimal-Music \

~/src/home-svn/syncer/trunk/syncer \
    --source "$source_dir" \
    --destination "$dest_dir" \
    --extensions mp3 \
    --verbose

# 2017-06-03: Intended to deal with phantom files in Poweramp.  Not yet tested.
find "$dest_dir" -type d -empty -print0 | xargs -0 --no-run-if-empty rmdir