blob: 27076a3a994d36eef77ac6c9081a7b142f5e255a [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() {
9 osName="$1"
10 buildNumber="5056338"
11 studioUrl="https://dl.google.com/dl/android/studio/ide-zips/3.2.1.0/android-studio-ide-181.${buildNumber}-${osName}.zip"
12 echo "${studioUrl}"
13}
14
15acceptsLicenseAgreement="$1"
16scriptDir="$(cd $(dirname $0) && pwd)"
Alan Viverette2fa738f2018-11-28 16:38:53 -050017projectDir=$scriptDir
Jeff Gaston259a9052018-10-19 14:55:19 -040018tempDir="${scriptDir}/studio"
19function getOsName() {
20 unameOutput="$(uname)"
21 osName=""
22 if [ "${unameOutput}" == "Linux" ]; then
23 osName="linux"
24 else
25 osName="mac"
26 fi
27 echo "${osName}"
28}
29osName="$(getOsName)"
30studioUrl="$(getStudioUrl $osName)"
31studioDestName="$(basename ${studioUrl})"
32studioZipPath="${tempDir}/${studioDestName}"
33studioUnzippedPath="$(echo ${studioZipPath} | sed 's/\.zip$//')"
34
35function downloadFile() {
36 fromUrl="$1"
37 destPath="$2"
38 tempPath="${destPath}.tmp"
39 echo "Downloading ${fromUrl} to ${destPath}"
40 curl "${fromUrl}" > "${tempPath}"
41 mv "${tempPath}" "${destPath}"
42}
43
44function checkLicenseAgreement() {
45 # TODO: Is there a more official way to check that the user accepts the license?
46 if [ "${acceptsLicenseAgreement}" != "-y" ]; then
47 echo "Do you accept the license agreement at ${studioUnzippedPath}/android-studio/LICENSE.txt ?"
48 echo "If you do, then rerun this script with a '-y' argument"
49 exit 1
50 fi
51}
52
53function updateStudio() {
54 # skip if already up-to-date
55 if stat "${studioZipPath}" >/dev/null 2>/dev/null; then
56 # already up-to-date
57 return
58 fi
59
60 mkdir -p "${tempDir}"
61 downloadFile "${studioUrl}" "${studioZipPath}"
62 echo
63
64 echo "Removing previous installations"
65 ls "${tempDir}" | grep -v "^${studioDestName}\$" | sed "s|^|${tempDir}/|" | xargs rm -rf
66
67 echo "Unzipping"
68 unzip "${studioZipPath}" -d "${studioUnzippedPath}"
69}
70
71function runStudioLinux() {
72 studioPath="${studioUnzippedPath}/android-studio/bin/studio.sh"
73 echo "$studioPath &"
Alan Viverette2fa738f2018-11-28 16:38:53 -050074 env STUDIO_PROPERTIES="${projectDir}/development/studio/idea.properties" "${studioPath}" "${projectDir}" &
Jeff Gaston259a9052018-10-19 14:55:19 -040075}
76
77function runStudioMac() {
78 studioPath="${studioUnzippedPath}/Android Studio.app"
79 echo "open ${studioPath}"
Alan Viverette2fa738f2018-11-28 16:38:53 -050080 env STUDIO_PROPERTIES="${projectDir}/development/studio/idea.properties" open "${studioPath}" "${projectDir}"
Jeff Gaston259a9052018-10-19 14:55:19 -040081}
82
83function runStudio() {
Chris Craikb84f61b2018-10-31 14:18:06 -070084 if [ "${osName}" == "mac" ]; then
Jeff Gaston259a9052018-10-19 14:55:19 -040085 runStudioMac
Chris Craikb84f61b2018-10-31 14:18:06 -070086 else
87 runStudioLinux
Jeff Gaston259a9052018-10-19 14:55:19 -040088 fi
89}
90
91function main() {
92 updateStudio
93 checkLicenseAgreement
94 runStudio
95}
96
97main