3 set -e # quit script on error
4 set -x # show each command as it is executed
7 echo "=============================================================================="
11 copy_apks_into_repo() {
13 for f in `find $APKDIR -name '*.apk' | grep -F -v -e unaligned -e unsigned -e badsig -e badcert`; 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
26 # keep this as an old version to test the automatic parsing of build-tools
27 # verion numbers in `fdroid init`
28 create_fake_android_home() {
30 mkdir $1/platform-tools
32 mkdir $1/build-tools/19.0.2
33 touch $1/build-tools/19.0.2/aapt
37 test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
38 TMPDIR=$WORKSPACE/.testfiles mktemp -d
42 test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
43 TMPDIR=$WORKSPACE/.testfiles mktemp
46 #------------------------------------------------------------------------------#
49 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
51 echo "Usage: $0 '/path/to/folder/with/apks'"
55 if [ -z "$ANDROID_HOME" ]; then
56 echo "ANDROID_HOME must be set with the path to the Android SDK, i.e.: "
57 echo " export ANDROID_HOME=/opt/android-sdk"
67 if [ -z $WORKSPACE ]; then
68 WORKSPACE=`dirname $(pwd)`
69 echo "Setting Workspace to $WORKSPACE"
72 # allow the location of the script to be overridden
73 if [ -z $fdroid ]; then
74 fdroid="$WORKSPACE/fdroid"
77 # allow the location of aapt to be overridden
79 aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
82 # allow the location of python to be overridden
83 if [ -z $python ]; then
88 #------------------------------------------------------------------------------#
89 echo_header "run commit hooks"
95 #------------------------------------------------------------------------------#
96 echo_header "test python getsig replacement"
98 cd $WORKSPACE/tests/getsig
100 for testcase in $WORKSPACE/tests/*.TestCase; do
105 #------------------------------------------------------------------------------#
106 echo_header "build the TeX manual"
109 ./gendocs.sh -o html --email admin@f-droid.org fdroid "F-Droid Server Manual"
112 #------------------------------------------------------------------------------#
113 echo_header "test metadata checks"
115 REPOROOT=`create_test_dir`
120 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
124 if [ $? -eq 0 ]; then
125 echo "This should have failed because there is no metadata!"
128 echo "testing metadata checks passed"
132 mkdir $REPOROOT/metadata/
133 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
136 # now make a fake duplicate
137 touch $REPOROOT/metadata/org.smssecure.smssecure.yaml
141 if [ $? -eq 0 ]; then
142 echo "This should have failed because there is a duplicate metadata file!"
145 echo "testing duplicate metadata checks passed"
150 #------------------------------------------------------------------------------#
151 echo_header "create a source tarball and use that to build a repo"
154 $python setup.py sdist
156 REPOROOT=`create_test_dir`
158 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
160 ./fdroidserver-*/fdroid init
161 copy_apks_into_repo $REPOROOT
162 ./fdroidserver-*/fdroid update --create-metadata
165 #------------------------------------------------------------------------------#
166 echo_header "test config checks of local_copy_dir"
168 REPOROOT=`create_test_dir`
171 $fdroid update --create-metadata
173 $fdroid server update --local-copy-dir=/tmp/fdroid
175 # now test the errors work
177 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
178 if [ $? -eq 0 ]; then
179 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
182 echo "testing absolute path checker passed"
184 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
185 if [ $? -eq 0 ]; then
186 echo "This should have failed because the path does not end with 'fdroid'!"
189 echo "testing dirname exists checker passed"
191 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
192 if [ $? -eq 0 ]; then
193 echo "This should have failed because the dirname path does not exist!"
196 echo "testing dirname exists checker passed"
201 #------------------------------------------------------------------------------#
202 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
204 REPOROOT=`create_test_dir`
207 copy_apks_into_repo $REPOROOT
208 $fdroid update --create-metadata
210 grep -F '<application id=' repo/index.xml > /dev/null
212 LOCALCOPYDIR=`create_test_dir`/fdroid
213 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
214 NEWREPOROOT=`create_test_dir`
217 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
220 #------------------------------------------------------------------------------#
221 # check that --android-home fails when dir does not exist or is not a dir
223 REPOROOT=`create_test_dir`
224 KEYSTORE=$REPOROOT/keystore.jks
227 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
228 if [ $? -eq 0 ]; then
229 echo "This should have failed because /opt/fakeandroidhome does not exist!"
232 echo "testing android-home path checker passed"
234 TESTFILE=`create_test_file`
235 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
236 if [ $? -eq 0 ]; then
237 echo "This should have failed because $TESTFILE is a file not a dir!"
240 echo "testing android-home not-dir checker passed"
245 #------------------------------------------------------------------------------#
246 echo_header "check that fake android home passes 'fdroid init'"
248 REPOROOT=`create_test_dir`
249 FAKE_ANDROID_HOME=`create_test_dir`
250 create_fake_android_home $FAKE_ANDROID_HOME
251 KEYSTORE=$REPOROOT/keystore.jks
253 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
256 #------------------------------------------------------------------------------#
257 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
259 if [ -e /usr/bin/aapt ]; then
260 echo "/usr/bin/aapt exists, not running test"
262 REPOROOT=`create_test_dir`
263 FAKE_ANDROID_HOME=`create_test_dir`
264 create_fake_android_home $FAKE_ANDROID_HOME
265 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
266 KEYSTORE=$REPOROOT/keystore.jks
269 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
270 [ $? -eq 0 ] && exit 1
275 #------------------------------------------------------------------------------#
276 echo_header "check that --android-home overrides ANDROID_HOME"
278 REPOROOT=`create_test_dir`
279 FAKE_ANDROID_HOME=`create_test_dir`
280 create_fake_android_home $FAKE_ANDROID_HOME
281 KEYSTORE=$REPOROOT/keystore.jks
283 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
285 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
286 if [ $? -ne 0 ]; then
287 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
293 #------------------------------------------------------------------------------#
294 # In this case, ANDROID_HOME is set to a fake, non-working version that will
295 # be detected by fdroid as an Android SDK install. It should use the path set
296 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
297 # in ANDROID_HOME, it won't work because it is a fake one. Only
298 # --android-home provides a working one.
299 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
301 REPOROOT=`create_test_dir`
302 KEYSTORE=$REPOROOT/keystore.jks
303 FAKE_ANDROID_HOME=`create_test_dir`
304 create_fake_android_home $FAKE_ANDROID_HOME
305 STORED_ANDROID_HOME=$ANDROID_HOME
307 echo "ANDROID_HOME: $ANDROID_HOME"
309 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
311 copy_apks_into_repo $REPOROOT
312 $fdroid update --create-metadata
314 grep -F '<application id=' repo/index.xml > /dev/null
315 test -e repo/index.xml
316 test -e repo/index.jar
317 export ANDROID_HOME=$STORED_ANDROID_HOME
320 #------------------------------------------------------------------------------#
321 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
323 REPOROOT=`create_test_dir`
326 copy_apks_into_repo $REPOROOT
328 $fdroid update --create-metadata
330 grep -F '<application id=' repo/index.xml > /dev/null
333 #------------------------------------------------------------------------------#
334 echo_header "setup a new repo from scratch and generate a keystore"
336 REPOROOT=`create_test_dir`
337 KEYSTORE=$REPOROOT/keystore.jks
339 $fdroid init --keystore $KEYSTORE
341 copy_apks_into_repo $REPOROOT
342 $fdroid update --create-metadata
344 test -e repo/index.xml
345 test -e repo/index.jar
346 grep -F '<application id=' repo/index.xml > /dev/null
349 #------------------------------------------------------------------------------#
350 echo_header "setup a new repo manually and generate a keystore"
352 REPOROOT=`create_test_dir`
353 KEYSTORE=$REPOROOT/keystore.jks
356 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
360 if [ $? -eq 0 ]; then
361 echo "This should have failed because this repo has no keystore!"
364 echo '`fdroid update` prompted to add keystore'
367 $fdroid update --create-key
369 copy_apks_into_repo $REPOROOT
370 $fdroid update --create-metadata
372 test -e repo/index.xml
373 test -e repo/index.jar
374 grep -F '<application id=' repo/index.xml > /dev/null
377 #------------------------------------------------------------------------------#
378 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
380 REPOROOT=`create_test_dir`
381 KEYSTORE=$REPOROOT/keystore.jks
383 $fdroid init --keystore $KEYSTORE
385 copy_apks_into_repo $REPOROOT
386 $fdroid update --create-metadata
388 test -e repo/index.xml
389 test -e repo/index.jar
390 grep -F '<application id=' repo/index.xml > /dev/null
391 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
392 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
393 $fdroid update --create-metadata
395 test -e repo/index.xml
396 test -e repo/index.jar
397 grep -F '<application id=' repo/index.xml > /dev/null
400 #------------------------------------------------------------------------------#
401 echo_header "setup a new repo from scratch with a HSM/smartcard"
403 REPOROOT=`create_test_dir`
405 $fdroid init --keystore NONE
406 test -e opensc-fdroid.cfg
410 #------------------------------------------------------------------------------#
411 echo_header "setup a new repo with no keystore, add APK, and update"
413 REPOROOT=`create_test_dir`
414 KEYSTORE=$REPOROOT/keystore.jks
417 touch fdroid-icon.png
419 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
421 $fdroid update --create-metadata
422 if [ $? -eq 0 ]; then
423 echo "This should have failed because this repo has no keystore!"
426 echo '`fdroid update` prompted to add keystore'
430 # now set up fake, non-working keystore setup
432 echo "keystore = \"$KEYSTORE\"" >> config.py
433 echo 'repo_keyalias = "foo"' >> config.py
434 echo 'keystorepass = "foo"' >> config.py
435 echo 'keypass = "foo"' >> config.py
437 $fdroid update --create-metadata
438 if [ $? -eq 0 ]; then
439 echo "This should have failed because this repo has a bad/fake keystore!"
442 echo '`fdroid update` prompted to add keystore'
447 #------------------------------------------------------------------------------#
448 echo_header "setup a new repo with keystore with APK, update, then without key"
450 REPOROOT=`create_test_dir`
451 KEYSTORE=$REPOROOT/keystore.jks
453 $fdroid init --keystore $KEYSTORE
455 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
456 $fdroid update --create-metadata
458 test -e repo/index.xml
459 test -e repo/index.jar
460 grep -F '<application id=' repo/index.xml > /dev/null
462 # now set fake repo_keyalias
463 sed -i 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
466 if [ $? -eq 0 ]; then
467 echo "This should have failed because this repo has a bad repo_keyalias!"
470 echo '`fdroid update` prompted to add keystore'
474 # try creating a new keystore, but fail because the old one is there
477 $fdroid update --create-key
478 if [ $? -eq 0 ]; then
479 echo "This should have failed because a keystore is already there!"
482 echo '`fdroid update` complained about existing keystore'
486 # now actually create the key with the existing settings
489 $fdroid update --create-key
493 #------------------------------------------------------------------------------#
495 # remove this to prevent git conflicts and complaining
496 rm -rf $WORKSPACE/fdroidserver.egg-info/