#!/bin/sh

#    malsync-prc-install: fetch and install AvantGo .prc on the Palm
#    Copyright (C) 2002, Ludovic Rousseau <ludovic.rousseau@free.fr>
#
#    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

set -e

FILE=avgo42.tgz
URL=http://www.tomw.org/malsync/
TMP=/tmp/jpilot-syncmal-prc-install.$$
PRCS="avgo42/*.prc"

bad=0
if [ ! -x /usr/bin/wget ]
then
	echo "Error: You must install wget (wget package) to use this script!"
	bad=1
fi

if [ ! -x /usr/bin/pilot-xfer ]
then
	echo "Error: You must install pilot-xfer (pilot-link package) to use this script!"
	bad=1
fi

if [ $bad -ne 0 ]
then
	exit
fi

# remove temporary files in case of premature exit (Ctrl-C)
clean_exit()
{
	echo
	rm -rf $TMP
}

trap clean_exit SIGINT

case "$1" in
	"-v"|"--version")
		echo "malsync-prc-install: fetch and install AvantGo .prc on the Palm"
		echo "Version 1.1, October 2003"
		echo "Copyright (C) 2002, Ludovic Rousseau <ludovic.rousseau@free.fr>"
		echo "This program is protected by the GNU GPL version 2 of later"
		exit
	;;

	"-5")
		FILE=avgo52.tgz
		PRCS="AvantGo52/*.prc"
	;;

	?*)
		echo "Usage: $0 [-5] [-h] [--help] [-v] [--version]"
		echo " -5: install AvantGo 5.2 for PalmOS 5.x"
		echo "     instead of default AvantGo 4.2 for PalmOS < 5.0"
		exit
	;;
esac

mkdir $TMP
cd $TMP

wget $URL/$FILE
tar xzvf $FILE

echo "Will install " $PRCS

pilot-xfer -i $PRCS

rm -rf $TMP

