user/dev discussion of public-inbox itself
 help / color / Atom feed
e0fda01191c0be44d61ab876febdb01377607afe blob 5911 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
 
#!/usr/bin/perl -w
# Copyright (C) 2019 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# Helper script for installing/uninstalling packages for CI use
# Intended for use on non-production chroots or VMs since it
# changes installed packages
use strict;
my $usage = "$0 PKG_FMT PROFILE [PROFILE_MOD]";
my $pkg_fmt = shift;
@ARGV or die $usage, "\n";

# package profiles
my $profiles = {
	# the smallest possible profile
	# TODO: trim this, Plack pulls in Filesys::Notify::Simple,
	# and we don't need that for mda-only installs
	essential => [ qw(
		git
		perl
		Date::Parse
		Devel::Peek
		Email::Simple
		Email::MIME
		Email::MIME::ContentType
		Encode
		Filesys::Notify::Simple
		Plack
		URI::Escape
		) ],

	# everything optional for normal use
	optional => [ qw(
		BSD::Resource
		DBD::SQLite
		DBI
		IO::Compress::Gzip
		Inline::C
		Net::Server
		Plack::Middleware::Deflater
		Plack::Middleware::ReverseProxy
		Search::Xapian
		Socket6
		highlight.pm
		xapian-compact
		) ],

	# developer stuff
	devtest => [ qw(
		IPC::Run
		Test::HTTP::Server::Simple
		XML::Feed
		curl
		w3m
		) ],
};

# account for granularity differences between package systems and OSes
my @precious;
if ($^O eq 'freebsd') {
	@precious = qw(perl curl Socket6 IO::Compress::Gzip);
}

if (@precious) {
	my $re = join('|', map { quotemeta($_) } @precious);
	for my $list (values %$profiles) {
		@$list = grep(!/\A(?:$re)\z/, @$list);
	}
	push @{$profiles->{essential}}, @precious;
}


# bare minimum for v2
$profiles->{v2essential} = [ @{$profiles->{essential}}, qw(
	DBD::SQLite
	DBI
	Search::Xapian
	xapian-compact
) ];

# package names which can't be mapped automatically:
my $non_auto = {
	'perl' => { pkg => 'perl5' },
	'Date::Parse' => {
		deb => 'libtimedate-perl',
		pkg => 'p5-TimeDate',
		rpm => 'perl-TimeDate',
	},
	'Devel::Peek' => {
		deb => 'perl', # libperl5.XX, but the XX varies
		pkg => 'perl5',
	},
	'Encode' => {
		deb => 'perl', # libperl5.XX, but the XX varies
		pkg => 'perl5',
		rpm => 'perl-Encode',
	},
	'IO::Compress::Gzip' => {
		deb => 'perl', # perl-modules-5.xx
		pkg => 'perl5',
		rpm => 'perl-PerlIO-gzip',
	},
	'DBD::SQLite' => { deb => 'libdbd-sqlite3-perl' },
	'URI::Escape' => {
		deb => 'liburi-perl',
		pkg => 'p5-URI',
		rpm => 'perl-URI',
	},
	'highlight.pm' => {
		deb => 'libhighlight-perl',
		pkg => [],
		rpm => [],
	},

	# we call xapian-compact(1) in public-inbox-compact(1)
	'xapian-compact' => {
		deb => 'xapian-tools',
		pkg => 'xapian-core',
		rpm => 'xapian-core', # ???
	},

	# OS-specific
	'IO::KQueue' => {
		deb => [],
		pkg => 'p5-IO-KQueue',
		rpm => [],
	},
};

my (@pkg_install, @pkg_remove, %all);
for my $ary (values %$profiles) {
	$all{$_} = \@pkg_remove for @$ary;
}
if ($^O eq 'freebsd') {
	$all{'IO::KQueue'} = \@pkg_remove;
}
$profiles->{all} = [ keys %all ]; # pseudo-profile for all packages

# parse the profile list from the command-line
for my $profile (@ARGV) {
	if ($profile =~ s/-\z//) {
		# like apt-get, trailing "-" means remove
		profile2dst($profile, \@pkg_remove);
	} else {
		profile2dst($profile, \@pkg_install);
	}
}

# fill in @pkg_install and @pkg_remove:
while (my ($pkg, $dst_pkg_list) = each %all) {
	push @$dst_pkg_list, list(pkg2ospkg($pkg, $pkg_fmt));
}

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,
		@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);
} elsif ($pkg_fmt eq 'pkg') {
	my @quiet = $ENV{V} ? () : ('-q');
	# FreeBSD, maybe other *BSDs are similar?

	# 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);
# TODO: yum / rpm support
} else {
	die "unsupported package format: $pkg_fmt\n";
}
exit 0;


# map a generic package name to an OS package name
sub pkg2ospkg {
	my ($pkg, $fmt) = @_;

	# check explicit overrides, first:
	if (my $ospkg = $non_auto->{$pkg}->{$fmt}) {
		return $ospkg;
	}

	# check common Perl module name patterns:
	if ($pkg =~ /::/ || $pkg =~ /\A[A-Z]/) {
		if ($fmt eq 'deb') {
			$pkg =~ s/::/-/g;
			$pkg =~ tr/A-Z/a-z/;
			return "lib$pkg-perl";
		} elsif ($fmt eq 'rpm') {
			$pkg =~ s/::/-/g;
			return "perl-$pkg"
		} elsif ($fmt eq 'pkg') {
			$pkg =~ s/::/-/g;
			return "p5-$pkg"
		} else {
			die "unsupported package format: $fmt for $pkg\n"
		}
	}

	# use package name as-is (e.g. 'curl' or 'w3m')
	$pkg;
}

# maps a install profile to a package list (@pkg_remove or @pkg_install)
sub profile2dst {
	my ($profile, $dst_pkg_list) = @_;
	if (my $pkg_list = $profiles->{$profile}) {
		$all{$_} = $dst_pkg_list for @$pkg_list;
	} elsif ($all{$profile}) { # $profile is just a package name
		$all{$profile} = $dst_pkg_list;
	} else {
		die "unrecognized profile or package: $profile\n";
	}
}

sub exclude_uninstalled {
	my ($list) = @_;
	my %inst_check = (
		pkg => sub { system(qw(pkg info -q), $_[0]) == 0 },
		deb => sub { system("dpkg -s $_[0] >/dev/null 2>&1") == 0 },
		rpm => sub { system("rpm -qs $_[0] >/dev/null 2>&1") == 0 },
	);

	my $cb = $inst_check{$pkg_fmt} || die <<"";
don't know how to check install status for $pkg_fmt

	my @tmp;
	for my $pkg (@$list) {
		push @tmp, $pkg if $cb->($pkg);
	}
	@$list = @tmp;
}

sub root {
	print join(' ', @_), "\n";
	return if $ENV{DRY_RUN};
	return if system(@_) == 0;
	warn 'command failed: ', join(' ', @_), "\n";
	exit($? >> 8);
}

# ensure result can be pushed into an array:
sub list {
	my ($pkg) = @_;
	ref($pkg) eq 'ARRAY' ? @$pkg : $pkg;
}
debug log:

solving e0fda01 ...
found e0fda01 in https://80x24.org/public-inbox.git

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror http://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox