#!/bin/sh

# Copyright (c) 2006 SUSE LINUX Products GmbH, Nuernberg, Germany.
# This file and all modifications and additions to the pristine
# package are under the same license as the package itself.
#
# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
# Anna Bernathova <anicka@novell.com> 2006
# Pavel Nemec <pnemec@novell.com> 2006
# 
# use proper binary (pinentry-qt, pinentry-gtk-2 or pinentry-curses) 

# if KDE is detected and pinentry-qt exists, use pinentry-qt
if [ "x${KDE_FULL_SESSION}" = "xtrue" -a -f /usr/bin/pinentry-qt ]
then
	export PINENTRY_BINARY="/usr/bin/pinentry-qt"
# otherwise test if pinentry-gtk-2 is installed
elif [ -f /usr/bin/pinentry-gtk-2 ] 
then
	export PINENTRY_BINARY="/usr/bin/pinentry-gtk-2"
# otherwise test if pinentry-qt exists although KDE is not detected
elif [ -f /usr/bin/pinentry-qt ]
then
	export PINENTRY_BINARY="/usr/bin/pinentry-qt"
# pinentry-curses is installed by default 
else
	#test if gui binary is required
	for opt in "$@"; do
		if [ "x$opt" = "x--display" ]; then
		        # should not happen because of package dependencies
			echo "Please install pinentry-qt or pinentry-gtk2" >&2
			exit 1
		fi
	done
	export PINENTRY_BINARY="/usr/bin/pinentry-curses"
		
fi
exec $PINENTRY_BINARY "$@"
