[go: nahoru, domu]

blob: 0d94339b49a79494b4f51324de51c5f5c162d28a [file] [log] [blame]
#!/bin/bash
set -e
# This is a wrapper script that runs the specific version of Android Studio that is recommended for developing in this repository.
# (This serves a similar purpose to gradlew)
function getStudioUrl() {
version="3.4.0.12"
ideaMajorVersion="183"
buildNumber="5256591"
osName="$1"
studioUrl="https://dl.google.com/dl/android/studio/ide-zips/${version}/android-studio-ide-${ideaMajorVersion}.${buildNumber}-${osName}.zip"
echo "${studioUrl}"
}
acceptsLicenseAgreement="$1"
scriptDir="$(cd $(dirname $0) && pwd)"
projectDir=$scriptDir
tempDir="${scriptDir}/studio"
function getOsName() {
unameOutput="$(uname)"
osName=""
if [ "${unameOutput}" == "Linux" ]; then
osName="linux"
else
osName="mac"
fi
echo "${osName}"
}
osName="$(getOsName)"
studioUrl="$(getStudioUrl $osName)"
studioDestName="$(basename ${studioUrl})"
studioZipPath="${tempDir}/${studioDestName}"
studioUnzippedPath="$(echo ${studioZipPath} | sed 's/\.zip$//')"
function downloadFile() {
fromUrl="$1"
destPath="$2"
tempPath="${destPath}.tmp"
echo "Downloading ${fromUrl} to ${destPath}"
curl "${fromUrl}" > "${tempPath}"
mv "${tempPath}" "${destPath}"
}
function findStudioMacAppPath() {
echo "$(find "${studioUnzippedPath}" -type d -depth 1 -name "Android Studio*.app")"
}
function getLicensePath() {
if [ "${osName}" == "mac" ]; then
appPath="$(findStudioMacAppPath)"
echo "${appPath}/Contents/Resources/LICENSE.txt"
else
echo "${studioUnzippedPath}/android-studio/LICENSE.txt"
fi
}
function checkLicenseAgreement() {
# TODO: Is there a more official way to check that the user accepts the license?
licenseAcceptedPath="${studioUnzippedPath}/STUDIOW_LICENSE_ACCEPTED"
if [ ! -f "${licenseAcceptedPath}" ]; then
if [ "${acceptsLicenseAgreement}" == "-y" ]; then
touch "${licenseAcceptedPath}"
else
echo "Do you accept the license agreement at $(getLicensePath) ?"
echo "If you do, then rerun this script with a '-y' argument"
exit 1
fi
fi
}
function updateStudio() {
# skip if already up-to-date
if stat "${studioZipPath}" >/dev/null 2>/dev/null; then
# already up-to-date
return
fi
mkdir -p "${tempDir}"
downloadFile "${studioUrl}" "${studioZipPath}"
echo
echo "Removing previous installations"
ls "${tempDir}" | grep -v "^${studioDestName}\$" | sed "s|^|${tempDir}/|" | xargs rm -rf
echo "Unzipping"
unzip "${studioZipPath}" -d "${studioUnzippedPath}"
}
function runStudioLinux() {
studioPath="${studioUnzippedPath}/android-studio/bin/studio.sh"
echo "$studioPath &"
env STUDIO_PROPERTIES="${projectDir}/development/studio/idea.properties" \
STUDIO_VM_OPTIONS="${projectDir}/development/studio/studio.vmoptions" \
"${studioPath}" "${projectDir}" &
}
function runStudioMac() {
appPath="$(findStudioMacAppPath)"
echo "open ${appPath}"
env STUDIO_PROPERTIES="${projectDir}/development/studio/idea.properties" \
STUDIO_VM_OPTIONS="${projectDir}/development/studio/studio.vmoptions" \
open -a "${appPath}" "${projectDir}"
}
function runStudio() {
if [ "${osName}" == "mac" ]; then
runStudioMac
else
runStudioLinux
fi
}
function main() {
updateStudio
checkLicenseAgreement
runStudio
}
main