myhome/.local/bin/Update-kernel

129 lines
3.3 KiB
Plaintext
Raw Normal View History

#!/bin/bash
2021-06-19 16:42:28 +02:00
BACKUP="/home/yorune/MEGA/Systems/Linux/portage"
2021-06-19 16:40:53 +02:00
TMP_KERNEL="/tmp/kernel-config-$(uname -r)"
DEFAULT_KERNEL="/usr/src/linux/.config"
2021-06-19 16:42:59 +02:00
GRUBRELOAD=1
function starting() {
echo -e "\e[93m----------------------COMPILING------------------------------\e[0m"
2021-06-19 16:44:20 +02:00
sudo cp -rv "$DEFAULT_KERNEL" "$TMP_KERNEL"
cp -r "$TMP_KERNEL" "$BACKUP/kernel-config"
sudo cp -r /etc/portage/* $BACKUP
qlist -I | sort -u > $BACKUP/list-of-programs
}
function selection() {
echo -e "\e[93m----------------------SELECTION-----------------------------\e[0m"
sudo eselect kernel list
echo
echo
2021-06-19 16:43:46 +02:00
read -rp "New kernel is: " KERVER
echo
echo -e "Your kernel now is \e[91m$(uname -sr)\e[0m"
2021-06-19 16:44:20 +02:00
echo -e "Your selected kernel is \e[91m$KERVER\e[0m"
sudo eselect kernel set "$KERVER"
2021-06-19 16:44:37 +02:00
sudo eselect kernel list | grep -iE "\*"
echo
}
function compilation() {
2021-06-19 16:43:46 +02:00
read -rp "Do you want to accept and compile (Y/N): " agreed
echo
if [ "$agreed" == "y" ] || [ "$agreed" == "Y" ]
then
echo -e "\e[91m----------------------\e[5mSTARTING\e[0m\e[91m------------------------------\e[0m" && sleep 10
$NOW > /tmp/compiling-starting
NEW_KERNEL="/tmp/new-kernel-config"
2021-06-19 16:42:07 +02:00
sudo cp -r "$TMP_KERNEL" "$DEFAULT_KERNEL"
2021-06-19 16:43:21 +02:00
cd /usr/src/linux || exit
sudo make menuconfig; sleep 2; sudo cp -r "$DEFAULT_KERNEL" "$NEW_KERNEL"
sudo genkernel all --makeopts=-j"$(nproc --all)" \
--kernel-config=$NEW_KERNEL \
--callback="emerge nvidia-drivers::gentoo" \
--zfs
elif [ "$agreed" == "N" ] || [ "$agreed" == "n" ]
then
exit
fi
}
function ending() {
echo
echo
echo -e "\e[93m----------------------CHECKING-----------------------------\e[0m"
checking
echo
echo
echo -e "\e[93m----------------------REMEMBER-----------------------------\e[0m"
echo "You can remove:"
echo "* /lib/modules/OLD_KERNEL"
echo "* /boot/initramfs-genkernel-OLD_KERNEL"
echo "* /boot/vmlinuz-OLD_KERNEL"
echo "* /boot/System.map-OLD_KERNEL"
echo "* /boot/initramfs-OLD_KERNEL"
echo "* /usr/src/linux-OLD_KERNEL"
echo
echo -e "AFTER EVERYTHING YOU MUST WRITE COMMAND \e[91m"sudo grub-mkconfig -o /boot/grub/grub.cfg"\e[0m"
}
function checking() {
2021-06-19 16:40:53 +02:00
KERNEL=$(eselect kernel list \
| awk '{print $2}' \
| grep -Eo '[0-9]+.[0-9]+.[0-9]+' \
| tail -n1)
INITRANFS="initramfs-$KERNEL-gentoo-x86_64.img"
SYSTEMMAP="System.map-$KERNEL-gentoo-x86_64"
VMLINUZ="vmlinuz-$KERNEL-gentoo-x86_64"
2021-06-19 16:42:07 +02:00
ifchecking "$INITRANFS"
ifchecking "$SYSTEMMAP"
ifchecking "$VMLINUZ"
2021-06-19 16:42:59 +02:00
[ "$GRUBRELOAD" -eq "1" ] && sudo grub-mkconfig -o /boot/grub/grub.cfg \
|| echo "Please check all files and regenerate grub again!"
}
function ifchecking () {
FILE=/boot/$1
if test -f "$FILE"; then
echo "$FILE exist in the /boot folder ;)"
else
echo "$FILE NOT exist in the /boot folder ;)"
2021-06-19 16:42:59 +02:00
GRUBRELOAD=0
fi
}
function addgit() {
2021-06-19 16:42:07 +02:00
cd "$BACKUP" || exit
sleep 20
git add .
git commit -m "Updated: $(date)"
git push
2021-06-19 16:42:07 +02:00
cd "$HOME" || exit
}
function main() {
clear
BEGIN=$(date +"%s")
starting
addgit
selection
compilation
echo -e "\e[31mI am leaving! Thank You!\e[0m" && sleep 3
TERMIN=$(date +"%s")
DIFFTLPS=$(($TERMIN-$BEGIN))
echo -e "\e[93m------------------TIME COMPILATION-------------------------\e[0m"
echo -e "\e[93m$(($DIFFTLPS / 60)) minutes and $(($DIFFTLPS % 60)) seconds \e[0m elapsed for Script Execution." && sleep 3
ending
exit
}
main