chiark / gitweb /
run-tests: find current version of aapt in folder rather than in PATH
[fdroidserver.git] / tests / run-tests
1 #!/bin/bash
2
3 set -e # quit script on error
4 set -x # show each command as it is executed
5
6 echo_header() {
7     echo "=============================================================================="
8     echo $1
9 }
10
11 copy_apks_into_repo() {
12     set +x
13     for f in `find $APKDIR -name '*.apk' | grep -F -v -e unaligned -e unsigned`; do
14         name=$(basename $(dirname `dirname $f`))
15         apk=`$aapt dump badging "$f" | sed -n "s,^package: name='\(.*\)' versionCode='\([0-9][0-9]*\)' .*,\1_\2.apk,p"`
16         test $f -nt repo/$apk && rm -f repo/$apk  # delete existing if $f is newer
17         if [ ! -e repo/$apk ] && [ ! -e archive/$apk ]; then
18             echo "$f --> repo/$apk"
19             ln $f $1/repo/$apk || \
20                 rsync -axv $f $1/repo/$apk # rsync if hard link is not possible
21         fi
22     done
23     set -x
24 }
25
26 create_fake_android_home() {
27     mkdir $1/build-tools
28     mkdir $1/build-tools/19.1.0
29     touch $1/build-tools/19.1.0/aapt
30 }
31
32 create_test_dir() {
33     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
34     mktemp --directory --tmpdir=$WORKSPACE/.testfiles
35 }
36
37 create_test_file() {
38     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
39     mktemp --tmpdir=$WORKSPACE/.testfiles
40 }
41
42 #------------------------------------------------------------------------------#
43 # "main"
44
45 if [ $# -ne 1 ]; then
46     echo "Usage: $0 '/path/to/folder/with/apks'"
47     exit 1
48 fi
49
50 if [ -z $ANDROID_HOME ]; then
51     echo "ANDROID_HOME must be set with the path to the Android SDK, i.e.: "
52     echo "  export ANDROID_HOME=/opt/android-sdk"
53     exit 1
54 fi
55
56 APKDIR=$1
57
58 if [ -z $WORKSPACE ]; then
59     WORKSPACE=`dirname $(pwd)`
60     echo "Setting Workspace to $WORKSPACE"
61 fi
62
63 # allow the location of the script to be overridden
64 if [ -z $fdroid ]; then
65     fdroid="$WORKSPACE/fdroid"
66 fi
67
68 # allow the location of aapt to be overridden
69 if [ -z $aapt ]; then
70     aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
71 fi
72
73 #------------------------------------------------------------------------------#
74 echo_header "setup a new repo from scratch using ANDROID_HOME"
75
76 REPOROOT=`create_test_dir`
77 cd $REPOROOT
78 $fdroid init
79 copy_apks_into_repo $REPOROOT
80 $fdroid update --create-metadata
81 grep -F '<application id=' repo/index.xml
82
83
84 #------------------------------------------------------------------------------#
85 # check that --android-home fails when dir does not exist or is not a dir
86
87 REPOROOT=`create_test_dir`
88 KEYSTORE=$REPOROOT/keystore.jks
89 cd $REPOROOT
90 set +e
91 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
92 if [ $? -eq 0 ]; then
93     echo "This should have failed because /opt/fakeandroidhome does not exist!"
94     exit 1
95 else
96     echo "testing android-home path checker passed"
97 fi
98 TESTFILE=`create_test_file`
99 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
100 if [ $? -eq 0 ]; then
101     echo "This should have failed because $TESTFILE is a file not a dir!"
102     exit 1
103 else
104     echo "testing android-home not-dir checker passed"
105 fi
106 set -e
107
108
109 #------------------------------------------------------------------------------#
110 echo_header "check that fake android home passes `fdroid init`"
111
112 REPOROOT=`create_test_dir`
113 FAKE_ANDROID_HOME=`create_test_dir`
114 create_fake_android_home $FAKE_ANDROID_HOME
115 KEYSTORE=$REPOROOT/keystore.jks
116 cd $REPOROOT
117 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
118
119
120 #------------------------------------------------------------------------------#
121 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
122
123 REPOROOT=`create_test_dir`
124 FAKE_ANDROID_HOME=`create_test_dir`
125 create_fake_android_home $FAKE_ANDROID_HOME
126 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
127 KEYSTORE=$REPOROOT/keystore.jks
128 cd $REPOROOT
129 set +e
130 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
131 [ $? -eq 0 ] && exit 1
132 set -e
133
134
135 #------------------------------------------------------------------------------#
136 echo_header "check that --android-home overrides ANDROID_HOME"
137
138 REPOROOT=`create_test_dir`
139 FAKE_ANDROID_HOME=`create_test_dir`
140 create_fake_android_home $FAKE_ANDROID_HOME
141 KEYSTORE=$REPOROOT/keystore.jks
142 cd $REPOROOT
143 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
144 set +e
145 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
146 if [ $? -ne 0 ]; then
147     echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
148     exit 1
149 fi
150 set -e
151
152
153 #------------------------------------------------------------------------------#
154 # In this case, ANDROID_HOME is set to a fake, non-working version that will
155 # be detected by fdroid as an Android SDK install.  It should use the path set
156 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
157 # in ANDROID_HOME, it won't work because it is a fake one.  Only
158 # --android-home provides a working one.
159 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
160
161 REPOROOT=`create_test_dir`
162 KEYSTORE=$REPOROOT/keystore.jks
163 FAKE_ANDROID_HOME=`create_test_dir`
164 create_fake_android_home $FAKE_ANDROID_HOME
165 STORED_ANDROID_HOME=$ANDROID_HOME
166 unset ANDROID_HOME
167 echo "ANDROID_HOME: $ANDROID_HOME"
168 cd $REPOROOT
169 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
170 test -e $KEYSTORE
171 copy_apks_into_repo $REPOROOT
172 $fdroid update --create-metadata
173 grep -F '<application id=' repo/index.xml
174 test -e repo/index.xml
175 test -e repo/index.jar
176 export ANDROID_HOME=$STORED_ANDROID_HOME
177
178
179 #------------------------------------------------------------------------------#
180 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
181
182 REPOROOT=`create_test_dir`
183 cd $REPOROOT
184 mkdir repo
185 copy_apks_into_repo $REPOROOT
186 $fdroid init
187 $fdroid update --create-metadata
188 grep -F '<application id=' repo/index.xml
189
190
191 #------------------------------------------------------------------------------#
192 echo_header "setup a new repo from scratch and generate a keystore"
193
194 REPOROOT=`create_test_dir`
195 KEYSTORE=$REPOROOT/keystore.jks
196 cd $REPOROOT
197 $fdroid init --keystore $KEYSTORE
198 test -e $KEYSTORE
199 copy_apks_into_repo $REPOROOT
200 $fdroid update --create-metadata
201 test -e repo/index.xml
202 test -e repo/index.jar
203 grep -F '<application id=' repo/index.xml
204
205
206 #------------------------------------------------------------------------------#
207 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
208
209 REPOROOT=`create_test_dir`
210 KEYSTORE=$REPOROOT/keystore.jks
211 cd $REPOROOT
212 $fdroid init --keystore $KEYSTORE
213 test -e $KEYSTORE
214 copy_apks_into_repo $REPOROOT
215 $fdroid update --create-metadata
216 test -e repo/index.xml
217 test -e repo/index.jar
218 grep -F '<application id=' repo/index.xml
219 cp $WORKSPACE/tests/urzip.apk $REPOROOT/
220 $fdroid update --create-metadata
221 test -e repo/index.xml
222 test -e repo/index.jar
223 grep -F '<application id=' repo/index.xml
224
225
226 #------------------------------------------------------------------------------#
227 echo_header "setup a new repo from scratch with a HSM/smartcard"
228
229 REPOROOT=`create_test_dir`
230 cd $REPOROOT
231 $fdroid init --keystore NONE
232 test -e opensc-fdroid.cfg
233 test ! -e NONE
234
235
236 echo SUCCESS