2012-05-18 20:27:25 +04:00
|
|
|
#!/bin/bash
|
|
|
|
|
2013-04-01 15:07:13 +04:00
|
|
|
[ -f /etc/gentoo-upgrade.conf ] && source /etc/gentoo-upgrade.conf
|
|
|
|
|
2012-08-17 11:08:15 +04:00
|
|
|
NICE_CMD="nice -n 19 ionice -c2"
|
2012-08-17 10:51:32 +04:00
|
|
|
|
2012-05-18 20:27:25 +04:00
|
|
|
REVISION=`kernel-config list | grep \*$ | cut -d" " -f6 | cut -d- -f2-8`
|
|
|
|
[ "" == "$REVISION" ] && echo "No appropriate kernel revision found ;-(" && exit -1
|
|
|
|
|
2013-12-01 01:18:03 +04:00
|
|
|
UNAME=`uname -r`
|
|
|
|
echo UNAME=$UNAME
|
|
|
|
|
2013-04-01 15:07:13 +04:00
|
|
|
# remounting file systems ro->rw
|
|
|
|
for fs in $RW_REMOUNT; do
|
|
|
|
if [[ "$fs" =~ ^/+usr/*$ || "$fs" =~ ^/+boot/*$ ]]; then
|
|
|
|
echo "remounting $fs -> rw"
|
|
|
|
mount -o remount,rw $fs
|
|
|
|
[ 0 -ne $? ] && echo "mount -o remount,rw $fs failed ;-( =======" && exit -1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2012-05-18 20:27:25 +04:00
|
|
|
# rm old modules
|
2013-12-01 01:18:03 +04:00
|
|
|
echo REVISION=$REVISION
|
2013-07-06 12:41:00 +04:00
|
|
|
cd /lib/modules && $NICE_CMD rm -rf `ls --color=never | sort -V | grep -vE "^$REVISION$|^$UNAME$"`
|
2012-05-18 20:27:25 +04:00
|
|
|
|
|
|
|
# rm old kernel revisions
|
|
|
|
mount -o remount,rw /boot
|
2013-12-01 01:18:03 +04:00
|
|
|
cd /boot
|
|
|
|
for f in System.map config vmlinuz kernel-genkernel initramfs; do
|
2013-07-06 12:41:00 +04:00
|
|
|
rm -f `ls --color=never $f-* 2>/dev/null | sort -V | grep -vE "$REVISION$|$REVISION.img$|$UNAME$|$UNAME.img$"`
|
2013-12-01 01:18:03 +04:00
|
|
|
done
|
2013-04-01 17:47:47 +04:00
|
|
|
mount -o remount,ro -force /boot
|
2012-05-18 20:27:25 +04:00
|
|
|
|
2014-08-07 15:45:42 +04:00
|
|
|
# Updating Grub config
|
2013-07-06 12:41:00 +04:00
|
|
|
echo "Updating Grub menu"
|
2016-08-17 13:13:34 +03:00
|
|
|
if [ `which grub-mkconfig 2>/dev/null` ]; then
|
|
|
|
[ -f /boot/grub/grub.cfg ] && grub-mkconfig -o /boot/grub/grub.cfg
|
|
|
|
[ -f /boot/grub2/grub.cfg ] && grub-mkconfig -o /boot/grub2/grub.cfg
|
|
|
|
elif [ `which grub2-mkconfig 2>/dev/null` ]; then
|
2014-08-07 15:45:42 +04:00
|
|
|
[ -f /boot/grub/grub.cfg ] && grub2-mkconfig -o /boot/grub/grub.cfg
|
|
|
|
[ -f /boot/grub2/grub.cfg ] && grub2-mkconfig -o /boot/grub2/grub.cfg
|
|
|
|
else
|
|
|
|
[ -f /boot/grub/grub.conf ] && \
|
|
|
|
sed -i "s~\/boot\/vmlinuz-[0-9][^ ]*~\/boot\/vmlinuz-$REVISION~g;
|
|
|
|
s~\/boot\/kernel-genkernel-`uname -m`-[0-9][^ ]*~\/boot\/kernel-genkernel-`uname -m`-$REVISION~g;
|
|
|
|
s~\/boot\/initramfs-[0-9][^ ]*~\/boot\/initramfs-$REVISION.img~g" \
|
|
|
|
/boot/grub/grub.conf
|
|
|
|
fi
|
2013-07-06 12:41:00 +04:00
|
|
|
|
2012-05-18 20:27:25 +04:00
|
|
|
# rm old sources
|
2013-07-06 12:36:29 +04:00
|
|
|
cd /usr/src
|
2013-07-06 12:41:00 +04:00
|
|
|
$NICE_CMD rm -rf `find -maxdepth 1 -name "linux-*" -type d | sort -V | grep -vE "linux-$REVISION$|linux-$UNAME"`
|
2012-05-18 20:27:25 +04:00
|
|
|
|
2013-04-01 15:07:13 +04:00
|
|
|
# remounting file systems rw->ro
|
|
|
|
for fs in $RO_REMOUNT; do
|
|
|
|
if [[ "$fs" =~ ^/+usr/*$ || "$fs" =~ ^/+boot/*$ ]]; then
|
|
|
|
echo "remounting $fs -> ro"
|
2013-04-01 17:47:47 +04:00
|
|
|
mount -o remount,ro -force $fs
|
|
|
|
[ 0 -ne $? ] && echo "mount -o remount,ro -force $fs failed ;-( =======" && exit -1
|
2013-04-01 15:07:13 +04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2012-05-18 20:27:25 +04:00
|
|
|
exit 0
|
|
|
|
|