chiark / gitweb /
tests: create a source tarball and use that to build a repo
[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 [ $1 = "-h" ] || [ $1 = "--help" ]; then
46     set +x
47     echo "Usage: $0 '/path/to/folder/with/apks'"
48     exit 1
49 fi
50
51 if [ -z $ANDROID_HOME ]; then
52     echo "ANDROID_HOME must be set with the path to the Android SDK, i.e.: "
53     echo "  export ANDROID_HOME=/opt/android-sdk"
54     exit 1
55 fi
56
57 if [ -z $1 ]; then
58     APKDIR=`pwd`
59 else
60     APKDIR=$1
61 fi
62
63 if [ -z $WORKSPACE ]; then
64     WORKSPACE=`dirname $(pwd)`
65     echo "Setting Workspace to $WORKSPACE"
66 fi
67
68 # allow the location of the script to be overridden
69 if [ -z $fdroid ]; then
70     fdroid="$WORKSPACE/fdroid"
71 fi
72
73 # allow the location of aapt to be overridden
74 if [ -z $aapt ]; then
75     aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
76 fi
77
78
79 #------------------------------------------------------------------------------#
80 echo_header "create a source tarball and use that to build a repo"
81
82 cd $WORKSPACE
83 python setup.py sdist
84
85 REPOROOT=`create_test_dir`
86 cd $REPOROOT
87 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
88 cd $REPOROOT/fdroidserver-*/fdroidserver/getsig
89 ./make.sh
90 cd $REPOROOT
91 ./fdroidserver-*/fdroid init
92 copy_apks_into_repo $REPOROOT
93 ./fdroidserver-*/fdroid update --create-metadata
94
95
96 #------------------------------------------------------------------------------#
97 echo_header "test config checks of local_copy_dir"
98
99 REPOROOT=`create_test_dir`
100 cd $REPOROOT
101 $fdroid init
102 $fdroid update --create-metadata
103 $fdroid server update --local-copy-dir=/tmp/fdroid
104
105 # now test the errors work
106 set +e
107 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
108 if [ $? -eq 0 ]; then
109     echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
110     exit 1
111 else
112     echo "testing absolute path checker passed"
113 fi
114 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
115 if [ $? -eq 0 ]; then
116     echo "This should have failed because the path does not end with 'fdroid'!"
117     exit 1
118 else
119     echo "testing dirname exists checker passed"
120 fi
121 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
122 if [ $? -eq 0 ]; then
123     echo "This should have failed because the dirname path does not exist!"
124     exit 1
125 else
126     echo "testing dirname exists checker passed"
127 fi
128 set -e
129
130
131 #------------------------------------------------------------------------------#
132 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
133
134 REPOROOT=`create_test_dir`
135 cd $REPOROOT
136 $fdroid init
137 copy_apks_into_repo $REPOROOT
138 $fdroid update --create-metadata
139 grep -F '<application id=' repo/index.xml
140
141 LOCALCOPYDIR=`create_test_dir`/fdroid
142 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
143 NEWREPOROOT=`create_test_dir`
144 cd $NEWREPOROOT
145 $fdroid init
146 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
147
148
149 #------------------------------------------------------------------------------#
150 # check that --android-home fails when dir does not exist or is not a dir
151
152 REPOROOT=`create_test_dir`
153 KEYSTORE=$REPOROOT/keystore.jks
154 cd $REPOROOT
155 set +e
156 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
157 if [ $? -eq 0 ]; then
158     echo "This should have failed because /opt/fakeandroidhome does not exist!"
159     exit 1
160 else
161     echo "testing android-home path checker passed"
162 fi
163 TESTFILE=`create_test_file`
164 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
165 if [ $? -eq 0 ]; then
166     echo "This should have failed because $TESTFILE is a file not a dir!"
167     exit 1
168 else
169     echo "testing android-home not-dir checker passed"
170 fi
171 set -e
172
173
174 #------------------------------------------------------------------------------#
175 echo_header "check that fake android home passes `fdroid init`"
176
177 REPOROOT=`create_test_dir`
178 FAKE_ANDROID_HOME=`create_test_dir`
179 create_fake_android_home $FAKE_ANDROID_HOME
180 KEYSTORE=$REPOROOT/keystore.jks
181 cd $REPOROOT
182 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
183
184
185 #------------------------------------------------------------------------------#
186 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
187
188 REPOROOT=`create_test_dir`
189 FAKE_ANDROID_HOME=`create_test_dir`
190 create_fake_android_home $FAKE_ANDROID_HOME
191 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
192 KEYSTORE=$REPOROOT/keystore.jks
193 cd $REPOROOT
194 set +e
195 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
196 [ $? -eq 0 ] && exit 1
197 set -e
198
199
200 #------------------------------------------------------------------------------#
201 echo_header "check that --android-home overrides ANDROID_HOME"
202
203 REPOROOT=`create_test_dir`
204 FAKE_ANDROID_HOME=`create_test_dir`
205 create_fake_android_home $FAKE_ANDROID_HOME
206 KEYSTORE=$REPOROOT/keystore.jks
207 cd $REPOROOT
208 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
209 set +e
210 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
211 if [ $? -ne 0 ]; then
212     echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
213     exit 1
214 fi
215 set -e
216
217
218 #------------------------------------------------------------------------------#
219 # In this case, ANDROID_HOME is set to a fake, non-working version that will
220 # be detected by fdroid as an Android SDK install.  It should use the path set
221 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
222 # in ANDROID_HOME, it won't work because it is a fake one.  Only
223 # --android-home provides a working one.
224 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
225
226 REPOROOT=`create_test_dir`
227 KEYSTORE=$REPOROOT/keystore.jks
228 FAKE_ANDROID_HOME=`create_test_dir`
229 create_fake_android_home $FAKE_ANDROID_HOME
230 STORED_ANDROID_HOME=$ANDROID_HOME
231 unset ANDROID_HOME
232 echo "ANDROID_HOME: $ANDROID_HOME"
233 cd $REPOROOT
234 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
235 test -e $KEYSTORE
236 copy_apks_into_repo $REPOROOT
237 $fdroid update --create-metadata
238 grep -F '<application id=' repo/index.xml
239 test -e repo/index.xml
240 test -e repo/index.jar
241 export ANDROID_HOME=$STORED_ANDROID_HOME
242
243
244 #------------------------------------------------------------------------------#
245 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
246
247 REPOROOT=`create_test_dir`
248 cd $REPOROOT
249 mkdir repo
250 copy_apks_into_repo $REPOROOT
251 $fdroid init
252 $fdroid update --create-metadata
253 grep -F '<application id=' repo/index.xml
254
255
256 #------------------------------------------------------------------------------#
257 echo_header "setup a new repo from scratch and generate a keystore"
258
259 REPOROOT=`create_test_dir`
260 KEYSTORE=$REPOROOT/keystore.jks
261 cd $REPOROOT
262 $fdroid init --keystore $KEYSTORE
263 test -e $KEYSTORE
264 copy_apks_into_repo $REPOROOT
265 $fdroid update --create-metadata
266 test -e repo/index.xml
267 test -e repo/index.jar
268 grep -F '<application id=' repo/index.xml
269
270
271 #------------------------------------------------------------------------------#
272 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
273
274 REPOROOT=`create_test_dir`
275 KEYSTORE=$REPOROOT/keystore.jks
276 cd $REPOROOT
277 $fdroid init --keystore $KEYSTORE
278 test -e $KEYSTORE
279 copy_apks_into_repo $REPOROOT
280 $fdroid update --create-metadata
281 test -e repo/index.xml
282 test -e repo/index.jar
283 grep -F '<application id=' repo/index.xml
284 cp $WORKSPACE/tests/urzip.apk $REPOROOT/
285 $fdroid update --create-metadata
286 test -e repo/index.xml
287 test -e repo/index.jar
288 grep -F '<application id=' repo/index.xml
289
290
291 #------------------------------------------------------------------------------#
292 echo_header "setup a new repo from scratch with a HSM/smartcard"
293
294 REPOROOT=`create_test_dir`
295 cd $REPOROOT
296 $fdroid init --keystore NONE
297 test -e opensc-fdroid.cfg
298 test ! -e NONE
299
300
301 echo SUCCESS