chiark / gitweb /
server: --sync-from-local-copy-dir for updating from offline signing repo
[fdroidserver.git] / tests / run-tests
1 #!/bin/bash
2
3 set -e # quit script on error
4 set -x # show each command as it is executed
5
6 echo_header() {
7     echo "=============================================================================="
8     echo $1
9 }
10
11 copy_apks_into_repo() {
12     set +x
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
21         fi
22     done
23     set -x
24 }
25
26 create_fake_android_home() {
27     mkdir $1/build-tools
28     mkdir $1/build-tools/19.1.0
29     touch $1/build-tools/19.1.0/aapt
30 }
31
32 create_test_dir() {
33     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
34     mktemp --directory --tmpdir=$WORKSPACE/.testfiles
35 }
36
37 create_test_file() {
38     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
39     mktemp --tmpdir=$WORKSPACE/.testfiles
40 }
41
42 #------------------------------------------------------------------------------#
43 # "main"
44
45 if [ $# -ne 1 ]; then
46     echo "Usage: $0 '/path/to/folder/with/apks'"
47     exit 1
48 fi
49
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"
53     exit 1
54 fi
55
56 APKDIR=$1
57
58 if [ -z $WORKSPACE ]; then
59     WORKSPACE=`dirname $(pwd)`
60     echo "Setting Workspace to $WORKSPACE"
61 fi
62
63 # allow the location of the script to be overridden
64 if [ -z $fdroid ]; then
65     fdroid="$WORKSPACE/fdroid"
66 fi
67
68 # allow the location of aapt to be overridden
69 if [ -z $aapt ]; then
70     aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
71 fi
72
73 #------------------------------------------------------------------------------#
74 echo_header "test config checks of local_copy_dir"
75
76 REPOROOT=`create_test_dir`
77 cd $REPOROOT
78 $fdroid init
79 $fdroid update --create-metadata
80 $fdroid server update --local-copy-dir=/tmp/fdroid
81
82 # now test the errors work
83 set +e
84 $fdroid server update --local-copy-dir=thisisnotanabsolutepath
85 if [ $? -eq 0 ]; then
86     echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
87     exit 1
88 else
89     echo "testing absolute path checker passed"
90 fi
91 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
92 if [ $? -eq 0 ]; then
93     echo "This should have failed because the path does not end with 'fdroid'!"
94     exit 1
95 else
96     echo "testing dirname exists checker passed"
97 fi
98 $fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
99 if [ $? -eq 0 ]; then
100     echo "This should have failed because the dirname path does not exist!"
101     exit 1
102 else
103     echo "testing dirname exists checker passed"
104 fi
105 set -e
106
107
108 #------------------------------------------------------------------------------#
109 echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
110
111 REPOROOT=`create_test_dir`
112 cd $REPOROOT
113 $fdroid init
114 copy_apks_into_repo $REPOROOT
115 $fdroid update --create-metadata
116 grep -F '<application id=' repo/index.xml
117
118 LOCALCOPYDIR=`create_test_dir`/fdroid
119 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
120 NEWREPOROOT=`create_test_dir`
121 cd $NEWREPOROOT
122 $fdroid init
123 $fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
124
125
126 #------------------------------------------------------------------------------#
127 # check that --android-home fails when dir does not exist or is not a dir
128
129 REPOROOT=`create_test_dir`
130 KEYSTORE=$REPOROOT/keystore.jks
131 cd $REPOROOT
132 set +e
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!"
136     exit 1
137 else
138     echo "testing android-home path checker passed"
139 fi
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!"
144     exit 1
145 else
146     echo "testing android-home not-dir checker passed"
147 fi
148 set -e
149
150
151 #------------------------------------------------------------------------------#
152 echo_header "check that fake android home passes `fdroid init`"
153
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
158 cd $REPOROOT
159 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
160
161
162 #------------------------------------------------------------------------------#
163 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
164
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
170 cd $REPOROOT
171 set +e
172 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
173 [ $? -eq 0 ] && exit 1
174 set -e
175
176
177 #------------------------------------------------------------------------------#
178 echo_header "check that --android-home overrides ANDROID_HOME"
179
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
184 cd $REPOROOT
185 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
186 set +e
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'"
190     exit 1
191 fi
192 set -e
193
194
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"
202
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
208 unset ANDROID_HOME
209 echo "ANDROID_HOME: $ANDROID_HOME"
210 cd $REPOROOT
211 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
212 test -e $KEYSTORE
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
219
220
221 #------------------------------------------------------------------------------#
222 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
223
224 REPOROOT=`create_test_dir`
225 cd $REPOROOT
226 mkdir repo
227 copy_apks_into_repo $REPOROOT
228 $fdroid init
229 $fdroid update --create-metadata
230 grep -F '<application id=' repo/index.xml
231
232
233 #------------------------------------------------------------------------------#
234 echo_header "setup a new repo from scratch and generate a keystore"
235
236 REPOROOT=`create_test_dir`
237 KEYSTORE=$REPOROOT/keystore.jks
238 cd $REPOROOT
239 $fdroid init --keystore $KEYSTORE
240 test -e $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
246
247
248 #------------------------------------------------------------------------------#
249 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
250
251 REPOROOT=`create_test_dir`
252 KEYSTORE=$REPOROOT/keystore.jks
253 cd $REPOROOT
254 $fdroid init --keystore $KEYSTORE
255 test -e $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
266
267
268 #------------------------------------------------------------------------------#
269 echo_header "setup a new repo from scratch with a HSM/smartcard"
270
271 REPOROOT=`create_test_dir`
272 cd $REPOROOT
273 $fdroid init --keystore NONE
274 test -e opensc-fdroid.cfg
275 test ! -e NONE
276
277
278 echo SUCCESS