Cut and paste below here


#!/bin/bash

############################################################################################
#
#    iriversync.sh - Synchronize an iRiver Hxxx series player with a local directory
#
#    Written by Ben Williams September 24th 2004
#    Web: http://sabaisabai.org/iRiver/
#    Email: webben@saabaisaabai.org
#
#    NOTE:  
#
#      1. The 'data' directory is *not* synched.  Use this for files you want to only keep on the iRiver, 
#         such as back-ups
#
#      2. The '-back' function has not been fully tested
#
#      3. The mount status of the iRiver prior to running the command is maintained after running the command, 
#         unless forced with '-mount' or '-umount' 
#
############################################################################################

# Source directory and mount point *must be the same*.  See LAPTOPDIRECTORY/MOUNTPOINT below
SYNCDIRECTORYNAME=iRiver

LAPTOPDIRECTORY=/home/ben/${SYNCDIRECTORYNAME}
IRIVERDIRECTORY=/mnt/
MOUNTPOINT=/mnt/${SYNCDIRECTORYNAME}

USAGE="Usage: iriversync.sh [-back] [-del] [-do] [-mount] [-umount] [--help]"

if [ "${1}" = "--help" ] 
then
   echo Script to synchronize an iRiver Hxxx series player with a local directory
   echo 
   echo ${USAGE}
   echo "   back   : sync from iRiver player to laptop"
   echo "   del    : delete files on destination that don't exist on source"
   echo "   do     : perform the sync without prompting"
   echo "   mount  : force keep iRiver mounted"
   echo "   umount : force unmount of iRiver"
   echo "   --help : show this message"
   exit 0
fi
   
for param in $*
do
   if [ "${param}" = "-back" ]
   then
      IRIVERSRC=${IRIVERDIRECTORY}
      IRIVERDEST=${LAPTOPDIRECTORY}
   fi
   
   if [ "${param}" = "-del" ]
   then
      deleteclause="--delete"
   fi
   
   if [ "${param}" = "-do" ]
   then
      dryrunclause="do"
   fi
   
   if [ "${param}" = "-mount" ]
   then
      mount="y"
   fi
   
   if [ "${param}" = "-umount" ]
   then
      umount="y"
   fi
done

if [ "${dryrunclause}" = "do" ]
then
   dryrunclause=""
else
   dryrunclause="--dry-run"
fi

if [ "${IRIVERDEST}" = "" ]
then
   IRIVERSRC=${LAPTOPDIRECTORY}
   IRIVERDEST=${IRIVERDIRECTORY}
fi


echo ${IRIVERDEST}iRiver/music

if [ ! -d ${IRIVERDEST}iRiver/music ]
then
   echo -n "iRiver is not mounted. Trying to mount at ${MOUNTPOINT}... "
   mount ${MOUNTPOINT} > /dev/null 2>&1
   
   mountresult=$?
   
   if [ ${mountresult} -eq 0 ]
   then
      echo done
      umount="y"
   else
      echo mounting failed >&2
      exit ${mountresult}
   fi
fi

if [ ! -d ${IRIVERSRC} ]
then
   echo source folder ${IRIVERSRC} was not found >&2
   exit 1
fi

if [ ! -d ${IRIVERDEST} ]
then
   echo destination folder ${IRIVERDEST} was not found >&2
   exit 1
fi


echo rsync -avu --size-only ${deleteclause} ${dryrunclause} ${IRIVERSRC} --exclude 'iRiver/data' ${IRIVERDEST}     
rsync -avu --size-only ${deleteclause} ${dryrunclause} ${IRIVERSRC} --exclude 'iRiver/data' ${IRIVERDEST}  
rsyncresult=$?


if [ "${dryrunclause}" = "--dry-run" ] && [ "${rsyncresult}" = "0" ]
then
   echo -n -e "\nPerform changes? [y/n] "
   read response
   if [ "${response}" = "y" ]
   then
      echo rsync -avu --size-only ${deleteclause} ${IRIVERSRC} --exclude 'iRiver/data' ${IRIVERDEST}     
      rsync -avu --size-only ${deleteclause} ${IRIVERSRC} --exclude 'iRiver/data' ${IRIVERDEST}  
      rsyncresult=$?
   fi
fi

if [ "${umount}" = "y" ] && [ "${mount}" != "y" ]
then
   echo -n "Trying to unmount ${MOUNTPOINT} ... "
   umount ${MOUNTPOINT} > /dev/null 2>&1
   
   mountresult=$?
   
   if [ ${mountresult} -eq 0 ]
   then
      echo done
   else
      echo unmounting failed >&2
   fi
fi

exit ${rsyncresult}