]> sourceware.org Git - systemtap.git/blob - stap-prep
Correct systemtap.spec to match support currently available on aarch64
[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 if [ "$#" -lt 1 ]; then
11 UNAME=`uname -r` # determine the kernel running on the machine
12 else
13 UNAME=$1 #user passed in uname value
14 fi
15 UNAME=`echo $UNAME | sed "s/ //"` #strip out any whitespace
16 KERNEL="kernel"
17 for VARIANT in debug kdump PAE xen; do
18 # strip out ".variant" or else "variant" at end.
19 TMP=`echo $UNAME | sed s/\\\\.$VARIANT\$// | sed s/$VARIANT\$//`
20 if [ "$TMP" != "$UNAME" ]; then
21 UNAME=$TMP; KERNEL="kernel-$VARIANT"
22 fi
23 done
24 KERN_ARCH=`uname -m`
25 KERN_REV=`echo $UNAME | sed s/.$KERN_ARCH//` # strip arch from uname
26 CANDIDATES="$KERNEL-$KERN_REV.$KERN_ARCH \
27 $KERNEL-devel-$KERN_REV.$KERN_ARCH \
28 $KERNEL-debuginfo-$KERN_REV.$KERN_ARCH"
29 NEEDED=`rpm --qf "%{name}-%{version}-%{release}.%{arch}\n" \
30 -q $CANDIDATES | grep "is not installed" | awk '{print $2}'`
31 if [ "$NEEDED" != "" ]; then
32 echo -e "Need to install the following packages:\n$NEEDED"
33 if [ `id -u` = "0" ]; then #attempt download and install
34 DIR=`mktemp -d` || exit 1
35 if [ ! -x /usr/bin/yumdownloader ]; then
36 echo "Need to first install yum-utils for yumdownloader"
37 yum install -y yum-utils
38 fi
39 yumdownloader --enablerepo="*debuginfo*" $NEEDED --destdir=$DIR \
40 --resolve
41 check_error $? "problem downloading rpm(s) $NEEDED"
42 rpm --force -ivh $DIR/*.rpm
43 check_error $? "problem installing rpm(s) $NEEDED"
44 rm -r $DIR #cleanup
45 fi
46 fi
47 }
48
49 prep_deb_based() {
50 if [ $# -ne 0 ]; then
51 echo "Specifying kernel version is not yet support on deb based systems." 1>&2
52 exit 1
53 fi
54
55 # 2.6.32-5-amd64
56 # 2.6.32-37-generic
57 ABINAME="$(cut -d " " -f 3 /proc/version)"
58
59 # 2.6.32
60 BASEVERSION="$(echo "$ABINAME" | cut -d "-" -f 1)"
61
62 case "$DISTRO" in
63 Debian) # 2.6.32-39
64 if uname -v | grep -q Debian; then
65 VERSION="$(uname -v | cut -d " " -f 4)"
66 else
67 VERSION="$(cut -d " " -f 5 /proc/version | cut -d ")" -f 1)"
68 fi
69 ;;
70 Ubuntu)
71 # 2.6.32-37.81
72 VERSION="$(cut -d " " -f 2 /proc/version_signature | cut -d "-" -f 1-2)"
73 ;;
74 esac
75
76 (
77 echo "make >= 0"
78 echo "linux-image-$ABINAME = $VERSION"
79 echo "linux-headers-$ABINAME = $VERSION"
80 case "$DISTRO" in
81 Debian)
82 echo "linux-image-$ABINAME-dbg = $VERSION"
83 ;;
84 Ubuntu)
85 echo "linux-image-$ABINAME-dbgsym = $VERSION"
86 ;;
87 esac
88 ) | while read package relation requiredversion; do
89 installedversion="$(dpkg-query -W "$package" 2> /dev/null | cut -f 2)"
90 if [ "$installedversion" = "" ]; then
91 availableversion="$(apt-cache show $package 2> /dev/null | grep ^Version: | cut -d " " -f 2)"
92 if [ "$availableversion" = "" ]; then
93 echo "You need package $package but it does not seem to be available"
94 if [ "$DISTRO" = "Ubuntu" -a "$(echo $package | grep dbgsym$)" ]; then
95 echo " Ubuntu -dbgsym packages are typically in a separate repository"
96 echo " Follow https://wiki.ubuntu.com/DebuggingProgramCrash to add this repository"
97 elif [ "$DISTRO" = "Debian" -a "$(echo $package | grep dbg$)" ]; then
98 echo " Debian does not have -dbg packages for all kernels. Consider switching to a kernel that has one."
99 fi
100 else
101 echo "Please install $package"
102 fi
103 elif ! dpkg --compare-versions $installedversion $relation $requiredversion; then
104 echo "Package $package version $installedversion does not match version of currently running kernel: $requiredversion"
105 echo " Consider apt-get upgrade && reboot"
106 fi
107 done
108
109 user="$(id --user --name)"
110 if [ "$user" != "root" ]; then
111 groups="$(id --groups --name)"
112 for i in stapusr stapdev; do
113 if [ "$(echo $groups | grep $i)" = "" ]; then
114 echo "Be root or adduser $user $i"
115 fi
116 done
117 fi
118 }
119
120 DISTRO="$(lsb_release --id --short 2> /dev/null)"
121 if [ $? -ne 0 ]; then
122 DISTRO="unknown"
123 fi
124 case "$DISTRO" in
125 Debian|Ubuntu)
126 prep_deb_based "$@"
127 ;;
128 *)
129 prep_rpm_based "$@"
130 ;;
131 esac
This page took 0.041776 seconds and 5 git commands to generate.