File: modify-active.sh

package info (click to toggle)
mdevctl 1.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,072 kB
  • sloc: sh: 731; makefile: 74
file content (103 lines) | stat: -rwxr-xr-x 2,317 bytes parent folder | download
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
#!/bin/sh
# A basic utility script used for debugging notification call-out events
# in mdevctl. Output can be observed via system logs.

#stdin | -t type -e event -a action -s state -u uuid -p parent
shift
type=$1
shift 2
event=$1
shift 2
action=$1
shift 2
state=$1
shift 2
uuid=$1
shift 2
parent=$1
json=$(cat)

tempfile="tmp_modify-live.json"


print_supported_version() {
    case "$1" in
        11111111-1111-0000-0000-000000000000)
            # full version 2 and RC=0
            echo "{\"supports\":{"
            echo "\"version\":2,"
            echo "\"actions\":[\"start\",\"stop\",\"define\",\"undefine\",\"modify\",\"attributes\",\"capabilities\"],"
            echo "\"events\":[\"pre\",\"post\",\"notify\",\"get\"]"
            echo "}}"
            exit 0
        ;;
        11111111-1111-1111-0000-000000000000)
            # valid version 3 and RC=0
            echo "{\"supports\":{"
            echo "\"version\":3,"
            echo "\"actions\":[\"start\",\"stop\",\"define\",\"undefine\",\"modify\",\"attributes\",\"capabilities\"],"
            echo "\"events\":[\"pre\",\"post\",\"notify\",\"get\",\"live\"]"
            echo "}}"
            exit 0
        ;;
        *)
            exit 2
        ;;
    esac
}

case "$event" in
    pre)
        case "$action" in
            modify)
                exit 0
            ;;
            *)
                exit 1
            ;;
        esac
    ;;
    get)
        case "$action" in
            capabilities)
                print_supported_version "$uuid"
            ;;
            attributes)
                if [ -f "$tempfile" ]; then
                    cat "$tempfile"
                    rm "$tempfile"
                else
                        echo "[]"
                fi
                exit 0
            ;;
            *)
                exit 1
            ;;
        esac
    ;;
    post)
        case "$action" in
            modify)
                exit 0
            ;;
            *)
                exit 1
            ;;
        esac
    ;;
    live)
        case "$action" in
            modify)
                echo "$json" | grep -oP '"attrs":+\K(\[.*\])' > "$tempfile"
                exit 0
            ;;
            *)
                exit 1
            ;;
        esac
    ;;
    *)
        exit 1
    ;;
esac