#!/bin/bash

KERNEL_VER=`uname -v | cut  -d ' ' -f 1 | cut -d '#' -f 2`
KERNEL_REL=`uname -r`
BACKUP_DIR=/opt/yum_back_up/${KERNEL_REL}_k${KERNEL_VER}

echo "back up kernel"
mkdir $BACKUP_DIR -p
cp /lib/modules/${KERNEL_REL}/ $BACKUP_DIR -r
rpm -ql kernel | grep -v "/lib" | xargs -I {} cp {} $BACKUP_DIR

echo "remove kernel pkg"
rpm -qa | grep kernel | xargs -I {} rpm -e {} --nodeps

echo "download and install kernel pkg "
yumdownloader --resolve kernel-headers kernel-tools kernel
ls | grep kernel | xargs -I {} rpm -i --force {}

echo "update system rpm pkg"
yum update -y

# change os release 
if [ -f "/etc/os-releas.rpmnew" ];then
mv /etc/os-release /etc/os-release.rpmsave -f
mv /etc/os-release.rpmnew /etc/os-release -f
fi

cat /etc/os-release

echo "\n finish to update system"
