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 "create a source tarball and use that to build a repo"
109 $python setup.py sdist
111 REPOROOT=`create_test_dir`
113 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
115 ./fdroidserver-*/fdroid init
116 copy_apks_into_repo $REPOROOT
117 ./fdroidserver-*/fdroid update --create-metadata
120 #------------------------------------------------------------------------------#
121 echo_header "test config checks of local_copy_dir"
123 REPOROOT=`create_test_dir`
126 $fdroid update --create-metadata
128 $fdroid server update --local-copy-dir=/tmp/fdroid
130 # now test the errors work
132 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
133 if [ $? -eq 0 ]; then
134 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
137 echo "testing absolute path checker passed"
139 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
140 if [ $? -eq 0 ]; then
141 echo "This should have failed because the path does not end with 'fdroid'!"
144 echo "testing dirname exists checker passed"
146 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
147 if [ $? -eq 0 ]; then
148 echo "This should have failed because the dirname path does not exist!"
151 echo "testing dirname exists checker passed"
156 #------------------------------------------------------------------------------#
157 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
159 REPOROOT=`create_test_dir`
162 copy_apks_into_repo $REPOROOT
163 $fdroid update --create-metadata
165 grep -F '<application id=' repo/index.xml > /dev/null
167 LOCALCOPYDIR=`create_test_dir`/fdroid
168 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
169 NEWREPOROOT=`create_test_dir`
172 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
175 #------------------------------------------------------------------------------#
176 # check that --android-home fails when dir does not exist or is not a dir
178 REPOROOT=`create_test_dir`
179 KEYSTORE=$REPOROOT/keystore.jks
182 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
183 if [ $? -eq 0 ]; then
184 echo "This should have failed because /opt/fakeandroidhome does not exist!"
187 echo "testing android-home path checker passed"
189 TESTFILE=`create_test_file`
190 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
191 if [ $? -eq 0 ]; then
192 echo "This should have failed because $TESTFILE is a file not a dir!"
195 echo "testing android-home not-dir checker passed"
200 #------------------------------------------------------------------------------#
201 echo_header "check that fake android home passes 'fdroid init'"
203 REPOROOT=`create_test_dir`
204 FAKE_ANDROID_HOME=`create_test_dir`
205 create_fake_android_home $FAKE_ANDROID_HOME
206 KEYSTORE=$REPOROOT/keystore.jks
208 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
211 #------------------------------------------------------------------------------#
212 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
214 if [ -e /usr/bin/aapt ]; then
215 echo "/usr/bin/aapt exists, not running test"
217 REPOROOT=`create_test_dir`
218 FAKE_ANDROID_HOME=`create_test_dir`
219 create_fake_android_home $FAKE_ANDROID_HOME
220 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
221 KEYSTORE=$REPOROOT/keystore.jks
224 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
225 [ $? -eq 0 ] && exit 1
230 #------------------------------------------------------------------------------#
231 echo_header "check that --android-home overrides ANDROID_HOME"
233 REPOROOT=`create_test_dir`
234 FAKE_ANDROID_HOME=`create_test_dir`
235 create_fake_android_home $FAKE_ANDROID_HOME
236 KEYSTORE=$REPOROOT/keystore.jks
238 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
240 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
241 if [ $? -ne 0 ]; then
242 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
248 #------------------------------------------------------------------------------#
249 # In this case, ANDROID_HOME is set to a fake, non-working version that will
250 # be detected by fdroid as an Android SDK install. It should use the path set
251 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
252 # in ANDROID_HOME, it won't work because it is a fake one. Only
253 # --android-home provides a working one.
254 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
256 REPOROOT=`create_test_dir`
257 KEYSTORE=$REPOROOT/keystore.jks
258 FAKE_ANDROID_HOME=`create_test_dir`
259 create_fake_android_home $FAKE_ANDROID_HOME
260 STORED_ANDROID_HOME=$ANDROID_HOME
262 echo "ANDROID_HOME: $ANDROID_HOME"
264 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
266 copy_apks_into_repo $REPOROOT
267 $fdroid update --create-metadata
269 grep -F '<application id=' repo/index.xml > /dev/null
270 test -e repo/index.xml
271 test -e repo/index.jar
272 export ANDROID_HOME=$STORED_ANDROID_HOME
275 #------------------------------------------------------------------------------#
276 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
278 REPOROOT=`create_test_dir`
281 copy_apks_into_repo $REPOROOT
283 $fdroid update --create-metadata
285 grep -F '<application id=' repo/index.xml > /dev/null
288 #------------------------------------------------------------------------------#
289 echo_header "setup a new repo from scratch and generate a keystore"
291 REPOROOT=`create_test_dir`
292 KEYSTORE=$REPOROOT/keystore.jks
294 $fdroid init --keystore $KEYSTORE
296 copy_apks_into_repo $REPOROOT
297 $fdroid update --create-metadata
299 test -e repo/index.xml
300 test -e repo/index.jar
301 grep -F '<application id=' repo/index.xml > /dev/null
304 #------------------------------------------------------------------------------#
305 echo_header "setup a new repo manually and generate a keystore"
307 REPOROOT=`create_test_dir`
308 KEYSTORE=$REPOROOT/keystore.jks
311 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
315 if [ $? -eq 0 ]; then
316 echo "This should have failed because this repo has no keystore!"
319 echo "`fdroid update` prompted to add keystore"
322 $fdroid update --create-key
324 copy_apks_into_repo $REPOROOT
325 $fdroid update --create-metadata
327 test -e repo/index.xml
328 test -e repo/index.jar
329 grep -F '<application id=' repo/index.xml > /dev/null
332 #------------------------------------------------------------------------------#
333 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
335 REPOROOT=`create_test_dir`
336 KEYSTORE=$REPOROOT/keystore.jks
338 $fdroid init --keystore $KEYSTORE
340 copy_apks_into_repo $REPOROOT
341 $fdroid update --create-metadata
343 test -e repo/index.xml
344 test -e repo/index.jar
345 grep -F '<application id=' repo/index.xml > /dev/null
346 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
347 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
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 from scratch with a HSM/smartcard"
358 REPOROOT=`create_test_dir`
360 $fdroid init --keystore NONE
361 test -e opensc-fdroid.cfg
365 #------------------------------------------------------------------------------#
366 echo_header "setup a new repo with no keystore, add APK, and update"
368 REPOROOT=`create_test_dir`
369 KEYSTORE=$REPOROOT/keystore.jks
372 touch fdroid-icon.png
374 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
376 $fdroid update --create-metadata
377 if [ $? -eq 0 ]; then
378 echo "This should have failed because this repo has no keystore!"
381 echo "`fdroid update` prompted to add keystore"
385 # now set up fake, non-working keystore setup
387 echo "keystore = \"$KEYSTORE\"" >> config.py
388 echo 'repo_keyalias = "foo"' >> config.py
389 echo 'keystorepass = "foo"' >> config.py
390 echo 'keypass = "foo"' >> config.py
392 $fdroid update --create-metadata
393 if [ $? -eq 0 ]; then
394 echo "This should have failed because this repo has a bad/fake keystore!"
397 echo "`fdroid update` prompted to add keystore"
402 #------------------------------------------------------------------------------#
403 echo_header "setup a new repo with keystore with APK, update, then without key"
405 REPOROOT=`create_test_dir`
406 KEYSTORE=$REPOROOT/keystore.jks
408 $fdroid init --keystore $KEYSTORE
410 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
411 $fdroid update --create-metadata
413 test -e repo/index.xml
414 test -e repo/index.jar
415 grep -F '<application id=' repo/index.xml > /dev/null
417 # now set fake repo_keyalias
418 sed -i 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
421 if [ $? -eq 0 ]; then
422 echo "This should have failed because this repo has a bad repo_keyalias!"
425 echo "`fdroid update` prompted to add keystore"
429 # try creating a new keystore, but fail because the old one is there
432 $fdroid update --create-key
433 if [ $? -eq 0 ]; then
434 echo "This should have failed because a keystore is already there!"
437 echo "`fdroid update` complained about existing keystore"
441 # now actually create the key with the existing settings
444 $fdroid update --create-key
448 #------------------------------------------------------------------------------#
450 # remove this to prevent git conflicts and complaining
451 rm -rf $WORKSPACE/fdroidserver.egg-info/