Created
January 15, 2024 09:32
-
-
Save kidpixo/8197d338df09c01c95a047230d70876b to your computer and use it in GitHub Desktop.
python script for Arch based distro : check loaded kernel, pacman latest kernel and show in color if they the same (green) or different (red).
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 python3 | |
import subprocess | |
import re | |
PACMAN_KERNEL_VERSION = subprocess.getoutput("pacman -Qi linux | sed -n -e '/Version/p'").split(':')[1].strip().split('.') | |
RUNNING_KERNEL_VERSION = subprocess.getoutput("uname -a") .split(' ')[2].strip().split('.') | |
if len(RUNNING_KERNEL_VERSION) != 4: | |
tmp=re.split(r'-', RUNNING_KERNEL_VERSION[-1],1) | |
RUNNING_KERNEL_VERSION[-1] = tmp[0] | |
RUNNING_KERNEL_VERSION.append(tmp[1]) | |
names = [ | |
'Kernel Version', | |
'Major Revision', | |
'Minor Revision', | |
'Patch number'] | |
# define colors | |
RED = '\033[31m' # mode 31 = red forground | |
GREEN = '\033[32m' # mode 32 = green forground | |
RESET = '\033[0m' # mode 0 = reset | |
print('{:14} : {:8} : {:7}'.format('number','pacman','running')) | |
print('-'*35) | |
for k,p,r in zip(names,PACMAN_KERNEL_VERSION,RUNNING_KERNEL_VERSION): | |
if p == r: | |
print(f'{GREEN}{k:14} : {p:7} == {r:7}',RESET) | |
else: | |
print(f'{RED}{k:14} : {p:7} != {r:7} <-- DIFFERENT!','-'*20,RESET) | |
print('-'*35) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment