📄 kernel.guess
字号:
#!/bin/shRHEL5_KERNEL_BASE="/usr/src/kernels"## This is a simple mapping of architectures to kernel flavors. One# entry per architecture, <arch>:<flavor1>[,<flavor> ...]## This is used when detecting kernels to build packages for. A kernel# is only built if build trees for all flavors are installed.## Unique to redhat, empty types (the 'default' kernel) are allowed.# Be careful parsing this!## Fedora Core only has one type of kernel. It's always SMP. So we have# a very simple type list :-)#RHEL5_KERNEL_TYPES=" i686:,PAE,xen,debug x86_64:,xen,debug ia64:,xen,debug ppc64:,debug s390x:,debug"guess_rhel5_arch(){ # This appears to DTRT (i686 on x86, ppc64 on pSeries). uname -m}guess_rhel5_type(){ # Only one type for rhel5 case "$1" in *PAE) echo "PAE" ;; *xen) echo "xen" ;; *debug) echo "debug" ;; *) echo "" ;; esac}guess_rhel5_dir(){ KVER="$1" DIRTYPE=$(guess_rhel5_type "$KVER") ARCH=$(guess_rhel5_arch) if [ -z "$DIRTYPE" ] then echo "${1%${DIRTYPE}}-${ARCH}" else echo "${1%${DIRTYPE}}-${DIRTYPE}-${ARCH}" fi}verfromdir(){ TESTDIR="$1" if [ -r "${TESTDIR}/include/linux/utsrelease.h" ] then awk '/UTS_RELEASE/{gsub(/"/,"",$3); print $3}' "${TESTDIR}/include/linux/utsrelease.h" fi}validate_dir(){ KVER="$1" DIR="$2" if [ ! -d "${RHEL5_KERNEL_BASE}/${DIR}" ] then return 1 elif [ ! -f "${RHEL5_KERNEL_BASE}/${DIR}/include/linux/autoconf.h" ] then return 1 elif [ ! -f "${RHEL5_KERNEL_BASE}/${DIR}/include/linux/version.h" ] then return 1 fi if [ "$KVER" != "$(verfromdir "${RHEL5_KERNEL_BASE}/${DIR}")" ] then return 1 fi return 0}# Takes a `uname -r` and returns "ver type", where ver# is 2.6.9-NN.EL and type is "smp" or the like.validate_version(){ KVER="$1" dir=$(guess_rhel5_dir "$KVER") if validate_dir "$KVER" "$dir" then echo "${RHEL5_KERNEL_BASE}/${dir}" fi}find_version(){ # Find the most recent valid kernel ls -1 -t "$RHEL5_KERNEL_BASE" | while read kdir do KVER="$(verfromdir "${RHEL5_KERNEL_BASE}/${kdir}")" if validate_dir "$KVER" "$kdir" then echo "${RHEL5_KERNEL_BASE}/${kdir}" break fi done}# For a given KVER, see if all the -devel packages existvalidate_target(){ KVER="$1" ARCH="$2" TYPELIST="$3" SUBVER="${KVER#2.6.18-}" SUBVER="${SUBVER%%.*}" # Red Hat introduced the "debug" type in 53.el5. Anything older can ignore it. if [ $SUBVER -lt 53 ] then TYPELIST="${TYPELIST%,debug}" fi typelist="${TYPELIST#$ARCH:}" while : do type="${typelist%%,*}" VERDIR="$(validate_version ${KVER}${type})" if [ -z "$VERDIR" ] then return 1 fi # This loop walks the list of types being careful of the empty # typename tmp="${typelist#*,}" if [ -z "$tmp" -o "$tmp" = "$typelist" ] then break fi typelist="$tmp" done return 0}find_targets(){ # Pre-calculate ARCH and TYPELIST, at least ARCH="$(guess_rhel5_arch)" if [ -z "$ARCH" ] then return fi TYPELIST= for typelist in $RHEL5_KERNEL_TYPES do TARCH=$(echo "$typelist" | cut -f1 -d:) if [ "$TARCH" = "$ARCH" ] then TYPELIST="$typelist" break fi done if [ -z "$TYPELIST" ] then return fi ls -1 -t "$RHEL5_KERNEL_BASE" | while read kdir do KVER="$(verfromdir "${RHEL5_KERNEL_BASE}/${kdir}")" if ! validate_dir "$KVER" "$kdir" then continue fi if validate_target "$KVER" "$ARCH" "$TYPELIST" then echo "rhel5_${KVER}_rpm" fi done}case "$1" ininclude|build) if [ -n "$2" ] then KPATH="$(validate_version "$2")" else KVER="$(uname -r)" KPATH="$(validate_version "$KVER")" if [ -z "$KPATH" ] then KPATH="$(find_version)" fi fi if [ -n "$KPATH" ] then if [ "$1" = "include" ] then KPATH="${KPATH}/include" fi echo "${KPATH}" fi ;;targets) find_targets ;;"") echo "Missing operation" >&2 ;;*) echo "Invalid operation: $1" >&2 exit 1 ;;esac
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -