* keylookup:
[pgp-tools.git] / keylookup / keylookup
index 115578015469f31b7219fa000d7724cd05fdb2d5..a8754d3f48fffcc87c3e24679d4c3c044cffd819 100755 (executable)
 #
 #   You should have received a copy of the GNU General Public License
 #   along with this program; if not, write to the Free Software Foundation,
-#   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#   Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 #
 # Keylookup is part of pgp-tools:
 #           http://pgp-tools.alioth.debian.org/
 #           svn://svn.debian.org/pgp-tools/trunk/
 #           http://svn.debian.org/wsvn/pgp-tools/trunk/
 
-delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV', 'PATH'};
+delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
 $|=1; # Always flush buffers
 
 
@@ -35,11 +35,6 @@ use Getopt::Long;
 
 my $version = '3.0 ($Id$)';
 
-# Where to find GnuPG's options file.
-# Full path to the dialog and whiptail executeable.
-my $Dialog = '/usr/bin/dialog';
-my $Whiptail = '/usr/bin/whiptail';
-
 # Strings to use in the dialog|whiptail frontend
 my $TITLE = 'Import Keys';
 my $BACKTITLE = 'KeyLookup $Revision$';
@@ -104,6 +99,7 @@ sub getHits($) {
 
        while (<KID>) {
                chomp;
+               if ( $_ eq "" ) { next; }
                my ($type, undef) = split /:/;
                if ($type eq 'pub') {
                        my ($type, $keyid, $algo, $bits, $created, undef, $revoked) = split /:/;
@@ -232,14 +228,14 @@ sub selectKeys {
        $frontend = 'dialog' unless (defined $frontend);
 
        if ($frontend eq 'dialog') {
-               unless (-x $Dialog) {
-                       warn("Dialog ($Dialog) not executeable/installed. Falling back to Whiptail\n");
+               unless (`which dialog` && $? == 0) {
+                       warn("Dialog not executeable/installed. Falling back to Whiptail\n");
                        $frontend = 'whiptail';
                }
        };
        if ($frontend eq 'whiptail') {
-               unless (-x $Whiptail ) {
-                       warn("Whiptail ($Whiptail) not executeable/installed. Falling back to plain\n");
+               unless (`which whiptail` && $? == 0 ) {
+                       warn("Whiptail not executeable/installed. Falling back to plain\n");
                        $frontend = 'plain';
                }
        };
@@ -247,7 +243,7 @@ sub selectKeys {
        if ( $frontend eq 'dialog' ) {
                calcDialogSize;
                my @ARGS = (
-                       $Dialog,
+                       'dialog',
                        '--backtitle',
                        $BACKTITLE,
                        '--separate-output',
@@ -261,7 +257,7 @@ sub selectKeys {
        } elsif ( $frontend eq 'whiptail' ) {
                calcDialogSize;
                my @ARGS = (
-                       $Whiptail,
+                       'whiptail',
                        '--backtitle',
                        $BACKTITLE,
                        '--separate-output',
@@ -349,6 +345,10 @@ sub version {
        my $keys = getHits( \%options );
        my $keyids;
 
+       if (scalar keys %$keys == 0) {
+               print "GnuPG did not find any keys matching your search string.\n";
+               exit 0;
+       };
        if ($options{'importall'}) {
                my @allkeys = keys %$keys;
                $keyids = \@allkeys;