VirtualBox

vbox的更動 64716 路徑 trunk/src/VBox/Installer


忽略:
時間撮記:
2016-11-19 下午02:41:26 (8 年 以前)
作者:
vboxsync
訊息:

bugref:#8530: Documentation: improve automated instructions for building kernel modules: rewrote check_module_dependencies script. The new one only recognises known kernel flavours from known distributions instead of trying to guess generically, greatly simplifying the script. In the end I did write a unit test as it was actually faster than testing manually, but it is at the end of the code where it does not harm readability.

位置:
trunk/src/VBox/Installer/linux
檔案:
修改 2 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/Installer/linux/check_module_dependencies.sh

    r58403 r64716  
    55
    66#
    7 # Copyright (C) 2007-2015 Oracle Corporation
     7# Copyright (C) 2007-2016 Oracle Corporation
    88#
    99# This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616#
    1717
    18 # This script tests whether a Linux system is set up to build kernel modules,
    19 # and if not attempts to discover and optionally perform the necessary steps to
    20 # set up the system correctly, based on knowledge of popular Linux
    21 # distributions.  It is written for use with the VirtualBox and the VirtualBox
    22 # Guest Additions kernel modules but should be useful for any package which
    23 # needs to build kernel modules on an unknown target system.  While patches to
    24 # extend the range of distributions supported are welcome, please bear in mind
    25 # that we try to keep distribution-specific parts as small as possible, and to
    26 # cover as many distributions as possible in single "families".  Any
    27 # distribution which requires specific code to support should be sufficiently
    28 # widely used to justify the addition.
     18set -e
     19
     20# Usage:
     21USAGE_MESSAGE=\
     22'Usage: `basename ${0}` [-h|--help|
     23    --test [<uname -r output> rpm|dpkg [<base expected> <versioned expected>]]]
     24This script tests whether a Linux system is set up to build kernel modules,
     25and if not prints a guess as to which distribution packages need to be
     26installed to do so, and what commands to use.  It uses the output of the
     27"uname -r" command to guess the packages and searches for packaging tools
     28by checking for packaging databases.
     29
     30For testing you can specify the output of "uname -r" which will be used
     31instead of the real one and the package type, and optionally the expected
     32output.  --test without parameters will test a number of known inputs.'
     33
     34# General theory of operation (valid Nov 19 2016): we check whether this is an
     35# rpm or dpkg system by checking for the respective non-empty database directory
     36# (we assert that only one is present), and based on that we map uname -r output
     37# to a kernel package name.  Here is a textual description of known mappings
     38# (not all of these are currently implemented) for both the general package name
     39# and the version-specific package name.  Keeping this here as it took some time
     40# and pain to research.
     41#
     42# Debian/Ubuntu (dpkg): <version>-<flavour> -> linux-headers-<flavour>,
     43#                                              linux-headers-<version>-<flavour>
     44DEBIAN_FLAVOURS="generic lowlatency virtual 486 686-pae amd64 rt-686-pae \
     45    rt-amd64 i386 586 grsec-686-pae grsec-amd64 686"
     46# SUSE (rpm): <version>-<flavour> -> kernel-<flavour>-devel,
     47#                                    kernel-<flavour>-devel-<version>
     48SUSE_FLAVOURS="debug default ec2 pae trace vanilla vmi xen"
     49# OL/RHEL/CentOS (rpm): <version><flavour>[.i686|.x86_64] -> kernel-<flavour>-devel,
     50#   kernel-<flavour>-devel-<`uname -r`>, where <version> ends in el*.
     51EL_FLAVOURS="uek xen"
     52# Fedora (rpm): <version> -> kernel-devel, kernel-devel-<version>, where <version>
     53#   ends in fc*.
     54#
     55# OUTPUT NOT YET TESTED ON REAL SYSTEMS
     56#
     57# Mageia (rpm): <version>-*.mga* -> kernel-linus-latest,
     58#                                   kernel-linus-<`uname -r`>
     59#   <version>-<flavour>-*.mga* -> kernel-<flavour>-latest,
     60#                                 kernel-<flavour>-<`uname -r`>
     61MAGEIA_FLAVOURS="desktop desktop586 server tmb-desktop"
     62# PCLinuxOS (dpkg): <version>-pclos* -> kernel-devel, kernel-devel-<`uname -r`>
    2963
    3064PATH=$PATH:/bin:/sbin:/usr/sbin
    3165
    32 ## @todo include routines.sh once it has been cleaned up
    33 
    34 ## Set all commands used in the script to their normal values.  These are the
    35 # script's interface to the outside world and should be overridden for self
    36 # testing.
    37 set_up_helpers()
    38 {
    39     exit=exit
    40     get_kernel_version="uname -r"
    41     file_exists="test -f"
    42     string_in_file="grep -q -s"
    43     do_type=type
    44     find_rpm_for_file="rpm -q --whatprovides"
    45     find_deb_for_file="dpkg -S"
    46 }
    47 
    48 
    49 ## uname -r stand-in for self testing
    50 test_get_kernel_version()
    51 {
    52     echo "$test_uname_r";
    53 }
    54 
    55 
    56 ## test -f $1 or grep $1 $2 stand-in for self testing
    57 test_file_exists()
    58 {
    59     test '(' -z "$2" -a "$test_test_f" = "$1" ')' -o \
    60          '(' "$test_grep_string" = "$1" -a "$test_grep_file" = "$2" ')';
    61 }
    62 
    63 
    64 ## rpm -q --whatprovides stand-in for self testing
    65 test_find_rpm_for_file()
    66 {
    67     echo "$test_rpm_q";
    68 }
    69 
    70 
    71 ## exit stand-in for self testing
    72 test_exit()
    73 {
    74     test_exit_return="$1";
    75 }
    76 
    77 
    78 ## dpkg -S stand-in for self testing
    79 test_find_deb_for_file()
    80 {
    81     echo "$test_dpkg_s";
    82 }
    83 
    84 
    85 ## type stand-in for self testing
    86 test_type()
    87 {
    88     test "$1" = "$test_type_binary" && echo "$test_type_binary";
    89 }
    90 
    91 
    92 ## Evaluate a line describing the results of a self test.  Outputs a line of
    93 #  text describing each failure.
    94 eval_test_line()
    95 {
    96     ## @param test_line      The test description line to evaluate in the
    97     #                        format:
    98     # "<line num>: <variable to set>=<value> ...=><variable to check>=<expected value>..."
    99     #                        All output variables will be nulled first.  Unused
    100     #                        "variables to set" should be explicitly set to
    101     #                        null in the list.  Spaces in variable names are
    102     #                        not allowed, in values they can be escaped with
    103     #                        backslash, and "=>" can be embedded as "=\>".
    104     test_line="$1"
    105     ## @param test_function  The function to call after setting the variables
    106     #                        from the test line
    107     test_function="$2"
    108 
    109     line_num=${test_line%%:*=>*}
    110     env_all=${test_line#*:}
    111     env_in=${env_all%%=>*}
    112     env_out=${env_all#*=>}
    113     # Blank out output variables first.
    114     eval set $env_out  # Trick for dealing with escaped embedded spaces.
    115     for j in "$@"; do
    116         var_name="${j%%=*}"
    117         eval $var_name=
    118     done
    119     # Set input variables.
    120     eval set $env_in
    121     for j in "$@"; do
    122         var_name=${j%%=*}
    123         var_value="${j#*=}"
    124         eval $var_name=\"$var_value\"  # More tricks
    125     done
    126     eval $test_function
    127     eval set $env_out
    128     for j in "$@"; do
    129         var_name=${j%%=*}
    130         var_value="$(eval echo \$$var_name)"
    131         var_expected="${j#*=}"
    132         case $var_value in
    133         $var_expected) ;;
    134         *)
    135             echo "$test_function: failure: $var_name=$var_value in line $line_num"
    136             ;;
    137         esac
    138     done
    139 }
    140 
    141 
    142 ## List of tests to be executed in a test run
    143 self_tests=
    144 
    145 
    146 ## Aborts the script and prints a printf-type error message to stderr.
    147 abort()
    148 {
    149     ## Message to print to stderr before aborting.
    150     message="$1"
    151 
    152     echo 1>&2 "$message"
    153     echo 1>&2 "Unable to continue."
    154     $exit 1
    155 }
    156 
    157 
    158 ## Abort if we are not running as root
    159 check_root() {
    160     case $(id -u) in 0) ;; *)
    161         abort "This program must be run with administrator privileges."
    162     esac
    163 }
    164 
    165 
    166 ## Get information about the kernel running on the system (version and path
    167 # information).
    168 # @param KERN_VER       [out]  Full kernel version (e.g. 3.0.0-15-generic).
    169 # @param KERN_VER_BASE  [out]  Base kernel version (e.g. 3.0.0).
    170 # @param KERN_VER_SHORT [out]  Kernel major and minor version (e.g. 3.0).
    171 # @param KERN_VER_EXTRA [out]  Kernel version "extra" information (e.g.
    172 #                              -15-generic).
    173 # @param KERN_DIR       [out]  The directory where kernel modules and headers
    174 #                              live (e.g. /lib/modules/3.0.0-15-generic)
    175 get_kernel_information()
    176 {
    177     KERN_VER=$($get_kernel_version 2>/dev/null || abort "'uname' tool not found.")
    178     kern_ver_rest=${KERN_VER#*.*.}
    179     kern_ver_micro=${kern_ver_rest%%[!0-9]*}
    180     KERN_VER_EXTRA=${kern_ver_rest#$kern_ver_micro}
    181     KERN_VER_BASE=${KERN_VER%$KERN_VER_EXTRA}
    182     KERN_VER_SHORT=${KERN_VER_BASE%.*}
    183     KERN_DIR="/lib/modules/$KERN_VER"
    184 }
    185 
    186 
    187 ## Self test for the "get_kernel_information" function.  Outputs a line of
    188 #  text describing each failure.
    189 test_get_kernel_information()
    190 {
    191     get_kernel_version=test_get_kernel_version
    192     for i in \
    193         "1: test_uname_r=3.0.0-15-generic=>KERN_VER=3.0.0-15-generic KERN_VER_BASE=3.0.0 KERN_VER_SHORT=3.0 KERN_VER_EXTRA=-15-generic KERN_DIR=/lib/modules/3.0.0-15-generic" \
    194         "2: test_uname_r=2.4.21-50.EL=>KERN_VER=2.4.21-50.EL KERN_VER_BASE=2.4.21 KERN_VER_SHORT=2.4 KERN_VER_EXTRA=-50.EL KERN_DIR=/lib/modules/2.4.21-50.EL"
    195     do eval_test_line "$i" get_kernel_information; done
    196 }
    197 
    198 self_tests="$self_tests test_get_kernel_information"
    199 
    200 
    201 ## Test whether a three-digit kernel version number is less than a second one.
    202 kernel_version_lt()
    203 {
    204     major1=${1%.*.*}
    205     major2=${2%.*.*}
    206     short1=${1%.*}
    207     short2=${2%.*}
    208     minor1=${short1#*.}
    209     minor2=${short2#*.}
    210     micro1=${1#*.*.}
    211     micro2=${2#*.*.}
    212     test $major1 -lt $major2 -o \
    213       '(' $major1 -eq $major2 -a $minor1 -lt $minor2 ')' -o \
    214       '(' $major1 -eq $major2 -a $minor1 -eq $minor2 -a $micro1 -lt $micro2 ')'
    215 }
    216 
    217 
    218 ## Self test for the "kernel_version_lt" function.  Outputs a line of
    219 #  text describing each failure.
    220 test_kernel_version_lt()
    221 {
    222     for i in \
    223         "1: ver1=2.4.6 ver2=3.4.6 =>lt=true" \
    224         "2: ver1=3.4.6 ver2=3.4.6 =>lt=" \
    225         "3: ver1=2.4.6 ver2=2.4.7 =>lt=true" \
    226         "4: ver1=2.4.60 ver2=2.4.7 =>lt=" \
    227         "5: ver1=2.31.7 ver2=2.4.7 =>lt="
    228     do eval_test_line "$i" "kernel_version_lt \$ver1 \$ver2 && lt=true"; done
    229 }
    230 
    231 self_tests="$self_tests test_kernel_version_lt"
    232 
    233 
    234 # Some SUSE systems match three packages to the kernel directory.  Selecting
    235 # the first is not quite right, but doesn't matter on those systems.
    236 FIND_KERNEL_RPM='rpm_q_out=$(echo $($find_rpm_for_file "$KERN_DIR/kernel")); KERN_PACKAGE=${rpm_q_out%%\ *}'
    237 FIND_KERNEL_DEB='dpkg_s_out=$($find_deb_for_file "$KERN_DIR/kernel"); KERN_PACKAGE=${dpkg_s_out%\: $KERN_DIR/kernel}'
    238 
    239 
    240 ## Determine the command patterns needed to install gcc, make and the kernel
    241 #  headers on the current distribution.
    242 #  @note  We want to support the distributions we do with the least possible
    243 #         special logic, so please do not add new code if existing code can
    244 #         catch a new distribution (e.g. it is similar to another).
    245 #  @note  This function is very long, but contains nearly all the distribution-
    246 #         specific logic in the file.
    247 #  @param KERN_VER_BASE               The three-point kernel version.
    248 #  @param GET_KERN_PACKAGE      [out] Command to find the kernel package name
    249 #                                     given the path $KERN_DIR.
    250 #  @param PATTERN_GCC_MAKE      [out] A pattern to be resolved to get the
    251 #                                     command to install gcc and make.
    252 #  @param PATTERN_HEADERS       [out] A pattern to be resolved to get the
    253 #                                     command to install the kernel headers for
    254 #                                     the currently running kernel.
    255 #  @param PATTERN_HEADERS_META  [out] A pattern to be resolved to get the
    256 #                                     command to install a dependency on the
    257 #                                     current kernel headers.  May be empty.
    258 #  @note These patterns may all depend on $KERN_VER (uname -r output),
    259 #        $KERN_PACKAGE_BASE (distribution kernel package name without any
    260 #        version information at all), $KERN_DEBIAN_SUFFIX (the Debian-style
    261 #        "-generic", "-586" etc kernel name suffix) and $KERN_RPM_SUFFIX
    262 #        (the kernel-version-plus-rpm-version for the current kernel RPM).
    263 get_system_information()
    264 {
    265     # SUSE and Man*/Mageia must come before Redhat.
    266     if $file_exists /etc/SuSE-release; then  # SUSE-based, before Red Hat
    267         GET_KERN_PACKAGE="$FIND_KERNEL_RPM"
    268         PATTERN_GCC_MAKE='zypper\ install\ gcc\ make'
    269         if kernel_version_lt "$KERN_VER_BASE" '2.6.30'; then
    270             PATTERN_HEADERS='zypper\ install\ kernel-source-$KERN_RPM_SUFFIX\ kernel-syms-$KERN_RPM_SUFFIX'
    271             PATTERN_HEADERS_META='zypper\ install\ kernel-source\ kernel-syms'
    272         else
    273             PATTERN_HEADERS='zypper\ install\ ${KERN_PACKAGE_BASE}devel-$KERN_RPM_SUFFIX'
    274             PATTERN_HEADERS_META='zypper\ install\ ${KERN_PACKAGE_BASE}devel'
    275         fi
    276     elif $file_exists /etc/pclinuxos-release; then  # PCLinuxOS - before Mandrake
    277         GET_KERN_PACKAGE=
    278         PATTERN_GCC_MAKE=
    279         PATTERN_HEADERS=
    280         PATTERN_HEADERS_META=
    281     elif $file_exists /etc/mandrake-release; then  # Mandrake family
    282         GET_KERN_PACKAGE="$FIND_KERNEL_RPM"
    283         PATTERN_GCC_MAKE='urpmi\ gcc\ make'
    284         if kernel_version_lt "$KERN_VER_BASE" '2.6.0'; then
    285             PATTERN_HEADERS='urpmi\ kernel-source-$KERN_VER'
    286             PATTERN_HEADERS_META='urpmi\ kernel-source'
    287         elif kernel_version_lt "$KERN_VER_BASE" '2.6.8'; then
    288             PATTERN_HEADERS='urpmi\ kernel-source-stripped-$KERN_VER'
    289             PATTERN_HEADERS_META='urpmi\ kernel-source-stripped'
    290         # Mandrake/Mandriva had a funny naming scheme for a few kernel versions
    291         elif kernel_version_lt "$KERN_VER_BASE" '2.6.17'; then
    292             PATTERN_HEADERS='urpmi\ kernel-source-stripped-2.6-${KERN_VER%-*}'
    293             PATTERN_HEADERS_META='urpmi\ kernel-source-stripped-2.6'
    294         elif kernel_version_lt "$KERN_VER_BASE" '2.6.22'; then
    295             PATTERN_HEADERS='urpmi\ kernel-source-stripped-$KERN_RPM_SUFFIX'
    296             PATTERN_HEADERS_META='urpmi\ kernel-source-stripped-latest'
    297         else
    298             PATTERN_HEADERS='urpmi\ ${KERN_PACKAGE_BASE}devel-$KERN_RPM_SUFFIX'
    299             PATTERN_HEADERS_META='urpmi\ ${KERN_PACKAGE_BASE}devel-latest'
    300         fi
    301     elif $file_exists /etc/redhat-release; then  # Red Hat family
    302         GET_KERN_PACKAGE="$FIND_KERNEL_RPM"
    303         if $do_type dns >/dev/null 2>&1; then
    304             PACKAGE_INSTALLER="dns install"
    305         elif $do_type yum >/dev/null 2>&1; then
    306             PACKAGE_INSTALLER="yum install"
    307         else
    308             PACKAGE_INSTALLER=up2date
    309         fi
    310         PATTERN_GCC_MAKE='$PACKAGE_INSTALLER\ gcc\ make'
    311         if kernel_version_lt "$KERN_VER_BASE" '2.6.9'; then
    312             PATTERN_HEADERS='$PACKAGE_INSTALLER\ kernel-source-$KERN_RPM_SUFFIX'
    313             PATTERN_HEADERS_META='$PACKAGE_INSTALLER\ kernel-source'
    314         else
    315             PATTERN_HEADERS='$PACKAGE_INSTALLER\ ${KERN_PACKAGE_BASE}devel-$KERN_RPM_SUFFIX'
    316             PATTERN_HEADERS_META='$PACKAGE_INSTALLER\ ${KERN_PACKAGE_BASE}devel'
    317         fi
    318     # Ubuntu must come before Debian.
    319     elif $string_in_file Ubuntu /etc/lsb-release; then  # Ubuntu before Debian
    320         GET_KERN_PACKAGE="$FIND_KERNEL_DEB"
    321         PATTERN_GCC_MAKE='apt-get\ install\ gcc\ make'
    322         if kernel_version_lt "$KERN_VER_BASE" '2.6.9'; then
    323             PATTERN_HEADERS='apt-get\ install\ ${KERN_PACKAGE_BASE%-image*}-headers-$KERN_VER_SHORT$KERN_VER'
    324             PATTERN_HEADERS_META='apt-get\ install\ ${KERN_PACKAGE_BASE%-image*}-headers-$KERN_VER_SHORT$KERN_DEBIAN_SUFFIX'
    325         else
    326             PATTERN_HEADERS='apt-get\ install\ ${KERN_PACKAGE_BASE%-image*}-headers-$KERN_VER'
    327             PATTERN_HEADERS_META='apt-get\ install\ ${KERN_PACKAGE_BASE%-image*}-headers$KERN_DEBIAN_SUFFIX'
    328         fi
    329     elif $file_exists /etc/debian_version; then  # Debian family
    330         GET_KERN_PACKAGE="$FIND_KERNEL_DEB"
    331         PATTERN_GCC_MAKE='apt-get\ install\ gcc\ make'
    332         if kernel_version_lt "$KERN_VER_BASE" '2.4.17'; then
    333             PATTERN_HEADERS='apt-get\ install\ ${KERN_PACKAGE_BASE%-image*}-headers-$KERN_VER'
    334             PATTERN_HEADERS_META=
    335         elif kernel_version_lt "$KERN_VER_BASE" '3.0.0'; then
    336             PATTERN_HEADERS='apt-get\ install\ ${KERN_PACKAGE_BASE%-image*}-headers-$KERN_VER'
    337             PATTERN_HEADERS_META='apt-get\ install\ ${KERN_PACKAGE_BASE%-image*}-headers-$KERN_VER_SHORT$KERN_DEBIAN_SUFFIX'
    338         else
    339             PATTERN_HEADERS='apt-get\ install\ ${KERN_PACKAGE_BASE%-image*}-headers-$KERN_VER'
    340             PATTERN_HEADERS_META='apt-get\ install\ ${KERN_PACKAGE_BASE%-image*}-headers$KERN_DEBIAN_SUFFIX'
    341         fi
    342     elif $file_exists /etc/gentoo-release; then  # Gentoo
    343         GET_KERN_PACKAGE=
    344         PATTERN_GCC_MAKE=
    345         PATTERN_HEADERS=
    346         PATTERN_HEADERS_META=
    347     elif $file_exists /etc/lfs-release -a -d /etc/rc.d/init.d; then  # LFS
    348         GET_KERN_PACKAGE=
    349         PATTERN_GCC_MAKE=
    350         PATTERN_HEADERS=
    351         PATTERN_HEADERS_META=
    352     elif $file_exists /etc/slackware-version; then  # Slackware
    353         GET_KERN_PACKAGE=
    354         PATTERN_GCC_MAKE=
    355         PATTERN_HEADERS=
    356         PATTERN_HEADERS_META=
    357     elif $file_exists /etc/arch-release; then  # Arch Linux
    358         GET_KERN_PACKAGE=
    359         PATTERN_GCC_MAKE=
    360         PATTERN_HEADERS=
    361         PATTERN_HEADERS_META=
    362     else
    363         echo "Linux distribution base type not recognised."
     66HAVE_TOOLS=
     67HAVE_HEADERS=
     68PACKAGE_TYPE=
     69UNAME=
     70BASE_PACKAGE=
     71VERSIONED_PACKAGE=
     72TOOLS="gcc make perl"
     73TEST=
     74UNIT_TEST=
     75
     76case "${1}" in
     77"")
     78    # Return immediately successfully if everything is installed
     79    type ${TOOLS} >/dev/null 2>&1 && HAVE_TOOLS=yes
     80    test -d "/lib/modules/`uname -r`/build/include" && HAVE_HEADERS=yes
     81    test -n "${HAVE_TOOLS}" && test -n "${HAVE_HEADERS}" && exit 0
     82    UNAME=`uname -r`
     83    for i in rpm dpkg; do
     84        for j in /var/lib/${i}/*; do
     85            test -e "${j}" || break
     86            if test -z "${PACKAGE_TYPE}"; then
     87                PACKAGE_TYPE="${i}"
     88            else
     89                PACKAGE_TYPE=unknown
     90            fi
     91            break
     92        done
     93    done
     94    ;;
     95-h|--help)
     96    echo "${USAGE_MESSAGE}"
     97    exit 0 ;;
     98*)
     99    ERROR=""
     100    UNAME="${2}"
     101    PACKAGE_TYPE="${3}"
     102    BASE_EXPECTED="${4}"
     103    VERSIONED_EXPECTED="${5}"
     104    test "${1}" = --test || ERROR=yes
     105    test -n "${UNAME}" && test -n "${PACKAGE_TYPE}" || test -z "${UNAME}" ||
     106        ERROR=yes
     107    test -n "${BASE_EXPECTED}" && test -n "${VERSIONED_EXPECTED}" ||
     108        test -z "${BASE_EXPECTED}" || ERROR=yes
     109    case "${ERROR}" in ?*)
     110        echo "${USAGE_MESSAGE}" >&2
     111        exit 1
     112    esac
     113    TEST=yes
     114    TEST_PARAMS="${2} ${3} ${4} ${5}"
     115    test -z "${UNAME}" && UNIT_TEST=yes
     116    ;;
     117esac
     118
     119case "${PACKAGE_TYPE}" in
     120rpm)
     121    for i in ${SUSE_FLAVOURS}; do
     122        case "${UNAME}" in *-"${i}")
     123            BASE_PACKAGE="kernel-${i}-devel"
     124            VERSIONED_PACKAGE="kernel-${i}-devel-${UNAME%-${i}}"
     125            break
     126        esac
     127    done
     128    for i in ${EL_FLAVOURS} ""; do
     129        case "${UNAME}" in *.el5"${i}"|*.el*"${i}".i686|*.el*"${i}".x86_64)
     130            test -n "${i}" && i="${i}-"  # Hack to handle empty flavour.
     131            BASE_PACKAGE="kernel-${i}devel"
     132            VERSIONED_PACKAGE="kernel-${i}devel-${UNAME}"
     133            break
     134        esac
     135    done
     136    case "${UNAME}" in *.fc*.i686|*.fc*.x86_64)  # Fedora
     137        BASE_PACKAGE="kernel-devel"
     138        VERSIONED_PACKAGE="kernel-devel-${UNAME}"
     139    esac
     140    for i in ${MAGEIA_FLAVOURS} ""; do  # Mageia
     141        case "${UNAME}" in *-"${i}"*.mga*)
     142            if test -z "${i}"; then
     143                BASE_PACKAGE="kernel-linus-devel"
     144                VERSIONED_PACKAGE="kernel-linus-devel-${UNAME}"
     145            else
     146                BASE_PACKAGE="kernel-${i}-devel"
     147                VERSIONED_PACKAGE="kernel-${i}-devel-${UNAME%-${i}*}${UNAME#*${i}}"
     148            fi
     149            break
     150        esac
     151    done
     152    ;;
     153dpkg)
     154    for i in ${DEBIAN_FLAVOURS}; do  # Debian/Ubuntu
     155        case "${UNAME}" in *-${i})
     156            BASE_PACKAGE="linux-headers-${i}"
     157            VERSIONED_PACKAGE="linux-headers-${UNAME}"
     158            break
     159        esac
     160    done
     161    case "${UNAME}" in *-pclos*)  # PCLinuxOS
     162        BASE_PACKAGE="kernel-devel"
     163        VERSIONED_PACKAGE="kernel-devel-${UNAME}"
     164    esac
     165esac
     166
     167case "${UNIT_TEST}${BASE_EXPECTED}" in "")
     168    echo "This system is currently not set up to build kernel modules." >&2
     169    test -n "${HAVE_TOOLS}" ||
     170        echo "Please install the ${TOOLS} packages from your distribution." >&2
     171    test -n "${HAVE_HEADERS}" && exit 1
     172    echo "You will also need to install the right \"header\" files for adding hardware" >&2
     173    echo "support to the running Linux kernel." >&2
     174    if test -n "${BASE_PACKAGE}${VERSIONED_PACKAGE}"; then
     175        echo "The distribution packages containing the headers are probably:" >&2
     176        echo "    ${BASE_PACKAGE} ${VERSIONED_PACKAGE}"
     177    fi
     178    test -z "${TEST}" && exit 1
     179    exit 0
     180esac
     181
     182case "${BASE_EXPECTED}" in ?*)
     183    case "${BASE_EXPECTED} ${VERSIONED_EXPECTED}" in
     184        "${BASE_PACKAGE} ${VERSIONED_PACKAGE}")
    364185        exit 0
    365     fi
    366 }
    367 
    368 
    369 ## Determine the commands needed to install gcc, make and the kernel headers on
    370 #  the current system.
    371 #  @param INSTALL_GCC_MAKE      [out] Command to install gcc and make.
    372 #  @param INSTALL_HEADERS       [out] Command to install gcc and make.
    373 #  @param INSTALL_HEADERS_META  [out] Command to install a dependency on the
    374 #                                     current kernel headers.  May be empty.
    375 generate_install_commands()
    376 {
    377     get_kernel_information
    378     get_system_information
    379     case "$GET_KERN_PACKAGE" in
    380     ?*)
    381         eval $GET_KERN_PACKAGE
    382         ;;
    383     "")
    384         echo "Unable to determine the software packaging system in use."
    385         exit 0
    386         ;;
    387     esac
    388     # Needed for many installers
    389     KERN_PACKAGE_BASE="${KERN_PACKAGE%%$KERN_VER_BASE*}"
    390     KERN_RPM_SUFFIX="${KERN_PACKAGE#"$KERN_PACKAGE_BASE"}"
    391     KERN_DEBIAN_SUFFIX="$(expr "$KERN_VER_EXTRA" : '-[^-]*\(.*\)')"
    392     INSTALL_GCC_MAKE=$(eval echo "$PATTERN_GCC_MAKE")
    393     INSTALL_HEADERS=$(eval echo "$PATTERN_HEADERS")
    394     INSTALL_HEADERS_META=$(eval echo "$PATTERN_HEADERS_META")
    395 }
    396 
    397 
    398 test_generate_install_commands()
    399 {
    400     get_kernel_version=test_get_kernel_version
    401     file_exists=test_file_exists
    402     string_in_file=test_file_exists
    403     exit=test_exit
    404     do_type=test_type
    405     find_rpm_for_file=test_find_rpm_for_file
    406     find_deb_for_file=test_find_deb_for_file
    407     for i in \
    408         "1: test_uname_r=2.4.21-50.EL test_test_f=/etc/redhat-release test_type_binary=yum test_rpm_q=kernel-2.4.21-50.EL test_dpkg_s= =>INSTALL_GCC_MAKE=yum\ install\ gcc\ make INSTALL_HEADERS=yum\ install\ kernel-source-2.4.21-50.EL INSTALL_HEADERS_META=yum\ install\ kernel-source" \
    409         "2: test_uname_r=2.6.34-12-default test_test_f=/etc/SuSE-release test_rpm_q=kernel-default-2.6.34-12.3 =>INSTALL_GCC_MAKE=zypper\ install\ gcc\ make INSTALL_HEADERS=zypper\ install\ kernel-default-devel-2.6.34-12.3 INSTALL_HEADERS_META=zypper\ install\ kernel-default-devel" \
    410         "3: test_uname_r=2.6.8.1-12mdkenterprise test_test_f=/etc/mandrake-release test_rpm_q=kernel-enterprise-2.6.8.1.12mdk-1-1mdk test_dpkg_s= =>INSTALL_GCC_MAKE=urpmi\ gcc\ make INSTALL_HEADERS=urpmi\ kernel-source-stripped-2.6-2.6.8.1 INSTALL_HEADERS_META=urpmi\ kernel-source-stripped-2.6" \
    411         "4: test_uname_r=2.6.26-2-686 test_test_f=/etc/debian_version test_rpm_q= test_dpkg_s=linux-image-2.6.26-2-686:\ /lib/modules/2.6.26-2-686/kernel =>INSTALL_GCC_MAKE=apt-get\ install\ gcc\ make INSTALL_HEADERS=apt-get\ install\ linux-headers-2.6.26-2-686 INSTALL_HEADERS_META=apt-get\ install\ linux-headers-2.6-686" \
    412         "5: test_uname_r=3.0.0-15-generic test_string_grep=Ubuntu test_string_file=/etc/lsb-release test_rpm_q= test_dpkg_s=linux-image-3.0.0-15-generic:\ /lib/modules/3.0.0-15-generic/kernel =>INSTALL_GCC_MAKE=apt-get\ install\ gcc\ make INSTALL_HEADERS=apt-get\ install\ linux-headers-3.0.0-15-generic INSTALL_HEADERS_META=apt-get\ install\ linux-headers-generic" \
    413         "6: test_uname_r=2.4.16-686-smp test_test_f=/etc/debian_version test_rpm_q= test_dpkg_s=kernel-image-2.4.16-686-smp =>INSTALL_GCC_MAKE=apt-get\ install\ gcc\ make INSTALL_HEADERS=apt-get\ install\ kernel-headers-2.4.16-686-smp INSTALL_HEADERS_META=" \
    414         "7: test_uname_r=2.6.38.8-desktop-9.mga test_test_f=/etc/mandrake-release test_rpm_q=kernel-desktop-2.6.38.8-9.mga-1-1.mga1 test_dpkg_s= =>INSTALL_GCC_MAKE=urpmi\ gcc\ make INSTALL_HEADERS=urpmi\ kernel-desktop-devel-2.6.38.8-9.mga-1-1.mga1 INSTALL_HEADERS_META=urpmi\ kernel-desktop-devel-latest" \
    415         "8: test_uname_r=2.6.17-13mdv test_test_f=/etc/mandrake-release test_rpm_q=kernel-2.6.17.13mdv-1-1mdv2007.1 test_dpkg_s= =>INSTALL_GCC_MAKE=urpmi\ gcc\ make INSTALL_HEADERS=urpmi\ kernel-source-stripped-2.6.17.13mdv-1-1mdv2007.1 INSTALL_HEADERS_META=urpmi\ kernel-source-stripped-latest" \
    416         "9: test_uname_r=2.6.27.7-9-default test_test_f=/etc/SuSE-release test_rpm_q=kernel-default-base-2.6.27.7-9.1\ kernel-default-2.6.27.7-9.1\ kernel-default-extra-2.6.27.7-9.1 test_dpkg_s= =>INSTALL_GCC_MAKE=zypper\ install\ gcc\ make INSTALL_HEADERS=zypper\ install\ kernel-source-2.6.27.7-9.1\ kernel-syms-2.6.27.7-9.1 INSTALL_HEADERS_META=zypper\ install\ kernel-source\ kernel-syms" \
    417         "10: test_exit_return= test_test_f=/etc/Windows-release =>test_exit_return=1"
    418     do eval_test_line "$i" "generate_install_commands 2> /dev/null"; done
    419 }
    420 
    421 self_tests="$self_tests test_generate_install_commands"
    422 
    423 
    424 ## Check whether gcc, make and the kernel headers are installed on the system.
    425 # @param MISSING_GCC     [out]  non-empty if make needs to be installed.
    426 #                               @todo Should we check the version of gcc?
    427 # @param MISSING_MAKE    [out]  non-empty if make needs to be installed.
    428 # @param MISSING_HEADERS [out]  non-empty if kernel headers need to be
    429 #                               installed.
    430 check_missing_packages()
    431 {
    432     if $do_type gcc >/dev/null 2>&1; then
    433         MISSING_GCC=
    434     else
    435         MISSING_GCC=gcc
    436     fi
    437     if $do_type make >/dev/null 2>&1; then
    438         MISSING_MAKE=
    439     else
    440         MISSING_MAKE=make
    441     fi
    442     # The following test looks valid on all distributions I have checked so
    443     # far.
    444     MISSING_HEADERS=$($file_exists "$KERN_DIR"/build/Makefile || echo headers)
    445 }
    446 
    447 
    448 case "$1" in livetest) LIVE_TEST=true ;; *) LIVE_TEST= ;; esac
    449 case "$1" in
    450 test)
    451     for i in $self_tests; do $i; done ;;
    452 *)
    453     set_up_helpers
    454     get_kernel_information
    455     check_missing_packages
    456     case "$MISSING_GCC$MISSING_MAKE$MISSING_HEADERS$LIVE_TEST" in "")
    457         exit 0
    458     esac
    459     generate_install_commands
    460     case "$1" in install)
    461         check_root
    462         $INSTALL_GCC_MAKE || abort "Unable to install tools for building kernel modules."
    463         case "$INSTALL_HEADERS_META" in
    464         "")
    465             $INSTALL_HEADERS || abort "Unable to install files needed to build modules for the current kernel." ;;
    466         *)
    467             $INSTALL_HEADERS || printf >&2 "Unable to install files needed to build modules for the current kernel.\nYou may need to restart your system to complete the installation."
    468             $INSTALL_HEADERS_META || abort "Unable to install files needed to build kernel modules."
    469         esac
    470         ;;
    471     *)
    472         echo "This system is not currently set up to build kernel modules (system extensions)."
    473         echo "Running the following commands should set the system up correctly:"
    474         echo
    475         case "$MISSING_GCC$MISSING_MAKE$LIVE_TEST" in ?*)
    476             echo "  $INSTALL_GCC_MAKE" ;;
    477         esac
    478         case "$MISSING_HEADERS$LIVE_TEST" in ?*)
    479             echo "  $INSTALL_HEADERS"
    480             echo "(The last command may fail if your system is not fully updated.)"
    481             case "$INSTALL_HEADERS_META" in ?*)
    482                 echo "  $INSTALL_HEADERS_META" ;;
    483             esac
    484             ;;
    485         esac
    486         exit 1
    487         ;;
    488     esac
    489     ;;
    490 esac
     186    esac
     187    echo "Test: ${TEST_PARAMS}" >&2
     188    echo "Result: ${BASE_PACKAGE} ${VERSIONED_PACKAGE}"
     189    exit 1
     190esac
     191
     192# Unit test as of here.
     193# Test expected correct results.
     194for i in \
     195    "4.1.12-37.5.1.el6uek.x86_64 rpm kernel-uek-devel kernel-uek-devel-4.1.12-37.5.1.el6uek.x86_64" \
     196    "2.6.32-642.el6.x86_64 rpm kernel-devel kernel-devel-2.6.32-642.el6.x86_64" \
     197    "4.1.12-vanilla rpm kernel-vanilla-devel kernel-vanilla-devel-4.1.12" \
     198    "4.8.8-pclos1 dpkg kernel-devel kernel-devel-4.8.8-pclos1" \
     199    "4.8.8-desktop-1.mga6 rpm kernel-desktop-devel kernel-desktop-devel-4.8.8-1.mga6" \
     200    "3.19.8-2.mga5 rpm kernel-linus-devel kernel-linus-devel-3.19.8-2.mga5" \
     201    "4.8.0-27-generic dpkg linux-headers-generic linux-headers-4.8.0-27-generic"
     202do
     203    "${0}" --test ${i} || exit 1
     204done
     205
     206# Test argument combinations expected to fail.
     207for i in \
     208    "--test NOT_EMPTY" \
     209    "--test NOT_EMPTY NOT_EMPTY NOT_EMPTY" \
     210    "--wrong" \
     211    "--test 4.8.8-pclos1 dpkg kernel-devel kernel-devel-WRONG" \
     212    "--test 4.8.8-pclos1 dpkg kernel-WRONG kernel-devel-4.8.8-pclos1"
     213do
     214    "${0}" ${i} >/dev/null 2>&1 && echo "Bad argument test failed:" &&
     215        echo "  ${i}" && exit 1
     216done
     217exit 0
  • trunk/src/VBox/Installer/linux/vboxdrv.sh

    r63757 r64716  
    394394        --module-source "$MODULE_SRC/vboxdrv" \
    395395        --no-print-directory install >> $LOG 2>&1; then
    396         "${INSTALL_DIR}/check_module_dependencies.sh"
     396        "${INSTALL_DIR}/check_module_dependencies.sh" || exit 1
    397397        failure "Look at $LOG to find out what went wrong"
    398398    fi
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette