3 set -e # quit script on error
6 { echo -e "==============================================================================\n$1"; } 2>/dev/null
9 copy_apks_into_repo() {
11 for f in `find $APKDIR -name '*.apk' | grep -F -v -e unaligned -e unsigned -e badsig -e badcert`; do
12 name=$(basename $(dirname `dirname $f`))
13 apk=`$aapt dump badging "$f" | sed -n "s,^package: name='\(.*\)' versionCode='\([0-9][0-9]*\)' .*,\1_\2.apk,p"`
14 test $f -nt repo/$apk && rm -f repo/$apk # delete existing if $f is newer
15 if [ ! -e repo/$apk ] && [ ! -e archive/$apk ]; then
16 echo "$f --> repo/$apk"
17 ln $f $1/repo/$apk || \
18 rsync -axv $f $1/repo/$apk # rsync if hard link is not possible
24 # keep this as an old version to test the automatic parsing of build-tools
25 # verion numbers in `fdroid init`
26 create_fake_android_home() {
28 mkdir $1/platform-tools
30 mkdir $1/build-tools/19.0.2
31 touch $1/build-tools/19.0.2/aapt
35 test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
36 mktemp -d $WORKSPACE/.testfiles/run-tests.XXXX
40 test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
41 TMPDIR=$WORKSPACE/.testfiles mktemp
44 #------------------------------------------------------------------------------#
47 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
49 echo "Usage: $0 '/path/to/folder/with/apks'"
53 if [ -z "$ANDROID_HOME" ]; then
54 echo "ANDROID_HOME must be set with the path to the Android SDK, i.e.: "
55 echo " export ANDROID_HOME=/opt/android-sdk"
69 if [ -z $WORKSPACE ]; then
70 WORKSPACE=`dirname $(pwd)`
71 echo "Setting Workspace to $WORKSPACE"
74 # allow the location of the script to be overridden
75 if [ -z $fdroid ]; then
76 fdroid="$WORKSPACE/fdroid"
79 # allow the location of aapt to be overridden
81 aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
84 # allow the location of python to be overridden
85 if [ -z $python ]; then
89 set -x # show each command as it is executed
91 #------------------------------------------------------------------------------#
92 echo_header "run commit hooks"
98 #------------------------------------------------------------------------------#
99 echo_header "test python getsig replacement"
101 cd $WORKSPACE/tests/getsig
103 for testcase in $WORKSPACE/tests/*.TestCase; do
108 #------------------------------------------------------------------------------#
109 echo_header "print fdroid version"
114 #------------------------------------------------------------------------------#
115 echo_header "build the TeX manual"
118 # this is only ever generated officially on GNU/Linux
119 if [ `uname -s` == "Linux" ]; then
120 ./gendocs.sh -o html --email admin@f-droid.org fdroid "F-Droid Server Manual"
124 #------------------------------------------------------------------------------#
125 echo_header "test metadata checks"
127 REPOROOT=`create_test_dir`
132 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
136 if [ $? -eq 0 ]; then
137 echo "This should have failed because there is no metadata!"
140 echo "testing metadata checks passed"
144 mkdir $REPOROOT/metadata/
145 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
148 # now make a fake duplicate
149 touch $REPOROOT/metadata/org.smssecure.smssecure.yaml
153 if [ $? -eq 0 ]; then
154 echo "This should have failed because there is a duplicate metadata file!"
157 echo "testing duplicate metadata checks passed"
162 #------------------------------------------------------------------------------#
163 echo_header "ensure commands that don't need the JDK work without a JDK configed"
165 REPOROOT=`create_test_dir`
169 echo "License:GPL" >> metadata/fake.txt
170 echo "Summary:Yup still fake" >> metadata/fake.txt
171 echo "Categories:Internet" >> metadata/fake.txt
172 echo "Description:" >> metadata/fake.txt
173 echo "this is fake" >> metadata/fake.txt
174 echo "." >> metadata/fake.txt
176 # fake that no JDKs are available
177 echo 'java_paths = {}' > config.py
179 LOCAL_COPY_DIR=`create_test_dir`/fdroid
180 mkdir -p $LOCAL_COPY_DIR/repo
181 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py
187 $fdroid rewritemeta fake
188 $fdroid server update
191 # run these to get their output, but the are not setup, so don't fail
192 $fdroid build || true
193 $fdroid import || true
194 $fdroid install || true
197 #------------------------------------------------------------------------------#
198 echo_header "create a source tarball and use that to build a repo"
201 $python setup.py sdist
203 REPOROOT=`create_test_dir`
205 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
207 ./fdroidserver-*/fdroid init
208 copy_apks_into_repo $REPOROOT
209 ./fdroidserver-*/fdroid update --create-metadata --verbose
212 #------------------------------------------------------------------------------#
213 echo_header "test config checks of local_copy_dir"
215 REPOROOT=`create_test_dir`
218 $fdroid update --create-metadata --verbose
220 $fdroid server update --local-copy-dir=/tmp/fdroid
222 # now test the errors work
224 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
225 if [ $? -eq 0 ]; then
226 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
229 echo "testing absolute path checker passed"
231 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
232 if [ $? -eq 0 ]; then
233 echo "This should have failed because the path does not end with 'fdroid'!"
236 echo "testing dirname exists checker passed"
238 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
239 if [ $? -eq 0 ]; then
240 echo "This should have failed because the dirname path does not exist!"
243 echo "testing dirname exists checker passed"
248 #------------------------------------------------------------------------------#
249 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
251 REPOROOT=`create_test_dir`
254 copy_apks_into_repo $REPOROOT
255 $fdroid update --create-metadata --verbose
257 grep -F '<application id=' repo/index.xml > /dev/null
259 LOCALCOPYDIR=`create_test_dir`/fdroid
260 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
261 NEWREPOROOT=`create_test_dir`
264 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
267 #------------------------------------------------------------------------------#
268 # check that --android-home fails when dir does not exist or is not a dir
270 REPOROOT=`create_test_dir`
271 KEYSTORE=$REPOROOT/keystore.jks
274 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
275 if [ $? -eq 0 ]; then
276 echo "This should have failed because /opt/fakeandroidhome does not exist!"
279 echo "testing android-home path checker passed"
281 TESTFILE=`create_test_file`
282 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
283 if [ $? -eq 0 ]; then
284 echo "This should have failed because $TESTFILE is a file not a dir!"
287 echo "testing android-home not-dir checker passed"
292 #------------------------------------------------------------------------------#
293 echo_header "check that fake android home passes 'fdroid init'"
295 REPOROOT=`create_test_dir`
296 FAKE_ANDROID_HOME=`create_test_dir`
297 create_fake_android_home $FAKE_ANDROID_HOME
298 KEYSTORE=$REPOROOT/keystore.jks
300 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
303 #------------------------------------------------------------------------------#
304 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
306 if [ -e /usr/bin/aapt ]; then
307 echo "/usr/bin/aapt exists, not running test"
309 REPOROOT=`create_test_dir`
310 FAKE_ANDROID_HOME=`create_test_dir`
311 create_fake_android_home $FAKE_ANDROID_HOME
312 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
313 KEYSTORE=$REPOROOT/keystore.jks
316 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
317 [ $? -eq 0 ] && exit 1
322 #------------------------------------------------------------------------------#
323 echo_header "check that --android-home overrides ANDROID_HOME"
325 REPOROOT=`create_test_dir`
326 FAKE_ANDROID_HOME=`create_test_dir`
327 create_fake_android_home $FAKE_ANDROID_HOME
328 KEYSTORE=$REPOROOT/keystore.jks
330 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
332 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
333 if [ $? -ne 0 ]; then
334 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
340 #------------------------------------------------------------------------------#
341 # In this case, ANDROID_HOME is set to a fake, non-working version that will
342 # be detected by fdroid as an Android SDK install. It should use the path set
343 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
344 # in ANDROID_HOME, it won't work because it is a fake one. Only
345 # --android-home provides a working one.
346 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
348 REPOROOT=`create_test_dir`
349 KEYSTORE=$REPOROOT/keystore.jks
350 FAKE_ANDROID_HOME=`create_test_dir`
351 create_fake_android_home $FAKE_ANDROID_HOME
352 STORED_ANDROID_HOME=$ANDROID_HOME
354 echo "ANDROID_HOME: $ANDROID_HOME"
356 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
358 copy_apks_into_repo $REPOROOT
359 $fdroid update --create-metadata --verbose
361 grep -F '<application id=' repo/index.xml > /dev/null
362 test -e repo/index.xml
363 test -e repo/index.jar
364 export ANDROID_HOME=$STORED_ANDROID_HOME
367 #------------------------------------------------------------------------------#
368 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
370 REPOROOT=`create_test_dir`
373 copy_apks_into_repo $REPOROOT
375 $fdroid update --create-metadata --verbose
377 grep -F '<application id=' repo/index.xml > /dev/null
380 #------------------------------------------------------------------------------#
381 echo_header "setup a new repo from scratch and generate a keystore"
383 REPOROOT=`create_test_dir`
384 KEYSTORE=$REPOROOT/keystore.jks
386 $fdroid init --keystore $KEYSTORE
388 copy_apks_into_repo $REPOROOT
389 $fdroid update --create-metadata --verbose
391 test -e repo/index.xml
392 test -e repo/index.jar
393 grep -F '<application id=' repo/index.xml > /dev/null
396 #------------------------------------------------------------------------------#
397 echo_header "setup a new repo manually and generate a keystore"
399 REPOROOT=`create_test_dir`
400 KEYSTORE=$REPOROOT/keystore.jks
403 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
407 if [ $? -eq 0 ]; then
408 echo "This should have failed because this repo has no keystore!"
411 echo '`fdroid update` prompted to add keystore'
414 $fdroid update --create-key
416 copy_apks_into_repo $REPOROOT
417 $fdroid update --create-metadata --verbose
419 test -e repo/index.xml
420 test -e repo/index.jar
421 grep -F '<application id=' repo/index.xml > /dev/null
424 #------------------------------------------------------------------------------#
425 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
427 REPOROOT=`create_test_dir`
428 KEYSTORE=$REPOROOT/keystore.jks
430 $fdroid init --keystore $KEYSTORE
432 copy_apks_into_repo $REPOROOT
433 $fdroid update --create-metadata --verbose
435 test -e repo/index.xml
436 test -e repo/index.jar
437 grep -F '<application id=' repo/index.xml > /dev/null
438 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
439 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
440 $fdroid update --create-metadata --verbose
442 test -e repo/index.xml
443 test -e repo/index.jar
444 grep -F '<application id=' repo/index.xml > /dev/null
447 #------------------------------------------------------------------------------#
448 echo_header "setup a new repo from scratch with a HSM/smartcard"
449 REPOROOT=`create_test_dir`
451 $fdroid init --keystore NONE
452 test -e opensc-fdroid.cfg
456 #------------------------------------------------------------------------------#
457 echo_header "setup a new repo with no keystore, add APK, and update"
459 REPOROOT=`create_test_dir`
460 KEYSTORE=$REPOROOT/keystore.jks
463 touch fdroid-icon.png
465 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
467 $fdroid update --create-metadata --verbose
468 if [ $? -eq 0 ]; then
469 echo "This should have failed because this repo has no keystore!"
472 echo '`fdroid update` prompted to add keystore'
476 # now set up fake, non-working keystore setup
478 echo "keystore = \"$KEYSTORE\"" >> config.py
479 echo 'repo_keyalias = "foo"' >> config.py
480 echo 'keystorepass = "foo"' >> config.py
481 echo 'keypass = "foo"' >> config.py
483 $fdroid update --create-metadata --verbose
484 if [ $? -eq 0 ]; then
485 echo "This should have failed because this repo has a bad/fake keystore!"
488 echo '`fdroid update` prompted to add keystore'
493 #------------------------------------------------------------------------------#
494 echo_header "setup a new repo with keystore with APK, update, then without key"
496 REPOROOT=`create_test_dir`
497 KEYSTORE=$REPOROOT/keystore.jks
499 $fdroid init --keystore $KEYSTORE
501 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
502 $fdroid update --create-metadata --verbose
504 test -e repo/index.xml
505 test -e repo/index.jar
506 grep -F '<application id=' repo/index.xml > /dev/null
508 # now set fake repo_keyalias
509 sed -i.tmp 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
512 if [ $? -eq 0 ]; then
513 echo "This should have failed because this repo has a bad repo_keyalias!"
516 echo '`fdroid update` prompted to add keystore'
520 # try creating a new keystore, but fail because the old one is there
523 $fdroid update --create-key
524 if [ $? -eq 0 ]; then
525 echo "This should have failed because a keystore is already there!"
528 echo '`fdroid update` complained about existing keystore'
532 # now actually create the key with the existing settings
535 $fdroid update --create-key
539 #------------------------------------------------------------------------------#
541 # remove this to prevent git conflicts and complaining
542 rm -rf $WORKSPACE/fdroidserver.egg-info/