#!/bin/sh

# Copyright (C) 2004, 2005, 2008 Simon Josefsson.
#
# This file is part of Autobuild.
#
# Autobuild 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.
#
# Autobuild 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 Autobuild.  If not, see <http://www.gnu.org/licenses/>.

prog="`basename \"$0\"`"
rcs_revision='$Revision: 1.7 $'
rcs_version=`set - $rcs_revision; echo $2`
program=`echo $0 | sed -e 's!.*/!!'`
version="abput-sourceforge (autobuild) $rcs_version

Copyright (C) 2004, 2005 Simon Josefsson
There is NO warranty.  You may redistribute this software under the
terms of the GNU General Public License.  For more information about
these matters, see the file named COPYING."

usage="Usage: $prog [OPTION]... FILES...

Upload FILES to SourceForge compile farm.

Options:
  -u, --username       SourceForge SSH username.  Defaults to \$USER.
  -v, --verbose        Pass '-v' to scp.
  -h, --help           Display this help and exit successfully.
      --version        Display version information and exit successfully.

Environment variables:
  ABSFUSER             SourceForge SSH username.

Files:
  \$HOME/.ab-sf         Shell script sourced, can be used to specify ABSFUSER.
                       E.g., run 'echo ABSFUSER=joe > \$HOME/.ab-sf'.

Simple example:
  $prog yourproject-4.2.tar.gz

Report bugs to <bug-autobuild@josefsson.org>."

test -f $HOME/.ab-sf && . $HOME/.ab-sf

while test $# -gt 0; do
  case $1 in
    -v) VERBOSE=-v;;
    -h) echo "$usage"; exit 0;;
    -u) shift; ABSFUSER=$1;;
    --username) shift; ABSFUSER=$1;;
    --help) echo "$usage"; exit 0;;
    --version) echo "$version"; exit 0;;
    -*)
      echo "$0: Unknown or ambiguous option \`$1'." >&2
      echo "$0: Try \`--help' for more information." >&2
      exit 1;;
    *)
      break;;
  esac
  shift
done

if test $# -eq 0; then
    echo "$0: Too few arguments." >&2
    echo "$0: Try \`--help' for more information." >&2
    exit 1
fi

if test -z "$ABSFUSER"; then
    echo "Sourceforge SSH user name not specified, defaulting to $USER."
    echo "Use 'echo ABSFUSER=joe > $HOME/.ab-sf' to change."
fi

ABSFUSER=${ABSFUSER:-$USER}
FILES="$@"

rsync -a -e ssh $VERBOSE $FILES $ABSFUSER@cf-shell.sf.net:
