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 mktemp --directory --tmpdir=$WORKSPACE/.testfiles
42 test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
43 mktemp --tmpdir=$WORKSPACE/.testfiles
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
127 $fdroid server update --local-copy-dir=/tmp/fdroid
129 # now test the errors work
131 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
132 if [ $? -eq 0 ]; then
133 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
136 echo "testing absolute path checker passed"
138 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
139 if [ $? -eq 0 ]; then
140 echo "This should have failed because the path does not end with 'fdroid'!"
143 echo "testing dirname exists checker passed"
145 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
146 if [ $? -eq 0 ]; then
147 echo "This should have failed because the dirname path does not exist!"
150 echo "testing dirname exists checker passed"
155 #------------------------------------------------------------------------------#
156 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
158 REPOROOT=`create_test_dir`
161 copy_apks_into_repo $REPOROOT
162 $fdroid update --create-metadata
163 grep -F '<application id=' repo/index.xml > /dev/null
165 LOCALCOPYDIR=`create_test_dir`/fdroid
166 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
167 NEWREPOROOT=`create_test_dir`
170 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
173 #------------------------------------------------------------------------------#
174 # check that --android-home fails when dir does not exist or is not a dir
176 REPOROOT=`create_test_dir`
177 KEYSTORE=$REPOROOT/keystore.jks
180 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
181 if [ $? -eq 0 ]; then
182 echo "This should have failed because /opt/fakeandroidhome does not exist!"
185 echo "testing android-home path checker passed"
187 TESTFILE=`create_test_file`
188 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
189 if [ $? -eq 0 ]; then
190 echo "This should have failed because $TESTFILE is a file not a dir!"
193 echo "testing android-home not-dir checker passed"
198 #------------------------------------------------------------------------------#
199 echo_header "check that fake android home passes 'fdroid init'"
201 REPOROOT=`create_test_dir`
202 FAKE_ANDROID_HOME=`create_test_dir`
203 create_fake_android_home $FAKE_ANDROID_HOME
204 KEYSTORE=$REPOROOT/keystore.jks
206 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
209 #------------------------------------------------------------------------------#
210 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
212 if [ -e /usr/bin/aapt ]; then
213 echo "/usr/bin/aapt exists, not running test"
215 REPOROOT=`create_test_dir`
216 FAKE_ANDROID_HOME=`create_test_dir`
217 create_fake_android_home $FAKE_ANDROID_HOME
218 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
219 KEYSTORE=$REPOROOT/keystore.jks
222 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
223 [ $? -eq 0 ] && exit 1
228 #------------------------------------------------------------------------------#
229 echo_header "check that --android-home overrides ANDROID_HOME"
231 REPOROOT=`create_test_dir`
232 FAKE_ANDROID_HOME=`create_test_dir`
233 create_fake_android_home $FAKE_ANDROID_HOME
234 KEYSTORE=$REPOROOT/keystore.jks
236 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
238 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
239 if [ $? -ne 0 ]; then
240 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
246 #------------------------------------------------------------------------------#
247 # In this case, ANDROID_HOME is set to a fake, non-working version that will
248 # be detected by fdroid as an Android SDK install. It should use the path set
249 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
250 # in ANDROID_HOME, it won't work because it is a fake one. Only
251 # --android-home provides a working one.
252 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
254 REPOROOT=`create_test_dir`
255 KEYSTORE=$REPOROOT/keystore.jks
256 FAKE_ANDROID_HOME=`create_test_dir`
257 create_fake_android_home $FAKE_ANDROID_HOME
258 STORED_ANDROID_HOME=$ANDROID_HOME
260 echo "ANDROID_HOME: $ANDROID_HOME"
262 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
264 copy_apks_into_repo $REPOROOT
265 $fdroid update --create-metadata
266 grep -F '<application id=' repo/index.xml > /dev/null
267 test -e repo/index.xml
268 test -e repo/index.jar
269 export ANDROID_HOME=$STORED_ANDROID_HOME
272 #------------------------------------------------------------------------------#
273 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
275 REPOROOT=`create_test_dir`
278 copy_apks_into_repo $REPOROOT
280 $fdroid update --create-metadata
281 grep -F '<application id=' repo/index.xml > /dev/null
284 #------------------------------------------------------------------------------#
285 echo_header "setup a new repo from scratch and generate a keystore"
287 REPOROOT=`create_test_dir`
288 KEYSTORE=$REPOROOT/keystore.jks
290 $fdroid init --keystore $KEYSTORE
292 copy_apks_into_repo $REPOROOT
293 $fdroid update --create-metadata
294 test -e repo/index.xml
295 test -e repo/index.jar
296 grep -F '<application id=' repo/index.xml > /dev/null
299 #------------------------------------------------------------------------------#
300 echo_header "setup a new repo manually and generate a keystore"
302 REPOROOT=`create_test_dir`
303 KEYSTORE=$REPOROOT/keystore.jks
306 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
310 if [ $? -eq 0 ]; then
311 echo "This should have failed because this repo has no keystore!"
314 echo "`fdroid update` prompted to add keystore"
317 $fdroid update --create-key
319 copy_apks_into_repo $REPOROOT
320 $fdroid update --create-metadata
321 test -e repo/index.xml
322 test -e repo/index.jar
323 grep -F '<application id=' repo/index.xml > /dev/null
326 #------------------------------------------------------------------------------#
327 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
329 REPOROOT=`create_test_dir`
330 KEYSTORE=$REPOROOT/keystore.jks
332 $fdroid init --keystore $KEYSTORE
334 copy_apks_into_repo $REPOROOT
335 $fdroid update --create-metadata
336 test -e repo/index.xml
337 test -e repo/index.jar
338 grep -F '<application id=' repo/index.xml > /dev/null
339 cp $WORKSPACE/tests/urzip.apk $REPOROOT/
340 $fdroid update --create-metadata
341 test -e repo/index.xml
342 test -e repo/index.jar
343 grep -F '<application id=' repo/index.xml > /dev/null
346 #------------------------------------------------------------------------------#
347 echo_header "setup a new repo from scratch with a HSM/smartcard"
349 REPOROOT=`create_test_dir`
351 $fdroid init --keystore NONE
352 test -e opensc-fdroid.cfg
356 #------------------------------------------------------------------------------#
357 echo_header "setup a new repo with no keystore, add APK, and update"
359 REPOROOT=`create_test_dir`
360 KEYSTORE=$REPOROOT/keystore.jks
363 touch fdroid-icon.png
365 cp $WORKSPACE/tests/urzip.apk $REPOROOT/
367 $fdroid update --create-metadata
368 if [ $? -eq 0 ]; then
369 echo "This should have failed because this repo has no keystore!"
372 echo "`fdroid update` prompted to add keystore"
376 # now set up fake, non-working keystore setup
378 echo "keystore = \"$KEYSTORE\"" >> config.py
379 echo 'repo_keyalias = "foo"' >> config.py
380 echo 'keystorepass = "foo"' >> config.py
381 echo 'keypass = "foo"' >> config.py
383 $fdroid update --create-metadata
384 if [ $? -eq 0 ]; then
385 echo "This should have failed because this repo has a bad/fake keystore!"
388 echo "`fdroid update` prompted to add keystore"
393 #------------------------------------------------------------------------------#
394 echo_header "setup a new repo with keystore with APK, update, then without key"
396 REPOROOT=`create_test_dir`
397 KEYSTORE=$REPOROOT/keystore.jks
399 $fdroid init --keystore $KEYSTORE
401 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
402 $fdroid update --create-metadata
403 test -e repo/index.xml
404 test -e repo/index.jar
405 grep -F '<application id=' repo/index.xml > /dev/null
407 # now set fake repo_keyalias
408 sed -i 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
411 if [ $? -eq 0 ]; then
412 echo "This should have failed because this repo has a bad repo_keyalias!"
415 echo "`fdroid update` prompted to add keystore"
419 # try creating a new keystore, but fail because the old one is there
422 $fdroid update --create-key
423 if [ $? -eq 0 ]; then
424 echo "This should have failed because a keystore is already there!"
427 echo "`fdroid update` complained about existing keystore"
431 # now actually create the key with the existing settings
434 $fdroid update --create-key
438 #------------------------------------------------------------------------------#
440 # remove this to prevent git conflicts and complaining
441 rm -rf $WORKSPACE/fdroidserver.egg-info/