summaryrefslogtreecommitdiff
path: root/src/ceph-clsinfo
blob: 5615af4852474a3a5cb5a7baf9a7f94273317d83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh


show_name=0
show_ver=0
show_arch=0
show_default=1
fname=""

usage="usage: $0 [option]... <cls_filename>\n"
usage=$usage"options:\n"
usage=$usage"\t-n, --name\n"
usage=$usage"\t-v, --ver\n"
usage=$usage"\t-a, --arch\n"

usage_exit() {
	printf "$usage"
	exit 1
}

err_exit() {
	echo "Error: $*"
	exit 1
}

while [ $# -ge 1 ]; do
case $1 in
    -n | --name )
	    show_name=1
	    show_default=0
	    ;;
    -v | --ver )
	    show_ver=1
	    show_default=0
	    ;;
    -a | --arch )
	    show_arch=1
	    show_default=0
	    ;;
    * )
	    [ -n "$fname" ] && usage_exit
	    fname=$1
	    ;;

esac
shift
done

[ -z "$fname" ] && usage_exit

if [ $show_default -eq 1 ]; then
	show_name=1
	show_ver=1
	show_arch=1
fi

[ -e "$fname" ] || err_exit "File not found: ${fname}"

if [ $show_name -eq 1 ]; then
	raw_name=`nm $fname | grep __cls_name__`
	name=`echo $raw_name | sed 's/.*cls_name__//g'`
	[ -z "$name" ] && err_exit "Could not detect class name"
	s=$name
	c=" "
fi

if [ $show_ver -eq 1 ]; then
	raw_ver=`nm $fname | grep __cls_ver__`
	ver=`echo $raw_ver | sed 's/.*cls_ver__//g; s/_/./g'`
	[ -z "$ver" ] && err_exit "Could not detect class version"
	s=$s$c$ver
	c=" "
fi

if [ $show_arch -eq 1 ]; then
	raw_arch=`readelf -h $fname | grep Machine`
	arch=""
	[ `echo $raw_arch | grep -c 386` -gt 0 ] && arch="i386"
	[ `echo $raw_arch | grep -c 86-64` -gt 0 ] && arch="x86-64"
	[ -z "$arch" ] && err_exit "unknown file architecture"
	s=$s$c$arch
	c=" "
fi

echo $s