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.0.1
29 touch $1/build-tools/19.0.1/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'"
52 if [ -z $WORKSPACE ]; then
53 WORKSPACE=`dirname $(pwd)`
54 echo "Setting Workspace to $WORKSPACE"
57 # allow the location of the script to be overridden
58 if [ -z $fdroid ]; then
59 fdroid="$WORKSPACE/fdroid"
62 #------------------------------------------------------------------------------#
63 echo_header "setup a new repo from scratch using ANDROID_HOME"
65 REPOROOT=`create_test_dir`
68 copy_apks_into_repo $REPOROOT
69 $fdroid update --create-metadata
70 grep -F '<application id=' repo/index.xml
73 #------------------------------------------------------------------------------#
74 # check that --android-home fails when dir does not exist or is not a dir
76 REPOROOT=`create_test_dir`
77 KEYSTORE=$REPOROOT/keystore.jks
80 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
82 echo "This should have failed because /opt/fakeandroidhome does not exist!"
85 echo "testing android-home path checker passed"
87 TESTFILE=`create_test_file`
88 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
90 echo "This should have failed because $TESTFILE is a file not a dir!"
93 echo "testing android-home not-dir checker passed"
98 #------------------------------------------------------------------------------#
99 echo_header "check that fake android home passes `fdroid init`"
101 REPOROOT=`create_test_dir`
102 FAKE_ANDROID_HOME=`create_test_dir`
103 create_fake_android_home $FAKE_ANDROID_HOME
104 KEYSTORE=$REPOROOT/keystore.jks
106 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
109 #------------------------------------------------------------------------------#
110 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
112 REPOROOT=`create_test_dir`
113 FAKE_ANDROID_HOME=`create_test_dir`
114 create_fake_android_home $FAKE_ANDROID_HOME
115 rm -f $FAKE_ANDROID_HOME/build-tools/*/aapt
116 KEYSTORE=$REPOROOT/keystore.jks
119 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
120 [ $? -eq 0 ] && exit 1
124 #------------------------------------------------------------------------------#
125 echo_header "check that --android-home overrides ANDROID_HOME"
127 REPOROOT=`create_test_dir`
128 FAKE_ANDROID_HOME=`create_test_dir`
129 create_fake_android_home $FAKE_ANDROID_HOME
130 KEYSTORE=$REPOROOT/keystore.jks
132 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
134 grep $FAKE_ANDROID_HOME $REPOROOT/config.py
135 if [ $? -ne 0 ]; then
136 echo "the value set in --android-home '$FAKE_ANDROID_HOME' should override ANDROID_HOME '$ANDROID_HOME'"
142 #------------------------------------------------------------------------------#
143 # In this case, ANDROID_HOME is set to a fake, non-working version that will
144 # be detected by fdroid as an Android SDK install. It should use the path set
145 # by --android-home over the one in ANDROID_HOME, therefore if it uses the one
146 # in ANDROID_HOME, it won't work because it is a fake one. Only
147 # --android-home provides a working one.
148 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
150 REPOROOT=`create_test_dir`
151 KEYSTORE=$REPOROOT/keystore.jks
152 FAKE_ANDROID_HOME=`create_test_dir`
153 create_fake_android_home $FAKE_ANDROID_HOME
154 STORED_ANDROID_HOME=$ANDROID_HOME
156 echo "ANDROID_HOME: $ANDROID_HOME"
158 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
160 copy_apks_into_repo $REPOROOT
161 $fdroid update --create-metadata
162 grep -F '<application id=' repo/index.xml
163 test -e repo/index.xml
164 test -e repo/index.jar
165 export ANDROID_HOME=$STORED_ANDROID_HOME
168 #------------------------------------------------------------------------------#
169 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
171 REPOROOT=`create_test_dir`
174 copy_apks_into_repo $REPOROOT
176 $fdroid update --create-metadata
177 grep -F '<application id=' repo/index.xml
180 #------------------------------------------------------------------------------#
181 echo_header "setup a new repo from scratch and generate a keystore"
183 REPOROOT=`create_test_dir`
184 KEYSTORE=$REPOROOT/keystore.jks
186 $fdroid init --keystore $KEYSTORE
188 copy_apks_into_repo $REPOROOT
189 $fdroid update --create-metadata
190 test -e repo/index.xml
191 test -e repo/index.jar
192 grep -F '<application id=' repo/index.xml
195 #------------------------------------------------------------------------------#
196 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
198 REPOROOT=`create_test_dir`
199 KEYSTORE=$REPOROOT/keystore.jks
201 $fdroid init --keystore $KEYSTORE
203 copy_apks_into_repo $REPOROOT
204 $fdroid update --create-metadata
205 test -e repo/index.xml
206 test -e repo/index.jar
207 grep -F '<application id=' repo/index.xml
208 cp $WORKSPACE/tests/urzip.apk $REPOROOT/
209 $fdroid update --create-metadata
210 test -e repo/index.xml
211 test -e repo/index.jar
212 grep -F '<application id=' repo/index.xml
215 #------------------------------------------------------------------------------#
216 echo_header "setup a new repo from scratch with a HSM/smartcard"
218 REPOROOT=`create_test_dir`
220 $fdroid init --keystore NONE
221 test -e opensc-fdroid.cfg