Jeff Gaston | 259a905 | 2018-10-19 14:55:19 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | set -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 | |
| 8 | function getStudioUrl() { |
Alan Viverette | 6ed162a | 2018-11-30 14:35:55 -0500 | [diff] [blame^] | 9 | version="3.3.0.17" |
| 10 | ideaMajorVersion="182" |
| 11 | buildNumber="5138683" |
Jeff Gaston | 259a905 | 2018-10-19 14:55:19 -0400 | [diff] [blame] | 12 | osName="$1" |
Alan Viverette | 6ed162a | 2018-11-30 14:35:55 -0500 | [diff] [blame^] | 13 | studioUrl="https://dl.google.com/dl/android/studio/ide-zips/${version}/android-studio-ide-${ideaMajorVersion}.${buildNumber}-${osName}.zip" |
Jeff Gaston | 259a905 | 2018-10-19 14:55:19 -0400 | [diff] [blame] | 14 | echo "${studioUrl}" |
| 15 | } |
| 16 | |
| 17 | acceptsLicenseAgreement="$1" |
| 18 | scriptDir="$(cd $(dirname $0) && pwd)" |
Alan Viverette | 2fa738f | 2018-11-28 16:38:53 -0500 | [diff] [blame] | 19 | projectDir=$scriptDir |
Jeff Gaston | 259a905 | 2018-10-19 14:55:19 -0400 | [diff] [blame] | 20 | tempDir="${scriptDir}/studio" |
| 21 | function 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 | } |
| 31 | osName="$(getOsName)" |
| 32 | studioUrl="$(getStudioUrl $osName)" |
| 33 | studioDestName="$(basename ${studioUrl})" |
| 34 | studioZipPath="${tempDir}/${studioDestName}" |
| 35 | studioUnzippedPath="$(echo ${studioZipPath} | sed 's/\.zip$//')" |
| 36 | |
| 37 | function 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 | |
| 46 | function 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 | |
| 55 | function 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 | |
| 73 | function runStudioLinux() { |
| 74 | studioPath="${studioUnzippedPath}/android-studio/bin/studio.sh" |
| 75 | echo "$studioPath &" |
Alan Viverette | 6ed162a | 2018-11-30 14:35:55 -0500 | [diff] [blame^] | 76 | env STUDIO_PROPERTIES="${projectDir}/development/studio/idea.properties" \ |
| 77 | STUDIO_VM_OPTIONS="${projectDir}/development/studio/studio.vmoptions" \ |
| 78 | "${studioPath}" "${projectDir}" & |
Jeff Gaston | 259a905 | 2018-10-19 14:55:19 -0400 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | function runStudioMac() { |
| 82 | studioPath="${studioUnzippedPath}/Android Studio.app" |
| 83 | echo "open ${studioPath}" |
Alan Viverette | 6ed162a | 2018-11-30 14:35:55 -0500 | [diff] [blame^] | 84 | env STUDIO_PROPERTIES="${projectDir}/development/studio/idea.properties" \ |
| 85 | STUDIO_VM_OPTIONS="${projectDir}/development/studio/studio.vmoptions" \ |
| 86 | open "${studioPath}" "${projectDir}" |
Jeff Gaston | 259a905 | 2018-10-19 14:55:19 -0400 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | function runStudio() { |
Chris Craik | b84f61b | 2018-10-31 14:18:06 -0700 | [diff] [blame] | 90 | if [ "${osName}" == "mac" ]; then |
Jeff Gaston | 259a905 | 2018-10-19 14:55:19 -0400 | [diff] [blame] | 91 | runStudioMac |
Chris Craik | b84f61b | 2018-10-31 14:18:06 -0700 | [diff] [blame] | 92 | else |
| 93 | runStudioLinux |
Jeff Gaston | 259a905 | 2018-10-19 14:55:19 -0400 | [diff] [blame] | 94 | fi |
| 95 | } |
| 96 | |
| 97 | function main() { |
| 98 | updateStudio |
| 99 | checkLicenseAgreement |
| 100 | runStudio |
| 101 | } |
| 102 | |
| 103 | main |