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