aptosid.com

User Scripts & Dragons - Script to show installed and latest available kernels

ibgb - 20.09.2010, 03:38
Post subject: Script to show installed and latest available kernels
On a couple systems I have, I don't have the kernel meta-package installed and I update kernels manually.

I threw together this script a while ago to show me my installed and latest available kernels. It's nothing fancy but it does what I want it to.

Since there was a request for something like it posted in another thread, I figured I'd put this up here in case someone might be able to use it.

Just put it somewhere, make it executable, and run it as user. If you want to do an apt-get update (and you should unless you know you're current), you can do it through a prompt while running the script.
      Code:
#! /bin/bash

# Script to show installed and available kernels in
# an aptosid system


  printf "\n  Do you want to run 'apt-get update' first\n    (to make sure the latest kernel info is current)?\n\n  Enter "Y" for yes or "n" for no   " && read yn
            case $yn in
               Y|y)
                  su-to-root -c 'apt-get update' || exit 2
                 ;;

               N|n)
                  :
                 ;;

                 *)
                  printf "\n  BAD CHOICE!\n\n" && exit 1
                 ;;
            esac


  printf "\nGathering information..."

crntkern=$(uname -r)
latkern=$(apt-cache search ^linux-image slh | cut -f1 -d" " | sort -V | tail -1 | sed 's|linux-image-||')
instkern=$(find /boot/ -maxdepth 1 -type f -name vmlinuz* | sed 's|/boot/vmlinuz-||' | egrep -v "$crntkern")
arrange=$(for i in ${instkern};do
               printf "\t\t $i\n"
          done)



  printf "\n\n   The latest available kernel is:\n\t\t $latkern\n\n   The currently running kernel is:\n\t\t $crntkern\n\n   Other installed kernels are:\n $arrange\n\n"

exit 0


edit: changed "sort -n" to "sort -V" in $latkern variable to fix dumb mistake
muchan - 20.09.2010, 08:00
Post subject: RE: Script to show installed and latest available kernels
I have much simpler script for myself
      Quote:

echo "apt-get install \\"
apt-cache depends linux-image-2.6-aptosid-amd64 | awk '/ Depends/ { print $2 " \\" }'
apt-cache depends linux-headers-2.6-aptosid-amd64 | awk '/ Depends/ { print $2 }'


or for i686 version

      Quote:

echo "apt-get install \\"
apt-cache depends linux-image-2.6-aptosid-i686 | awk '/ Depends/ { print $2 " \\" }'
apt-cache depends linux-headers-2.6-aptosid-i686 | awk '/ Depends/ { print $2 }'


It generate the apt-get command to install the current version.
(redirect the out put to new script and call it with shell)

current installed version of kernel can be seen in uname -u, so it's easy for me to
decide if I want to install the new or not.

Officially recommended way is having meta-packages installed and automatically install
new kernel packages at d-u. I'm posting this above for this User script forum only.
Mte90 - 20.09.2010, 09:10
Post subject: RE: Script to show installed and latest available kernels
but an autoremover or a script that remove the oldest kernel installed after the installation of a new?

sorry for my english
muchan - 20.09.2010, 10:19
Post subject: Re: RE: Script to show installed and latest available kernel
      Mte90 wrote:
but an autoremover or a script that remove the oldest kernel installed after the installation of a new?

sorry for my english


Installation of new kernel should not remove already installed kernel.
Simply because new kernel may not work, or some devices or programs may be incompatible with the new kernel.

So, it's the administrator's (yours, for your PC) task to decide which old kernels to be removed.
se7en - 20.09.2010, 10:39
Post subject: RE: Re: RE: Script to show installed and latest available ke
I think Mte90 asks. if there is a script to remove old kernel.
kernel-remover is the script but like muchan said you should always keep at least 1 older besides the new one. Just in case the new one doesn't work.
Mte90 - 20.09.2010, 12:09
Post subject: RE: Re: RE: Script to show installed and latest available ke
It is like se7en says. I have always two versions of the kernel when I install a new version remove the oldest with kernel-remover.
If you could automate it install the new kernel and remove the old one is more practical.
blackhole - 20.09.2010, 13:08
Post subject: RE: Re: RE: Script to show installed and latest available ke
I checked the script but it is not giving me the latest kernel:

      Quote:

The latest available kernel is:
2.6.35-4.slh.6-aptosid-amd64

The currently running kernel is:
2.6.35-4.slh.15-aptosid-amd64

Other installed kernels are:
2.6.34-0.slh.11-sidux-amd64
2.6.35-4.slh.6-aptosid-amd64

cleary - 20.09.2010, 13:15
Post subject: Re: RE: Re: RE: Script to show installed and latest availabl
      blackhole wrote:
I checked the script but it is not giving me the latest kernel:

      Quote:

The latest available kernel is:
2.6.35-4.slh.6-aptosid-amd64

The currently running kernel is:
2.6.35-4.slh.15-aptosid-amd64

Other installed kernels are:
2.6.34-0.slh.11-sidux-amd64
2.6.35-4.slh.6-aptosid-amd64


I think it's a bug related to the use of the sort function...

2.6.35-4.slh.6 > 2.6.35-4.slh.1(5-aptosid-amd64)
ibgb - 20.09.2010, 18:27
Post subject: RE: Re: RE: Re: RE: Script to show installed and latest avai
blackhole

I forgot that when you put a script out there for others to use it's SUPPOSED TO WORK RIGHT! Wink

Sorry.

cleary is of course correct in pointing to my sort as the culprit. The -n option won't work here. But the -V option seems made for it and I should have used it from the beginning. It works perfectly in some quick testing I did with it.

The posted script has been updated.

Thanks to you for pointing out the problem and to cleary for pointing to the source of it.
blackhole - 21.09.2010, 13:12
Post subject: RE: Re: RE: Re: RE: Script to show installed and latest avai
However, I have something very simple for doing what sidux hermes was doing:

      Quote:

apt-get update; apt-cache search aptosid-amd64; apt-get -d dist-upgrade


You can put this text in a "link to application" for easy launch.
All times are GMT - 12 Hours
Powered by PNphpBB2 © 2003-2010 The Zafenio Group
Credits