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/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 "create a source tarball and use that to build a repo"
99 $python setup.py sdist
101 REPOROOT=`create_test_dir`
103 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
104 cd $REPOROOT/fdroidserver-*/fdroidserver/getsig
107 ./fdroidserver-*/fdroid init
108 copy_apks_into_repo $REPOROOT
109 ./fdroidserver-*/fdroid update --create-metadata
112 #------------------------------------------------------------------------------#
113 echo_header "test config checks of local_copy_dir"
115 REPOROOT=`create_test_dir`
118 $fdroid update --create-metadata
119 $fdroid server update --local-copy-dir=/tmp/fdroid
121 # now test the errors work
123 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
124 if [ $? -eq 0 ]; then
125 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
128 echo "testing absolute path checker passed"
130 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
131 if [ $? -eq 0 ]; then
132 echo "This should have failed because the path does not end with 'fdroid'!"
135 echo "testing dirname exists checker passed"
137 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
138 if [ $? -eq 0 ]; then
139 echo "This should have failed because the dirname path does not exist!"
142 echo "testing dirname exists checker passed"
147 #------------------------------------------------------------------------------#
148 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
150 REPOROOT=`create_test_dir`
153 copy_apks_into_repo $REPOROOT
154 $fdroid update --create-metadata
155 grep -F '<application id=' repo/index.xml
157 LOCALCOPYDIR=`create_test_dir`/fdroid
158 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
159 NEWREPOROOT=`create_test_dir`
162 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
165 #------------------------------------------------------------------------------#
166 # check that --android-home fails when dir does not exist or is not a dir
168 REPOROOT=`create_test_dir`
169 KEYSTORE=$REPOROOT/keystore.jks
172 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
173 if [ $? -eq 0 ]; then
174 echo "This should have failed because /opt/fakeandroidhome does not exist!"
177 echo "testing android-home path checker passed"
179 TESTFILE=`create_test_file`
180 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
181 if [ $? -eq 0 ]; then
182 echo "This should have failed because $TESTFILE is a file not a dir!"
185 echo "testing android-home not-dir checker passed"
190 #------------------------------------------------------------------------------#
191 echo_header "check that fake android home passes 'fdroid init'"
193 REPOROOT=`create_test_dir`
194 FAKE_ANDROID_HOME=`create_test_dir`
195 create_fake_android_home $FAKE_ANDROID_HOME
196 KEYSTORE=$REPOROOT/keystore.jks
198 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
201 #------------------------------------------------------------------------------#
202 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
204 REPOROOT=`create_test_dir`
205 FAKE_ANDROID_HOME=`create_test_dir`
206 create_fake_android_home $FAKE_ANDROID_HOME
207 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
208 KEYSTORE=$REPOROOT/keystore.jks
211 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
212 [ $? -eq 0 ] && exit 1
216 #------------------------------------------------------------------------------#
217 echo_header "check that --android-home overrides ANDROID_HOME"
219 REPOROOT=`create_test_dir`
220 FAKE_ANDROID_HOME=`create_test_dir`
221 create_fake_android_home $FAKE_ANDROID_HOME
222 KEYSTORE=$REPOROOT/keystore.jks
224 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
226 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
227 if [ $? -ne 0 ]; then
228 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
234 #------------------------------------------------------------------------------#
235 # In this case, ANDROID_HOME is set to a fake, non-working version that will
236 # be detected by fdroid as an Android SDK install. It should use the path set
237 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
238 # in ANDROID_HOME, it won't work because it is a fake one. Only
239 # --android-home provides a working one.
240 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
242 REPOROOT=`create_test_dir`
243 KEYSTORE=$REPOROOT/keystore.jks
244 FAKE_ANDROID_HOME=`create_test_dir`
245 create_fake_android_home $FAKE_ANDROID_HOME
246 STORED_ANDROID_HOME=$ANDROID_HOME
248 echo "ANDROID_HOME: $ANDROID_HOME"
250 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
252 copy_apks_into_repo $REPOROOT
253 $fdroid update --create-metadata
254 grep -F '<application id=' repo/index.xml
255 test -e repo/index.xml
256 test -e repo/index.jar
257 export ANDROID_HOME=$STORED_ANDROID_HOME
260 #------------------------------------------------------------------------------#
261 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
263 REPOROOT=`create_test_dir`
266 copy_apks_into_repo $REPOROOT
268 $fdroid update --create-metadata
269 grep -F '<application id=' repo/index.xml
272 #------------------------------------------------------------------------------#
273 echo_header "setup a new repo from scratch and generate a keystore"
275 REPOROOT=`create_test_dir`
276 KEYSTORE=$REPOROOT/keystore.jks
278 $fdroid init --keystore $KEYSTORE
280 copy_apks_into_repo $REPOROOT
281 $fdroid update --create-metadata
282 test -e repo/index.xml
283 test -e repo/index.jar
284 grep -F '<application id=' repo/index.xml
287 #------------------------------------------------------------------------------#
288 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
290 REPOROOT=`create_test_dir`
291 KEYSTORE=$REPOROOT/keystore.jks
293 $fdroid init --keystore $KEYSTORE
295 copy_apks_into_repo $REPOROOT
296 $fdroid update --create-metadata
297 test -e repo/index.xml
298 test -e repo/index.jar
299 grep -F '<application id=' repo/index.xml
300 cp $WORKSPACE/tests/urzip.apk $REPOROOT/
301 $fdroid update --create-metadata
302 test -e repo/index.xml
303 test -e repo/index.jar
304 grep -F '<application id=' repo/index.xml
307 #------------------------------------------------------------------------------#
308 echo_header "setup a new repo from scratch with a HSM/smartcard"
310 REPOROOT=`create_test_dir`
312 $fdroid init --keystore NONE
313 test -e opensc-fdroid.cfg