Compare commits
2 Commits
c08a9f4b40
...
b30dea35b8
Author | SHA1 | Date | |
---|---|---|---|
b30dea35b8 | |||
d90016fd8c |
55
pacundo.pl
55
pacundo.pl
@ -141,25 +141,46 @@ $n, $tx->{action}, $tx->{pkg_name}
|
||||
sub get_pkgmgr() {
|
||||
# TODO: autodetect AUR helper
|
||||
my $mgr = $ENV{DEFAULT_PKGMGR} // 'pacman';
|
||||
my $mgr_bin = `which $mgr 2>&1`;
|
||||
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 => "$mgr_bin -Ss",
|
||||
install_remote => "$mgr_bin -S",
|
||||
install_local => "$mgr_bin -U",
|
||||
remove => "$mgr_bin -R",
|
||||
search => "$sudo $mgr_bin -Ss",
|
||||
install_remote => "$sudo $mgr_bin -S",
|
||||
install_local => "$sudo $mgr_bin -U",
|
||||
remove => "$sudo $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'}) {
|
||||
@ -186,3 +207,27 @@ 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 '');
|
||||
|
Loading…
Reference in New Issue
Block a user