]> sourceware.org Git - systemtap.git/blame - stap-prep
Update systemtap.base/cast.stp test to work with newer kernels
[systemtap.git] / stap-prep
CommitLineData
3266a355 1#! /bin/bash
39f95e37
FCE
2
3# This file is part of systemtap, and is free software. You can
4# redistribute it and/or modify it under the terms of the GNU General
5# Public License (GPL); either version 2, or (at your option) any
6# later version.
7
8
cdd7ce2e 9LANG=C; export LANG
0c5c0f43
FCE
10PATH=/usr/sbin:/sbin:/usr/bin:/bin:$PATH; export PATH
11
a17088d1 12check_error() { if test $1 != 0; then printf "\n$2\n"; exit $1; fi }
3266a355 13
705eae40
MC
14help()
15{
16 cat <<'EOF'
17Usage: stap-prep [OPTION]... [custom_uname]
18prepare system for systemtap use
19
20Options:
21[-q|--quiet]
22[-h|--help]
23[custom_uname]
24EOF
25}
26
27UNAME=`uname -r` # determine the kernel running on the machine
28
29# Suppress verbose output and progress indicators
30bequiet=false
31
32while [ $# -gt 0 ]; do
33 case "$1" in
34 -q|--quiet)
35 bequiet=true
36 ;;
37 -h|--help)
38 help
39 done=true
40 ;;
41 *)
42 UNAME=$1
43 shift
44 break
45 ;;
46 esac
47 shift
48done
49
50# help given
51if [ "$done" = "true" ]; then exit 0; fi
a708b90a 52
3266a355 53UNAME=`echo $UNAME | sed "s/ //"` #strip out any whitespace
a708b90a
FCE
54echo "Configuring for kernel release $UNAME"
55
56
57# See if the configured debuginfod
58DEBUGINFOD=0
59prep_debuginfod() {
294b7a53
FCE
60 # Choose a representative part - the vmlinuz file itself, which
61 # may be compressed-ELF or something else. Previously, used a
62 # vdso* image only, but that false-positive tricks stap-prep on
63 # aarch64/s390x, due to rhbz 1891509 / elfutils PR25498
64 vmlinuz=/lib/modules/$UNAME/vmlinuz
65
66 if [ -n "$DEBUGINFOD_URLS" ]; then
67 echo "Please wait, attempting to download $vmlinuz debuginfo"
68 if [ -z "$DEBUGINFOD_TIMEOUT" ]; then
69 DEBUGINFOD_TIMEOUT=300
70 export DEBUGINFOD_TIMEOUT
71 echo "Increasing DEBUGINFOD_TIMEOUT to $DEBUGINFOD_TIMEOUT temporarily"
72 fi
ae32a2cc
FCE
73 # DEBUGINFOD_PROGRESS=1
74 # export DEBUGINFOD_PROGRESS
294b7a53
FCE
75 if debuginfod-find debuginfo "$vmlinuz" > /dev/null; then
76 DEBUGINFOD=1
77 ls -ald `debuginfod-find debuginfo "$vmlinuz"`
78 echo "Download successful. Assuming debuginfod server usage."
79 else
80 echo "Download failed."
81 fi
82 else
b2d1fa19 83 echo 'Suggestion: consider configuring automatic debuginfo downloading via debuginfod.'
a708b90a
FCE
84 fi
85}
86
87
88prep_rpm_based() {
89# uname -r can produce different kinds of output:
90# 2.6.32-30.el6.x86_64 (no variant, but including ".arch")
91# 2.6.18-194.3.1.el5debug ("variant", without dot, no arch)
92# 2.6.33.4-95.fc13.i686.PAE (".arch.variant", two dots)
93# 3.18.6-100.fc20.i686+PAE (".arch+variant", dot, plus)
3266a355
WC
94KERNEL="kernel"
95for VARIANT in debug kdump PAE xen; do
ab9ec3fb
MC
96 # strip out ".variant" or else "+variant" or else "variant" at end.
97 TMP=`echo $UNAME | sed "s/[\.\+]\?$VARIANT\$//"`
3266a355
WC
98 if [ "$TMP" != "$UNAME" ]; then
99 UNAME=$TMP; KERNEL="kernel-$VARIANT"
100 fi
101done
01d4f0da
FCE
102# and then we have rhel9 era kernel-rt's:
103# 5.14.0-200.rt14.201.el9 ->
104# "kernel-rt-debug-5.14.0-200.rt14.201.el9"
105# OR?! "kernel-rt-5.14.0-200.rt14.201.el9"
b87891f5
MC
106# OR??!"kernel-rt-5.14.0-447.el9.x86_64+rt"
107if expr "$UNAME" : ".*\.rt.*" || expr "$UNAME" : ".*\+rt.*" >/dev/null;
01d4f0da
FCE
108then
109 KERNEL=`echo $KERNEL | sed -e s,kernel,kernel-rt,`
110fi
111
3266a355 112KERN_ARCH=`uname -m`
b87891f5
MC
113# strip arch from uname, for kernels like 5.14.0-447.el9.x86_64+rt or
114# 6.9.0-0.rc2.1.el10.x86_64+rt strip the +rt suffix too
115KERN_REV=`echo $UNAME | sed s/.$KERN_ARCH// | sed s/\+rt$//`
3b2b14c5
MC
116if [ -x /usr/bin/dnf4 ]; then
117 DI="dnf4 debuginfo-install"
118 DI_DEPS=""
119 D="dnf4"
120elif [ -x /usr/bin/dnf-3 ]; then
121 DI="dnf-3 debuginfo-install"
122 DI_DEPS=""
123 D="dnf-3"
124elif [ -x /usr/bin/dnf ]; then
b6b9b54b
FCE
125 DI="dnf debuginfo-install"
126 DI_DEPS=""
127 D="dnf"
128else
129 DI="debuginfo-install"
130 DI_DEPS="yum-utils"
131 D="yum"
132fi
705eae40
MC
133if test "$bequiet" = "true"; then
134 DI="$DI --quiet"
135 D="$D --quiet"
136fi
ca8bf77e
WC
137CANDIDATES="$KERNEL-$KERN_REV.$KERN_ARCH \
138 $KERNEL-devel-$KERN_REV.$KERN_ARCH \
a708b90a
FCE
139 $DI_DEPS"
140if [ "$DEBUGINFOD" -eq 0 ]; then # add debuginfo search if not already
141 CANDIDATES="$CANDIDATES $KERNEL-debuginfo-$KERN_REV.$KERN_ARCH"
142fi
ca8bf77e
WC
143NEEDED=`rpm --qf "%{name}-%{version}-%{release}.%{arch}\n" \
144 -q $CANDIDATES | grep "is not installed" | awk '{print $2}'`
3266a355
WC
145if [ "$NEEDED" != "" ]; then
146 echo -e "Need to install the following packages:\n$NEEDED"
fb3db0ca 147 if [ `id -u` = "0" ]; then #attempt to install
b6b9b54b 148 $D install -y --enablerepo=\* $NEEDED
0513bfe0 149 if expr "$NEEDED" : ".*debuginfo.*" >/dev/null;
a17088d1 150 then
b6b9b54b 151 $DI -y $KERNEL-$KERN_REV.$KERN_ARCH;
0513bfe0 152 fi
fb3db0ca 153 rpm -q $NEEDED
a17088d1 154 rc=$?
b6b9b54b 155 check_error $rc "problem installing rpm(s) $NEEDED\nin case of file conflicts, try again after # $D erase $KERNEL-debuginfo"
3266a355
WC
156 fi
157fi
74f5df1a
TJL
158}
159
a708b90a
FCE
160
161
67862af5
TJL
162prep_deb_based() {
163if [ $# -ne 0 ]; then
164 echo "Specifying kernel version is not yet support on deb based systems." 1>&2
165 exit 1
166fi
167
168# 2.6.32-5-amd64
169# 2.6.32-37-generic
170ABINAME="$(cut -d " " -f 3 /proc/version)"
171
172# 2.6.32
173BASEVERSION="$(echo "$ABINAME" | cut -d "-" -f 1)"
0c5c0f43
FCE
174DEBIAN_FRONTEND=noninteractive # don't confirm or chat
175export DEBIAN_FRONTEND
67862af5
TJL
176
177case "$DISTRO" in
178 Debian) # 2.6.32-39
179 if uname -v | grep -q Debian; then
180 VERSION="$(uname -v | cut -d " " -f 4)"
181 else
de25b7bb 182 VERSION="$(cut -d " " -f 3 /proc/version)"
67862af5
TJL
183 fi
184 ;;
185 Ubuntu)
186 # 2.6.32-37.81
dd1f4360
FCE
187 if [ -f /proc/version_signature ]; then
188 VERSION="$(cut -d " " -f 2 /proc/version_signature | cut -d "-" -f 1-2)"
189 else # 4.18
190 VERSION="$(cut -d " " -f 3 /proc/version)"
191 fi
67862af5
TJL
192 ;;
193esac
194
195(
196 echo "make >= 0"
197 echo "linux-image-$ABINAME = $VERSION"
198 echo "linux-headers-$ABINAME = $VERSION"
a708b90a
FCE
199 if [ "$DEBUGINFOD" -eq 0 ]; then # add dbgsym search if not already
200 echo "linux-image-$ABINAME-dbgsym = $VERSION"
201 fi
67862af5
TJL
202) | while read package relation requiredversion; do
203 installedversion="$(dpkg-query -W "$package" 2> /dev/null | cut -f 2)"
204 if [ "$installedversion" = "" ]; then
205 availableversion="$(apt-cache show $package 2> /dev/null | grep ^Version: | cut -d " " -f 2)"
eea974ac 206 if [ "$availableversion" = "" -a "$(echo $package | grep dbgsym$)" ]; then
67862af5 207 echo "You need package $package but it does not seem to be available"
eea974ac 208 if [ "$DISTRO" = "Ubuntu" ]; then
67862af5
TJL
209 echo " Ubuntu -dbgsym packages are typically in a separate repository"
210 echo " Follow https://wiki.ubuntu.com/DebuggingProgramCrash to add this repository"
eea974ac
RRS
211 elif [ "$DISTRO" = "Debian" ]; then
212 echo " Debian -dbgsym packages are typically in a separate repository"
213 echo " Follow https://wiki.debian.org/AutomaticDebugPackages to add this repository"
67862af5
TJL
214 fi
215 else
7b76b6b6
FCE
216 echo "Need to install $package"
217 if [ `id -u` = "0" ]; then #attempt to install
705eae40
MC
218 q=""; test "$bequiet" = "true" && q='--quiet'
219 apt-get $q -y install $package
7b76b6b6 220 fi
67862af5
TJL
221 fi
222 elif ! dpkg --compare-versions $installedversion $relation $requiredversion; then
223 echo "Package $package version $installedversion does not match version of currently running kernel: $requiredversion"
224 echo " Consider apt-get upgrade && reboot"
225 fi
226done
227
228user="$(id --user --name)"
229if [ "$user" != "root" ]; then
230 groups="$(id --groups --name)"
231 for i in stapusr stapdev; do
232 if [ "$(echo $groups | grep $i)" = "" ]; then
233 echo "Be root or adduser $user $i"
234 fi
235 done
236fi
237}
238
a708b90a
FCE
239
240prep_debuginfod "$@"
74f5df1a 241DISTRO="$(lsb_release --id --short 2> /dev/null)"
74f5df1a 242case "$DISTRO" in
67862af5
TJL
243Debian|Ubuntu)
244 prep_deb_based "$@"
245 ;;
74f5df1a
TJL
246*)
247 prep_rpm_based "$@"
248 ;;
249esac
This page took 0.222431 seconds and 6 git commands to generate.