-
Notifications
You must be signed in to change notification settings - Fork 65
/
android-sdk-installer.sh
executable file
·92 lines (74 loc) · 2.41 KB
/
android-sdk-installer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env bash
# Copyright (c) 2013 Embark Mobile
# Licensed under the MIT License.
# https://github.com/embarkmobile/android-sdk-installer
set +e
#detecting os
os=linux
if [[ `uname` == 'Darwin' ]]; then
os=osx
fi
# Constants
if [[ $os == 'linux' ]]; then
SDK_FILE=android-sdk_r23.0.2-linux.tgz
elif [[ $os == 'osx' ]]; then
SDK_FILE=android-sdk_r23.0.2-macosx.zip
fi
SDK_URL=http://dl.google.com/android/$SDK_FILE
DEFAULT_INSTALL=platform-tools
WAIT_FOR_EMULATOR_URL=https://github.com/embarkmobile/android-sdk-installer/raw/version-2/wait_for_emulator
ACCEPT_LICENSES_URL=https://github.com/embarkmobile/android-sdk-installer/raw/version-2/accept-licenses
# Defaults
INSTALLER_DIR=$HOME/.android-sdk-installer
INSTALL=""
LICENSES="android-sdk-license-5be876d5"
for i in "$@"
do
case $i in
--dir=*)
INSTALLER_DIR=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
;;
--install=*)
INSTALL=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
;;
--accept=*)
LICENSES=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
;;
*)
# unknown option
;;
esac
done
# Expand the path
if [[ $os == 'linux' ]]; then
INSTALLER_DIR=`readlink -f "$INSTALLER_DIR"`
elif [[ $os == 'osx' ]]; then
INSTALLER_DIR=`stat -f "$INSTALLER_DIR"`
fi
TOOLS_DIR=$INSTALLER_DIR/tools
echo "Installing SDK in $INSTALLER_DIR"
mkdir -p $INSTALLER_DIR
mkdir -p $TOOLS_DIR
echo "Downloading SDK"
wget -c -O $INSTALLER_DIR/$SDK_FILE $SDK_URL
echo "Extracting SDK"
if [[ $os == 'linux' ]]; then
tar xzf $INSTALLER_DIR/$SDK_FILE --directory $INSTALLER_DIR
export ANDROID_HOME=$INSTALLER_DIR/android-sdk-linux
elif [[ $os == 'osx' ]]; then
unzip -q -d $INSTALLER_DIR $INSTALLER_DIR/$SDK_FILE
export ANDROID_HOME=$INSTALLER_DIR/android-sdk-macosx
fi
# Download scripts
# Mac on Travis has issues with SSL certs if we don't use the -3 / -ssl3 option
curl -3L -o $TOOLS_DIR/wait_for_emulator $WAIT_FOR_EMULATOR_URL
chmod +x $TOOLS_DIR/wait_for_emulator
curl -3L -o $TOOLS_DIR/accept-licenses $ACCEPT_LICENSES_URL
chmod +x $TOOLS_DIR/accept-licenses
# Setup environment file
echo "export ANDROID_HOME=$ANDROID_HOME" > $INSTALLER_DIR/env
echo "export PATH=$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$TOOLS_DIR:\$PATH" >> $INSTALLER_DIR/env
# Install components
ALL_INSTALL=$DEFAULT_INSTALL,$INSTALL
echo "Installing $ALL_INSTALL"
$TOOLS_DIR/accept-licenses "$ANDROID_HOME/tools/android update sdk --no-ui -a --filter $ALL_INSTALL" "$LICENSES"