]>
Commit | Line | Data |
---|---|---|
3266a355 | 1 | #! /bin/bash |
cdd7ce2e | 2 | LANG=C; export LANG |
a17088d1 | 3 | check_error() { if test $1 != 0; then printf "\n$2\n"; 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 | |
b6b9b54b FCE |
27 | if [ -x /usr/bin/dnf ]; then |
28 | DI="dnf debuginfo-install" | |
29 | DI_DEPS="" | |
30 | D="dnf" | |
31 | else | |
32 | DI="debuginfo-install" | |
33 | DI_DEPS="yum-utils" | |
34 | D="yum" | |
35 | fi | |
ca8bf77e WC |
36 | CANDIDATES="$KERNEL-$KERN_REV.$KERN_ARCH \ |
37 | $KERNEL-devel-$KERN_REV.$KERN_ARCH \ | |
b6b9b54b | 38 | $DI_DEPS \ |
928c149c | 39 | $KERNEL-debuginfo-$KERN_REV.$KERN_ARCH" |
ca8bf77e WC |
40 | NEEDED=`rpm --qf "%{name}-%{version}-%{release}.%{arch}\n" \ |
41 | -q $CANDIDATES | grep "is not installed" | awk '{print $2}'` | |
3266a355 WC |
42 | if [ "$NEEDED" != "" ]; then |
43 | echo -e "Need to install the following packages:\n$NEEDED" | |
fb3db0ca | 44 | if [ `id -u` = "0" ]; then #attempt to install |
b6b9b54b | 45 | $D install -y --enablerepo=\* $NEEDED |
0513bfe0 | 46 | if expr "$NEEDED" : ".*debuginfo.*" >/dev/null; |
a17088d1 | 47 | then |
b6b9b54b | 48 | $DI -y $KERNEL-$KERN_REV.$KERN_ARCH; |
0513bfe0 | 49 | fi |
fb3db0ca | 50 | rpm -q $NEEDED |
a17088d1 | 51 | rc=$? |
b6b9b54b | 52 | check_error $rc "problem installing rpm(s) $NEEDED\nin case of file conflicts, try again after # $D erase $KERNEL-debuginfo" |
3266a355 WC |
53 | fi |
54 | fi | |
74f5df1a TJL |
55 | } |
56 | ||
67862af5 TJL |
57 | prep_deb_based() { |
58 | if [ $# -ne 0 ]; then | |
59 | echo "Specifying kernel version is not yet support on deb based systems." 1>&2 | |
60 | exit 1 | |
61 | fi | |
62 | ||
63 | # 2.6.32-5-amd64 | |
64 | # 2.6.32-37-generic | |
65 | ABINAME="$(cut -d " " -f 3 /proc/version)" | |
66 | ||
67 | # 2.6.32 | |
68 | BASEVERSION="$(echo "$ABINAME" | cut -d "-" -f 1)" | |
69 | ||
70 | case "$DISTRO" in | |
71 | Debian) # 2.6.32-39 | |
72 | if uname -v | grep -q Debian; then | |
73 | VERSION="$(uname -v | cut -d " " -f 4)" | |
74 | else | |
de25b7bb | 75 | VERSION="$(cut -d " " -f 3 /proc/version)" |
67862af5 TJL |
76 | fi |
77 | ;; | |
78 | Ubuntu) | |
79 | # 2.6.32-37.81 | |
dd1f4360 FCE |
80 | if [ -f /proc/version_signature ]; then |
81 | VERSION="$(cut -d " " -f 2 /proc/version_signature | cut -d "-" -f 1-2)" | |
82 | else # 4.18 | |
83 | VERSION="$(cut -d " " -f 3 /proc/version)" | |
84 | fi | |
67862af5 TJL |
85 | ;; |
86 | esac | |
87 | ||
88 | ( | |
89 | echo "make >= 0" | |
90 | echo "linux-image-$ABINAME = $VERSION" | |
91 | echo "linux-headers-$ABINAME = $VERSION" | |
eea974ac | 92 | echo "linux-image-$ABINAME-dbgsym = $VERSION" |
67862af5 TJL |
93 | ) | while read package relation requiredversion; do |
94 | installedversion="$(dpkg-query -W "$package" 2> /dev/null | cut -f 2)" | |
95 | if [ "$installedversion" = "" ]; then | |
96 | availableversion="$(apt-cache show $package 2> /dev/null | grep ^Version: | cut -d " " -f 2)" | |
eea974ac | 97 | if [ "$availableversion" = "" -a "$(echo $package | grep dbgsym$)" ]; then |
67862af5 | 98 | echo "You need package $package but it does not seem to be available" |
eea974ac | 99 | if [ "$DISTRO" = "Ubuntu" ]; then |
67862af5 TJL |
100 | echo " Ubuntu -dbgsym packages are typically in a separate repository" |
101 | echo " Follow https://wiki.ubuntu.com/DebuggingProgramCrash to add this repository" | |
eea974ac RRS |
102 | elif [ "$DISTRO" = "Debian" ]; then |
103 | echo " Debian -dbgsym packages are typically in a separate repository" | |
104 | echo " Follow https://wiki.debian.org/AutomaticDebugPackages to add this repository" | |
67862af5 TJL |
105 | fi |
106 | else | |
7b76b6b6 FCE |
107 | echo "Need to install $package" |
108 | if [ `id -u` = "0" ]; then #attempt to install | |
53ff2b5d | 109 | apt-get -y install $package |
7b76b6b6 | 110 | fi |
67862af5 TJL |
111 | fi |
112 | elif ! dpkg --compare-versions $installedversion $relation $requiredversion; then | |
113 | echo "Package $package version $installedversion does not match version of currently running kernel: $requiredversion" | |
114 | echo " Consider apt-get upgrade && reboot" | |
115 | fi | |
116 | done | |
117 | ||
118 | user="$(id --user --name)" | |
119 | if [ "$user" != "root" ]; then | |
120 | groups="$(id --groups --name)" | |
121 | for i in stapusr stapdev; do | |
122 | if [ "$(echo $groups | grep $i)" = "" ]; then | |
123 | echo "Be root or adduser $user $i" | |
124 | fi | |
125 | done | |
126 | fi | |
127 | } | |
128 | ||
74f5df1a TJL |
129 | DISTRO="$(lsb_release --id --short 2> /dev/null)" |
130 | if [ $? -ne 0 ]; then | |
131 | DISTRO="unknown" | |
132 | fi | |
133 | case "$DISTRO" in | |
67862af5 TJL |
134 | Debian|Ubuntu) |
135 | prep_deb_based "$@" | |
136 | ;; | |
74f5df1a TJL |
137 | *) |
138 | prep_rpm_based "$@" | |
139 | ;; | |
140 | esac |