Search pacman for latest kernel in script

#1

Hi there,
I have two strings, runnung kernel and installed kernel:

uname -r | cut -d- -f1,2,3

5.0.3-arch1-1

pacman -Q linux | cut -d’ ’ -f2 | sed -e ‘s/.([^.]*)$/-\1/’

5.0.4-arch1-1
I am seeking a way to get a similar string containing the latest kernel in the repo, but unfortunately none of my approaches succeed. If you have any idea I’d highly appreciate!

0 Likes

#2

I do not understand the issue

[don@don-pc ~]$ uname -r | cut -d- -f1,2,3
5.0.4-zen1-1
[don@don-pc ~]$ 

even if that’s enough?

[don@don-pc ~]$ uname -a
Linux don-pc 5.0.4-zen1-1-zen #1 ZEN SMP PREEMPT Sat Mar 23 20:59:30 UTC 2019 x86_64 GNU/Linux
[don@don-pc ~]$ 
0 Likes

#3

Ive no idea about sed commands but a simple
pacman -Si linux
shows latest kernel in repo.

1 Like

#4

Thank you very much, @s7l!

pacman -Si linux | sed -n 3p | cut -d: -f2 | tr -d " " | sed -e ‘s/.([^.]*)$/-\1/’

gave me the output I need:
5.0.4-arch1-1

1 Like

#5

Those output are supposed to match, looks like you may have had your /boot partition unmounted during a kernel upgrade.

I am surprised you can boot at all tbh.

1 Like

#6

Question: could it have two kernels and start with the second one?

0 Likes

#7

Glad that helped entropy, can i ask what you are doing, what sort of script your putting together?

1 Like

#8

@Head_on_a_Stick: This is after kernel update not yet rebooted. uname -r output running kernel, pacman -Q linux installed kernel and pacman -Si linux latest kernel available.
@ector: No!
@s7l: I am sometimes lazy rebooting what can lead to something not working, like android usb tethering, CPU downvolting etc. So I setup script to show if I am running latest kernel installed and thought it would be nice if it would also show if there is an even newer kernel available, before I reboot. Will post here once I finished. Thanks again for your solution!

1 Like

#9
#! /usr/bin/env zsh
installed_kernel=$(pacman -Q linux | cut -d' ' -f2 | sed -e 's/.\([^.]*\)$/-\1/')
running_kernel=$(uname -r | cut -d- -f1,2,3)
available_kernel=$(pacman -Si linux | sed -n 3p | cut -d: -f2 | tr -d " " | sed -e 's/.\([^.]*\)$/-\1/')

# DEBUG
#echo -e "running:\t$running_kernel\ninstalled:\t$installed_kernel\navailable:\t$available_kernel\n"
#installed_kernel="21301"
#running_kernel="12300"
#available_kernel="32123"
#tabs 4

if [ "$installed_kernel" = "$running_kernel" ]
	then
	echo -e "\e[32mKernel in sync!\t\e[1m$running_kernel\e[0m"
	if [ "$running_kernel" != "$available_kernel" ]
		then
		echo -e "However, new kernel available:\t\e[33m\e[1m$available_kernel\e[0m"
	fi
else
	echo -e "\e[31mkernel out of sync!\e[0m"
	echo -e "running:\t\e[31m\e[1m$running_kernel\n\e[0minstalled:\t\e[32m\e[1m$installed_kernel\e[0m"
	if [ "$installed_kernel" != "$available_kernel" ]
		then
		echo -e "available:\t\e[33m\e[1m$available_kernel\e[0m"
	fi
	read -k 1 "REPLY?Reboot new kernel now? (y/n)"
	if [[ "$REPLY" =~ ^[Yy]$ ]]
		then
		reboot
	else
		exit 1
	fi
fi
1 Like

#11

thank @entr0py
my test

[don@don-pc ~]$ /home/don/Script/control.sh
kernel out of sync!
running:	5.0.4-zen1-1
installed:	4.8-14-1
available:	5.0.4-arch1-1
Reboot new kernel now? (y/n)n[don@don-pc ~]$ 
1 Like

#12

Thank you @ector!
Looks pretty buggy, as my script can’t handle different kernels! Could you please post the output of:
uname -a && pacman -Q linux && pacman -Si linux

0 Likes

#13

Ah yes, that would explain things :slight_smile:

Note that pacman -Si linux and pacman -Qi linux should always match:

https://wiki.archlinux.org/index.php/System_maintenance#Partial_upgrades_are_unsupported

It is not safely possible to update the package database and leave the packages un-upgraded, this is why ArchLabs’ update checker does it work in a chroot.

1 Like

#14
 
[don@don-pc ~] 
[don@don-pc ~]$ uname -a && pacman -Q linux && pacman -Si linux
Linux don-pc 5.0.4-zen1-1-zen #1 ZEN SMP PREEMPT Sat Mar 23 20:59:30 UTC 2019 x86_64 GNU/Linux
[sudo] password di don: 
linux 4.8.14-1
Repository                : core
Nome                      : linux
Versione                  : 5.0.4.arch1-1
Descrizione               : The Linux kernel and modules
Architettura              : x86_64
URL                       : https://git.archlinux.org/linux.git/log/?h=v5.0.4-arch1
Licenze                   : GPL2
Gruppi                    : base
Fornisce                  : Nessuno
Dipenda da                : coreutils  linux-firmware  kmod  mkinitcpio
Dipendenze opzionali      : crda: to set the correct wireless channels of your
                            country
Conflitti con             : Nessuno
Sostituisce               : Nessuno
Dimensione del download   : 70,66 MiB
Spazio richiesto          : 75,40 MiB
Pacchettizzatore          : Jan Alexander Steffens (heftig)
                            <jan.steffens@gmail.com>
Data di creazione         : sab 23 mar 2019 21:57:31 CET
Convalidato da            : Somma MD5  Somma SHA-256  Firma

[don@don-pc ~]$ 

edit
I have two kenels installed
this is correct
4.8-14-1

0 Likes

#15

Hmm, I’m a bit confused. I guess you are running zen actual zen kernel, which you installed while 4.8.14-1 was actual?
Anyway, I have no clue how to adopt the script to this situation, as I have never used anything but stock stock kernels.

0 Likes

#16

yes,booting the zen kernel, 4.18 is for emergencies, in case you don’t start zen when I update the kernel.
Cheers

0 Likes