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 "setup a new repo from scratch using ANDROID_HOME"
76 REPOROOT=`create_test_dir`
79 copy_apks_into_repo $REPOROOT
80 $fdroid update --create-metadata
81 grep -F '<application id=' repo/index.xml
84 #------------------------------------------------------------------------------#
85 # check that --android-home fails when dir does not exist or is not a dir
87 REPOROOT=`create_test_dir`
88 KEYSTORE=$REPOROOT/keystore.jks
91 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
93 echo "This should have failed because /opt/fakeandroidhome does not exist!"
96 echo "testing android-home path checker passed"
98 TESTFILE=`create_test_file`
99 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
100 if [ $? -eq 0 ]; then
101 echo "This should have failed because $TESTFILE is a file not a dir!"
104 echo "testing android-home not-dir checker passed"
109 #------------------------------------------------------------------------------#
110 echo_header "check that fake android home passes `fdroid init`"
112 REPOROOT=`create_test_dir`
113 FAKE_ANDROID_HOME=`create_test_dir`
114 create_fake_android_home $FAKE_ANDROID_HOME
115 KEYSTORE=$REPOROOT/keystore.jks
117 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
120 #------------------------------------------------------------------------------#
121 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
123 REPOROOT=`create_test_dir`
124 FAKE_ANDROID_HOME=`create_test_dir`
125 create_fake_android_home $FAKE_ANDROID_HOME
126 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
127 KEYSTORE=$REPOROOT/keystore.jks
130 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
131 [ $? -eq 0 ] && exit 1
135 #------------------------------------------------------------------------------#
136 echo_header "check that --android-home overrides ANDROID_HOME"
138 REPOROOT=`create_test_dir`
139 FAKE_ANDROID_HOME=`create_test_dir`
140 create_fake_android_home $FAKE_ANDROID_HOME
141 KEYSTORE=$REPOROOT/keystore.jks
143 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
145 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
146 if [ $? -ne 0 ]; then
147 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
153 #------------------------------------------------------------------------------#
154 # In this case, ANDROID_HOME is set to a fake, non-working version that will
155 # be detected by fdroid as an Android SDK install. It should use the path set
156 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
157 # in ANDROID_HOME, it won't work because it is a fake one. Only
158 # --android-home provides a working one.
159 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
161 REPOROOT=`create_test_dir`
162 KEYSTORE=$REPOROOT/keystore.jks
163 FAKE_ANDROID_HOME=`create_test_dir`
164 create_fake_android_home $FAKE_ANDROID_HOME
165 STORED_ANDROID_HOME=$ANDROID_HOME
167 echo "ANDROID_HOME: $ANDROID_HOME"
169 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
171 copy_apks_into_repo $REPOROOT
172 $fdroid update --create-metadata
173 grep -F '<application id=' repo/index.xml
174 test -e repo/index.xml
175 test -e repo/index.jar
176 export ANDROID_HOME=$STORED_ANDROID_HOME
179 #------------------------------------------------------------------------------#
180 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
182 REPOROOT=`create_test_dir`
185 copy_apks_into_repo $REPOROOT
187 $fdroid update --create-metadata
188 grep -F '<application id=' repo/index.xml
191 #------------------------------------------------------------------------------#
192 echo_header "setup a new repo from scratch and generate a keystore"
194 REPOROOT=`create_test_dir`
195 KEYSTORE=$REPOROOT/keystore.jks
197 $fdroid init --keystore $KEYSTORE
199 copy_apks_into_repo $REPOROOT
200 $fdroid update --create-metadata
201 test -e repo/index.xml
202 test -e repo/index.jar
203 grep -F '<application id=' repo/index.xml
206 #------------------------------------------------------------------------------#
207 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
209 REPOROOT=`create_test_dir`
210 KEYSTORE=$REPOROOT/keystore.jks
212 $fdroid init --keystore $KEYSTORE
214 copy_apks_into_repo $REPOROOT
215 $fdroid update --create-metadata
216 test -e repo/index.xml
217 test -e repo/index.jar
218 grep -F '<application id=' repo/index.xml
219 cp $WORKSPACE/tests/urzip.apk $REPOROOT/
220 $fdroid update --create-metadata
221 test -e repo/index.xml
222 test -e repo/index.jar
223 grep -F '<application id=' repo/index.xml
226 #------------------------------------------------------------------------------#
227 echo_header "setup a new repo from scratch with a HSM/smartcard"
229 REPOROOT=`create_test_dir`
231 $fdroid init --keystore NONE
232 test -e opensc-fdroid.cfg