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`
81 #------------------------------------------------------------------------------#
82 echo_header "create a source tarball and use that to build a repo"
87 REPOROOT=`create_test_dir`
89 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
90 cd $REPOROOT/fdroidserver-*/fdroidserver/getsig
93 ./fdroidserver-*/fdroid init
94 copy_apks_into_repo $REPOROOT
95 ./fdroidserver-*/fdroid update --create-metadata
98 #------------------------------------------------------------------------------#
99 echo_header "test config checks of local_copy_dir"
101 REPOROOT=`create_test_dir`
104 $fdroid update --create-metadata
105 $fdroid server update --local-copy-dir=/tmp/fdroid
107 # now test the errors work
109 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
110 if [ $? -eq 0 ]; then
111 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
114 echo "testing absolute path checker passed"
116 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
117 if [ $? -eq 0 ]; then
118 echo "This should have failed because the path does not end with 'fdroid'!"
121 echo "testing dirname exists checker passed"
123 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
124 if [ $? -eq 0 ]; then
125 echo "This should have failed because the dirname path does not exist!"
128 echo "testing dirname exists checker passed"
133 #------------------------------------------------------------------------------#
134 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
136 REPOROOT=`create_test_dir`
139 copy_apks_into_repo $REPOROOT
140 $fdroid update --create-metadata
141 grep -F '<application id=' repo/index.xml
143 LOCALCOPYDIR=`create_test_dir`/fdroid
144 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
145 NEWREPOROOT=`create_test_dir`
148 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
151 #------------------------------------------------------------------------------#
152 # check that --android-home fails when dir does not exist or is not a dir
154 REPOROOT=`create_test_dir`
155 KEYSTORE=$REPOROOT/keystore.jks
158 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
159 if [ $? -eq 0 ]; then
160 echo "This should have failed because /opt/fakeandroidhome does not exist!"
163 echo "testing android-home path checker passed"
165 TESTFILE=`create_test_file`
166 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
167 if [ $? -eq 0 ]; then
168 echo "This should have failed because $TESTFILE is a file not a dir!"
171 echo "testing android-home not-dir checker passed"
176 #------------------------------------------------------------------------------#
177 echo_header "check that fake android home passes `fdroid init`"
179 REPOROOT=`create_test_dir`
180 FAKE_ANDROID_HOME=`create_test_dir`
181 create_fake_android_home $FAKE_ANDROID_HOME
182 KEYSTORE=$REPOROOT/keystore.jks
184 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
187 #------------------------------------------------------------------------------#
188 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
190 REPOROOT=`create_test_dir`
191 FAKE_ANDROID_HOME=`create_test_dir`
192 create_fake_android_home $FAKE_ANDROID_HOME
193 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
194 KEYSTORE=$REPOROOT/keystore.jks
197 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
198 [ $? -eq 0 ] && exit 1
202 #------------------------------------------------------------------------------#
203 echo_header "check that --android-home overrides ANDROID_HOME"
205 REPOROOT=`create_test_dir`
206 FAKE_ANDROID_HOME=`create_test_dir`
207 create_fake_android_home $FAKE_ANDROID_HOME
208 KEYSTORE=$REPOROOT/keystore.jks
210 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
212 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
213 if [ $? -ne 0 ]; then
214 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
220 #------------------------------------------------------------------------------#
221 # In this case, ANDROID_HOME is set to a fake, non-working version that will
222 # be detected by fdroid as an Android SDK install. It should use the path set
223 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
224 # in ANDROID_HOME, it won't work because it is a fake one. Only
225 # --android-home provides a working one.
226 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
228 REPOROOT=`create_test_dir`
229 KEYSTORE=$REPOROOT/keystore.jks
230 FAKE_ANDROID_HOME=`create_test_dir`
231 create_fake_android_home $FAKE_ANDROID_HOME
232 STORED_ANDROID_HOME=$ANDROID_HOME
234 echo "ANDROID_HOME: $ANDROID_HOME"
236 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
238 copy_apks_into_repo $REPOROOT
239 $fdroid update --create-metadata
240 grep -F '<application id=' repo/index.xml
241 test -e repo/index.xml
242 test -e repo/index.jar
243 export ANDROID_HOME=$STORED_ANDROID_HOME
246 #------------------------------------------------------------------------------#
247 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
249 REPOROOT=`create_test_dir`
252 copy_apks_into_repo $REPOROOT
254 $fdroid update --create-metadata
255 grep -F '<application id=' repo/index.xml
258 #------------------------------------------------------------------------------#
259 echo_header "setup a new repo from scratch and generate a keystore"
261 REPOROOT=`create_test_dir`
262 KEYSTORE=$REPOROOT/keystore.jks
264 $fdroid init --keystore $KEYSTORE
266 copy_apks_into_repo $REPOROOT
267 $fdroid update --create-metadata
268 test -e repo/index.xml
269 test -e repo/index.jar
270 grep -F '<application id=' repo/index.xml
273 #------------------------------------------------------------------------------#
274 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
276 REPOROOT=`create_test_dir`
277 KEYSTORE=$REPOROOT/keystore.jks
279 $fdroid init --keystore $KEYSTORE
281 copy_apks_into_repo $REPOROOT
282 $fdroid update --create-metadata
283 test -e repo/index.xml
284 test -e repo/index.jar
285 grep -F '<application id=' repo/index.xml
286 cp $WORKSPACE/tests/urzip.apk $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
293 #------------------------------------------------------------------------------#
294 echo_header "setup a new repo from scratch with a HSM/smartcard"
296 REPOROOT=`create_test_dir`
298 $fdroid init --keystore NONE
299 test -e opensc-fdroid.cfg