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

Info:

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

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

  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 Apr 22 16:53:00 CST 2012
  6. #: Author      : J. McDaniel
  7. #: Version     : 2.71
  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.71 "
  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 April 22, 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. # Set .config editor based on desktop *****************************************
  178. #
  179. function set_editor {
  180.  
  181. #
  182. # Determine which desktop that we are using ***********************************
  183. #
  184.   ps nc -C plasma-desktop >/dev/null && de=1    # For kde
  185.   ps nc -C xfce4-panel >/dev/null && de=2       # For xfce
  186.   ps nc -C gnome-panel >/dev/null && de=3       # For gnome2
  187.   ps nc -C gnome-shell >/dev/null && de=4       # For gnome3
  188.   ps nc -C lxsession >/dev/null && de=5         # lxde
  189.  
  190. #
  191. # Insert the Name Of your Favorite KDE or GNOME File Editor *******************
  192. #
  193.   case "$de" in
  194.     "1") EDITOR="kwrite"                ;; # For KDE
  195.     "2") EDITOR="mousepad"      ;; # For xfce
  196.     "3") EDITOR="gedit"                 ;; # For gnome2
  197.     "4") EDITOR="gedit"                 ;; # For gnome3
  198.     "5") EDITOR="leafpad"       ;; # For lxde
  199.     *) exit 1 ;;
  200.   esac
  201. #
  202. # Set Editor to what you want or prefer here just add the name and remove remark
  203. #
  204. # EDITOR="kwrite"
  205.   return 0
  206. }
  207.  
  208. #
  209. # Display All Text in Color as requested
  210. #
  211. # syntax: print_color line col fgrd_color bgrd_color #lines "text"...
  212. #
  213. # 0: Black 1: Blue 2: Green 3: Cyan 4: Red  5: Magenta 6: Yellow 7: White
  214. #
  215. function print_color {
  216.   WIDTH=$(tput cols)
  217.   HEIGHT=$(tput lines)
  218.   line_os=0
  219.   if [ $(($WIDTH)) -le  80  ] ; then
  220.     col_os=0
  221.   else
  222.     col_os=$((($WIDTH - 80) / 2 ))
  223.   fi
  224.   fgrd=${3}
  225.   bgrd=${4}
  226.   s_line=${1}
  227.   s_col=${2}
  228.   maxnum=${5}
  229.   counter=0
  230.   while [ $(( counter )) -lt $(( maxnum + 1 )) ] ; do
  231.     tput cup $(( s_line + counter + line_os)) $(( s_col + col_os ))
  232.     color $((fgrd)) $((bgrd)) B
  233.     echo "${6}$(tput sgr0)"
  234.     let counter=counter+1
  235.     shift
  236.   done
  237. }
  238.  
  239. #
  240. # Display Elapsed Time While doing the compile / This runs in the background
  241. #
  242. function time_display {
  243.   tput cup $(( 14 + line_os)) $(( 41 + col_os ))
  244.   echo -n "Elapsed Time: 0   minute(s) "
  245.   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 &
  246. PID1=$!
  247. }
  248.  
  249. #
  250. # Extract the base Kernel Folder Name from .tar.bz2 File Name *****************
  251. #
  252. function folder_name {
  253.   shortname=$(basename $FILE)
  254.   NUM=${#shortname}
  255.   folder="${shortname:0:$(($NUM-8))}"
  256.   NUM=${#folder}
  257. }
  258.  
  259. #
  260. # S.A.K.C. Main Header Display ************************************************
  261. #
  262. function display_header {
  263.  
  264.   tput clear
  265.  
  266.   print_color 1 0 7 0 1 "$(date +%m/%d/%y)"
  267.   print_color 1 $((80-NUM)) 7 0 1 "$folder"
  268.  
  269.   print_color 3 0 7 2 1 "           $TITLE           "
  270.   if $turbomode ; then
  271.     print_color 1 34 4 0 1               "TURBO MODE"
  272.   fi
  273.   l1="--------------------------------------------------------------------------------"
  274.   l2=""
  275.   l3="--------------------------------------------------------------------------------"
  276.   l4=""
  277.   l5="--------------------------------------------------------------------------------"
  278.   l6=" Num          Function                    Status                      Exit Code "
  279.   l7="--------------------------------------------------------------------------------"
  280.  
  281.   print_color 2 0 3 0 7 "$l1" "$l2" "$l3" "$l4" "$l5" "$l6" "$l7"
  282.  
  283.   l1="  1.  Kernel File Decompression:                                                "
  284.   l2=""
  285.   l3="  2.  Kernel File Configuration:                                                "
  286.   l4=""
  287.   l5="  3.  Kernel File Compile Process:                                              "
  288.   l6=""
  289.   l7="  4.  Kernel File Installation:                                                 "
  290.   print_color 10 0 7 0 7 "$l1" "$l2" "$l3" "$l4" "$l5" "$l6" "$l7"
  291.   l1="--------------------------------------------------------------------------------"
  292.   l2=""
  293.   l3="--------------------------------------------------------------------------------"
  294.   print_color 18 0 3 0 3 "$l1" "$l2" "$l3"
  295. }
  296.  
  297. #
  298. # S.A.K.C. top status display *************************************************
  299. #
  300. function status_display {
  301.  
  302.   case $1 in
  303.  
  304.     1) print_color 5 0 7 1 1 "          Your Kernel file is now being uncompressed.  Please Wait ...          " ;;
  305.     2) print_color 5 0 6 1 1 "          Your Kernel file is now being Configured.    Please Wait ...          " ;;
  306.     3) print_color 5 0 7 4 1 "        Would you like to modify your Kernel configurations in a GUI?           " ;;
  307.     4) print_color 5 0 7 1 1 "          Your Kernel file is now being Compiled.      Please Wait ...          " ;;
  308.     5) print_color 5 0 7 4 1 "              Your Kernel file has been Compiled Successfully!                  " ;;
  309.     6) print_color 5 0 6 1 1 "          Your Kernel file is now being Installed.     Please Wait ...          " ;;
  310.     7) print_color 5 0 7 4 1 "      Would you like to view your Kernel Config/Compile/Install Log File?       " ;;
  311.     8) print_color 5 0 7 1 1 "                Your Kernel file Has Been Installed Successfully                " ;;
  312.     *) ;;
  313.  
  314.   esac
  315.   tput cup $(( 5 + line_os)) $(( 75 + col_os ))
  316. }
  317.  
  318. #
  319. # S.A.K.C. Kernel Function progress display ***********************************
  320. #
  321. function progress_display {
  322.   for ((i=1;i<=$1;++i)) ; do
  323.     case $i in
  324.       1) ON_LINE=10
  325.          Exit_Code=$uncompress_exit ;;
  326.       2) ON_LINE=12
  327.          Exit_Code=$configure_exit ;;
  328.       3) ON_LINE=14
  329.          Exit_Code=$compile_exit ;;
  330.       4) ON_LINE=16
  331.          Exit_Code=$install_exit ;;
  332.       *) ;;
  333.     esac
  334.     print_color $(( ON_LINE )) 74 7 0 1 "$Exit_Code"
  335.     if [ $(( Exit_Code )) -ge 1 ] ; then
  336.       print_color $(( ON_LINE )) 41 4 0 1 "Failed!   "
  337.       exit $Exit_Code
  338.     else
  339.       print_color $(( ON_LINE )) 41 7 0 1 "Completed!   "
  340.     fi
  341.   done
  342. }
  343.  
  344. #
  345. # Get User Input Display ******************************************************
  346. #
  347. function get_input {
  348.   print_color 19 10 7 0 1 " Please make your selection and press <enter> (Y=Yes/N=No): "
  349.   tput cup $(( 19 + line_os)) $(( 69 + col_os ))
  350.   read CHOICE
  351.   print_color 19 10 7 0 1 "                                                            "
  352. }
  353.  
  354. #
  355. # Get User Input & password Display *******************************************
  356. #
  357. function get_password {
  358.   print_color 19 9 7 0 1 " Press the <enter> key to proceed to your Kernel Instalation "
  359.   tput cup $(( 19 + line_os)) $(( 69 + col_os ))
  360.   read CHOICE
  361.   print_color 19 9 7 0 1 "                                                             "
  362.   tput cup $(( 16 + line_os)) $(( 41 + col_os ))
  363.   sudo dir > /dev/null
  364.   tput cup $(( 16 + line_os)) $(( 41 + col_os ))
  365.   echo "                "
  366. }
  367.  
  368. #
  369. # Prompt for user input in bold while, for startup error messages *************
  370. #
  371. function enter_prompt {
  372.   echo
  373.   tput bold
  374.   tput setf 7
  375.   tput cup $(( 4 + line_os)) $(( 0 + col_os ))
  376.   echo -n "$1$(tput sgr0)"
  377.   read CHOICE
  378.   echo
  379. }
  380.  
  381. #
  382. # Setup Name and Location of your Log File ************************************
  383. #
  384. function start_log {
  385.   ext=$(date +%m%d%y.%H%M%S)
  386.   if $log_file ; then
  387.     log_file_name=$log_file_location"/"$folder"."$ext".txt"
  388.   else
  389.     log_file_name="/dev/null"
  390.   fi
  391. # Start The Log File Output if Selected
  392.   echo "$TITLE" > $log_file_name
  393.   echo " " >> $log_file_name
  394.   echo " S.A.C.K. Start: $script_start of kernel: $folder " >> $log_file_name
  395.   echo " " >> $log_file_name
  396. }
  397.  
  398. function log_heading {
  399. echo " " >> $log_file_name
  400. echo "*********** Command: $1 *********************" >> $log_file_name
  401. echo " " >> $log_file_name
  402. }
  403.  
  404. function log_complete {
  405. echo " " >> $log_file_name
  406. echo " Compile Start: $start_of_compile             Compile Finish: $end_of_compile " >> $log_file_name
  407. echo "  Script Start: $script_start              Script Finish: $script_stops " >> $log_file_name
  408. echo " " >> $log_file_name
  409. echo "            $TITLE            " >> $log_file_name
  410. }
  411.  
  412. #
  413. # Common Text to Display When an Error is Detected ****************************
  414. #
  415. function error_message {
  416.   tput clear
  417.   color 2 0 B
  418.   echo $Dash1
  419.   color 7 2 B
  420.   echo "$TITLE"
  421.   color 2 0 B
  422.   echo $Dash1
  423.   color 7 0 B
  424.   echo
  425.   color 7 4 B
  426.   echo "$1"
  427.   color 7 0 B
  428.   echo
  429. }
  430.  
  431. #
  432. # Kernel Configuration Selector ***********************************************
  433. #
  434. function config_slection {
  435.   config_menu=true
  436.   delete_config=false
  437.   edit_config=false
  438.   while $config_menu ; do
  439.     if $delete_config ; then
  440.       error_message "You have elected to manually Delete a kernel config file!"
  441.     else
  442.       if $edit_config ; then
  443.         error_message "You have elected to manually Edit a kernel config file!"
  444.       else
  445.         error_message "You have elected to manually Select the kernel config file!"
  446.       fi
  447.     fi
  448.     color 6 1 B
  449.     echo "Active Config uses your Config from your running Kernel."
  450.     echo "Configs < 100kB in size suggest they are for Turbo Mode."
  451.     echo "Configs from a Turbo Compile will always Compile Fast.  "
  452.     color 7 0 B
  453.     echo
  454.     echo "Please select the configuration file from this list:"
  455.     echo
  456.     let counter=0
  457.     for i in $compile_folder/$config_folder/c* ; do
  458.       if [ -f $i ] ; then
  459.         let counter=counter+1
  460.         configs[$counter]=$(basename $i)
  461.         file_size $compile_folder/$config_folder/${configs[$counter]} KB
  462.         color 7 0 B
  463.         echo -n " $counter) "
  464.         color 3 0 B
  465.         echo -n "${configs[$counter]}, "
  466.         color 7 0 B
  467.         echo -n "filesize="
  468.         color 3 0 B
  469.         echo -n "$filesize"
  470.         color 7 0 B
  471.         if [ $counter -eq 1 ] ; then
  472.           echo ", Original Default Config"
  473.         else
  474.           echo -n ", Ext="
  475.           color 3 0 B
  476.           echo "Date.Time"
  477.           color 7 0 B
  478.         fi
  479.       fi
  480.     done
  481.     if [[ $counter -eq 0 ]]; then
  482.       echo
  483.       color 7 4 B
  484.       echo "No Kernel Config Files were found in $compile_folder/$config_folder!"
  485.       color 7 0 B
  486.       echo
  487.       exit 1
  488.     fi
  489.     echo
  490.     if [ $delete_config == false ] && [ $edit_config == false ] ; then
  491.       echo "Commands: S=Save, D=Delete, E=Edit or A=Active Config & Q=Quit"
  492.     else
  493.       echo "Commands: B=Back to Config Select or Q=Quit"
  494.     fi
  495.     echo
  496.     color 7 1 B
  497.     if $delete_config ; then
  498.       echo -n "Please Select Kernel Config File # [1-$counter] or (Q/B): "
  499.     else
  500.       if $edit_config ; then
  501.         echo -n "Please Select Kernel Config File # [1-$counter] or (Q/B): "
  502.       else
  503.         echo -n "Please Select Kernel Config File # [1-$counter] or (S/D/E/A/Q): "
  504.       fi
  505.     fi
  506.     color 7 0 B
  507.     read CHOICE
  508.     if [[ $CHOICE =~ ^[0-9]+$ ]] ; then
  509.       if [[ $CHOICE -le $counter ]] && [[ $CHOICE -gt 0 ]]; then
  510.         if $delete_config ; then
  511.             if [ -f "$compile_folder/$config_folder/${configs[$CHOICE]}" ] ; then
  512.               echo
  513.               read -p "Are You Sure you want to remove: ${configs[$CHOICE]}? (y/N): " something
  514.               if [[ $something == [yY] ]] ; then
  515.                 rm "$compile_folder/$config_folder/${configs[$CHOICE]}"
  516.               fi
  517.             fi
  518.         else
  519.           if $edit_config ; then
  520.             $EDITOR "$compile_folder/$config_folder/${configs[$CHOICE]}"
  521.           else
  522.             config_menu=false
  523.             config_name=${configs[$CHOICE]}
  524.           fi
  525.         fi
  526.       else
  527.         config_name="config.sav"
  528.       fi
  529.     else
  530.       if [[ $CHOICE == [sS] ]] ; then
  531.         ext=$(date +%y%m%d.%H%M%S)
  532.         echo "# Created on $ext by $TITLE" > "$compile_folder/$config_folder/config_sav.$ext"
  533.         zcat /proc/config.gz >> "$compile_folder/$config_folder/config_sav.$ext"
  534.       fi
  535.       if [[ $CHOICE == [dD] ]] ; then
  536.         delete_config=true
  537.       fi
  538.       if [[ $CHOICE == [eE] ]] ; then
  539.         edit_config=true
  540.       fi
  541.       if [[ $CHOICE == [bB] ]] ; then
  542.         delete_config=false
  543.         edit_config=false
  544.       fi            
  545.       if [[ $CHOICE == [aA] ]] ; then
  546.         if [ $delete_config == false ] ; then
  547.            use_active_config=true
  548.            config_menu=false
  549.         fi
  550.       fi
  551.       if [[ $CHOICE == [Qq] ]] ; then
  552.         clear
  553.         banner
  554.         show_gpl
  555.         exit 0
  556.       fi
  557.     fi
  558.   done
  559. }
  560.  
  561. #
  562. # Allow new Compile option that can speed up the Compile time *****************
  563. #
  564. function use_turbo_mode {
  565. # We Must save a copy of your config file before you EVER use Turbo Mode
  566.  
  567.   if [ "$turbomode" == "ask" ] ; then
  568.     error_message "Do you wish to Enable the Turbo Mode Compiler? (Y=Yes/N=No)"
  569.     color 7 0 B
  570.     echo -n "On Your Last Compile You: "
  571.     color 3 0 B
  572.     if [ -f "$compile_folder/$config_folder/turbomode" ] ; then
  573.       echo "Used the Turbo Compile Mode"
  574.     else
  575.       echo "Did Not Use Turbo Compile Mode"
  576.     fi
  577.     echo
  578.     color 7 1 B
  579.     echo "Using Turbo Mode can reduce the compile time up to 25% of  "                                                                                                  
  580.     echo "normal.  Before using Turbo Mode, All hardware you expect  "                                                                                            
  581.     echo "to use with this kernel should be connected now and turned "                                                                                          
  582.     echo "on.  Failure to do so might cause them to not work.  If    "                                                                                          
  583.     echo "you have issues using this option, just recompile and don't"                                                                                                
  584.     echo "use the Turbo Mode Compile Mode option.  If you want to use"
  585.     echo "the new Turbo Mode Compiler and you are not sure everything"
  586.     echo "is connected turned on and working, then Quit now and make "
  587.     echo "sure it is on! Please see the C=Config menu for more kernel"
  588.     echo "configuration options.  Using Active Config from the Config"
  589.     echo "menu preserves all installed Turbo Compile Modules from a  "
  590.     echo "previous successful Turbo Mode Compile and will be as fast."
  591.     echo
  592.     color 7 4 B
  593.     read -s -n1 -p "Wish to Use the fast Turbo Mode Compiler? (y/N) Q=Quit: " CHOICE
  594.     color 7 0 B
  595.     if [[ $CHOICE == [qQ] ]] ; then
  596.       clear
  597.       banner
  598.       show_gpl
  599.       exit 0
  600.     fi
  601.     if [[ $CHOICE == [yY] ]] ; then
  602.       turbomode=true
  603.       echo "true" > $compile_folder/$config_folder/turbomode
  604.     else
  605.       turbomode=false
  606.     fi
  607.   else
  608.     if [ $turbomode != true ] ; then
  609.       if [ $turbomode != false ] ; then
  610.         turbomode=false
  611.       fi
  612.     fi
  613.   fi
  614. }
  615.  
  616. #
  617. # 2nd Menu to be displayed ****************************************************
  618. #
  619. function menu_two {
  620.   manual_config=false
  621.   use_active_config=false
  622.   if [ ! -f "$compile_folder/$config_folder/config.sav" ] ; then
  623.         cp /boot/config-*-desktop "$compile_folder/$config_folder/config.sav" 2>&1
  624.   fi
  625.   if [ ! -f "$compile_folder/$config_folder/config.sav" ] ; then
  626.         cp /boot/config-*-default "$compile_folder/$config_folder/config.sav" 2>&1
  627.   fi
  628.   if [ ! -f "$compile_folder/$config_folder/config.sav" ] ; then
  629.           zcat /proc/config.gz >"$compile_folder/$config_folder/config.sav"
  630.   fi
  631.   error_message "Kernel Source File: $FILE"
  632.   color 3 0 B
  633.   echo -n "1) "
  634.   color 7 0 B
  635.   echo "Standand Kernel Compile (All Users)"
  636.   color 3 0 B
  637.   echo
  638.   echo -n "2) "
  639.   color 7 0 B
  640.   echo "Turbo Mode Selection Menu (Advanced Users Only)"
  641.   echo
  642.   color 3 0 B
  643.   echo -n "3) "
  644.   color 7 0 B
  645.   echo "Kernel Configuration Selection Menu (Advanced Users Only)"
  646.   echo
  647.   color 3 0 B
  648.   echo -n "Q) "
  649.   color 7 0 B
  650.   echo "Quit SAKC Compiler Selection Menu"
  651.   echo
  652.   color 7 2 B
  653.   echo -n "Please Select From these SAKC Compiler Options [1-3] Q=Quit"
  654.   color 7 0 B
  655.   while [ "$CHOICE" == "" ] ; do
  656.     read -s -n1 CHOICE
  657.     if [[ $CHOICE == [qQ] ]] ; then
  658.       clear
  659.       banner
  660.       show_gpl
  661.       exit 0
  662.     fi
  663.     if [[ $CHOICE == [123] ]] ; then
  664.       if [ $CHOICE -eq 1 ] ; then
  665.         turbomode=false
  666.       fi
  667.       if [ $CHOICE -eq 2 ] ; then
  668.         use_turbo_mode
  669.       fi
  670.       if [ $CHOICE -eq 3 ] ; then
  671.         config_slection
  672.         turbomode=false
  673.         manual_config=true
  674.         if $use_active_config ; then
  675.           manual_config=false
  676.         else
  677.           echo
  678.           echo -n "Your Config Selection was: "
  679.           color 3 0 B
  680.           echo -n "$config_name"
  681.           color 7 0 B
  682.           read -p ", Press Enter to Continue ..." something
  683.         fi
  684.       fi
  685.     else
  686.       CHOICE=""
  687.     fi
  688.   done
  689.   return 0
  690. }
  691.  
  692. #
  693. # Help is Displayed from here *************************************************
  694. #
  695. function help {
  696.     cat << EOFHELP
  697.  
  698. $TITLE
  699.  
  700. Your S.A.K.C. Startup and help options are:
  701.  
  702. $0 -h --help :to show this help
  703.  
  704. OR
  705.  
  706. $0 [kernel_file_name.bz2]
  707.  
  708. The kernel_file_name.bz2 name is optional and will be requested if not supplied.
  709.  
  710. EOFHELP
  711. show_gpl
  712. exit 0
  713. }
  714.  
  715. #
  716. # Display Help if requested.  Example from Findgrub ***************************
  717. #
  718. case "$1" in
  719.     -h|--help) help ;;
  720. esac
  721.  
  722. #
  723. # S.A.K.C. Display Error Messages *********************************************
  724. #
  725. tput clear        
  726.  
  727. #
  728. # Make sure script was not started as root ************************************
  729. #
  730. if [ $UID -eq 0 ] ; then
  731.   l1=""
  732.   l2=" Do Not Start $(basename $0) as a root user!  Your password will be "
  733.   l3=" requested later when needed to install your new Kernel.  "
  734.   print_color 0 0 7 4 4 "$TITLE" "$l1" "$l2" "$l3"
  735.   enter_prompt "Press <enter> to exit..."
  736.   exit 2
  737. fi
  738.  
  739. #
  740. # Determine if the compile_folder exists **************************************
  741. #
  742. if [[ -d "$compile_folder" ]] ; then
  743.   cd "$compile_folder"
  744.   if [[ ! -d "$config_folder" ]] ; then
  745.     mkdir "$config_folder"
  746.   fi
  747. else
  748.   error_message "The Kernel Compile Folder: $compile_folder, does not exist!"
  749.   echo "Please create or change this folder name and start $(basename $0) again."
  750.   echo
  751.   exit 1
  752. fi
  753.  
  754. #
  755. # Make sure the sakc script file exists in the folder specified ***************
  756. #
  757. if [ ! -e "$sakc_name" ] ; then
  758.   error_message "The S.A.K.C. Kernel Source File Compiler: $sakc_name, was not found!"
  759.   exit 1
  760. fi
  761.  
  762. #
  763. # Determine if a kernel file name was given at start **************************
  764. #
  765. if [ $# -eq 0 ] ; then
  766.  
  767. #
  768. # Determine if the kernel_folder (default is ~/Downloads) Exists **************
  769. #
  770.   if [[ -d "$kernel_folder" ]] ; then
  771.  
  772.     menu=true
  773.     delete_kernel=false
  774.     while $menu ; do
  775.  
  776.       tput clear
  777.       color 2 0 B
  778.       echo $Dash1
  779.       color 7 2 B
  780.       echo "$TITLE"
  781.       color 2 0 B
  782.       echo $Dash1
  783.       color 7 0 B
  784.       echo
  785.       echo -n "S.A.K.C. Location/Name: "
  786.       color 3 0 B
  787.       echo "$sakc_name"
  788.       color 7 0 B
  789.       echo
  790.       echo -n " Kernel Compile Folder: "
  791.       color 3 0 B
  792.       echo "$compile_folder"
  793.       color 7 0 B
  794.       echo -n " Kernel Config  Folder: "
  795.       color 3 0 B
  796.       echo "$compile_folder/$config_folder"
  797.       color 7 0 B
  798.       echo -n " Kernel Source  Folder: "
  799.       color 3 0 B
  800.       echo "$kernel_folder"
  801.       color 7 0 B
  802.       echo
  803.       echo -n " "
  804.       color 7 6 B
  805.       echo " Kernel Source File Tar Ball Listing "
  806.       color 7 0 B
  807.       echo
  808.  
  809.       counter=0
  810.       declare -a kernels
  811. #
  812. # Find and display all files that start with linux* and end with .tar.bz2
  813. #
  814.       for i in "$kernel_folder"/linux*.tar.bz2 ; do
  815. #
  816. # Determine if the kernel source file exists **********************************
  817. #
  818.         if [ -f $i ] ; then
  819.  
  820.           let counter=counter+1
  821.           kernels[$counter]=$i
  822.           color 7 0 B
  823.           echo -n " $counter) "
  824.           color 3 0 B
  825.           echo "$(basename ${kernels[$counter]})"
  826.  
  827.         fi
  828.  
  829.       done
  830. #
  831. # Determine if any Kernel Source Files were found *****************************
  832. #
  833.       if [[ $counter -eq 0 ]]; then
  834.  
  835.         echo
  836.         color 7 4 B
  837.         echo "No Kernel Source Files were found in $kernel_folder!"
  838.         color 7 0 B
  839.         echo
  840.         exit 1
  841.  
  842.       fi
  843. #
  844. # Main Program Prompt Displayed Here ******************************************
  845. #
  846.       echo
  847.       color 7 1 B
  848.       if $delete_kernel ; then
  849.         echo -n "Enter Kernel Source File # to Delete (Q=Quit,B=Back): "
  850.       else
  851.         echo -n "Enter Kernel Source File # to Compile (Q=Quit,D=Delete): "
  852.       fi
  853.       color 7 0 B
  854.       read CHOICE
  855. #
  856. # Determine if input ($CHOICE) is an integer number and in range, look for Q to
  857. # Quit. If menu is not set to false, the menu will just be redisplayed as you
  858. # did not enter a valid menu option number for a kernel source file to compile.
  859. #
  860.       if [[ $CHOICE =~ ^[0-9]+$ ]] ; then
  861.         if [[ $CHOICE -le $counter ]] && [[ $CHOICE -gt 0 ]]; then
  862.           if $delete_kernel ; then
  863.             echo
  864.             read -p "Are You Sure you want to remove: $(basename ${kernels[$CHOICE]})? (y/N): " something
  865.             if [[ $something == [yY] ]] ; then
  866.               rm "${kernels[$CHOICE]}"
  867.             fi
  868.           else
  869.             menu=false
  870.           fi
  871.         fi
  872.       else
  873.         if [[ $CHOICE == [Qq] ]] ; then
  874.           clear
  875.           banner
  876.           show_gpl
  877.           exit 0
  878.         fi
  879.         if [[ $CHOICE == [dD] ]] ; then
  880.           delete_kernel=true
  881.         fi
  882.         if [[ $CHOICE == [bB] ]] ; then
  883.           delete_kernel=false
  884.         fi    
  885.       fi
  886.     done
  887.  
  888.     $sakc_name ${kernels[$CHOICE]}
  889.  
  890.   else
  891.  
  892. #
  893. # The Kernel Source File Folder (default=~/Downloads) was not found ***********
  894. #
  895.     error_message "The Kernel Source File Folder: $kernel_folder, does not exist!"
  896.     exit 1
  897.   fi
  898.   exit 0
  899. else
  900.  
  901. #
  902. # Make sure we got kernel source file name as a command line argument *********
  903. #
  904.   if [ $# -eq 0 ] ; then
  905.     l1=""
  906.     l2=" Command Syntax is: $(basename $0) kernel_source_file_name.tar.bz2  "
  907.     l3=""
  908.     print_color 0 0 7 4 4 "$TITLE" "$l1" "$l2" "$l3"
  909.     enter_prompt "Press <enter> to exit..."
  910.     exit 1
  911.   fi
  912.  
  913. #
  914. # Determine if kernel file-name is present ************************************
  915. #
  916.   if [ ! -e $FILE ] ; then
  917.     l1=""
  918.     l2=" The Kernel Source file: --> $1 <-- was not Found!  "
  919.     l3=""
  920.     print_color 0 0 7 4 4 "$TITLE" "$l1" "$l2" "$l3"
  921.     enter_prompt "Press <enter> to exit..."
  922.     exit 10
  923.   fi
  924.  
  925. #
  926. # S.A.K.C. Main Program Starts Here *******************************************
  927. #
  928.   set_editor
  929.   menu_two
  930.   folder_name
  931.   start_log
  932.   display_header
  933.  
  934. #
  935. # S.A.K.C. Kernel Decompression ***********************************************
  936. #
  937.  
  938. #
  939. # Your Kernel file is now being uncompressed.  Please Wait ... ****************
  940. #
  941.   status_display 1
  942.  
  943.   tar -vxjf $FILE > /dev/null 2>&1
  944.   uncompress_exit=$?
  945. #
  946. # 1.  Kernel File Decompression: Completed! ***********************************
  947. #
  948.   progress_display 1
  949.  
  950.   if [ -d "$folder" ] ; then
  951.     cd $folder
  952.   else
  953.     error_message "Kernel Source Folder $folder Does Not Exist!"
  954.     read -p "Press Any Key to Exit S.A.K.C." CHOICE
  955.     exit 1
  956.   fi
  957.  
  958. #
  959. # S.A.K.C. Kernel Configuration ***********************************************
  960. #
  961.  
  962. #
  963. # Your Kernel file is now being Configured.    Please Wait ... ****************
  964. #
  965.   status_display 2
  966.  
  967.   log_heading "make mrproper"
  968.  
  969. #
  970. # Fix any left over compile issues before we start again **********************
  971. #
  972.   make mrproper 2>&1 >> $log_file_name
  973.  
  974. #
  975. # Get the Configuration for the running kernel ********************************
  976. #
  977.   log_heading "make oldconfig"
  978.  
  979. #
  980. # What kernel config file are you using? **************************************
  981. #
  982.   if $manual_config ; then
  983.     cp "$compile_folder/$config_folder/$config_name" .config
  984.     echo "**** Manual Config file was selected ****" >> $log_file_name
  985.   else
  986.     if $turbomode ; then
  987.       chmod +x ./scripts/kconfig/streamline_config.pl
  988.       text=$(./scripts/kconfig/streamline_config.pl 2>&1 > ./config_strip)
  989.       mv ./config_strip ./.config
  990.       echo "**** Turbo Compile Mode is Enabled ****" >> $log_file_name
  991.     else
  992.       if $use_active_config ; then
  993.         zcat /proc/config.gz >.config
  994.         echo "**** Using Last Kernel Configuration ****" >> $log_file_name
  995.       else
  996.         echo "**** Turbo Compile Mode is Disabled ****" >> $log_file_name
  997.         if [ -f "$compile_folder/$config_folder/turbomode" ] ; then
  998.           if [ -f "$compile_folder/$config_folder/config.sav" ] ; then
  999.             cp "$compile_folder/$config_folder/config.sav" .config
  1000.           else
  1001.             zcat /proc/config.gz >.config
  1002.           fi
  1003.         else
  1004.           zcat /proc/config.gz >.config
  1005.         fi
  1006.       fi
  1007.     fi
  1008.   fi
  1009.  
  1010. #
  1011. # Lets save a copy of every config file that was used. ************************
  1012. #
  1013.   ext=$(date +%y%m%d.%H%M%S)
  1014.   if $turbomode ; then
  1015.     echo "# Created on $ext by $TITLE in TURBO MODE" > "$compile_folder/$config_folder/config_sav.$ext"
  1016.     cat .config >> "$compile_folder/$config_folder/config_sav.$ext"
  1017.   else
  1018.     echo "# Created on $ext by $TITLE" > "$compile_folder/$config_folder/config_sav.$ext"
  1019.     cat .config >> "$compile_folder/$config_folder/config_sav.$ext"
  1020.   fi
  1021. #
  1022. # Take the defaults for all new kernel module configurations ******************
  1023. #
  1024.   yes "" | make oldconfig >> $log_file_name 2>&1
  1025.  
  1026.   configure_exit=$?
  1027.  
  1028. #
  1029. # Would you like to modify your Kernel configurations in a GUI? ***************
  1030. #
  1031.   status_display 3
  1032.  
  1033.   get_input
  1034.  
  1035.   if [[ $CHOICE == [Yy] ]] ; then
  1036.     tput clear
  1037.     make menuconfig
  1038.     configure_exit=$?
  1039.     if [ $configure_exit -gt 0 ] ; then
  1040.       make xconfig
  1041.       configure_exit=$?
  1042.     fi
  1043.     display_header
  1044.   fi
  1045.  
  1046. #
  1047. # 2.  Kernel File Configuration: Completed! ***********************************
  1048. #
  1049.   progress_display 2
  1050.  
  1051. #
  1052. # S.A.K.C. Kernel Compile *****************************************************
  1053. #
  1054.   start_of_compile=$(date +%m/%d/%y-%H:%M:%S)
  1055.  
  1056. #
  1057. # Your Kernel file is now being Compiled.      Please Wait ... ****************
  1058. #
  1059.   status_display 4
  1060.  
  1061.   if $show_time ; then
  1062.     time_display
  1063.   fi
  1064.  
  1065.   if [ $Jobs -ge 2 ] ; then
  1066.  
  1067.     log_heading "make -j$Jobs"
  1068.  
  1069.     make -j$Jobs >> $log_file_name 2>&1
  1070.     compile_exit=$?
  1071.  
  1072.   else
  1073.  
  1074.     log_heading "make"
  1075.  
  1076.     make >> $log_file_name 2>&1
  1077.     compile_exit=$?
  1078.   fi
  1079.  
  1080. #
  1081. # Kill Background Elasped Time Display shown during the compile ***************
  1082. #
  1083.   if $show_time ; then
  1084.     disown $PID1
  1085.     kill -9 $PID1
  1086.   fi
  1087.  
  1088. #
  1089. # 3.  Kernel File Compile Process: Completed! *********************************
  1090. #
  1091.   progress_display 3
  1092.  
  1093.   end_of_compile=$(date +%m/%d/%y-%H:%M:%S)
  1094.  
  1095. #
  1096. # Your Kernel file has been Compiled Successfully! ****************************
  1097. #
  1098.   status_display 5
  1099.  
  1100. #
  1101. # Play a Sound file When the Compile is Complete ******************************
  1102. #
  1103.   which $wav_Player > /dev/null 2>&1
  1104.   error_code1=$?
  1105.  
  1106.   which $wav_File > /dev/null 2>&1
  1107.   error_code2=$?
  1108.  
  1109.   if $Play_Sound ; then
  1110.     if [ $(( error_code1 )) -eq 0 ] || [ $(( error_code2 )) -eq 0 ] ; then
  1111.       $wav_Player -q $wav_File > /dev/null 2>&1
  1112.     fi
  1113.   fi
  1114.  
  1115. #
  1116. # S.A.K.C. Kernel Install *****************************************************
  1117. #
  1118.  
  1119.   get_password
  1120.  
  1121. # Your Kernel file is now being Installed.     Please Wait ...
  1122.   status_display 6
  1123.  
  1124.   log_heading "make modules_install install"
  1125.  
  1126.   sudo make modules_install install >> $log_file_name 2>&1
  1127.   install_exit=$?
  1128.  
  1129. # 4.  Kernel File Installation: Completed!
  1130.   progress_display 4
  1131.  
  1132. #
  1133. # S.A.K.C. is Complete ********************************************************
  1134. #
  1135.  
  1136.   script_stops=$(date +%m/%d/%y-%H:%M:%S)
  1137.  
  1138.   log_complete
  1139.  
  1140.   if $log_file ; then
  1141. # Would you like to view your Kernel Config/Compile Log File?
  1142.     status_display  7
  1143.     get_input
  1144.     if [[ $CHOICE == [Yy] ]] ; then
  1145.       less $log_file_name
  1146.     fi
  1147.   fi
  1148.  
  1149. # Your Kernel file Has Been Installed Successfully
  1150.   status_display  8
  1151.   print_color 19 0 7 1 1 "  Script Start: $script_start              Script Finish: $script_stops "
  1152.   tput cup 24 0
  1153.   read something
  1154.   tput clear
  1155.   banner
  1156.   show_gpl
  1157.   if [ $turbomode != true ] || [ $manual_config == true ] ; then
  1158.     if [ -f "$compile_folder/$config_folder/turbomode" ] ; then
  1159.       rm "$compile_folder/$config_folder/turbomode"
  1160.     fi
  1161.   fi
  1162. fi
  1163.  
  1164. exit 0
  1165.  
  1166. # End Of Script
  1167.