1#!/bin/sh -ex
2
3conf=${1}
4arch=$(uname -m)
5kver=$(uname -r)
6
7. "${conf}"
8
9echo "Verify Kernel version >= 2.6.16."
10# Kernel might in the following format.
11# x.y.z-1.el
12# x.y.z.1.el
13kx=${kver%%.*}
14tmp=${kver#*.}
15ky=${tmp%%.*}
16tmp=${tmp#*.}
17tmp=${tmp%%.*}
18kz=${tmp%%-*}
19
20if [ "${kx}" -lt 2 ]; then
21    error=1
22
23elif [ "${kx}" -eq 2 ]; then
24    if [ "${ky}" -lt 6 ]; then
25        error=1
26
27    elif [ "${ky}" -eq 6 ]; then
28        if [ "${kz}" -lt 16 ]; then
29            error=1
30        fi
31    fi
32fi
33
34if [ "${error}" ]; then
35    echo "Fail: kernel version ${kver} is less than 2.6.16."
36fi
37
38
39echo "Verify user is root."
40if [ $(id -u) != 0 ]; then
41    echo "Fail: root is required."
42    error=1
43fi
44
45
46echo "Verify prerequisite."
47if [ ! -x "/sbin/kexec" ]; then
48    echo "Fail: kexec-tools not found."
49    error=1
50fi
51
52if [ ! -d "/lib/modules/${kver}/build" ]; then
53    echo "Fail: kernel-devel not found."
54    error=1
55fi
56
57if [ "${CRASH}" ] && [ "${CRASH}" -eq 1 ]; then
58    if [ ! -x "/usr/bin/crash" ]; then
59        echo "Fail: crash not found."
60        error=1
61    fi
62
63    if [ ! -f "${VMLINUX}" ]; then
64        echo "Fail: kernel-debuginfo not found."
65        error=1
66    fi
67fi
68
69# Final result.
70if [ "${error}" ]; then
71    echo "Please fixed the above failures before continuing."
72    exit 1
73fi
74
75echo "Compile Kernel modules."
76make clean
77
78# Test if struct kprobe has "symbol_name" field.
79if make -C kprobes >/dev/null 2>&1; then
80    export USE_SYMBOL_NAME=1
81fi
82
83make
84
85echo "Modify Boot Loader."
86if [ "${arch}" = "ppc64" ]; then
87    args="crashkernel=256M@32M xmon=off"
88elif [ "${arch}" = "i686" ]; then
89    args="crashkernel=256M@128M nmi_watchdog=1"
90elif [ "${arch}" = "ia64" ]; then
91    args="crashkernel=512M@256M"
92else
93    args="crashkernel=256M@128M"
94fi
95
96if [ -x "/sbin/grubby" ]; then
97    /sbin/grubby --default-kernel |
98     xargs /sbin/grubby --args="${args}" --update-kernel
99
100else
101    echo "Warn: please make sure the following arguments are in Boot\
102 Loader:"
103    echo "$args"
104    echo "Hit any key when ready."
105    read
106fi
107
108exit 0
109