chiark / gitweb /
Current build-tools is 19.1.0, not 19.1
[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 APKDIR=$1
51
52 if [ -z $WORKSPACE ]; then
53     WORKSPACE=`dirname $(pwd)`
54     echo "Setting Workspace to $WORKSPACE"
55 fi
56
57 # allow the location of the script to be overridden
58 if [ -z $fdroid ]; then
59     fdroid="$WORKSPACE/fdroid"
60 fi
61
62 #------------------------------------------------------------------------------#
63 echo_header "setup a new repo from scratch using ANDROID_HOME"
64
65 REPOROOT=`create_test_dir`
66 cd $REPOROOT
67 $fdroid init
68 copy_apks_into_repo $REPOROOT
69 $fdroid update --create-metadata
70 grep -F '<application id=' repo/index.xml
71
72
73 #------------------------------------------------------------------------------#
74 # check that --android-home fails when dir does not exist or is not a dir
75
76 REPOROOT=`create_test_dir`
77 KEYSTORE=$REPOROOT/keystore.jks
78 cd $REPOROOT
79 set +e
80 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
81 if [ $? -eq 0 ]; then
82     echo "This should have failed because /opt/fakeandroidhome does not exist!"
83     exit 1
84 else
85     echo "testing android-home path checker passed"
86 fi
87 TESTFILE=`create_test_file`
88 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
89 if [ $? -eq 0 ]; then
90     echo "This should have failed because $TESTFILE is a file not a dir!"
91     exit 1
92 else
93     echo "testing android-home not-dir checker passed"
94 fi
95 set -e
96
97
98 #------------------------------------------------------------------------------#
99 echo_header "check that fake android home passes `fdroid init`"
100
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
105 cd $REPOROOT
106 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
107
108
109 #------------------------------------------------------------------------------#
110 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
111
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
117 cd $REPOROOT
118 set +e
119 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
120 [ $? -eq 0 ] && exit 1
121 set -e
122
123
124 #------------------------------------------------------------------------------#
125 echo_header "check that --android-home overrides ANDROID_HOME"
126
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
131 cd $REPOROOT
132 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
133 set +e
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'"
137     exit 1
138 fi
139 set -e
140
141
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"
149
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
155 unset ANDROID_HOME
156 echo "ANDROID_HOME: $ANDROID_HOME"
157 cd $REPOROOT
158 $fdroid init --keystore $KEYSTORE --android-home $STORED_ANDROID_HOME --no-prompt
159 test -e $KEYSTORE
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
166
167
168 #------------------------------------------------------------------------------#
169 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
170
171 REPOROOT=`create_test_dir`
172 cd $REPOROOT
173 mkdir repo
174 copy_apks_into_repo $REPOROOT
175 $fdroid init
176 $fdroid update --create-metadata
177 grep -F '<application id=' repo/index.xml
178
179
180 #------------------------------------------------------------------------------#
181 echo_header "setup a new repo from scratch and generate a keystore"
182
183 REPOROOT=`create_test_dir`
184 KEYSTORE=$REPOROOT/keystore.jks
185 cd $REPOROOT
186 $fdroid init --keystore $KEYSTORE
187 test -e $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
193
194
195 #------------------------------------------------------------------------------#
196 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
197
198 REPOROOT=`create_test_dir`
199 KEYSTORE=$REPOROOT/keystore.jks
200 cd $REPOROOT
201 $fdroid init --keystore $KEYSTORE
202 test -e $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
213
214
215 #------------------------------------------------------------------------------#
216 echo_header "setup a new repo from scratch with a HSM/smartcard"
217
218 REPOROOT=`create_test_dir`
219 cd $REPOROOT
220 $fdroid init --keystore NONE
221 test -e opensc-fdroid.cfg
222 test ! -e NONE
223
224
225 echo SUCCESS