ZappeL

gentoo-build-kernel.sh

Aug 25th, 2011
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.28 KB | None | 0 0
  1. #/bin/bash
  2.  
  3. #######################################################
  4. # Automatic kernel compilescript with old conf (gentoo)
  5. #                   by ZappeL 2011
  6. #
  7. # requires root-privileges, awk, sort and a configured
  8. # kernel is needed
  9. #######################################################
  10.  
  11.  
  12. LINUX=/usr/src/linux
  13. NEWEST=$(find /usr/src/ -name 'linux-*-gentoo*' -print | sort -r | grep "" -m1)
  14. CUR=/usr/src/linux-$(uname -r)
  15. let JOBS=$(cat /proc/cpuinfo | grep "cpu cores" -m 1 | awk '{print $4}')+1
  16.  
  17. echo -en "Checking symlink..."
  18. if [ -L $LINUX ]; then
  19.         echo -en "\nRemoving old symlink.."
  20.         rm $LINUX
  21. fi
  22. if [ ! -L $LINUX ]; then
  23.         echo -e "\t\t\t\t\t\t [ok]"
  24. else
  25.         echo -e "\t\t\t\t\t\t [error]"
  26. fi
  27.  
  28. echo -en "Creating new symlink for: "$NEWEST".."
  29. ln -s $NEWEST $LINUX
  30. if [ -L $LINUX ]; then
  31.         echo -e "\t\t [ok]"
  32. else
  33.         echo -e "\t\t [error]"
  34. fi
  35.  
  36. echo -en "Checking /boot directory.."
  37. if [ -d /boot/ ]; then
  38.         echo -en "\nFound /boot directory. \nChecking its contents.."
  39.         let BCNT=$(ls /boot/ | wc -l)-1
  40.         if [ $BCNT -lt 3 ]; then
  41.                         echo -en "\nTt seems that the /boot directory is empty. \nTrying to mount it.."
  42.                         mount /boot
  43.                         let BCNT=$(ls /boot/ | wc -l)-1
  44.                         if [ $BCNT -gt 2 ]; then
  45.                                 echo -e "\t\t\t\t\t\t [ok]"
  46.                         else
  47.                                 echo -e "\t\t\t\t\t\t [error]"
  48.                                 echo -e "Problem with your /boot direcoty. \nPLEASE CHECK YOUR INSTALLATION!"
  49.                                 exit
  50.                         fi
  51.                 else
  52.                         echo -e "\t\t\t\t\t\t [ok]"
  53.         fi
  54. else
  55.         echo -e "\t\t\t\t\t [error]"
  56.         echo -e "No /boot direcoty found.. \nPLEASE CHECK YOUR INSTALLATION!"
  57.         exit
  58. fi
  59.  
  60. echo -en "Getting current .config.."
  61. if [ -f "$CUR/.config" ];then
  62.         echo -e "\t\t\t\t\t [ok]"
  63. else
  64.         echo -e "\t\t\t\t\t [error]\nCould not find current config, make sure it is placed in:"
  65.         echo -e $CUR/.config
  66.         exit
  67. fi
  68.  
  69. echo -en "Copying config file.."
  70. cp $CUR/.config $LINUX >/dev/null 2>&1
  71. if [ -f $LINUX/.config ];then
  72.         echo -e "\t\t\t\t\t\t [ok]"
  73. else
  74.         echo -e "\t\t\t\t\t\t [error]\nCould not copy .config to "$LINUX".\nPlease copy the file manually."
  75.         exit
  76. fi
  77.  
  78. echo -e "Preparing to build the kernel.."
  79. cd $LINUX
  80. echo -en "Building the Kernel, please standby..."
  81. BZI=$(make -j$JOBS -s | awk '{print $2}')
  82. echo -e "\t\t\t\t [ok]"
  83.  
  84. echo -en "Checking kernel image.."
  85. if [ -f $LINUX/$BZI ]; then
  86.         echo -e "\t\t\t\t\t\t [ok]"
  87. else
  88.         echo -e "\t\t\t\t\t\t [error]\nCoukd not find kernel image!\n Givin up!"
  89.         exit
  90. fi
  91.  
  92. echo -en "Installing the kernel.."
  93. make -s modules_install
  94. make -s install
  95. if [ -e $(find /usr/src/ -name 'linux-*-gentoo*' -print | sort -r | grep '' -m1 | awk '{printf "/boot/vmlinuz%s\n",substr($1,15,255)}') ]; then
  96.         echo -e "\t\t\t\t\t\t [ok]\nInstalltion complete.\nNext step is to check your bootloader configuration or simply reboot the system!"
  97. else
  98.         echo -e "\t\t\t\t\t\t [error]\nInstallation failed!\nPlease try manual installtion of the kernel."
  99. fi
  100.  
  101. exit
Advertisement
Add Comment
Please, Sign In to add comment