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
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
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 REPOROOT=`create_test_dir`
213 FAKE_ANDROID_HOME=`create_test_dir`
214 create_fake_android_home $FAKE_ANDROID_HOME
215 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
216 KEYSTORE=$REPOROOT/keystore.jks
219 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
220 [ $? -eq 0 ] && exit 1
224 #------------------------------------------------------------------------------#
225 echo_header "check that --android-home overrides ANDROID_HOME"
227 REPOROOT=`create_test_dir`
228 FAKE_ANDROID_HOME=`create_test_dir`
229 create_fake_android_home $FAKE_ANDROID_HOME
230 KEYSTORE=$REPOROOT/keystore.jks
232 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
234 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
235 if [ $? -ne 0 ]; then
236 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
242 #------------------------------------------------------------------------------#
243 # In this case, ANDROID_HOME is set to a fake, non-working version that will
244 # be detected by fdroid as an Android SDK install. It should use the path set
245 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
246 # in ANDROID_HOME, it won't work because it is a fake one. Only
247 # --android-home provides a working one.
248 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
250 REPOROOT=`create_test_dir`
251 KEYSTORE=$REPOROOT/keystore.jks
252 FAKE_ANDROID_HOME=`create_test_dir`
253 create_fake_android_home $FAKE_ANDROID_HOME
254 STORED_ANDROID_HOME=$ANDROID_HOME
256 echo "ANDROID_HOME: $ANDROID_HOME"
258 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
260 copy_apks_into_repo $REPOROOT
261 $fdroid update --create-metadata
262 grep -F '<application id=' repo/index.xml
263 test -e repo/index.xml
264 test -e repo/index.jar
265 export ANDROID_HOME=$STORED_ANDROID_HOME
268 #------------------------------------------------------------------------------#
269 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
271 REPOROOT=`create_test_dir`
274 copy_apks_into_repo $REPOROOT
276 $fdroid update --create-metadata
277 grep -F '<application id=' repo/index.xml
280 #------------------------------------------------------------------------------#
281 echo_header "setup a new repo from scratch and generate a keystore"
283 REPOROOT=`create_test_dir`
284 KEYSTORE=$REPOROOT/keystore.jks
286 $fdroid init --keystore $KEYSTORE
288 copy_apks_into_repo $REPOROOT
289 $fdroid update --create-metadata
290 test -e repo/index.xml
291 test -e repo/index.jar
292 grep -F '<application id=' repo/index.xml
295 #------------------------------------------------------------------------------#
296 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
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
305 test -e repo/index.xml
306 test -e repo/index.jar
307 grep -F '<application id=' repo/index.xml
308 cp $WORKSPACE/tests/urzip.apk $REPOROOT/
309 $fdroid update --create-metadata
310 test -e repo/index.xml
311 test -e repo/index.jar
312 grep -F '<application id=' repo/index.xml
315 #------------------------------------------------------------------------------#
316 echo_header "setup a new repo from scratch with a HSM/smartcard"
318 REPOROOT=`create_test_dir`
320 $fdroid init --keystore NONE
321 test -e opensc-fdroid.cfg
324 rm -rf $WORKSPACE/fdroidserver.egg-info/