88 lines
3.5 KiB
Plaintext
88 lines
3.5 KiB
Plaintext
|
#!/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
|