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 "run commit hooks"
93 #------------------------------------------------------------------------------#
94 echo_header "create a source tarball and use that to build a repo"
97 $python setup.py sdist
99 REPOROOT=`create_test_dir`
101 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
102 cd $REPOROOT/fdroidserver-*/fdroidserver/getsig
105 ./fdroidserver-*/fdroid init
106 copy_apks_into_repo $REPOROOT
107 ./fdroidserver-*/fdroid update --create-metadata
110 #------------------------------------------------------------------------------#
111 echo_header "test config checks of local_copy_dir"
113 REPOROOT=`create_test_dir`
116 $fdroid update --create-metadata
117 $fdroid server update --local-copy-dir=/tmp/fdroid
119 # now test the errors work
121 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
122 if [ $? -eq 0 ]; then
123 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
126 echo "testing absolute path checker passed"
128 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
129 if [ $? -eq 0 ]; then
130 echo "This should have failed because the path does not end with 'fdroid'!"
133 echo "testing dirname exists checker passed"
135 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
136 if [ $? -eq 0 ]; then
137 echo "This should have failed because the dirname path does not exist!"
140 echo "testing dirname exists checker passed"
145 #------------------------------------------------------------------------------#
146 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
148 REPOROOT=`create_test_dir`
151 copy_apks_into_repo $REPOROOT
152 $fdroid update --create-metadata
153 grep -F '<application id=' repo/index.xml
155 LOCALCOPYDIR=`create_test_dir`/fdroid
156 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
157 NEWREPOROOT=`create_test_dir`
160 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
163 #------------------------------------------------------------------------------#
164 # check that --android-home fails when dir does not exist or is not a dir
166 REPOROOT=`create_test_dir`
167 KEYSTORE=$REPOROOT/keystore.jks
170 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
171 if [ $? -eq 0 ]; then
172 echo "This should have failed because /opt/fakeandroidhome does not exist!"
175 echo "testing android-home path checker passed"
177 TESTFILE=`create_test_file`
178 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
179 if [ $? -eq 0 ]; then
180 echo "This should have failed because $TESTFILE is a file not a dir!"
183 echo "testing android-home not-dir checker passed"
188 #------------------------------------------------------------------------------#
189 echo_header "check that fake android home passes 'fdroid init'"
191 REPOROOT=`create_test_dir`
192 FAKE_ANDROID_HOME=`create_test_dir`
193 create_fake_android_home $FAKE_ANDROID_HOME
194 KEYSTORE=$REPOROOT/keystore.jks
196 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
199 #------------------------------------------------------------------------------#
200 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
202 REPOROOT=`create_test_dir`
203 FAKE_ANDROID_HOME=`create_test_dir`
204 create_fake_android_home $FAKE_ANDROID_HOME
205 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
206 KEYSTORE=$REPOROOT/keystore.jks
209 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
210 [ $? -eq 0 ] && exit 1
214 #------------------------------------------------------------------------------#
215 echo_header "check that --android-home overrides ANDROID_HOME"
217 REPOROOT=`create_test_dir`
218 FAKE_ANDROID_HOME=`create_test_dir`
219 create_fake_android_home $FAKE_ANDROID_HOME
220 KEYSTORE=$REPOROOT/keystore.jks
222 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
224 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
225 if [ $? -ne 0 ]; then
226 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
232 #------------------------------------------------------------------------------#
233 # In this case, ANDROID_HOME is set to a fake, non-working version that will
234 # be detected by fdroid as an Android SDK install. It should use the path set
235 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
236 # in ANDROID_HOME, it won't work because it is a fake one. Only
237 # --android-home provides a working one.
238 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
240 REPOROOT=`create_test_dir`
241 KEYSTORE=$REPOROOT/keystore.jks
242 FAKE_ANDROID_HOME=`create_test_dir`
243 create_fake_android_home $FAKE_ANDROID_HOME
244 STORED_ANDROID_HOME=$ANDROID_HOME
246 echo "ANDROID_HOME: $ANDROID_HOME"
248 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
250 copy_apks_into_repo $REPOROOT
251 $fdroid update --create-metadata
252 grep -F '<application id=' repo/index.xml
253 test -e repo/index.xml
254 test -e repo/index.jar
255 export ANDROID_HOME=$STORED_ANDROID_HOME
258 #------------------------------------------------------------------------------#
259 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
261 REPOROOT=`create_test_dir`
264 copy_apks_into_repo $REPOROOT
266 $fdroid update --create-metadata
267 grep -F '<application id=' repo/index.xml
270 #------------------------------------------------------------------------------#
271 echo_header "setup a new repo from scratch and generate a keystore"
273 REPOROOT=`create_test_dir`
274 KEYSTORE=$REPOROOT/keystore.jks
276 $fdroid init --keystore $KEYSTORE
278 copy_apks_into_repo $REPOROOT
279 $fdroid update --create-metadata
280 test -e repo/index.xml
281 test -e repo/index.jar
282 grep -F '<application id=' repo/index.xml
285 #------------------------------------------------------------------------------#
286 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
288 REPOROOT=`create_test_dir`
289 KEYSTORE=$REPOROOT/keystore.jks
291 $fdroid init --keystore $KEYSTORE
293 copy_apks_into_repo $REPOROOT
294 $fdroid update --create-metadata
295 test -e repo/index.xml
296 test -e repo/index.jar
297 grep -F '<application id=' repo/index.xml
298 cp $WORKSPACE/tests/urzip.apk $REPOROOT/
299 $fdroid update --create-metadata
300 test -e repo/index.xml
301 test -e repo/index.jar
302 grep -F '<application id=' repo/index.xml
305 #------------------------------------------------------------------------------#
306 echo_header "setup a new repo from scratch with a HSM/smartcard"
308 REPOROOT=`create_test_dir`
310 $fdroid init --keystore NONE
311 test -e opensc-fdroid.cfg