Minor fixes
[apps/app-templates.git] / test-widget / launcher.sh.in
1 #!/bin/bash
2
3 ###########################################################################
4 # Copyright (C) 2017, 2018 IoT.bzh
5 #
6 # Author: Romain Forlot <romain.forlot@iot.bzh>
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #     http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 ###########################################################################
20
21 PORT=$1
22 TOKEN=$2
23
24 # Research the Api name used
25 CFGFILE=$(find ${AFM_APP_INSTALL_DIR} -name "*json" -print | head -n1)
26 API=$(grep '\"api\"' ${CFGFILE} | cut -d'"' -f4)
27
28 AFBCLIENTIN=$(mktemp -u)
29 AFBCLIENTOUT=$(mktemp -u)
30 mkfifo $AFBCLIENTIN
31 mkfifo $AFBCLIENTOUT
32
33 declare -a testVerb
34
35 if [[ $(jq '.testVerb|type' $CFGFILE) == "array" ]]
36 then
37         testVerbLength=$(jq '.testVerb | length')
38         for (( idx=0; idx<testVerbLength; idx++ )) do
39                 testVerb[$idx]=$(jq -r ".testVerb[$idx].uid" ${CFGFILE})
40         done
41 else
42         testVerb[0]=$(jq -r ".testVerb.uid" ${CFGFILE})
43 fi
44
45 testVerbLength=${#testVerb[@]}
46 for (( idx=0; idx<testVerbLength; idx++ )) do
47         afb-client-demo -s ws://localhost:${PORT}/api?token=${TOKEN} "$API" "${testVerb[$idx]}"
48 done
49
50 afb-client-demo ws://localhost:${PORT}/api?token=${TOKEN} "$API" "exit"