#! /bin/bash

# savannah_helper
# Copyright (C) 2004 Patrick Deschenes (patrickd@aei.ca)
#
# 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 2
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


# Commands
    # create - create a GPG key
    # upload - upload a file or a directory using the login/projectname
    # 

function savannah_create ()
{
    gpg --gen-key
    gpg --output gpgkey.txt --armor --export \<$1\>

    echo "Set the contain of the file 'gpgkey.txt' at this location"
    echo "    https://savannah.gnu.org/$1/change.php?item=gpgkey"
}

function savannah_upload ()
{
  echo "uploading '$2'"
  echo "...detaching the signature"
  gpg -b --yes -q $2
  echo "...uploading the file"

  ftp -n savannah.gnu.org <<End-Of-Session
  user anonymous
  binary
  cd /incoming/savannah/$1 
  put $2
  put $2.sig
  bye
End-Of-Session
  
  echo "...result can be see at (http://savannah.nongnu.org/download/$1"
  echo "...finished (please wait about 5 minutes)"
}

echo ""
echo "Savannah helper"
echo "---------------"
echo ""

if [ "$1" == "create" ]; then
    savannah_create $2
    exit
fi

if [ "$1" == "upload" ]; then
    savannah_upload $2 $3
    exit
fi

echo "savannah usage:"
echo "   savannah create <email>"
echo "   savannah upload <project-name> <file>"
echo ""





