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