Last active
October 1, 2017 15:56
-
-
Save paulbdavis/4744581 to your computer and use it in GitHub Desktop.
Bash Script for getting your current Linux Kernel's Codename from the kernel source makefile. Uses a cache file so it does not do excessive curl calls (especially when run in something like conky)
This file contains hidden or 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 bash | |
pattern="NAME\s\?=\s\?" | |
kernelVersion=$(uname -r | sed "s/-.*//g") | |
# strip trailing .0 version, since the git tags on kernel.org do not have them | |
kernelVersion=${kernelVersion/%".0"/} | |
cacheFile="$HOME/.kernelcodename" | |
if [ -f "$cacheFile" ] | |
then | |
cache=$(cat $cacheFile) | |
cachedVersion=$(expr "$cache" : '\([0-9.]*\)') | |
cachedName=$(expr "$cache" : '.*@\([-A-Za-z ]*\)') | |
# echo "v:$cachedVersion n:$cachedName" | |
if [ "$cachedVersion" = "$kernelVersion" ] | |
then | |
kernelCodename="$cachedName" | |
fi | |
fi | |
if [ ! "$kernelCodename" ] | |
then | |
url="http://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/plain/Makefile?id=refs/tags/v${kernelVersion}" | |
kernelCodename=$(grep $pattern <<<"$(curl -s "$url")" | sed "s/$pattern//g") | |
fi | |
echo "$kernelVersion@$kernelCodename" > "$cacheFile" | |
if [ "$1" == "-a" ] | |
then | |
echo "$kernelCodename ($kernelVersion)" | |
else | |
echo "$kernelCodename" | |
fi |
Hi git.kernel.org has moved location of Makefile again. I got mine working by updating my url to be.
url="https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/plain/Makefile?id=refs/tags/v${kernelVersion}"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the script!
I thinks that getting codename should be standard feature of uname.