978f000cd65f2cef408aeabd7e8009a85a97aeeb
[src/app-framework-main.git] / scripts / afm-util.in
1 #!/bin/bash
2
3 send() {
4         afb-client-demo -H -d unix:@afm_platform_rundir@/apis/ws/afm-main "$1" "$2" |
5         awk '$1=="ON-REPLY" && $3!="success"{$1="ERROR:";$2="";print > "/dev/stderr";exit 1;}NR>1'
6 }
7
8 getall() {
9   case "$1" in
10     -a|--all) echo -n '{"all":true}';;
11     *) echo -n true;;
12   esac
13 }
14
15 case "$1" in
16
17   list|runnables)
18     send runnables $(getall $2)
19     ;;
20
21   add|install)
22     f=$(realpath $2)
23     r=true
24     if [[ "$(basename $0)" = "afm-install" ]]; then r=false; fi
25     send install '{"wgt":"'"$f"'","force":true,"reload":'"$r"'}'
26     ;;
27
28   remove|uninstall)
29     i=$2
30     send uninstall "\"$i\""
31     ;;
32
33   info|detail)
34     i=$2
35     send detail "\"$i\""
36     ;;
37
38   ps|runners)
39     send runners  $(getall $2)
40     ;;
41
42   run|start)
43     i=$2
44     send start "\"$i\""
45     ;;
46
47   run-remote|start-remote)
48     i=$2
49     send start '{"id":"'"$i"'","mode":"remote"}'
50     ;;
51
52   once)
53     i=$2
54     send once "\"$i\""
55     ;;
56
57   terminate|kill)
58     i=$2
59     send terminate "$i"
60     ;;
61
62   stop|pause)
63     i=$2
64     send pause "$i"
65     ;;
66
67   resume|continue)
68     i=$2
69     send resume "$i"
70     ;;
71
72   state|status)
73     i=$2
74     send state "$i"
75     ;;
76
77   -h|--help|help)
78     cat << EOC
79 usage: $(basename $0) command [arg]
80
81 The commands are:
82
83   list
84   runnables      list the runnable widgets installed
85                  option -a or --all for all instances
86
87   add wgt
88   install wgt    install the wgt file
89
90   remove id
91   uninstall id   remove the installed widget of id
92
93   info id
94   detail id      print detail about the installed widget of id
95
96   ps
97   runners        list the running instance
98                  option -a or --all for all instances
99
100   run id
101   start id       start an instance of the widget of id
102
103   once id        run once an instance of the widget of id
104
105   kill rid
106   terminate rid  terminate the running instance rid
107
108   stop rid
109   pause rid      pause the running instance rid
110
111   resume rid
112   continue rid   continue the previously paused rid
113
114   status rid
115   state rid      get status of the running instance rid
116
117 EOC
118     ;;
119
120   *)
121     echo "unknown command $1" >&2
122     exit 1
123     ;;
124 esac
125
126