From 874659bf739757cb56218de323a40e2238ebe187 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Tue, 21 Mar 2023 13:23:50 -0300 Subject: src/bin/paku: General cleanup and tidyness --- src/bin/paku | 320 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 165 insertions(+), 155 deletions(-) (limited to 'src/bin/paku') diff --git a/src/bin/paku b/src/bin/paku index d73107a..262d0c8 100755 --- a/src/bin/paku +++ b/src/bin/paku @@ -1,7 +1,5 @@ #!/usr/bin/env perl -# FIXME: add html output - use v5.34; use warnings; use feature 'signatures'; @@ -9,12 +7,14 @@ no warnings ('experimental::signatures'); use Getopt::Std (); use JSON (); use MIME::Base64 (); -use open IN => ':encoding(UTF-8)'; +use File::Basename (); +use Digest::MD5 (); +use Digest::SHA (); sub usage($fh) { print $fh <<~'EOF' Usage: - paku [-f FILE] FIXME + paku [-d DIR] [-f FILE] ACTION paku -h EOF } @@ -24,18 +24,33 @@ sub help($fh) { Options: - -f FILE use data from FILE (default: paku.json) + -d DIR use DIR for intermediary data (default: .paku/) + -f FILE use data from FILE (default: paku.lock) -h, --help show this message + ACTION what to emit, one of: + - guix + - debian + - nix + - html + Generate package definitions for different package managers. Examples: - FIXME: + Emit Guix package definitions using all defaults: + + $ paku guix > packages.scm + $ guix build -f packages.scm - $ FIXME + + Emit Debian build recipes from "debian.json", using + ".debtmp/" as the temporary directory, and execute them + as is: + + $ paku -d .debtemp/ -f debian.json debian | make -f- EOF } @@ -50,7 +65,7 @@ for (@ARGV) { } my %opts; -if (!Getopt::Std::getopts('f:h', \%opts)) { +if (!Getopt::Std::getopts('d:f:h', \%opts)) { usage *STDERR; exit 2; } @@ -62,7 +77,7 @@ if ($opts{h}) { } -my $dir = '.paku'; # FIXME: parameterize +my $dir = $opts{d} || '.paku'; my $fname = $opts{f} || 'paku.lock'; my $json_str = do { open my $fh, $fname or die "Failed opening \"$fname\""; @@ -70,22 +85,10 @@ my $json_str = do { <$fh>; }; my $json = JSON::decode_json($json_str); - -my $action = $ARGV[0]; +my $action = $ARGV[0] or die "Missing ACTION"; - -use Data::Dumper; -use POSIX qw(); -use File::Basename (); -use Digest::MD5 (); -use Digest::SHA (); - - -# FIXME -my $base_url_prefix = 'https://euandre.org/s'; - -if ($action eq 'release') { +sub emit_release() { my $f = $ARGV[1]; my $name = File::Basename::basename $f; my $size = (stat($f))[7]; @@ -125,8 +128,9 @@ if ($action eq 'release') { exit; } -if ($action eq 'nix') { - my $ns = 'org-euandre'; # FIXME +sub emit_nix() { + my $ns = $json->{namespace}; + $ns =~ s/\./-/g; print <<~EOF; { pkgs }: self: super: { @@ -146,8 +150,6 @@ if ($action eq 'nix') { my $long = $pkg->{'long-description'}; $long =~ s/^(.)/ $1/gm; - my $base_url = $base_url_prefix . '/' . $pkg->{name}; - print <<~EOF; $pkg->{name}-$ver = pkgs.stdenv.mkDerivation rec { name = "$pkg->{name}"; @@ -190,39 +192,34 @@ if ($action eq 'nix') { longDescription = '' $long ''; - homepage = "$base_url/"; - changelog = "$base_url/CHANGELOG.html"; - downloadPage = "$base_url/#releases"; + homepage = "$pkg->{'base-url'}/"; + changelog = "$pkg->{'base-url'}/CHANGELOG.html"; + downloadPage = "$pkg->{'base-url'}/#releases"; license = licenses.agpl3; platforms = platforms.unix; }; }; EOF - # FIXME: escape quotes in description - # FIXME: parameterize license } print <<~EOF; }; } EOF - exit; } - -if ($action eq 'guix') { - my @pkgs = (); - my $ns = 'org euandre'; # FIXME +sub emit_guix() { + my $ns = $json->{namespace}; + $ns =~ s/\./ /g; print <<~EOF; - (define-module ($ns packages) - EOF + (define-module ($ns packages) + EOF for my $module (@{$json->{guix}{'module-use'}}) { print <<~EOF; #:use-module (gnu packages $module) EOF } - # FIXME: rename to 'licenses:' print <<~EOF; - #:use-module ((guix licenses) #:prefix license:) + #:use-module ((guix licenses) #:prefix licenses:) #:use-module (guix gexp) #:use-module (guix packages) #:use-module (guix download) @@ -230,6 +227,7 @@ if ($action eq 'guix') { EOF + my @pkgs = (); for my $pkg (@{$json->{packages}}) { my $ver = $pkg->{version}; $ver =~ s/^v//; @@ -242,20 +240,18 @@ if ($action eq 'guix') { my $long = $pkg->{'long-description'}; $long =~ s/^(.)/ $1/gm; - my $base_url = $base_url_prefix . '/' . $pkg->{name}; - push @pkgs, "$pkg->{name}-$ver"; - # FIXME: indentation of (source ...) print <<~EOF; (define-public $pkg->{name}-$ver (package (name "$pkg->{name}-$ver") (version "$pkg->{version}") - (source (origin - (method url-fetch) - (uri "$pkg->{url}") - (sha256 - (base32 "$pkg->{sha256FIXME}")))) + (source + (origin + (method url-fetch) + (uri "$pkg->{url}") + (sha256 + (base32 "$pkg->{sha256base32}")))) (build-system gnu-build-system) (native-inputs EOF @@ -285,12 +281,10 @@ if ($action eq 'guix') { (synopsis "$pkg->{description}") (description "$pkg->{'long-description'}") - (home-page "$base_url/") - (license license:agpl3+))) + (home-page "$pkg->{'base-url'}/") + (license licenses:agpl3+))) EOF - # FIXME: escape quotes in description - # FIXME: parameterize license if ($pkg->{type} eq 'latest') { print <<~EOF; (define-public $pkg->{name} @@ -307,132 +301,148 @@ if ($action eq 'guix') { print "\n $_"; } print ")\n"; - exit; } +sub emit_debian() { + my %vars = ( + tarballs => ["tarballs = \\\n"], + checkouts => ["checkouts = \\\n"], + destdirs => ["debian-destdirs = \\\n"], + ctrlfiles => ["control-files = \\\n"], + destdebs => ["destdir-debs = \\\n"], + debs => ["debs = \\\n"], + ); -my %vars = ( - tarballs => ["tarballs = \\\n"], - checkouts => ["checkouts = \\\n"], - destdirs => ["debian-destdirs = \\\n"], - ctrlfiles => ["control-files = \\\n"], - destdebs => ["destdir-debs = \\\n"], - debs => ["debs = \\\n"], -); + my @targets = (); -my @targets = (); + for my $pkg (@{$json->{packages}}) { + push @{$vars{tarballs}}, "\t$dir/tarballs/$pkg->{fname} \\\n"; + push @{$vars{checkouts}}, "\t$dir/checkouts/$pkg->{name}-$pkg->{version} \\\n"; -for my $pkg (@{$json->{packages}}) { - push @{$vars{tarballs}}, "\t$dir/tarballs/$pkg->{fname} \\\n"; - push @{$vars{checkouts}}, "\t$dir/checkouts/$pkg->{name}-$pkg->{version} \\\n"; + push @targets, <<~EOF; + $dir/tarballs/$pkg->{fname}: + mkdir -p \$(\@D) + wget -O \$\@ \\ + '$pkg->{url}' - push @targets, <<~EOF; - $dir/tarballs/$pkg->{fname}: - mkdir -p \$(\@D) - wget -O \$\@ \\ - '$pkg->{url}' + $dir/checkouts/$pkg->{name}-$pkg->{version}: $dir/tarballs/$pkg->{fname} + mkdir -p \$(\@D) + tar -C $dir/checkouts/ -xf $dir/tarballs/$pkg->{fname} + touch \$\@ - $dir/checkouts/$pkg->{name}-$pkg->{version}: $dir/tarballs/$pkg->{fname} - mkdir -p \$(\@D) - tar -C $dir/checkouts/ -xf $dir/tarballs/$pkg->{fname} - touch \$\@ + EOF - EOF + next if $pkg->{architectures} ne 'any'; - next if $pkg->{architectures} ne 'any'; - - push @{$vars{destdirs}}, "\t$dir/debian-destdir/$pkg->{name}-$pkg->{version}/DEBIAN \\\n"; - push @{$vars{ctrlfiles}}, "\t$dir/debian-destdir/$pkg->{name}-$pkg->{version}/DEBIAN/control \\\n"; - push @{$vars{destdebs}}, "\t$dir/debian-destdir/$pkg->{name}-$pkg->{version}.deb \\\n"; - push @{$vars{debs}}, "\t$dir/debian/$pkg->{name}_$pkg->{version}_all.deb \\\n"; - - my $ver = $pkg->{type} eq 'latest' ? '0.' . $pkg->{version} . '.latest' : $pkg->{version}; - $ver =~ s/^v//; - my $maintainer_b64 = MIME::Base64::encode_base64 $pkg->{maintainer}, ''; - my $desc_b64 = MIME::Base64::encode_base64 $pkg->{description}, ''; - my $long_desc_b64 = MIME::Base64::encode_base64 $pkg->{'long-description'}, ''; - - push @targets, <<~EOF; - $dir/debian-destdir/$pkg->{name}-$pkg->{version}/DEBIAN: $dir/checkouts/$pkg->{name}-$pkg->{version} - \$(MAKE) \\ - -C $dir/checkouts/$pkg->{name}-$pkg->{version} \\ - install \\ - PREFIX=/usr \\ - DESTDIR="\$\$PWD"/$dir/debian-destdir/$pkg->{name}-$pkg->{version} - mkdir -p \$\@ - touch \$\@ - - $dir/debian-destdir/$pkg->{name}-$pkg->{version}/DEBIAN/control: $dir/debian-destdir/$pkg->{name}-$pkg->{version}/DEBIAN - printf '' > \$\@ - printf 'Package: $pkg->{name}\\n' >> \$\@ - printf 'Version: $ver\\n' >> \$\@ - printf 'Section: custom\\n' >> \$\@ - printf 'Depends:\\n' >> \$\@ - printf 'Priority: optional\\n' >> \$\@ - printf 'Architecture: all\\n' >> \$\@ - printf 'Essential: no\\n' >> \$\@ - - printf 'Maintainer: ' >> \$\@ - printf '$maintainer_b64' | base64 -d >> \$\@ - printf '\\n' >> \$\@ - - printf 'Description: ' >> \$\@ - printf '$desc_b64' | base64 -d >> \$\@ - printf '\\n' >> \$\@ - - printf '$long_desc_b64' | \\ - base64 -d | \\ - sed 's|^\$\$|.|' | \\ - sed 's|^| |' >> \$\@ - printf '\\n' >> \$\@ - - $dir/debian-destdir/$pkg->{name}-$pkg->{version}.deb: $dir/debian-destdir/$pkg->{name}-$pkg->{version}/DEBIAN/control - dpkg-deb --build $dir/debian-destdir/$pkg->{name}-$pkg->{version} - - $dir/debian/$pkg->{name}_$pkg->{version}_all.deb: $dir/debian-destdir/$pkg->{name}-$pkg->{version}.deb - mkdir -p \$(\@D) - cp $dir/debian-destdir/$pkg->{name}-$pkg->{version}.deb \$\@ + push @{$vars{destdirs}}, "\t$dir/debian-destdir/$pkg->{name}-$pkg->{version}/DEBIAN \\\n"; + push @{$vars{ctrlfiles}}, "\t$dir/debian-destdir/$pkg->{name}-$pkg->{version}/DEBIAN/control \\\n"; + push @{$vars{destdebs}}, "\t$dir/debian-destdir/$pkg->{name}-$pkg->{version}.deb \\\n"; + push @{$vars{debs}}, "\t$dir/debian/$pkg->{name}_$pkg->{version}_all.deb \\\n"; + my $ver = $pkg->{type} eq 'latest' ? '0.' . $pkg->{version} . '.latest' : $pkg->{version}; + $ver =~ s/^v//; + my $maintainer_b64 = MIME::Base64::encode_base64 $pkg->{maintainer}, ''; + my $desc_b64 = MIME::Base64::encode_base64 $pkg->{description}, ''; + my $long_desc_b64 = MIME::Base64::encode_base64 $pkg->{'long-description'}, ''; + + push @targets, <<~EOF; + $dir/debian-destdir/$pkg->{name}-$pkg->{version}/DEBIAN: $dir/checkouts/$pkg->{name}-$pkg->{version} + \$(MAKE) \\ + -C $dir/checkouts/$pkg->{name}-$pkg->{version} \\ + install \\ + PREFIX=/usr \\ + DESTDIR="\$\$PWD"/$dir/debian-destdir/$pkg->{name}-$pkg->{version} + mkdir -p \$\@ + touch \$\@ + + $dir/debian-destdir/$pkg->{name}-$pkg->{version}/DEBIAN/control: $dir/debian-destdir/$pkg->{name}-$pkg->{version}/DEBIAN + printf '' > \$\@ + printf 'Package: $pkg->{name}\\n' >> \$\@ + printf 'Version: $ver\\n' >> \$\@ + printf 'Section: custom\\n' >> \$\@ + printf 'Depends:\\n' >> \$\@ + printf 'Priority: optional\\n' >> \$\@ + printf 'Architecture: all\\n' >> \$\@ + printf 'Essential: no\\n' >> \$\@ + + printf 'Maintainer: ' >> \$\@ + printf '$maintainer_b64' | base64 -d >> \$\@ + printf '\\n' >> \$\@ + + printf 'Description: ' >> \$\@ + printf '$desc_b64' | base64 -d >> \$\@ + printf '\\n' >> \$\@ + + printf '$long_desc_b64' | \\ + base64 -d | \\ + sed 's|^\$\$|.|' | \\ + sed 's|^| |' >> \$\@ + printf '\\n' >> \$\@ + + $dir/debian-destdir/$pkg->{name}-$pkg->{version}.deb: $dir/debian-destdir/$pkg->{name}-$pkg->{version}/DEBIAN/control + dpkg-deb --build $dir/debian-destdir/$pkg->{name}-$pkg->{version} + + $dir/debian/$pkg->{name}_$pkg->{version}_all.deb: $dir/debian-destdir/$pkg->{name}-$pkg->{version}.deb + mkdir -p \$(\@D) + cp $dir/debian-destdir/$pkg->{name}-$pkg->{version}.deb \$\@ - EOF -} + EOF + } -print - @{$vars{tarballs}}, "\n", - @{$vars{checkouts}}, "\n", - @{$vars{destdirs}}, "\n", - @{$vars{ctrlfiles}}, "\n", - @{$vars{destdebs}}, "\n", - @{$vars{debs}}, "\n"; -print <<~EOF; - FIXME = eu\@euandre.org + print + @{$vars{tarballs}}, "\n", + @{$vars{checkouts}}, "\n", + @{$vars{destdirs}}, "\n", + @{$vars{ctrlfiles}}, "\n", + @{$vars{destdebs}}, "\n", + @{$vars{debs}}, "\n"; + print <<~EOF; + GPGKEY = '$json->{maintainer}' - all: $dir/debian/InRelease $dir/debian/Release.gpg $dir/debian/public-key.asc - public-dir: - \@printf '$dir/debian' + all: $dir/debian/InRelease $dir/debian/Release.gpg $dir/debian/public-key.asc + public-dir: + \@printf '$dir/debian' - $dir/debian/Packages: \$(debs) - cd \$(\@D) && dpkg-scanpackages -m . > \$(\@F) - $dir/debian/Release: $dir/debian/Packages - perl src/bin/paku release $dir/debian/Packages > \$\@ + $dir/debian/Packages: \$(debs) + cd \$(\@D) && dpkg-scanpackages -m . > \$(\@F) - $dir/debian/Release.gpg: $dir/debian/Release - gpg -abs -o \$\@ $dir/debian/Release + $dir/debian/Release: $dir/debian/Packages + perl src/bin/paku debian-release $dir/debian/Packages > \$\@ - $dir/debian/InRelease: $dir/debian/Release - gpg --default-key \$(FIXME) -a --clear-sign -o \$\@ $dir/debian/Release + $dir/debian/Release.gpg: $dir/debian/Release + gpg -abs -o \$\@ $dir/debian/Release - $dir/debian/public-key.asc: $dir/debian/Release - gpg --armour --export \$(FIXME) > \$\@ + $dir/debian/InRelease: $dir/debian/Release + gpg --default-key \$(GPGKEY) -a --clear-sign -o \$\@ $dir/debian/Release + $dir/debian/public-key.asc: $dir/debian/Release + gpg --armour --export \$(GPGKEY) > \$\@ - EOF -print @targets; + EOF + + print @targets; +} + +sub emit_html() { + +} + + +my %actions = ( + 'debian-release' => \&emit_release, + nix => \&emit_nix, + guix => \&emit_guix, + debian => \&emit_debian, + html => \&emit_html, +); + +my $fn = $actions{$action} or die "Unknown ACTION: \"$action\""; +&$fn; -- cgit v1.2.3