| 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() { |
| 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 | |
| 15 | acceptsLicenseAgreement="$1" |
| 16 | scriptDir="$(cd $(dirname $0) && pwd)" |
| Alan Viverette | 2fa738f | 2018-11-28 16:38:53 -0500 | [diff] [blame] | 17 | projectDir=$scriptDir |
| Jeff Gaston | 259a905 | 2018-10-19 14:55:19 -0400 | [diff] [blame] | 18 | tempDir="${scriptDir}/studio" |
| 19 | function 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 | } |
| 29 | osName="$(getOsName)" |
| 30 | studioUrl="$(getStudioUrl $osName)" |
| 31 | studioDestName="$(basename ${studioUrl})" |
| 32 | studioZipPath="${tempDir}/${studioDestName}" |
| 33 | studioUnzippedPath="$(echo ${studioZipPath} | sed 's/\.zip$//')" |
| 34 | |
| 35 | function 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 | |
| 44 | function 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 | |
| 53 | function 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 | |
| 71 | function runStudioLinux() { |
| 72 | studioPath="${studioUnzippedPath}/android-studio/bin/studio.sh" |
| 73 | echo "$studioPath &" |
| Alan Viverette | 2fa738f | 2018-11-28 16:38:53 -0500 | [diff] [blame] | 74 | env STUDIO_PROPERTIES="${projectDir}/development/studio/idea.properties" "${studioPath}" "${projectDir}" & |
| Jeff Gaston | 259a905 | 2018-10-19 14:55:19 -0400 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | function runStudioMac() { |
| 78 | studioPath="${studioUnzippedPath}/Android Studio.app" |
| 79 | echo "open ${studioPath}" |
| Alan Viverette | 2fa738f | 2018-11-28 16:38:53 -0500 | [diff] [blame] | 80 | env STUDIO_PROPERTIES="${projectDir}/development/studio/idea.properties" open "${studioPath}" "${projectDir}" |
| Jeff Gaston | 259a905 | 2018-10-19 14:55:19 -0400 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | function runStudio() { |
| Chris Craik | b84f61b | 2018-10-31 14:18:06 -0700 | [diff] [blame] | 84 | if [ "${osName}" == "mac" ]; then |
| Jeff Gaston | 259a905 | 2018-10-19 14:55:19 -0400 | [diff] [blame] | 85 | runStudioMac |
| Chris Craik | b84f61b | 2018-10-31 14:18:06 -0700 | [diff] [blame] | 86 | else |
| 87 | runStudioLinux |
| Jeff Gaston | 259a905 | 2018-10-19 14:55:19 -0400 | [diff] [blame] | 88 | fi |
| 89 | } |
| 90 | |
| 91 | function main() { |
| 92 | updateStudio |
| 93 | checkLicenseAgreement |
| 94 | runStudio |
| 95 | } |
| 96 | |
| 97 | main |