From 2d4ec58a81fde779a8f27d4339f9f77ece63fdc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Wed, 27 Mar 2024 10:26:35 +0100 Subject: [PATCH] Get package manager variables. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ortega Froysa --- pacundo.pl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pacundo.pl b/pacundo.pl index 02e8dfb..2f60367 100755 --- a/pacundo.pl +++ b/pacundo.pl @@ -136,6 +136,30 @@ $n, $tx->{action}, $tx->{pkg_name} return @sel_undo; } +sub get_pkgmgr() { + my $mgr = $ENV{DEFAULT_PKGMGR} // 'pacman'; + my $mgr_bin = `which $mgr`; + + if ($? != 0) { + print(STDERR "Failed to find pacman executable. Are you using an ArchLinux system?\n"); + exit 1; + } + + my $mgr_cmd_search = "$mgr_bin -Ss"; + my $mgr_cmd_install_remote = "$mgr_bin -S"; + my $mgr_cmd_install_local = "$mgr_bin -U"; + + my %pkgmgr = ( + name => $mgr, + bin => $mgr_bin, + search => $mgr_cmd_search, + install_remote => $mgr_cmd_install_remote, + install_local => $mgr_cmd_install_local, + ); + + return \%pkgmgr; +} + getopts("irt:dvh", \my %opts); if ($opts{'v'}) { @@ -157,6 +181,7 @@ my $r_flag = $opts{'r'} // 0; my $dry_run = $opts{'d'} // 0; my $num_txs = $opts{'t'} // 1; +my $pkgmgr = &get_pkgmgr(); my @undo_txs = &read_txs($num_txs); # Interactive mode