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 TMPDIR=$WORKSPACE/.testfiles mktemp -d
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 ./gendocs.sh -o html --email admin@f-droid.org fdroid "F-Droid Server Manual"
121 #------------------------------------------------------------------------------#
122 echo_header "test metadata checks"
124 REPOROOT=`create_test_dir`
129 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
133 if [ $? -eq 0 ]; then
134 echo "This should have failed because there is no metadata!"
137 echo "testing metadata checks passed"
141 mkdir $REPOROOT/metadata/
142 cp $WORKSPACE/tests/metadata/org.smssecure.smssecure.txt $REPOROOT/metadata/
145 # now make a fake duplicate
146 touch $REPOROOT/metadata/org.smssecure.smssecure.yaml
150 if [ $? -eq 0 ]; then
151 echo "This should have failed because there is a duplicate metadata file!"
154 echo "testing duplicate metadata checks passed"
159 #------------------------------------------------------------------------------#
160 echo_header "create a source tarball and use that to build a repo"
163 $python setup.py sdist
165 REPOROOT=`create_test_dir`
167 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
169 ./fdroidserver-*/fdroid init
170 copy_apks_into_repo $REPOROOT
171 ./fdroidserver-*/fdroid update --create-metadata --verbose
174 #------------------------------------------------------------------------------#
175 echo_header "test config checks of local_copy_dir"
177 REPOROOT=`create_test_dir`
180 $fdroid update --create-metadata --verbose
182 $fdroid server update --local-copy-dir=/tmp/fdroid
184 # now test the errors work
186 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
187 if [ $? -eq 0 ]; then
188 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
191 echo "testing absolute path checker passed"
193 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
194 if [ $? -eq 0 ]; then
195 echo "This should have failed because the path does not end with 'fdroid'!"
198 echo "testing dirname exists checker passed"
200 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
201 if [ $? -eq 0 ]; then
202 echo "This should have failed because the dirname path does not exist!"
205 echo "testing dirname exists checker passed"
210 #------------------------------------------------------------------------------#
211 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
213 REPOROOT=`create_test_dir`
216 copy_apks_into_repo $REPOROOT
217 $fdroid update --create-metadata --verbose
219 grep -F '<application id=' repo/index.xml > /dev/null
221 LOCALCOPYDIR=`create_test_dir`/fdroid
222 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
223 NEWREPOROOT=`create_test_dir`
226 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
229 #------------------------------------------------------------------------------#
230 # check that --android-home fails when dir does not exist or is not a dir
232 REPOROOT=`create_test_dir`
233 KEYSTORE=$REPOROOT/keystore.jks
236 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
237 if [ $? -eq 0 ]; then
238 echo "This should have failed because /opt/fakeandroidhome does not exist!"
241 echo "testing android-home path checker passed"
243 TESTFILE=`create_test_file`
244 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
245 if [ $? -eq 0 ]; then
246 echo "This should have failed because $TESTFILE is a file not a dir!"
249 echo "testing android-home not-dir checker passed"
254 #------------------------------------------------------------------------------#
255 echo_header "check that fake android home passes 'fdroid init'"
257 REPOROOT=`create_test_dir`
258 FAKE_ANDROID_HOME=`create_test_dir`
259 create_fake_android_home $FAKE_ANDROID_HOME
260 KEYSTORE=$REPOROOT/keystore.jks
262 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
265 #------------------------------------------------------------------------------#
266 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
268 if [ -e /usr/bin/aapt ]; then
269 echo "/usr/bin/aapt exists, not running test"
271 REPOROOT=`create_test_dir`
272 FAKE_ANDROID_HOME=`create_test_dir`
273 create_fake_android_home $FAKE_ANDROID_HOME
274 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
275 KEYSTORE=$REPOROOT/keystore.jks
278 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
279 [ $? -eq 0 ] && exit 1
284 #------------------------------------------------------------------------------#
285 echo_header "check that --android-home overrides ANDROID_HOME"
287 REPOROOT=`create_test_dir`
288 FAKE_ANDROID_HOME=`create_test_dir`
289 create_fake_android_home $FAKE_ANDROID_HOME
290 KEYSTORE=$REPOROOT/keystore.jks
292 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
294 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
295 if [ $? -ne 0 ]; then
296 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
302 #------------------------------------------------------------------------------#
303 # In this case, ANDROID_HOME is set to a fake, non-working version that will
304 # be detected by fdroid as an Android SDK install. It should use the path set
305 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
306 # in ANDROID_HOME, it won't work because it is a fake one. Only
307 # --android-home provides a working one.
308 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
310 REPOROOT=`create_test_dir`
311 KEYSTORE=$REPOROOT/keystore.jks
312 FAKE_ANDROID_HOME=`create_test_dir`
313 create_fake_android_home $FAKE_ANDROID_HOME
314 STORED_ANDROID_HOME=$ANDROID_HOME
316 echo "ANDROID_HOME: $ANDROID_HOME"
318 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
320 copy_apks_into_repo $REPOROOT
321 $fdroid update --create-metadata --verbose
323 grep -F '<application id=' repo/index.xml > /dev/null
324 test -e repo/index.xml
325 test -e repo/index.jar
326 export ANDROID_HOME=$STORED_ANDROID_HOME
329 #------------------------------------------------------------------------------#
330 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
332 REPOROOT=`create_test_dir`
335 copy_apks_into_repo $REPOROOT
337 $fdroid update --create-metadata --verbose
339 grep -F '<application id=' repo/index.xml > /dev/null
342 #------------------------------------------------------------------------------#
343 echo_header "setup a new repo from scratch and generate a keystore"
345 REPOROOT=`create_test_dir`
346 KEYSTORE=$REPOROOT/keystore.jks
348 $fdroid init --keystore $KEYSTORE
350 copy_apks_into_repo $REPOROOT
351 $fdroid update --create-metadata --verbose
353 test -e repo/index.xml
354 test -e repo/index.jar
355 grep -F '<application id=' repo/index.xml > /dev/null
358 #------------------------------------------------------------------------------#
359 echo_header "setup a new repo manually and generate a keystore"
361 REPOROOT=`create_test_dir`
362 KEYSTORE=$REPOROOT/keystore.jks
365 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
369 if [ $? -eq 0 ]; then
370 echo "This should have failed because this repo has no keystore!"
373 echo '`fdroid update` prompted to add keystore'
376 $fdroid update --create-key
378 copy_apks_into_repo $REPOROOT
379 $fdroid update --create-metadata --verbose
381 test -e repo/index.xml
382 test -e repo/index.jar
383 grep -F '<application id=' repo/index.xml > /dev/null
386 #------------------------------------------------------------------------------#
387 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
389 REPOROOT=`create_test_dir`
390 KEYSTORE=$REPOROOT/keystore.jks
392 $fdroid init --keystore $KEYSTORE
394 copy_apks_into_repo $REPOROOT
395 $fdroid update --create-metadata --verbose
397 test -e repo/index.xml
398 test -e repo/index.jar
399 grep -F '<application id=' repo/index.xml > /dev/null
400 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
401 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
402 $fdroid update --create-metadata --verbose
404 test -e repo/index.xml
405 test -e repo/index.jar
406 grep -F '<application id=' repo/index.xml > /dev/null
409 #------------------------------------------------------------------------------#
410 echo_header "setup a new repo from scratch with a HSM/smartcard"
411 REPOROOT=`create_test_dir`
413 $fdroid init --keystore NONE
414 test -e opensc-fdroid.cfg
418 #------------------------------------------------------------------------------#
419 echo_header "setup a new repo with no keystore, add APK, and update"
421 REPOROOT=`create_test_dir`
422 KEYSTORE=$REPOROOT/keystore.jks
425 touch fdroid-icon.png
427 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
429 $fdroid update --create-metadata --verbose
430 if [ $? -eq 0 ]; then
431 echo "This should have failed because this repo has no keystore!"
434 echo '`fdroid update` prompted to add keystore'
438 # now set up fake, non-working keystore setup
440 echo "keystore = \"$KEYSTORE\"" >> config.py
441 echo 'repo_keyalias = "foo"' >> config.py
442 echo 'keystorepass = "foo"' >> config.py
443 echo 'keypass = "foo"' >> config.py
445 $fdroid update --create-metadata --verbose
446 if [ $? -eq 0 ]; then
447 echo "This should have failed because this repo has a bad/fake keystore!"
450 echo '`fdroid update` prompted to add keystore'
455 #------------------------------------------------------------------------------#
456 echo_header "setup a new repo with keystore with APK, update, then without key"
458 REPOROOT=`create_test_dir`
459 KEYSTORE=$REPOROOT/keystore.jks
461 $fdroid init --keystore $KEYSTORE
463 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
464 $fdroid update --create-metadata --verbose
466 test -e repo/index.xml
467 test -e repo/index.jar
468 grep -F '<application id=' repo/index.xml > /dev/null
470 # now set fake repo_keyalias
471 sed -i 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
474 if [ $? -eq 0 ]; then
475 echo "This should have failed because this repo has a bad repo_keyalias!"
478 echo '`fdroid update` prompted to add keystore'
482 # try creating a new keystore, but fail because the old one is there
485 $fdroid update --create-key
486 if [ $? -eq 0 ]; then
487 echo "This should have failed because a keystore is already there!"
490 echo '`fdroid update` complained about existing keystore'
494 # now actually create the key with the existing settings
497 $fdroid update --create-key
501 #------------------------------------------------------------------------------#
503 # remove this to prevent git conflicts and complaining
504 rm -rf $WORKSPACE/fdroidserver.egg-info/