#!/bin/sh

# Copyright (C) 2004, 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.6 $'
rcs_version=`set - $rcs_revision; echo $2`
program=`echo $0 | sed -e 's!.*/!!'`
version="abput (autobuild) $rcs_version

Copyright (C) 2004 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 -s SYSTEM [OPTION]... FILES...

Upload FILES to build platforms.

Options:
  -s, --system SYSTEM  Upload file to specified system.  Multiple uses valid.
                       Abput will invoke the command \"abput-SYSTEM\"
                       for the SYSTEM specified here.  Available
                       systems include \"sourceforge\".
  -v, --verbose        Produce verbose output.
  -h, --help           Display this help and exit successfully.
      --version        Display version information and exit successfully. 

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

For details on each system, invoke the system specific script directly:
  $prog-sourceforge --help

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

while test $# -gt 0; do
  case $1 in
    -v) VERBOSE=t;;
    -h) echo "$usage"; exit 0;;
    --help) echo "$usage"; exit 0;;
    --version) echo "$version"; exit 0;;
    -s) shift; SYSTEMS="$SYSTEMS $1";;
    --system) shift; SYSTEMS="$SYSTEMS $1";;
    -*)
      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 "$usage"
    exit 0
fi

if test -z "$SYSTEMS"; then
    echo "$0: Missing --system parameter." >&2
    echo "$0: Try \`--help' for more information." >&2
    exit 1
fi

while test $# -gt 0; do
    FILE="$1"
    shift

    if test ! -f "$FILE"; then
	echo "$0: No such file \`$FILE'." >&2
	continue;
    fi

    for system in $SYSTEMS; do
	test -z "$VERBOSE" || echo "Invoking \`abput-$system $FILE'..."
	abput-$system "$FILE"
	test -z "$VERBOSE" || echo "Command returned exit code $?..."
    done
done
