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`; 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/build-tools/19.0.2
31 touch $1/build-tools/19.0.2/aapt
35 test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
36 mktemp --directory --tmpdir=$WORKSPACE/.testfiles
40 test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
41 mktemp --tmpdir=$WORKSPACE/.testfiles
44 #------------------------------------------------------------------------------#
47 if [ $1 = "-h" ] || [ $1 = "--help" ]; then
49 echo "Usage: $0 '/path/to/folder/with/apks'"
53 if [ -z $ANDROID_HOME ]; then
54 echo "ANDROID_HOME must be set with the path to the Android SDK, i.e.: "
55 echo " export ANDROID_HOME=/opt/android-sdk"
65 if [ -z $WORKSPACE ]; then
66 WORKSPACE=`dirname $(pwd)`
67 echo "Setting Workspace to $WORKSPACE"
70 # allow the location of the script to be overridden
71 if [ -z $fdroid ]; then
72 fdroid="$WORKSPACE/fdroid"
75 # allow the location of aapt to be overridden
77 aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
80 # allow the location of python to be overridden
81 if [ -z $python ]; then
86 #------------------------------------------------------------------------------#
87 echo_header "create a source tarball and use that to build a repo"
90 $python setup.py sdist
92 REPOROOT=`create_test_dir`
94 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
95 cd $REPOROOT/fdroidserver-*/fdroidserver/getsig
98 ./fdroidserver-*/fdroid init
99 copy_apks_into_repo $REPOROOT
100 ./fdroidserver-*/fdroid update --create-metadata
103 #------------------------------------------------------------------------------#
104 echo_header "test config checks of local_copy_dir"
106 REPOROOT=`create_test_dir`
109 $fdroid update --create-metadata
110 $fdroid server update --local-copy-dir=/tmp/fdroid
112 # now test the errors work
114 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
115 if [ $? -eq 0 ]; then
116 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
119 echo "testing absolute path checker passed"
121 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
122 if [ $? -eq 0 ]; then
123 echo "This should have failed because the path does not end with 'fdroid'!"
126 echo "testing dirname exists checker passed"
128 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
129 if [ $? -eq 0 ]; then
130 echo "This should have failed because the dirname path does not exist!"
133 echo "testing dirname exists checker passed"
138 #------------------------------------------------------------------------------#
139 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
141 REPOROOT=`create_test_dir`
144 copy_apks_into_repo $REPOROOT
145 $fdroid update --create-metadata
146 grep -F '<application id=' repo/index.xml
148 LOCALCOPYDIR=`create_test_dir`/fdroid
149 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
150 NEWREPOROOT=`create_test_dir`
153 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
156 #------------------------------------------------------------------------------#
157 # check that --android-home fails when dir does not exist or is not a dir
159 REPOROOT=`create_test_dir`
160 KEYSTORE=$REPOROOT/keystore.jks
163 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
164 if [ $? -eq 0 ]; then
165 echo "This should have failed because /opt/fakeandroidhome does not exist!"
168 echo "testing android-home path checker passed"
170 TESTFILE=`create_test_file`
171 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
172 if [ $? -eq 0 ]; then
173 echo "This should have failed because $TESTFILE is a file not a dir!"
176 echo "testing android-home not-dir checker passed"
181 #------------------------------------------------------------------------------#
182 echo_header "check that fake android home passes `fdroid init`"
184 REPOROOT=`create_test_dir`
185 FAKE_ANDROID_HOME=`create_test_dir`
186 create_fake_android_home $FAKE_ANDROID_HOME
187 KEYSTORE=$REPOROOT/keystore.jks
189 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
192 #------------------------------------------------------------------------------#
193 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
195 REPOROOT=`create_test_dir`
196 FAKE_ANDROID_HOME=`create_test_dir`
197 create_fake_android_home $FAKE_ANDROID_HOME
198 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
199 KEYSTORE=$REPOROOT/keystore.jks
202 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
203 [ $? -eq 0 ] && exit 1
207 #------------------------------------------------------------------------------#
208 echo_header "check that --android-home overrides ANDROID_HOME"
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
217 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
218 if [ $? -ne 0 ]; then
219 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
225 #------------------------------------------------------------------------------#
226 # In this case, ANDROID_HOME is set to a fake, non-working version that will
227 # be detected by fdroid as an Android SDK install. It should use the path set
228 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
229 # in ANDROID_HOME, it won't work because it is a fake one. Only
230 # --android-home provides a working one.
231 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
233 REPOROOT=`create_test_dir`
234 KEYSTORE=$REPOROOT/keystore.jks
235 FAKE_ANDROID_HOME=`create_test_dir`
236 create_fake_android_home $FAKE_ANDROID_HOME
237 STORED_ANDROID_HOME=$ANDROID_HOME
239 echo "ANDROID_HOME: $ANDROID_HOME"
241 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
243 copy_apks_into_repo $REPOROOT
244 $fdroid update --create-metadata
245 grep -F '<application id=' repo/index.xml
246 test -e repo/index.xml
247 test -e repo/index.jar
248 export ANDROID_HOME=$STORED_ANDROID_HOME
251 #------------------------------------------------------------------------------#
252 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
254 REPOROOT=`create_test_dir`
257 copy_apks_into_repo $REPOROOT
259 $fdroid update --create-metadata
260 grep -F '<application id=' repo/index.xml
263 #------------------------------------------------------------------------------#
264 echo_header "setup a new repo from scratch and generate a keystore"
266 REPOROOT=`create_test_dir`
267 KEYSTORE=$REPOROOT/keystore.jks
269 $fdroid init --keystore $KEYSTORE
271 copy_apks_into_repo $REPOROOT
272 $fdroid update --create-metadata
273 test -e repo/index.xml
274 test -e repo/index.jar
275 grep -F '<application id=' repo/index.xml
278 #------------------------------------------------------------------------------#
279 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
281 REPOROOT=`create_test_dir`
282 KEYSTORE=$REPOROOT/keystore.jks
284 $fdroid init --keystore $KEYSTORE
286 copy_apks_into_repo $REPOROOT
287 $fdroid update --create-metadata
288 test -e repo/index.xml
289 test -e repo/index.jar
290 grep -F '<application id=' repo/index.xml
291 cp $WORKSPACE/tests/urzip.apk $REPOROOT/
292 $fdroid update --create-metadata
293 test -e repo/index.xml
294 test -e repo/index.jar
295 grep -F '<application id=' repo/index.xml
298 #------------------------------------------------------------------------------#
299 echo_header "setup a new repo from scratch with a HSM/smartcard"
301 REPOROOT=`create_test_dir`
303 $fdroid init --keystore NONE
304 test -e opensc-fdroid.cfg