File: getglibcversion

package info (click to toggle)
glib2.0 2.0.1-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,072 kB
  • ctags: 24
  • sloc: sh: 4,219; makefile: 254
file content (56 lines) | stat: -rw-r--r-- 1,397 bytes parent folder | download | duplicates (104)
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
#!/bin/sh
# GNU C library version detection shell script.
# Copyright 1999 Branden Robinson.
# Licensed under the GNU General Public License, version 2.  See the file
# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.

# This script probably makes about a billion too many assumptions, but it's
# better than hardcoding the glibc version on a per-architecture basis.

set -e

usage () {
  echo "Usage: getglibcversion [option]"
  echo "  Where [option] may be one of:"
  echo "  --major      return major version only"
  echo "  --minor      return minor version only"
  echo "  --point  return ittybitty version only"
  echo "With no option, returns major.minor.ittybitty .";
}

case $# in
  0) ;;
  1) case $1 in
       --help) usage
               exit 0 ;;
       --major) RETURN=1 ;;
       --minor) RETURN=2 ;;
       --point) RETURN=3 ;;
       *) exec 1>&2
          usage
          exit 1 ;;
     esac ;;
  *) exec 1>&2
     usage
     exit 1 ;;
esac

LIBCLIST=$(cd /lib && ls libc-*.so)

case $(echo $LIBCLIST | wc -l | awk '{print $1}') in
  0) echo "No GNU C library found!  Aborting." >&2
     exit 1 ;;
  1) ;;
  *) echo "Multiple versions of GNU C library found!  Aborting." >&2
     exit 1 ;;
esac

LIBCVERSION=$(echo $LIBCLIST | sed 's/libc-//;s/\.so//')

if [ -z $RETURN ]; then
  echo $LIBCVERSION
else
  echo $LIBCVERSION | cut -d. -f$RETURN
fi

exit 0