Automatically detect package manager.

Signed-off-by: Nicolás Ortega Froysa <nicolas@ortegas.org>
This commit is contained in:
Nicolás A. Ortega Froysa 2024-05-02 13:00:27 +02:00
parent e6d814d438
commit 8525b7f4e8

View File

@ -139,13 +139,24 @@ $n, $tx->{action}, $tx->{pkg_name}
# NOTE: Currently this subroutine only works for pacman and yay. You'll have to # NOTE: Currently this subroutine only works for pacman and yay. You'll have to
# add options for additional AUR helpers. # add options for additional AUR helpers.
sub get_pkgmgr() { sub get_pkgmgr() {
# TODO: autodetect AUR helper my $mgr = '';
my $mgr = $ENV{DEFAULT_PKGMGR} // 'pacman'; my $mgr_bin;
my @supported_mgrs = (
'yay',
'pacman',
);
my $sudo = ''; my $sudo = '';
my $user = $ENV{LOGNAME} || $ENV{USER}; my $user = $ENV{LOGNAME} || $ENV{USER};
my $mgr_bin = `which $mgr 2>&1`; foreach my $i (@supported_mgrs) {
if ($? != 0) { $mgr_bin = `which $i 2>&1`;
if ($? == 0) {
$mgr = $i;
last;
}
}
if ($mgr eq '') {
print(STDERR "Failed to find pacman executable. Are you using an ArchLinux system?\n"); print(STDERR "Failed to find pacman executable. Are you using an ArchLinux system?\n");
exit 1; exit 1;
} }