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 "print fdroid version"
111 #------------------------------------------------------------------------------#
112 echo_header "build the TeX manual"
115 ./gendocs.sh -o html --email admin@f-droid.org fdroid "F-Droid Server Manual"
118 #------------------------------------------------------------------------------#
119 echo_header "test metadata checks"
121 REPOROOT=`create_test_dir`
126 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
130 if [ $? -eq 0 ]; then
131 echo "This should have failed because there is no metadata!"
134 echo "testing metadata checks passed"
138 mkdir $REPOROOT/metadata/
139 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
142 # now make a fake duplicate
143 touch $REPOROOT/metadata/org.smssecure.smssecure.yaml
147 if [ $? -eq 0 ]; then
148 echo "This should have failed because there is a duplicate metadata file!"
151 echo "testing duplicate metadata checks passed"
156 #------------------------------------------------------------------------------#
157 echo_header "create a source tarball and use that to build a repo"
160 $python setup.py sdist
162 REPOROOT=`create_test_dir`
164 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
166 ./fdroidserver-*/fdroid init
167 copy_apks_into_repo $REPOROOT
168 ./fdroidserver-*/fdroid update --create-metadata
171 #------------------------------------------------------------------------------#
172 echo_header "test config checks of local_copy_dir"
174 REPOROOT=`create_test_dir`
177 $fdroid update --create-metadata
179 $fdroid server update --local-copy-dir=/tmp/fdroid
181 # now test the errors work
183 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
184 if [ $? -eq 0 ]; then
185 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
188 echo "testing absolute path checker passed"
190 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
191 if [ $? -eq 0 ]; then
192 echo "This should have failed because the path does not end with 'fdroid'!"
195 echo "testing dirname exists checker passed"
197 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
198 if [ $? -eq 0 ]; then
199 echo "This should have failed because the dirname path does not exist!"
202 echo "testing dirname exists checker passed"
207 #------------------------------------------------------------------------------#
208 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
210 REPOROOT=`create_test_dir`
213 copy_apks_into_repo $REPOROOT
214 $fdroid update --create-metadata
216 grep -F '<application id=' repo/index.xml > /dev/null
218 LOCALCOPYDIR=`create_test_dir`/fdroid
219 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
220 NEWREPOROOT=`create_test_dir`
223 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
226 #------------------------------------------------------------------------------#
227 # check that --android-home fails when dir does not exist or is not a dir
229 REPOROOT=`create_test_dir`
230 KEYSTORE=$REPOROOT/keystore.jks
233 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
234 if [ $? -eq 0 ]; then
235 echo "This should have failed because /opt/fakeandroidhome does not exist!"
238 echo "testing android-home path checker passed"
240 TESTFILE=`create_test_file`
241 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
242 if [ $? -eq 0 ]; then
243 echo "This should have failed because $TESTFILE is a file not a dir!"
246 echo "testing android-home not-dir checker passed"
251 #------------------------------------------------------------------------------#
252 echo_header "check that fake android home passes 'fdroid init'"
254 REPOROOT=`create_test_dir`
255 FAKE_ANDROID_HOME=`create_test_dir`
256 create_fake_android_home $FAKE_ANDROID_HOME
257 KEYSTORE=$REPOROOT/keystore.jks
259 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
262 #------------------------------------------------------------------------------#
263 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
265 if [ -e /usr/bin/aapt ]; then
266 echo "/usr/bin/aapt exists, not running test"
268 REPOROOT=`create_test_dir`
269 FAKE_ANDROID_HOME=`create_test_dir`
270 create_fake_android_home $FAKE_ANDROID_HOME
271 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
272 KEYSTORE=$REPOROOT/keystore.jks
275 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
276 [ $? -eq 0 ] && exit 1
281 #------------------------------------------------------------------------------#
282 echo_header "check that --android-home overrides ANDROID_HOME"
284 REPOROOT=`create_test_dir`
285 FAKE_ANDROID_HOME=`create_test_dir`
286 create_fake_android_home $FAKE_ANDROID_HOME
287 KEYSTORE=$REPOROOT/keystore.jks
289 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
291 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
292 if [ $? -ne 0 ]; then
293 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
299 #------------------------------------------------------------------------------#
300 # In this case, ANDROID_HOME is set to a fake, non-working version that will
301 # be detected by fdroid as an Android SDK install. It should use the path set
302 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
303 # in ANDROID_HOME, it won't work because it is a fake one. Only
304 # --android-home provides a working one.
305 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
307 REPOROOT=`create_test_dir`
308 KEYSTORE=$REPOROOT/keystore.jks
309 FAKE_ANDROID_HOME=`create_test_dir`
310 create_fake_android_home $FAKE_ANDROID_HOME
311 STORED_ANDROID_HOME=$ANDROID_HOME
313 echo "ANDROID_HOME: $ANDROID_HOME"
315 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
317 copy_apks_into_repo $REPOROOT
318 $fdroid update --create-metadata
320 grep -F '<application id=' repo/index.xml > /dev/null
321 test -e repo/index.xml
322 test -e repo/index.jar
323 export ANDROID_HOME=$STORED_ANDROID_HOME
326 #------------------------------------------------------------------------------#
327 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
329 REPOROOT=`create_test_dir`
332 copy_apks_into_repo $REPOROOT
334 $fdroid update --create-metadata
336 grep -F '<application id=' repo/index.xml > /dev/null
339 #------------------------------------------------------------------------------#
340 echo_header "setup a new repo from scratch and generate a keystore"
342 REPOROOT=`create_test_dir`
343 KEYSTORE=$REPOROOT/keystore.jks
345 $fdroid init --keystore $KEYSTORE
347 copy_apks_into_repo $REPOROOT
348 $fdroid update --create-metadata
350 test -e repo/index.xml
351 test -e repo/index.jar
352 grep -F '<application id=' repo/index.xml > /dev/null
355 #------------------------------------------------------------------------------#
356 echo_header "setup a new repo manually and generate a keystore"
358 REPOROOT=`create_test_dir`
359 KEYSTORE=$REPOROOT/keystore.jks
362 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
366 if [ $? -eq 0 ]; then
367 echo "This should have failed because this repo has no keystore!"
370 echo '`fdroid update` prompted to add keystore'
373 $fdroid update --create-key
375 copy_apks_into_repo $REPOROOT
376 $fdroid update --create-metadata
378 test -e repo/index.xml
379 test -e repo/index.jar
380 grep -F '<application id=' repo/index.xml > /dev/null
383 #------------------------------------------------------------------------------#
384 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
386 REPOROOT=`create_test_dir`
387 KEYSTORE=$REPOROOT/keystore.jks
389 $fdroid init --keystore $KEYSTORE
391 copy_apks_into_repo $REPOROOT
392 $fdroid update --create-metadata
394 test -e repo/index.xml
395 test -e repo/index.jar
396 grep -F '<application id=' repo/index.xml > /dev/null
397 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
398 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
399 $fdroid update --create-metadata
401 test -e repo/index.xml
402 test -e repo/index.jar
403 grep -F '<application id=' repo/index.xml > /dev/null
406 #------------------------------------------------------------------------------#
407 echo_header "setup a new repo from scratch with a HSM/smartcard"
409 REPOROOT=`create_test_dir`
411 $fdroid init --keystore NONE
412 test -e opensc-fdroid.cfg
416 #------------------------------------------------------------------------------#
417 echo_header "setup a new repo with no keystore, add APK, and update"
419 REPOROOT=`create_test_dir`
420 KEYSTORE=$REPOROOT/keystore.jks
423 touch fdroid-icon.png
425 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
427 $fdroid update --create-metadata
428 if [ $? -eq 0 ]; then
429 echo "This should have failed because this repo has no keystore!"
432 echo '`fdroid update` prompted to add keystore'
436 # now set up fake, non-working keystore setup
438 echo "keystore = \"$KEYSTORE\"" >> config.py
439 echo 'repo_keyalias = "foo"' >> config.py
440 echo 'keystorepass = "foo"' >> config.py
441 echo 'keypass = "foo"' >> config.py
443 $fdroid update --create-metadata
444 if [ $? -eq 0 ]; then
445 echo "This should have failed because this repo has a bad/fake keystore!"
448 echo '`fdroid update` prompted to add keystore'
453 #------------------------------------------------------------------------------#
454 echo_header "setup a new repo with keystore with APK, update, then without key"
456 REPOROOT=`create_test_dir`
457 KEYSTORE=$REPOROOT/keystore.jks
459 $fdroid init --keystore $KEYSTORE
461 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
462 $fdroid update --create-metadata
464 test -e repo/index.xml
465 test -e repo/index.jar
466 grep -F '<application id=' repo/index.xml > /dev/null
468 # now set fake repo_keyalias
469 sed -i 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
472 if [ $? -eq 0 ]; then
473 echo "This should have failed because this repo has a bad repo_keyalias!"
476 echo '`fdroid update` prompted to add keystore'
480 # try creating a new keystore, but fail because the old one is there
483 $fdroid update --create-key
484 if [ $? -eq 0 ]; then
485 echo "This should have failed because a keystore is already there!"
488 echo '`fdroid update` complained about existing keystore'
492 # now actually create the key with the existing settings
495 $fdroid update --create-key
499 #------------------------------------------------------------------------------#
501 # remove this to prevent git conflicts and complaining
502 rm -rf $WORKSPACE/fdroidserver.egg-info/