summaryrefslogtreecommitdiffstats
path: root/openlmi-mof-register
blob: 9ee9ee45897b0805526086e3cd70b34f309f8799 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/sh
#
# Copyright (C) 2012 Red Hat, Inc.  All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
#
# Authors: Radek Novacek <rnovacek@redhat.com>
#

pegasus_repository="/var/lib/Pegasus/"

function usage()
{
    printf "Usage: $0 [ register | unregister ] <mof> [mof] [...] <reg>\n"
}

function register()
{
    reg=$1
    shift
    mofs="$@"
    if [ $HAS_SFCBD -eq 1 ];
    then
        /usr/bin/sfcbstage -r "$reg" "$mofs"
        /usr/bin/sfcbrepos -f
        /usr/bin/systemctl reload-or-try-restart sblim-sfcb.service
    fi

    if [ $HAS_PEGASUS -eq  1 ];
    then
        /usr/sbin/cimserver --status > /dev/null 2>&1
        if [ $? -eq 0 ];
        then
            CIMMOF="/usr/bin/cimmof -aEV"
        else
            CIMMOF="/usr/bin/cimmofl -aEV -R $pegasus_repository"
        fi

        $CIMMOF -uc $mofs
        if [ -x $(dirname $0)/openlmi-register-pegasus ];
        then
            cat "$reg" | $(dirname $0)/openlmi-register-pegasus | $CIMMOF -uc -n root/PG_Interop
        else
            cat "$reg" | /usr/libexec/openlmi-register-pegasus | $CIMMOF -uc -n root/PG_Interop
        fi
    fi
}

function unregister()
{
    reg=$1
    shift
    # convert mofs to `basename mof`
    declare -a mofs=("$@")
    for ((i=0; i<${#mofs[@]}; i++)); do
        mofs[$i]=$(basename "${mofs[$i]}")
    done

    if [ $HAS_SFCBD -eq 1 ];
    then
        /usr/bin/sfcbunstage -r $(basename "$reg") ${mofs[@]}
        /usr/bin/sfcbrepos -f
        /usr/bin/systemctl reload-or-try-restart sblim-sfcb.service
    fi

    if [ $HAS_PEGASUS -eq 1 ];
    then
        for provider in $(sed -n 's/ *location: *//p' "$reg" | sort | uniq);
        do
            /usr/bin/cimprovider -d -m ${provider} && /usr/bin/cimprovider -r -m ${provider}
        done
    fi
}

if [ $# -lt 3 ];
then
    usage
    exit 1
fi

if [ -e /usr/sbin/sfcbd ];
then
    HAS_SFCBD=1
else
    HAS_SFCBD=0
fi

if [ -e /usr/sbin/cimserver ];
then
    HAS_PEGASUS=1
else
    HAS_PEGASUS=0
fi

# TODO: check if at least one server is installed

CMD=$1
shift

# parse the reg and mofs - use $@ and remove the last item
declare -a ARGS=("$@")
LEN=$(( ${#ARGS[@]} -1 ))
REG=${ARGS[$LEN]}
MOFS=(${ARGS[@]:0:$(($LEN))})

case $CMD in
    register)
        register $REG ${MOFS[@]}
        ;;
    unregister)
        unregister $REG ${MOFS[@]}
        ;;
    **)
        usage
        exit 1
esac