File pinentry of Package pinentry

#!/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
# Pavol Rusnak <prusnak@novell.com> 2009
#
# use proper binary (pinentry-qt4, pinentry-qt, pinentry-gtk-2 or pinentry-curses)

kde_running=
if [ -n "$KDE_FULL_SESSION" ]; then
    kde_running=1
    kde_ver="$KDE_SESSION_VERSION"
elif [ -n "$DISPLAY" ]; then
    xprop -root | grep "^KDE_FULL_SESSION" >/dev/null 2>/dev/null
    if test $? -eq 0; then
        kde_running=1
        kde_ver="`xprop -root | sed -n 's/KDE_SESSION_VERSION(CARDINAL) = //p'`" 2>/dev/null
    fi
else
    arg=
    display=
    for opt in "$@"; do
        if [ "$opt" = "--display" ]; then
            arg=1
        elif [ -n "$arg" ]; then
            display="$opt"
        else
            arg=
        fi
    done
    if [ -n "$display" ]; then
        DISPLAY="$display" xprop -root | grep "^KDE_FULL_SESSION" >/dev/null 2>/dev/null
        if test $? -eq 0; then
            kde_running=1
            kde_ver="`DISPLAY="$display" xprop -root | sed -n 's/KDE_SESSION_VERSION(CARDINAL) = //p'`" 2>/dev/null
        fi
    fi
fi

# if KDE is detected and pinentry-qt4 exists, use pinentry-qt4
if [ -n "$kde_running" -a "$kde_ver"x = 4x -a -f /usr/bin/pinentry-qt4 ]
then
	export PINENTRY_BINARY="/usr/bin/pinentry-qt4"
# if KDE is detected and pinentry-qt exists, use pinentry-qt
elif [ -n "$kde_running" -a -f /usr/bin/pinentry-qt ]
then
	export PINENTRY_BINARY="/usr/bin/pinentry-qt"
# otherwise test if pinentry-gtk-2 is installed
elif [ -n "$DISPLAY" -a -f /usr/bin/pinentry-gtk-2 ]
then
	export PINENTRY_BINARY="/usr/bin/pinentry-gtk-2"
# otherwise test if pinentry-qt4 exists although KDE is not detected
elif [ -n "$DISPLAY" -a -f /usr/bin/pinentry-qt4 ]
then
	export PINENTRY_BINARY="/usr/bin/pinentry-qt4"
# otherwise test if pinentry-qt exists although KDE is not detected
elif [ -n "$DISPLAY" -a -f /usr/bin/pinentry-qt ]
then
	export PINENTRY_BINARY="/usr/bin/pinentry-qt"
# pinentry-curses is installed by default
else
	export PINENTRY_BINARY="/usr/bin/pinentry-curses"
fi
exec $PINENTRY_BINARY "$@"
openSUSE Build Service is sponsored by