Compare commits

...

6 Commits

Author SHA1 Message Date
c08a9f4b40 Simplify and clean up strings and output.
Signed-off-by: Nicolás Ortega Froysa <nicolas@ortegas.org>
2024-03-28 11:40:57 +01:00
ec535f860c Add TODO for autodetecting AUR helper.
Signed-off-by: Nicolás Ortega Froysa <nicolas@ortegas.org>
2024-03-28 11:32:38 +01:00
a458f2dc67 Fix filter regex.
Signed-off-by: Nicolás Ortega Froysa <nicolas@ortegas.org>
2024-03-28 11:14:16 +01:00
615f491433 Simplify get_pkgmgr() subroutine.
Currently it only is configured to deal with pacman or yay (as noted in
the comment). Other AUR helpers would need to be configured.

Signed-off-by: Nicolás Ortega Froysa <nicolas@ortegas.org>
2024-03-28 10:45:24 +01:00
aa7e2d2fbc Add package manager remove command.
Signed-off-by: Nicolás Ortega Froysa <nicolas@ortegas.org>
2024-03-28 10:42:49 +01:00
f55124759e Don't print stderr output of commands (send to stdout).
Signed-off-by: Nicolás Ortega Froysa <nicolas@ortegas.org>
2024-03-28 10:37:46 +01:00

View File

@ -29,8 +29,8 @@ use feature qw(signatures);
use Getopt::Std; use Getopt::Std;
use File::ReadBackwards; use File::ReadBackwards;
my $VERSION = "1.0"; my $VERSION = '1.0';
my $PROG_NAME = "pacundo"; my $PROG_NAME = 'pacundo';
sub print_version() { sub print_version() {
print("$PROG_NAME v$VERSION\n"); print("$PROG_NAME v$VERSION\n");
@ -60,8 +60,8 @@ sub read_txs($num_txs = 1) {
my $found_txs = 0; my $found_txs = 0;
my $in_tx = 0; my $in_tx = 0;
my @undo_txs; my @undo_txs;
my $pacman_log = File::ReadBackwards->new("/var/log/pacman.log") or my $pacman_log = File::ReadBackwards->new('/var/log/pacman.log') or
die("Failed to load pacman log file.\n$!"); die("Failed to load pacman log file.\n$!\n");
while ($found_txs < $num_txs && defined(my $line = $pacman_log->readline)) { while ($found_txs < $num_txs && defined(my $line = $pacman_log->readline)) {
unless ($in_tx) { unless ($in_tx) {
@ -77,18 +77,18 @@ sub read_txs($num_txs = 1) {
$line =~ /\[ALPM\] (upgraded|downgraded) ([^\s]+) \((.*) -> (.*)\)/; $line =~ /\[ALPM\] (upgraded|downgraded) ([^\s]+) \((.*) -> (.*)\)/;
push(@undo_txs, push(@undo_txs,
{ {
'action' => $action, action => $action,
'pkg_name' => $pkg_name, pkg_name => $pkg_name,
'oldver' => $oldver, oldver => $oldver,
'newver' => $newver, newver => $newver,
} }
); );
} elsif ($line =~ /\[ALPM\] (installed|removed)/) { } elsif ($line =~ /\[ALPM\] (installed|removed)/) {
my ($action, $pkg_name) = $line =~ /\[ALPM\] (installed|removed) ([^\s]+)/; my ($action, $pkg_name) = $line =~ /\[ALPM\] (installed|removed) ([^\s]+)/;
push(@undo_txs, push(@undo_txs,
{ {
'action' => $action, action => $action,
'pkg_name' => $pkg_name, pkg_name => $pkg_name,
} }
); );
} }
@ -118,8 +118,7 @@ $n, $tx->{action}, $tx->{pkg_name}
$n++; $n++;
} }
print("Select transactions to undo (e.g. '1 2 3', '1-3')\n"); print("Select transactions to undo (e.g. '1 2 3', '1-3')\n> ");
print("> ");
my @sel = split(' ', <STDIN>); my @sel = split(' ', <STDIN>);
@ -129,7 +128,7 @@ $n, $tx->{action}, $tx->{pkg_name}
push(@sel, ($start..$end)); push(@sel, ($start..$end));
} }
@sel = sort grep({!/[0-9+]-[0-9+]/} @sel); @sel = sort grep({!/[0-9]+-[0-9]+/} @sel);
my @sel_undo; my @sel_undo;
push(@sel_undo, $undo_txs[$_-1]) foreach (@sel); push(@sel_undo, $undo_txs[$_-1]) foreach (@sel);
@ -137,25 +136,25 @@ $n, $tx->{action}, $tx->{pkg_name}
return @sel_undo; return @sel_undo;
} }
# NOTE: Currently this subroutine only works for pacman and yay. You'll have to
# add options for additional AUR helpers.
sub get_pkgmgr() { sub get_pkgmgr() {
# TODO: autodetect AUR helper
my $mgr = $ENV{DEFAULT_PKGMGR} // 'pacman'; my $mgr = $ENV{DEFAULT_PKGMGR} // 'pacman';
my $mgr_bin = `which $mgr`; my $mgr_bin = `which $mgr 2>&1`;
if ($? != 0) { if ($? != 0) {
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;
} }
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 = ( my %pkgmgr = (
name => $mgr, name => $mgr,
bin => $mgr_bin, bin => $mgr_bin,
search => $mgr_cmd_search, search => "$mgr_bin -Ss",
install_remote => $mgr_cmd_install_remote, install_remote => "$mgr_bin -S",
install_local => $mgr_cmd_install_local, install_local => "$mgr_bin -U",
remove => "$mgr_bin -R",
); );
return \%pkgmgr; return \%pkgmgr;