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