afm-util: install and pretty printing
[src/app-framework-main.git] / scripts / afm-util
1 #!/bin/sh
2
3 if [ "x" = "x${DBUS_SESSION_BUS_ADDRESS}" ]; then
4         DBUS_SESSION_BUS_ADDRESS:=unix:path=/run/user/$UID/bus
5 fi
6
7 pretty() {
8         sed \
9                 -e '/^method return .*/d' \
10                 -e 's/^Error org.freedesktop.DBus.Error.Failed: "\?\(.*\)"\?$/ERROR: \1/' \
11                 -e 's/^   string "\(.*\)"/\1/' \
12                 -e 's/},/&\n/'
13 }
14
15 send() {
16         dbus-send --session --print-reply \
17                 --dest=org.AGL.afm.user \
18                 /org/AGL/afm/user \
19                 org.AGL.afm.user.$1 \
20                 "string:$2" |
21         pretty
22 }
23
24 case "$1" in
25
26   list|runnables)
27     send runnables true
28     ;;
29
30   add|install)
31     f=$(realpath $2)
32     send install '{"wgt":"'"$f"'","force":true}'
33     ;;
34
35   remove|uninstall)
36     i=$2
37     send uninstall "\"$i\""
38     ;;
39
40   info|detail)
41     i=$2
42     send detail "\"$i\""
43     ;;
44
45   ps|runners)
46     send runners true
47     ;;
48
49   run|start)
50     i=$2
51     send start "\"$i\""
52     ;;
53
54   terminate|kill)
55     i=$2
56     send terminate "$i"
57     ;;
58
59   stop|pause)
60     i=$2
61     send stop "$i"
62     ;;
63
64   resume|continue)
65     i=$2
66     send continue "$i"
67     ;;
68
69   state|status)
70     i=$2
71     send state "$i"
72     ;;
73
74   -h|--help|help)
75     cat << EOC
76 usage: $(basename $0) command [arg]
77
78 The commands are:
79
80   list
81   runnables      list the runnable widgets installed
82
83   add wgt
84   install wgt    install the wgt file
85
86   remove id
87   uninstall id   remove the installed widget of id
88
89   info id
90   detail id      print detail about the installed widget of id
91
92   ps
93   runners        list the running instance
94
95   run id
96   start id       start an instance of the widget of id
97
98   kill rid
99   terminate rid       terminate the running instance rid
100
101   stop rid
102   pause rid      stop the running instance rid
103
104   resume rid
105   continue rid   continue the previously rid
106
107   status rid
108   state rid     get status of the running instance rid
109
110 EOC
111     ;;
112
113   *)
114     echo "unknown command $1" >&2
115     exit 1
116     ;;
117 esac
118
119