]> sourceware.org Git - systemtap.git/blame - stap-prep
buildrun.cxx: adapt to kernel 5.4+
[systemtap.git] / stap-prep
CommitLineData
3266a355 1#! /bin/bash
cdd7ce2e 2LANG=C; export LANG
a17088d1 3check_error() { if test $1 != 0; then printf "\n$2\n"; exit $1; fi }
3266a355 4
74f5df1a 5prep_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
11if [ "$#" -lt 1 ]; then
12 UNAME=`uname -r` # determine the kernel running on the machine
13else
14 UNAME=$1 #user passed in uname value
15fi
16UNAME=`echo $UNAME | sed "s/ //"` #strip out any whitespace
17KERNEL="kernel"
18for 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
24done
25KERN_ARCH=`uname -m`
26KERN_REV=`echo $UNAME | sed s/.$KERN_ARCH//` # strip arch from uname
b6b9b54b
FCE
27if [ -x /usr/bin/dnf ]; then
28 DI="dnf debuginfo-install"
29 DI_DEPS=""
30 D="dnf"
31else
32 DI="debuginfo-install"
33 DI_DEPS="yum-utils"
34 D="yum"
35fi
ca8bf77e
WC
36CANDIDATES="$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
40NEEDED=`rpm --qf "%{name}-%{version}-%{release}.%{arch}\n" \
41 -q $CANDIDATES | grep "is not installed" | awk '{print $2}'`
3266a355
WC
42if [ "$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
54fi
74f5df1a
TJL
55}
56
67862af5
TJL
57prep_deb_based() {
58if [ $# -ne 0 ]; then
59 echo "Specifying kernel version is not yet support on deb based systems." 1>&2
60 exit 1
61fi
62
63# 2.6.32-5-amd64
64# 2.6.32-37-generic
65ABINAME="$(cut -d " " -f 3 /proc/version)"
66
67# 2.6.32
68BASEVERSION="$(echo "$ABINAME" | cut -d "-" -f 1)"
69
70case "$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 ;;
86esac
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
116done
117
118user="$(id --user --name)"
119if [ "$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
126fi
127}
128
74f5df1a
TJL
129DISTRO="$(lsb_release --id --short 2> /dev/null)"
130if [ $? -ne 0 ]; then
131 DISTRO="unknown"
132fi
133case "$DISTRO" in
67862af5
TJL
134Debian|Ubuntu)
135 prep_deb_based "$@"
136 ;;
74f5df1a
TJL
137*)
138 prep_rpm_based "$@"
139 ;;
140esac
This page took 0.158321 seconds and 5 git commands to generate.