commit 33e26eda296de2233a05585ae36f991161371d1d
parent 58278bd5567ea7ae3efa53ba49dc84f5b94a8520
Author: lash <dev@holbrook.no>
Date: Wed, 19 Jun 2024 19:07:17 +0100
WIP genconfig script and input validation
Diffstat:
5 files changed, 143 insertions(+), 24 deletions(-)
diff --git a/Bluto.pm b/Bluto.pm
@@ -34,6 +34,71 @@ my %m_main = (
);
my $have_version_match = undef;
+sub _set_single {
+ my $cfg = shift;
+ my $cfg_k = shift;
+ my $main_k = shift;
+ my $need = shift;
+
+ my $v = $cfg->param($cfg_k);
+ if (ref($v) eq 'ARRAY') {
+ if ($#v < 0) {
+ debug('empty value not set: ' . $cfg_k);
+ $v = undef;
+ }
+ }
+
+ if ($need && !defined $v) {
+ error('required config key not set: ' . $cfg_k);
+ return 1;
+ }
+
+ $m_main{$main_k} = $v;
+
+ return 0;
+}
+
+sub _set_author {
+ my $cfg = shift;
+ my $k = shift;
+ my $need = shift;
+ my $name;
+ my $email;
+ my $pgp;
+
+ my $cfg_k = 'author:' . $k;
+ my $v = $cfg->param($cfg_k . '.name');
+ # TODO if if if...
+ if (defined $v) {
+ $name = $cfg->param($cfg_k . '.name');
+ if (ref($name) eq 'ARRAY') {
+ $v = undef;
+ } else {
+ $email = $cfg->param($cfg_k . '.email');
+ if (ref($email) eq 'ARRAY') {
+ $email = undef;
+ }
+ $pgp = $cfg->param($cfg_k . '.pgp');
+ if (ref($pgp) eq 'ARRAY') {
+ $pgp = undef;
+ }
+ }
+ }
+
+ if ($need && !defined $v) {
+ error('required author data not set: ' . $cfg_k);
+ return 1;
+ }
+
+ $m_main{'author_' . $k}[0] = $name;
+ if (defined $email) {
+ $m_main{'author_' . $k}[1] = $name . ' <' . $email . '>';
+ }
+ $m_main{'author_' . $k}[2] = $pgp;
+
+ return 0;
+}
+
sub from_config {
my $cfg = shift;
my $env = shift;
@@ -50,30 +115,38 @@ sub from_config {
}
info('using version ' . $version);
- $m_main{name} = $cfg->param('main.name');
$m_main{version} = $version;
- $m_main{slug} = $cfg->param('main.slug');
- $m_main{summary} = $cfg->param('main.summary');
- $m_main{license} = $cfg->param('main.license');
- $m_main{url} = $cfg->param('main.url');
- $m_main{author_maintainer}[0] = $cfg->param('author:maintainer.name');
- $m_main{author_maintainer}[1] = $m_main{author_maintainer}[0] . " <" . $cfg->param('author:maintainer.email') . ">";
- $m_main{author_maintainer}[2] = $cfg->param('author:maintainer.pgp');
+ my $r = 0;
+ $r += _set_single($cfg, 'main.name', 'name', 1);
+ $r += _set_single($cfg, 'main.slug', 'slug', 1);
+ $r += _set_single($cfg, 'main.summary', 'summary', 1);
+ $r += _set_single($cfg, 'main.license', 'license', 1);
+ $r += _set_single($cfg, 'main.uri', 'uri', 1);
+ $r += _set_author($cfg, 'maintainer', 1);
+ if ($r) {
+ error('invalid configuration');
+ return undef;
+ }
+
+# $m_main{author_maintainer}[0] = $cfg->param('author:maintainer.name');
+# $m_main{author_maintainer}[1] = $m_main{author_maintainer}[0] . " <" . $cfg->param('author:maintainer.email') . ">";
+# $m_main{author_maintainer}[2] = $cfg->param('author:maintainer.pgp');
+#
my $feed_file = File::Spec->catfile( $feed_dir, $m_main{slug} ) . ".rss";
- if (!defined $cfg->param('author:origin')) {
- $m_main{author_origin}[0] = $m_main{author_maintainer}[0];
- $m_main{author_origin}[1] = $m_main{author_maintainer}[1];
- $m_main{author_origin}[2] = $m_main{author_maintainer}[2];
- }
+# if (!defined $cfg->param('author:origin')) {
+# $m_main{author_origin}[0] = $m_main{author_maintainer}[0];
+# $m_main{author_origin}[1] = $m_main{author_maintainer}[1];
+# $m_main{author_origin}[2] = $m_main{author_maintainer}[2];
+# }
if (defined $cfg->param('vcs.tag_prefix')) {
$m_main{tag_prefix} = $cfg->param('vcs.tag_prefix');
}
- foreach my $v ( $cfg->param('locate.url') ) {
+ foreach my $v ( $cfg->param('locate.www') ) {
warn('not checking url formatting for ' . $v);
push(@m_url, $v);
}
@@ -101,8 +174,9 @@ sub from_config {
return undef;
}
- my $targz = Bluto::Archive::create($m_main{slug}, $m_main{version}, $m_main{author_maintainer}[2], $m_main{tag_prefix}, $env->{src_dir});
+ my $targz = Bluto::Archive::create($m_main{slug}, $m_main{version}, $m_main{author_maintainer}[2], $m_main{tag_prefix}, $env->{src_dir}, 0);
if (!defined $targz) {
+ error('failed to generate archive');
return undef;
}
my @targz_stat = stat ( $targz );
@@ -149,6 +223,10 @@ sub from_config {
error('changelog content empty after exhausting all options');
}
+ for $k (keys %m_main) {
+ debug('release data: ' . $k . ': ' . $m_main{$k});
+ }
+
return $have_version_match;
}
diff --git a/Bluto/Archive.pm b/Bluto/Archive.pm
@@ -10,6 +10,14 @@ use Log::Term::Ansi qw/error info debug warn trace/;
sub seal {
my $targz = shift;
my $keygrip = shift;
+ my $safe = shift;
+
+ if (!defined $keygrip) {
+ if ($safe) {
+ error('have no signing key and safe bit set');
+ return undef;
+ }
+ }
my $h = Digest::SHA->new('sha256');
$h->addfile($targz);
@@ -21,6 +29,10 @@ sub seal {
print $f $z . "\t" . basename($targz) . "\n";
close($f);
+ if (!defined $keygrip) {
+ return $z;
+ }
+
my @cmd = ('gpg', '-a', '-b', '-u', $keygrip, $hp);
system(@cmd);
if ($?) {
@@ -38,6 +50,7 @@ sub create {
my $keygrip = shift;
my $git_prefix = shift;
my $src_dir = shift;
+ my $flags = shift;
my $old_dir = cwd;
@@ -46,7 +59,6 @@ sub create {
my $targz = $slug . '-' . $version . '.tar.gz';
my $targz_local = File::Spec->catfile($src_dir, $targz);
if (! -f $targz_local ) {
- #croak("no package file found, looked for: " . $targz);
debug("no package file found, looked for: " . $targz);
my @cmd = ('git', 'archive', $git_prefix . $version, '--format', 'tar.gz', '-o', $targz);
@@ -69,21 +81,18 @@ sub create {
return undef;
}
- my $seal = seal($targz_local, $keygrip);
+ my $seal = seal($targz_local, $keygrip, $flags & 1);
if (!defined $seal) {
error("failed sealing archive");
unlink($targz);
return undef;
}
info('sealed archive as sha256 ' . $seal . ' signed by ' . $keygrip);
-
} else {
info("using existing package file: " . $targz);
warn("existing package file is not being checked in any way 8|");
}
-
-
chdir($old_dir);
return $targz_local;
diff --git a/Bluto/RSS.pm b/Bluto/RSS.pm
@@ -43,7 +43,7 @@ sub process {
$rss = XML::RSS->new(version => '1.0');
$rss->channel (
title => $release->{name},
- link => $release->{url},
+ link => $release->{uri},
description => $release->{summary},
dc => {
date => DateTime->now()->stringify(),
@@ -71,8 +71,6 @@ sub process {
}
}
- debug('outs '. $release->{url});
-
$rss->add_item (
title => $rss_title,
link => $release->{src}[0],
diff --git a/genconfig.pl b/genconfig.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/env perl
+
+use Config::Simple;
+
+my @keys = (
+ 'main.name',
+ 'main.slug',
+ 'main.version',
+ 'main.summary',
+ 'main.license',
+ 'main.uri',
+ 'main.tech',
+ 'vcs.tag_prefix',
+ 'author:maintainer.name',
+ 'author:maintainer.email',
+ 'author:maintainer.pgp',
+ 'key.rsa',
+ 'key.ed25519',
+ 'key.secp256k1',
+ 'fund.btc',
+ 'fund.eth',
+ 'fund.monero',
+ 'locate.www',
+ 'locate.vcs',
+ 'locate.tgzbase',
+);
+
+my $cfg = new Config::Simple(syntax=>'ini');
+for my $k ( @keys ) {
+ $cfg->param($k, '');
+}
+
+$cfg->param('changelog.0.0.0-alpha.1', '');
+
+print $cfg->as_string;
diff --git a/to_std.pl b/to_std.pl
@@ -53,7 +53,6 @@ debug("import from " . $fn);
my $cfg = new Config::Simple($fn);
my $version = Bluto::from_config($cfg, \%env);
-
if (!defined $version) {
die("config processing failed");
}