summaryrefslogtreecommitdiffstats
path: root/doc/server/plugins/probes/group.txt
blob: 13b0d12ebf805a8f10b945c4327f103fae5a9cb0 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
.. -*- mode: rst -*-

.. _server-plugins-probes-group:

group
=====

Probe used to dynamically set client groups based on OS/distro.

.. note::

    Some parts of this script may depend on having lsb-release
    installed.

.. code-block:: sh

    #!/bin/bash

    OUTPUT=""

    if [ -e /etc/release ]; then
            # Solaris
            OUTPUT=$OUTPUT'\n'`echo group:solaris`
    elif [ -e /etc/debian_version ]; then
            # debian based
            OUTPUT=$OUTPUT'\n'`echo group:deb`
            if [ -e /etc/lsb-release ]; then
                    # variant
                    . /etc/lsb-release
                    OS_GROUP=$DISTRIB_CODENAME
                    DEBIAN_VERSION=$(echo "$DISTRIB_ID" | tr '[A-Z' '[a-z]')
                    case "$OS_GROUP" in
                            "lucid")
                            OUTPUT=$OUTPUT'\n'`echo group:$DISTRIB_CODENAME`
                            OUTPUT=$OUTPUT'\n'`echo group:$DEBIAN_VERSION`
                            ;;
                    esac
            else
                    # debian
                    OS_GROUP=`cat /etc/debian_version`
                    OUTPUT=$OUTPUT'\n'`echo group:debian`
                    case "$OS_GROUP" in
                            5.*)
                            OUTPUT=$OUTPUT'\n'`echo group:lenny`
                            ;;
                            "sid")
                            OUTPUT=$OUTPUT'\n'`echo group:sid`
                            ;;
                    esac
            fi
    elif [ -e /etc/redhat-release ]; then
            # redhat based
            OUTPUT=$OUTPUT'\n'`echo group:rpm`
            OS_GROUP=`cat /etc/redhat-release | cut -d' ' -f1 | tr '[A-Z]' '[a-z]'`
            REDHAT_VERSION=`cat /etc/redhat-release | cut -d' ' -f3`
            case "$OS_GROUP" in
                    "centos" | "fedora")
                    OUTPUT=$OUTPUT'\n'`echo group:$OS_GROUP`
                    OUTPUT=$OUTPUT'\n'`echo group:$OS_GROUP$REDHAT_VERSION`
                    ;;
            esac
    elif [ -e /etc/gentoo-release ]; then
            # gentoo
            OUTPUT=$OUTPUT'\n'`echo group:gentoo`
    elif [ -x /usr/sbin/system_profiler ]; then
            # os x
            ### NOTE: Think about using system_profiler SPSoftwareDataType here
            OUTPUT=$OUTPUT'\n'`echo group:osx`
            OSX_VERSION=`sw_vers | grep 'ProductVersion:' | egrep -o '[0-9]+\.[0-9]+'`
            if [ "$OSX_VERSION" == "10.6" ]; then
                    OUTPUT=$OUTPUT'\n'`echo group:osx-snow`
            elif [ "$OSX_VERSION" == "10.5" ]; then
                    OUTPUT=$OUTPUT'\n'`echo group:osx-leo`
            fi
            echo $OUTPUT
    else
            exit 0
    fi
    # get the proper architecture
    ARCH=`uname -m`
    case "$ARCH" in
            "x86_64")
            if [ "$OS_GROUP" == 'centos' ]; then
                    OUTPUT=$OUTPUT'\n'`echo group:$ARCH`
            else
                    OUTPUT=$OUTPUT'\n'`echo group:amd64`
            fi
            ;;
            "i386" | "i686")
            OUTPUT=$OUTPUT'\n'`echo group:i386`
            ;;
            "sparc64")
            OUTPUT=$OUTPUT'\n'`echo group:sparc64`
            ;;
    esac

    # output the result of all the group probing
    # (interpreting the backslashed newlines)
    echo -e $OUTPUT