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"
71 if [ -z $WORKSPACE ]; then
72 WORKSPACE=`dirname $(pwd)`
73 echo "Setting Workspace to $WORKSPACE"
76 # allow the location of the script to be overridden
77 if [ -z $fdroid ]; then
78 fdroid="$WORKSPACE/fdroid"
81 # allow the location of aapt to be overridden
83 aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
86 # allow the location of python to be overridden
87 if [ -z $python ]; then
92 #------------------------------------------------------------------------------#
93 echo_header "run commit hooks"
99 #------------------------------------------------------------------------------#
100 echo_header "test python getsig replacement"
102 cd $WORKSPACE/tests/getsig
104 for testcase in $WORKSPACE/tests/*.TestCase; do
109 #------------------------------------------------------------------------------#
110 echo_header "print fdroid version"
115 #------------------------------------------------------------------------------#
116 echo_header "build the TeX manual"
119 ./gendocs.sh -o html --email admin@f-droid.org fdroid "F-Droid Server Manual"
122 #------------------------------------------------------------------------------#
123 echo_header "test metadata checks"
125 REPOROOT=`create_test_dir`
130 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
134 if [ $? -eq 0 ]; then
135 echo "This should have failed because there is no metadata!"
138 echo "testing metadata checks passed"
142 mkdir $REPOROOT/metadata/
143 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
146 # now make a fake duplicate
147 touch $REPOROOT/metadata/org.smssecure.smssecure.yaml
151 if [ $? -eq 0 ]; then
152 echo "This should have failed because there is a duplicate metadata file!"
155 echo "testing duplicate metadata checks passed"
160 #------------------------------------------------------------------------------#
161 echo_header "create a source tarball and use that to build a repo"
164 $python setup.py sdist
166 REPOROOT=`create_test_dir`
168 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
170 ./fdroidserver-*/fdroid init
171 copy_apks_into_repo $REPOROOT
172 ./fdroidserver-*/fdroid update --create-metadata
175 #------------------------------------------------------------------------------#
176 echo_header "test config checks of local_copy_dir"
178 REPOROOT=`create_test_dir`
181 $fdroid update --create-metadata
183 $fdroid server update --local-copy-dir=/tmp/fdroid
185 # now test the errors work
187 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
188 if [ $? -eq 0 ]; then
189 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
192 echo "testing absolute path checker passed"
194 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
195 if [ $? -eq 0 ]; then
196 echo "This should have failed because the path does not end with 'fdroid'!"
199 echo "testing dirname exists checker passed"
201 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
202 if [ $? -eq 0 ]; then
203 echo "This should have failed because the dirname path does not exist!"
206 echo "testing dirname exists checker passed"
211 #------------------------------------------------------------------------------#
212 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
214 REPOROOT=`create_test_dir`
217 copy_apks_into_repo $REPOROOT
218 $fdroid update --create-metadata
220 grep -F '<application id=' repo/index.xml > /dev/null
222 LOCALCOPYDIR=`create_test_dir`/fdroid
223 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
224 NEWREPOROOT=`create_test_dir`
227 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
230 #------------------------------------------------------------------------------#
231 # check that --android-home fails when dir does not exist or is not a dir
233 REPOROOT=`create_test_dir`
234 KEYSTORE=$REPOROOT/keystore.jks
237 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
238 if [ $? -eq 0 ]; then
239 echo "This should have failed because /opt/fakeandroidhome does not exist!"
242 echo "testing android-home path checker passed"
244 TESTFILE=`create_test_file`
245 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
246 if [ $? -eq 0 ]; then
247 echo "This should have failed because $TESTFILE is a file not a dir!"
250 echo "testing android-home not-dir checker passed"
255 #------------------------------------------------------------------------------#
256 echo_header "check that fake android home passes 'fdroid init'"
258 REPOROOT=`create_test_dir`
259 FAKE_ANDROID_HOME=`create_test_dir`
260 create_fake_android_home $FAKE_ANDROID_HOME
261 KEYSTORE=$REPOROOT/keystore.jks
263 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
266 #------------------------------------------------------------------------------#
267 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
269 if [ -e /usr/bin/aapt ]; then
270 echo "/usr/bin/aapt exists, not running test"
272 REPOROOT=`create_test_dir`
273 FAKE_ANDROID_HOME=`create_test_dir`
274 create_fake_android_home $FAKE_ANDROID_HOME
275 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
276 KEYSTORE=$REPOROOT/keystore.jks
279 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
280 [ $? -eq 0 ] && exit 1
285 #------------------------------------------------------------------------------#
286 echo_header "check that --android-home overrides ANDROID_HOME"
288 REPOROOT=`create_test_dir`
289 FAKE_ANDROID_HOME=`create_test_dir`
290 create_fake_android_home $FAKE_ANDROID_HOME
291 KEYSTORE=$REPOROOT/keystore.jks
293 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
295 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
296 if [ $? -ne 0 ]; then
297 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
303 #------------------------------------------------------------------------------#
304 # In this case, ANDROID_HOME is set to a fake, non-working version that will
305 # be detected by fdroid as an Android SDK install. It should use the path set
306 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
307 # in ANDROID_HOME, it won't work because it is a fake one. Only
308 # --android-home provides a working one.
309 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
311 REPOROOT=`create_test_dir`
312 KEYSTORE=$REPOROOT/keystore.jks
313 FAKE_ANDROID_HOME=`create_test_dir`
314 create_fake_android_home $FAKE_ANDROID_HOME
315 STORED_ANDROID_HOME=$ANDROID_HOME
317 echo "ANDROID_HOME: $ANDROID_HOME"
319 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
321 copy_apks_into_repo $REPOROOT
322 $fdroid update --create-metadata
324 grep -F '<application id=' repo/index.xml > /dev/null
325 test -e repo/index.xml
326 test -e repo/index.jar
327 export ANDROID_HOME=$STORED_ANDROID_HOME
330 #------------------------------------------------------------------------------#
331 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
333 REPOROOT=`create_test_dir`
336 copy_apks_into_repo $REPOROOT
338 $fdroid update --create-metadata
340 grep -F '<application id=' repo/index.xml > /dev/null
343 #------------------------------------------------------------------------------#
344 echo_header "setup a new repo from scratch and generate a keystore"
346 REPOROOT=`create_test_dir`
347 KEYSTORE=$REPOROOT/keystore.jks
349 $fdroid init --keystore $KEYSTORE
351 copy_apks_into_repo $REPOROOT
352 $fdroid update --create-metadata
354 test -e repo/index.xml
355 test -e repo/index.jar
356 grep -F '<application id=' repo/index.xml > /dev/null
359 #------------------------------------------------------------------------------#
360 echo_header "setup a new repo manually and generate a keystore"
362 REPOROOT=`create_test_dir`
363 KEYSTORE=$REPOROOT/keystore.jks
366 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
370 if [ $? -eq 0 ]; then
371 echo "This should have failed because this repo has no keystore!"
374 echo '`fdroid update` prompted to add keystore'
377 $fdroid update --create-key
379 copy_apks_into_repo $REPOROOT
380 $fdroid update --create-metadata
382 test -e repo/index.xml
383 test -e repo/index.jar
384 grep -F '<application id=' repo/index.xml > /dev/null
387 #------------------------------------------------------------------------------#
388 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
390 REPOROOT=`create_test_dir`
391 KEYSTORE=$REPOROOT/keystore.jks
393 $fdroid init --keystore $KEYSTORE
395 copy_apks_into_repo $REPOROOT
396 $fdroid update --create-metadata
398 test -e repo/index.xml
399 test -e repo/index.jar
400 grep -F '<application id=' repo/index.xml > /dev/null
401 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
402 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
403 $fdroid update --create-metadata
405 test -e repo/index.xml
406 test -e repo/index.jar
407 grep -F '<application id=' repo/index.xml > /dev/null
410 #------------------------------------------------------------------------------#
411 echo_header "setup a new repo from scratch with a HSM/smartcard"
413 REPOROOT=`create_test_dir`
415 $fdroid init --keystore NONE
416 test -e opensc-fdroid.cfg
420 #------------------------------------------------------------------------------#
421 echo_header "setup a new repo with no keystore, add APK, and update"
423 REPOROOT=`create_test_dir`
424 KEYSTORE=$REPOROOT/keystore.jks
427 touch fdroid-icon.png
429 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
431 $fdroid update --create-metadata
432 if [ $? -eq 0 ]; then
433 echo "This should have failed because this repo has no keystore!"
436 echo '`fdroid update` prompted to add keystore'
440 # now set up fake, non-working keystore setup
442 echo "keystore = \"$KEYSTORE\"" >> config.py
443 echo 'repo_keyalias = "foo"' >> config.py
444 echo 'keystorepass = "foo"' >> config.py
445 echo 'keypass = "foo"' >> config.py
447 $fdroid update --create-metadata
448 if [ $? -eq 0 ]; then
449 echo "This should have failed because this repo has a bad/fake keystore!"
452 echo '`fdroid update` prompted to add keystore'
457 #------------------------------------------------------------------------------#
458 echo_header "setup a new repo with keystore with APK, update, then without key"
460 REPOROOT=`create_test_dir`
461 KEYSTORE=$REPOROOT/keystore.jks
463 $fdroid init --keystore $KEYSTORE
465 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
466 $fdroid update --create-metadata
468 test -e repo/index.xml
469 test -e repo/index.jar
470 grep -F '<application id=' repo/index.xml > /dev/null
472 # now set fake repo_keyalias
473 sed -i 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
476 if [ $? -eq 0 ]; then
477 echo "This should have failed because this repo has a bad repo_keyalias!"
480 echo '`fdroid update` prompted to add keystore'
484 # try creating a new keystore, but fail because the old one is there
487 $fdroid update --create-key
488 if [ $? -eq 0 ]; then
489 echo "This should have failed because a keystore is already there!"
492 echo '`fdroid update` complained about existing keystore'
496 # now actually create the key with the existing settings
499 $fdroid update --create-key
503 #------------------------------------------------------------------------------#
505 # remove this to prevent git conflicts and complaining
506 rm -rf $WORKSPACE/fdroidserver.egg-info/