openSUSE Paste > S.A.K.C. - 2.62 - SUSE Automated
Login

Info:

By James D. McDaniel, 1 Year ago, written in Bash. This post will never expire.

URL: http://paste.opensuse.org/28696095

  1. #!/bin/bash
  2.  
  3. #: Title       : S.A.K.C. - SUSE Automated Kernel Compiler
  4. #: Date Created: Wed Dec  8 19:10:59 CST 2010
  5. #: Last Edit   : Sun Jan 29  8:50:00 CST 2012
  6. #: Author      : J. McDaniel
  7. #: Version     : 2.61
  8. #: Description : Kernel Compile Script for openSUSE
  9. #: Options     : sakc [-h --help] [kernel_file_name.bz2]
  10.  
  11. TITLE=" S.A.K.C. - SUSE Automated Kernel Compiler - Version 2.62 "
  12. Dash1="----------------------------------------------------------"
  13.  
  14. FILE=$1
  15.  
  16. declare -a configs
  17. declare -a kernels
  18.  
  19. #
  20. # Written for the openSUSE forums on Sunday January 29, 2012
  21. #
  22.  
  23. #
  24. # Copy and Paste the text of this script into a text editor and save
  25. # it as the file sakc in your home area bin folder (~/bin/sakc).
  26. # This script must be marked executable to be used.  Please run
  27. # the following Terminal command: chmod +x ~/bin/sakc
  28. # To use sakc, download the latest kernel source files from ...
  29. # http://www.kernel.org/ into your download(s) folder.
  30. # Open up a terminal session, change to your download(s) folder
  31. # and run the command: sakc kernel_name
  32. #
  33.  
  34. #
  35. # Make Sure the Following Folder/File names are correct and exist!!!
  36. #
  37.  
  38. #
  39. # Where do you Keep/Download Your Kernel Source Files? This Folder Name Must Exist!
  40. #
  41. kernel_folder=$HOME/Downloads
  42.  
  43. #
  44. # Where do you want to place your Compiled Kernels? This Folder Name Must Exist!
  45. #
  46. compile_folder=$HOME/Kernel
  47.  
  48. # Where do you want to place your Saved Configs? To be inside of compile_folder above
  49. # As in $compile_folder/$config_folder OR /home/username/Kernel/Configs by default
  50. #
  51. config_folder=Configs
  52.  
  53. # Where is SAKC located and what is it called  (folder/name)
  54. # Don't Like the name sakc?  Save it as anything you like,
  55. # but make sure this is the name/location that you used!
  56. sakc_name=$HOME/bin/sakc
  57.  
  58. #
  59. # Kernel Compile/Configuration Log File. Do you wish to save all information for viewing later?
  60. #
  61. log_file=true
  62. log_file_location=$HOME/Documents
  63.  
  64. #
  65. # Do You Wish SAKC to play a Sound When the Compile is complete? (true / false)
  66. # play is included with the --> sox <-- application found in YaST
  67. #
  68. Play_Sound=true
  69. wav_Player=/usr/bin/play
  70. wav_File=/usr/share/sounds/alsa/test.wav
  71.  
  72. #
  73. # Turbo Mode Default; false or ask (Don't use true!) ******************************
  74. #
  75. turbomode=ask
  76.  
  77. #
  78. # Do you want to see SAKC in color?  ******************************************
  79. # The default is true, but can be set to false ********************************
  80. #
  81. use_color=true
  82.  
  83. #
  84. # Time Display Function.  Do you want the Elasped time displayed while your compile is running?  
  85. #
  86. show_time=true
  87.  
  88. # GPL Statement Output
  89.  
  90. function show_gpl {
  91. echo "S.A.K.C. is designed to compile a kernel source file in openSUSE."
  92. echo "Copyright (C) 2011-2012 by James D. McDaniel, jmcdaniel3@austin.rr.com"
  93. echo
  94. echo "This program is free software; you can redistribute it and/or modify"
  95. echo "it under the terms of the GNU General Public License as published by"
  96. echo "the Free Software Foundation; either version 2 of the License, or"
  97. echo "(at your option) any later version."
  98. echo
  99. echo "This program is distributed in the hope that it will be useful,"
  100. echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
  101. echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the"
  102. echo "GNU General Public License for more details."
  103. echo
  104. echo "You should have received a copy of the GNU General Public License"
  105. echo "along with this program; if not, write to the Free Software"
  106. echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA"
  107. echo
  108. }
  109.  
  110. #
  111. # Produced using figlet *******************************************************
  112. #
  113. function banner {
  114.   cat << "EOFBANNER"
  115.                 ____      _      _  __  ____  
  116.                / ___|    / \    | |/ / / ___|  
  117.                \___ \   / _ \   | ' / | |      
  118.                ___) | / ___ \ _| . \ | |___ _
  119.               |____(_)_/   \_(_)_|\_(_)____(_)
  120.  
  121.                              ____  _   _ ____  _____
  122.        ___  _ __   ___ _ __ / ___|| | | / ___|| ____|
  123.       / _ \| '_ \ / _ \ '_ \\___ \| | | \___ \|  _|  
  124.      | (_) | |_) |  __/ | | |___) | |_| |___) | |___
  125.       \___/| .__/ \___|_| |_|____/ \___/|____/|_____|
  126.            |_|  
  127.  
  128. EOFBANNER
  129. }
  130.  
  131. script_start=$(date +%m/%d/%y-%H:%M:%S)
  132.  
  133. #
  134. # Set Number of Compile Jobs based on number of CPU's times two ***************
  135. #
  136. Number_CPUS=$(getconf _NPROCESSORS_ONLN)
  137. Jobs=$(($Number_CPUS+$Number_CPUS))
  138.  
  139. #
  140. # S.A.K.C. Function Blocks ****************************************************
  141. #
  142.  
  143. #
  144. # Determine file size *********************************************************
  145. # $2 is kB (1000), K (1024), mB (1000*1000), M (1024*1024), and so on for G, T, P, E, Z, Y.
  146. #
  147. function file_size {
  148.   if [ -f "$1" ] ; then
  149.     filesize=$(ls -l --block-size=$2 $1  | awk -F " " '{ print $5 }')
  150.   else
  151.     let filesize=0
  152.   fi
  153. }
  154.  
  155. #
  156. # Color Display Request - color forground background [b/n] ********************
  157. #
  158. # 0:Black 1:Blue 2:Green 3:Cyan 4:Red  5:Magenta 6:Yellow 7:White
  159. function color {
  160.   if [[ $3 == [Bb] ]] ; then
  161.     tput bold
  162.   fi
  163.   if [[ $3 == [Nn] ]] ; then
  164.     tput sgr0
  165.   fi
  166.   if $use_color ; then
  167.     tput setf $(( $1 ))
  168.     tput setb $(( $2 ))
  169.   else
  170.     tput setf 7
  171.     tput setb 0
  172.   fi
  173.   return 0
  174. }
  175.  
  176. #
  177. # Display All Text in Color as requested
  178. #
  179. # syntax: print_color line col fgrd_color bgrd_color #lines "text"...
  180. #
  181. # 0: Black 1: Blue 2: Green 3: Cyan 4: Red  5: Magenta 6: Yellow 7: White
  182. #
  183. function print_color {
  184.   WIDTH=$(tput cols)
  185.   HEIGHT=$(tput lines)
  186.   line_os=0
  187.   if [ $(($WIDTH)) -le  80  ] ; then
  188.     col_os=0
  189.   else
  190.     col_os=$((($WIDTH - 80) / 2 ))
  191.   fi
  192.   fgrd=${3}
  193.   bgrd=${4}
  194.   s_line=${1}
  195.   s_col=${2}
  196.   maxnum=${5}
  197.   counter=0
  198.   while [ $(( counter )) -lt $(( maxnum + 1 )) ] ; do
  199.     tput cup $(( s_line + counter + line_os)) $(( s_col + col_os ))
  200.     color $((fgrd)) $((bgrd)) B
  201.     echo "${6}$(tput sgr0)"
  202.     let counter=counter+1
  203.     shift
  204.   done
  205. }
  206.  
  207. #
  208. # Display Elapsed Time While doing the compile / This runs in the background
  209. #
  210. function time_display {
  211.   tput cup $(( 14 + line_os)) $(( 41 + col_os ))
  212.   echo -n "Elapsed Time: 0   minute(s) "
  213.   while true ; do let comp_time=comp_time+1 && sleep 60 && tput cup $(( 14 + line_os)) $(( 55 + col_os )) && echo -n "$comp_time$(tput sgr0)" ; done &
  214. PID1=$!
  215. }
  216.  
  217. #
  218. # Extract the base Kernel Folder Name from .tar.bz2 File Name *****************
  219. #
  220. function folder_name {
  221.   shortname=$(basename $FILE)
  222.   NUM=${#shortname}
  223.   folder="${shortname:0:$(($NUM-8))}"
  224.   NUM=${#folder}
  225. }
  226.  
  227. #
  228. # S.A.K.C. Main Header Display ************************************************
  229. #
  230. function display_header {
  231.  
  232.   tput clear
  233.  
  234.   print_color 1 0 7 0 1 "$(date +%m/%d/%y)"
  235.   print_color 1 $((80-NUM)) 7 0 1 "$folder"
  236.  
  237.   print_color 3 0 7 2 1 "           $TITLE           "
  238.   if $turbomode ; then
  239.     print_color 1 34 4 0 1               "TURBO MODE"
  240.   fi
  241.   l1="--------------------------------------------------------------------------------"
  242.   l2=""
  243.   l3="--------------------------------------------------------------------------------"
  244.   l4=""
  245.   l5="--------------------------------------------------------------------------------"
  246.   l6=" Num          Function                    Status                      Exit Code "
  247.   l7="--------------------------------------------------------------------------------"
  248.  
  249.   print_color 2 0 3 0 7 "$l1" "$l2" "$l3" "$l4" "$l5" "$l6" "$l7"
  250.  
  251.   l1="  1.  Kernel File Decompression:                                                "
  252.   l2=""
  253.   l3="  2.  Kernel File Configuration:                                                "
  254.   l4=""
  255.   l5="  3.  Kernel File Compile Process:                                              "
  256.   l6=""
  257.   l7="  4.  Kernel File Installation:                                                 "
  258.   print_color 10 0 7 0 7 "$l1" "$l2" "$l3" "$l4" "$l5" "$l6" "$l7"
  259.   l1="--------------------------------------------------------------------------------"
  260.   l2=""
  261.   l3="--------------------------------------------------------------------------------"
  262.   print_color 18 0 3 0 3 "$l1" "$l2" "$l3"
  263. }
  264.  
  265. #
  266. # S.A.K.C. top status display *************************************************
  267. #
  268. function status_display {
  269.  
  270.   case $1 in
  271.  
  272.     1) print_color 5 0 7 1 1 "          Your Kernel file is now being uncompressed.  Please Wait ...          " ;;
  273.     2) print_color 5 0 6 1 1 "          Your Kernel file is now being Configured.    Please Wait ...          " ;;
  274.     3) print_color 5 0 7 4 1 "        Would you like to modify your Kernel configurations in a GUI?           " ;;
  275.     4) print_color 5 0 7 1 1 "          Your Kernel file is now being Compiled.      Please Wait ...          " ;;
  276.     5) print_color 5 0 7 4 1 "              Your Kernel file has been Compiled Successfully!                  " ;;
  277.     6) print_color 5 0 6 1 1 "          Your Kernel file is now being Installed.     Please Wait ...          " ;;
  278.     7) print_color 5 0 7 4 1 "      Would you like to view your Kernel Config/Compile/Install Log File?       " ;;
  279.     8) print_color 5 0 7 1 1 "                Your Kernel file Has Been Installed Successfully                " ;;
  280.     *) ;;
  281.  
  282.   esac
  283.   tput cup $(( 5 + line_os)) $(( 75 + col_os ))
  284. }
  285.  
  286. #
  287. # S.A.K.C. Kernel Function progress display ***********************************
  288. #
  289. function progress_display {
  290.   for ((i=1;i<=$1;++i)) ; do
  291.     case $i in
  292.       1) ON_LINE=10
  293.          Exit_Code=$uncompress_exit ;;
  294.       2) ON_LINE=12
  295.          Exit_Code=$configure_exit ;;
  296.       3) ON_LINE=14
  297.          Exit_Code=$compile_exit ;;
  298.       4) ON_LINE=16
  299.          Exit_Code=$install_exit ;;
  300.       *) ;;
  301.     esac
  302.     print_color $(( ON_LINE )) 74 7 0 1 "$Exit_Code"
  303.     if [ $(( Exit_Code )) -ge 1 ] ; then
  304.       print_color $(( ON_LINE )) 41 4 0 1 "Failed!   "
  305.       exit $Exit_Code
  306.     else
  307.       print_color $(( ON_LINE )) 41 7 0 1 "Completed!   "
  308.     fi
  309.   done
  310. }
  311.  
  312. #
  313. # Get User Input Display ******************************************************
  314. #
  315. function get_input {
  316.   print_color 19 10 7 0 1 " Please make your selection and press <enter> (Y=Yes/N=No): "
  317.   tput cup $(( 19 + line_os)) $(( 69 + col_os ))
  318.   read CHOICE
  319.   print_color 19 10 7 0 1 "                                                            "
  320. }
  321.  
  322. #
  323. # Get User Input & password Display *******************************************
  324. #
  325. function get_password {
  326.   print_color 19 9 7 0 1 " Press the <enter> key to proceed to your Kernel Instalation "
  327.   tput cup $(( 19 + line_os)) $(( 69 + col_os ))
  328.   read CHOICE
  329.   print_color 19 9 7 0 1 "                                                             "
  330.   tput cup $(( 16 + line_os)) $(( 41 + col_os ))
  331.   sudo dir > /dev/null
  332.   tput cup $(( 16 + line_os)) $(( 41 + col_os ))
  333.   echo "                "
  334. }
  335.  
  336. #
  337. # Prompt for user input in bold while, for startup error messages *************
  338. #
  339. function enter_prompt {
  340.   echo
  341.   tput bold
  342.   tput setf 7
  343.   tput cup $(( 4 + line_os)) $(( 0 + col_os ))
  344.   echo -n "$1$(tput sgr0)"
  345.   read CHOICE
  346.   echo
  347. }
  348.  
  349. #
  350. # Setup Name and Location of your Log File ************************************
  351. #
  352. function start_log {
  353.   ext=$(date +%m%d%y.%H%M%S)
  354.   if $log_file ; then
  355.     log_file_name=$log_file_location"/"$folder"."$ext".txt"
  356.   else
  357.     log_file_name="/dev/null"
  358.   fi
  359. # Start The Log File Output if Selected
  360.   echo "$TITLE" > $log_file_name
  361.   echo " " >> $log_file_name
  362.   echo " S.A.C.K. Start: $script_start of kernel: $folder " >> $log_file_name
  363.   echo " " >> $log_file_name
  364. }
  365.  
  366. function log_heading {
  367. echo " " >> $log_file_name
  368. echo "*********** Command: $1 *********************" >> $log_file_name
  369. echo " " >> $log_file_name
  370. }
  371.  
  372. function log_complete {
  373. echo " " >> $log_file_name
  374. echo " Compile Start: $start_of_compile             Compile Finish: $end_of_compile " >> $log_file_name
  375. echo "  Script Start: $script_start              Script Finish: $script_stops " >> $log_file_name
  376. echo " " >> $log_file_name
  377. echo "            $TITLE            " >> $log_file_name
  378. }
  379.  
  380. #
  381. # Common Text to Display When an Error is Detected ****************************
  382. #
  383. function error_message {
  384.   tput clear
  385.   color 2 0 B
  386.   echo $Dash1
  387.   color 7 2 B
  388.   echo "$TITLE"
  389.   color 2 0 B
  390.   echo $Dash1
  391.   color 7 0 B
  392.   echo
  393.   color 7 4 B
  394.   echo "$1"
  395.   color 7 0 B
  396.   echo
  397. }
  398.  
  399. #
  400. # Kernel Configuration Selector ***********************************************
  401. #
  402. function config_slection {
  403.   config_menu=true
  404.   delete_config=false
  405.   while $config_menu ; do
  406.     if $delete_config ; then
  407.       error_message "You have elected to manually Delete a kernel config file!"
  408.     else
  409.       error_message "You have elected to manually pick the kernel config file!"
  410.     fi
  411.     color 6 1 B
  412.     echo "Active Config uses your Config from your running Kernel."
  413.     echo "Configs < 100kB in size suggest they are for Turbo Mode."
  414.     echo "Configs from a Turbo Compile will always Compile Fast.  "
  415.     color 7 0 B
  416.     echo
  417.     echo "Please select the configuration file from this list:"
  418.     echo
  419.     let counter=0
  420.     for i in $compile_folder/$config_folder/c* ; do
  421.       if [ -f $i ] ; then
  422.         let counter=counter+1
  423.         configs[$counter]=$(basename $i)
  424.         file_size $compile_folder/$config_folder/${configs[$counter]} KB
  425.         color 7 0 B
  426.         echo -n " $counter) "
  427.         color 3 0 B
  428.         echo -n "${configs[$counter]}, "
  429.         color 7 0 B
  430.         echo -n "filesize="
  431.         color 3 0 B
  432.         echo -n "$filesize"
  433.         color 7 0 B
  434.         if [ $counter -eq 1 ] ; then
  435.           echo ", Original Default Config"
  436.         else
  437.           echo -n ", Ext="
  438.           color 3 0 B
  439.           echo "Date.Time"
  440.           color 7 0 B
  441.         fi
  442.       fi
  443.     done
  444.     if [[ $counter -eq 0 ]]; then
  445.       echo
  446.       color 7 4 B
  447.       echo "No Kernel Config Files were found in $compile_folder/$config_folder!"
  448.       color 7 0 B
  449.       echo
  450.       exit 1
  451.     fi
  452.     echo
  453.     if [ $delete_config == false ] ; then
  454.       echo "Commands are: A=Active Config, D=Delete or Q=Quit"
  455.     else
  456.       echo "Commands are: B=Back to Config Select or Q=Quit"
  457.     fi
  458.     echo
  459.     color 7 1 B
  460.     if $delete_config ; then
  461.       echo -n "Please Select Kernel Config File # [1-$counter] or (Q/B): "
  462.     else
  463.       echo -n "Please Select Kernel Config File # [1-$counter] or (A/Q/D): "
  464.     fi
  465.     color 7 0 B
  466.     read CHOICE
  467.     if [[ $CHOICE =~ ^[0-9]+$ ]] ; then
  468.       if [[ $CHOICE -le $counter ]] && [[ $CHOICE -gt 0 ]]; then
  469.         if $delete_config ; then
  470.             if [ -f "$compile_folder/$config_folder/${configs[$CHOICE]}" ] ; then
  471.               echo
  472.               read -p "Are You Sure you want to remove: ${configs[$CHOICE]}? (y/N): " something
  473.               if [[ $something == [yY] ]] ; then
  474.                 rm "$compile_folder/$config_folder/${configs[$CHOICE]}"
  475.               fi
  476.             fi
  477.         else
  478.           config_menu=false
  479.           if [ -f "$compile_folder/$config_folder/${configs[$CHOICE]}" ] ; then
  480.             config_name=${configs[$CHOICE]}
  481.           else
  482.             config_name="config.sav"
  483.           fi
  484.         fi
  485.       fi
  486.     else
  487.       if [[ $CHOICE == [Qq] ]] ; then
  488.         clear
  489.         show_gpl
  490.         exit 0
  491.       fi
  492.       if [[ $CHOICE == [dD] ]] ; then
  493.         delete_config=true
  494.       fi
  495.       if [[ $CHOICE == [bB] ]] ; then
  496.         delete_config=false
  497.       fi            
  498.       if [[ $CHOICE == [aA] ]] ; then
  499.         if [ $delete_config == false ] ; then
  500.            use_active_config=true
  501.            config_menu=false
  502.         fi
  503.       fi
  504.     fi
  505.   done
  506. }
  507.  
  508. #
  509. # Allow new Compile option that can speed up the Compile time *****************
  510. #
  511. function use_turbo_mode {
  512. # We Must save a copy of your config file before you EVER use Turbo Mode
  513.   manual_config=false
  514.   use_active_config=false
  515.   if [ ! -f "$compile_folder/$config_folder/config.sav" ] ; then
  516.         cp /boot/config-*-desktop "$compile_folder/$config_folder/config.sav" 2>&1
  517.   fi
  518.   if [ ! -f "$compile_folder/$config_folder/config.sav" ] ; then
  519.         cp /boot/config-*-default "$compile_folder/$config_folder/config.sav" 2>&1
  520.   fi
  521.   if [ ! -f "$compile_folder/$config_folder/config.sav" ] ; then
  522.           zcat /proc/config.gz >"$compile_folder/$config_folder/config.sav"
  523.   fi
  524.   if [ "$turbomode" == "ask" ] ; then
  525.     error_message "Do you wish to Enable the Turbo Mode Compiler? (Y=Yes/N=No)"
  526.     color 7 0 B
  527.     echo -n "On Your Last Compile You: "
  528.     color 3 0 B
  529.     if [ -f "$compile_folder/$config_folder/turbomode" ] ; then
  530.       echo "Used the Turbo Compile Mode"
  531.     else
  532.       echo "Did Not Use Turbo Compile Mode"
  533.     fi
  534.     echo
  535.     color 7 1 B
  536.     echo "Using Turbo Mode can reduce the compile time up to 25% of  "                                                                                                  
  537.     echo "normal.  Before using Turbo Mode, All hardware you expect  "                                                                                            
  538.     echo "to use with this kernel should be connected now and turned "                                                                                          
  539.     echo "on.  Failure to do so might cause them to not work.  If    "                                                                                          
  540.     echo "you have issues using this option, just recompile and don't"                                                                                                
  541.     echo "use the Turbo Mode Compile Mode option.  If you want to use"
  542.     echo "the new Turbo Mode Compiler and you are not sure everything"
  543.     echo "is connected turned on and working, then Quit now and make "
  544.     echo "sure it is on! Please see the C=Config menu for more kernel"
  545.     echo "configuration options.  Using Active Config from the Config"
  546.     echo "menu preserves all installed Turbo Compile Modules from a  "
  547.     echo "previous successful Turbo Mode Compile and will be as fast."
  548.     color 7 0 B
  549.     echo
  550.     echo "Commands are: Y=Yes, N=No, C=Config Select Menu and Q=Quit"
  551.     echo
  552.     color 7 4 B
  553.     read -p "Wish to Use the fast Turbo Mode Compiler? (Y/N/C/Q): " CHOICE
  554.     color 7 0 B
  555.     if [[ $CHOICE == [qQ] ]] ; then
  556.       clear
  557.       show_gpl
  558.       exit 0
  559.     fi
  560.     if [[ $CHOICE == [cC] ]] ; then
  561.       config_slection
  562.       turbomode=false
  563.       manual_config=true
  564.       echo
  565.       echo -n "Your Config Selection was: "
  566.       color 3 0 B
  567.       echo -n "$config_name"
  568.       color 7 0 B
  569.       echo -n ", Press Enter to Continue ..."
  570.       read CHOICE
  571.     fi
  572.     if [[ $CHOICE == [yY] ]] ; then
  573.       turbomode=true
  574.       echo "true" > $compile_folder/$config_folder/turbomode
  575.     else
  576.       turbomode=false
  577.     fi
  578.   else
  579.     if [ $turbomode != true ] ; then
  580.       if [ $turbomode != false ] ; then
  581.         turbomode=false
  582.       fi
  583.     fi
  584.   fi
  585. }
  586.  
  587. #
  588. # Help is Displayed from here *************************************************
  589. #
  590. function help {
  591.     cat << EOFHELP
  592.  
  593. $TITLE
  594.  
  595. Your S.A.K.C. Startup and help options are:
  596.  
  597. $0 -h --help :to show this help
  598.  
  599. OR
  600.  
  601. $0 [kernel_file_name.bz2]
  602.  
  603. The kernel_file_name.bz2 name is optional and will be requested if not supplied.
  604.  
  605. EOFHELP
  606. show_gpl
  607. exit 0
  608. }
  609.  
  610. #
  611. # Display Help if requested.  Example from Findgrub ***************************
  612. #
  613. case "$1" in
  614.     -h|--help) help ;;
  615. esac
  616.  
  617. #
  618. # S.A.K.C. Display Error Messages *********************************************
  619. #
  620. tput clear        
  621.  
  622. #
  623. # Make sure script was not started as root ************************************
  624. #
  625. if [ $UID -eq 0 ] ; then
  626.   l1=""
  627.   l2=" Do Not Start $(basename $0) as a root user!  Your password will be "
  628.   l3=" requested later when needed to install your new Kernel.  "
  629.   print_color 0 0 7 4 4 "$TITLE" "$l1" "$l2" "$l3"
  630.   enter_prompt "Press <enter> to exit..."
  631.   exit 2
  632. fi
  633.  
  634. #
  635. # Determine if the compile_folder exists **************************************
  636. #
  637. if [[ -d "$compile_folder" ]] ; then
  638.   cd "$compile_folder"
  639.   if [[ ! -d "$config_folder" ]] ; then
  640.     mkdir "$config_folder"
  641.   fi
  642. else
  643.   error_message "The Kernel Compile Folder: $compile_folder, does not exist!"
  644.   echo "Please create or change this folder name and start $(basename $0) again."
  645.   echo
  646.   exit 1
  647. fi
  648.  
  649. #
  650. # Make sure the sakc script file exists in the folder specified ***************
  651. #
  652. if [ ! -e "$sakc_name" ] ; then
  653.   error_message "The S.A.K.C. Kernel Source File Compiler: $sakc_name, was not found!"
  654.   exit 1
  655. fi
  656.  
  657. #
  658. # Determine if a kernel file name was given at start **************************
  659. #
  660. if [ $# -eq 0 ] ; then
  661.  
  662. #
  663. # Determine if the kernel_folder (default is ~/Downloads) Exists **************
  664. #
  665.   if [[ -d "$kernel_folder" ]] ; then
  666.  
  667.     menu=true
  668.     delete_kernel=false
  669.     while $menu ; do
  670.  
  671.       tput clear
  672.       color 2 0 B
  673.       echo $Dash1
  674.       color 7 2 B
  675.       echo "$TITLE"
  676.       color 2 0 B
  677.       echo $Dash1
  678.       color 7 0 B
  679.       echo
  680.       echo -n "S.A.K.C. Location/Name: "
  681.       color 3 0 B
  682.       echo "$sakc_name"
  683.       color 7 0 B
  684.       echo
  685.       echo -n " Kernel Compile Folder: "
  686.       color 3 0 B
  687.       echo "$compile_folder"
  688.       color 7 0 B
  689.       echo -n " Kernel Config  Folder: "
  690.       color 3 0 B
  691.       echo "$compile_folder/$config_folder"
  692.       color 7 0 B
  693.       echo -n " Kernel Source  Folder: "
  694.       color 3 0 B
  695.       echo "$kernel_folder"
  696.       color 7 0 B
  697.       echo
  698.       echo -n " "
  699.       color 7 6 B
  700.       echo " Kernel Source File Tar Ball Listing "
  701.       color 7 0 B
  702.       echo
  703.  
  704.       counter=0
  705.       declare -a kernels
  706. #
  707. # Find and display all files that start with linux* and end with .tar.bz2
  708. #
  709.       for i in "$kernel_folder"/linux*.tar.bz2 ; do
  710. #
  711. # Determine if the kernel source file exists **********************************
  712. #
  713.         if [ -f $i ] ; then
  714.  
  715.           let counter=counter+1
  716.           kernels[$counter]=$i
  717.           color 7 0 B
  718.           echo -n " $counter) "
  719.           color 3 0 B
  720.           echo "$(basename ${kernels[$counter]})"
  721.  
  722.         fi
  723.  
  724.       done
  725. #
  726. # Determine if any Kernel Source Files were found *****************************
  727. #
  728.       if [[ $counter -eq 0 ]]; then
  729.  
  730.         echo
  731.         color 7 4 B
  732.         echo "No Kernel Source Files were found in $kernel_folder!"
  733.         color 7 0 B
  734.         echo
  735.         exit 1
  736.  
  737.       fi
  738. #
  739. # Main Program Prompt Displayed Here ******************************************
  740. #
  741.       echo
  742.       color 7 1 B
  743.       if $delete_kernel ; then
  744.         echo -n "Enter Kernel Source File # to Delete (Q=Quit,B=Back): "
  745.       else
  746.         echo -n "Enter Kernel Source File # to Compile (Q=Quit,D=Delete): "
  747.       fi
  748.       color 7 0 B
  749.       read CHOICE
  750. #
  751. # Determine if input ($CHOICE) is an integer number and in range, look for Q to
  752. # Quit. If menu is not set to false, the menu will just be redisplayed as you
  753. # did not enter a valid menu option number for a kernel source file to compile.
  754. #
  755.       if [[ $CHOICE =~ ^[0-9]+$ ]] ; then
  756.         if [[ $CHOICE -le $counter ]] && [[ $CHOICE -gt 0 ]]; then
  757.           if $delete_kernel ; then
  758.             echo
  759.             read -p "Are You Sure you want to remove: $(basename ${kernels[$CHOICE]})? (y/N): " something
  760.             if [[ $something == [yY] ]] ; then
  761.               rm "${kernels[$CHOICE]}"
  762.             fi
  763.           else
  764.             menu=false
  765.           fi
  766.         fi
  767.       else
  768.         if [[ $CHOICE == [Qq] ]] ; then
  769.           clear
  770.           show_gpl
  771.           exit 0
  772.         fi
  773.         if [[ $CHOICE == [dD] ]] ; then
  774.           delete_kernel=true
  775.         fi
  776.         if [[ $CHOICE == [bB] ]] ; then
  777.           delete_kernel=false
  778.         fi    
  779.       fi
  780.     done
  781.  
  782.     $sakc_name ${kernels[$CHOICE]}
  783.  
  784.   else
  785.  
  786. #
  787. # The Kernel Source File Folder (default=~/Downloads) was not found ***********
  788. #
  789.     error_message "The Kernel Source File Folder: $kernel_folder, does not exist!"
  790.     exit 1
  791.   fi
  792.   exit 0
  793. else
  794.  
  795. #
  796. # Make sure we got kernel source file name as a command line argument *********
  797. #
  798.   if [ $# -eq 0 ] ; then
  799.     l1=""
  800.     l2=" Command Syntax is: $(basename $0) kernel_source_file_name.tar.bz2  "
  801.     l3=""
  802.     print_color 0 0 7 4 4 "$TITLE" "$l1" "$l2" "$l3"
  803.     enter_prompt "Press <enter> to exit..."
  804.     exit 1
  805.   fi
  806.  
  807. #
  808. # Determine if kernel file-name is present ************************************
  809. #
  810.   if [ ! -e $FILE ] ; then
  811.     l1=""
  812.     l2=" The Kernel Source file: --> $1 <-- was not Found!  "
  813.     l3=""
  814.     print_color 0 0 7 4 4 "$TITLE" "$l1" "$l2" "$l3"
  815.     enter_prompt "Press <enter> to exit..."
  816.     exit 10
  817.   fi
  818.  
  819. #
  820. # S.A.K.C. Main Program Starts Here *******************************************
  821. #
  822.  
  823.   use_turbo_mode
  824.   folder_name
  825.   start_log
  826.   display_header
  827.  
  828. #
  829. # S.A.K.C. Kernel Decompression ***********************************************
  830. #
  831.  
  832. #
  833. # Your Kernel file is now being uncompressed.  Please Wait ... ****************
  834. #
  835.   status_display 1
  836.  
  837.   tar -vxjf $FILE > /dev/null 2>&1
  838.   uncompress_exit=$?
  839. #
  840. # 1.  Kernel File Decompression: Completed! ***********************************
  841. #
  842.   progress_display 1
  843.  
  844.   if [ -d "$folder" ] ; then
  845.     cd $folder
  846.   else
  847.     error_message "Kernel Source Folder $folder Does Not Exist!"
  848.     read -p "Press Any Key to Exit S.A.K.C." CHOICE
  849.     exit 1
  850.   fi
  851.  
  852. #
  853. # S.A.K.C. Kernel Configuration ***********************************************
  854. #
  855.  
  856. #
  857. # Your Kernel file is now being Configured.    Please Wait ... ****************
  858. #
  859.   status_display 2
  860.  
  861.   log_heading "make mrproper"
  862.  
  863. #
  864. # Fix any left over compile issues before we start again **********************
  865. #
  866.   make mrproper 2>&1 >> $log_file_name
  867.  
  868. #
  869. # Get the Configuration for the running kernel ********************************
  870. #
  871.   log_heading "make oldconfig"
  872.  
  873. #
  874. # What kernel config file are you using? **************************************
  875. #
  876.   if $manual_config ; then
  877.     cp "$compile_folder/$config_folder/$config_name" .config
  878.     echo "**** Manual Config file was selected ****" >> $log_file_name
  879.   else
  880.     if $turbomode ; then
  881.          chmod +x ./scripts/kconfig/streamline_config.pl
  882.          text=$(./scripts/kconfig/streamline_config.pl 2>&1 > ./config_strip)
  883.          mv ./config_strip ./.config
  884.          echo "**** Turbo Compile Mode is Enabled ****" >> $log_file_name
  885.     else
  886.       if $use_active_config ; then
  887.         zcat /proc/config.gz >.config
  888.         echo "**** Using Last Kernel Configuration ****" >> $log_file_name
  889.       else
  890.         echo "**** Turbo Compile Mode is Disabled ****" >> $log_file_name
  891.         if [ -f "$compile_folder/$config_folder/turbomode" ] ; then
  892.           if [ -f "$compile_folder/$config_folder/config.sav" ] ; then
  893.             cp "$compile_folder/$config_folder/config.sav" .config
  894.           else
  895.             zcat /proc/config.gz >.config
  896.           fi
  897.         else
  898.           zcat /proc/config.gz >.config
  899.         fi
  900.       fi
  901.     fi
  902.   fi
  903.  
  904. #
  905. # Lets save a copy of every config file that was used. ************************
  906. #
  907.   ext=$(date +%y%m%d.%H%M%S)
  908.   cp .config "$compile_folder/$config_folder/config_sav.$ext"
  909.  
  910. #
  911. # Take the defaults for all new kernel module configurations ******************
  912. #
  913.   yes "" | make oldconfig >> $log_file_name 2>&1
  914.  
  915.   configure_exit=$?
  916.  
  917. #
  918. # Would you like to modify your Kernel configurations in a GUI? ***************
  919. #
  920.   status_display 3
  921.  
  922.   get_input
  923.  
  924.   if [[ $CHOICE == [Yy] ]] ; then
  925.     tput clear
  926.     make menuconfig
  927.     configure_exit=$?
  928.     if [ $configure_exit -gt 0 ] ; then
  929.       make xconfig
  930.       configure_exit=$?
  931.     fi
  932.     display_header
  933.   fi
  934.  
  935. #
  936. # 2.  Kernel File Configuration: Completed! ***********************************
  937. #
  938.   progress_display 2
  939.  
  940. #
  941. # S.A.K.C. Kernel Compile *****************************************************
  942. #
  943.   start_of_compile=$(date +%m/%d/%y-%H:%M:%S)
  944.  
  945. #
  946. # Your Kernel file is now being Compiled.      Please Wait ... ****************
  947. #
  948.   status_display 4
  949.  
  950.   if $show_time ; then
  951.     time_display
  952.   fi
  953.  
  954.   if [ $Jobs -ge 2 ] ; then
  955.  
  956.     log_heading "make -j$Jobs"
  957.  
  958.     make -j$Jobs >> $log_file_name 2>&1
  959.     compile_exit=$?
  960.  
  961.   else
  962.  
  963.     log_heading "make"
  964.  
  965.     make >> $log_file_name 2>&1
  966.     compile_exit=$?
  967.   fi
  968.  
  969. #
  970. # Kill Background Elasped Time Display shown during the compile ***************
  971. #
  972.   if $show_time ; then
  973.     disown $PID1
  974.     kill -9 $PID1
  975.   fi
  976.  
  977. #
  978. # 3.  Kernel File Compile Process: Completed! *********************************
  979. #
  980.   progress_display 3
  981.  
  982.   end_of_compile=$(date +%m/%d/%y-%H:%M:%S)
  983.  
  984. #
  985. # Your Kernel file has been Compiled Successfully! ****************************
  986. #
  987.   status_display 5
  988.  
  989. #
  990. # Play a Sound file When the Compile is Complete ******************************
  991. #
  992.   which $wav_Player > /dev/null 2>&1
  993.   error_code1=$?
  994.  
  995.   which $wav_File > /dev/null 2>&1
  996.   error_code2=$?
  997.  
  998.   if $Play_Sound ; then
  999.     if [ $(( error_code1 )) -eq 0 ] || [ $(( error_code2 )) -eq 0 ] ; then
  1000.       $wav_Player -q $wav_File > /dev/null 2>&1
  1001.     fi
  1002.   fi
  1003.  
  1004. #
  1005. # S.A.K.C. Kernel Install *****************************************************
  1006. #
  1007.  
  1008.   get_password
  1009.  
  1010. # Your Kernel file is now being Installed.     Please Wait ...
  1011.   status_display 6
  1012.  
  1013.   log_heading "make modules_install install"
  1014.  
  1015.   sudo make modules_install install >> $log_file_name 2>&1
  1016.   install_exit=$?
  1017.  
  1018. # 4.  Kernel File Installation: Completed!
  1019.   progress_display 4
  1020.  
  1021. #
  1022. # S.A.K.C. is Complete ********************************************************
  1023. #
  1024.  
  1025.   script_stops=$(date +%m/%d/%y-%H:%M:%S)
  1026.  
  1027.   log_complete
  1028.  
  1029.   if $log_file ; then
  1030. # Would you like to view your Kernel Config/Compile Log File?
  1031.     status_display  7
  1032.     get_input
  1033.     if [[ $CHOICE == [Yy] ]] ; then
  1034.       less $log_file_name
  1035.     fi
  1036.   fi
  1037.  
  1038. # Your Kernel file Has Been Installed Successfully
  1039.   status_display  8
  1040.   print_color 19 0 7 1 1 "  Script Start: $script_start              Script Finish: $script_stops "
  1041.   tput cup 24 0
  1042.   read something
  1043.   tput clear
  1044.   banner
  1045.   show_gpl
  1046.   if [ $turbomode != true ] || [ $manual_config == true ] ; then
  1047.     if [ -f "$compile_folder/$config_folder/turbomode" ] ; then
  1048.       rm "$compile_folder/$config_folder/turbomode"
  1049.     fi
  1050.   fi
  1051. fi
  1052.  
  1053. exit 0
  1054.  
  1055. # End Of Script
  1056.