#!/usr/bin/env bash
#
# Copyright (C) 2003 VA Linux Systems Japan, K.K. All rights reserved.
#
# LICENSE NOTICE
#
#  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.
#

set -e

usage() {
  echo "$0 protocol|provider [<protocol>...]" 1>&2
  exit 1
}

case "x$1" in
  xprotocol)
    ultrapossum-config variable | grep _PROVIDER | cut -d_ -f1 | tr A-Z a-z
    ;;
  xprovider)
    eval `ultrapossum-config init`
    trap "eval `ultrapossum-config term`" 0

    if test "x$2" != "x"; then
      shift
      ss="$@"
    else
      ss=`$0 protocol`
    fi
    for s in $ss
    do
      v="`echo $s | tr 'a-z' 'A-Z'`_PROVIDER"
      echo "$v=\"${!v}\""
    done
    ;;
  x*)
    usage
    exit 1
    ;;
esac


