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