Created
December 19, 2016 18:19
-
-
Save egg82/6be9c64aabe5cc638f552edddf2eba08 to your computer and use it in GitHub Desktop.
Apply New Kernel Debs (Cron-able)
This file contains 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
#!/bin/bash | |
cd /mnt/build-bucket/grsec-kernel/ | |
last=`ls -t linux-headers-*.deb | xargs -L 1 basename | sed -n 1p` | |
version=`echo $last | cut -d - -f 3` | |
currentversion=`uname -r | cut -d - -f 1` | |
pkg=`echo "linux-*"$version"*.deb"` | |
if [ $version == $currentversion ]; then | |
exit | |
fi | |
echo Installing new kernel.. | |
dpkg -i $pkg | |
echo Removing old kernels.. | |
dpkg -l linux-{image,headers}-* | \ | |
awk '/^ii/{print $2}' | \ | |
egrep '[0-9]+\.[0-9]+\.[0-9]+' | \ | |
awk 'BEGIN{FS="-"}; {if ($3 ~ /[0-9]+/) print $3"-"$4,$0; else if ($4 ~ /[0-9]+/) print $4"-"$5,$0}' | \ | |
sort -k1,1 --version-sort -r | \ | |
sed -e "1,/$(uname -r | cut -f1,2 -d"-")/d" | \ | |
grep -v -e `uname -r | cut -f1,2 -d"-"` | \ | |
awk '{print $2}' | \ | |
xargs apt-get -y purge | |
update-grub | |
echo Restarting.. | |
reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment