Quote:
Originally Posted by chrisridd
As an aside, how do folks generally manage upgrading from a previous patched firmware? By that I mean: I'd enabled a bunch of patches on 4.4.9344 (say), and now I want "the same" things enabled on 4.5.9587.
|
I wrote a Perl script that takes as input a list of patch names to be activated, and does that.
The config file (named enabled_patches.conf) in my case is
Code:
Custom left & right margins
Custom page refresh options
Fix three KePub fullScreenReading bugs
Change dicthtml strings to micthtml
Fix page breaks bug
Default ePub monospace font (Courier)
Custom reading footer style
Dictionary frame size - beta8
Increase The Cover Size In Library
Increasing The View Details Container
New home screen increasing cover size
Reading stats/Author name cut when the series is showing bug fix
and the perl code is
Code:
#!/usr/bin/perl
$^W = 1;
use strict;
use File::Copy qw(copy);
use Getopt::Long;
my $opt_conf = 'enabled_patches.conf';
my $opt_patchdir;
my $opt_help = 0;
my %patches;
GetOptions(
"config-file|c=s" => \$opt_conf,
"patch-dir|p=s" => \$opt_patchdir,
"help|h|?" => \$opt_help
) || die ("Unknown option: $!");
if ($opt_help) {
print "prepare-patch-files [-p <patch_dir>] [-c <config>]
Prepares the Kobo patcher .patch files according to the config file,
which defaults to 'enabled_patches.conf'.
Format of this files is the one patch name per line, empty lines are
ignored. All the patches listed in this file are activated, all others
are deactivated.
If the option 'patch-dir' is not given, the directory of patches is
searched in the current directory under the name N.N.NNNN_source.
";
exit(0);
}
die ("config file not readable: $opt_conf") if (! -r $opt_conf);
open CONF, "<", $opt_conf || die("Cannot open $opt_conf: $!");
while (<CONF>) {
s/\r?\n$//;
next if (m/^\s*$/);
$patches{$_} = 1;
}
close(CONF) || warn("Cannot close $opt_conf, continuing anyway: $!");
# search for patch dir
if (!defined($opt_patchdir)) {
opendir my $dh, "." || die("Cannot open '.' for reading: $!");
while (my $entry = readdir $dh) {
if ($entry =~ m/^\d\.\d\.\d\d\d\d_source$/) {
$opt_patchdir = $entry;
print "found patch dir $opt_patchdir\n";
}
}
# closedir not necessary, $dh goes out of scope so handle will be closed
}
die ("Cannot find patch directory!") if (!defined($opt_patchdir));
opendir my $pd, $opt_patchdir || die ("Cannot open $opt_patchdir: $!");
while (my $pfname = readdir $pd) {
if ($pfname =~ m/^.*\.patch$/) {
copy("$opt_patchdir/$pfname", "$opt_patchdir/$pfname.orig") || die ("Cannot make backup $opt_patchdir/$pfname.orig: $!");
open (my $pfold, "<", "$opt_patchdir/$pfname.orig") || die ("Cannot open $opt_patchdir/$pfname.orig: $!");
open (my $pfnew, ">", "$opt_patchdir/$pfname") || die ("Cannot open $opt_patchdir/$pfname for writing: $!");
my $enable_patch = 0;
my $patch_name;
while (my $l = <$pfold>) {
# we cannot use chomp as it depends on $/ and might not chop of \r
$l =~ s/\r?\n$//;
if ($l =~ m/^patch_name = `(.*)`\s*$/) {
$patch_name = $1;
# default to be disabled
$enable_patch = 0;
if (defined($patches{$patch_name})) {
$enable_patch = 1;
# memorize that we found that patch
$patches{$patch_name} = 0;
}
print $pfnew "$l\n";
} elsif ($l =~ m/^patch_enable = `(.*)`\s*$/) {
print $pfnew "patch_enable = `", ($enable_patch ? "yes" : "no"), "`\n";
print(($enable_patch ? "Enabling" : "Disabling"), " patch $patch_name\n");
} else {
print $pfnew "$l\n";
}
}
close $pfold || warn("Cannot close $pfname.orig: $!");
close $pfnew || warn("Cannot close $pfname: $!");
}
}
closedir($pd);
# check whether all patches to be enabled have been found
my $warning = "The following patches are listed in the config file
but haven't been found in any of the patches,
please check them!
";
my $do_warn = 0;
for my $k (keys %patches) {
if ($patches{$k}) {
# we have set all found patches to 0, so this one wasn't found
$warning .= " $k\n";
$do_warn = 1;
}
}
print $warning if ($do_warn);
print "All done.\n";
exit(0);
Hope that helps