]> sourceware.org Git - systemtap.git/blob - stap-prep
Fix PR19954 by avoiding "suspicious RCU usage" message.
[systemtap.git] / stap-prep
1 #! /bin/bash
2 LANG=C; export LANG
3 check_error() { if test $1 != 0; then echo $2; exit $1; fi }
4
5 prep_rpm_based() {
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)
10 # 3.18.6-100.fc20.i686+PAE (".arch+variant", dot, plus)
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
19 # strip out ".variant" or else "+variant" or else "variant" at end.
20 TMP=`echo $UNAME | sed "s/[\.\+]\?$VARIANT\$//"`
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
27 CANDIDATES="$KERNEL-$KERN_REV.$KERN_ARCH \
28 $KERNEL-devel-$KERN_REV.$KERN_ARCH \
29 $KERNEL-debuginfo-$KERN_REV.$KERN_ARCH"
30 NEEDED=`rpm --qf "%{name}-%{version}-%{release}.%{arch}\n" \
31 -q $CANDIDATES | grep "is not installed" | awk '{print $2}'`
32 if [ "$NEEDED" != "" ]; then
33 echo -e "Need to install the following packages:\n$NEEDED"
34 if [ `id -u` = "0" ]; then #attempt to install
35 yum install -y --enablerepo=\* $NEEDED
36 rpm -q $NEEDED
37 check_error $? "problem installing rpm(s) $NEEDED"
38 fi
39 fi
40 }
41
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"
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
113 DISTRO="$(lsb_release --id --short 2> /dev/null)"
114 if [ $? -ne 0 ]; then
115 DISTRO="unknown"
116 fi
117 case "$DISTRO" in
118 Debian|Ubuntu)
119 prep_deb_based "$@"
120 ;;
121 *)
122 prep_rpm_based "$@"
123 ;;
124 esac
This page took 0.039107 seconds and 5 git commands to generate.