blob: 6458339c001ee3556c74de607a2e21e935a5df36 [file] [log] [blame]
Jeff Gaston259a9052018-10-19 14:55:19 -04001#!/bin/bash
2set -e
3
4# This is a wrapper script that runs the specific version of Android Studio that is recommended for developing in this repository.
5# (This serves a similar purpose to gradlew)
6
7
8function getStudioUrl() {
Alan Viverette6ed162a2018-11-30 14:35:55 -05009 version="3.3.0.17"
10 ideaMajorVersion="182"
11 buildNumber="5138683"
Jeff Gaston259a9052018-10-19 14:55:19 -040012 osName="$1"
Alan Viverette6ed162a2018-11-30 14:35:55 -050013 studioUrl="https://dl.google.com/dl/android/studio/ide-zips/${version}/android-studio-ide-${ideaMajorVersion}.${buildNumber}-${osName}.zip"
Jeff Gaston259a9052018-10-19 14:55:19 -040014 echo "${studioUrl}"
15}
16
17acceptsLicenseAgreement="$1"
18scriptDir="$(cd $(dirname $0) && pwd)"
Alan Viverette2fa738f2018-11-28 16:38:53 -050019projectDir=$scriptDir
Jeff Gaston259a9052018-10-19 14:55:19 -040020tempDir="${scriptDir}/studio"
21function getOsName() {
22 unameOutput="$(uname)"
23 osName=""
24 if [ "${unameOutput}" == "Linux" ]; then
25 osName="linux"
26 else
27 osName="mac"
28 fi
29 echo "${osName}"
30}
31osName="$(getOsName)"
32studioUrl="$(getStudioUrl $osName)"
33studioDestName="$(basename ${studioUrl})"
34studioZipPath="${tempDir}/${studioDestName}"
35studioUnzippedPath="$(echo ${studioZipPath} | sed 's/\.zip$//')"
36
37function downloadFile() {
38 fromUrl="$1"
39 destPath="$2"
40 tempPath="${destPath}.tmp"
41 echo "Downloading ${fromUrl} to ${destPath}"
42 curl "${fromUrl}" > "${tempPath}"
43 mv "${tempPath}" "${destPath}"
44}
45
46function checkLicenseAgreement() {
47 # TODO: Is there a more official way to check that the user accepts the license?
48 if [ "${acceptsLicenseAgreement}" != "-y" ]; then
49 echo "Do you accept the license agreement at ${studioUnzippedPath}/android-studio/LICENSE.txt ?"
50 echo "If you do, then rerun this script with a '-y' argument"
51 exit 1
52 fi
53}
54
55function updateStudio() {
56 # skip if already up-to-date
57 if stat "${studioZipPath}" >/dev/null 2>/dev/null; then
58 # already up-to-date
59 return
60 fi
61
62 mkdir -p "${tempDir}"
63 downloadFile "${studioUrl}" "${studioZipPath}"
64 echo
65
66 echo "Removing previous installations"
67 ls "${tempDir}" | grep -v "^${studioDestName}\$" | sed "s|^|${tempDir}/|" | xargs rm -rf
68
69 echo "Unzipping"
70 unzip "${studioZipPath}" -d "${studioUnzippedPath}"
71}
72
73function runStudioLinux() {
74 studioPath="${studioUnzippedPath}/android-studio/bin/studio.sh"
75 echo "$studioPath &"
Alan Viverette6ed162a2018-11-30 14:35:55 -050076 env STUDIO_PROPERTIES="${projectDir}/development/studio/idea.properties" \
77 STUDIO_VM_OPTIONS="${projectDir}/development/studio/studio.vmoptions" \
78 "${studioPath}" "${projectDir}" &
Jeff Gaston259a9052018-10-19 14:55:19 -040079}
80
81function runStudioMac() {
82 studioPath="${studioUnzippedPath}/Android Studio.app"
83 echo "open ${studioPath}"
Alan Viverette6ed162a2018-11-30 14:35:55 -050084 env STUDIO_PROPERTIES="${projectDir}/development/studio/idea.properties" \
85 STUDIO_VM_OPTIONS="${projectDir}/development/studio/studio.vmoptions" \
86 open "${studioPath}" "${projectDir}"
Jeff Gaston259a9052018-10-19 14:55:19 -040087}
88
89function runStudio() {
Chris Craikb84f61b2018-10-31 14:18:06 -070090 if [ "${osName}" == "mac" ]; then
Jeff Gaston259a9052018-10-19 14:55:19 -040091 runStudioMac
Chris Craikb84f61b2018-10-31 14:18:06 -070092 else
93 runStudioLinux
Jeff Gaston259a9052018-10-19 14:55:19 -040094 fi
95}
96
97function main() {
98 updateStudio
99 checkLicenseAgreement
100 runStudio
101}
102
103main