summaryrefslogtreecommitdiffstats
path: root/plugins.d/charts.d.dryrun-helper.sh
blob: 8142f9882b6aa79573d45eb744ba04496f9a0085 (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
#!/usr/bin/env bash

# will stop the script for any error
set -e

me="$0"
name="$1"
chart="$2"
conf="$3"

can_diff=1

tmp1="`mktemp`"
tmp2="`mktemp`"

myset() {
    set | grep -v "^_=" | grep -v "^PIPESTATUS=" | grep -v "^BASH_LINENO="
}

# save 2 'set'
myset >"$tmp1"
myset >"$tmp2"

# make sure they don't differ
diff "$tmp1" "$tmp2" >/dev/null 2>&1
if [ $? -ne 0 ]
then
    # they differ, we cannot do the check
    echo >&2 "$me: cannot check with diff."
    can_diff=0
fi

# do it again, now including the script
myset >"$tmp1"

# include the plugin and its config
if [ -f "$conf" ]
then
    . "$conf"
    if [ $? -ne 0 ]
    then
        echo >&2 "$me: cannot load config file $conf"
        rm "$tmp1" "$tmp2"
        exit 1
    fi
fi

. "$chart"
if [ $? -ne 0 ]
then
    echo >&2 "$me: cannot load chart file $chart"
    rm "$tmp1" "$tmp2"
    exit 1
fi

# remove all variables starting with the plugin name
myset | grep -v "^$name" >"$tmp2"

if [ $can_diff -eq 1 ]
then
    # check if they are different
    # make sure they don't differ
    diff "$tmp1" "$tmp2" >&2
    if [ $? -ne 0 ]
    then
        # they differ
        rm "$tmp1" "$tmp2"
        exit 1
    fi
fi

rm "$tmp1" "$tmp2"
exit 0