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 #------------------------------------------------------------------------------#
45 if [ $1 = "-h" ] || [ $1 = "--help" ]; then
47 echo "Usage: $0 '/path/to/folder/with/apks'"
51 if [ -z $ANDROID_HOME ]; then
52 echo "ANDROID_HOME must be set with the path to the Android SDK, i.e.: "
53 echo " export ANDROID_HOME=/opt/android-sdk"
63 if [ -z $WORKSPACE ]; then
64 WORKSPACE=`dirname $(pwd)`
65 echo "Setting Workspace to $WORKSPACE"
68 # allow the location of the script to be overridden
69 if [ -z $fdroid ]; then
70 fdroid="$WORKSPACE/fdroid"
73 # allow the location of aapt to be overridden
75 aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
79 #------------------------------------------------------------------------------#
80 echo_header "create a source tarball and use that to build a repo"
85 REPOROOT=`create_test_dir`
87 tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
88 cd $REPOROOT/fdroidserver-*/fdroidserver/getsig
91 ./fdroidserver-*/fdroid init
92 copy_apks_into_repo $REPOROOT
93 ./fdroidserver-*/fdroid update --create-metadata
96 #------------------------------------------------------------------------------#
97 echo_header "test config checks of local_copy_dir"
99 REPOROOT=`create_test_dir`
102 $fdroid update --create-metadata
103 $fdroid server update --local-copy-dir=/tmp/fdroid
105 # now test the errors work
107 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
108 if [ $? -eq 0 ]; then
109 echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
112 echo "testing absolute path checker passed"
114 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
115 if [ $? -eq 0 ]; then
116 echo "This should have failed because the path does not end with 'fdroid'!"
119 echo "testing dirname exists checker passed"
121 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
122 if [ $? -eq 0 ]; then
123 echo "This should have failed because the dirname path does not exist!"
126 echo "testing dirname exists checker passed"
131 #------------------------------------------------------------------------------#
132 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
134 REPOROOT=`create_test_dir`
137 copy_apks_into_repo $REPOROOT
138 $fdroid update --create-metadata
139 grep -F '<application id=' repo/index.xml
141 LOCALCOPYDIR=`create_test_dir`/fdroid
142 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
143 NEWREPOROOT=`create_test_dir`
146 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
149 #------------------------------------------------------------------------------#
150 # check that --android-home fails when dir does not exist or is not a dir
152 REPOROOT=`create_test_dir`
153 KEYSTORE=$REPOROOT/keystore.jks
156 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
157 if [ $? -eq 0 ]; then
158 echo "This should have failed because /opt/fakeandroidhome does not exist!"
161 echo "testing android-home path checker passed"
163 TESTFILE=`create_test_file`
164 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
165 if [ $? -eq 0 ]; then
166 echo "This should have failed because $TESTFILE is a file not a dir!"
169 echo "testing android-home not-dir checker passed"
174 #------------------------------------------------------------------------------#
175 echo_header "check that fake android home passes `fdroid init`"
177 REPOROOT=`create_test_dir`
178 FAKE_ANDROID_HOME=`create_test_dir`
179 create_fake_android_home $FAKE_ANDROID_HOME
180 KEYSTORE=$REPOROOT/keystore.jks
182 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
185 #------------------------------------------------------------------------------#
186 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
188 REPOROOT=`create_test_dir`
189 FAKE_ANDROID_HOME=`create_test_dir`
190 create_fake_android_home $FAKE_ANDROID_HOME
191 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
192 KEYSTORE=$REPOROOT/keystore.jks
195 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
196 [ $? -eq 0 ] && exit 1
200 #------------------------------------------------------------------------------#
201 echo_header "check that --android-home overrides ANDROID_HOME"
203 REPOROOT=`create_test_dir`
204 FAKE_ANDROID_HOME=`create_test_dir`
205 create_fake_android_home $FAKE_ANDROID_HOME
206 KEYSTORE=$REPOROOT/keystore.jks
208 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
210 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
211 if [ $? -ne 0 ]; then
212 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
218 #------------------------------------------------------------------------------#
219 # In this case, ANDROID_HOME is set to a fake, non-working version that will
220 # be detected by fdroid as an Android SDK install. It should use the path set
221 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
222 # in ANDROID_HOME, it won't work because it is a fake one. Only
223 # --android-home provides a working one.
224 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
226 REPOROOT=`create_test_dir`
227 KEYSTORE=$REPOROOT/keystore.jks
228 FAKE_ANDROID_HOME=`create_test_dir`
229 create_fake_android_home $FAKE_ANDROID_HOME
230 STORED_ANDROID_HOME=$ANDROID_HOME
232 echo "ANDROID_HOME: $ANDROID_HOME"
234 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
236 copy_apks_into_repo $REPOROOT
237 $fdroid update --create-metadata
238 grep -F '<application id=' repo/index.xml
239 test -e repo/index.xml
240 test -e repo/index.jar
241 export ANDROID_HOME=$STORED_ANDROID_HOME
244 #------------------------------------------------------------------------------#
245 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
247 REPOROOT=`create_test_dir`
250 copy_apks_into_repo $REPOROOT
252 $fdroid update --create-metadata
253 grep -F '<application id=' repo/index.xml
256 #------------------------------------------------------------------------------#
257 echo_header "setup a new repo from scratch and generate a keystore"
259 REPOROOT=`create_test_dir`
260 KEYSTORE=$REPOROOT/keystore.jks
262 $fdroid init --keystore $KEYSTORE
264 copy_apks_into_repo $REPOROOT
265 $fdroid update --create-metadata
266 test -e repo/index.xml
267 test -e repo/index.jar
268 grep -F '<application id=' repo/index.xml
271 #------------------------------------------------------------------------------#
272 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
274 REPOROOT=`create_test_dir`
275 KEYSTORE=$REPOROOT/keystore.jks
277 $fdroid init --keystore $KEYSTORE
279 copy_apks_into_repo $REPOROOT
280 $fdroid update --create-metadata
281 test -e repo/index.xml
282 test -e repo/index.jar
283 grep -F '<application id=' repo/index.xml
284 cp $WORKSPACE/tests/urzip.apk $REPOROOT/
285 $fdroid update --create-metadata
286 test -e repo/index.xml
287 test -e repo/index.jar
288 grep -F '<application id=' repo/index.xml
291 #------------------------------------------------------------------------------#
292 echo_header "setup a new repo from scratch with a HSM/smartcard"
294 REPOROOT=`create_test_dir`
296 $fdroid init --keystore NONE
297 test -e opensc-fdroid.cfg