Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate

Advertising

Paste Description for aMoRPHeouS

I get a '"(" unexpected at line 64' error when I try to run the install script.

aMoRPHeouS
Sunday, January 14th, 2007 at 12:40:13am UTC 

  1. #!/bin/sh
  2. ###############################################################################
  3. # Part of Marvell Yukon/SysKonnect sk98lin Driver for Linux                   #
  4. ###############################################################################
  5. # Installation script for Marvell Chip based Ethernet Gigabit Cards           #
  6. # $Revision: 1.36 $                                                            #
  7. # $Date: 2004/08/17 15:29:07 $                                                #
  8. # =========================================================================== #
  9. #                                                                             #
  10. #  Main - Global function                                                     #
  11. #                                                                             #
  12. # Description:                                                                #
  13. #  This file includes all functions and parts of the script                   #
  14. #                                                                             #
  15. # Returns:                                                                    #
  16. #       N/A                                                                   #
  17. # =========================================================================== #
  18. # Usage:                                                                      #
  19. #     ./install.sh                                                            #
  20. #                                                                             #
  21. # =========================================================================== #
  22. # COPYRIGHT NOTICE :                                                          #
  23. #                                                                             #
  24. # (C)Copyright 2003-2004 Marvell(R).                                          #
  25. #                                                                             #
  26. #  This program is free software; you can redistribute it                     #
  27. #  and/or modify it under the terms of the GNU General Public                 #
  28. #  License as published by the Free Software Foundation; either               #
  29. #  version 2 of the License, or (at your option) any later version.           #
  30. #                                                                             #
  31. #                                                                             #
  32. # WARRANTY DISCLAIMER:                                                        #
  33. #                                                                             #
  34. # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT #
  35. # ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR       #
  36. # FITNESS FOR A PARTICULAR PURPOSE.                                           #
  37. #                                                                             #
  38. # =========================================================================== #
  39. #                                                                             #
  40. #     History:                                                                #
  41. #     2004-07-23 - Insert likely() if not available               (mlindner)  #
  42. #                  Display driver version in the log files                    #
  43. #                  Parameter check changed                                    #
  44. #                  Use /proc/config.gz if available                           #
  45. #     2004-07-01 - Better version.h check                         (mlindner)  #
  46. #     2004-04-26 - New parameter configuration                    (mlindner)  #
  47. #     2004-04-26 - Support for Intel x86_64 arch                  (mlindner)  #
  48. #     2004-02-15 - Support for yukon2 chipsets                    (mlindner)  #
  49. #                  Support for kernel 2.6                                     #
  50. #                  Support for parallel make on SMP-Hosts                     #
  51. #                  Make a patch against the current kernel                    #
  52. #                  Added help option.                                         #
  53. #                  More command line parameters for auto installation         #
  54. #                  Better SMP detection                                       #
  55. #                  Highmem detection                                          #
  56. #                                                                             #
  57. #                                                                             #
  58. ###############################################################################
  59.  
  60.  
  61. # Functions
  62. ###########################################
  63.  
  64. function message_status ()
  65. {
  66.         # Print a status message
  67.         # Syntax: message_status STATUS STRING
  68.         #       STATUS
  69.         #              0) FAILED
  70.         #              1) OK
  71.         #              2) WARN
  72.         # Author: mlindner
  73.         # Returns:
  74.         #       N/A
  75.  
  76.         if test -z "$LINES" -o -z "$COLUMNS" ; then
  77.                 eval `stty size 2>/dev/null | (read L C; \
  78.                 echo LINES=${L:-24} COLUMNS=${C:-80})`
  79.         fi
  80.         test $COLUMNS -eq 0 && COLUMNS=80
  81.         esc=`echo -en "\033"`
  82.         error="${esc}[1;31m"
  83.         ok="${esc}[1;32m"
  84.         warn="${esc}[1;33m"
  85.         working="${esc}[1;34m"
  86.         stat=`echo -en "\015${esc}[${COLUMNS}C${esc}[10D"`
  87.         norm=`echo -en "${esc}[m\017"`
  88.  
  89.         m_ok="${stat}[${ok}   OK   ${norm}]"
  90.         m_failed="${stat}[${error} failed ${norm}]"
  91.         m_warning="${stat}[${warn}  warn  ${norm}]"
  92.         m_working="${stat}${working}  working${norm}"
  93.         if [ "$2" != "working" ]; then
  94.                 echo -n " ($2)"
  95.         fi
  96.  
  97.         case "$1" in
  98.         3)      echo -n "$m_working" ;;
  99.         2)      echo "$m_warning" ;;
  100.         1)      echo "$m_ok" ;;
  101.         0)      echo "$m_failed" ;;
  102.         esac
  103.  
  104.         return 0;
  105. }
  106.  
  107. function make_safe_tmp_dir ()
  108. {
  109.         # Generate safe tmp dir
  110.         # Syntax: make_safe_tmp_dir
  111.         # Author: mlindner
  112.         # Returns:
  113.         #       TMP_DIRECTORY
  114.  
  115.         fname="Create tmp dir"
  116.         echo -n $fname
  117.         message_status 3 "working"
  118.         BASE_TMP_DIR="/tmp"
  119.         if ! [ -e "$BASE_TMP_DIR" ]; then
  120.                 BASE_TMP_DIR=`pwd`
  121.                 mkdir ${BASE_TMP_DIR}/tmp
  122.                 BASE_TMP_DIR=`echo ${BASE_TMP_DIR}/tmp`
  123.         fi     
  124.  
  125.         TMP_DIR=${BASE_TMP_DIR}/Sk98I`awk 'BEGIN { srand(); for (i=1;i<21;i++) { a=95; while (a > 90 && a < 97) { a=65+int(50*rand())}; printf("%c", a) } }'`
  126.  
  127.         [ -e "$TMP_DIR" ] && rm -rf $TMP_DIR
  128.         if [ -e "$TMP_DIR" ]; then
  129.                 echo
  130.                 echo "My temp dir exists already."
  131.                 echo "This looks like a symlink attack!"
  132.                 echo
  133.                 echo "*** Aborting"
  134.                 echo
  135.                 exit 1
  136.         fi
  137.  
  138.         if [ "$TMP_DIR" = "$BASE_TMP_DIR" -o "$TMP_DIR" = "/" ]; then
  139.                 echo
  140.                 echo "\"$TMP_DIR\" is an unacceptable value for the temp dir. Please"
  141.                 echo "edit the variable definition for $TMP_DIR and try again."
  142.                 echo
  143.                 echo "*** Aborting"
  144.                 echo
  145.                 exit 1
  146.         fi
  147.  
  148.         mkdir $TMP_DIR
  149.         chmod 700 $TMP_DIR &> /dev/null
  150.  
  151.         echo -en "\015"
  152.         echo -n $fname
  153.         message_status 1 "$TMP_DIR"
  154. }
  155.  
  156. function unpack_driver ()
  157. {
  158.         # Create tmp dir and unpack the driver
  159.         # Syntax: unpack_driver
  160.         # Author: mlindner
  161.         # Returns:
  162.         #       N/A
  163.  
  164.  
  165.         # Create tmp dir and unpack the driver
  166.         fname="Unpack the sources"
  167.         echo -n $fname
  168.         message_status 3 "working"
  169.  
  170.         # Archive file not found
  171.         if [ ! -f $drv_name.tar.bz2 ]; then
  172.                 echo -en "\015"
  173.                 echo -n $fname
  174.                 message_status 0 "error"
  175.                 echo
  176.                 echo "Driver package $drv_name.tar.bz2 not found. "; \
  177.                 echo "Please download the package again."; \
  178.                 echo "+++ Unpack error!!!" >> $logfile 2>&1
  179.                 echo $inst_failed
  180.                 clean
  181.                 exit 1
  182.        
  183.         fi
  184.  
  185.         echo "+++ Unpack the sources" >> $logfile
  186.         echo "+++ ====================================" >> $logfile
  187.         cd $working_dir
  188.         cp $drv_name.tar.bz2 ${TMP_DIR}/
  189.  
  190.         cd ${TMP_DIR}
  191.         bunzip2 $drv_name.tar.bz2 &> /dev/null
  192.         echo "+++ tar xfv $drv_name.tar" >> $logfile
  193.         tar xfv $drv_name.tar >> $logfile
  194.         cd ..
  195.  
  196.         if [ -f ${TMP_DIR}/2.4/skge.c ]; then
  197.                 echo -en "\015"
  198.                 echo -n $fname
  199.                 message_status 1 "done"
  200.         else
  201.                 echo -en "\015"
  202.                 echo -n $fname
  203.                 message_status 0 "error"
  204.                 echo
  205.                 echo "An error has occurred during the unpack proces which prevented "; \
  206.                 echo "the installation from completing.                              "; \
  207.                 echo "Take a look at the log file install.log for more informations.  "; \
  208.                 echo "+++ Unpack error!!!" >> $logfile 2>&1
  209.                 echo $inst_failed
  210.                 clean
  211.                 exit 1
  212.         fi
  213.  
  214.         # Generate all build dir...
  215.         mkdir ${TMP_DIR}/all
  216.         cp -pr ${TMP_DIR}/common/* ${TMP_DIR}/all
  217.         cp -pr ${TMP_DIR}/${KERNEL_FAMILY}/* ${TMP_DIR}/all
  218. }
  219.  
  220. function extract_params ()
  221. {
  222.         # Extract all given parameters
  223.         # Syntax:  extract_params
  224.         # Author: mlindner
  225.         # Returns:
  226.         #       N/A
  227.  
  228.         if [ $# -eq "0" ];then
  229.                 # Script invoked with no command-line args?
  230.                 return
  231.         fi
  232.  
  233.         while getopts ":schp" Option
  234.                 do
  235.               case $Option in
  236.                         s     ) OPTION_SILENT=1;;
  237.                         c     ) OPTION_CLEANUP=1;;
  238.                         h     ) OPTION_HELP=1;;
  239.                         p     ) OPTION_PATCH=1;;
  240.                         *     ) echo "Option $OPTARG ignored";;   # DEFAULT
  241.                 esac
  242.         done
  243.  
  244.         if [ "${OPTION_PATCH}" ]; then
  245.                 if [ ! $2 ] || [ ! $3 ]; then
  246.                         echo "install: option requires an argument -- p"
  247.                         echo "Try "install.sh -h" for more information."
  248.                         echo
  249.                         exit
  250.                 fi
  251.         fi
  252.  
  253. }
  254.  
  255.  
  256. function help ()
  257. {
  258.         echo "Usage: install.sh [OPTIONS]"
  259.         echo "   Install the sk98lin driver or generate a patch"
  260.         echo "   Example: install.sh"
  261.         echo
  262.         echo "Optional parameters:"
  263.         echo "   -s              install the driver wothout any user interaction"
  264.         echo "   -c              cleanup all sk98lin temp directories"
  265.         echo "   -p [KERNEL_DIR] [PATCH_FILE]         generate a patch"
  266.         echo "   -h              display this help and exit"
  267.         echo "   -v              output version information and exit"
  268.         echo
  269.         echo "Report bugs to <[email protected]>."
  270.         exit
  271. }
  272.  
  273. #################################################################
  274. # Check functions
  275. #################################################################
  276. function check_user_and_tools ()
  277. {
  278.         # Check user informations and the existence of defferent tools
  279.         # Syntax:  check_user_and_tools
  280.         # Author: mlindner
  281.         # Returns:
  282.         #       N/A
  283.  
  284.         # Check user id
  285.         inst_failed="Installation of $drv_name driver module failed."
  286.         fname="Check user id"
  287.         echo -n $fname
  288.         if [ `id -u` != 0 ] && [ "$INSTALL_MODE" != "PATCH" ]; then
  289.                 message_status 0 `id -u`
  290.                 echo "+++ Wrong user"  >> $logfile 2>&1
  291.                 echo "You must have root privileges to install the $drv_name driver module."
  292.                 inst_failed
  293.                 clean
  294.                 exit 1
  295.         else
  296.                 message_status 1 `id -u`
  297.         fi
  298.  
  299.  
  300.         # Check kernel version
  301.         export KERNEL_VERSION=`uname -r`
  302.         echo -n "Check kernel version"
  303.         echo "+++ Kernel version ${KERNEL_VERSION}" >> $logfile 2>&1
  304.        
  305.         split_kernel_ver=`echo ${KERNEL_VERSION} | cut -d '.' -f 1`     
  306.         if [ $split_kernel_ver != 2 ]; then
  307.                 message_status 0 ${KERNEL_VERSION}
  308.                 kernel_check_failed
  309.         fi
  310.  
  311.         KERNEL_FAMILY="$split_kernel_ver"
  312.         split_kernel_ver=`echo ${KERNEL_VERSION} | cut -d '.' -f 2`     
  313.         if [ $split_kernel_ver != 4 ] && [ $split_kernel_ver != 6 ]; then
  314.                 message_status 0 ${KERNEL_VERSION}
  315.                 kernel_check_failed
  316.         fi
  317.         KERNEL_FAMILY="$KERNEL_FAMILY.$split_kernel_ver"
  318.  
  319.         split_kernel_ver=`echo ${KERNEL_VERSION} | cut -d '.' -f 3`
  320.         split_kernel_ver2=`echo $split_kernel_ver | cut -d '-' -f 1`
  321.         KERNEL_MINOR_VERSION=`echo $split_kernel_ver2`
  322.         KERNEL_MAJOR_VERSION=`echo ${KERNEL_VERSION} | cut -d '.' -f 2`
  323.         if [ "$split_kernel_ver2" -lt  13 ] && [ $KERNEL_MAJOR_VERSION == 4 ]; then
  324.                 message_status 0 ${KERNEL_VERSION}
  325.                 kernel_check_failed
  326.         fi
  327.         message_status 1 ${KERNEL_VERSION}
  328.  
  329.         echo -n "Check kernel symbol file"
  330.         if [ -f "/proc/ksyms" ]; then
  331.                 SYMSFILE="/proc/ksyms"
  332.         fi
  333.         if [ -f "/proc/kallsyms" ]; then
  334.                 SYMSFILE="/proc/kallsyms"
  335.         fi
  336.  
  337.         if [ ! $SYMSFILE ]; then
  338.                 if [ -f "/boot/System.map-${KERNEL_VERSION}" ]; then
  339.                         SYMSFILE="/boot/System.map-${KERNEL_VERSION}"
  340.                 fi
  341.         fi
  342.         message_status 1 $SYMSFILE
  343.  
  344.  
  345.  
  346.         # Check machine type
  347.         fname="Check kernel type"
  348.         echo -n $fname
  349.         message_status 3 "working"
  350.         kernel_machine=`uname -m`
  351.         SYSTEM_NUMBER_OF_CPUS=1;
  352.         MAKE_CPU_FLAG=""
  353.         local no_smp_cpus=0
  354.  
  355.         # New smp detection (preliminary!)
  356.         smp_count=`cat /proc/cpuinfo | grep processor -c`
  357.  
  358.         if [ $smp_count -lt 2 ]; then
  359.         # check for smp (step2)
  360.                 smp_count=`cat $SYMSFILE | grep smp_call_function$ -c`
  361.                 ((smp_count=$smp_count + 1))
  362.                 no_smp_cpus=1
  363.         fi
  364.  
  365.         if [ $smp_count -lt 2 ]; then
  366.         # check for smp (step3)
  367.                 smp_count=`cat $SYMSFILE | grep smp_call_function_R -c`
  368.                 ((smp_count=$smp_count + 1))
  369.                 no_smp_cpus=1
  370.         fi
  371.  
  372.         if [ $smp_count -lt 2 ]; then
  373.         # check for smp (step4)
  374.                 smp_count=`cat $SYMSFILE | grep smp_prepare_cpus$ -c`
  375.                 ((smp_count=$smp_count + 1))
  376.                 no_smp_cpus=1
  377.         fi
  378.        
  379.         if [ $smp_count -gt 1 ]; then
  380.                 echo -en "\015"
  381.                 echo -n $fname
  382.                 message_status 1 "SMP"
  383.  
  384.                 echo -n "Check number of CPUs"
  385.                 if [ $no_smp_cpus == 1 ]; then
  386.                         SYSTEM_NUMBER_OF_CPUS=1
  387.                         smp_count=1
  388.                 else
  389.                         SYSTEM_NUMBER_OF_CPUS=$smp_count
  390.                         MAKE_CPU_FLAG="-j$SYSTEM_NUMBER_OF_CPUS"
  391.                         smp_count=1
  392.                 fi
  393.                 message_status 1 $SYSTEM_NUMBER_OF_CPUS
  394.         else
  395.                 smp_count=0
  396.                 echo -en "\015"
  397.                 echo -n $fname
  398.                 message_status 1 "SP"
  399.         fi
  400.  
  401.         echo "+++ smp_count=$smp_count" >> $logfile 2>&1
  402.         echo "+++ cpu_number=$SYSTEM_NUMBER_OF_CPUS" >> $logfile 2>&1
  403.         echo "+++ kernel_machine=$kernel_machine" >> $logfile 2>&1
  404.  
  405.         # Check architecture
  406.         echo -n "Check architecture"
  407.  
  408.         # Use the arch command at the first
  409.         arch_out=`arch`
  410.  
  411.         if [ "$arch_out" != "ia64" ] && [ "$arch_out" != "x86_64" ]; then
  412.                 # Probably the x86 archtecture...
  413.                 # We have to check some infos for prototype CPU detection
  414.  
  415.                 architecture=`cat /proc/cpuinfo | grep "model name" | cut -d ':' -f 2`
  416.  
  417.                 if [ "$architecture" == "" ]; then
  418.                 # Architecture not found... 2nd chance
  419.                         architecture=`cat /proc/cpuinfo | grep "family" | cut -d ':' -f 2`
  420.                         if [ "$architecture" == "" ] && ["$arch_out" == "" ]; then
  421.                         # Architecture still not found... :(
  422.                                 echo "+++ Architecture not found" >> $logfile 2>&1     
  423.                                 if [ -z ${SK_ARCH} ]; then
  424.                                 message_status 0 "not found"
  425.                                 echo "Architecture not detected."
  426.                                 echo "Please set the architecture manually."
  427.                                 echo "If you know what you are doing and want to set the"
  428.                                 echo "architecture, you can do so by setting SK_ARCH system  "
  429.                                 echo "variable:"
  430.                                 echo ""
  431.                                 echo "  For i386 architecture"
  432.                                 echo "    Example: export SK_ARCH=\"i386\""
  433.                                 echo "  For ia64 or ia64-2 architecture"
  434.                                 echo "    Example: export SK_ARCH=\"ia64\""
  435.                                 echo "  For Athlon64, Hammer or Opteron architecture"
  436.                                 echo "    Example: export SK_ARCH=\"x86_64\""
  437.                                 echo $inst_failed
  438.                                 clean
  439.                                 exit 1
  440.                                 else
  441.                                 echo "+++ Architecture setted manually: ${SK_ARCH}" >> $logfile 2>&1   
  442.                                 message_status 1 "m:${SK_ARCH}"
  443.                                 fi
  444.                         else
  445.                                 message_status 1 "found"
  446.                         fi
  447.                 else
  448.                         message_status 1 "found"
  449.                 fi
  450.         else
  451.                 architecture=`echo $arch_out`
  452.                 message_status 1 "found"
  453.         fi
  454.  
  455.         # Create the final arch type
  456.         if [ "$architecture" != "ia64" ] && [ "$archtecture" != "x86_64" ]; then
  457.                 architecture=`echo $arch_out`
  458.         fi
  459.  
  460.         echo -n "Set architecture"
  461.         # AMD64, Opteron, Hammer...
  462.         if [ `echo $architecture | grep -i "Opteron" -c` -gt 0 ]; then ARCH=x86_64; fi
  463.         if [ `echo $architecture | grep -i "Athlon HX" -c` -gt 0 ]; then ARCH=x86_64; fi
  464.         if [ `echo $architecture | grep -i "Hammer" -c` -gt 0 ]; then ARCH=x86_64; fi
  465.         if [ `echo $architecture | grep -i "K8" -c` -gt 0 ]; then ARCH=x86_64; fi
  466.         if [ `echo $architecture | grep -i " 15" -c` -gt 0 ]; then ARCH=x86_64; fi
  467.         if [ `echo $architecture | grep -i "AMD Athlon(tm) 64" -c` -gt 0 ]; then ARCH=x86_64; fi
  468.         if [ `echo $architecture | grep -i "x86_64" -c` -gt 0 ]; then ARCH=x86_64; fi
  469.  
  470.         # IA-64, IA-64 2...
  471.         if [ `echo $architecture | grep -i "ia-64" -c` -gt 0 ]; then ARCH=ia64; fi
  472.         if [ `echo $architecture | grep -i "ia64" -c` -gt 0 ]; then ARCH=ia64; fi
  473.                 if [ `echo $architecture | grep -i "itanium" -c` -gt 0 ]; then ARCH=ia64; fi
  474.  
  475.         if [ -z ${SK_ARCH} ]; then
  476.                 if [ "$ARCH" == "" ]; then
  477.                         ARCH=`echo i386`
  478.                 fi
  479.         else
  480.                 ARCH=`echo ${SK_ARCH}`
  481.         fi
  482.         echo "+++ Architecture: $ARCH" >> $logfile 2>&1
  483.         message_status 1 "$ARCH"
  484.  
  485.  
  486.         # Check gcc
  487.         echo -n "Check compiler"
  488.         if [ `which gcc` ]; then
  489.                 message_status 1 `which gcc`
  490.         else
  491.                 message_status 0 "not found"
  492.                 echo "+++ Compiler not found" >> $logfile 2>&1 
  493.                 inst_failed "You have to install the gcc compiler."
  494.         fi
  495.  
  496.  
  497.         # Check mcmodel flags
  498.         echo -n "Check mcmodel flags"
  499.         echo "int main(void) { int i; return; }" >> $TMP_DIR/test.c
  500.         `gcc -mcmodel=kernel $TMP_DIR/test.c -o $TMP_DIR/out.o &> /dev/null`
  501.         if [ $? -gt 0 ]; then
  502.                 message_status 1 "32bit"
  503.         else
  504.                 if [ "$ARCH" == "x86_64" ]; then
  505.                         export MCMODEL="-mcmodel=kernel"
  506.                 fi
  507.                 if [ "$ARCH" == "ia64" ]; then
  508.                         export MCMODEL="-mcmodel=kernel"
  509.                 fi
  510.                 if [ "$MCMODEL" == "" ]; then
  511.                         message_status 1 "32bit"
  512.                 else
  513.                         message_status 1 "64bit"
  514.                 fi
  515.         fi
  516.  
  517.         # Check module support
  518.         echo -n "Check module support"
  519.         if [ `which insmod` ]; then
  520.                 insmod_bin=`which insmod`
  521.                 message_status 1 $insmod_bin
  522.         else
  523.                 if [ -e /sbin/insmod ]; then
  524.                         insmod_bin="/sbin/insmod"
  525.                         message_status 1 $insmod_bin
  526.                 else
  527.                         if [ -e /usr/sbin/insmod ]; then
  528.                                 insmod_bin=`echo "/usr/sbin/insmod"`
  529.                                 message_status 1 $insmod_bin
  530.                         else
  531.                                 message_status 0 "not found"
  532.                                 echo "+++ Insmod not found" >> $logfile 2>&1   
  533.                                 inst_failed "You have to install the modutils package."
  534.                         fi
  535.                 fi
  536.         fi
  537.  
  538.  
  539.         # Check make
  540.         echo -n "Check make"
  541.         if [ `which make` ]; then
  542.                 message_status 1 `which make`
  543.         else
  544.                 message_status 0 "not found"
  545.                 echo "+++ Make not found" >> $logfile 2>&1     
  546.                 inst_failed "You have to install the make package."
  547.         fi
  548.  
  549.  
  550.         # Check archive file
  551.         echo -n "Check archive file"
  552.         if [ -e $drv_name.tar.bz2 ]; then
  553.                 message_status 1 "$drv_name"
  554.         else
  555.                 message_status 0 "not found"
  556.                echo "You have to copy the $drv_name.tar.bz2 file into the current"
  557.                 echo "$working_dir directory"
  558.                 echo "+++ $drv_name.tar.bz package not found" >> $logfile 2>&1 
  559.                 echo $inst_failed
  560.                 cleanup
  561.                 clean
  562.                 exit
  563.         fi
  564. }
  565.  
  566. function check_config ()
  567. {
  568.         # Check and change the config file
  569.         # Syntax: check_config
  570.         # Author: mlindner
  571.         # Returns:
  572.         #       N/A
  573.  
  574.         # Backup old .config file
  575.         fname="Copy and check .config file"
  576.         echo -n $fname
  577.         message_status 3 "working"
  578.  
  579.         # Check config
  580.         cp ${KERNEL_SOURCE}/.config ${TMP_DIR}/config
  581.         cp ${KERNEL_SOURCE}/.config ${TMP_DIR}/config-backup
  582.         rm -rf ${TMP_DIR}/newconfig &> /dev/null
  583.         if [ $smp_count == 1 ]; then
  584.                 if [ `grep CONFIG_NR_CPUS ${TMP_DIR}/config -c` -gt "0" ]; then
  585.                         sed -e 's/# CONFIG_NR_CPUS/CONFIG_NR_CPUS=8/' \
  586.                                 ${TMP_DIR}/config \
  587.                                 >> ${TMP_DIR}/newconfig
  588.                         cp ${TMP_DIR}/newconfig ${TMP_DIR}/config
  589.                 else
  590.                         sed -e 's/# CONFIG_SMP is not set/CONFIG_SMP=y/' \
  591.                                 ${TMP_DIR}/config \
  592.                                 >> ${TMP_DIR}/newconfig
  593.                 fi
  594.         else
  595.                 sed -e 's/CONFIG_SMP=y/# CONFIG_SMP is not set/' \
  596.                         ${TMP_DIR}/config >> ${TMP_DIR}/newconfig
  597.         fi
  598.  
  599.         # Set the mem address space
  600.         if [ $HIGHMEM == 1 ]; then
  601.         # Highmem enabled... Turn highmen on.
  602.                 sed -e 's/# CONFIG_HIGHMEM4G is not set/CONFIG_HIGHMEM4G=y/' \
  603.                         ${TMP_DIR}/newconfig &> ${TMP_DIR}/newconfig2
  604.                 sed -e 's/CONFIG_HIGHMEM64G=y/# CONFIG_HIGHMEM64G is not set/' \
  605.                         ${TMP_DIR}/newconfig2 &> ${TMP_DIR}/newconfig
  606.                 sed -e 's/CONFIG_NOHIGHMEM=y/# CONFIG_NOHIGHMEM is not set/' \
  607.                         ${TMP_DIR}/newconfig &> ${TMP_DIR}/newconfig2
  608.                 sed -e 's/# CONFIG_HIGHMEM is not set/CONFIG_HIGHMEM=y/' \
  609.                         ${TMP_DIR}/newconfig2 &> ${TMP_DIR}/newconfig
  610.         else
  611.         # Set highmem back
  612.                 sed -e 's/CONFIG_HIGHMEM4G=y/# CONFIG_HIGHMEM4G is not set/' \
  613.                         ${TMP_DIR}/newconfig &> ${TMP_DIR}/newconfig2
  614.                 sed -e 's/CONFIG_HIGHMEM64G=y/# CONFIG_HIGHMEM64G is not set/' \
  615.                         ${TMP_DIR}/newconfig2 &> ${TMP_DIR}/newconfig
  616.                 sed -e 's/# CONFIG_NOHIGHMEM is not set/CONFIG_NOHIGHMEM=y/' \
  617.                         ${TMP_DIR}/newconfig &> ${TMP_DIR}/newconfig2
  618.                 sed -e 's/CONFIG_HIGHMEM=y/# CONFIG_HIGHMEM is not set/' \
  619.                         ${TMP_DIR}/newconfig2 &> ${TMP_DIR}/newconfig
  620.         fi
  621.                
  622.         # Set version management back
  623.         sed -e 's/CONFIG_MODVERSIONS=y/# CONFIG_MODVERSIONS is not set/' \
  624.                 ${TMP_DIR}/newconfig &> ${TMP_DIR}/newconfig2
  625.  
  626.         mv ${TMP_DIR}/newconfig2 ${TMP_DIR}/newconfig
  627.  
  628.         cp ${TMP_DIR}/newconfig ${KERNEL_SOURCE}/.config
  629.  
  630.         echo -en "\015"
  631.         echo -n $fname
  632.         message_status 1 "done"
  633. }
  634.  
  635.  
  636. function check_kernel_informations ()
  637. {
  638.         # Check kernel and module informations
  639.         # Syntax:  check_kernel_informations
  640.         # Author: mlindner
  641.         # Returns:
  642.         #       N/A
  643.  
  644.  
  645.         # Check gcc and kernel version
  646.         GCCNAME=`echo gcc`
  647.         gcc_version=`gcc -v 2>&1 | tail -1`
  648.         gcc_version=`echo $gcc_version | cut -d ' ' -f 3`
  649.         kernel_gcc_version=`cat /proc/version | sed -e "s/^.*gcc version//g"`
  650.         kernel_gcc_version=`echo $kernel_gcc_version | sed -e "s/)//g"`
  651.         kernel_gcc_version=`echo $kernel_gcc_version | cut -d ' ' -f 1`
  652.         echo -n "Check kernel gcc version (${kernel_gcc_version})"
  653.  
  654.         if [ $kernel_gcc_version != $gcc_version ]; then
  655.                 othergccfound=`echo 0`
  656.                 PathOfGcc=`which $GCCNAME | sed -e 's/\/gcc//'`
  657.                 AllGccInDir=`ls -1 $PathOfGcc | grep ^$GCCNAME`
  658.  
  659.                 for currGcc in $AllGccInDir
  660.                 do
  661.                         if [ $othergccfound -lt 1 ]; then
  662.                                 version=`$PathOfGcc/$currGcc -v 2>&1 | tail -1 | awk '{print $3}'`
  663.                                 # echo "+++ Version of $currGcc is $version +++"
  664.                                 if [ $kernel_gcc_version == $version ]; then
  665.                                         GCCNAME=`echo $currGcc`
  666.                                         othergccfound=`echo 1`
  667.                                 fi
  668.                         fi
  669.                 done
  670.  
  671.                 if [ $othergccfound -lt 1 ]; then
  672.                         message_status 0 "Kernel:$kernel_gcc_version != gcc:$gcc_version"
  673.                         echo "+++ Mismatch!!! Kernel:$kernel_gcc_version != gcc:$gcc_version" >> $logfile 2>&1
  674.                         if [ -z ${IGNORE_CC_MISMATCH} ]; then \
  675.  
  676.                         echo "There is a version mismatch between the compiler that was used"
  677.                         echo "to build the current running kernel and the compiler which you"
  678.                         echo "intend to compile the kernel module with. In most of the cases,"
  679.                         echo "this is no problem, but there are cases in which this compiler-"
  680.                         echo "mismatch leads to unexpected system crashes"
  681.                         echo " "
  682.                         echo "If you know what you are doing and want to override this   "; \
  683.                         echo "check, you can do so by setting IGNORE_CC_MISMATCH system  "; \
  684.                         echo "variable:                                                  "; \
  685.                         echo "    Example: export IGNORE_CC_MISMATCH="1"                 "; \
  686.                         echo $inst_failed
  687.                         cleanup
  688.                         clean
  689.                         exit 1
  690.                         fi
  691.                 else
  692.                         message_status 1 "use $GCCNAME"
  693.                 fi           
  694.         else
  695.                 message_status 1 "Kernel:$kernel_gcc_version == gcc:$gcc_version"
  696.         fi
  697.        
  698.         # Check the driver availability
  699.         echo -n "Check $drv_name driver availability"
  700.         check_sk98lin=`lsmod | grep $drv_name -c`
  701.         if [ $check_sk98lin != 1 ]; then
  702.                 message_status 1 "not loaded"
  703.         else
  704.                 if [ -z ${IGNORE_SKAVAIL_CHECK} ]; then
  705.                         if [ "$user_sel" == "user installation" ]
  706.                         then
  707.                                 message_status 1 "loaded"
  708.                         else
  709.                                 echo "+++ Driver loaded. OK" >> $logfile 2>&1
  710.                                 message_status 0 "loaded"
  711.                         fi
  712.  
  713.                         if [ -z ${REMOVE_SKDEVICE} ] && [ "$user_sel" != "user installation" ]; then
  714.                         echo
  715.                         echo "Driver $drv_name loaded. Please remove the driver with rmmod."
  716.                         echo "If you want override this check, you can do so by setting   "
  717.                         echo "IGNORE_SKAVAIL_CHECK:";
  718.                         echo "    Example: export IGNORE_SKAVAIL_CHECK="1"             "
  719.                         echo
  720.                         echo "If you want to remove the devices and the driver automatically,"
  721.                         echo "you can do so by setting REMOVE_SKDEVICE:"
  722.                         echo "    Example: export REMOVE_SKDEVICE="1"             "
  723.                         echo
  724.                         echo "+++ Driver loaded. ERROR!" >> $logfile 2>&1
  725.                         echo $inst_failed
  726.                         cleanup
  727.                         clean
  728.                         exit 1
  729.                         else
  730.                                 echo -n "Disconnect devices: "
  731.                                 for devices in `ls /proc/net/sk98lin`; do
  732.                                         echo -n "$devices "
  733.                                         ifconfig $devices down &> /dev/null
  734.                                 done
  735.                                 message_status 1 "done"
  736.                                 echo -n "Remove driver"
  737.                                 rmmod $drv_name &> /dev/null
  738.                                 message_status 1 "done"
  739.                         fi
  740.                 else
  741.                         message_status 2 "loaded"
  742.                 fi
  743.         fi
  744.  
  745.  
  746.         # Check header files
  747.         echo -n "Check kernel header files"
  748.         if [ -d /usr/src/linux/include/linux/ ]; then
  749.                 message_status 1 "/usr/src/linux"
  750.                 export KERNEL_HEADER="/usr/src/linux/include";
  751.                 export KERNEL_SOURCE="/usr/src/linux";
  752.         else
  753.                 if [ -d /usr/src/linux-${KERNEL_VERSION}/include/linux/ ]; then
  754.                         message_status 1 "/usr/src/linux-${KERNEL_VERSION}"
  755.                         export KERNEL_HEADER="/usr/src/linux-${KERNEL_VERSION}/include";
  756.                         export KERNEL_SOURCE="/usr/src/linux-${KERNEL_VERSION}";
  757.                 else
  758.                         kernel_check_dir="linux-$KERNEL_FAMILY"
  759.                         if [ -d /usr/src/$kernel_check_dir/include/linux/ ]; then
  760.                                 message_status 1 "/usr/src/$kernel_check_dir"
  761.                                 export KERNEL_HEADER="/usr/src/$kernel_check_dir/include";
  762.                                 export KERNEL_SOURCE="/usr/src/$kernel_check_dir";
  763.                         else           
  764.                         message_status 0 "not found"
  765.                         echo "Kernel header not found. Please install the linux header files "
  766.                         echo "development package or crate a symbolic link from the "
  767.                         echo "/usr/src/KERNEL_VERSION directory to linux"
  768.                         echo "     Example: ln -s /usr/src/KERNEL_VERSION /usr/src/linux"
  769.                         echo ""
  770.                         echo "+++ Kernel header not found. ln -s /usr/src/KERNEL_VERSION?" >> $logfile 2>&1
  771.                         echo $inst_failed
  772.                         cleanup
  773.                         clean
  774.                         exit 1
  775.                         fi
  776.              fi
  777.         fi
  778.  
  779.         # Check highmem
  780.         echo -n "Check the mem address space"
  781.         if [ `cat $SYMSFILE | grep "kmap_high" -c` -gt 0 ]; then
  782.                 message_status 1 "highmem"
  783.                 HIGHMEM=1
  784.         else
  785.                 message_status 1 "lowmem"
  786.                 HIGHMEM=0
  787.         fi
  788.  
  789. }
  790.  
  791. function check_kernel_functions ()
  792. {
  793.         # Check some kernel functions and insert a function if
  794.         # available in the kernel
  795.         # Syntax: check_kernel_functions
  796.         # Author: mlindner
  797.         # Returns:
  798.         #       N/A
  799.  
  800.         fname="Check kernel functions"
  801.         echo -n $fname
  802.         message_status 3 "working"
  803.  
  804.         if [ "$KERNEL_MAJOR_VERSION" ==  4 ]; then
  805.                 if [ "$KERNEL_MINOR_VERSION" -lt  20 ]; then
  806.                 # Prepare driver for a new skb_padto function
  807.                 # Pads up a buffer to ensure the trailing bytes exist and are
  808.                 # blanked. If the buffer already contains sufficient data it
  809.                 # is untouched. Returns the buffer, which may be a replacement
  810.                 # for the original, or NULL for out of memory - in which case
  811.                 # the original buffer is still freed.
  812.                 #
  813.                 # A similar function is already in the kernel (skb_padto()) but we
  814.                 # need a new one. The driver is still used by older kernels without
  815.                 # the new kernel function.
  816.  
  817.                 sed -e 's/static void   FreeResources(struct SK_NET_DEVICE \*dev);/\
  818. static struct sk_buff *skb_padto(struct sk_buff *skb,unsigned int len)\
  819. {\
  820. \#ifndef likely\
  821. \#define __builtin_expect(x, expected_value) (x)\
  822. \#define likely(x) __builtin_expect((x),1)\
  823. \#endif\
  824. struct sk_buff *nskb;\
  825. unsigned int size = skb->len + skb->data_len;\
  826. if(likely(size >= len)) return skb;\
  827. if(skb_tailroom(skb) >= len-size) { memset(skb->data+skb->len, 0, len-size);return skb;}\
  828. nskb = skb_copy_expand(skb,skb_headroom(skb),skb_tailroom(skb) + len-size,GFP_ATOMIC);\
  829. kfree_skb(skb);\
  830. if(nskb) memset(nskb->data+nskb->len, 0, len-size);\
  831. return skb;\
  832. }\
  833. \
  834. static void     FreeResources(struct SK_NET_DEVICE \*dev);/' \
  835.                         ${TMP_DIR}/all/skge.c &> ${TMP_DIR}/all/skge.c2
  836.  
  837.                         mv ${TMP_DIR}/all/skge.c2 ${TMP_DIR}/all/skge.c
  838.                       changes=`echo $changes skb_padto`;
  839.                 fi
  840.         fi
  841.  
  842.         # Change sky2.c on fedora core 2
  843.         if [ -e "/etc/fedora-release" ]; then
  844.                 if [ `grep -wc "Fedora Core release 2" /etc/fedora-release` -gt 0 ]; then
  845.                         # fedora core 2
  846.                         sed -e 's/      dma_addr_t     pPhysMemAddr;/ dma64_addr_t     pPhysMemAddr;/' ${TMP_DIR}/all/sky2.c &> ${TMP_DIR}/all/sky2.c2
  847.                         mv ${TMP_DIR}/all/sky2.c2 ${TMP_DIR}/all/sky2.c
  848.                       changes=`echo $changes dma64_addr_t`;
  849.                 fi
  850.         fi
  851.  
  852.  
  853.         if [ "$changes" == "" ]; then
  854.                 changes="nothing"
  855.         fi
  856.  
  857.         echo -en "\015"
  858.         echo -n $fname
  859.         message_status 1 "Changed: $changes"
  860. }
  861.  
  862. #################################################################
  863. # Kernel 2.4 make functions
  864. #################################################################
  865. function create_makefile_24 ()
  866. {
  867.         # Create makefile (kernel 2.4 version)
  868.         # Syntax: create_makefile_24
  869.         # Author: mlindner
  870.         # Returns:
  871.         #       N/A
  872.  
  873.         if [ $1 == "1" ]; then
  874.         {
  875.         echo '# Makefile for Marvell Yukon/SysKonnect SK-98xx/SK-95xx Gigabit'
  876.         echo '# Ethernet Adapter driver'
  877.         echo ''
  878.         echo '# just to get the CONFIG_SMP and CONFIG_MODVERSIONS defines:'
  879.         echo 'ifeq ($(KERNEL_SOURCE)/.config, $(wildcard $(KERNEL_SOURCE)/.config))'
  880.         echo 'include $(KERNEL_SOURCE)/.config'
  881.         echo 'endif'
  882.         echo 'SYSINC =  -I$(KERNEL_HEADER) -I.'
  883.         echo 'SYSDEF = -DLINUX -D__KERNEL__'
  884.         echo 'ifdef CONFIG_SMP'
  885.         echo 'SYSDEF += -D__SMP__'
  886.         echo 'endif'
  887.         echo 'SRCDEF = -DMODULE -O2 -DGENESIS -DSK_DIAG_SUPPORT -DSK_USE_CSUM \'
  888.         echo '         -DYUKON -DYUK2 -DCONFIG_SK98LIN_ZEROCOPY'
  889.         echo 'ifdef CONFIG_MODVERSIONS'
  890.         echo 'SRCDEF += -DMODVERSIONS -include $(KERNEL_HEADER)/linux/modversions.h'
  891.         echo 'SRCDEF += -include $(KERNEL_HEADER)/config/modversions.h '
  892.         echo 'endif'
  893.         echo 'USERDEF='
  894.         echo 'WARNDEF=-Wall -Wimplicit -Wreturn-type -Wswitch -Wformat -Wchar-subscripts \'
  895.         echo '     -Wparentheses -Wpointer-arith -Wcast-qual -Wno-multichar  \'
  896.         echo '     -Wno-cast-qual $(MCMODEL)'
  897.         echo 'INCLUDE= $(SYSINC)'
  898.         echo 'DEFINES=  $(SYSDEF) $(SRCDEF) $(USERDEF) $(WARNDEF)'
  899.         echo 'SRCFILES = skge.c kgeinit.c skgesirq.c skxmac2.c skvpd.c skgehwt.c \'
  900.         echo '     skqueue.c sktimer.c sktwsi.c sklm80.c skrlmt.c skgepnmi.c \'
  901.         echo '     skaddr.c skcsum.c skproc.c skdim.c sky2.c skethtool.c sky2le.c'
  902.         echo 'OBJECTS =  skge.o skaddr.o skgehwt.o skgeinit.o skgepnmi.o skgesirq.o \'
  903.         echo '     sktwsi.o sklm80.o skqueue.o skrlmt.o sktimer.o skvpd.o skdim.o\'
  904.         echo '     skxmac2.o skcsum.o skproc.o sky2.o skethtool.o sky2le.o'
  905.         echo 'DRVBIN = sk98lin.o'
  906.         echo 'LD        = ld'
  907.         echo "CC        = $GCCNAME"
  908.         echo 'CFLAGS    = $(INCLUDE) $(DEFINES)'
  909.         echo 'FILES     = $(SRCFILES) makefile'
  910.         echo 'TARGETS   = $(DRVBIN)'
  911.         echo '.c.o:   $<'
  912.         echo '  $(CC) $(CFLAGS) -c $<'
  913.         echo 'all:  $(OBJECTS)'
  914.         echo '  $(LD) -r -o $(DRVBIN) $(OBJECTS)'
  915.         echo 'clean:'
  916.         echo '  rm *.o'
  917.         echo '*.o: \'
  918.         echo '  h/*.h'
  919.         } &> ${TMP_DIR}/all/Makefile
  920.         else
  921.         cp ${TMP_DIR}/2.4/Makefile ${TMP_DIR}/all/Makefile
  922.         fi
  923. }
  924.  
  925. function make_driver_24 ()
  926. {
  927.         # Configure, check and build the driver (kernel 2.4)
  928.         # Syntax: make_driver
  929.         # Author: mlindner
  930.         # Returns:
  931.         #       N/A
  932.  
  933.         # Compile the driver
  934.         echo >> $logfile 2>&1
  935.         echo "+++ Compile the driver" >> $logfile 2>&1
  936.         echo "+++ ====================================" >> $logfile 2>&1
  937.         cd ${TMP_DIR}/all
  938.  
  939.         fname="Compile the driver"
  940.         echo -n $fname
  941.         message_status 3 "working"
  942.         make $MAKE_CPU_FLAG >> $logfile 2>&1
  943.  
  944.  
  945.         if [ ! -f $drv_name.o ]; then
  946.                 echo -en "\015"
  947.                 echo -n $fname
  948.                 message_status 2 "failed"
  949.  
  950.                 make_dep
  951.                 fname="Compile the driver"
  952.                 echo -n $fname
  953.                 message_status 3 "working"
  954.                 make $MAKE_CPU_FLAG >> $logfile 2>&1
  955.         fi
  956.  
  957.  
  958.         if [ -f $drv_name.o ]; then
  959.                 cp $drv_name.o ../
  960.                 echo -en "\015"
  961.                 echo -n $fname
  962.                 message_status 1 "done"
  963.         else
  964.                 echo -en "\015"
  965.                 echo -n $fname
  966.                 message_status 0 "error"
  967.               echo
  968.                 echo "An error has occurred during the compile proces which prevented "; \
  969.                 echo "the installation from completing.                              "; \
  970.                 echo "Take a look at the log file install.log for more informations.  "; \
  971.                 echo "+++ Compiler error" >> $logfile 2>&1
  972.                 echo $inst_failed
  973.                 cleanup
  974.                 clean
  975.                 exit 1
  976.         fi
  977. }
  978.  
  979.  
  980. #################################################################
  981. # Kernel 2.6 make functions
  982. #################################################################
  983. function create_makefile_26 ()
  984. {
  985.         # Create makefile (kernel 2.6 version)
  986.         # Syntax: create_makefile_26
  987.         #       1 == change makefile for compilation
  988.         #       1 != don't change
  989.         # Author: mlindner
  990.         # Returns:
  991.         #       N/A
  992.  
  993.  
  994.         # we have to use the makefile and change the include dir
  995.         rm -rf ${TMP_DIR}/all/Makefile
  996.         if [ $1 == "1" ]; then
  997.                 rm -rf ${TMP_DIR}/all/Makefile
  998.                 local A="`echo | tr '\012' '\001' `"
  999.                 local AFirst="Idrivers/net/sk98lin"
  1000.                 local ALast="I${TMP_DIR}/all"
  1001.                 sed -e "s$A$AFirst$A$ALast$A" \
  1002.                         ${TMP_DIR}/2.6/Makefile \
  1003.                         >> ${TMP_DIR}/all/Makefile
  1004.         else
  1005.                 cp ${TMP_DIR}/2.6/Makefile ${TMP_DIR}/all/Makefile
  1006.         fi
  1007. }
  1008.  
  1009. function make_driver_26 ()
  1010. {
  1011.         # Configure, check and build the driver (kernel 2.4)
  1012.         # Syntax: make_driver
  1013.         # Author: mlindner
  1014.         # Returns:
  1015.         #       N/A
  1016.  
  1017.         # Compile the driver
  1018.         echo >> $logfile 2>&1
  1019.         echo "+++ Compile the driver" >> $logfile 2>&1
  1020.         echo "+++ ====================================" >> $logfile 2>&1
  1021.         cd ${TMP_DIR}/all
  1022.  
  1023.         fname="Compile the kernel"
  1024.         echo -n $fname
  1025.         message_status 3 "working"
  1026.         make $MAKE_CPU_FLAG -C ${KERNEL_SOURCE}  SUBDIRS=${TMP_DIR}/all modules >> $logfile 2>&1
  1027.  
  1028.         if [ -f $drv_name.ko ]; then
  1029.                 cp $drv_name.ko ../
  1030.                 echo -en "\015"
  1031.                 echo -n $fname
  1032.                 message_status 1 "done"
  1033.         else
  1034.                 echo -en "\015"
  1035.                 echo -n $fname
  1036.                 message_status 0 "error"
  1037.                echo
  1038.                 echo "An error has occurred during the compile proces which prevented "; \
  1039.                 echo "the installation from completing.                              "; \
  1040.                 echo "Take a look at the log file install.log for more informations.  "; \
  1041.                 echo "+++ Compiler error" >> $logfile 2>&1
  1042.                 echo $inst_failed
  1043.                 cleanup
  1044. #              clean
  1045.                 exit 1
  1046.         fi
  1047. }
  1048.  
  1049. #################################################################
  1050. # Messages functions
  1051. #################################################################
  1052. function header_check_failed ()
  1053. {
  1054.         # Print a error message and exit
  1055.         # Syntax: header_check_failed
  1056.         # Author: mlindner
  1057.         # Returns:
  1058.         #       N/A
  1059.  
  1060.         echo "There is a mismatch between the current running kernel and"
  1061.         echo "the header files the kernel module will be compiled with."
  1062.         echo " "
  1063.         echo "For instance, it might be, that you run kernel version"
  1064.         echo "2.4.20, but the header files the kernel module will be"
  1065.         echo "compiled with refer to kernel version 2.4.21"
  1066.         echo
  1067.         echo "Due to this mismatch, you will not be able to load the "
  1068.         echo "driver without the force option (insmod -f $drv_name) after"
  1069.         echo "its compilation finished."
  1070.         echo " "
  1071.         echo "This problem can be resolved by overwriting the current"
  1072.         echo "include/version.h (which corresponds to another kernel "
  1073.         echo "version), with the include/version.h of the kernel version"
  1074.         echo "currently running."
  1075.         echo " "
  1076.         echo "BEWARE: OVERWRITE THE FILE ONLY IF YOU HAVE REALLY THE "
  1077.         echo "CORRECT HEADER FILE CORRESPONDING TO THE CURRENT RUNNING"
  1078.         echo " "
  1079.         echo "If you don't have the same kernel version, please install  "; \
  1080.         echo "the sources or a new kernel. It's not possible to mix      "; \
  1081.         echo "different kernel versions!                                 "; \
  1082.         echo "                                                           "; \
  1083.         echo "If you know what you are doing and want to override this   "; \
  1084.         echo "check, you can do so by setting IGNORE_HEADER_MISMATCH     "; \
  1085.         echo "system variable:                                           "; \
  1086.         echo "    Example: export IGNORE_HEADER_MISMATCH="1"             "; \
  1087.         echo "                                                           "; \
  1088.         echo "or change the file ${KERNEL_HEADER}/linux/version.h,       "; \
  1089.         echo "remove the define UTS_RELEASE line and insert:             "; \
  1090.         echo "#define UTS_RELEASE \"${KERNEL_VERSION}\"                  "; \
  1091.         echo "                                                           "; \
  1092.         echo "    Your kernel version: ${KERNEL_VERSION}                 "; \
  1093.         echo "    Your header version: $header_version                   "; \
  1094.         echo $inst_failed
  1095.         echo "                                                           "; \
  1096.         cleanup
  1097.         clean
  1098.         exit
  1099. }
  1100.  
  1101. function kernel_check_failed ()
  1102. {
  1103.         # Print kernel error informations
  1104.         # Syntax:  kernel_check_failed
  1105.         # Author: mlindner
  1106.         # Returns:
  1107.  
  1108.         echo "Kernel version unsupported."
  1109.         echo "This driver was developed for the kernel family 2.4.x"
  1110.         echo "higher then 2.4.13. If you are still using a old version"
  1111.         echo "of the kernel, please uptade to the newest version from"
  1112.         echo "ftp://ftp.kernel.org"
  1113.         echo "+++ Kernel version unsupported" >> $logfile 2>&1 
  1114.         echo $inst_failed
  1115.         echo
  1116.         cleanup
  1117.         clean
  1118.         exit
  1119. }
  1120.  
  1121.  
  1122. #################################################################
  1123. # Common kernel functions
  1124. #################################################################
  1125. function check_driver ()
  1126. {
  1127.         # Copy the news sources and check the driver
  1128.         # Syntax:  check_driver
  1129.         # Author: mlindner
  1130.         # Returns:
  1131.         #       N/A
  1132.  
  1133.         echo -n "Copy driver man page into /usr/share/man/man4/"
  1134.         rm -rf /usr/share/man/man4/sk98lin.4 &> /dev/null
  1135.         rm -rf /usr/share/man/man4/sk98lin.4.gz &> /dev/null
  1136.         cp -f sk98lin.4 /usr/share/man/man4/ &> /dev/null
  1137.         gzip /usr/share/man/man4/sk98lin.4 &> /dev/null
  1138.         message_status 1 "done"
  1139.  
  1140.         # Check the driver
  1141.         fname="Check the driver"
  1142.         echo -n $fname
  1143.         message_status 3 "working"
  1144.  
  1145.         echo "Check the driver" >> $logfile 2>&1
  1146.         echo "====================================" >> $logfile 2>&1
  1147.         sync
  1148.         sleep 1
  1149.         sync
  1150.         if [ ${KERNEL_FAMILY} == 2.4 ]; then
  1151.                 $insmod_bin ./$drv_name.o >> $logfile 2>&1
  1152.         else
  1153.                 $insmod_bin ./$drv_name.ko >> $logfile 2>&1
  1154.         fi
  1155.         insmod_count=`lsmod | grep $drv_name -c`
  1156.  
  1157.         if [ $insmod_count != 1 ]; then
  1158.                 echo -en "\015"
  1159.                 echo -n $fname
  1160.                 message_status 0 "error"       
  1161.                 echo "An error has occurred during the check proces which prevented  "; \
  1162.                 echo "the installation from completing.                              "; \
  1163.                 echo "It's not possible to build a standalone $drv_name driver on this "; \
  1164.                 echo "host. The kernel don't export a neccesary symbols for the      "; \
  1165.                 echo "device driver and we aren't able to load the driver.           "; \
  1166.                 echo
  1167.                 echo "Please compile the kernel and the driver manually.             "; \
  1168.                 echo "The new driver has been installed in the /usr/src/linux        "; \
  1169.                 echo "directory.                                                     "; \
  1170.                 echo
  1171.                 echo "   1.) Go to the directory /usr/src/linux                      "; \
  1172.                 echo "   2.) For the console mode, run the command: make menuconfig  "; \
  1173.                 echo "   3.) Select the options you want to compile into the kernel  "; \
  1174.                 echo "   4.) Select the menu \"Network Device Support\"              "; \
  1175.                 echo "   5.) Select \"Ethernet (1000 Mbit)\".                        "; \
  1176.                 echo "   5.) Mark \"Marvell Yukon/SysKonnect SK-98xx/SK-95xx Gigabit "; \
  1177.                 echo "       Ethernet Adapter support\" with (M)                     "; \
  1178.                 echo "   6.) Execute the command:                                    "; \
  1179.                 echo "           make dep clean bzImage modules modules_install      "; \
  1180.                 echo "   7.) Install the new kernel                                  "; \
  1181.  
  1182.                 echo "+++ Check error. Insmod error!" >> $logfile 2>&1
  1183.                 echo $inst_failed
  1184.                 return 1
  1185.         else
  1186.                 echo -en "\015"
  1187.                 echo -n $fname
  1188.                 message_status 1 "done"
  1189.         fi
  1190.  
  1191.  
  1192.         # Check driver directory
  1193.         if [ ! -e "/lib/modules/${KERNEL_VERSION}/kernel/drivers/net/$drv_name" ]; then
  1194.                 fname="Create kernel modules driver directory"
  1195.                 echo -n $fname
  1196.                 message_status 3 "working"
  1197.                 mkdir /lib/modules/${KERNEL_VERSION}/kernel/drivers/net/$drv_name
  1198.                 echo -en "\015"
  1199.                 echo -n $fname
  1200.                 message_status 1 "done"
  1201.         fi
  1202.  
  1203.         # Delete old driver
  1204.         fname="Delete old driver"
  1205.         echo -n $fname
  1206.         message_status 3 "working"
  1207.         rm -rf /lib/modules/${KERNEL_VERSION}/kernel/drivers/net/$drv_name/sk98lin.*
  1208.         echo -en "\015"
  1209.         echo -n $fname
  1210.         message_status 1 "done"
  1211.  
  1212.        
  1213.         # Copy the driver
  1214.         fname="Copying driver"
  1215.         echo -n $fname
  1216.         message_status 3 "working"
  1217.         if [ ${KERNEL_FAMILY} == 2.4 ]; then
  1218.                 cp $drv_name.o \
  1219.                 /lib/modules/${KERNEL_VERSION}/kernel/drivers/net/$drv_name/
  1220.         else
  1221.                 cp $drv_name.ko \
  1222.                 /lib/modules/${KERNEL_VERSION}/kernel/drivers/net/$drv_name/$drv_name.ko
  1223.         fi
  1224.         echo -en "\015"
  1225.         echo -n $fname
  1226.         message_status 1 "done"
  1227.  
  1228.         # Make dependency
  1229.         fname="Make dependency"
  1230.         echo -n $fname
  1231.         message_status 3 "working"
  1232.         depmod -a &> /dev/null
  1233.         echo -en "\015"
  1234.         echo -n $fname
  1235.         message_status 1 "done"
  1236.  
  1237. }
  1238.  
  1239.  
  1240. function copy_driver ()
  1241. {
  1242.         # Copy driver
  1243.         # Syntax: copy_driver
  1244.         # Author: mlindner
  1245.         # Returns:
  1246.         #       N/A
  1247.  
  1248.         # Copy sources and check the new driver (only if silent mode disabled)
  1249.         if [ ! "${OPTION_SILENT}" ]; then
  1250.                 check_driver
  1251.                 retvar=$?
  1252.                 cleanup
  1253.                 clean
  1254.  
  1255.                 if [ $retvar != 1 ]; then
  1256.                         echo "All done. Driver installed and loaded."
  1257.                         echo "To load the module manually, proceed as follows:"
  1258.                         echo "      Enter \"modprobe $drv_name\""
  1259.                         echo
  1260.                         echo "                                                     Have fun..."
  1261.                 fi
  1262.         else
  1263. #       if [ ${SK_RPM_BUILD_ROOT} ]; then
  1264. #              cp $drv_name.o ${SK_RPM_BUILD_ROOT}
  1265. #       fi
  1266.                 cp $drv_name.o $working_dir
  1267.                 cleanup
  1268.                 echo "All done. Driver compiled."
  1269.         fi
  1270. }
  1271.  
  1272.  
  1273. function read_and_change_version_file ()
  1274. {
  1275.         # Check version.h
  1276.         # Syntax: read_and_change_version_file FILE_AS_STRING
  1277.         # Author: mlindner
  1278.         # Returns:
  1279.         #       N/A
  1280.  
  1281.         dline_count=0
  1282.         rm -rf ${TMP_DIR}/newversion.h
  1283.         pure_kernel_version=`echo ${KERNEL_VERSION}`
  1284.         pure_kernel_version=`echo $pure_kernel_version | cut -d '-' -f 1`
  1285.  
  1286.         while read line  # For as many lines as the input file has...
  1287.         do
  1288.                 line_count=`echo $line | grep -c "UTS_RELEASE"`
  1289.                 if [ $line_count != 0 ]; then
  1290.                         if [ $dline_count == 0 ]; then
  1291.                                 version_count=`echo $line | grep -c "$pure_kernel_version"`
  1292.                                 if [ $version_count == 1 ]; then
  1293.                                 # Change line
  1294.                                         echo "#define UTS_RELEASE \"${KERNEL_VERSION}\"" \
  1295.                                                 >> ${TMP_DIR}/newversion.h
  1296.                                         dline_count=1
  1297.                                 fi
  1298.                         fi
  1299.                 else
  1300.                         echo "$line" >> ${TMP_DIR}/newversion.h
  1301.                 fi
  1302.         done
  1303.  
  1304.         if [ $dline_count == 0 ]; then
  1305.                 header_check_failed
  1306.         fi
  1307.  
  1308.         cp ${TMP_DIR}/newversion.h ${KERNEL_HEADER}/linux/version.h
  1309. }
  1310.  
  1311.  
  1312. function generate_sources_version ()
  1313. {
  1314.         # Check and generate a correct version.h file
  1315.         # Syntax: generate_sources_version
  1316.         # Author: mlindner
  1317.         # Returns:
  1318.         #       N/A
  1319.  
  1320.         # We have to "make prepare" if version sill not available
  1321.         if [ ! -f ${KERNEL_SOURCE}/include/linux/version.h ]; then
  1322.                 fname="Execute: make prepare"
  1323.                 echo -n $fname
  1324.                 message_status 3 "working"
  1325.                 cd ${KERNEL_SOURCE}
  1326.                 make prepare &> /dev/null
  1327.                 echo -en "\015"
  1328.                 echo -n $fname
  1329.                 message_status 1 "done"
  1330.         fi
  1331.  
  1332.         # Check header version
  1333.         echo -n "Check kernel header version"
  1334.         header_count=`grep -c RELEASE ${KERNEL_HEADER}/linux/version.h`
  1335.  
  1336.         if [ $header_count != 1 ]; then
  1337.                 message_status 2 "not recognized"
  1338.         else   
  1339.                 header_version=`grep RELEASE ${KERNEL_HEADER}/linux/version.h`
  1340.                 header_version=`echo $header_version | cut -d '"' -f 2`
  1341.                 if [ $header_version != ${KERNEL_VERSION} ]; then
  1342.                         if [ -z ${IGNORE_HEADER_MISMATCH} ]; then
  1343.                                 if [ "$user_sel" == "user installation" ]
  1344.                                 then
  1345.                                         message_status 1 "Kernel:${KERNEL_VERSION} != Header:$header_version"
  1346.                                         echo -n "Save old version.h"
  1347.                                         cp ${KERNEL_HEADER}/linux/version.h ./
  1348.                                         message_status 1 "saved"       
  1349.  
  1350.                                         echo -n "Check and create new version.h"
  1351.                                         tmp_version=`cat ${KERNEL_HEADER}/linux/version.h`
  1352.                                         read_and_change_version_file <<INPUTSTART
  1353. $tmp_version
  1354. INPUTSTART
  1355.  
  1356.                                         message_status 1 "created"
  1357.  
  1358.                                         # Make dependency
  1359. #                                   make_dep
  1360.  
  1361.                                 else
  1362.                                         message_status 0 "Kernel:${KERNEL_VERSION} != Header:$header_version"
  1363.                                         echo "+++ Kernel:${KERNEL_VERSION} != Header:$header_version" >> $logfile 2>&1
  1364.                                         header_check_failed
  1365.                                 fi
  1366.                         fi
  1367.                 else
  1368.                         message_status 1 "Kernel:${KERNEL_VERSION} == Header:$header_version"
  1369.                 fi
  1370.         fi
  1371. }
  1372.  
  1373.  
  1374. function generate_config ()
  1375. {
  1376.         # Check config file; Save old version and modify
  1377.         # Syntax: generate_config
  1378.         # Author: mlindner
  1379.         # Returns:
  1380.         #       N/A
  1381.  
  1382.         echo -n "Check sources for .config file"
  1383.         echo 'while true; do echo -en "\012";done' &> ${TMP_DIR}/enter
  1384.         chmod 755 ${TMP_DIR}/enter
  1385.  
  1386.         if [ -f ${KERNEL_SOURCE}/.config ]; then
  1387.         # Config file available
  1388.                 message_status 1 "${KERNEL_SOURCE}/.config"
  1389.  
  1390.                 if [ -f /proc/config.gz ]; then
  1391.                         copy_proc_fs_config
  1392.                 fi
  1393.  
  1394.                 if [ -f ${KERNEL_SOURCE}/drivers/net/$drv_name/$drv_name.o ]; then
  1395.                         # Driver already generated. Check config
  1396.                         rm -rf ${KERNEL_SOURCE}/drivers/net/sk98lin/*.o
  1397.                         # Modversions not available. We have to regenerate the dep
  1398.                         check_config
  1399.  
  1400.                         # Regenerate the config file
  1401.                         rebuild_config_file
  1402.  
  1403.                         if [ `diff ${TMP_DIR}/config-backup ${KERNEL_SOURCE}/.config | wc -l` -gt 0 ]; then
  1404.                         # Create dependency
  1405.                                 make_dep
  1406.                         fi
  1407.                        
  1408.                 else
  1409.                         if [ -f ${KERNEL_HEADER}/linux/version.h ] &&
  1410.                                 [ -f ${KERNEL_SOURCE}/include/linux/autoconf.h ]; then
  1411.                                 # Driver already generated. Check config
  1412.                                         # Modversions not available. We have to regenerate the dep
  1413.                                         check_config
  1414.  
  1415.                                         # Regenerate the config file
  1416.                                         rebuild_config_file
  1417.  
  1418.                                         if [ `diff ${TMP_DIR}/config-backup ${KERNEL_SOURCE}/.config | wc -l` -gt 0 ]; then
  1419.                                         # Create dependency
  1420.                                                 make_dep
  1421.                                         fi
  1422.                         else
  1423.                         if [ -f ${KERNEL_SOURCE}/drivers/net/$drv_name/.depend ] ||
  1424.                                 [ -f ${KERNEL_SOURCE}/drivers/net/$drv_name/.built-in.o.cmd ]; then
  1425.                                 if [ -f ${KERNEL_HEADER}/linux/modversions.h ] ||
  1426.                                         [ ${KERNEL_FAMILY} == 2.6 ]; then
  1427.                                 # Modversions available. nothing to do
  1428.                                         DONT_CLEANUP_TREE=1;
  1429.                                 else
  1430.                                         # Modversions not available. We have to regenerate the dep
  1431.                                         check_config
  1432.  
  1433.                                         # Regenerate the config file
  1434.                                         rebuild_config_file
  1435.  
  1436.                                         if [ `diff ${TMP_DIR}/config-backup ${KERNEL_SOURCE}/.config | wc -l` -gt 0 ]; then
  1437.                                         # Create dependency
  1438.                                                 make_dep
  1439.                                         fi
  1440.                                 fi
  1441.                         else
  1442.                                 # Change the config file
  1443.                                 check_config
  1444.  
  1445.                                 # Generate the config file
  1446.                                 rebuild_config_file
  1447.  
  1448.                                 # Create dependency
  1449.                                 make_dep
  1450.                         fi
  1451.                         fi
  1452.                 fi
  1453.         else
  1454.         # Config file _not_ available
  1455.                 message_status 1 "none"
  1456.  
  1457.                 # Clean the distriubuted files 
  1458.                 make_mrproper
  1459.  
  1460.                 if [ -d ${KERNEL_SOURCE}/configs ]; then
  1461.                         echo -n "Config files found"
  1462.                         message_status 1 "${KERNEL_SOURCE}/configs/"
  1463.  
  1464.                         # restore old config file from an alternative place (RedHat)
  1465.                         copy_alternative_configs
  1466.                 fi
  1467.  
  1468.                 if [ -f /proc/config.gz ]; then
  1469.                         copy_proc_fs_config
  1470.                 fi
  1471.  
  1472.                 # Restore old version.h file
  1473.                 version_h_management 0
  1474.  
  1475.                 # Generate the config file (step 1)
  1476.                 generate_config_file
  1477.  
  1478.                 # Change the config file
  1479.                 cp ${KERNEL_SOURCE}/.config ${TMP_DIR}/config-bk2
  1480.                 check_config
  1481.  
  1482.                 if [ `diff ${TMP_DIR}/config-bk2 ${KERNEL_SOURCE}/.config | wc -l` -gt 0 ]; then
  1483.                         # Generate the config file (step 2)
  1484.                         rebuild_config_file     
  1485.                 fi
  1486.  
  1487.                 # Create dependency
  1488.                 make_dep
  1489.         fi
  1490. }
  1491.  
  1492.  
  1493. function copy_proc_fs_config () {
  1494.         # Restore old config file from /proc/ fs
  1495.         # Syntax: copy_proc_fs_config
  1496.         # Author: mlindner
  1497.         # Returns:
  1498.         #       N/A
  1499.  
  1500.         echo -n "Copying file from proc directory"
  1501.         zcat /proc/config.gz &> ${KERNEL_SOURCE}/.config
  1502.         message_status 1 "done"
  1503. }
  1504.  
  1505.  
  1506. function copy_alternative_configs ()
  1507. {
  1508.         # Restore old config file from an alternative place (RedHat)
  1509.         # Syntax: copy_alternative_configs
  1510.         # Author: mlindner
  1511.         # Returns:
  1512.         #       N/A
  1513.  
  1514.         echo -n "Copying file from config directory"
  1515.         cpu_count=`cat /proc/cpuinfo | grep "cpu family" -c`
  1516.  
  1517.         pure_kernel=`echo ${KERNEL_VERSION} | cut -d '-' -f 1`
  1518.         mach_config="${KERNEL_SOURCE}/configs/kernel-$pure_kernel-$kernel_machine.config"
  1519.  
  1520.         if [ -f $mach_config ]; then
  1521.                if [ $cpu_count != 1 ]; then
  1522.                         if [ $cpu_count -gt 1 ]; then
  1523.                                 mach_config="${KERNEL_SOURCE}/configs/kernel-$pure_kernel-$kernel_machine-smp.config"
  1524.                                 cp $mach_config ${KERNEL_SOURCE}/.config
  1525.                                 message_status 1 "done"
  1526.                         else
  1527.                                 message_status 1 "file not found"
  1528.                         fi
  1529.                 else
  1530.                         cp $mach_config ${KERNEL_SOURCE}/.config
  1531.                         message_status 1 "done"
  1532.                 fi
  1533.         else
  1534.                 message_status 1 "file not found"
  1535.         fi
  1536. }
  1537.  
  1538.  
  1539. function generate_config_file ()
  1540. {
  1541.         # Generate a new .config file
  1542.         # Syntax: generate_config_file
  1543.         # Author: mlindner
  1544.         # Returns:
  1545.         #       N/A
  1546.  
  1547.         fname="Execute: make config"
  1548.         echo -n $fname
  1549.         message_status 3 "working"
  1550.         cd ${KERNEL_SOURCE}
  1551.         ${TMP_DIR}/enter | make config $MAKE_CPU_FLAG &> /dev/null
  1552.         echo -en "\015"
  1553.         echo -n $fname
  1554.         message_status 1 "done"
  1555.  
  1556. }
  1557.  
  1558. function rebuild_config_file ()
  1559. {
  1560.         # Rebuild the .config file
  1561.         # Syntax: rebuild_config_file
  1562.         # Author: mlindner
  1563.         # Returns:
  1564.         #       N/A
  1565.  
  1566.         fname="Execute: make oldconfig"
  1567.         echo -n $fname
  1568.         message_status 3 "working"
  1569.         cd ${KERNEL_SOURCE}
  1570.         ${TMP_DIR}/enter | make oldconfig $MAKE_CPU_FLAG &> /dev/null
  1571.         returnvalue=$?
  1572.         echo -en "\015"
  1573.         echo -n $fname
  1574.         message_status 1 "done"
  1575.  
  1576.         if [ $returnvalue != 0 ]; then
  1577.                 echo -n "Delete old .config file"
  1578.                 rm -rf .config
  1579.                 message_status 1 "done"
  1580.  
  1581.                 fname="Execute: make oldconfig (step2)"
  1582.                 echo -n $fname
  1583.                 message_status 3 "working"
  1584.                 cd ${KERNEL_SOURCE}
  1585.                 ${TMP_DIR}/enter | make oldconfig $MAKE_CPU_FLAG &> /dev/null
  1586.                 returnvalue=$?
  1587.                 echo -en "\015"
  1588.                 fname="Execute: make oldconfig"
  1589.                 echo -n $fname
  1590.                 message_status 1 "done"
  1591.         fi
  1592. }
  1593.  
  1594. function make_dep ()
  1595. {
  1596.         # Execute make dep
  1597.         # Syntax: make_dep
  1598.         # Author: mlindner
  1599.         # Returns:
  1600.         #       N/A
  1601.  
  1602.         # Make dep
  1603.         if [ ${KERNEL_FAMILY} == 2.4 ]; then
  1604.                 fname="Execute: make dep"
  1605.                 echo -n $fname
  1606.                 message_status 3 "working"
  1607.                 cd ${KERNEL_SOURCE}
  1608.                 make dep $MAKE_CPU_FLAG &> /dev/null
  1609.                 echo -en "\015"
  1610.                 echo -n $fname
  1611.                 message_status 1 "done"
  1612.         fi
  1613.  
  1614. }
  1615.  
  1616.  
  1617. function make_mrproper ()
  1618. {
  1619.         # Execute make mrproper
  1620.         # Syntax: make_mrproper
  1621.         # Author: mlindner
  1622.         # Returns:
  1623.         #       N/A
  1624.  
  1625.         # Make dep
  1626.         fname="Execute: make mrproper"
  1627.         echo -n $fname
  1628.         message_status 3 "working"
  1629.         cd ${KERNEL_SOURCE}
  1630.         make mrproper $MAKE_CPU_FLAG &> /dev/null
  1631.         echo -en "\015"
  1632.         echo -n $fname
  1633.         message_status 1 "done"
  1634.  
  1635. }
  1636.  
  1637.  
  1638. function version_header_management ()
  1639. {
  1640.         # Check version header and change it if neccassary
  1641.         # Syntax: version_header_management
  1642.         # Author: mlindner
  1643.         # Returns:
  1644.         #       N/A
  1645.  
  1646.         # Check header version
  1647.         echo -n "Check kernel header version"
  1648.         header_count=`grep -c RELEASE ${KERNEL_HEADER}/linux/version.h`
  1649.  
  1650.         if [ $header_count != 1 ]; then
  1651.                 message_status 2 "not recognized"
  1652.         else   
  1653.                 header_version=`grep RELEASE ${KERNEL_HEADER}/linux/version.h`
  1654.                 header_version=`echo $header_version | cut -d '"' -f 2`
  1655.                 if [ $header_version != ${KERNEL_VERSION} ]; then
  1656.                         if [ -z ${IGNORE_HEADER_MISMATCH} ]; then
  1657.                                 if [ "$user_sel" == "user installation" ]
  1658.                                 then
  1659.                                         message_status 1 "Kernel:${KERNEL_VERSION} != Header:$header_version"
  1660.  
  1661.                                         # Backup the version.h file
  1662.                                         version_h_management 1
  1663.  
  1664.                                         echo -n "Check and create new version.h"
  1665.                                         tmp_version=`cat ${KERNEL_HEADER}/linux/version.h`
  1666.                                         read_and_change_version_file <<INPUTSTART
  1667. $tmp_version
  1668. INPUTSTART
  1669.  
  1670.                                         message_status 1 "created"
  1671.                                 else
  1672.                                         message_status 0 "Kernel:${KERNEL_VERSION} != Header:$header_version"
  1673.                                         echo "+++ Kernel:${KERNEL_VERSION} != Header:$header_version" >> $logfile 2>&1
  1674.                                         header_check_failed
  1675.                                 fi
  1676.                         fi
  1677.                 else
  1678.                         message_status 1 "Kernel:${KERNEL_VERSION} == Header:$header_version"
  1679.                 fi
  1680.         fi
  1681. }
  1682.  
  1683.  
  1684. function read_and_change_version_file ()
  1685. {
  1686.         # change version file (version.h)
  1687.         # Syntax: read_and_change_version_file FILE_AS_STRING
  1688.         # Author: mlindner
  1689.         # Returns:
  1690.         #       N/A
  1691.  
  1692.         dline_count=0
  1693.         rm -rf ${TMP_DIR}/newversion.h
  1694.         pure_kernel_version=`echo ${KERNEL_VERSION}`
  1695.         pure_kernel_version=`echo $pure_kernel_version | cut -d '-' -f 1`
  1696.  
  1697.         while read line  # For as many lines as the input file has...
  1698.         do
  1699.                 line_count=`echo $line | grep -c "UTS_RELEASE"`
  1700.                 if [ $line_count != 0 ]; then
  1701.                         if [ $dline_count == 0 ]; then
  1702.                                 version_count=`echo $line | grep -c "$pure_kernel_version"`
  1703.                                 if [ $version_count == 1 ]; then
  1704.                                 # Change line
  1705.                                         echo "#define UTS_RELEASE \"${KERNEL_VERSION}\"" \
  1706.                                                 >> ${TMP_DIR}/newversion.h
  1707.                                         dline_count=1
  1708.                                 fi
  1709.                         fi
  1710.                 else
  1711.                         echo "$line" >> ${TMP_DIR}/newversion.h
  1712.                 fi
  1713.         done
  1714.  
  1715.         if [ $dline_count == 0 ]; then
  1716.                 header_check_failed
  1717.         fi
  1718.  
  1719.         cp ${TMP_DIR}/newversion.h ${KERNEL_HEADER}/linux/version.h
  1720. }
  1721.  
  1722.  
  1723. function version_h_management ()
  1724. {
  1725.         # Save or restore version.h file
  1726.         # Syntax: version_h_management FLAG
  1727.         #       FLAG:
  1728.         #              1 == Save version.h
  1729.         #              1 != Restore version.h
  1730.         # Author: mlindner
  1731.         # Returns:
  1732.         #       N/A
  1733.  
  1734.         if [ $1 != 1 ]; then
  1735.         # Restore version.h
  1736.                 if [ "$user_sel" == "user installation" ]; then
  1737.                         if [ -e ${TMP_DIR}/version.h ]; then
  1738.                                 echo -n "Restore old version.h"
  1739.                                 cp ${TMP_DIR}/version.h ${KERNEL_HEADER}/linux/version.h
  1740.                                 message_status 1 "done"
  1741.                         fi
  1742.                 fi
  1743.         else
  1744.         # Save old version.h file
  1745.                 if [ -f ${KERNEL_SOURCE}/include/linux/version.h ]; then
  1746.                         echo -n "Save old version.h file"
  1747.                         cp ${KERNEL_SOURCE}/include/linux/version.h ${TMP_DIR}/
  1748.                         message_status 1 "done"
  1749.                 fi
  1750.         fi
  1751.  
  1752. }
  1753.  
  1754. function autoconf_h_management ()
  1755. {
  1756.         # Save or restore autoconf.h file
  1757.         # Syntax: autoconf_h_management FLAG
  1758.         #       FLAG:
  1759.         #              1 == Save autoconf.h
  1760.         #              1 != Restore autoconf.h
  1761.         # Author: mlindner
  1762.         # Returns:
  1763.         #       N/A
  1764.  
  1765.         if [ $1 != 1 ]; then
  1766.         # Restore autoconf.h
  1767.                 if [ "$user_sel" == "user installation" ]; then
  1768.                         if [ -e ${TMP_DIR}/autoconf.h ]; then
  1769.                                 echo -n "Restore old autoconf.h"
  1770.                                 cp ${TMP_DIR}/autoconf.h ${KERNEL_HEADER}/linux/autoconf.h
  1771.                                 message_status 1 "done"
  1772.                         fi
  1773.                 fi
  1774.         else
  1775.         # Save old autoconf.h file
  1776.                 if [ -f ${KERNEL_SOURCE}/include/linux/autoconf.h ]; then
  1777.                         echo -n "Save old autoconf.h file"
  1778.                         cp ${KERNEL_SOURCE}/include/linux/autoconf.h ${TMP_DIR}/
  1779.                         message_status 1 "done"
  1780.                 fi
  1781.         fi
  1782.  
  1783. }
  1784.  
  1785. function dot_config_management ()
  1786. {
  1787.         # Save or restore config file
  1788.         # Syntax: dot_config_management FLAG
  1789.         #       FLAG:
  1790.         #              1 == Save .config
  1791.         #              1 != Restore .config
  1792.         # Author: mlindner
  1793.         # Returns:
  1794.         #       N/A
  1795.  
  1796.         if [ $1 != 1 ]; then
  1797.         # Restore .config
  1798.                 if [ "$user_sel" == "user installation" ]; then
  1799.                         if [ -e ${TMP_DIR}/config-backup ]; then
  1800.                                 echo -n "Restore old .config"
  1801.                                 cp ${TMP_DIR}/config-backup ${KERNEL_SOURCE}/.config
  1802.                                 message_status 1 "done"
  1803.                         fi
  1804.                 fi
  1805.         else
  1806.         # Save old .config file
  1807.                 if [ -f ${KERNEL_SOURCE}/include/linux/autoconf.h ]; then
  1808.                         echo -n "Save old .config file"
  1809.                         cp ${KERNEL_SOURCE}/.config ${TMP_DIR}/config-backup
  1810.                         message_status 1 "done"
  1811.                 fi
  1812.         fi
  1813.  
  1814. }
  1815.  
  1816. #################################################################
  1817. # Cleanup functions
  1818. #################################################################
  1819.  
  1820. function cleanup_trap ()
  1821. {
  1822.         # Sig handling
  1823.         # Syntax: cleanup_trap
  1824.         #       FLAG:
  1825.         # Author: mlindner
  1826.         # Returns:
  1827.         #       N/A
  1828.  
  1829.         cleanup
  1830.         clean
  1831.         exit 1
  1832.        
  1833. }
  1834.  
  1835. function cleanup ()
  1836. {
  1837.         # Restore all files
  1838.         # Syntax: cleanup
  1839.         # Author: mlindner
  1840.         # Returns:
  1841.         #       N/A
  1842.  
  1843.        
  1844.         # Restore version.h
  1845.         version_h_management 0
  1846.  
  1847.         # Restore old autoconf.h file
  1848.         autoconf_h_management 0
  1849.  
  1850.         if [ -e ${TMP_DIR}/config ]; then
  1851.                 if [ ${KERNEL_SOURCE} ]; then
  1852.                         cp ${TMP_DIR}/config ${KERNEL_SOURCE}/.config
  1853.                 fi
  1854.         fi
  1855.  
  1856.         return
  1857. }
  1858.  
  1859. function clean ()
  1860. {
  1861.         # Clean temp directory
  1862.         # Syntax: clean
  1863.         # Author: mlindner
  1864.         # Returns:
  1865.         #       N/A
  1866.  
  1867.         echo -n "Delete temp directories"
  1868.         cd $working_dir
  1869.         if [ ${TMP_DIR} ]; then
  1870.                rm -rf ${TMP_DIR}
  1871.         else
  1872.                 rm -rf /tmp/Sk98I*
  1873.         fi
  1874.         rm -rf $drv_name.o
  1875.         message_status 1 "done"
  1876.  
  1877.         return
  1878. }
  1879.  
  1880.  
  1881. #################################################################
  1882. # Generate patch functions
  1883. #################################################################
  1884. function check_driver_sources ()
  1885. {
  1886.         # Get some infos from the driver sources dir
  1887.         # Syntax: check_driver_sources
  1888.         # Author: mlindner
  1889.         # Returns:
  1890.         #       N/A
  1891.  
  1892.         local verstring=`cat ${TMP_DIR}/common/h/skversion.h | grep "VER_STRING"`
  1893.         DRIVER_VERSION=`echo $verstring | cut -d '"' -f 2`
  1894.         verstring=`cat ${TMP_DIR}/common/h/skversion.h | grep "DRIVER_REL_DATE"`
  1895.         DRIVER_REL_DATE=`echo $verstring | cut -d '"' -f 2`
  1896. }
  1897.  
  1898.  
  1899. function check_headers_for_patch ()
  1900. {
  1901.         # Get some infos from the Makefile
  1902.         # Syntax: check_headers_for_patch
  1903.         # Author: mlindner
  1904.         # Returns:
  1905.         #       N/A
  1906.  
  1907.         local mainkernel
  1908.         local patchkernel
  1909.         local sublevelkernel
  1910.  
  1911.         # Check header files
  1912.         if [ -d $KERNEL_SOURCE ]; then
  1913.                 export KERNEL_SOURCE=$KERNEL_SOURCE
  1914.         else
  1915.                 echo
  1916.                 echo "An error has occurred during the patch proces which prevented "; \
  1917.                 echo "the installation from completing.                              "; \
  1918.                 echo "Directory $KERNEL_SOURCE not found!.  "; \
  1919.                 echo $inst_failed
  1920.                 cleanup
  1921.                 clean
  1922.                 exit 1
  1923.         fi
  1924.  
  1925.         if [ -f $KERNEL_SOURCE/Makefile ]; then
  1926.                 export KERNEL_SOURCE=$KERNEL_SOURCE
  1927.         else
  1928.                 echo
  1929.                 echo "An error has occurred during the patch proces which prevented "; \
  1930.                 echo "the installation from completing.                              "; \
  1931.                 echo "Makefile in the directory $KERNEL_SOURCE not found!.  "; \
  1932.                 echo $inst_failed
  1933.                 cleanup
  1934.                 clean
  1935.                 exit 1
  1936.         fi
  1937.  
  1938.  
  1939.         # Get main version
  1940.         local mainversion=`grep "^VERSION =" $KERNEL_SOURCE/Makefile`
  1941.         local vercount=`echo $mainversion | wc -c`
  1942.         if [ $vercount -lt 1 ]; then
  1943.                 mainversion=`grep "^VERSION=" $KERNEL_SOURCE/Makefile`
  1944.         fi
  1945.         mainkernel=`echo $mainversion | cut -d '=' -f 2 | sed -e "s/ //g"`
  1946.  
  1947.         # Get patchlevel
  1948.         local patchlevel=`grep "^PATCHLEVEL =" $KERNEL_SOURCE/Makefile`
  1949.         vercount=`echo $patchlevel | wc -c`
  1950.         if [ $vercount -lt 1 ]; then
  1951.                 patchlevel=`grep "^PATCHLEVEL=" $KERNEL_SOURCE/Makefile`
  1952.         fi
  1953.         patchkernel=`echo $patchlevel | cut -d '=' -f 2 | sed -e "s/ //g"`
  1954.  
  1955.         # Get sublevel
  1956.         local sublevel=`grep "^SUBLEVEL =" $KERNEL_SOURCE/Makefile`
  1957.         vercount=`echo $sublevel | wc -c`
  1958.         if [ $vercount -lt 1 ]; then
  1959.                 sublevel=`grep "^SUBLEVEL=" $KERNEL_SOURCE/Makefile`
  1960.         fi
  1961.         sublevelkernel=`echo $sublevel | cut -d '=' -f 2 | sed -e "s/ //g"`
  1962.  
  1963.         # Version checks
  1964.         if [ $mainkernel != 2 ]; then
  1965.                 kernel_check_failed
  1966.         fi
  1967.  
  1968.         if [ $patchkernel != 4 ] && [ $patchkernel != 6 ]; then
  1969.                 kernel_check_failed
  1970.         fi
  1971.  
  1972.         if [ "$sublevelkernel" -lt  13 ] && [ $patchkernel == 4 ]; then
  1973.                 kernel_check_failed
  1974.         fi
  1975.  
  1976.         KERNEL_VERSION=`echo "$mainkernel.$patchkernel.$sublevelkernel"`
  1977.         KERNEL_FAMILY=`echo "$mainkernel.$patchkernel"`
  1978.         KERNEL_MINOR_VERSION=$sublevelkernel
  1979.         KERNEL_MAJOR_VERSION=$patchkernel
  1980. }
  1981.  
  1982.  
  1983. function check_system_for_patch ()
  1984. {
  1985.         # Get some infos from host
  1986.         # Syntax: check_system_for_patch
  1987.         # Author: mlindner
  1988.         # Returns:
  1989.         #       N/A
  1990.  
  1991.         # Check kernel version
  1992.  
  1993.         export KERNEL_VERSION=`uname -r`       
  1994.         split_kernel_ver=`echo ${KERNEL_VERSION} | cut -d '.' -f 1`
  1995.  
  1996.         KERNEL_FAMILY="$split_kernel_ver"
  1997.         split_kernel_ver=`echo ${KERNEL_VERSION} | cut -d '.' -f 2`
  1998.         KERNEL_FAMILY="$KERNEL_FAMILY.$split_kernel_ver"
  1999.  
  2000.         split_kernel_ver=`echo ${KERNEL_VERSION} | cut -d '.' -f 3`
  2001.         split_kernel_ver2=`echo $split_kernel_ver | cut -d '-' -f 1`
  2002.         KERNEL_MINOR_VERSION=`echo $split_kernel_ver2`
  2003.         KERNEL_MAJOR_VERSION=`echo ${KERNEL_VERSION} | cut -d '.' -f 2`
  2004.  
  2005.         # Check header files
  2006.         if [ -d /usr/src/linux/include/linux/ ]; then
  2007.                 export KERNEL_SOURCE="/usr/src/linux";
  2008.         else
  2009.                 if [ -d /usr/src/linux-${KERNEL_VERSION}/include/linux/ ]; then
  2010.                         export KERNEL_SOURCE="/usr/src/linux-${KERNEL_VERSION}";
  2011.                 else
  2012.                         kernel_check_dir="linux-$KERNEL_FAMILY"
  2013.                         if [ -d /usr/src/$kernel_check_dir/include/linux/ ]; then
  2014.                                 export KERNEL_SOURCE="/usr/src/$kernel_check_dir";
  2015.                         fi
  2016.              fi
  2017.         fi
  2018.  
  2019. }
  2020.  
  2021. function get_patch_infos ()
  2022. {
  2023.         # Interactive formular
  2024.         # Syntax: get_patch_infos
  2025.         # Author: mlindner
  2026.         # Returns:
  2027.         #       N/A
  2028.  
  2029.         if [ ! ${INSTALL_AUTO} ]; then
  2030.                 PS3='Choose your favorite installation method: ' # Sets the prompt string.
  2031.                 echo -n "Kernel source directory (${KERNEL_SOURCE}) : "
  2032.                 read kernel_source_in
  2033.                 if [ "$kernel_source_in" != "" ]; then
  2034.                         KERNEL_SOURCE=$kernel_source_in
  2035.                 fi
  2036.         fi
  2037.  
  2038.         # Check the headers
  2039.         check_headers_for_patch
  2040.  
  2041.         # Check driver version
  2042.         check_driver_sources
  2043.  
  2044.         if [ ! ${INSTALL_AUTO} ]; then
  2045.                 drvvertmp=`echo $DRIVER_VERSION | sed -e "s/ //g"`
  2046.                 PATCH_NAME="$working_dir/sk98lin_v"
  2047.                 PATCH_NAME="$PATCH_NAME$drvvertmp"
  2048.                 PATCH_NAME="${PATCH_NAME}_${KERNEL_VERSION}_patch"
  2049.  
  2050.                 echo -n "Patch name ($PATCH_NAME) : "
  2051.                 read patch_name_in
  2052.  
  2053.                 if [ "$patch_name_in" != "" ]; then
  2054.                         PATCH_NAME=$patch_name_in
  2055.                 fi
  2056.         fi
  2057. }
  2058.  
  2059.  
  2060. function generate_patch_for_help24 ()
  2061. {
  2062.         # Generate a patch for the config file
  2063.         # Syntax: generate_patch_for_help24
  2064.         #       package_root, kernel_root
  2065.         # Author: mlindner
  2066.         # Returns:
  2067.         #       N/A
  2068.         fname="Generate Config.help patch"
  2069.         echo -n $fname
  2070.         message_status 3 "working"
  2071.         local packagedir="$1"
  2072.         local kerneldir=$2
  2073.         local startline
  2074.         local totalline
  2075.         local splitline
  2076.         local count=0
  2077.         local splt=0
  2078.         local A="`echo | tr '\012' '\001' `"
  2079.  
  2080.         # initial cleanup
  2081.         rm -rf ${TMP_DIR}/all_sources_patch
  2082.  
  2083.         # find the first line of the sk block
  2084.         startline=`grep "CONFIG_SK98LIN$" $kerneldir/Documentation/Configure.help -n | cut -d ':' -f 1`
  2085.         totalline=`cat $kerneldir/Documentation/Configure.help | wc -l`
  2086.         ((startline=$startline - 2))
  2087.         ((splitline=$totalline - $startline))
  2088.         ((splitline=$splitline - 2))
  2089.  
  2090.         head -n $startline $kerneldir/Documentation/Configure.help > ${TMP_DIR}/Configure.help
  2091.         cat $packagedir/misc/Configure.help >> ${TMP_DIR}/Configure.help
  2092.         tail -n $splitline $kerneldir/Documentation/Configure.help > ${TMP_DIR}/Configuretemp
  2093.  
  2094.         # find the end of the block     
  2095.         while read line; do
  2096.                 ((count=$count + 1))
  2097.                 splt=`echo $line | grep CONFIG_ -c`
  2098.                 if [ $splt -gt 0 ]; then break; fi
  2099.         done < ${TMP_DIR}/Configuretemp
  2100.         ((count=$count - 2))
  2101.         ((splitline=$splitline - $count))
  2102.         tail -n $splitline $kerneldir/Documentation/Configure.help >> ${TMP_DIR}/Configure.help
  2103.  
  2104.         # Make diff
  2105.         diff -ruN $kerneldir/Documentation/Configure.help ${TMP_DIR}/Configure.help \
  2106.                 > ${TMP_DIR}/all_sources_patch
  2107.         replacement="linux-new/Documentation"
  2108.         sed -e "s$A${TMP_DIR}$A$replacement$A" \
  2109.                 ${TMP_DIR}/all_sources_patch &> ${TMP_DIR}/all_sources_patch2
  2110.         replacement="linux"
  2111.         sed -e "s$A$kerneldir$A$replacement$A" \
  2112.                 ${TMP_DIR}/all_sources_patch2 &> ${TMP_DIR}/all_sources_patch
  2113.  
  2114.  
  2115.         # Complete the patch
  2116.         if [ -f ${TMP_DIR}/all_sources_patch ] && \
  2117.                 [ `cat ${TMP_DIR}/all_sources_patch | wc -c` -gt 0 ]; then
  2118.                 echo "diff -ruN linux/Documentation/Configure.help \
  2119. linux-new/Documentation/Configure.help" >> ${PATCH_NAME}
  2120.                 cat ${TMP_DIR}/all_sources_patch >> ${PATCH_NAME}
  2121.         fi
  2122.  
  2123.         # Status
  2124.         echo -en "\015"
  2125.         echo -n $fname
  2126.         message_status 1 "done"
  2127. }
  2128.  
  2129.  
  2130. function generate_patch_for_config24 ()
  2131. {
  2132.         # Generate a patch for the config file
  2133.         # Syntax: generate_patch_for_config
  2134.         #       package_root, kernel_root
  2135.         # Author: mlindner
  2136.         # Returns:
  2137.         #       N/A
  2138.         fname="Generate Config.in patch"
  2139.         echo -n $fname
  2140.         message_status 3 "working"
  2141.         local packagedir="$1"
  2142.         local kerneldir=$2
  2143.         local startline
  2144.         local totalline
  2145.         local splitline
  2146.         local count=0
  2147.         local splt=0
  2148.         local A="`echo | tr '\012' '\001' `"
  2149.  
  2150.         # find the first line of the sk block
  2151.         startline=`grep "CONFIG_SK98LIN " $kerneldir/drivers/net/Config.in -n | cut -d ':' -f 1`
  2152.         totalline=`cat $kerneldir/drivers/net/Config.in | wc -l`
  2153.  
  2154.  
  2155.         ((startline=$startline - 1))
  2156.         ((splitline=$totalline - $startline))
  2157.         ((splitline=$splitline - 1))
  2158.         head -n $startline $kerneldir/drivers/net/Config.in > ${TMP_DIR}/Config.in
  2159.  
  2160.         # Insert a new description
  2161.         echo "dep_tristate 'Marvell Yukon Chipset / SysKonnect SK-98xx Support' CONFIG_SK98LIN \$CONFIG_PCI" >> ${TMP_DIR}/Config.in
  2162.         echo 'if [ "$CONFIG_SK98LIN" != "n" ]; then' >> ${TMP_DIR}/Config.in
  2163.         echo "  bool '    Use Rx polling (NAPI)' CONFIG_SK98LIN_NAPI" >> ${TMP_DIR}/Config.in
  2164.         echo "fi" >> ${TMP_DIR}/Config.in
  2165.  
  2166.         tail -n $splitline $kerneldir/drivers/net/Config.in > ${TMP_DIR}/Config.intemp
  2167.  
  2168.         # find the end of the block     
  2169.         while read line; do
  2170.                 ((count=$count + 1))
  2171.                 splt=`echo $line | grep "^dep_tristate"  -c`
  2172.                 if [ $splt -gt 0 ]; then break; fi
  2173.         done < ${TMP_DIR}/Config.intemp
  2174.         ((count=$count - 1))
  2175.         ((splitline=$splitline - $count))
  2176.         tail -n $splitline $kerneldir/drivers/net/Config.in >> ${TMP_DIR}/Config.in
  2177.  
  2178.         # Make diff
  2179.         diff -ruN $kerneldir/drivers/net/Config.in ${TMP_DIR}/Config.in \
  2180.                 > ${TMP_DIR}/all_sources_patch
  2181.         replacement="linux-new/drivers/net"
  2182.         sed -e "s$A${TMP_DIR}$A$replacement$A" \
  2183.                 ${TMP_DIR}/all_sources_patch &> ${TMP_DIR}/all_sources_patch2
  2184.         replacement="linux"
  2185.         sed -e "s$A$kerneldir$A$replacement$A" \
  2186.                 ${TMP_DIR}/all_sources_patch2 &> ${TMP_DIR}/all_sources_patch
  2187.  
  2188.         # Complete the patch
  2189.         if [ -f ${TMP_DIR}/all_sources_patch ] && \
  2190.                 [ `cat ${TMP_DIR}/all_sources_patch | wc -c` -gt 0 ]; then
  2191.                 echo "diff -ruN linux/drivers/net/Config.in \
  2192. linux-new/drivers/net/Config.in" >> ${PATCH_NAME}
  2193.                 cat ${TMP_DIR}/all_sources_patch >> ${PATCH_NAME}
  2194.         fi
  2195.  
  2196.  
  2197.         # Status
  2198.         echo -en "\015"
  2199.         echo -n $fname
  2200.         message_status 1 "done"
  2201. }
  2202.  
  2203.  
  2204. function generate_patch_for_kconfig26 ()
  2205. {
  2206.         # Generate a patch for the config file (kernel 2.6.x)
  2207.         # Syntax: generate_patch_for_kconfig26
  2208.         #       package_root, kernel_root
  2209.         # Author: mlindner
  2210.         # Returns:
  2211.         #       N/A
  2212.         fname="Generate Kconfig patch"
  2213.         echo -n $fname
  2214.         message_status 3 "working"
  2215.  
  2216.         local packagedir="$1"
  2217.         local kerneldir=$2
  2218.         local startline
  2219.         local totalline
  2220.         local splitline
  2221.         local count=0
  2222.         local splt=0
  2223.         local A="`echo | tr '\012' '\001' `"
  2224.  
  2225.         # find the first line of the sk block
  2226.         startline=`grep "SK98LIN$" $kerneldir/drivers/net/Kconfig -n | cut -d ':' -f 1`
  2227.         totalline=`cat $kerneldir/drivers/net/Kconfig | wc -l`
  2228.         ((startline=$startline - 1))
  2229.         ((splitline=$totalline - $startline))
  2230.         ((splitline=$splitline - 2))
  2231.         head -n $startline $kerneldir/drivers/net/Kconfig > ${TMP_DIR}/Kconfig
  2232.         cat $packagedir/misc/Kconfig >> ${TMP_DIR}/Kconfig
  2233.         tail -n $splitline $kerneldir/drivers/net/Kconfig > ${TMP_DIR}/Kconfigtemp
  2234.  
  2235.         # find the end of the block     
  2236.         while read line; do
  2237.                 ((count=$count + 1))
  2238.                 splt=`echo $line | grep "^config"  -c`
  2239.                 if [ $splt -gt 0 ]; then break; fi
  2240.         done < ${TMP_DIR}/Kconfigtemp
  2241.         ((count=$count - 2))
  2242.         ((splitline=$splitline - $count))
  2243.         tail -n $splitline $kerneldir/drivers/net/Kconfig >> ${TMP_DIR}/Kconfig
  2244.  
  2245.         # Make diff
  2246.         diff -ruN $kerneldir/drivers/net/Kconfig ${TMP_DIR}/Kconfig \
  2247.                 > ${TMP_DIR}/all_sources_patch
  2248.         replacement="linux-new/drivers/net"
  2249.         sed -e "s$A${TMP_DIR}$A$replacement$A" \
  2250.                 ${TMP_DIR}/all_sources_patch &> ${TMP_DIR}/all_sources_patch2
  2251.         replacement="linux"
  2252.         sed -e "s$A$kerneldir$A$replacement$A" \
  2253.                 ${TMP_DIR}/all_sources_patch2 &> ${TMP_DIR}/all_sources_patch
  2254.  
  2255.  
  2256.         # Complete the patch
  2257.         echo "diff -ruN linux/drivers/net/Kconfig \
  2258. linux-new/drivers/net/Kconfig" >> ${PATCH_NAME}
  2259.         cat ${TMP_DIR}/all_sources_patch >> ${PATCH_NAME}
  2260.  
  2261.         # Status
  2262.         echo -en "\015"
  2263.         echo -n $fname
  2264.         message_status 1 "done"
  2265. }
  2266.  
  2267.  
  2268. function generate_patch_for_readme ()
  2269. {
  2270.         # Generate a patch for the readme file
  2271.         # Syntax: generate_patch_for_readme
  2272.         #       package_root, kernel_root
  2273.         # Author: mlindner
  2274.         # Returns:
  2275.         #       N/A
  2276.  
  2277.         fname="Generate readme patch"
  2278.         echo -n $fname
  2279.         message_status 3 "working"
  2280.         local packagedir="$1/all"
  2281.         local kerneldir=$2
  2282.         local replacement
  2283.         local A="`echo | tr '\012' '\001' `"
  2284.  
  2285.         # initial cleanup
  2286.         rm -rf ${TMP_DIR}/all_sources_patch
  2287.  
  2288.         # Make diff
  2289.         diff -ruN $kerneldir/Documentation/networking/sk98lin.txt $packagedir/sk98lin.txt \
  2290.                 > ${TMP_DIR}/all_sources_patch
  2291.         replacement="linux-new/drivers/net/sk98lin"
  2292.         sed -e "s$A$packagedir$A$replacement$A" \
  2293.                 ${TMP_DIR}/all_sources_patch &> ${TMP_DIR}/all_sources_patch2
  2294.         replacement="linux"
  2295.         sed -e "s$A$kerneldir$A$replacement$A" \
  2296.                 ${TMP_DIR}/all_sources_patch2 &> ${TMP_DIR}/all_sources_patch
  2297.  
  2298.  
  2299.         # Complete the patch
  2300.        
  2301.         if [ -f ${TMP_DIR}/all_sources_patch ] && \
  2302.                 [ `cat ${TMP_DIR}/all_sources_patch | wc -c` -gt 0 ]; then
  2303.                 echo "diff -ruN linux/Documentation/networking/sk98lin.txt \
  2304. linux-new/Documentation/networking/sk98lin.txt" >> ${PATCH_NAME}
  2305.                 cat ${TMP_DIR}/all_sources_patch >> ${PATCH_NAME}
  2306.         fi
  2307.  
  2308.         # Status
  2309.         echo -en "\015"
  2310.         echo -n $fname
  2311.         message_status 1 "done"
  2312. }
  2313.  
  2314. function generate_patch_file ()
  2315. {
  2316.         # Generate a patch for a specific kernel version
  2317.         # Syntax: generate_patch_file
  2318.         #       package_root, kernel_root
  2319.         # Author: mlindner
  2320.         # Returns:
  2321.         #       N/A
  2322.  
  2323.         fname="Kernel version"
  2324.         echo -n $fname
  2325.         message_status 1 "${KERNEL_VERSION}"
  2326.  
  2327.         fname="Driver version"
  2328.         echo -n $fname
  2329.         message_status 1 "$DRIVER_VERSION"
  2330.  
  2331.         fname="Release date"
  2332.         echo -n $fname
  2333.         message_status 1 "$DRIVER_REL_DATE"
  2334.  
  2335.         # Check if some kernel functions are available
  2336.         check_kernel_functions
  2337.  
  2338.         fname="Generate driver patches"
  2339.         echo -n $fname
  2340.         message_status 3 "working"
  2341.         local packagedir="$1/all"
  2342.         local kerneldir=$2
  2343.         local replacement
  2344.         local line=`echo "-x '\*.\[o4\]' -x '.\*' -x '\*.ko' -x '\*.txt' -x '\*.htm\*' "`
  2345.         local A="`echo | tr '\012' '\001' `"
  2346.  
  2347.         diff -ruN -x "*.[o4]" -x ".*" -x "*.ko" -x "*.txt" -x "*.htm*" \
  2348.                 $kerneldir/drivers/net/sk98lin $packagedir > ${TMP_DIR}/all_sources_patch
  2349.         replacement="linux-new/drivers/net/sk98lin"
  2350.         sed -e "s$A$packagedir$A$replacement$A" \
  2351.                 ${TMP_DIR}/all_sources_patch &> ${TMP_DIR}/all_sources_patch2
  2352.         replacement="linux"
  2353.         sed -e "s$A$kerneldir$A$replacement$A" \
  2354.                 ${TMP_DIR}/all_sources_patch2 &> ${TMP_DIR}/all_sources_patch
  2355.         replacement=`echo ""`
  2356.         sed -e "s$A$line$A$A" \
  2357.                 ${TMP_DIR}/all_sources_patch &> ${PATCH_NAME}
  2358.  
  2359.         # Status
  2360.         echo -en "\015"
  2361.         echo -n $fname
  2362.         message_status 1 "done"
  2363. }
  2364.  
  2365.  
  2366. function patch_generation ()
  2367. {
  2368.         # Generate a patch for a specific kernel version
  2369.         # Syntax: patch_generation
  2370.         # Author: mlindner
  2371.         # Returns:
  2372.         #       N/A
  2373.  
  2374.         # Check system
  2375.         check_system_for_patch
  2376.  
  2377.         # Generate safe tmp dir
  2378.         make_safe_tmp_dir
  2379.  
  2380.         # Create tmp dir and unpack the driver
  2381.         unpack_driver
  2382.         clear
  2383.  
  2384.         # Get user infos
  2385.         get_patch_infos
  2386.  
  2387.         # Copy files
  2388.         cp -pr ${TMP_DIR}/common/* ${TMP_DIR}/all
  2389.         cp -pr ${TMP_DIR}/${KERNEL_FAMILY}/* ${TMP_DIR}/all
  2390.  
  2391.         # Create makefile
  2392.         [ $KERNEL_FAMILY == "2.4" ] && create_makefile_24 0
  2393.         [ $KERNEL_FAMILY == "2.6" ] && create_makefile_26 0
  2394.         clear
  2395.  
  2396.         # Generate a patch for a specific kernel version
  2397.         generate_patch_file ${TMP_DIR} $KERNEL_SOURCE
  2398.  
  2399.         # Generate a patch for the readme file
  2400.         generate_patch_for_readme ${TMP_DIR} $KERNEL_SOURCE
  2401.  
  2402.         # Generate a patch for the config file
  2403.         if [ "${KERNEL_FAMILY}" == "2.4" ]; then
  2404.                 generate_patch_for_config24 ${TMP_DIR} $KERNEL_SOURCE
  2405.         else
  2406.                 generate_patch_for_kconfig26 ${TMP_DIR} $KERNEL_SOURCE
  2407.         fi
  2408.  
  2409.         # Generate a patch for the config file
  2410.         if [ "${KERNEL_FAMILY}" == "2.4" ]; then
  2411.                 generate_patch_for_help24 ${TMP_DIR} $KERNEL_SOURCE
  2412.         fi
  2413.  
  2414.         # Clear the tmp dirs
  2415.         clean
  2416.  
  2417.         if [ ! -f ${PATCH_NAME} ] || \
  2418.                 [ `cat ${PATCH_NAME} | wc -c` == 0 ]; then
  2419.                 rm -rf ${PATCH_NAME}
  2420.                 echo
  2421.                 echo "Patch not generated."
  2422.                 echo "The sources already installed on the system in the directory "
  2423.                 echo "     $KERNEL_SOURCE"
  2424.                 echo "are equal to the sources from the install package."
  2425.                 echo "This implies that it makes not sense to create the patch, "
  2426.                 echo "because it'll be of size zero!"
  2427.                 echo "Don't worry, this is not a failure. It just means, that you"
  2428.                 echo "already use the latest driver version."
  2429.                 echo
  2430.                 echo "                                                     Have fun..."
  2431.  
  2432.                 exit
  2433.                
  2434.         else
  2435.                 echo
  2436.                 echo "All done. Patch successfully generated."
  2437.                 echo "To apply the patch to the system, proceed as follows:"
  2438.                 echo "      # cd $KERNEL_SOURCE"
  2439.                 echo "      # cat ${PATCH_NAME} | patch -p1"
  2440.                 echo
  2441.                 echo "                                                     Have fun..."
  2442.                 exit
  2443.         fi
  2444. }
  2445.  
  2446.  
  2447.  
  2448. #################################################################
  2449. # Main functions
  2450. #################################################################
  2451. function start_sequence ()
  2452. {
  2453.         # Print copyright informations, mode selection and check
  2454.         # Syntax: start_sequence
  2455.         # Author: mlindner
  2456.         # Returns:
  2457.         #       N/A
  2458.  
  2459.         # Start. Choose a installation method and check method
  2460.         echo
  2461.         echo "Installation script for $drv_name driver."
  2462.         echo "Version $VERSION"
  2463.         echo "(C)Copyright 2003-2004 Marvell(R)."
  2464.         echo "===================================================="
  2465.         echo "Add to your trouble-report the logfile install.log"
  2466.         echo "which is located in the  DriverInstall directory."
  2467.         echo "===================================================="
  2468.         echo
  2469.  
  2470.         # Silent option. Return...
  2471.         [ "$OPTION_SILENT" ] && return
  2472.         [ "$INSTALL_AUTO" ] && patch_generation
  2473.  
  2474.  
  2475.         PS3='Choose your favorite installation method: ' # Sets the prompt string.
  2476.  
  2477.         echo
  2478.  
  2479.         select user_sel in "user installation" "expert installation" "generate patch" "exit"
  2480.         do
  2481.                 break  # if no 'break' here, keeps looping forever.
  2482.         done
  2483.  
  2484.         if [ "$user_sel" == "exit" ]; then
  2485.                 echo "Exit."
  2486.                 exit
  2487.         fi
  2488.  
  2489.         if [ "$user_sel" != "user installation" ] && [ "$user_sel" != "expert installation" ] && [ "$user_sel" != "generate patch" ]; then
  2490.                 echo "Exit."
  2491.                 exit
  2492.         fi
  2493.  
  2494.         clear
  2495.  
  2496.         if [ "$user_sel" == "user installation" ]; then
  2497.                 echo "Please read this carfully!"
  2498.                 echo
  2499.                 echo "This script will automatically compile and load the $drv_name"
  2500.                 echo "driver on your host system. Before performing both compilation"
  2501.                 echo "and loading, it is necessary to shutdown any device using the"
  2502.                 echo "$drv_name kernel module and to unload the old $drv_name kernel "
  2503.                 echo "module. This script will do this automatically per default."
  2504.                 echo "If you want to shutdown and unload the old $drv_name kernel module"
  2505.                 echo "manually, run the script in the EXPERT mode."
  2506.                 echo " "
  2507.                 echo "Please plug a card into your machine. Without a card we aren't"
  2508.                 echo "able to check the full driver functionality."
  2509.                 echo
  2510.                 echo -n "Do you want proceed? (y/N) "
  2511.  
  2512.                 old_tty_settings=$(stty -g)          # Save old settings.
  2513.                 stty -icanon
  2514.                 Keypress=$(head -c1)
  2515.                 stty "$old_tty_settings"                        # Restore old terminal settings.
  2516.                 echo "+++ Install mode: User" >> $logfile 2>&1
  2517.                 echo "+++ Driver version: $VERSION" >> $logfile 2>&1
  2518.  
  2519.                 if [ "$Keypress" == "Y" ]
  2520.                 then
  2521.                         clear
  2522.                 else
  2523.                         if [ "$Keypress" == "y" ]
  2524.                         then
  2525.                                 clear
  2526.                         else
  2527.                                 echo "Exit"
  2528.                                 clean
  2529.                                 exit 0
  2530.                         fi
  2531.                 fi
  2532.                
  2533.                 export REMOVE_SKDEVICE=1
  2534.  
  2535.         else
  2536.                 if [ "$user_sel" == "expert installation" ]; then
  2537.                         INSTALL_MODE="INSTALL"
  2538.                         echo "+++ Install mode: Expert" >> $logfile 2>&1
  2539.                         clear
  2540.                 else
  2541.                         clear
  2542.                         INSTALL_MODE="PATCH"
  2543.                         patch_generation
  2544.                 fi
  2545.         fi
  2546. }
  2547.  
  2548. function main_global ()
  2549. {
  2550.         # Main function
  2551.         # Syntax: patch_generation
  2552.         # Author: mlindner
  2553.         # Returns:
  2554.         #       N/A
  2555.  
  2556.         # Extract all given parameters
  2557.         extract_params $*
  2558.  
  2559.         # Run given functions
  2560.         if [ "${OPTION_HELP}" ]; then help; fi
  2561.         if [ "${OPTION_SILENT}" ]; then user_sel=`echo user`; fi
  2562.         if [ "${OPTION_CLEANUP}" ]; then clean; exit 0; fi
  2563.         if [ "${OPTION_PATCH}" ]; then
  2564.                 INSTALL_MODE="PATCH"
  2565.                 INSTALL_AUTO=1
  2566.                 KERNEL_SOURCE=$2
  2567.                 if [ `echo $3 | grep -c "/"` gt 0 ]; then
  2568.                         PATCH_NAME=$3
  2569.                 else
  2570.                         PATCH_NAME=${working_dir}/$3
  2571.                 fi
  2572.         fi
  2573.  
  2574.         # Print copyright informations, mode selection and check
  2575.         start_sequence
  2576.  
  2577.         # Generate safe tmp dir
  2578.         make_safe_tmp_dir
  2579.  
  2580.         # Check user informations and tools availability
  2581.         check_user_and_tools
  2582.  
  2583.         # Check kernel and module informations
  2584.         check_kernel_informations
  2585.  
  2586.         # Create tmp dir and unpack the driver
  2587.         unpack_driver
  2588.  
  2589.         # Create makefile
  2590.         [ $KERNEL_FAMILY == "2.4" ] && create_makefile_24 1
  2591.         [ $KERNEL_FAMILY == "2.6" ] && create_makefile_26 1
  2592.  
  2593.         # Check config files
  2594.         generate_config
  2595.  
  2596.         # Check and generate a correct version.h file
  2597.         generate_sources_version
  2598.  
  2599.         # Check if some kernel functions are available
  2600.         check_kernel_functions
  2601.  
  2602.  
  2603.         # Configure, check and build the driver
  2604.         [ $KERNEL_FAMILY == "2.4" ] && make_driver_24
  2605.         [ $KERNEL_FAMILY == "2.6" ] && make_driver_26 1
  2606.  
  2607.         # Copy driver
  2608.         copy_driver
  2609.  
  2610. }
  2611.  
  2612.  
  2613. # Start
  2614. #####################################################################
  2615.  
  2616. drv_name=`echo sk98lin`
  2617. VERSION=`echo "7.06 (Aug-20-2004)"`
  2618. #drv_name=`echo sk98lin`
  2619. working_dir=`pwd`
  2620. logfile="$working_dir/install.log"
  2621. rm -rf $logfile &> /dev/null
  2622. trap cleanup_trap INT TERM
  2623. KERNEL_TREE_MAKE=0;
  2624. clear
  2625.  
  2626. # Run main function
  2627. main_global $*
  2628.  
  2629. # Exit
  2630. exit 0

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right