7 echo "=============================================================================="
11 copy_apks_into_repo() {
12 for f in `find $APKDIR -name '*.apk' | grep -F -v -e unaligned -e unsigned`; do
13 name=$(basename $(dirname `dirname $f`))
14 apk=`aapt dump badging "$f" | sed -n "s,^package: name='\(.*\)' versionCode='\([0-9][0-9]*\)' .*,\1_\2.apk,p"`
15 test $f -nt repo/$apk && rm -f repo/$apk # delete existing if $f is newer
16 if [ ! -e repo/$apk ] && [ ! -e archive/$apk ]; then
17 echo "$f --> repo/$apk"
18 ln $f $1/repo/$apk || \
19 rsync -axv $f $1/repo/$apk # rsync if hard link is not possible
24 create_fake_android_home() {
26 mkdir $1/build-tools/19.0.1
27 touch $1/build-tools/19.0.1/aapt
31 test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
32 mktemp --directory --tmpdir=$WORKSPACE/.testfiles
36 test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
37 mktemp --tmpdir=$WORKSPACE/.testfiles
40 #------------------------------------------------------------------------------#
44 echo "Usage: $0 '/path/to/folder/with/apks'"
50 if [ -z $WORKSPACE ]; then
51 WORKSPACE=`dirname $(pwd)`
52 echo "Setting Workspace to $WORKSPACE"
55 # allow the location of the script to be overridden
56 if [ -z $fdroid ]; then
57 fdroid="$WORKSPACE/fdroid"
60 #------------------------------------------------------------------------------#
61 echo_header "setup a new repo from scratch using ANDROID_HOME"
63 REPOROOT=`create_test_dir`
66 copy_apks_into_repo $REPOROOT
67 $fdroid update --create-metadata
68 grep -F '<application id=' repo/index.xml
71 #------------------------------------------------------------------------------#
72 # check that --android-home fails when dir does not exist or is not a dir
74 REPOROOT=`create_test_dir`
75 KEYSTORE=$REPOROOT/keystore.jks
78 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
80 echo "This should have failed because /opt/fakeandroidhome does not exist!"
83 echo "testing android-home path checker passed"
85 TESTFILE=`create_test_file`
86 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
88 echo "This should have failed because $TESTFILE is a file not a dir!"
91 echo "testing android-home not-dir checker passed"
96 #------------------------------------------------------------------------------#
97 echo_header "check that fake android home passes `fdroid init`"
99 REPOROOT=`create_test_dir`
100 FAKE_ANDROID_HOME=`create_test_dir`
101 create_fake_android_home $FAKE_ANDROID_HOME
102 KEYSTORE=$REPOROOT/keystore.jks
104 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
107 #------------------------------------------------------------------------------#
108 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
110 REPOROOT=`create_test_dir`
111 FAKE_ANDROID_HOME=`create_test_dir`
112 create_fake_android_home $FAKE_ANDROID_HOME
113 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
114 KEYSTORE=$REPOROOT/keystore.jks
117 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
118 [ $? -eq 0 ] && exit 1
122 #------------------------------------------------------------------------------#
123 echo_header "check that --android-home overrides ANDROID_HOME"
125 REPOROOT=`create_test_dir`
126 FAKE_ANDROID_HOME=`create_test_dir`
127 create_fake_android_home $FAKE_ANDROID_HOME
128 KEYSTORE=$REPOROOT/keystore.jks
130 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
132 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
133 if [ $? -ne 0 ]; then
134 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
140 #------------------------------------------------------------------------------#
141 # In this case, ANDROID_HOME is set to a fake, non-working version that will
142 # be detected by fdroid as an Android SDK install. It should use the path set
143 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
144 # in ANDROID_HOME, it won't work because it is a fake one. Only
145 # --android-home provides a working one.
146 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
148 REPOROOT=`create_test_dir`
149 KEYSTORE=$REPOROOT/keystore.jks
150 FAKE_ANDROID_HOME=`create_test_dir`
151 create_fake_android_home $FAKE_ANDROID_HOME
152 STORED_ANDROID_HOME=$ANDROID_HOME
154 echo "ANDROID_HOME: $ANDROID_HOME"
156 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
158 copy_apks_into_repo $REPOROOT
159 $fdroid update --create-metadata
160 grep -F '<application id=' repo/index.xml
161 test -e repo/index.xml
162 test -e repo/index.jar
163 export ANDROID_HOME=$STORED_ANDROID_HOME
166 #------------------------------------------------------------------------------#
167 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
169 REPOROOT=`create_test_dir`
172 copy_apks_into_repo $REPOROOT
174 $fdroid update --create-metadata
175 grep -F '<application id=' repo/index.xml
178 #------------------------------------------------------------------------------#
179 echo_header "setup a new repo from scratch and generate a keystore"
181 REPOROOT=`create_test_dir`
182 KEYSTORE=$REPOROOT/keystore.jks
184 $fdroid init --keystore $KEYSTORE
186 copy_apks_into_repo $REPOROOT
187 $fdroid update --create-metadata
188 test -e repo/index.xml
189 test -e repo/index.jar
190 grep -F '<application id=' repo/index.xml
193 #------------------------------------------------------------------------------#
194 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
196 REPOROOT=`create_test_dir`
197 KEYSTORE=$REPOROOT/keystore.jks
199 $fdroid init --keystore $KEYSTORE
201 copy_apks_into_repo $REPOROOT
202 $fdroid update --create-metadata
203 test -e repo/index.xml
204 test -e repo/index.jar
205 grep -F '<application id=' repo/index.xml
206 cp $WORKSPACE/tests/urzip.apk $REPOROOT/
207 $fdroid update --create-metadata
208 test -e repo/index.xml
209 test -e repo/index.jar
210 grep -F '<application id=' repo/index.xml
213 #------------------------------------------------------------------------------#
214 echo_header "setup a new repo from scratch with a HSM/smartcard"
216 REPOROOT=`create_test_dir`
218 $fdroid init --keystore NONE
219 test -e opensc-fdroid.cfg