Testing release

This commit is contained in:
toloveru 2017-04-03 19:45:41 +02:00
parent e9909cb6aa
commit 21d8d38284
4 changed files with 135 additions and 1 deletions

View File

@ -1 +1,26 @@
# kernelcheck # Introduction
Ever thought of compiling a custom kernel, but held back because of the need for manual tracking, compilation and installation? Well, I say no more. This tool can do it for you.
# What does it do?
* Periodically check for updates on kernel.org
* Download a new kernel if available
* Verify the kernel signature
* Compile and install the kernel
* Nofity the users about what is going on (tested only on Xfce).
* Remove a distribution kernel if present (currently only on Arch and Manjaro).
# This script runs as root. Isn't that unsafe?
In a non-interactive script, it's much easier to run priveleged by default and drop priveleges as needed, instead of requiring authentication every time. If you have a fully non-interactive way of achieving this though, feel free to open a pull request.
# I want to use this code in my own projects. What license do you use?
This work is licensed under the CC BY-NC 4.0 license, which you can read more about [here](https://creativecommons.org/licenses/by-nc/4.0/legalcode).
In a nutshell, this means:
* You can copy and redistribute the material in any medium or format.
* You can remix, transform, and build upon the material.
Provided that:
* You give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggest the licensor endorses you or your use.
* You do not use the material for commercial purposes.
# Contact me
If you have any questions, encountered bugs, feature requests, etc. about this project, please send me a message at facebook.com/irc.condor, and I'll get back to you as soon as possible.
If you find this an interesting project, consider following me there also!

9
install Normal file
View File

@ -0,0 +1,9 @@
#!/bin/sh
sudo cp -v kernelcheck /usr/local/sbin/kernelcheck
sudo cp -v notify_all /usr/local/sbin/notify_all
printf "Adding hourly service to cron scheduler..\n"
(sudo crontab -l; echo "@hourly /usr/local/sbin/kernelcheck" ) | sudo crontab -
printf "Enabling cronie scheduler..\n" # Let me know if you use something else, and enable manually.
sudo systemctl start cronie.service
sudo systemctl enable cronie.service
printf "Installation complete.\n"

87
kernelcheck Executable file
View File

@ -0,0 +1,87 @@
#!/bin/sh
# Variables
latest="$(wget -qO - 'https://kernel.org' | sed -n '/stable:/{n;p;}' | sed 's.[a-z]\|<\|>\|/\|[[:space:]]..g')"
current="$(uname -r)"
user="$(users)"
cores=$(nproc)
# Function body
function verify(){
local sign=$1 out=
gkh="647F28654894E3BD457199BE38DBBDC86092693E" # Kroah-Hartman's key
lt="ABAF11C65A2970B130ABE3C479BE3E4300411886" # Torvalds' key
if out=$(sudo -u $user gpg --status-fd 1 --verify "$sign" 2>/dev/null) && echo "$out" | grep -qs "^\[GNUPG:\] VALIDSIG $gkh"
then
return 0
elif out=$(sudo -u $user gpg --status-fd 1 --verify "$sign" 2>/dev/null) && echo "$out" | grep -qs "^\[GNUPG:\] VALIDSIG $lt"
then
return 0
else
echo "$out" >&2
return 1
fi
}
if [[ "$latest" != "$current" ]] && [[ ! -z $latest ]]
then
/usr/local/sbin/notify_all "Kernel update tracker" "There's a new kernel available\!\nGetting the kernel for you.." --icon=dialog-information
download="$(wget -qO - 'https://kernel.org' | sed -n '/latest_link/{n;p;}' | cut -d '"' -f2)"
sudo -u $user wget -qP /tmp $download
sudo -u $user wget -qP /tmp $(sed 's/.xz/.sign/' <<< $download)
/usr/local/sbin/notify_all "Kernel update tracker" "Kernel downloaded\!\nNow extracting and verifying." --icon=dialog-information
sudo -u $user unxz /tmp/linux-$latest.tar.xz
if verify /tmp/linux-$latest.tar.sign
then
/usr/local/sbin/notify_all "Kernel update tracker" "Verification success\!\nStarting compilation.." --icon=dialog-information
else
/usr/local/sbin/notify_all "Kernel update tracker" "Couldn't verify the kernel. Quitting\!" --icon=dialog-warning
exit 1
fi
tar xf /tmp/linux-$latest.tar
cd /tmp/linux-$latest
make clean &>/dev/null
make mrproper &>/dev/null
if [ -f "/root/.config/kernel/.config" ]
then
cp /root/.config/kernel/.config /tmp/linux-$latest/.config
else
/usr/local/sbin/notify_all "Kernel update tracker" "No config file found\!\nAdd it to /root/.config/kernel/.config" --icon=dialog-warning
exit 1
fi
/usr/local/sbin/notify_all "Kernel update tracker" "Starting kernel build..\nThis can take a while."
make -j$cores &>/dev/null
make modules_install &>/dev/null
cp arch/$(uname -m)/boot/bzImage /boot/vmlinuz-$latest
mkinitcpio -k $latest -g /boot/initramfs-$latest.img &>/dev/null
if [ "$(echo $(uname -r) | sed 's/ARCH//')" != "$(uname -r)" ]
then
/usr/local/sbin/notify_all "Kernel update tracker" "Removing the Arch distribution kernel.." --icon=dialog-information
pacman -R --noconfirm linux
elif [ "$(echo $(uname -r) | sed 's/MANJARO//')" != "$(uname -r)" ]
then
/usr/local/sbin/notify_all "Kernel update tracker" "Removing the Manjaro distribution kernel.." --icon=dialog-information
pacman -R --noconfirm linux
else
/usr/local/sbin/notify_all "Kernel update tracker" "Removing the current kernel.." --icon=dialog-information
rm -f /boot/initramfs-$current.img
rm -f /boot/vmlinuz-$current
rm -rf /usr/lib/modules/$current
fi
grub-mkconfig -o /boot/grub/grub.cfg &>/dev/null
/usr/local/sbin/notify_all "Kernel update tracker" "New kernel installed\!" --icon=dialog-information
elif [[ "$latest" == "$current" ]] && [[ ! -z $latest ]]
then
exit 0
elif [[ -z $latest ]]
then
if ncat -zw1 kernel.org 443
then
/usr/local/sbin/notify_all "Kernel update tracker" "Website didn't return the required data." --icon=dialog-warning
else
/usr/local/sbin/notify_all "Kernel update tracker" "No network connection." --icon=dialog-information
fi
else
/usr/local/sbin/notify_all "Kernel update tracker" "Internal error.. Debug time\!" --icon=dialog-warning
exit 1
fi

13
notify_all Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
PATH=/usr/bin
XUSERS=($(who|egrep "\(:[0-9](\.[0-9])*\)"|awk '{print $1$5}'|sort -u))
for XUSER in $XUSERS; do
NAME=(${XUSER/(/ })
DISPLAY=${NAME[1]/)/}
DBUS_ADDRESS=unix:path=/run/user/$(id -u ${NAME[0]})/bus
sudo -u ${NAME[0]} DISPLAY=${DISPLAY} \
DBUS_SESSION_BUS_ADDRESS=${DBUS_ADDRESS} \
PATH=${PATH} \
notify-send "$@"
done