chiark / gitweb /
ac5ab59033d4fda6c4e412ea68117a00a8a708c7
[fdroidserver.git] / buildserver / provision-android-sdk
1 #!/bin/bash
2 #
3
4 set -e
5
6 if [ -z $ANDROID_HOME ]; then
7     echo "ANDROID_HOME env var must be set!"
8     exit 1
9 fi
10
11 # TODO remove the rm, this should work with an existing ANDROID_HOME
12 if [ ! -x $ANDROID_HOME/tools/android ]; then
13     rm -rf $ANDROID_HOME
14     mkdir ${ANDROID_HOME}
15     mkdir ${ANDROID_HOME}/temp
16     mkdir ${ANDROID_HOME}/platforms
17     mkdir ${ANDROID_HOME}/build-tools
18     cd $ANDROID_HOME
19
20     tools=`ls -1 /vagrant/cache/tools_*.zip | sort -n | tail -1`
21     unzip -qq $tools
22 fi
23
24 cd /vagrant/cache
25
26 # make links for `android update sdk` to use and delete
27 for f in android_*.zip android-[0-9]*.zip platform-[0-9]*.zip build-tools_r*-linux.zip; do
28     rm -f ${ANDROID_HOME}/temp/$f
29     ln -s /vagrant/cache/$f ${ANDROID_HOME}/temp/
30 done
31
32 # install all cached platforms
33 cached=""
34 for f in `ls -1 android-[0-9]*.zip platform-[0-9]*.zip`; do
35     sdk=`unzip -c $f "*/build.prop" | sed -n 's,^ro.build.version.sdk=,,p'`
36     cached=,android-${sdk}${cached}
37 done
38
39 # install all cached build-tools
40 for f in `ls -1 build-tools*.zip`; do
41     ver=`unzip -c $f "*/source.properties" | sed -n 's,^Pkg.Revision=,,p'`
42     cached=,build-tools-${ver}${cached}
43 done
44
45 ${ANDROID_HOME}/tools/android update sdk --no-ui --all \
46     --filter platform-tools,extra-android-m2repository${cached} > /dev/null <<EOH
47 y
48
49 EOH
50
51
52 chmod -R a+rX $ANDROID_HOME/
53 find $ANDROID_HOME/ -type f -executable -print0 | xargs -0 chmod a+x