remove debuging information of do_afm_util
[src/qa-testdefinitions.git] / common / scripts / application-lifecycle.sh
1 #!/bin/sh
2
3 set -x
4
5 export TERM=dumb
6
7 AGLDRIVER=agl-driver
8
9 while [ $# -ge 1 ]
10 do
11         case $1 in
12         -b)
13                 shift
14                 BASEURL=$1
15                 shift
16         ;;
17         *)
18                 echo "Unknown argument $1"
19                 exit 1
20         ;;
21         esac
22 done
23
24 if [ -z "$BASEURL" ]; then
25         echo "$0: missing BASEURL"
26         echo "Usage: $0 -b BASEURL"
27         exit 1
28 fi
29
30 do_afm_util()
31 {
32         if [ $SERVICE_USER -eq 1 -o $APPLICATION_USER -eq 1 ];then
33                 su - $AGLDRIVER -c "afm-util $*"
34         else
35                 afm-util $*
36         fi
37         return $?
38 }
39
40 wget -q $BASEURL -O index.html
41 if [ $? -ne 0 ];then
42         echo "ERROR: Cannot wget $BASEURL"
43         exit 1
44 fi
45
46 grep -o '[a-z-]*.wgt' index.html | sort | uniq |
47 while read wgtfile
48 do
49         WGTNAME=$(echo $wgtfile | sed 's,.wgt$,,')
50         SERVICE_PLATFORM=0
51         SERVICE_USER=0
52         APPLICATION_USER=0
53         echo "DEBUG: fetch $wgtfile"
54         wget -q $BASEURL/$wgtfile
55         if [ $? -ne 0 ];then
56                 echo "ERROR: wget from $BASEURL/$wgtfile"
57                 continue
58         fi
59
60         echo "DEBUG: analyse wgt file"
61         unzip $wgtfile
62         if [ $? -ne 0 ];then
63                 # TODO Do not fail yet, busybox unzip seems to "fail with success" when checking CRC
64                 echo "ERROR: cannot unzip $wgtfile"
65         fi
66         if [ -f config.xml ];then
67                 grep hidden config.xml
68                 if [ $? -eq 0 ];then
69                         echo "DEBUG: hidden package"
70                 else
71                         echo "DEBUG: not hidden package"
72                 fi
73                 # a service sets urn:AGL:widget:provided-api
74                 grep "urn:AGL:widget:provided-api" config.xml
75                 if [ $? -eq 0 ] ; then
76                     # we are a service, now determine the scope ...
77                     grep "urn:AGL:permission::partner:scope-platform" config.xml
78                     if [ $? -eq 0 ];then
79                         SERVICE_PLATFORM=1
80                     else
81                         SERVICE_USER=1
82                     fi
83                 else
84                     # we are an application
85                     APPLICATION_USER=1
86                     # no other type known (yet)
87                 fi
88         else
89                 echo "DEBUG: fail to unzip"
90         fi
91
92         echo "DEBUG: list current pkgs"
93         # TODO mktemp
94         LIST='list'
95         afm-util list --all > $LIST
96         if [ $? -ne 0 ];then
97                 echo "ERROR: afm-util list exit with error"
98                 continue
99         fi
100         if [ ! -s "$LIST" ];then
101                 echo "ERROR: afm-util list is empty"
102                 continue
103         fi
104
105         echo "DEBUG: check presence of $WGTNAME"
106         NAMEID=$(grep id\\\":\\\"${WGTNAME}@ $LIST | cut -d\" -f4 | cut -d\\ -f1)
107         if [ ! -z "$NAMEID" ];then
108                 echo "DEBUG: $WGTNAME already installed as $NAMEID"
109                 # need to kill then deinstall
110                 afm-util ps | grep -q $WGTNAME
111                 if [ $? -eq 0 ];then
112                         echo "DEBUG: kill $WGTNAME"
113                         afm-util kill $WGTNAME
114                         if [ $? -ne 0 ];then
115                                 echo "ERROR: afm-util kill"
116                                 lava-test-case afm-util-pre-kill-$WGTNAME --result fail
117                                 continue
118                         else
119                                 lava-test-case afm-util-pre-kill-$WGTNAME --result pass
120                         fi
121                 else
122                         echo "DEBUG: no need to kill $WGTNAME"
123                 fi
124
125                 echo "DEBUG: deinstall $WGTNAME"
126                 afm-util remove $NAMEID
127                 if [ $? -ne 0 ];then
128                         echo "ERROR: afm-util remove"
129                         lava-test-case afm-util-remove-$WGTNAME --result fail
130                         continue
131                 else
132                         lava-test-case afm-util-remove-$WGTNAME --result pass
133                 fi
134         else
135                 echo "DEBUG: $WGTNAME not installed"
136         fi
137         grep id $LIST
138
139         echo "DEBUG: install $wgtfile"
140         OUT="out"
141         afm-util install $wgtfile > $OUT
142         if [ $? -ne 0 ];then
143                 echo "ERROR: afm-util install"
144                 lava-test-case afm-util-install-$WGTNAME --result fail
145                 continue
146         else
147                 lava-test-case afm-util-install-$WGTNAME --result pass
148         fi
149         # message is like \"added\":\"mediaplayer@0.1\"
150         NAMEID=$(grep d\\\":\\\"${WGTNAME}@ $OUT | cut -d\" -f4 | cut -d\\ -f1)
151         if [ -z "$NAMEID" ];then
152                 echo "ERROR: Cannot get nameid"
153                 continue
154         fi
155         echo "DEBUG: $WGTNAME is installed as $NAMEID"
156
157         afm-util list --all > $LIST
158         if [ $? -ne 0 ];then
159                 echo "ERROR: afm-util list exit with error"
160                 continue
161         fi
162         if [ ! -s "$LIST" ];then
163                 echo "ERROR: afm-util list is empty"
164                 continue
165         fi
166         echo "DEBUG: Verify that $WGTNAME is installed"
167         grep -q $NAMEID $LIST
168         if [ $? -ne 0 ];then
169                 echo "ERROR: $WGTNAME is not installed"
170                 # for debugging, give full output
171                 echo "DEBUG: start of list"
172                 cat $LIST
173                 echo "DEBUG: end of list"
174         fi
175
176         afm-util info $NAMEID
177         if [ $? -ne 0 ];then
178                 echo "ERROR: afm-util info"
179                 lava-test-case afm-util-info-$WGTNAME --result fail
180         else
181                 lava-test-case afm-util-info-$WGTNAME --result pass
182         fi
183
184         echo "DEBUG: check if we see the package with systemctl list-units (before start)"
185         systemctl list-units --full | grep "afm.*$WGTNAME"
186         echo "DEBUG: check if we see the package with systemctl -a (before start)"
187         systemctl -a |grep "afm.*$WGTNAME"
188
189         echo "DEBUG: start $NAMEID"
190         do_afm_util start $NAMEID > "rid"
191         if [ $? -ne 0 ];then
192                 echo "ERROR: afm-util start"
193                 lava-test-case afm-util-start-$WGTNAME --result fail
194                 continue
195         else
196                 lava-test-case afm-util-start-$WGTNAME --result pass
197         fi
198
199         echo "DEBUG: check if we see the package with systemctl list-units (after start)"
200         systemctl list-units --full | grep "afm.*$WGTNAME"
201         echo "DEBUG: check if we see the package with systemctl -a (after start)"
202         systemctl -a |grep "afm.*$WGTNAME"
203
204         echo "DEBUG: Get RID for $NAMEID"
205         PSLIST="pslist"
206         afm-util ps > $PSLIST
207         if [ $? -ne 0 ];then
208                 echo "ERROR: afm-util ps"
209                 lava-test-case afm-util-ps-$WGTNAME --result fail
210                 continue
211         else
212                 cat $PSLIST
213                 lava-test-case afm-util-ps-$WGTNAME --result pass
214         fi
215         # TODO, compare RID with the list in $PSLIST"
216         RID="$(cat rid)"
217
218         echo "DEBUG: status $NAMEID ($RID)"
219         afm-util status $RID
220         if [ $? -ne 0 ];then
221                 echo "ERROR: afm-util status"
222                 lava-test-case afm-util-status-$WGTNAME --result fail
223                 continue
224         else
225                 lava-test-case afm-util-status-$WGTNAME --result pass
226         fi
227
228         echo "DEBUG: kill $NAMEID ($RID)"
229         afm-util kill $NAMEID
230         if [ $? -ne 0 ];then
231                 echo "ERROR: afm-util kill"
232                 lava-test-case afm-util-kill-$WGTNAME --result fail
233                 continue
234         else
235                 lava-test-case afm-util-kill-$WGTNAME --result pass
236         fi
237
238         echo "DEBUG: start2 $NAMEID"
239         do_afm_util start $NAMEID
240         if [ $? -ne 0 ];then
241                 echo "ERROR: afm-util start2"
242                 lava-test-case afm-util-start2-$WGTNAME --result fail
243                 continue
244         else
245                 lava-test-case afm-util-start2-$WGTNAME --result pass
246         fi
247 done