#!/bin/bash

if [ "x$WGETRC" != "x" ] ; then

    wgetrc_dir=${WGETRC%/*}

    which_wget=`which wget`
    wget_dir=${which_wget%/*}

    if [ $wgetrc_dir != $wget_dir ] ; then
	echo "+--------" >&2
	echo "+ Located wget is not the Greenstone one" >&2
	echo "+ Temporarily setting:"                   >&2
	echo "+     WGETRC=$WGETRC"                     >&2
	echo "+ to be empty"                            >&2
	echo "+--------" >&2
	export WGETRC=
    fi
fi

echo "GS2 Extensions: "

command -v wget >/dev/null
wget_status=$?

command -v curl >/dev/null
curl_status=$?

if [ $wget_status = 0 ] ; then
  wget --no-check-certificate -q -O - https://svn.greenstone.org/main/trunk/gs2-extensions/ | \
    grep '<li>' | \
    sed 's/^.*href="\(.*\)\/".*$/  \1/' |
    grep -v '\.\.'
#     tr '\n' ' '    

elif [ $curl_status = 0 ] ; then
  curl -s https://svn.greenstone.org/main/trunk/gs2-extensions/ | \
    grep '<li>' | \
    sed 's/^.*href="\(.*\)\/".*$/  \1/' |
    grep -v '\.\.'
  #     tr '\n' ' '
  
else
    echo "Error: Failed to find either 'wget' or 'curl' to download list of extensions from Greenstone svn server" >&2
    exit 1
fi





