#!/usr/bin/perl

package keyparty_addkey;

### Configuration

# only real configuration option, everything else can be overridden by plugins
# where are the plugins?
$plugin_dir = "/home/stefan/dev/keyparty/addkey_plugins";

use vars qw! $plugin_dir @plugins $keyfile @newkeys!;
use strict;
use utf8;

require "common.pl";
$keyfile = shift;


@plugins = keyparty_common::load_plugins($plugin_dir);

#allow plugins to override or create configuration settings
#keyparty_common::run_plugins_configure(@plugins);

# calculate path and file names from configuration
keyparty_common::calc_paths();

@newkeys = ();
my @import_output = qx! gpg --keyring $keyparty_common::event_keyring --no-default-keyring --import --batch --yes $keyfile --display-charset utf-8 --no-options 2>&1!;
foreach my $line (@import_output) {
    if (my ($id, $name) = $line =~ /key ([0-9A-F]+): public key "([^"]+)" imported/) {
        push @newkeys, {id => $id, name => $name};
    }
}

# allow plugins to do something after the keyring has been updated but
# not exported, yet
keyparty_common::run_plugins("pre_export", @plugins);

keyparty_common::export_keys();

# allow plugins to something after we've done all other stuff
keyparty_common::run_plugins("postprocess", @plugins);

