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
104 #------------------------------------------------------------------------------#
105 echo_header "create a source tarball and use that to build a repo"
108 $python setup.py sdist
110 REPOROOT=`create_test_dir`
112 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
114 ./fdroidserver-*/fdroid init
115 copy_apks_into_repo $REPOROOT
116 ./fdroidserver-*/fdroid update --create-metadata
119 #------------------------------------------------------------------------------#
120 echo_header "test config checks of local_copy_dir"
122 REPOROOT=`create_test_dir`
125 $fdroid update --create-metadata
126 $fdroid server update --local-copy-dir=/tmp/fdroid
128 # now test the errors work
130 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
131 if [ $? -eq 0 ]; then
132 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
135 echo "testing absolute path checker passed"
137 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
138 if [ $? -eq 0 ]; then
139 echo "This should have failed because the path does not end with 'fdroid'!"
142 echo "testing dirname exists checker passed"
144 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
145 if [ $? -eq 0 ]; then
146 echo "This should have failed because the dirname path does not exist!"
149 echo "testing dirname exists checker passed"
154 #------------------------------------------------------------------------------#
155 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
157 REPOROOT=`create_test_dir`
160 copy_apks_into_repo $REPOROOT
161 $fdroid update --create-metadata
162 grep -F '<application id=' repo/index.xml
164 LOCALCOPYDIR=`create_test_dir`/fdroid
165 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
166 NEWREPOROOT=`create_test_dir`
169 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
172 #------------------------------------------------------------------------------#
173 # check that --android-home fails when dir does not exist or is not a dir
175 REPOROOT=`create_test_dir`
176 KEYSTORE=$REPOROOT/keystore.jks
179 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
180 if [ $? -eq 0 ]; then
181 echo "This should have failed because /opt/fakeandroidhome does not exist!"
184 echo "testing android-home path checker passed"
186 TESTFILE=`create_test_file`
187 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
188 if [ $? -eq 0 ]; then
189 echo "This should have failed because $TESTFILE is a file not a dir!"
192 echo "testing android-home not-dir checker passed"
197 #------------------------------------------------------------------------------#
198 echo_header "check that fake android home passes 'fdroid init'"
200 REPOROOT=`create_test_dir`
201 FAKE_ANDROID_HOME=`create_test_dir`
202 create_fake_android_home $FAKE_ANDROID_HOME
203 KEYSTORE=$REPOROOT/keystore.jks
205 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
208 #------------------------------------------------------------------------------#
209 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
211 REPOROOT=`create_test_dir`
212 FAKE_ANDROID_HOME=`create_test_dir`
213 create_fake_android_home $FAKE_ANDROID_HOME
214 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
215 KEYSTORE=$REPOROOT/keystore.jks
218 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
219 [ $? -eq 0 ] && exit 1
223 #------------------------------------------------------------------------------#
224 echo_header "check that --android-home overrides ANDROID_HOME"
226 REPOROOT=`create_test_dir`
227 FAKE_ANDROID_HOME=`create_test_dir`
228 create_fake_android_home $FAKE_ANDROID_HOME
229 KEYSTORE=$REPOROOT/keystore.jks
231 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
233 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
234 if [ $? -ne 0 ]; then
235 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
241 #------------------------------------------------------------------------------#
242 # In this case, ANDROID_HOME is set to a fake, non-working version that will
243 # be detected by fdroid as an Android SDK install. It should use the path set
244 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
245 # in ANDROID_HOME, it won't work because it is a fake one. Only
246 # --android-home provides a working one.
247 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
249 REPOROOT=`create_test_dir`
250 KEYSTORE=$REPOROOT/keystore.jks
251 FAKE_ANDROID_HOME=`create_test_dir`
252 create_fake_android_home $FAKE_ANDROID_HOME
253 STORED_ANDROID_HOME=$ANDROID_HOME
255 echo "ANDROID_HOME: $ANDROID_HOME"
257 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
259 copy_apks_into_repo $REPOROOT
260 $fdroid update --create-metadata
261 grep -F '<application id=' repo/index.xml
262 test -e repo/index.xml
263 test -e repo/index.jar
264 export ANDROID_HOME=$STORED_ANDROID_HOME
267 #------------------------------------------------------------------------------#
268 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
270 REPOROOT=`create_test_dir`
273 copy_apks_into_repo $REPOROOT
275 $fdroid update --create-metadata
276 grep -F '<application id=' repo/index.xml
279 #------------------------------------------------------------------------------#
280 echo_header "setup a new repo from scratch and generate a keystore"
282 REPOROOT=`create_test_dir`
283 KEYSTORE=$REPOROOT/keystore.jks
285 $fdroid init --keystore $KEYSTORE
287 copy_apks_into_repo $REPOROOT
288 $fdroid update --create-metadata
289 test -e repo/index.xml
290 test -e repo/index.jar
291 grep -F '<application id=' repo/index.xml
294 #------------------------------------------------------------------------------#
295 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
297 REPOROOT=`create_test_dir`
298 KEYSTORE=$REPOROOT/keystore.jks
300 $fdroid init --keystore $KEYSTORE
302 copy_apks_into_repo $REPOROOT
303 $fdroid update --create-metadata
304 test -e repo/index.xml
305 test -e repo/index.jar
306 grep -F '<application id=' repo/index.xml
307 cp $WORKSPACE/tests/urzip.apk $REPOROOT/
308 $fdroid update --create-metadata
309 test -e repo/index.xml
310 test -e repo/index.jar
311 grep -F '<application id=' repo/index.xml
314 #------------------------------------------------------------------------------#
315 echo_header "setup a new repo from scratch with a HSM/smartcard"
317 REPOROOT=`create_test_dir`
319 $fdroid init --keystore NONE
320 test -e opensc-fdroid.cfg
323 rm -rf $WORKSPACE/fdroidserver.egg-info/