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 create_fake_android_home() {
28 mkdir $1/build-tools/19.1.0
29 touch $1/build-tools/19.1.0/aapt
33 test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
34 mktemp --directory --tmpdir=$WORKSPACE/.testfiles
38 test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
39 mktemp --tmpdir=$WORKSPACE/.testfiles
42 #------------------------------------------------------------------------------#
46 echo "Usage: $0 '/path/to/folder/with/apks'"
50 if [ -z $ANDROID_HOME ]; then
51 echo "ANDROID_HOME must be set with the path to the Android SDK, i.e.: "
52 echo " export ANDROID_HOME=/opt/android-sdk"
58 if [ -z $WORKSPACE ]; then
59 WORKSPACE=`dirname $(pwd)`
60 echo "Setting Workspace to $WORKSPACE"
63 # allow the location of the script to be overridden
64 if [ -z $fdroid ]; then
65 fdroid="$WORKSPACE/fdroid"
68 # allow the location of aapt to be overridden
70 aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
73 #------------------------------------------------------------------------------#
74 echo_header "test config checks of local_copy_dir"
76 REPOROOT=`create_test_dir`
79 $fdroid update --create-metadata
80 $fdroid server update --local-copy-dir=/tmp/fdroid
82 # now test the errors work
84 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
86 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
89 echo "testing absolute path checker passed"
91 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
93 echo "This should have failed because the path does not end with 'fdroid'!"
96 echo "testing dirname exists checker passed"
98 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
100 echo "This should have failed because the dirname path does not exist!"
103 echo "testing dirname exists checker passed"
108 #------------------------------------------------------------------------------#
109 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
111 REPOROOT=`create_test_dir`
114 copy_apks_into_repo $REPOROOT
115 $fdroid update --create-metadata
116 grep -F '<application id=' repo/index.xml
118 LOCALCOPYDIR=`create_test_dir`/fdroid
119 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
120 NEWREPOROOT=`create_test_dir`
123 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
126 #------------------------------------------------------------------------------#
127 # check that --android-home fails when dir does not exist or is not a dir
129 REPOROOT=`create_test_dir`
130 KEYSTORE=$REPOROOT/keystore.jks
133 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
134 if [ $? -eq 0 ]; then
135 echo "This should have failed because /opt/fakeandroidhome does not exist!"
138 echo "testing android-home path checker passed"
140 TESTFILE=`create_test_file`
141 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
142 if [ $? -eq 0 ]; then
143 echo "This should have failed because $TESTFILE is a file not a dir!"
146 echo "testing android-home not-dir checker passed"
151 #------------------------------------------------------------------------------#
152 echo_header "check that fake android home passes `fdroid init`"
154 REPOROOT=`create_test_dir`
155 FAKE_ANDROID_HOME=`create_test_dir`
156 create_fake_android_home $FAKE_ANDROID_HOME
157 KEYSTORE=$REPOROOT/keystore.jks
159 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
162 #------------------------------------------------------------------------------#
163 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
165 REPOROOT=`create_test_dir`
166 FAKE_ANDROID_HOME=`create_test_dir`
167 create_fake_android_home $FAKE_ANDROID_HOME
168 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
169 KEYSTORE=$REPOROOT/keystore.jks
172 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
173 [ $? -eq 0 ] && exit 1
177 #------------------------------------------------------------------------------#
178 echo_header "check that --android-home overrides ANDROID_HOME"
180 REPOROOT=`create_test_dir`
181 FAKE_ANDROID_HOME=`create_test_dir`
182 create_fake_android_home $FAKE_ANDROID_HOME
183 KEYSTORE=$REPOROOT/keystore.jks
185 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
187 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
188 if [ $? -ne 0 ]; then
189 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
195 #------------------------------------------------------------------------------#
196 # In this case, ANDROID_HOME is set to a fake, non-working version that will
197 # be detected by fdroid as an Android SDK install. It should use the path set
198 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
199 # in ANDROID_HOME, it won't work because it is a fake one. Only
200 # --android-home provides a working one.
201 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
203 REPOROOT=`create_test_dir`
204 KEYSTORE=$REPOROOT/keystore.jks
205 FAKE_ANDROID_HOME=`create_test_dir`
206 create_fake_android_home $FAKE_ANDROID_HOME
207 STORED_ANDROID_HOME=$ANDROID_HOME
209 echo "ANDROID_HOME: $ANDROID_HOME"
211 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
213 copy_apks_into_repo $REPOROOT
214 $fdroid update --create-metadata
215 grep -F '<application id=' repo/index.xml
216 test -e repo/index.xml
217 test -e repo/index.jar
218 export ANDROID_HOME=$STORED_ANDROID_HOME
221 #------------------------------------------------------------------------------#
222 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
224 REPOROOT=`create_test_dir`
227 copy_apks_into_repo $REPOROOT
229 $fdroid update --create-metadata
230 grep -F '<application id=' repo/index.xml
233 #------------------------------------------------------------------------------#
234 echo_header "setup a new repo from scratch and generate a keystore"
236 REPOROOT=`create_test_dir`
237 KEYSTORE=$REPOROOT/keystore.jks
239 $fdroid init --keystore $KEYSTORE
241 copy_apks_into_repo $REPOROOT
242 $fdroid update --create-metadata
243 test -e repo/index.xml
244 test -e repo/index.jar
245 grep -F '<application id=' repo/index.xml
248 #------------------------------------------------------------------------------#
249 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
251 REPOROOT=`create_test_dir`
252 KEYSTORE=$REPOROOT/keystore.jks
254 $fdroid init --keystore $KEYSTORE
256 copy_apks_into_repo $REPOROOT
257 $fdroid update --create-metadata
258 test -e repo/index.xml
259 test -e repo/index.jar
260 grep -F '<application id=' repo/index.xml
261 cp $WORKSPACE/tests/urzip.apk $REPOROOT/
262 $fdroid update --create-metadata
263 test -e repo/index.xml
264 test -e repo/index.jar
265 grep -F '<application id=' repo/index.xml
268 #------------------------------------------------------------------------------#
269 echo_header "setup a new repo from scratch with a HSM/smartcard"
271 REPOROOT=`create_test_dir`
273 $fdroid init --keystore NONE
274 test -e opensc-fdroid.cfg