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 "build the TeX manual"
109 ./gendocs.sh -o html --email admin@f-droid.org fdroid "F-Droid Server Manual"
112 #------------------------------------------------------------------------------#
113 echo_header "create a source tarball and use that to build a repo"
116 $python setup.py sdist
118 REPOROOT=`create_test_dir`
120 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
122 ./fdroidserver-*/fdroid init
123 copy_apks_into_repo $REPOROOT
124 ./fdroidserver-*/fdroid update --create-metadata
127 #------------------------------------------------------------------------------#
128 echo_header "test config checks of local_copy_dir"
130 REPOROOT=`create_test_dir`
133 $fdroid update --create-metadata
135 $fdroid server update --local-copy-dir=/tmp/fdroid
137 # now test the errors work
139 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
140 if [ $? -eq 0 ]; then
141 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
144 echo "testing absolute path checker passed"
146 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
147 if [ $? -eq 0 ]; then
148 echo "This should have failed because the path does not end with 'fdroid'!"
151 echo "testing dirname exists checker passed"
153 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
154 if [ $? -eq 0 ]; then
155 echo "This should have failed because the dirname path does not exist!"
158 echo "testing dirname exists checker passed"
163 #------------------------------------------------------------------------------#
164 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
166 REPOROOT=`create_test_dir`
169 copy_apks_into_repo $REPOROOT
170 $fdroid update --create-metadata
172 grep -F '<application id=' repo/index.xml > /dev/null
174 LOCALCOPYDIR=`create_test_dir`/fdroid
175 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
176 NEWREPOROOT=`create_test_dir`
179 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
182 #------------------------------------------------------------------------------#
183 # check that --android-home fails when dir does not exist or is not a dir
185 REPOROOT=`create_test_dir`
186 KEYSTORE=$REPOROOT/keystore.jks
189 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
190 if [ $? -eq 0 ]; then
191 echo "This should have failed because /opt/fakeandroidhome does not exist!"
194 echo "testing android-home path checker passed"
196 TESTFILE=`create_test_file`
197 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
198 if [ $? -eq 0 ]; then
199 echo "This should have failed because $TESTFILE is a file not a dir!"
202 echo "testing android-home not-dir checker passed"
207 #------------------------------------------------------------------------------#
208 echo_header "check that fake android home passes 'fdroid init'"
210 REPOROOT=`create_test_dir`
211 FAKE_ANDROID_HOME=`create_test_dir`
212 create_fake_android_home $FAKE_ANDROID_HOME
213 KEYSTORE=$REPOROOT/keystore.jks
215 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
218 #------------------------------------------------------------------------------#
219 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
221 if [ -e /usr/bin/aapt ]; then
222 echo "/usr/bin/aapt exists, not running test"
224 REPOROOT=`create_test_dir`
225 FAKE_ANDROID_HOME=`create_test_dir`
226 create_fake_android_home $FAKE_ANDROID_HOME
227 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
228 KEYSTORE=$REPOROOT/keystore.jks
231 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
232 [ $? -eq 0 ] && exit 1
237 #------------------------------------------------------------------------------#
238 echo_header "check that --android-home overrides ANDROID_HOME"
240 REPOROOT=`create_test_dir`
241 FAKE_ANDROID_HOME=`create_test_dir`
242 create_fake_android_home $FAKE_ANDROID_HOME
243 KEYSTORE=$REPOROOT/keystore.jks
245 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
247 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
248 if [ $? -ne 0 ]; then
249 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
255 #------------------------------------------------------------------------------#
256 # In this case, ANDROID_HOME is set to a fake, non-working version that will
257 # be detected by fdroid as an Android SDK install. It should use the path set
258 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
259 # in ANDROID_HOME, it won't work because it is a fake one. Only
260 # --android-home provides a working one.
261 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
263 REPOROOT=`create_test_dir`
264 KEYSTORE=$REPOROOT/keystore.jks
265 FAKE_ANDROID_HOME=`create_test_dir`
266 create_fake_android_home $FAKE_ANDROID_HOME
267 STORED_ANDROID_HOME=$ANDROID_HOME
269 echo "ANDROID_HOME: $ANDROID_HOME"
271 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
273 copy_apks_into_repo $REPOROOT
274 $fdroid update --create-metadata
276 grep -F '<application id=' repo/index.xml > /dev/null
277 test -e repo/index.xml
278 test -e repo/index.jar
279 export ANDROID_HOME=$STORED_ANDROID_HOME
282 #------------------------------------------------------------------------------#
283 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
285 REPOROOT=`create_test_dir`
288 copy_apks_into_repo $REPOROOT
290 $fdroid update --create-metadata
292 grep -F '<application id=' repo/index.xml > /dev/null
295 #------------------------------------------------------------------------------#
296 echo_header "setup a new repo from scratch and generate a keystore"
298 REPOROOT=`create_test_dir`
299 KEYSTORE=$REPOROOT/keystore.jks
301 $fdroid init --keystore $KEYSTORE
303 copy_apks_into_repo $REPOROOT
304 $fdroid update --create-metadata
306 test -e repo/index.xml
307 test -e repo/index.jar
308 grep -F '<application id=' repo/index.xml > /dev/null
311 #------------------------------------------------------------------------------#
312 echo_header "setup a new repo manually and generate a keystore"
314 REPOROOT=`create_test_dir`
315 KEYSTORE=$REPOROOT/keystore.jks
318 cp $WORKSPACE/examples/fdroid-icon.png $REPOROOT/
322 if [ $? -eq 0 ]; then
323 echo "This should have failed because this repo has no keystore!"
326 echo '`fdroid update` prompted to add keystore'
329 $fdroid update --create-key
331 copy_apks_into_repo $REPOROOT
332 $fdroid update --create-metadata
334 test -e repo/index.xml
335 test -e repo/index.jar
336 grep -F '<application id=' repo/index.xml > /dev/null
339 #------------------------------------------------------------------------------#
340 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
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
353 test -e $REPOROOT/repo/info.guardianproject.urzip_100.apk || \
354 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
355 $fdroid update --create-metadata
357 test -e repo/index.xml
358 test -e repo/index.jar
359 grep -F '<application id=' repo/index.xml > /dev/null
362 #------------------------------------------------------------------------------#
363 echo_header "setup a new repo from scratch with a HSM/smartcard"
365 REPOROOT=`create_test_dir`
367 $fdroid init --keystore NONE
368 test -e opensc-fdroid.cfg
372 #------------------------------------------------------------------------------#
373 echo_header "setup a new repo with no keystore, add APK, and update"
375 REPOROOT=`create_test_dir`
376 KEYSTORE=$REPOROOT/keystore.jks
379 touch fdroid-icon.png
381 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
383 $fdroid update --create-metadata
384 if [ $? -eq 0 ]; then
385 echo "This should have failed because this repo has no keystore!"
388 echo '`fdroid update` prompted to add keystore'
392 # now set up fake, non-working keystore setup
394 echo "keystore = \"$KEYSTORE\"" >> config.py
395 echo 'repo_keyalias = "foo"' >> config.py
396 echo 'keystorepass = "foo"' >> config.py
397 echo 'keypass = "foo"' >> config.py
399 $fdroid update --create-metadata
400 if [ $? -eq 0 ]; then
401 echo "This should have failed because this repo has a bad/fake keystore!"
404 echo '`fdroid update` prompted to add keystore'
409 #------------------------------------------------------------------------------#
410 echo_header "setup a new repo with keystore with APK, update, then without key"
412 REPOROOT=`create_test_dir`
413 KEYSTORE=$REPOROOT/keystore.jks
415 $fdroid init --keystore $KEYSTORE
417 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
418 $fdroid update --create-metadata
420 test -e repo/index.xml
421 test -e repo/index.jar
422 grep -F '<application id=' repo/index.xml > /dev/null
424 # now set fake repo_keyalias
425 sed -i 's,^ *repo_keyalias.*,repo_keyalias = "fake",' $REPOROOT/config.py
428 if [ $? -eq 0 ]; then
429 echo "This should have failed because this repo has a bad repo_keyalias!"
432 echo '`fdroid update` prompted to add keystore'
436 # try creating a new keystore, but fail because the old one is there
439 $fdroid update --create-key
440 if [ $? -eq 0 ]; then
441 echo "This should have failed because a keystore is already there!"
444 echo '`fdroid update` complained about existing keystore'
448 # now actually create the key with the existing settings
451 $fdroid update --create-key
455 #------------------------------------------------------------------------------#
457 # remove this to prevent git conflicts and complaining
458 rm -rf $WORKSPACE/fdroidserver.egg-info/