Created
October 16, 2012 15:55
-
-
Save hashar/3900138 to your computer and use it in GitHub Desktop.
shell script to install Android SDK from CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ANDROID_ARCHIVE="android-sdk_r20.0.3-linux.tgz" | |
ANDROID_URL="http://dl.google.com/android/$ANDROID_ARCHIVE" | |
BASE_DIR="/opt/androidsdk" | |
ANDROID_BIN="$BASE_DIR/android-sdk-linux/tools/android" | |
ANDROID_VERSIONS="android-8,android-10" | |
### Pre checks ######## | |
has_error="0" | |
CURL_BIN=`which curl` | |
if [ "0" != "$?" ]; then | |
echo "curl is required: sudo apt-get install curl" | |
has_error=1 | |
fi | |
if [ ! `which java` ]; then | |
echo "java not found: sudo apt-get install default-jre" | |
has_error=1 | |
fi | |
if [ ! -w $BASE_DIR ]; then | |
echo "Unable to write to $BASE_DIR" | |
has_error=1 | |
fi | |
if [ "$has_error" -eq "1" ]; then | |
echo -e "\nPlease fix above errors." | |
exit 1 | |
fi | |
if [ ! -e $BASE_DIR/$ANDROID_ARCHIVE ]; then | |
(cd $BASE_DIR && curl "$ANDROID_URL" -o $BASE_DIR/$ANDROID_ARCHIVE ) \ | |
|| (fatal "Download failed"; rm $BASE_DIR/$ANDROID_ARCHIVE) \ | |
&& echo "Download successful" | |
else | |
echo "Found Android SDK $BASE_DIR/$ANDROID_ARCHIVE" | |
echo "...skipped dowloading" | |
fi | |
if [ ! -e "$BASE_DIR/android-sdk-linux" ]; then | |
echo "Uncompressing Android SDK..." | |
(cd $BASE_DIR && tar -xzvf "$BASE_DIR/$ANDROID_ARCHIVE") | |
else | |
echo "Found uncompressed Android SDK in $BASE_DIR/android-sdk-linux" | |
echo "...skipped uncompressing" | |
fi | |
$ANDROID_BIN --verbose update sdk -u --filter $ANDROID_VERSIONS | |
### Helper functions | |
warn() { | |
echo "$*" | |
} | |
fatal() { | |
warn "$*" | |
exit 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment