dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH 7/7] ok-pkg
Date: Tue, 12 Sep 2023 11:21:53 +0000	[thread overview]
Message-ID: <20230912112153.2484197-7-e@80x24.org> (raw)
In-Reply-To: <20230912112153.2484197-1-e@80x24.org>

---
 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 = <<EOM;
+my $help = <<EOM; # make sure this fits in 80x24 terminals
 usage: $^X $0 [-f PKG_FMT] [--allow-remove] PROFILE [PROFILE_MOD]
 
   -f PKG_FMT      package format (`deb', `pkg', `pkg_add', `pkgin' or `rpm')
   --allow-remove  allow removing packages (for development use only)
   --dry-run | -n  show commands that would be run
+  --yes | -y      non-interactive mode / assume yes to package manager
 
-PROFILE is typically `all'.  Other profiles are subject to change.
+PROFILE is typically `www-search', `lei', or `nntpd'
+Some profile names are intended for developer use only and subject to change.
 PROFILE_MOD is only for developers checking dependencies
 
 OS package installation typically requires administrative privileges
@@ -19,7 +21,8 @@ EOM
 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
 BEGIN { require './install/os.perl' };
 my $opt = {};
-GetOptions($opt, qw(pkg-fmt|f=s allow-remove dry-run|n help|h)) or die $help;
+GetOptions($opt, qw(pkg-fmt|f=s allow-remove dry-run|n yes|y help|h))
+	or die $help;
 if ($opt->{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";
 }

      parent reply	other threads:[~2023-09-12 11:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-12 11:21 [PATCH 1/7] move deps.perl into new install/ directory Eric Wong
2023-09-12 11:21 ` [PATCH 2/7] INSTALL: update for 2023, NetBSD and OpenBSD Eric Wong
2023-09-12 11:21 ` [PATCH 3/7] tests: favor IO::Socket::IP for IPv6 listeners Eric Wong
2023-09-12 11:21 ` [PATCH 4/7] updates around RPM packages on CentOS 7.x Eric Wong
2023-09-12 11:21 ` [PATCH 5/7] install: note curl Eric Wong
2023-09-12 11:21 ` [PATCH 6/7] tests: allow more tests to pass without xapian-compact Eric Wong
2023-09-12 11:21 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230912112153.2484197-7-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).