#!/bin/sh
# ====================[ psp-cohere                         ]====================
#                     [ Time-stamp: "2009-04-21 18:45:24 leycec" ]             
#
# --------------------( CHANGELOG                          )--------------------
# [2007-08-10] 0.0.1: Creation.

# ....................{ CONFIGURATION                      }....................
# The absolute path to the root of your mounted PSP. This is the "source."
#
# The default, here, is probably not fine. You'll probably want to change it.
SOURCE_ROOT="/media/usbdisk/PSP/SAVEDATA/"

# The absolute path to the root of a local repository to which PSP savefiles,
# gamefiles, and other files will be saved. This is the "target."
#
# The default, here, is probably not fine. You'll probably want to change it.
TARGET_ROOT="/home/leycec/var/psp/PSP/SAVEDATA"

# Command-line filters to be passed to the "rsync" binary. See the
# <FILTER RULES> section of "man rsync".
#
# All files or paths in the remote repository matching at least one of these
# filters will be ignored (i.e., not "rsync"-synchronized into the local
# repository).
#
# The default, here, is probably fine. It filters out the following patterns:
#   /PSP/SAVEDATA/UCUS98612D*  ~ addon packs for "Wipeout Pure""
RSYNC_FILTERS="\
  --exclude=UCUS98612D*/ \
"
# "\
#   --include=/current.css \
#   --include=/current.pl \
#   --include=/wiki/ \
#   --exclude=/wiki/config_private.pl \
#   --exclude=/*"

# Command-line options to be passed to the "rsync" binary, when performing
# rsync-synchronizations. See the <OPTIONS> section of "man rsync".
#
# The defaults, here, are probably fine.
RSYNC_OPTIONS="\
  --archive \
  --no-perms --no-owner --no-group \
  --human-readable \
  --keep-dirlinks --safe-links \
  --sparse \
  --super \
  --verbose \
"

# ....................{ CONSTANTS                          }....................
SCRIPT_NAME=$(basename "$0")
SCRIPT_VERSION="0.0.1"

# ....................{ I/O HANDLING                       }....................
mutter() {
  echo -n "${SCRIPT_NAME}: $*"
}

utter() {
  if [ -n "$IS_CRON" ]
  then logger -p cron.notice "${SCRIPT_NAME}: $*"
  else echo "${SCRIPT_NAME}: $*"
  fi
}

curse() {
  if [ -n "$IS_CRON" ]
  then logger -p cron.err "${SCRIPT_NAME}! $*"
  else echo "${SCRIPT_NAME}! $*" 1>&2
  fi
}

# ....................{ ERROR HANDLING                     }....................
try() {
  $*
  [ $? = 0 ] || exit 1
}

die() {
  curse $*
  exit 1
}

# ....................{ INITIALIZATION                     }....................
utter "v${SCRIPT_VERSION}"
echo ""

[ -x "$(which rsync 2>/dev/null)" ] ||
  die 'rsync not installed! ("rsync" binary not found in your $PATH.)'

# ....................{ EXECUTION                          }....................
utter "$SOURCE_ROOT -> $TARGET_ROOT"
try nice rsync $RSYNC_OPTIONS $RSYNC_FILTERS "$SOURCE_ROOT" "$TARGET_ROOT"
  
# --------------------( COPYRIGHT AND LICENSE              )--------------------
# The information below applies to everything in this distribution,
# except where noted.
#              
# Copyleft 2008 by Cecil Curry.
#   
#   http://www.raiazome.com
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
