Gentoo-Upgrade/sbin/kernel-clean.sh

44 lines
1.3 KiB
Bash
Raw Normal View History

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
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
SOURCES=linux-$REVISION
[ "" == "$SOURCES" ] && echo "No appropriate kernel sources found ;-(" && exit -1
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
2012-08-17 10:51:32 +04:00
cd /lib/modules && $NICE_CMD rm -rf `ls | grep -v "^$REVISION$"`
2012-05-18 20:27:25 +04:00
# rm old kernel revisions
mount -o remount,rw /boot
2012-07-17 11:10:55 +04:00
cd /boot && rm -f `ls System.map-* config-* vmlinuz-* initramfs-* 2>/dev/null | grep -vE "$REVISION$|$REVISION.img$"`
2013-04-01 17:47:47 +04:00
mount -o remount,ro -force /boot
2012-05-18 20:27:25 +04:00
# rm old sources
2012-08-17 10:51:32 +04:00
cd /usr/src && $NICE_CMD rm -rf `find -maxdepth 1 -name "linux-*" -type d | grep -v "$SOURCES$"`
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