Added Gentoo script

This commit is contained in:
dbroqua 2021-03-08 13:43:22 +01:00
parent d23d9e2e09
commit db5705f005

96
mrgkernel.sh Executable file
View File

@ -0,0 +1,96 @@
#! /bin/bash
# Gentoo version
# Some colors
GREEN='\033[0;32m'
RED='\033[0;31m'
DEFAULT='\033[0m'
# Defaults values
DIR="/usr/src/"
PREFIX='linux-'
EXTENSION='.tar.xz'
MAINLINE=1
SHOW_MENU_CONFIG=0
CURRENT_VERSION=`uname -r`
# Function to script script if step fail
isPreviousStepOk () {
if [ $? -ne 0 ]; then
echo -e "${RED} Error!${DEFAULT}"
exit 1
fi
}
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
sudo $0
exit 1
fi
# Get last kernel version
INFO=`curl -Ls https://www.kernel.org/ | perl -lne 'BEGIN{$/=""} print "$1 $2" if \
/latest_link.*?<a.*?href=\"(.*?)\".*?>(.*?)</s'`
# Extract some values from kernel name
KERNEL=`echo ${INFO} | cut -d' ' -f 2`
URL=`echo ${INFO} | cut -d' ' -f 1`
FILE=`echo ${URL}|rev|cut -d'/' -f 1 | rev`
if [ "${CURRENT_VERSION}" == "${KERNEL}" ]; then
echo -e "${RED}You are already on the latest version${DEFAULT}"
exit 1
fi
# Go to build dir
cd ${DIR} || exit
# Get kernel archive
wget ${URL}
isPreviousStepOk
# Extract kernel archive
tar xavf "${FILE}"
isPreviousStepOk
# Updated symlink
ln -snf linux-${KERNEL} linux
isPreviousStepOk
# Enter kernel directory
cd linux
isPreviousStepOk
# Get old config
make oldconfig
isPreviousStepOk
# Show kernel menu
if [ ${SHOW_MENU_CONFIG} -eq 1 ]; then
make menuconfig
fi
# Build kernel
make -j$(nproc)
# Build modules
make modules_install
# Install kernel
make install
# Update grub
grub-mkconfig -o /boot/grub/grub.cfg
# Rebuild modules
emerge --ask --verbose @module-rebuild
# Go to parent directory
cd ..
# Remove archive
rm ${FILE}
echo -e "${GREEN} ALL DONE!\n"