eb800d9342a43b1c8884423ee9c8346445643d38
[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   once)
56     i=$2
57     send once "\"$i\""
58     ;;
59
60   terminate|kill)
61     i=$2
62     send terminate "$i"
63     ;;
64
65   stop|pause)
66     i=$2
67     send pause "$i"
68     ;;
69
70   resume|continue)
71     i=$2
72     send resume "$i"
73     ;;
74
75   state|status)
76     i=$2
77     send state "$i"
78     ;;
79
80   -h|--help|help)
81     cat << EOC
82 usage: $(basename $0) command [arg]
83
84 The commands are:
85
86   list
87   runnables      list the runnable widgets installed
88
89   add wgt
90   install wgt    install the wgt file
91
92   remove id
93   uninstall id   remove the installed widget of id
94
95   info id
96   detail id      print detail about the installed widget of id
97
98   ps
99   runners        list the running instance
100
101   run id
102   start id       start an instance of the widget of id
103
104   once id        run once an instance of the widget of id
105
106   kill rid
107   terminate rid  terminate the running instance rid
108
109   stop rid
110   pause rid      pause the running instance rid
111
112   resume rid
113   continue rid   continue the previously paused rid
114
115   status rid
116   state rid      get status of the running instance rid
117
118 EOC
119     ;;
120
121   *)
122     echo "unknown command $1" >&2
123     exit 1
124     ;;
125 esac
126
127