gonito/helpers/gitolite/get_keys.pl

31 lines
657 B
Perl
Raw Normal View History

2019-11-24 14:39:33 +01:00
#!/usr/bin/perl
use strict;
use DBI;
my $dbh = DBI->connect("dbi:Pg:dbname=gonito", "", "");
my $sh = $dbh->prepare(qq{SELECT * FROM "user" U, public_key K WHERE U.id = K.user and U.id >= 40});
$sh->execute();
while (my $key = $sh->fetchrow_hashref()) {
my $local_id = $key->{'local_id'};
my $pkey = $key->{'pubkey'};
if ($pkey =~ /PRIVATE/) {
print STDERR "$local_id has private key!\n";
} elsif (! defined($local_id) && $local_id !~ /\S/) {
print STDERR "not defined local_id\n";
} else {
2022-01-15 16:51:13 +01:00
if ($pkey !~ /^ssh-/) {
2019-11-24 14:39:33 +01:00
$pkey = 'ssh-rsa ' . $pkey;
}
open my $fh, '>', $local_id.".pub";
print $fh $pkey;
close $fh;
}
}