File: get-platform-os

package info (click to toggle)
dpm-postgres 1.7.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,788 kB
  • ctags: 10,782
  • sloc: ansic: 146,136; sh: 13,362; perl: 11,142; python: 5,529; cpp: 5,113; sql: 1,790; makefile: 955; fortran: 113
file content (63 lines) | stat: -rwxr-xr-x 1,718 bytes parent folder | download | duplicates (4)
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
#!/bin/sh

# set DEBUG to print some debug information!
if [ -n "$DEBUG" ]; then
    d_p=$(basename $0)" DEBUG:"
fi

platform_os='unknown'
set +e

IFS_SAVED="$IFS"
IFS=':'
while read pattern os cos; do
    # pattern: regexp pattern to recognize the OS
    # os: OS release abbreviation
    # cos: compatible OS release abbreviation
    if [ -n "$DEBUG" ]; then echo "$d_p Testing pattern='$pattern' for $os ($cos)" >&2; fi
    egrep -qi "$pattern" /etc/issue.net
    if [ $? -eq 0 ]; then
        if [ -n "$DEBUG" ]; then echo "$d_p recognized $os ($cos)!" >&2; fi
        platform_os="$cos"
    fi
done <<EOF
taroon:rhel3:slc3
scientific linux.*release 3:sl3:slc3
scientific linux.*cern.*release 3:slc3:slc3
centos.*release 3:centos3:slc3
scientific linux.*release 4:sl4:slc4
scientific linux.*cern.*release 4:slc4:slc4
centos.*release 4:centos4:slc4
scientific linux.*release 5:sl5:sl5
scientific linux.*cern.*release 5:slc5:sl5
centos.*release 5:centos5:sl5
debian:debian:debian
ubuntu 7.10:ubuntu710:sl5
EOF
IFS="$IFS_SAVED"

# do a more expensive check if /etc/issue.net is unrecognizable
if [ "$platform_os" = 'unknown' -a -x '/bin/rpm' ]; then
    if [ -n "$DEBUG" ]; then echo "$d_p not recognized /etc/issue.net, checking the RPM." >&2; fi
    rpmname=$(rpm -qf /etc/issue.net)
    case $rpmname in 
        sl-release-4.*.cern-*)
            platform_os='slc4'
            ;;
        sl-release-4.*)
            # in reality this is sl4
            platform_os='slc4'
            ;;
        sl-release-3.*.cern-*)
            platform_os='slc3'
            ;;
        sl-release-3.*)
            # in reality this is sl3
            platform_os='slc3'
            ;;
    esac
fi

set -e

echo ${platform_os}