35 lines
896 B
Perl
Executable file
35 lines
896 B
Perl
Executable file
#!/usr/bin/env perl
|
|
|
|
use strict;
|
|
use warnings;
|
|
use 5.010;
|
|
use LWP::UserAgent;
|
|
use HTTP::Request::Common qw(POST);
|
|
|
|
# Check for command line arguments
|
|
if (@ARGV != 2) {
|
|
die "Usage: perl upload_key.pl <key_file.asc> <keyserver_url>\n";
|
|
}
|
|
|
|
my ($key_file, $keyserver_url) = @ARGV;
|
|
|
|
# Read the armored key file
|
|
open my $fh, '<', $key_file or die "Could not open '$key_file': $!";
|
|
my $key_text = do { local $/; <$fh> }; # Read the entire file
|
|
close $fh;
|
|
|
|
# Create a user agent
|
|
my $ua = LWP::UserAgent->new;
|
|
|
|
# Prepare the POST request
|
|
my $request = POST $keyserver_url, Content => [ keytext => $key_text ];
|
|
|
|
# Send the request
|
|
my $response = $ua->request($request);
|
|
|
|
# Check the response
|
|
if ($response->is_success) {
|
|
say "Key uploaded successfully: " . $response->decoded_content . "\n";
|
|
} else {
|
|
die "Failed to upload key: " . $response->status_line . "\n\n" . $response->decoded_content . "\n";
|
|
}
|