This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathtestapp.sh
executable file
·150 lines (129 loc) · 3.01 KB
/
testapp.sh
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/sh
NL='
'
result_value="$1"
case "$result_value" in
"success" | "noupdate" | "error") ;;
"")
result_value="success"
;;
*)
exit 1
;;
esac
read -r header init_cmd version
if [ "$header" != "ELEKTRA_PROCESS" ]; then
exit 1
fi
if [ "$init_cmd" != "INIT" ]; then
exit 1
fi
if [ "$version" != "v1" ]; then
exit 1
fi
printf "ELEKTRA_PROCESS ACK v1\n"
printf "testapp\n"
# shellcheck disable=SC2016
printf 'kdbOpen 2
$key string 49 1
system:/elektra/modules/process/exports/has/close
1
$key string 47 1
system:/elektra/modules/process/exports/has/get
1
$key string 48 1
system:/elektra/modules/process/exports/has/open
1
$key string 47 1
system:/elektra/modules/process/exports/has/set
1
$key string 37 58
system:/elektra/modules/process/infos
Information about the process test plugin is in keys below
$key string 44 45
system:/elektra/modules/process/infos/author
Klemens Böswirth <[email protected]>
$key string 49 23
system:/elektra/modules/process/infos/description
test plugin for process
$key string 45 3
system:/elektra/modules/process/infos/licence
BSD
$key string 46 0
system:/elektra/modules/process/infos/metadata
$key string 43 0
system:/elektra/modules/process/infos/needs
$key string 48 21
system:/elektra/modules/process/infos/placements
getstorage setstorage
$key string 46 0
system:/elektra/modules/process/infos/provides
$key string 48 0
system:/elektra/modules/process/infos/recommends
$key string 44 42
system:/elektra/modules/process/infos/status
maintained unittest shelltest experimental
$end
'
read_keyset() {
read -r header
if [ "$header" != "kdbOpen 2" ]; then
exit 1
fi
keyset="kdbOpen 2$NL"
while read -r line; do
keyset="$keyset$line$NL"
# shellcheck disable=SC2016
if [ "$line" = '$end' ]; then
echo "$keyset"
return 0
fi
done
}
while read -r cmd; do
case "$cmd" in
"open")
parent_ks=$(read_keyset)
# shellcheck disable=SC2034
config_ks=$(read_keyset) # config_ks ignored
parent=$(echo "$parent_ks" | sed -n 3p)
plen=${#parent}
printf "%s\n" "$result_value"
# shellcheck disable=SC2016
printf 'kdbOpen 2\n$key string %d %d\n%s\n%s\n$end\n' "${#parent}" "${#cmd}" "$parent" "$cmd"
;;
"close")
parent_ks=$(read_keyset)
parent=$(echo "$parent_ks" | sed -n 3p)
plen=${#parent}
printf "%s\n" "$result_value"
# shellcheck disable=SC2016
printf 'kdbOpen 2\n$key string %d %d\n%s\n%s\n$end\n' "${#parent}" "${#cmd}" "$parent" "$cmd"
;;
"get" | "set")
parent_ks=$(read_keyset)
data_ks=$(read_keyset)
parent=$(echo "$parent_ks" | sed -n 3p)
plen=${#parent}
klen=$((plen + 10))
extra_key="\$key string $klen ${#cmd}$NL"
extra_key="$extra_key$parent/operation$NL"
extra_key="$extra_key$cmd$NL"
data_ks=$(
echo "$data_ks" | sed '$d'
echo "$extra_key\$end$NL"
)
printf "%s\n" "$result_value"
# shellcheck disable=SC2016
printf 'kdbOpen 2\n$key string %d %d\n%s\n%s\n$end\n' "$plen" "${#cmd}" "$parent" "$cmd"
printf "%s\n" "$data_ks"
;;
"ELEKTRA_PROCESS TERMINATE")
exit 0
;;
*)
# shouldn't happen
exit 1
;;
esac
done