Created
September 16, 2017 08:32
-
-
Save sQu1rr/6d40a81a40de44b5f4e5b2b50899f888 to your computer and use it in GitHub Desktop.
gentoo kenel update script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
src='/usr/src' | |
# Get current version | |
cur_ver="linux-`uname -r`" | |
# Get new version | |
ver=`ls $src | grep linux- | sort -V | tail -1` | |
path="$src/$ver" | |
if [[ $cur_ver = $ver ]]; then | |
echo "Already on Latest Version" | |
read -r -p "Run menuconfig? [Y/n] " response | |
response=${response,,} # tolower | |
if ! [[ $response =~ ^(no|n)$ ]]; then | |
( cd $path && make menuconfig ) | |
fi | |
else | |
echo "Performing Upgrade $cur_ver -> $ver" | |
config="$src/$cur_ver/.config" | |
if [ ! -f "$config" ]; then | |
echo "Cannot find old config ($config)" | |
exit | |
fi | |
echo "Copying old config" | |
cp $config "$path/" | |
echo "Running config upgrade" | |
( cd $path && make oldconfig ) | |
echo "Relinking kernel and fixing permissions" | |
eselect kernel set $ver | |
# TODO: make a callback from gentoo-sources update | |
#chown squ1rr:users "$src/linux" | |
#chown -R squ1rr:users $path | |
read -r -p "Run menuconfig? [y/N] " response | |
response=${response,,} # tolower | |
if [[ $response =~ ^(yes|y)$ ]]; then | |
( cd $path && make menuconfig ) | |
fi | |
fi | |
echo "Building kernel" | |
( cd $path && make -j9 ) | |
( cd $path && make modules_install ) | |
bzimage="$path/arch/x86_64/boot/bzImage" | |
if [ ! -f "$bzimage" ]; then | |
echo "Kernel compilation failed" | |
exit | |
fi | |
ending=${cur_ver//linux-/} | |
echo "Backing up current initramfs" | |
mkdir -p /boot/bak | |
cp /boot/initramfs-*-$ending /boot/bak/ | |
echo "Making initramfs" | |
genkernel initramfs | |
if [[ $? -ne 0 ]]; then | |
echo "Genkernel failed" | |
exit | |
fi | |
echo "Backing up current kernel" | |
if [[ $ver != $cur_ver ]]; then | |
rm /boot/initramfs-*-$ending | |
fi | |
mv /boot/kernel-$cur_ver /boot/bak/ | |
echo "Moving kernel to boot" | |
cp $path/arch/x86_64/boot/bzImage /boot/kernel-$ver | |
echo "Re-generating grub" | |
grub-mkconfig -o /boot/grub/grub.cfg | |
read -r -p "Rebuild module-dependent packages? [Y/n] " response | |
response=${response,,} # tolower | |
if [[ ! $response =~ ^(no|n)$ ]]; then | |
echo "Rebuilding module-dependent packages" | |
emerge @module-rebuild | |
fi | |
read -r -p "Reboot the system? [Y/n] " response | |
response=${response,,} # tolower | |
if [[ ! $response =~ ^(no|n)$ ]]; then | |
sudo reboot | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment