Compare commits
No commits in common. "8a62fc9064a7fffa9677c1e963b7975dc0d1fcee" and "bea2957889c182c9912956342f24c08276256128" have entirely different histories.
8a62fc9064
...
bea2957889
144
pacundo.pl
144
pacundo.pl
@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use feature qw(signatures);
|
|
||||||
|
|
||||||
use Getopt::Std;
|
use Getopt::Std;
|
||||||
use File::ReadBackwards;
|
use File::ReadBackwards;
|
||||||
@ -32,12 +31,15 @@ use File::ReadBackwards;
|
|||||||
my $VERSION = "1.0";
|
my $VERSION = "1.0";
|
||||||
my $PROG_NAME = "pacundo";
|
my $PROG_NAME = "pacundo";
|
||||||
|
|
||||||
sub print_version() {
|
my $r_flag = 0;
|
||||||
|
my $dry_run = 0;
|
||||||
|
my $num_txs = 1;
|
||||||
|
|
||||||
|
sub print_version {
|
||||||
print("$PROG_NAME v$VERSION\n");
|
print("$PROG_NAME v$VERSION\n");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub print_help() {
|
sub print_help {
|
||||||
&print_version();
|
&print_version();
|
||||||
print("A time machine to return your ArchLinux machine back to a working state.\n");
|
print("A time machine to return your ArchLinux machine back to a working state.\n");
|
||||||
print("\nUSAGE:
|
print("\nUSAGE:
|
||||||
@ -52,95 +54,6 @@ OPTIONS:
|
|||||||
-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");
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub read_txs($num_txs = 1) {
|
|
||||||
my $found_txs = 0;
|
|
||||||
my $in_tx = 0;
|
|
||||||
my @undo_txs;
|
|
||||||
my $pacman_log = File::ReadBackwards->new("/var/log/pacman.log") ||
|
|
||||||
die("Failed to load pacman log file.\n$!");
|
|
||||||
|
|
||||||
while ($found_txs < $num_txs && defined(my $line = $pacman_log->readline)) {
|
|
||||||
unless ($in_tx) {
|
|
||||||
# Remeber that we're reading this in reverse order
|
|
||||||
if ($line =~ /\[ALPM\] transaction completed/) {
|
|
||||||
$in_tx = 1;
|
|
||||||
}
|
|
||||||
} elsif ($line =~ /\[ALPM\] transaction started/) {
|
|
||||||
$found_txs++;
|
|
||||||
$in_tx = 0;
|
|
||||||
} elsif ($line =~ /\[ALPM\] (upgraded|downgraded)/) {
|
|
||||||
my ($action, $pkg_name, $oldver, $newver) =
|
|
||||||
$line =~ /\[ALPM\] (upgraded|downgraded) ([^\s]+) \((.*) -> (.*)\)/;
|
|
||||||
push(@undo_txs,
|
|
||||||
{
|
|
||||||
'action' => $action,
|
|
||||||
'pkg_name' => $pkg_name,
|
|
||||||
'oldver' => $oldver,
|
|
||||||
'newver' => $newver,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} elsif ($line =~ /\[ALPM\] (installed|removed)/) {
|
|
||||||
my ($action, $pkg_name) = $line =~ /\[ALPM\] (installed|removed) ([^\s]+)/;
|
|
||||||
push(@undo_txs,
|
|
||||||
{
|
|
||||||
'action' => $action,
|
|
||||||
'pkg_name' => $pkg_name,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return @undo_txs;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub select_txs(@undo_txs) {
|
|
||||||
print("Last changes:\n");
|
|
||||||
|
|
||||||
my $n = 1;
|
|
||||||
|
|
||||||
foreach my $tx (@undo_txs) {
|
|
||||||
format UPGRFORMAT =
|
|
||||||
@|| @<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<< -> @<<<<<<<<<<<<<
|
|
||||||
$n, $tx->{action}, $tx->{pkg_name}, $tx->{oldver}, $tx->{newver}
|
|
||||||
.
|
|
||||||
format INSTFORMAT =
|
|
||||||
@|| @<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|
||||||
$n, $tx->{action}, $tx->{pkg_name}
|
|
||||||
.
|
|
||||||
|
|
||||||
local $~ = ($tx->{action} =~ /(upgraded|downgraded)/) ? "UPGRFORMAT" : "INSTFORMAT";
|
|
||||||
write();
|
|
||||||
|
|
||||||
$n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
print("Select transactions to undo (e.g. '1 2 3', '1-3')\n");
|
|
||||||
print("> ");
|
|
||||||
|
|
||||||
my @sel = split(' ', <STDIN>);
|
|
||||||
|
|
||||||
foreach my $i (@sel) {
|
|
||||||
if ($i =~ /^[0-9]+-[0-9]+$/) {
|
|
||||||
my ($start, $end) = $i =~ /^([0-9]+)-([0-9]+)$/;
|
|
||||||
if ($start >= $end) {
|
|
||||||
die("Invalid range: $start-$end\n");
|
|
||||||
}
|
|
||||||
push(@sel, ($start..$end));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@sel = sort grep({!/[0-9+]-[0-9+]/} @sel);
|
|
||||||
|
|
||||||
my @sel_undo;
|
|
||||||
|
|
||||||
foreach my $i (@sel) {
|
|
||||||
push(@sel_undo, $undo_txs[$i-1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return @sel_undo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getopts("irt:dvh", \my %opts);
|
getopts("irt:dvh", \my %opts);
|
||||||
@ -160,11 +73,44 @@ if ($opts{'v'}) {
|
|||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $r_flag = $opts{'r'} // 0;
|
$r_flag = 1 if ($opts{'r'});
|
||||||
my $dry_run = $opts{'d'} // 0;
|
$dry_run = 1 if ($opts{'d'});
|
||||||
my $num_txs = $opts{'t'} // 1;
|
$num_txs = $opts{'t'} if ($opts{'t'});
|
||||||
|
|
||||||
my @undo_txs = &read_txs($num_txs);
|
my $pacman_log = File::ReadBackwards->new("/var/log/pacman.log") or
|
||||||
|
die("Failed to load pacman log file.\n$!");
|
||||||
|
|
||||||
# Interactive mode
|
my $found_txs = 0;
|
||||||
@undo_txs = &select_txs(@undo_txs) unless ($r_flag);
|
my $in_tx = 0;
|
||||||
|
|
||||||
|
my @undo_txs;
|
||||||
|
|
||||||
|
while ($found_txs < $num_txs && defined(my $line = $pacman_log->readline)) {
|
||||||
|
# Remeber that we're reading this in reverse order
|
||||||
|
if (!$in_tx && $line =~ /\[ALPM\] transaction completed/) {
|
||||||
|
$in_tx = 1;
|
||||||
|
} elsif ($in_tx) {
|
||||||
|
if ($line =~ /\[ALPM\] transaction started/) {
|
||||||
|
$found_txs++;
|
||||||
|
$in_tx = 0;
|
||||||
|
} elsif ($line =~ /\[ALPM\] (upgraded|downgraded)/) {
|
||||||
|
my ($action, $pkg_name, $oldver, $newver) = $line =~ /\[ALPM\] (upgraded|downgraded) ([^\s]+) \((.*) -> (.*)\)/;
|
||||||
|
push(@undo_txs,
|
||||||
|
{
|
||||||
|
'action' => $action,
|
||||||
|
'pkg_name' => $pkg_name,
|
||||||
|
'oldver' => $oldver,
|
||||||
|
'newver' => $newver,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} elsif ($line =~ /\[ALPM\] (installed|removed)/) {
|
||||||
|
my ($action, $pkg_name) = $line =~ /\[ALPM\] (installed|removed) ([^\s]+)/;
|
||||||
|
push(@undo_txs,
|
||||||
|
{
|
||||||
|
'action' => $action,
|
||||||
|
'pkg_name' => $pkg_name,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user