#!/usr/bin/perl --
# Automatic PGP encryption/decryption (mainly for emacs).
# Copyright (C) 1993 Ian Jackson.

# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# It is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with GNU Emacs; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
# chop($ENV{'PGPPATH'}=`pwd`) unless length($ENV{'PGPPATH'});
$ENV{'PGPPATH'}=$ENV{'HOME'}."/.pgp" unless length($ENV{'PGPPATH'});
$config_pgppath= $ENV{'PGPPATH'};
$config_wrapperdir=	"$config_pgppath/.wrapper";
$config_socketname=	"pass-socket";
$config_allkeys=	"$config_pgppath/public-keys.pgp";
# $config_l_bindir=	"/usr/local/bin";
$config_l_bindir=	"/usr/bin"; # for Debian
$config_execuser=	'root';
$config_execgroup=	'root';
$config_execmode=	'755';
# $config_l_emacs=	"/usr/local/emacs"; # for Emacs 18
# $config_l_emacs=	"/usr/local/lib/emacs"; # for Emacs 19
$config_l_emacs=	"/usr/share/emacs/site-lisp"; # for Debian
$config_lispuser=	'root';
$config_lispgroup=	'root';
$config_lispmode=	'644';
# $config_i_info=	"$config_l_emacs/info/auto-pgp.info"; # for Emacs 18
# $config_i_info=	"/usr/local/info/auto-pgp.info"; # for Emacs 19
$config_i_info=		"/usr/share/info/auto-pgp.info"; # for Debian
$config_infouser=	'root';
$config_infogroup=	'root';
$config_infomode=	'644';
$config_lisp=		"auto-pgp";
# $config_i_lisp=	"$config_l_emacs/lisp/$config_lisp.el"; # for Emacs 18
# $config_i_lisp=	"$config_l_emacs/site-lisp/$config_lisp.el"; # 19
$config_i_lisp=	"$config_l_emacs/$config_lisp.el"; # for Debian
#$config_i_mandir=	"/usr/local/man/man1";
$config_i_mandir=	"/usr/share/man/man1"; # for Debian
$config_i_manext=	"1";
$config_manuser=	'root';
$config_mangroup=	'root';
$config_manmode=	'644';
$config_x_normalpgp=	"pgp";
$config_l_pgpauto=	"pgp-auto";
$config_i_pgpauto=	"$config_l_bindir/$config_l_pgpauto";
$config_x_pgpauto=	"$config_l_pgpauto"; # or perhaps $config_i_pgpauto
$config_l_decrypt=	"pgp-decrypt";
$config_i_decrypt=	"$config_l_bindir/$config_l_decrypt";
$config_x_decrypt=	"$config_l_decrypt"; # or perhaps $config_i_decrypt
$config_l_ringsearch=	"pgp-ringsearch";
$config_i_ringsearch=	"$config_l_bindir/$config_l_ringsearch";
$config_x_ringsearch=	"$config_l_ringsearch"; # or perhaps $config_i_ringsearch
$config_l_pixie=	"pgp-pixie";
$config_i_pixie=	"$config_l_bindir/$config_l_pixie";
$config_x_pixie=	"$config_l_pixie"; # or perhaps $config_i_pixie
# Usage:
#  pgp-auto ... pgp options ...
# Supplies passphrase (from pixie) to PGP.

# This file is COPYRIGHT - see notice above or file COPYRIGHT
# in this directory.

#require 'sys/socket.ph';
use Socket; # updated for perl 5 in Debian Linux

$path= "$config_wrapperdir/$config_socketname";

unless (defined($ENV{'PGPPASS'})) {
    socket(S, &AF_UNIX, &SOCK_STREAM, 0)
        || die "$0: create unix-domain socket: $!\n";
    connect(S,pack('S',&AF_UNIX).$path)
        || die "$0: connect to pass-socket for passphrase: $!\n";
    $ENV{'PGPPASSFD'}= fileno(S);
}

exec $config_x_normalpgp,@ARGV;
die "$0: exec $config_x_normalpgp: $!\n";
