5c001e4
#!/usr/bin/sh
Rex Dieter e4f740c
Rex Dieter e4f740c
# Copyright (c) 2006 SUSE LINUX Products GmbH, Nuernberg, Germany.
Rex Dieter e4f740c
# Copyright (c) 2009 Fedora Project
3a12e82
# Copyright (c) 2014-2015 Red Hat
Rex Dieter e4f740c
# This file and all modifications and additions to the pristine
Rex Dieter e4f740c
# package are under the same license as the package itself.
Rex Dieter e4f740c
#
Rex Dieter e4f740c
# Please submit bugfixes or comments via http://bugzilla.redhat.com/
Rex Dieter e4f740c
#
Rex Dieter e4f740c
# Anna Bernathova <anicka@novell.com> 2006
Rex Dieter e4f740c
# Pavel Nemec <pnemec@novell.com> 2006
Rex Dieter e4f740c
# Rex Dieter <rdieter@fedoraproject.org> 2009
Rex Dieter e4f740c
# Pavol Rusnak <prusnak@novell.com> 2009
Rex Dieter e4f740c
# Boris Ranto <branto@redhat.com> 2014
Rex Dieter e4f740c
#
38bb0af
# use proper binary (pinentry-qt, pinentry-gnome, pinentry-gtk-2 or pinentry-curses)
Rex Dieter e4f740c
Rex Dieter e4f740c
kde_running=
Rex Dieter e4f740c
arg=
Rex Dieter e4f740c
display=
Rex Dieter e4f740c
# look for a --display option
Rex Dieter e4f740c
for opt in "$@"; do
Rex Dieter e4f740c
    if [ "$opt" = "--display" ]; then
Rex Dieter e4f740c
        arg=1
Rex Dieter e4f740c
    elif [ -n "$arg" ]; then
Rex Dieter e4f740c
        display="$opt"
Rex Dieter e4f740c
    else
Rex Dieter e4f740c
        arg=
Rex Dieter e4f740c
    fi
Rex Dieter e4f740c
done
Rex Dieter e4f740c
Rex Dieter e4f740c
# export DISPLAY if pinentry is meant to be run on a different display
Rex Dieter e4f740c
# check the KDE_FULL_SESSION variable otherwise
caf43c1
if [ -n "$display" ] && [ "$DISPLAY" != "$display" ]; then
Rex Dieter e4f740c
    export DISPLAY="$display"
Rex Dieter e4f740c
elif [ -n "$KDE_FULL_SESSION" ]; then
Rex Dieter e4f740c
    kde_running=1
Rex Dieter e4f740c
fi
Rex Dieter e4f740c
Rex Dieter e4f740c
# Check for presence of xprop binary
Rex Dieter e4f740c
type xprop >/dev/null 2>/dev/null
Rex Dieter e4f740c
XPROP=$?
Rex Dieter e4f740c
caf43c1
if [ -n "$DISPLAY" ] && [ $XPROP -eq 0 ]; then
Rex Dieter e4f740c
    xprop -root | grep "^KDE_FULL_SESSION" >/dev/null 2>/dev/null
Rex Dieter e4f740c
    if test $? -eq 0; then
Rex Dieter e4f740c
        kde_running=1
Rex Dieter e4f740c
    fi
Rex Dieter e4f740c
fi
Rex Dieter e4f740c
Rex Dieter e4f740c
# if a user supplied a pinentry binary, use it
Rex Dieter e4f740c
if [ -n "$PINENTRY_BINARY" ];
Rex Dieter e4f740c
then
Rex Dieter e4f740c
	export PINENTRY_BINARY="$PINENTRY_BINARY"
Rex Dieter e4f740c
# if KDE is detected and pinentry-qt exists, use pinentry-qt
caf43c1
elif [ -n "$kde_running" ] && [ -x /usr/bin/pinentry-qt ]
Rex Dieter e4f740c
then
Rex Dieter e4f740c
	export PINENTRY_BINARY="/usr/bin/pinentry-qt"
3a12e82
# otherwise test if pinentry-gnome3 is installed
caf43c1
elif [ -n "$DISPLAY" ] && [ -x /usr/bin/pinentry-gnome3 ]
3a12e82
then
3a12e82
	export PINENTRY_BINARY="/usr/bin/pinentry-gnome3"
Rex Dieter e4f740c
# otherwise test if pinentry-gtk-2 is installed
caf43c1
elif [ -n "$DISPLAY" ] && [ -x /usr/bin/pinentry-gtk-2 ]
Rex Dieter e4f740c
then
Rex Dieter e4f740c
	export PINENTRY_BINARY="/usr/bin/pinentry-gtk-2"
Rex Dieter e4f740c
# otherwise test if pinentry-qt exists although KDE is not detected
caf43c1
elif [ -n "$DISPLAY" ] && [ -x /usr/bin/pinentry-qt ]
Rex Dieter e4f740c
then
Rex Dieter e4f740c
	export PINENTRY_BINARY="/usr/bin/pinentry-qt"
b8e3599
# use pinentry-tty if installed
b8e3599
elif [ -x /usr/bin/pinentry-tty ]
5c001e4
then
5c001e4
	export PINENTRY_BINARY="/usr/bin/pinentry-tty"
b8e3599
# pinentry-curses is installed by default
b8e3599
else
b8e3599
	export PINENTRY_BINARY="/usr/bin/pinentry-curses"
Rex Dieter e4f740c
fi
Rex Dieter e4f740c
exec $PINENTRY_BINARY "$@"