Compare commits

..

No commits in common. "b30dea35b86fcede09232a1c8c4897d46e475bd5" and "c08a9f4b40071d77ed1488eda0d851982192e5d2" have entirely different histories.

View File

@ -141,46 +141,25 @@ $n, $tx->{action}, $tx->{pkg_name}
sub get_pkgmgr() {
# TODO: autodetect AUR helper
my $mgr = $ENV{DEFAULT_PKGMGR} // 'pacman';
my $sudo = '';
my $user = $ENV{LOGNAME} || $ENV{USER};
my $mgr_bin = `which $mgr 2>&1`;
if ($? != 0) {
print(STDERR "Failed to find pacman executable. Are you using an ArchLinux system?\n");
exit 1;
}
chomp($mgr_bin);
if ($mgr eq 'pacman' && $user ne 'root') {
$sudo = 'sudo';
}
my %pkgmgr = (
name => $mgr,
bin => $mgr_bin,
search => "$sudo $mgr_bin -Ss",
install_remote => "$sudo $mgr_bin -S",
install_local => "$sudo $mgr_bin -U",
remove => "$sudo $mgr_bin -R",
search => "$mgr_bin -Ss",
install_remote => "$mgr_bin -S",
install_local => "$mgr_bin -U",
remove => "$mgr_bin -R",
);
return \%pkgmgr;
}
sub find_local_pkg($pkgmgr, $pkg_name, $pkg_ver) {
my $pkg_file = '';
my $aur_dir = "$ENV{'XDG_CACHE_HOME'}/yay/$pkg_name";
if ($pkgmgr->{name} eq 'yay' && -d $aur_dir) {
$pkg_file = `ls $aur_dir/$pkg_name-$pkg_ver-*.pkg.tar.zst | tail -n1`;
} else {
$pkg_file = `ls /var/cache/pacman/pkg/$pkg_name-$pkg_ver-*.pkg.tar.zst | tail -n1`;
}
chomp($pkg_file);
return $pkg_file;
}
getopts("irt:dvh", \my %opts);
if ($opts{'v'}) {
@ -207,27 +186,3 @@ my @undo_txs = &read_txs($num_txs);
# Interactive mode
@undo_txs = &select_txs(@undo_txs) unless ($r_flag);
my $remove_pkgs = ""; # executed via -R
my $remote_install_pkgs = ""; # executed via -S
my $local_install_pkgs = ""; # executed via -U
foreach my $tx (@undo_txs) {
if ($tx->{action} eq 'installed') {
$remove_pkgs .= "$tx->{pkg_name} ";
} elsif ($tx->{action} eq 'removed') {
# TODO: install local package if available
$remote_install_pkgs .= "$tx->{pkg_name} ";
} else {
my $pkg_file = &find_local_pkg($pkgmgr, $tx->{pkg_name}, $tx->{oldver});
if ($pkg_file eq '') {
$remote_install_pkgs .= "$tx->{pkg_name} ";
} else {
$local_install_pkgs .= "$pkg_file ";
}
}
}
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 '');