From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id ED0651F569 for ; Tue, 12 Sep 2023 11:21:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1694517715; bh=4en/1muyvLZNIs6mlEQa9rChY2ri0ORTJEkD1IA4PAM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hWn1FUcnrvRkx3/pykLMVc+f0tmzayff3WjiIOoK1N4HJp7GDEMqaFKXUagY5ucTo g9pXvhIPPgm1XF79PWvPiiXONjlBZlctAyVExHk8T9iR+SZQw1V80BxounPbBt7PDw d//rVRh7MZ63KRjDF3BdRgmAd2apmO+XJr1bf7fA= From: Eric Wong To: spew@80x24.org Subject: [PATCH 7/7] ok-pkg Date: Tue, 12 Sep 2023 11:21:53 +0000 Message-Id: <20230912112153.2484197-7-e@80x24.org> In-Reply-To: <20230912112153.2484197-1-e@80x24.org> References: <20230912112153.2484197-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: --- install/deps.perl | 106 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 75 insertions(+), 31 deletions(-) diff --git a/install/deps.perl b/install/deps.perl index a7b42607..13d54205 100755 --- a/install/deps.perl +++ b/install/deps.perl @@ -4,14 +4,16 @@ eval 'exec perl -S $0 ${1+"$@"}' # no shebang if 0; # running under some shell use v5.12; -my $help = <{help}) { print $help; exit } my $pkg_fmt = $opt->{'pkg-fmt'} // do { my $fmt = pkg_fmt; @@ -47,10 +50,10 @@ my $profiles = { # everything optional for normal use optional => [ qw( + curl Date::Parse BSD::Resource DBD::SQLite - DBI Inline::C Mail::IMAPClient Net::Server @@ -66,14 +69,44 @@ my $profiles = { # optional developer stuff devtest => [ qw( XML::TreePP - curl w3m Plack::Test::ExternalServer ) ], }; +# only for distro-agnostic dependencies which are always true: +my $always_deps = { + 'DBD::SQLite' => [ qw(DBI) ], + 'Mail::IMAPClient' => [ qw(Parse::RecDescent) ], + 'Plack::Middleware::ReverseProxy' => [ qw(Plack) ], +}; + # bare minimum for v2 -$profiles->{v2essential} = [ @{$profiles->{essential}}, qw(DBD::SQLite DBI) ]; +$profiles->{v2essential} = [ @{$profiles->{essential}}, qw(DBD::SQLite) ]; + +# for old v1 installs +$profiles->{'www-v1'} = [ @{$profiles->{essential}}, qw(Plack) ]; +$profiles->{'www-thread'} = [ @{$profiles->{v2essential}}, qw(Plack) ]; + +# common profile for PublicInbox::WWW +$profiles->{'www-search'} = [ @{$profiles->{'www-thread'}}, qw(Xapian) ]; + +# bare mininum for lei +$profiles->{'lei-core'} = [ @{$profiles->{v2essential}}, qw(Xapian) ]; +push @{$profiles->{'lei-core'}}, 'Inline::C' if $^O ne 'linux'; + +# common profile for lei: +$profiles->{lei} = [ @{$profiles->{'lei-core'}}, qw(Mail::IMAPClient curl) ]; + +$profiles->{nntpd} = [ @{$profiles->{v2essential}} ]; +$profiles->{pop3d} = [ @{$profiles->{v2essential}} ]; +$profiles->{'imapd-bare'} = [ @{$profiles->{v2essential}}, + qw(Parse::RecDescent) ]; +$profiles->{imapd} = [ @{$profiles->{'imapd-bare'}}, qw(Xapian) ]; +$profiles->{pop3d} = [ @{$profiles->{v2essential}} ]; +$profiles->{watch} = [ @{$profiles->{v2essential}}, qw(Mail::IMAPClient) ]; +$profiles->{'watch-v1'} = [ @{$profiles->{essential}} ]; +$profiles->{'watch-maildir'} = [ @{$profiles->{v2essential}} ]; # package names which can't be mapped automatically and explicit # dependencies to prevent essential package removal: @@ -167,8 +200,15 @@ my %inst_check = ( # subs which return true if a package is intalled our $INST_CHECK = $inst_check{$pkg_fmt} || die <<""; don't know how to check install status for $pkg_fmt + my (@pkg_install, @pkg_remove, %all); for my $ary (values %$profiles) { + my @extra; + for my $pkg (@$ary) { + my $deps = $always_deps->{$pkg} // next; + push @extra, @$deps; + } + push @$ary, @extra; $all{$_} = \@pkg_remove for @$ary; } if ($^O =~ /\A(?:free|net|open)bsd\z/) { @@ -177,7 +217,8 @@ if ($^O =~ /\A(?:free|net|open)bsd\z/) { $profiles->{all} = [ keys %all ]; # pseudo-profile for all packages # parse the profile list from the command-line -for my $profile (@ARGV) { +my @profiles = @ARGV; +while (defined(my $profile = shift @profiles)) { if ($profile =~ s/-\z//) { # like apt-get, trailing "-" means remove profile2dst($profile, \@pkg_remove); @@ -191,57 +232,60 @@ while (my ($pkg, $dst_pkg_list) = each %all) { push @$dst_pkg_list, list(pkg2ospkg($pkg, $pkg_fmt)); } -my %inst = map { $_ => 1 } @pkg_install; -@pkg_remove = $opt->{'allow-remove'} ? grep { !$inst{$_} } @pkg_remove : (); +my (%add, %rm); # uniquify list +@pkg_install = grep { !$add{$_}++ } @pkg_install; +@pkg_remove = $opt->{'allow-remove'} ? + grep { !$add{$_} && !$rm{$_}++ } @pkg_remove : (); @pkg_install = grep { !$INST_CHECK->($_) } @pkg_install; -my @apt_opts = - qw(-o APT::Install-Recommends=false -o APT::Install-Suggests=false); - # OS-specific cleanups appreciated if ($pkg_fmt eq 'deb') { - my @quiet = $ENV{V} ? () : ('-q'); - root('apt-get', @apt_opts, qw(install --purge -y), @quiet, + my @apt_opt = qw(-o APT::Install-Recommends=false + -o APT::Install-Suggests=false); + push @apt_opt, '-y' if $opt->{yes}; + root('apt-get', @apt_opt, qw(install), + ($opt->{'allow-remove'} ? '--purge' : ()), @pkg_install, # apt-get lets you suffix a package with "-" to # remove it in an "install" sub-command: map { "$_-" } @pkg_remove); - root('apt-get', @apt_opts, qw(autoremove --purge -y), @quiet); + root('apt-get', @apt_opt, qw(autoremove --purge)) + if $opt->{'allow-remove'}; } elsif ($pkg_fmt eq 'pkg') { # FreeBSD - my @quiet = $ENV{V} ? () : ('-q'); + my @pkg_opt = $opt->{yes} ? ('-y') : (); # don't remove stuff that isn't installed: exclude_uninstalled(\@pkg_remove); - root(qw(pkg remove -y), @quiet, @pkg_remove) if @pkg_remove; - root(qw(pkg install -y), @quiet, @pkg_install) if @pkg_install; - root(qw(pkg autoremove -y), @quiet); + root(qw(pkg remove), @pkg_opt, @pkg_remove) if @pkg_remove; + root(qw(pkg install), @pkg_opt, @pkg_install) if @pkg_install; + root(qw(pkg autoremove), @pkg_opt) if $opt->{'allow-remove'}; } elsif ($pkg_fmt eq 'pkgin') { # NetBSD - my @quiet = $ENV{V} ? ('-'.('V'x$ENV{V})) : (); + my @pkg_opt = $opt->{yes} ? ('-y') : (); exclude_uninstalled(\@pkg_remove); - root(qw(pkgin -y), @quiet, 'remove', @pkg_remove) if @pkg_remove; - root(qw(pkgin -y), @quiet, 'install', @pkg_install) if @pkg_install; - root(qw(pkgin -y), @quiet, 'autoremove'); + root(qw(pkgin), @pkg_opt, 'remove', @pkg_remove) if @pkg_remove; + root(qw(pkgin), @pkg_opt, 'install', @pkg_install) if @pkg_install; + root(qw(pkgin), @pkg_opt, 'autoremove') if $opt->{'allow-remove'}; # TODO: yum / rpm support } elsif ($pkg_fmt eq 'rpm') { - my @quiet = $ENV{V} ? () : ('-q'); + my @pkg_opt = $opt->{yes} ? ('-y') : (); exclude_uninstalled(\@pkg_remove); - root(qw(yum remove -y), @quiet, @pkg_remove) if @pkg_remove; - root(qw(yum install -y), @quiet, @pkg_install) if @pkg_install; + root(qw(yum remove), @pkg_opt, @pkg_remove) if @pkg_remove; + root(qw(yum install), @pkg_opt, @pkg_install) if @pkg_install; } elsif ($pkg_fmt eq 'pkg_add') { # OpenBSD exclude_uninstalled(\@pkg_remove); - my @quiet = $ENV{V} ? ('-'.('v'x$ENV{V})) : qw(-x); # -x : no progress + my @pkg_opt = $opt->{yes} ? ('-I') : (); # -I means non-interactive if (@pkg_remove) { my @lifo = qw(xapian-bindings-perl); for my $dep (@lifo) { grep(/\A\Q$dep\E\z/, @pkg_remove) or next; - root(qw(pkg_delete -I), @quiet, $dep); + root(qw(pkg_delete), @pkg_opt, $dep); @pkg_remove = grep(!/\A\Q$dep\E\z/, @pkg_remove); } - root(qw(pkg_delete -I), @quiet, @pkg_remove); + root(qw(pkg_delete), @pkg_opt, @pkg_remove); } - root(qw(pkg_delete -a), @quiet); + root(qw(pkg_delete -a), @pkg_opt); # autoremove unspecified @pkg_install = map { "$_--" } @pkg_install; # disambiguate w3m - root(qw(pkg_add), @quiet, @pkg_install) if @pkg_install; + root(qw(pkg_add), @pkg_opt, @pkg_install) if @pkg_install; } else { die "unsupported package format: $pkg_fmt\n"; }