2012-05-18 20:27:25 +04:00
|
|
|
#!/bin/bash
|
|
|
|
|
2012-12-18 17:20:45 +04:00
|
|
|
let FORCE_REBUILD=0
|
2012-12-18 21:42:33 +04:00
|
|
|
KERNEL_REBUILD_ARGS=""
|
2013-04-01 15:25:16 +04:00
|
|
|
GENKERNEL_ARGS="--no-clean --no-mrproper"
|
2012-12-18 17:20:45 +04:00
|
|
|
|
2013-04-01 15:04:51 +04:00
|
|
|
[ -f /etc/gentoo-upgrade.conf ] && source /etc/gentoo-upgrade.conf
|
|
|
|
|
2012-12-18 17:20:45 +04:00
|
|
|
# available parameters
|
2013-04-01 15:25:16 +04:00
|
|
|
eval set -- "`getopt -o h,q,g: --long help,force-rebuild,mrproper,quiet,genkernel-args: -- \"$@\"`"
|
2012-12-18 17:20:45 +04:00
|
|
|
|
|
|
|
while true ; do
|
|
|
|
case "$1" in
|
|
|
|
-h|--help)
|
|
|
|
echo "Usage: kernel-getlast.sh [keys]..."
|
|
|
|
echo "Keys:"
|
|
|
|
echo -e "-h, --help\t\t\tShow this help and exit."
|
|
|
|
echo -e "--force-rebuild\t\t\tForce to rebuild kernel even if no new versions found."
|
2013-04-01 15:25:16 +04:00
|
|
|
echo -e "-g,--genkernel-args\t\tPass arguments to genkernel."
|
2012-12-18 21:42:33 +04:00
|
|
|
echo -e "--mrproper\t\t\tClean kernel sources before rebuild."
|
2013-01-13 16:26:42 +04:00
|
|
|
echo -e "-q, --quiet\t\t\tMake kernel configuration non-interactive."
|
2012-12-18 17:20:45 +04:00
|
|
|
echo
|
|
|
|
echo -e "This program works on any GNU/Linux with GNU Baurne's shell"
|
|
|
|
echo -e "Report bugs to <mecareful@gmail.com>"
|
|
|
|
exit 0
|
|
|
|
;;
|
2012-12-18 21:42:33 +04:00
|
|
|
--force-rebuild) let FORCE_REBUILD=1 ; shift ;;
|
2013-04-01 19:43:23 +04:00
|
|
|
-g|--genkernel-args) GENKERNEL_ARGS="$GENKERNEL_ARGS $2" ; shift 2 ;;
|
|
|
|
--mrproper) KERNEL_REBUILD_ARGS="$KERNEL_REBUILD_ARGS --mrproper" ; shift ;;
|
|
|
|
-q|--quiet) KERNEL_REBUILD_ARGS="$KERNEL_REBUILD_ARGS --silent" ; shift ;;
|
2012-12-18 17:20:45 +04:00
|
|
|
--) shift ; break ;;
|
|
|
|
*) echo "Internal error!" ; exit -1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2012-07-08 16:45:24 +04:00
|
|
|
kernel_regex=`kernel-config list | grep \* | cut -d" " -f6 | sed 's~[0-9]*\.[0-9]*\.[0-9]*~[0-9]*\.[0-9]*\.[0-9]*~ ; s~-r[0-9]*$~~; s~$~\\\(-r[0-9]\\\)\\\?~'`
|
2012-05-18 20:27:25 +04:00
|
|
|
[ "" == "$kernel_regex" ] && echo "kernel_regex build failed ;-(" && exit -1
|
|
|
|
|
|
|
|
new_kernel=`kernel-config list | cut -d" " -f6 | grep ^$kernel_regex$ | sort -V | tail -n1`
|
|
|
|
[ "" == "$new_kernel" ] && echo "Couldn't find appropriate new kernel version ;-(" && exit -1
|
|
|
|
|
2012-10-31 21:15:31 +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
|
|
|
kernel-config set $new_kernel
|
|
|
|
[ 0 -ne $? ] && echo "kernel-config set $new_kernel failed ;-(" && exit -1
|
|
|
|
|
|
|
|
kernel-clean.sh
|
|
|
|
[ 0 -ne $? ] && echo "kernel-clean.sh failed ;-(" && exit -1
|
|
|
|
|
|
|
|
vmlinuz_file=/boot/`echo $new_kernel | sed 's~^linux~vmlinuz~'`
|
|
|
|
[ "" == "$vmlinuz_file" ] && echo "vmlinuz_file == \"\"" && exit -1
|
|
|
|
|
2013-04-01 15:25:16 +04:00
|
|
|
# genkernel or kernel-rebuild ?
|
|
|
|
if [ `which genkernel 2>/dev/null` ]; then
|
2013-04-01 22:36:26 +04:00
|
|
|
[ -f /proc/config.gz ] && zcat /proc/config.gz >/usr/src/linux/.config
|
|
|
|
[ 0 -ne $? ] && echo "zcat /proc/config.gz >/usr/src/linux.config failed ;-( =======" && exit -1
|
|
|
|
|
2013-04-01 15:25:16 +04:00
|
|
|
genkernel $GENKERNEL_ARGS all
|
|
|
|
[ 0 -ne $? ] && echo "genkernel $GENKERNEL_ARGS all failed ;-( =======" && exit -1
|
2012-12-18 21:42:33 +04:00
|
|
|
|
2013-04-01 19:38:28 +04:00
|
|
|
[ -f /boot/grub/grub.conf ] && \
|
|
|
|
sed -i "s~\/boot\/vmlinuz-[0-9][^ ]*~\/boot\/vmlinuz-$REVISION~g;
|
|
|
|
s~\/boot\/initramfs-[0-9][^ ]*~\/boot\/initramfs-$REVISION.img~g" \
|
|
|
|
/boot/grub/grub.conf
|
|
|
|
|
|
|
|
[ -f /boot/grub2/grub.cfg ] && grub2-mkconfig -o /boot/grub2/grub.cfg
|
|
|
|
|
|
|
|
echo "--------- Rebuilding kernel modules ---------"
|
|
|
|
emerge -1v @module-rebuild
|
|
|
|
[ 0 -ne $? ] && echo "Upgrading kernel modules failed ;-(" && exit -1
|
|
|
|
|
2013-04-01 15:25:16 +04:00
|
|
|
else # using kernel-rebuild
|
|
|
|
if [[ ! -f "$vmlinuz_file" || 1 -eq $FORCE_REBUILD ]]; then
|
|
|
|
kernel-rebuild.sh $KERNEL_REBUILD_ARGS
|
|
|
|
[ 0 -ne $? ] && echo "kernel-rebuild.sh $KERNEL_REBUILD_ARGS failed" && exit -1
|
|
|
|
fi
|
2012-05-18 20:27:25 +04:00
|
|
|
|
2013-04-01 15:25:16 +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:25:16 +04:00
|
|
|
fi
|
|
|
|
done
|
2013-04-01 17:49:20 +04:00
|
|
|
fi
|
2012-10-31 21:15:31 +04:00
|
|
|
|
2012-05-18 20:27:25 +04:00
|
|
|
exit 0
|
|
|
|
|