📄 kernel.guess
字号:
#!/bin/shSLES9_KERNEL_BASE="/usr/src"## SLES9 has wacky names for its kernel flavors. So we'll just create# a list here of the mappings. It's pretty simple. One entry per# architecture, <arch>:<flavor1>[,<flavor> ...]## Anyway, we can even reuse this when detecting kernels to build# packages for. A kernel is only built if build trees for all flavors# are installed.#SLES9_KERNEL_TYPES=" x86_64:default,smp ppc64:pseries64,iseries64,pmac64 ia64:default,64k-pagesize,sn2 i386:default,smp,bigsmp s390:s390x" guess_sles9_arch(){ ARCH=$(uname -m) case "$ARCH" in i386|i586|i686) echo "i386" ;; s390x) echo "s390" ;; *) # This appears to be correct on ppc64 echo "$ARCH" ;; esac}guess_sles9_type(){ KVER="$1" ARCH="$(guess_sles9_arch)" if [ -z "$ARCH" ] then return fi for typelist in $SLES9_KERNEL_TYPES do TARCH=$(echo $typelist | cut -f1 -d:) if [ "$TARCH" = "$ARCH" ] then for type in $(echo $typelist | cut -f2 -d: | sed -e 's/,/ /g') do case "$KVER" in *-${type}) echo "$type" break ;; *) ;; esac done break fi done}guess_sles9_dir(){ KVER="$1" DIRTYPE=$(guess_sles9_type "$KVER") ARCH=$(guess_sles9_arch) if [ -n "$DIRTYPE" ] then echo "linux-${1%-${DIRTYPE}}-obj/${ARCH}/${DIRTYPE}" fi}## OCFS2 can only use SLES9 SP3 and newer#new_enough(){ KVER="$1" # # SLES9 versions look like # 2.6.5-7.<something>-<type # or # 2.6.5-7.<something>.<something else>-<type> # We only care about "something", which we'll call COUNTER # EXTPART="${KVER#2.6.5-}" EXTPART="${EXTPART%%-*}" SEVEN="${EXTPART%%.*}" EXTPART="${EXTPART#${SEVEN}.}" COUNTER="${EXTPART%%.*}" if [ -z "$SEVEN" -o "$SEVEN" -lt 7 ] then return 1 fi # SP3 is 7.244 if [ -z "$COUNTER" -o "$COUNTER" -lt 244 ] then return 1 fi return 0}verfromdir(){ TESTDIR="$1" if [ -r "${TESTDIR}/include/linux/version.h" ] then awk '/UTS_RELEASE/{gsub(/"/,"",$3); print $3}' "${TESTDIR}/include/linux/version.h" fi}validate_dir(){ KVER="$1" DIR="$2" if [ ! -d "${SLES9_KERNEL_BASE}/${DIR}" ] then return 1 elif [ ! -f "${SLES9_KERNEL_BASE}/${DIR}/include/linux/autoconf.h" ] then return 1 elif [ ! -f "${SLES9_KERNEL_BASE}/${DIR}/include/linux/version.h" ] then return 1 fi if [ "$KVER" != "`verfromdir "${SLES9_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" if ! new_enough "$KVER" 2>/dev/null then return fi dir=`guess_sles9_dir "$KVER"` if validate_dir "$KVER" "$dir" then echo "${SLES9_KERNEL_BASE}/${dir}" fi}find_version(){ ARCH="$(guess_sles9_arch)" if [ -z "$ARCH" ] then return fi types= for typelist in $SLES9_KERNEL_TYPES do TARCH=$(echo $typelist | cut -f1 -d:) if [ "$TARCH" = "$ARCH" ] then types=$(echo $typelist | cut -f2 -d: | sed -e 's/,/ /g') break fi done if [ -z "$types" ] then return fi # Find the most recent valid kernel ls -1 -t "$SLES9_KERNEL_BASE" | while read kdir do if [ -L "${SLES9_KERNEL_BASE}/${kdir}" -o ! -d "${SLES9_KERNEL_BASE}/${kdir}" ] then continue fi case "$kdir" in *-obj) ;; *) continue ;; esac KERNELDIR= for type in $types do KVER="`verfromdir "${SLES9_KERNEL_BASE}/${kdir}/${ARCH}/${type}"`" if validate_dir "$KVER" "$kdir/${ARCH}/${type}" then KERNELDIR="${SLES9_KERNEL_BASE}/${kdir}/${ARCH}/${type}" break fi done if [ -n "$KERNELDIR" ] then echo "$KERNELDIR" break fi done}validate_target(){ DIR="$1" ARCH="$2" types="$3" for type in $types do KVER="`verfromdir "${SLES9_KERNEL_BASE}/${kdir}/${ARCH}/${type}"`" if ! new_enough "$KVER" 2>/dev/null then return 1 fi if ! validate_dir "$KVER" "$kdir/${ARCH}/${type}" then return 1 fi done return 0}find_targets(){ ARCH="$(guess_sles9_arch)" if [ -z "$ARCH" ] then return fi types= for typelist in $SLES9_KERNEL_TYPES do TARCH=$(echo $typelist | cut -f1 -d:) if [ "$TARCH" = "$ARCH" ] then types=$(echo $typelist | cut -f2 -d: | sed -e 's/,/ /g') break fi done if [ -z "$types" ] then return fi ls -1 -t "$SLES9_KERNEL_BASE" | while read kdir do # Avoid the symlinks if [ -L "${SLES9_KERNEL_BASE}/${kdir}" -o ! -d "${SLES9_KERNEL_BASE}/${kdir}" ] then continue fi case "$kdir" in linux-*-obj) if validate_target "$kdir" "$ARCH" "$types" then KVER="${kdir#linux-}" KVER="${KVER%-obj}" if rpm -q "kernel-syms-${KVER}" 1>/dev/null 2>&1 then echo "sles9_${KVER}_rpm" fi fi ;; *) ;; esac 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 + -