Compare commits
12 Commits
b2f5793c21
...
v1.0.1
Author | SHA1 | Date | |
---|---|---|---|
858d44b5ca | |||
e18136e43c | |||
d692d4aa59 | |||
1516ce9ff3 | |||
555ead272e | |||
d616930208 | |||
347b49d5ee | |||
641163a495 | |||
75c663eb1e | |||
8525b7f4e8 | |||
e6d814d438 | |||
a7bae301b3 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
pacundo
|
||||
pacundo.1.gz
|
||||
|
6
Makefile
6
Makefile
@ -20,7 +20,9 @@
|
||||
# 3. This notice may not be removed or altered from any source
|
||||
# distribution.
|
||||
|
||||
PREFIX=/usr/local
|
||||
ifeq ($(PREFIX),)
|
||||
PREFIX := /usr/local
|
||||
endif
|
||||
|
||||
pacundo: pacundo.pl
|
||||
pp -o $@ $^
|
||||
@ -35,5 +37,7 @@ clean:
|
||||
$(RM) pacundo.1.gz
|
||||
|
||||
install: pacundo pacundo.1.gz
|
||||
install -d $(PREFIX)/bin
|
||||
install -m 755 pacundo $(PREFIX)/bin/
|
||||
install -d $(PREFIX)/share/man/man1
|
||||
install -m 644 pacundo.1.gz $(PREFIX)/share/man/man1/
|
||||
|
31
README.md
31
README.md
@ -7,7 +7,7 @@ to boot from a USB depending on just how broken it is).
|
||||
|
||||
## Installation
|
||||
|
||||
Dependencies:
|
||||
### Dependencies
|
||||
|
||||
- Perl 5
|
||||
- `File::ReadBackwards` module
|
||||
@ -20,6 +20,35 @@ You can install these packages with the following command:
|
||||
# pacman -S perl perl-file-readbackwards perl-par-packer
|
||||
```
|
||||
|
||||
### Compiling & Installing
|
||||
|
||||
The script is compiled and installed using GNU Makefile. Therefore you can use
|
||||
`make install` to build and install the script and its man-page as expected.
|
||||
They are installed (by default) to `/usr/local`. To change this to a different
|
||||
directory simply prepend the `PREFIX=<path>` to your `make install` command.
|
||||
|
||||
## Usage
|
||||
|
||||
The first concept to understand is that of a transaction. A transaction is
|
||||
defined in the pacman logs as package operations done during a single use of the
|
||||
command (or so it seems, at least). If you look at the logs
|
||||
(`/var/log/pacman.log`) this would be everything between the lines `[ALPM]
|
||||
transaction started` and `[ALPM] transaction completed`. You can set how many
|
||||
transactions to list/undo by using the `-t` argument.
|
||||
|
||||
There are two modes for undoing pacman transactions:
|
||||
|
||||
- Interactive (`-i`, default): will show you a numbered list with all the package
|
||||
operations of the selected transactions.
|
||||
- Automatic (`-r`): will automatically undo all package operations of the
|
||||
selected transactions.
|
||||
|
||||
Look at the man-page (`man pacundo`) for more information.
|
||||
|
||||
### Supported AUR Helpers
|
||||
|
||||
- [yay](https://github.com/Jguer/yay)
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the terms & conditions of the Zlib license.
|
||||
|
15
pacundo.1
15
pacundo.1
@ -1,4 +1,4 @@
|
||||
.TH PACUNDO "1" "April 2024" "pacundo 1.0" "User Commands"
|
||||
.TH PACUNDO "1" "April 2024" "pacundo 1.0.1" "User Commands"
|
||||
.SH "NAME"
|
||||
pacundo - A time machine to return your ArchLinux machine back to a working state.
|
||||
.SH "SYNOPSIS"
|
||||
@ -21,19 +21,22 @@ is especially helpful if the last update broke your system for some reason.
|
||||
.SH "OPTIONS"
|
||||
.TP
|
||||
\fB\-i\fR
|
||||
Interactively select the transactions to undo (default behavior)
|
||||
Enter interactive mode to select package operations to undo (default behavior)
|
||||
.TP
|
||||
\fB\-r\fR
|
||||
Non-interactively undo transactions
|
||||
Non-interactively undo entire transactions
|
||||
.TP
|
||||
\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
|
||||
\fB\-h\fR
|
||||
Show help information
|
||||
Show this help information
|
||||
.TP
|
||||
\fB\-v\fR
|
||||
Show program version
|
||||
Print program version
|
||||
|
||||
.SH "AUTHOR"
|
||||
Written by Nicolás A. Ortega Froysa.
|
||||
|
68
pacundo.pl
68
pacundo.pl
@ -29,7 +29,7 @@ use feature qw(signatures);
|
||||
use Getopt::Std;
|
||||
use File::ReadBackwards;
|
||||
|
||||
my $VERSION = '1.0';
|
||||
my $VERSION = '1.0.1';
|
||||
my $PROG_NAME = 'pacundo';
|
||||
|
||||
sub print_version() {
|
||||
@ -47,9 +47,9 @@ USAGE:
|
||||
$PROG_NAME -v
|
||||
|
||||
OPTIONS:
|
||||
-i Enter interactive mode to select packages to downgrade [default behavior]
|
||||
-r Automatically downgrade all packages from last upgrade
|
||||
-t <num> Specify the number of transactions to include for undoing selection [default 1]
|
||||
-i Enter interactive mode to select package operations to undo (default behavior)
|
||||
-r Non-interactively undo entire transactions
|
||||
-t <num> Specify the number of transactions to include (default: 1)
|
||||
-d Dry run, i.e. don't actually do anything
|
||||
-h Show this help information
|
||||
-v Print program version\n");
|
||||
@ -139,13 +139,24 @@ $n, $tx->{action}, $tx->{pkg_name}
|
||||
# NOTE: Currently this subroutine only works for pacman and yay. You'll have to
|
||||
# add options for additional AUR helpers.
|
||||
sub get_pkgmgr() {
|
||||
# TODO: autodetect AUR helper
|
||||
my $mgr = $ENV{DEFAULT_PKGMGR} // 'pacman';
|
||||
my $mgr = '';
|
||||
my $mgr_bin;
|
||||
my @supported_mgrs = (
|
||||
'yay',
|
||||
'pacman',
|
||||
);
|
||||
my $sudo = '';
|
||||
my $user = $ENV{LOGNAME} || $ENV{USER};
|
||||
|
||||
my $mgr_bin = `which $mgr 2>&1`;
|
||||
if ($? != 0) {
|
||||
foreach my $i (@supported_mgrs) {
|
||||
$mgr_bin = `which $i 2>&1`;
|
||||
if ($? == 0) {
|
||||
$mgr = $i;
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
if ($mgr eq '') {
|
||||
print(STDERR "Failed to find pacman executable. Are you using an ArchLinux system?\n");
|
||||
exit 1;
|
||||
}
|
||||
@ -158,7 +169,8 @@ sub get_pkgmgr() {
|
||||
my %pkgmgr = (
|
||||
name => $mgr,
|
||||
bin => $mgr_bin,
|
||||
search => "$sudo $mgr_bin -Ss",
|
||||
search => "$mgr_bin -Ss",
|
||||
info => "$mgr_bin -Si",
|
||||
install_remote => "$sudo $mgr_bin -S",
|
||||
install_local => "$sudo $mgr_bin -U",
|
||||
remove => "$sudo $mgr_bin -R",
|
||||
@ -167,17 +179,33 @@ sub get_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 $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) {
|
||||
$pkg_file = `ls $aur_dir/$pkg_name-$pkg_ver-*.pkg.tar.zst | tail -n1`;
|
||||
if ($pkg_ver ne '') {
|
||||
$pkg_pat = "$pkg_name-$pkg_ver-*.pkg.tar.zst";
|
||||
} 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);
|
||||
|
||||
return $pkg_file;
|
||||
}
|
||||
|
||||
@ -216,8 +244,12 @@ 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
|
||||
my $pkg_file = &find_local_pkg($pkgmgr, $tx->{pkg_name});
|
||||
if ($pkg_file eq '') {
|
||||
$remote_install_pkgs .= "$tx->{pkg_name} ";
|
||||
} else {
|
||||
$local_install_pkgs .= "$pkg_file ";
|
||||
}
|
||||
} else {
|
||||
my $pkg_file = &find_local_pkg($pkgmgr, $tx->{pkg_name}, $tx->{oldver});
|
||||
if ($pkg_file eq '') {
|
||||
@ -228,6 +260,12 @@ foreach my $tx (@undo_txs) {
|
||||
}
|
||||
}
|
||||
|
||||
if ($dry_run) {
|
||||
print("$pkgmgr->{remove} $remove_pkgs\n") if ($remove_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 '');
|
||||
}
|
||||
|
Reference in New Issue
Block a user