create caff configfile on first use
authormyon-guest <myon-guest@b513b33f-fedd-0310-b452-c3deb5f4c849>
Sun, 7 Aug 2005 20:25:17 +0000 (20:25 +0000)
committermyon-guest <myon-guest@b513b33f-fedd-0310-b452-c3deb5f4c849>
Sun, 7 Aug 2005 20:25:17 +0000 (20:25 +0000)
git-svn-id: svn://svn.debian.org/pgp-tools/trunk@160 b513b33f-fedd-0310-b452-c3deb5f4c849

caff/caff
debian/changelog

index 02569f5d6e8ec01d6bfc119f0950c9f2bc4a7512..35be431932aa20e283b390fb3599820552896a9b 100755 (executable)
--- a/caff/caff
+++ b/caff/caff
@@ -266,9 +266,62 @@ my $REVISION = '$Rev$';
 my ($REVISION_NUMER) = $REVISION =~ /(\d+)/;
 my $VERSION = "0.0.0.$REVISION_NUMER";
 
+sub generate_config() {
+       die "Error: \$LOGNAME is not set.\n" unless $ENV{LOGNAME};
+       my $gecos = (getpwnam($ENV{LOGNAME}))[6];
+       $gecos =~ s/,.*//;
+
+       my $gpg = GnuPG::Interface->new();
+       $gpg->call( 'gpg' );
+       $gpg->options->hash_init(
+               'extra_args' => [ qw{ --no-auto-check-trustdb --trust-model=always --with-colons --fixed-list-mode } ] );
+       $gpg->options->meta_interactive( 0 );
+       my ($inputfd, $stdoutfd, $stderrfd, $statusfd, $handles) = make_gpg_fds();
+       my $pid = $gpg->list_public_keys(handles => $handles, command_args => [ $gecos ]);
+       my ($stdout, $stderr, $status) = readwrite_gpg('', $inputfd, $stdoutfd, $stderrfd, $statusfd);
+       waitpid $pid, 0;
+
+       if ($stdout eq '') {
+               warn ("No data from gpg for list-key\n"); # There should be at least 'tru:' everywhere.
+       };
+
+       my @keys;
+       unless (@keys = ($stdout =~ /^pub:[^r:]*:(?:[^:]*:){2,2}([^:]+):/mg)) {
+               die "Error: No keys were found using \"gpg --list-public-keys '$gecos'\".\n";
+       }
+       unless ($stdout =~ /^uid:.*<(.+@.+)>.*:/m) {
+               die "Error: No email address was found using \"gpg --list-public-keys '$gecos'\".\n";
+       }
+       my $email = $1;
+
+       return <<EOT;
+# .caffrc -- vim:syntax=perl:
+# This file is in perl(1) format - see caff(1) for details.
+
+\$CONFIG{'owner'}       = '$gecos';
+\$CONFIG{'email'}       = '$email';
+
+# you can get your long keyid from
+#   gpg --with-colons --list-key <yourkeyid|name|emailaddress..>
+#
+# if you have a v4 key, it will simply be the last 16 digits of
+# your fingerprint.
+
+\$CONFIG{'keyid'}       = [ qw{@keys} ];
+EOT
+};
+
 sub load_config() {
        my $config = $ENV{'HOME'} . '/.caffrc';
-       -f $config or die "No file $config present.  See caff(1).\n";
+       unless (-f $config) {
+               print "No configfile $config present, I will use this template:\n";
+               my $template = generate_config();
+               print "$template\nPress enter to continue.";
+               <STDIN>;
+               open F, ">$config" or die "$config: $!";
+               print F $template;
+               close F;
+       }
        unless (scalar eval `cat $config`) {
                die "Couldn't parse $config: $EVAL_ERROR\n" if $EVAL_ERROR;
        };
index 39e7bcc15c3c1c0eb1af9339c007ecfbbb0dab92..772434cd8b2ccb18624f9c1a103d6680eeedf838 100644 (file)
@@ -1,3 +1,10 @@
+signing-party (0.4.1-2) unstable; urgency=low
+
+  * caff:
+     + create configfile on first use (Closes: #316611).
+
+ -- Christoph Berg <cb@df7cb.de>  Sun,  7 Aug 2005 22:23:43 +0200
+
 signing-party (0.4.1-1) unstable; urgency=low
 
   * New upstream release. Lots of fixes and enhancements, including: