chiark / gitweb /
tests: specify dir for APKs as cmd line arg, and set jenkins to ~
[fdroidserver.git] / tests / run-tests
1 #!/bin/bash
2
3 set -e
4 set -x
5
6 echo_header() {
7     echo "=============================================================================="
8     echo $1
9 }
10
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
20         fi
21     done
22 }
23
24 create_fake_android_home() {
25     mkdir $1/build-tools
26     mkdir $1/build-tools/19.0.1
27     touch $1/build-tools/19.0.1/aapt
28 }
29
30 create_test_dir() {
31     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
32     mktemp --directory --tmpdir=$WORKSPACE/.testfiles
33 }
34
35 create_test_file() {
36     test -e $WORKSPACE/.testfiles || mkdir $WORKSPACE/.testfiles
37     mktemp --tmpdir=$WORKSPACE/.testfiles
38 }
39
40 #------------------------------------------------------------------------------#
41 # "main"
42
43 if [ $# -ne 1 ]; then
44     echo "Usage: $0 '/path/to/folder/with/apks'"
45     exit 1
46 fi
47
48 APKDIR=$1
49
50 if [ -z $WORKSPACE ]; then
51     WORKSPACE=`dirname $(pwd)`
52     echo "Setting Workspace to $WORKSPACE"
53 fi
54
55 # allow the location of the script to be overridden
56 if [ -z $fdroid ]; then
57     fdroid="$WORKSPACE/fdroid"
58 fi
59
60 #------------------------------------------------------------------------------#
61 echo_header "setup a new repo from scratch using ANDROID_HOME"
62
63 REPOROOT=`create_test_dir`
64 cd $REPOROOT
65 $fdroid init
66 copy_apks_into_repo $REPOROOT
67 $fdroid update --create-metadata
68 grep -F '<application id=' repo/index.xml
69
70
71 #------------------------------------------------------------------------------#
72 # check that --android-home fails when dir does not exist or is not a dir
73
74 REPOROOT=`create_test_dir`
75 KEYSTORE=$REPOROOT/keystore.jks
76 cd $REPOROOT
77 set +e
78 $fdroid init --keystore $KEYSTORE --android-home /opt/fakeandroidhome
79 if [ $? -eq 0 ]; then
80     echo "This should have failed because /opt/fakeandroidhome does not exist!"
81     exit 1
82 else
83     echo "testing android-home path checker passed"
84 fi
85 TESTFILE=`create_test_file`
86 $fdroid init --keystore $KEYSTORE --android-home $TESTFILE
87 if [ $? -eq 0 ]; then
88     echo "This should have failed because $TESTFILE is a file not a dir!"
89     exit 1
90 else
91     echo "testing android-home not-dir checker passed"
92 fi
93 set -e
94
95
96 #------------------------------------------------------------------------------#
97 echo_header "check that fake android home passes `fdroid init`"
98
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
103 cd $REPOROOT
104 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
105
106
107 #------------------------------------------------------------------------------#
108 echo_header "check that 'fdroid init' fails when build-tools cannot be found"
109
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
115 cd $REPOROOT
116 set +e
117 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
118 [ $? -eq 0 ] && exit 1
119 set -e
120
121
122 #------------------------------------------------------------------------------#
123 echo_header "check that --android-home overrides ANDROID_HOME"
124
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
129 cd $REPOROOT
130 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME
131 set +e
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'"
135     exit 1
136 fi
137 set -e
138
139
140 #------------------------------------------------------------------------------#
141 echo_header "setup a new repo from scratch with keystore and android-home set on cmd line"
142
143 REPOROOT=`create_test_dir`
144 KEYSTORE=$REPOROOT/keystore.jks
145 FAKE_ANDROID_HOME=`create_test_dir`
146 create_fake_android_home $FAKE_ANDROID_HOME
147 STORED_ANDROID_HOME=$ANDROID_HOME
148 unset ANDROID_HOME
149 echo "ANDROID_HOME: $ANDROID_HOME"
150 cd $REPOROOT
151 $fdroid init --keystore $KEYSTORE --android-home $FAKE_ANDROID_HOME --no-prompt
152 test -e $KEYSTORE
153 copy_apks_into_repo $REPOROOT
154 $fdroid update --create-metadata
155 grep -F '<application id=' repo/index.xml
156 test -e repo/index.xml
157 test -e repo/index.jar
158 export ANDROID_HOME=$STORED_ANDROID_HOME
159
160
161 #------------------------------------------------------------------------------#
162 echo_header "setup new repo from scratch using ANDROID_HOME, putting APKs in repo first"
163
164 REPOROOT=`create_test_dir`
165 cd $REPOROOT
166 mkdir repo
167 copy_apks_into_repo $REPOROOT
168 $fdroid init
169 $fdroid update --create-metadata
170 grep -F '<application id=' repo/index.xml
171
172
173 #------------------------------------------------------------------------------#
174 echo_header "setup a new repo from scratch and generate a keystore"
175
176 REPOROOT=`create_test_dir`
177 KEYSTORE=$REPOROOT/keystore.jks
178 cd $REPOROOT
179 $fdroid init --keystore $KEYSTORE
180 test -e $KEYSTORE
181 copy_apks_into_repo $REPOROOT
182 $fdroid update --create-metadata
183 test -e repo/index.xml
184 test -e repo/index.jar
185 grep -F '<application id=' repo/index.xml
186
187
188 #------------------------------------------------------------------------------#
189 echo_header "setup a new repo from scratch, generate a keystore, then add APK and update"
190
191 REPOROOT=`create_test_dir`
192 KEYSTORE=$REPOROOT/keystore.jks
193 cd $REPOROOT
194 $fdroid init --keystore $KEYSTORE
195 test -e $KEYSTORE
196 copy_apks_into_repo $REPOROOT
197 $fdroid update --create-metadata
198 test -e repo/index.xml
199 test -e repo/index.jar
200 grep -F '<application id=' repo/index.xml
201 cp $WORKSPACE/tests/urzip.apk $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
207
208 #------------------------------------------------------------------------------#
209 echo_header "setup a new repo from scratch with a HSM/smartcard"
210
211 REPOROOT=`create_test_dir`
212 cd $REPOROOT
213 $fdroid init --keystore NONE
214 test -e opensc-fdroid.cfg
215 test ! -e NONE
216
217
218 echo SUCCESS