#!/bin/bash
# => Filename: linux_kernel.sh (C) 2011 Eugene J. Markow
# => Maintainer and Lead Developer: Eugene J. Markow, Siemiechów, Poland, EU, Vous devez vous inscrire pour voir le lien
# => Contributor: John Lambrechts, Chicago, Illinois, USA, Vous devez vous inscrire pour voir le lien
# => Last Update: Tuesday, March 15, 2011, 00:45 CET
#================================================= =========================
# Enter 7 Kernel Variables Values Here (You MUST fill in ALL values after "="):
# Directory Name holding "mainline", "stable" and/or "snapshot"(patch) source files from kernel.org
# Must end with "/"
kern_src_dir=/usr/src/
# Directory Name holding current Kernel ".config" file (".config" will be copied automatically into new directory)
# Must end with "/"
config_dir=/usr/src/linux-2.6.38-rc8-git3-KNL/
# Value of CONFIG_LOCALVERSION parameter in Kernel ".config" file (Ex. CONFIG_LOCALVERSION="-ARCHMOD")
local_ver=-ARCHMOD
# File Name of "mainline" or "stable" Linux Kernel (Must be downloaded and reside in the "kern_src_dir" (/usr/src/)
kern_file_name=linux-2.6.38-rc8.tar.bz2
# Is a Patch file involved? YES or NO (Must be CAPITALIZED Letters)
patch=YES
# If patch=YES, File Name of "snapshot" patch (Ex. patch-2.6.37-rc1-git12.bz2) residing in "kern_src_dir" (/usr/src/)
# If patch=NO, then this value does NOT matter. If you wish, enter NONE (patch=NONE)
patch_file_name=patch-2.6.38-rc8-git4.bz2
# To build the kernel in a multithreaded (faster) way, the -j option is used with the 'make' program
# It is BEST to give a number to the -j option that corresponds to TWICE the number of processors in the system
# ( Ex. Machine with 1 processor: jval=2, Machine with 2 processors: jval=4, etc.)
# To disable this option, enter the value zero ("0"): ( Ex. jval=0 )
jval=2
#================================================= =========================
#*****************DO NOT ALTER ANYTHING BEYOND THIS POINT******************
#================================================= =========================
#Script Code
#Other Variables:
#usr_src
#kern_num
#kern_num_loc_ver
#kern_dir
#patch_num
#patch_num_loc_ver
#patch_dir
#Functions (Subroutines)
#Ex.
#patch_y(){
#echo "Hello"
#}
#--------------------------------------------------------------------------------------------------------
mmc(){
make menuconfig
#echo
#echo "Menuconfig Executed..."
#echo
}
#--------------------------------------------------------------------------------------------------------
qmmc(){
echo
echo -e "Would you like the script to CONTINUE (y / n)?"
echo -e "[ If \"y\", the script will PROCEED to the END ]"
echo -e "[ If \"n\", the script will RE-ENTER the Kernel Configuration Menu AGAIN ]"
echo
echo -ne "Please type your answer followed by [ENTER]: "
read ques2
echo
if [ "$ques2" != "y" -a "$ques2" != "n" ]; then
clear
echo
echo "**Use LOWERCASE 'y' or 'n' ... TRY AGAIN**"
qmmc
else
if [ "$ques2" == "n" ]; then
mmc
qmmc
fi
fi
}
#--------------------------------------------------------------------------------------------------------
cont(){
echo
echo -e "Would you like the script to CONTINUE (y / n)?"
echo -e "[ If \"y\", the script will PROCEED and the listed Soft Link files will be deleted and replaced ]"
echo -e "[ If \"n\", the script will TERMINATE ]"
echo
echo -ne "Please type your answer followed by [ENTER]: "
read ques
echo
if [ "$ques" != "y" -a "$ques" != "n" ]; then
echo "**Use LOWERCASE 'y' or 'n' ... TRY AGAIN**"
cont
fi
}
#--------------------------------------------------------------------------------------------------------
patch_y(){
echo "*Patch detected*"
echo
patch_num=$(echo $patch_file_name | sed 's/patch-//g')
patch_num=$(echo $patch_num | sed 's/.bz2//g')
patch_num_loc_ver=$patch_num$local_ver
patch_dir=$kern_src_dir'linux-'$patch_num'/'
#echo "The Patch Value is $patch_num"
#echo "The Patch Value Local Version is $patch_num_loc_ver"
#echo "The Patch Directory is $patch_dir"
#echo
echo -ne Checking if Patched Kernel Directory $kern_src_dir'linux-'$patch_num'-KNL/' is duplicate..." "
if [ -d $kern_src_dir'linux-'$patch_num'-KNL/' ]; then
echo "*Directory already exits*"
echo
echo "*Script Terminated*"
echo
exit
else
echo "*OK*"
echo
extract_src
cd $kern_dir
echo
echo Applying patch file $patch_file_name and renaming kernel directory to $kern_src_dir'linux-'$patch_num'-KNL/'
echo
bzip2 -dc $kern_src_dir$patch_file_name | patch -p1
cd $kern_src_dir
mv 'linux-'$kern_num 'linux-'$patch_num'-KNL'
kern_num=$(echo $patch_file_name | sed 's/patch-//g')
kern_num=$(echo $kern_num | sed 's/.bz2//g')
kern_num_loc_ver=$kern_num$local_ver
kern_dir=$kern_src_dir'linux-'$kern_num'-KNL/'
a_inc
a_array[$a_ctr]=$kern_dir
cd $kern_dir
fi
}
#--------------------------------------------------------------------------------------------------------
patch_n(){
echo "*No Patch Detected*"
echo
echo -ne Checking if Kernel Directory $kern_src_dir'linux-'$kern_num'-KNL/' is duplicate..." "
if [ -d $kern_src_dir'linux-'$kern_num'-KNL/' ]; then
echo "*Directory already exits*"
echo
echo "*Script Terminated*"
echo
exit
else
echo "*OK*"
echo
extract_src
echo Renaming Kernel Directory to $kern_src_dir'linux-'$kern_num'-KNL/'
mv 'linux-'$kern_num 'linux-'$kern_num'-KNL'
kern_dir=$kern_src_dir'linux-'$kern_num'-KNL/'
a_inc
a_array[$a_ctr]=$kern_dir
cd $kern_dir
fi
}
#--------------------------------------------------------------------------------------------------------
extract_src(){
echo "Extracting $kern_file_name into newly created kernel directory $kern_dir"
echo
#Extract Kernel Source
cd $kern_src_dir
tar -xvjf $kern_file_name
echo
}
#--------------------------------------------------------------------------------------------------------
r_inc(){
r_ctr=$((r_ctr+1))
}
#--------------------------------------------------------------------------------------------------------
a_inc(){
a_ctr=$((a_ctr+1))
}
#--------------------------------------------------------------------------------------------------------
#MAIN BODY
clear
echo
echo "|=====> Welcome to the Automated Linux Kernel Configuration, Compilation, and Installation Script <=====|"
echo
r_ctr=-1
a_ctr=-1
sl_flag=0
usr_src=/usr/src/
if [ $jval -eq 0 ]; then
jv=$NULL
else
jv='-j '$jval
fi
kern_num=$(echo $kern_file_name | sed 's/linux-//g')
kern_num=$(echo $kern_num | sed 's/.tar.bz2//g')
kern_num_loc_ver=$kern_num$local_ver
kern_dir=$kern_src_dir'linux-'$kern_num'/'
#echo "The Kernel Value is $kern_num"
#echo "The Kernel Value Local Version is $kern_num_loc_ver"
#echo "The Kernel Directory is $kern_dir"
#---------------------
echo
echo
echo -ne "Checking for the possible duplicate of 3 Soft Link files... "
if [ -h /boot/System.map -o -h $usr_src'linux' -o -h $usr_src'linux-2.6' ]; then
echo "*Yes - Present*"
echo
echo "The following Soft Link files already exist on your system:"
echo
else
echo "*OK*"
echo
fi
if [ -h /boot/System.map ]; then
echo /boot/System.map
sl_flag=1
fi
if [ -h $usr_src'linux' ]; then
echo $usr_src'linux'
sl_flag=1
fi
if [ -h $usr_src'linux-2.6' ]; then
echo $usr_src'linux-2.6'
sl_flag=1
fi
if [ $sl_flag -eq 1 ]; then
cont
fi
if [ "$ques" == "n" ]; then
echo "The script has been voluntarily TERMINATED. NOTHING has changed on your system."
echo
exit
fi
#---------------------
echo -ne "Checking if main Kernel Directory $usr_src exists... "
if [ ! -d $usr_src ]; then
echo "*The Directory does not exist*"
echo
echo "*Please create the directory $usr_src"
echo
echo "*Script Terminated*"
echo
exit
else
echo "*OK*"
echo
fi
echo -ne "Checking if the parameter \"patch=\" contains YES or NO... "
if [ "$patch" != "YES" -a "$patch" != "NO" ]; then
echo "*Invalid Value*"
echo
echo "*In the Kernel Variables Values section, the value for \"patch=\" must contain YES or NO (Capitalized)*"
echo
echo "*Script Terminated*"
echo
exit
else
echo "*OK*"
echo
fi
echo -ne "Checking if Kernel Directory $kern_dir is duplicate... "
if [ -d $kern_dir ]; then
echo "*The Directory already exist*"
echo
echo "*Script Terminated*"
echo
exit
else
echo "*OK*"
echo
fi
echo -ne "Checking Patch Status... "
if [ $patch = YES ]; then
patch_y
else
patch_n
fi
#echo
#echo "The Kernel Value is $kern_num"
#echo "The Kernel Value Local Version is $kern_num_loc_ver"
#echo "The Kernel Directory is $kern_dir"
echo
make mrproper &&
echo "Copying $config_dir.config to $kern_dir" &&
echo
cp $config_dir'.config' $kern_dir &&
echo "Entering Kernel Configuration menu for customization..." &&
echo &&
mmc &&
clear &&
qmmc &&
make clean && make $jv bzImage && make $jv modules && make $jv modules_install &&
a_inc &&
a_array[$a_ctr]=/lib/modules/$kern_num_loc_ver/ &&
cp -v arch/x86/boot/bzImage /boot/vmlinuz-$kern_num_loc_ver &&
a_inc &&
a_array[$a_ctr]=/boot/vmlinuz-$kern_num_loc_ver &&
mkinitcpio -k $kern_num_loc_ver -g /boot/kernel26-$kern_num_loc_ver'.img' &&
a_inc &&
a_array[$a_ctr]=/boot/kernel26-$kern_num_loc_ver'.img' &&
if [ -h /boot/System.map ]; then
rm /boot/System.map
r_inc
r_array[$r_ctr]='/boot/System.map'
fi &&
if [ -h $usr_src'linux' ]; then
rm $usr_src'linux'
r_inc
r_array[$r_ctr]=$usr_src'linux'
fi &&
if [ -h $usr_src'linux-2.6' ]; then
rm $usr_src'linux-2.6'
r_inc
r_array[$r_ctr]=$usr_src'linux-2.6'
fi &&
ln -s $kern_dir $usr_src'linux' &&
a_inc &&
a_array[$a_ctr]=$usr_src'linux' &&
ln -s $kern_dir $usr_src'linux-2.6' &&
a_inc &&
a_array[$a_ctr]=$usr_src'linux-2.6' &&
cp System.map /boot/System.map-$kern_num &&
a_inc &&
a_array[$a_ctr]=/boot/System.map-$kern_num &&
ln -s /boot/System.map-$kern_num /boot/System.map &&
a_inc &&
a_array[$a_ctr]=/boot/System.map &&
echo &&
echo &&
echo &&
clear &&
echo &&
echo " *Summary of Changes - File(s) Created and/or Deleted*" &&
if [ $a_ctr -gt -1 ]; then
echo
echo " ${#a_array[@]} File(s) Created:"
echo
for (( start = 0; start <= $a_ctr; start++ ))
do
echo " ${a_array[$start]}"
done
else
echo
echo " *No Files Were Created*"
fi &&
if [ $r_ctr -gt -1 ]; then
echo
echo " ${#r_array[@]} File(s) Deleted:"
echo
for (( start = 0; start <= $r_ctr; start++ ))
do
echo " ${r_array[$start]}"
done
else
echo
echo " *No Files Were Deleted*"
fi &&
echo &&
echo &&
echo " *SUCCESS - Main Processes COMPLETE*" &&
echo &&
echo " *NVIDIA users, please make additional NECESSARY adjustments*" &&
echo &&
echo " *Please Configure /boot/grub/menu.lst accordingly and you are done. Then REBOOT & TEST!*" &&
echo &&
echo &&
echo &&
echo


LinkBack URL
About LinkBacks
