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

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

. /usr/local/bin/usr_local_tput.bash || exit 2

if [ "$#" -eq 0 ] ; then
    echo USAGE: $0 [options]
    cat << EOF
USAGE:
  --password PASSWORD   Database password.
  --password-command PW_CMD
                        Password will be obtained from the output of this
                        command.
  --keyfile KEYFILE     Key file for unlocking database.
  --pinentry PINENTRY   Command used to run pinentry.
  -c COMMAND, --command COMMAND
                        Command to execute. If command arguments contain
                        spaces, they must be enclosed in double quotes. With
                        this switch, kpsh will be started in non-interactive
                        mode. A list of available commands can be found by
                        running 'kpsh -c help':
  {open,unlock,lock,db,ls,show,add,edit,delete,move,autotype,exit,echo,sleep,help}
    open                Change currently opened database.
    unlock              Unlock currently opened database.
    lock                Lock a database.
    db                  Query opened database info.
    ls                  List contents of database.
    show                Show contents of entry.
    add                 Add a new entry if it doesn't exist yet.
    edit                Edit existing entry
    delete              Delete entry from database
    move                Move entry to the new path.
    autotype            Auto-type sequence of entry fields.
    exit                Exit shell.
    echo                Display a message.
    sleep               Sleep for a given number of seconds.

  --prompt PROMPT       Text used by shell for prompt.
  -d, --daemon          Start as a daemon listening on a socket given by
                        --socket-path
  -s SOCKET_PATH, --socket-path SOCKET_PATH
                        Path to the socket which will be created in daemon
                        mode (default: /tmp/kpsh-$UID.sock).

USAGE: $0  -- kpsh-args
`basename $0` arguments go before the -- kpsh args go after

EOF
    exit 1
  fi

# FixMe: nonewline
exec $PREFIX/bin/gridfire -H "kpsh password on stdin" --stdin -- \
     kpsh "$@"
