]>
Commit | Line | Data |
---|---|---|
3266a355 | 1 | #! /bin/bash |
cdd7ce2e | 2 | LANG=C; export LANG |
3266a355 | 3 | check_error() { if test $1 != 0; then echo $2; exit $1; fi } |
3266a355 | 4 | |
74f5df1a | 5 | prep_rpm_based() { |
6f6a731f MW |
6 | # uname -r can produce different kinds of output: |
7 | # 2.6.32-30.el6.x86_64 (no variant, but including ".arch") | |
8 | # 2.6.18-194.3.1.el5debug ("variant", without dot, no arch) | |
9 | # 2.6.33.4-95.fc13.i686.PAE (".arch.variant", two dots) | |
ab9ec3fb | 10 | # 3.18.6-100.fc20.i686+PAE (".arch+variant", dot, plus) |
3266a355 WC |
11 | if [ "$#" -lt 1 ]; then |
12 | UNAME=`uname -r` # determine the kernel running on the machine | |
13 | else | |
14 | UNAME=$1 #user passed in uname value | |
15 | fi | |
16 | UNAME=`echo $UNAME | sed "s/ //"` #strip out any whitespace | |
17 | KERNEL="kernel" | |
18 | for VARIANT in debug kdump PAE xen; do | |
ab9ec3fb MC |
19 | # strip out ".variant" or else "+variant" or else "variant" at end. |
20 | TMP=`echo $UNAME | sed "s/[\.\+]\?$VARIANT\$//"` | |
3266a355 WC |
21 | if [ "$TMP" != "$UNAME" ]; then |
22 | UNAME=$TMP; KERNEL="kernel-$VARIANT" | |
23 | fi | |
24 | done | |
25 | KERN_ARCH=`uname -m` | |
26 | KERN_REV=`echo $UNAME | sed s/.$KERN_ARCH//` # strip arch from uname | |
ca8bf77e WC |
27 | CANDIDATES="$KERNEL-$KERN_REV.$KERN_ARCH \ |
28 | $KERNEL-devel-$KERN_REV.$KERN_ARCH \ | |
928c149c | 29 | $KERNEL-debuginfo-$KERN_REV.$KERN_ARCH" |
ca8bf77e WC |
30 | NEEDED=`rpm --qf "%{name}-%{version}-%{release}.%{arch}\n" \ |
31 | -q $CANDIDATES | grep "is not installed" | awk '{print $2}'` | |
3266a355 WC |
32 | if [ "$NEEDED" != "" ]; then |
33 | echo -e "Need to install the following packages:\n$NEEDED" | |
fb3db0ca MC |
34 | if [ `id -u` = "0" ]; then #attempt to install |
35 | yum install -y --enablerepo=\* $NEEDED | |
36 | rpm -q $NEEDED | |
ca8bf77e | 37 | check_error $? "problem installing rpm(s) $NEEDED" |
3266a355 WC |
38 | fi |
39 | fi | |
74f5df1a TJL |
40 | } |
41 | ||
67862af5 TJL |
42 | prep_deb_based() { |
43 | if [ $# -ne 0 ]; then | |
44 | echo "Specifying kernel version is not yet support on deb based systems." 1>&2 | |
45 | exit 1 | |
46 | fi | |
47 | ||
48 | # 2.6.32-5-amd64 | |
49 | # 2.6.32-37-generic | |
50 | ABINAME="$(cut -d " " -f 3 /proc/version)" | |
51 | ||
52 | # 2.6.32 | |
53 | BASEVERSION="$(echo "$ABINAME" | cut -d "-" -f 1)" | |
54 | ||
55 | case "$DISTRO" in | |
56 | Debian) # 2.6.32-39 | |
57 | if uname -v | grep -q Debian; then | |
58 | VERSION="$(uname -v | cut -d " " -f 4)" | |
59 | else | |
60 | VERSION="$(cut -d " " -f 5 /proc/version | cut -d ")" -f 1)" | |
61 | fi | |
62 | ;; | |
63 | Ubuntu) | |
64 | # 2.6.32-37.81 | |
65 | VERSION="$(cut -d " " -f 2 /proc/version_signature | cut -d "-" -f 1-2)" | |
66 | ;; | |
67 | esac | |
68 | ||
69 | ( | |
70 | echo "make >= 0" | |
71 | echo "linux-image-$ABINAME = $VERSION" | |
72 | echo "linux-headers-$ABINAME = $VERSION" | |
67862af5 TJL |
73 | case "$DISTRO" in |
74 | Debian) | |
75 | echo "linux-image-$ABINAME-dbg = $VERSION" | |
76 | ;; | |
77 | Ubuntu) | |
78 | echo "linux-image-$ABINAME-dbgsym = $VERSION" | |
79 | ;; | |
80 | esac | |
81 | ) | while read package relation requiredversion; do | |
82 | installedversion="$(dpkg-query -W "$package" 2> /dev/null | cut -f 2)" | |
83 | if [ "$installedversion" = "" ]; then | |
84 | availableversion="$(apt-cache show $package 2> /dev/null | grep ^Version: | cut -d " " -f 2)" | |
85 | if [ "$availableversion" = "" ]; then | |
86 | echo "You need package $package but it does not seem to be available" | |
87 | if [ "$DISTRO" = "Ubuntu" -a "$(echo $package | grep dbgsym$)" ]; then | |
88 | echo " Ubuntu -dbgsym packages are typically in a separate repository" | |
89 | echo " Follow https://wiki.ubuntu.com/DebuggingProgramCrash to add this repository" | |
90 | elif [ "$DISTRO" = "Debian" -a "$(echo $package | grep dbg$)" ]; then | |
91 | echo " Debian does not have -dbg packages for all kernels. Consider switching to a kernel that has one." | |
92 | fi | |
93 | else | |
94 | echo "Please install $package" | |
95 | fi | |
96 | elif ! dpkg --compare-versions $installedversion $relation $requiredversion; then | |
97 | echo "Package $package version $installedversion does not match version of currently running kernel: $requiredversion" | |
98 | echo " Consider apt-get upgrade && reboot" | |
99 | fi | |
100 | done | |
101 | ||
102 | user="$(id --user --name)" | |
103 | if [ "$user" != "root" ]; then | |
104 | groups="$(id --groups --name)" | |
105 | for i in stapusr stapdev; do | |
106 | if [ "$(echo $groups | grep $i)" = "" ]; then | |
107 | echo "Be root or adduser $user $i" | |
108 | fi | |
109 | done | |
110 | fi | |
111 | } | |
112 | ||
74f5df1a TJL |
113 | DISTRO="$(lsb_release --id --short 2> /dev/null)" |
114 | if [ $? -ne 0 ]; then | |
115 | DISTRO="unknown" | |
116 | fi | |
117 | case "$DISTRO" in | |
67862af5 TJL |
118 | Debian|Ubuntu) |
119 | prep_deb_based "$@" | |
120 | ;; | |
74f5df1a TJL |
121 | *) |
122 | prep_rpm_based "$@" | |
123 | ;; | |
124 | esac |