#!/bin/bash
# -*- mode: sh; tab-width: 8; encoding: utf-8-unix -*-

prog=`basename $0 .bash`
PREFIX=/usr/local
ROLE=gpgkey

. /usr/local/bin/gridfire.rc

declare -a ELTS LARGS RARGS
ELTS=(
    gridfire_ansible-vault.sh
    gridfire_keepassxc-cli.sh
    gridfire_keepassxc.sh
    gridfire_keyring.sh
    gridfire_openssl.sh
    gridfire_secret-tool.sh
    gridfire_staticgpg.sh
    gridfire_truecrypt.sh
    gridfire_veracrypt.sh
)
SHORTOPTS="ha:cgulbodfpwm:nv:s:D:P:H:A:"

OARGS="$@"
ARGS=$(getopt --options $SHORTOPTS  -- "$@")
[ $? != 0 ] && error 2 "Aborting."
eval set -- "$ARGS"

while true; do
    case "$1" in
	-h|-c|-g|-u|-l|-b|-o|-d|-f|-p|-w|-n)
	    LARGS+=($1)
	    shift;;
	-a|-m|-v|-s|-D|-P|-H|-A)
	    LARGS+=($1)
	    shift
	    LARGS+=($1)
	    shift;;
        '--')
            shift
            RARGS=("$@")
            break
            ;;
      esac

done
#echo DEBUG: LARGS ${LARGS[@]}
#echo DEBUG: RARGS ${RARGS[@]}
case  ${RARGS[0]} in
    ansible-vault|keepassxc-cli|keepassxc|keyring|openssl|secret-tool|staticgpg|truecrypt|veracrypt|foo)
	elt=gridfire_${RARGS[0]}.bash
	unset ${RARGS[0]}
	RARGS[0]=""
	exec bash $elt ${LARGS[@]} ${RARGS[@]}
        ;;
      esac
# echo ${RARGS[@]}

exec python3.sh $PREFIX/src/gridfire/gridfire.py "$OARGS"
