Last active
February 27, 2024 00:16
-
-
Save rage311/fa69eaac953a1653d3c942cc873fa981 to your computer and use it in GitHub Desktop.
Arch Linux zen kernel minor version pinning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/pacman.d/hooks/zen_kernel_version_pin.hook | |
[Trigger] | |
Operation = Upgrade | |
Type = Package | |
Target = linux-zen | |
Target = linux-zen-headers | |
[Action] | |
Description = Prevent zen kernel from upgrading past X.Y major.minor version | |
When = PreTransaction | |
Exec = PATH/TO/zen_kernel_version_pinning_hook.pl | |
AbortOnFail = True | |
Depends = perl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use 5.036; | |
use Archive::Tar; | |
### check uname -r (best way?) to see current version | |
# ex: | |
# 6.7.6-zen1-1-zen | |
# use version of installed zen kernel instead? (in case of currently running other kernel) | |
my $uname = `/usr/bin/env uname -r`; | |
my $current->@{qw/ major minor patch /} = $uname =~ /(\d+)\.(\d+)\.(\d+)-zen.*/; | |
die "No current 'major.minor.patch' pattern from regex in uname -r" | |
unless defined $current->{major} | |
&& defined $current->{minor} | |
&& defined $current->{patch}; | |
### check extra.db to see the new version | |
# really a .tar.gz | |
# /var/lib/pacman/sync/extra.db | |
# after extraction, directories like: | |
# ./linux-zen-6.7.6.zen1-1/desc (all that's in dirs) | |
my $tar = Archive::Tar->new; | |
$tar->read('/var/lib/pacman/sync/extra.db', 1); | |
my @target = grep { /linux-zen-\d+\.\d+\.\d+/ } $tar->list_files(); | |
my $new->@{qw/ major minor patch /} = $target[0] =~ /linux-zen-(\d+)\.(\d+)\.(\d+)/; | |
die "No new 'major.minor.patch' pattern from regex in pacman db tar archive" | |
unless defined $new->{major} | |
&& defined $new->{minor} | |
&& defined $new->{patch}; | |
### see if it's still in the major/minor version | |
my $eligible = | |
$current->{major} >= $new->{major} | |
&& $current->{minor} >= $new->{minor}; | |
say "Current (running) zen kernel: ", join '.', $current->@{qw/ major minor patch /}; | |
my $new_version_str = join '.', $new->@{qw/ major minor patch /}; | |
say "Update candidate zen kernel: $new_version_str"; | |
# JustUnixThings | |
if ($eligible) { | |
# all good | |
exit 0; | |
} else { | |
say "Installing linux-zen kernel $new_version_str" | |
. " violates major/minor version pinning to version " | |
. join '.', $current->@{qw/ major minor /}, 'X' | |
. "\n"; | |
exit 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment