#!/bin/sh
#****************************************************************#
# ScriptName: default/removeoldkernel.sh
# Author: xhy
# Create Date: 2020-03-22 12:10
# Modify Author: xhy
# Modify Date: 2020-11-06 11:45
# Version: 
#***************************************************************#
platform=$(cat /etc/redhat-release | grep -o "[0-9]*[0-9]" | sed -n '1p;1q')
newkernel=`cat /proc/version | awk '{print $3}' | awk -F '-' '{print $1}'`
oldkernel=`rpm -qa | grep kernel | grep -v "${newkernel}"`
yum -y remove ${oldkernel}

if [ ${platform} -eq 8 ];then
    find /boot/*init* | grep -v ${newkernel} | grep -v rescue | xargs rm -rf
    find /boot/loader/entries/* | grep -v ${newkernel} | grep -v rescue | xargs rm -rf
    OS=`cat /etc/redhat-release | awk '{print $1}'`
    if [ $OS\X == 'CentOSX' ];then
        find /boot/loader/entries/* | grep -v rescue | grep ${newkernel} | xargs sed -i 's/Red Hat Enterprise/CentOS/' 
        source /root/.bashrc
    fi
else
    source /root/.bashrc
fi

yum clean all 
yum makecache
yum -y install git gcc gcc-c++ make wget openssh-clients bash-completion net-tools vim chrony screen lrzsz epel-release tree jq curl lvm2 yum-utils zlib zlib-devel libffi-devel perl-Pod-Html --skip-broken
rm -rf /tmp/*
rm -rf /etc/yum.repos.d/epel.repo
rm -rf /etc/yum.repos.d/epel-*.repo
sed -i -e '/removeoldkernel/d' /etc/rc.d/rc.local
yum -y update
history -w
history -c
