6 Commits

Author SHA1 Message Date
1516ce9ff3 Include section for supported AUR helpers.
Signed-off-by: Nicolás Ortega Froysa <nicolas@ortegas.org>
2024-05-07 18:07:13 +02:00
555ead272e Improve repository check.
Signed-off-by: Nicolás Ortega Froysa <nicolas@ortegas.org>
2024-05-07 18:05:11 +02:00
d616930208 Remove unnecessary sudo.
Signed-off-by: Nicolás Ortega Froysa <nicolas@ortegas.org>
2024-05-07 17:49:20 +02:00
347b49d5ee Find local package when reinstalling removed package.
Signed-off-by: Nicolás Ortega Froysa <nicolas@ortegas.org>
2024-05-02 13:36:07 +02:00
641163a495 Implement dry-run mode.
Signed-off-by: Nicolás Ortega Froysa <nicolas@ortegas.org>
2024-05-02 13:17:02 +02:00
75c663eb1e Update help information.
Signed-off-by: Nicolás Ortega Froysa <nicolas@ortegas.org>
2024-05-02 13:12:34 +02:00
3 changed files with 53 additions and 19 deletions

View File

@ -45,6 +45,10 @@ There are two modes for undoing pacman transactions:
Look at the man-page (`man pacundo`) for more information. Look at the man-page (`man pacundo`) for more information.
### Supported AUR Helpers
- [yay](https://github.com/Jguer/yay)
## License ## License
This project is licensed under the terms & conditions of the Zlib license. This project is licensed under the terms & conditions of the Zlib license.

View File

@ -21,19 +21,22 @@ is especially helpful if the last update broke your system for some reason.
.SH "OPTIONS" .SH "OPTIONS"
.TP .TP
\fB\-i\fR \fB\-i\fR
Interactively select the transactions to undo (default behavior) Enter interactive mode to select package operations to undo (default behavior)
.TP .TP
\fB\-r\fR \fB\-r\fR
Non-interactively undo transactions Non-interactively undo entire transactions
.TP .TP
\fB\-t\fR <\fInum\fR> \fB\-t\fR <\fInum\fR>
Select number of transactions to include (default: 1) Specify the number of transactions to include (default: 1)
.TP
\fB\-d\fR
Dry run, i.e. don't actually do anything
.TP .TP
\fB\-h\fR \fB\-h\fR
Show help information Show this help information
.TP .TP
\fB\-v\fR \fB\-v\fR
Show program version Print program version
.SH "AUTHOR" .SH "AUTHOR"
Written by Nicolás A. Ortega Froysa. Written by Nicolás A. Ortega Froysa.

View File

@ -47,9 +47,9 @@ USAGE:
$PROG_NAME -v $PROG_NAME -v
OPTIONS: OPTIONS:
-i Enter interactive mode to select packages to downgrade [default behavior] -i Enter interactive mode to select package operations to undo (default behavior)
-r Automatically downgrade all packages from last upgrade -r Non-interactively undo entire transactions
-t <num> Specify the number of transactions to include for undoing selection [default 1] -t <num> Specify the number of transactions to include (default: 1)
-d Dry run, i.e. don't actually do anything -d Dry run, i.e. don't actually do anything
-h Show this help information -h Show this help information
-v Print program version\n"); -v Print program version\n");
@ -169,7 +169,8 @@ sub get_pkgmgr() {
my %pkgmgr = ( my %pkgmgr = (
name => $mgr, name => $mgr,
bin => $mgr_bin, bin => $mgr_bin,
search => "$sudo $mgr_bin -Ss", search => "$mgr_bin -Ss",
info => "$mgr_bin -Si",
install_remote => "$sudo $mgr_bin -S", install_remote => "$sudo $mgr_bin -S",
install_local => "$sudo $mgr_bin -U", install_local => "$sudo $mgr_bin -U",
remove => "$sudo $mgr_bin -R", remove => "$sudo $mgr_bin -R",
@ -178,17 +179,33 @@ sub get_pkgmgr() {
return \%pkgmgr; return \%pkgmgr;
} }
sub find_local_pkg($pkgmgr, $pkg_name, $pkg_ver) { sub find_local_pkg($pkgmgr, $pkg_name, $pkg_ver='') {
my $pkg_file = ''; my $pkg_file = '';
my $aur_dir = "$ENV{'XDG_CACHE_HOME'}/yay/$pkg_name"; my $pkg_pat;
my $repo = `$pkgmgr->{info} $pkg_name | awk '{ if (\$1 == "Repository") print \$3; }'`;;
if ($pkgmgr->{name} eq 'yay' && -d $aur_dir) { if ($pkg_ver ne '') {
$pkg_file = `ls $aur_dir/$pkg_name-$pkg_ver-*.pkg.tar.zst | tail -n1`; $pkg_pat = "$pkg_name-$pkg_ver-*.pkg.tar.zst";
} else { } else {
$pkg_file = `ls /var/cache/pacman/pkg/$pkg_name-$pkg_ver-*.pkg.tar.zst | tail -n1`; $pkg_pat = "$pkg_name-*.pkg.tar.zst";
}
if ($repo eq 'aur') {
my $aur_dir;
if ($pkgmgr->{name} eq 'yay') {
$aur_dir = "$ENV{'XDG_CACHE_HOME'}/yay/$pkg_name";
} else {
return '';
}
$pkg_file = `ls $aur_dir/$pkg_pat | tail -n1`;
} else {
$pkg_file = `ls /var/cache/pacman/pkg/$pkg_pat | tail -n1`;
} }
chomp($pkg_file); chomp($pkg_file);
return $pkg_file; return $pkg_file;
} }
@ -227,8 +244,12 @@ foreach my $tx (@undo_txs) {
if ($tx->{action} eq 'installed') { if ($tx->{action} eq 'installed') {
$remove_pkgs .= "$tx->{pkg_name} "; $remove_pkgs .= "$tx->{pkg_name} ";
} elsif ($tx->{action} eq 'removed') { } elsif ($tx->{action} eq 'removed') {
# TODO: install local package if available my $pkg_file = &find_local_pkg($pkgmgr, $tx->{pkg_name});
$remote_install_pkgs .= "$tx->{pkg_name} "; if ($pkg_file eq '') {
$remote_install_pkgs .= "$tx->{pkg_name} ";
} else {
$local_install_pkgs .= "$pkg_file ";
}
} else { } else {
my $pkg_file = &find_local_pkg($pkgmgr, $tx->{pkg_name}, $tx->{oldver}); my $pkg_file = &find_local_pkg($pkgmgr, $tx->{pkg_name}, $tx->{oldver});
if ($pkg_file eq '') { if ($pkg_file eq '') {
@ -239,6 +260,12 @@ foreach my $tx (@undo_txs) {
} }
} }
system("$pkgmgr->{remove} $remove_pkgs") if ($remove_pkgs ne ''); if ($dry_run) {
system("$pkgmgr->{install_remote} $remote_install_pkgs") if ($remote_install_pkgs ne ''); print("$pkgmgr->{remove} $remove_pkgs\n") if ($remove_pkgs ne '');
system("$pkgmgr->{install_local} $local_install_pkgs") if ($local_install_pkgs ne ''); print("$pkgmgr->{install_remote} $remote_install_pkgs\n") if ($remote_install_pkgs ne '');
print("$pkgmgr->{install_local} $local_install_pkgs\n") if ($local_install_pkgs ne '');
} else {
system("$pkgmgr->{remove} $remove_pkgs") if ($remove_pkgs ne '');
system("$pkgmgr->{install_remote} $remote_install_pkgs") if ($remote_install_pkgs ne '');
system("$pkgmgr->{install_local} $local_install_pkgs") if ($local_install_pkgs ne '');
}