From 7682d7645f579ba531717ba95c8f3d4ff63af53f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 13 Sep 2023 09:12:39 +0000 Subject: move deps.perl into new install/ directory deps.perl can be useful for non-CI purposes as long as it's not blindly removing packages. Thus, a --allow-remove flag now exists for CI use and removals are disabled by default. deps.perl also gets easier-to-use in that now install/os.perl is split off from from ci/profiles.perl so OS-supplied packaged manager. --- install/os.perl | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 install/os.perl (limited to 'install/os.perl') diff --git a/install/os.perl b/install/os.perl new file mode 100644 index 00000000..4fcbcbe4 --- /dev/null +++ b/install/os.perl @@ -0,0 +1,78 @@ +# Copyright (C) all contributors +# License: AGPL-3.0+ + +# Helper library for detecting distro info and mapping to package manager. +# This should NOT be installed via `make install'. +# This is used by install/deps.perl and ci/profiles.perl +package PublicInbox::InstallOS; +use v5.12; +use parent qw(Exporter); +our ($ID, $PRETTY_NAME, $VERSION_ID); # same vars as os-release(5) +our @EXPORT = qw($ID $VERSION_ID pkg_fmt); + +my ($release, $version); # from uname +if ($^O eq 'linux') { # try using os-release(5) + for my $f (qw(/etc/os-release /usr/lib/os-release)) { + next unless -f $f; + my @echo = map { + qq{echo "\$"$_" = qq[\$$_];"; } + } qw(ID PRETTY_NAME VERSION_ID); + # rely on sh(1) to handle interpolation and such: + my $vars = `sh -c '. $f; @echo'`; + die "sh \$?=$?" if $?; + eval $vars; + die $@ if $@; + $VERSION_ID //= ''; + $ID //= ''; + if ($ID eq 'debian' && $VERSION_ID eq '') { + if ($PRETTY_NAME =~ m!/sid\z!) { + $VERSION_ID = 'sid'; + } else { + open my $fh, '<', $f or die "open($f): $!"; + my $msg = do { local $/; <$fh> }; + die < $f <== +$msg +EOM + } + } + last if $ID ne '' && $VERSION_ID ne ''; + } + $ID = 'linux' if $ID eq ''; # cf. os-release(5) +} elsif ($^O =~ m!\A(?:free|net|open)bsd\z!) { # TODO: net? dragonfly? + $ID = $^O; + require POSIX; + (undef, undef, $release, $version) = POSIX::uname(); + $VERSION_ID = lc $release; + $VERSION_ID =~ s/[^0-9a-z\.\_\-]//sg; # cf. os-release(5) +} else { # only support POSIX-like and Free systems: + die "$^O unsupported"; +} +$VERSION_ID //= 0; # numeric? could be 'sid', actually... +my %MIN_VER = (freebsd => v11, openbsd => v7.3, netbsd => v9.3); + +if (defined(my $min_ver = $MIN_VER{$^O})) { + my $vid = $VERSION_ID; + $vid =~ s/-.*\z//s; # no dashes in v-strings + my $vstr = eval "v$vid"; + die "can't convert VERSION_ID=$VERSION_ID to v-string" if $@; + die <import; + +1; -- cgit v1.2.3-24-ge0c7