Last active
October 13, 2019 17:06
-
-
Save cyfrost/c7138bc0d28ca241340ff49fc71f12e3 to your computer and use it in GitHub Desktop.
[Linux only] Download and Install latest Android Studio anytime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# For most (if not all) Linux distros, there is no official repository package available to install Android Studio | |
# and still get regular updates. I made the below bash script that'll automatically scrape their download site for | |
# the download link of the latest version and can also optionally install it. | |
# As a forewarning, the method used to scrape the download link (sed and grep) may not always work, in which case, | |
# the script will notify it and exit without making any changes. | |
pageSource="/tmp/androidStudioHTML" && \ | |
website="https://developer.android.com/studio" && \ | |
printf "\nGetting the download link for latest Android Studio (linux)..." | |
status=$(curl --head --location --connect-timeout 5 --write-out %{http_code} --silent --output /dev/null ${website}) | |
if [ $status != 200 ]; then | |
printf "\nError: HTTP request failed to site. Skipping Android Studio installation!" | |
return 1 | |
fi | |
# save the page source into a temp file. | |
curl -s "$website" > "$pageSource" && \ | |
# get all href links from the page source via sed, then grep out the filename linux.tar.gz, get first match only. | |
downloadURL="$(sed -n 's/.*href="\([^"]*\).*/\1/p' "$pageSource" | grep -i linux.tar.gz | head -1)" && \ | |
# validate URL by checking filesize | |
filesize="$(wget "$downloadURL" --spider --server-response -O - 2>&1 | sed -ne '/Content-Length/{s/.*: //;p}')" && \ | |
# If its atleast above 100megs, its safe to assume we got the right thing. | |
if (( $filesize > 100000000 )); then | |
printf "\n\nFound latest download link: $downloadURL" | |
else | |
printf "\n\nFailed to get the latest download link for Android Studio. Abort." | |
exit 1 | |
fi | |
echo | |
echo | |
read -p "Do you want to install Android Studio now? (y/N)" -n 1 -r | |
echo | |
echo | |
if [[ ! $REPLY =~ ^[Yy]$ ]] | |
then | |
printf "Finished\n\n" | |
exit 0 | |
fi | |
# ============================ | |
# Downloading and Installing android studio | |
# ============================ | |
# | |
printf "Downloading Android Studio..." | |
filename="android_studio.tar.gz" | |
rm -f "$filename" | |
echo | |
echo | |
wget -O "$filename" "$downloadURL" -q --show-progress && \ | |
installation_dir="$HOME/Programs/Android_Studio" && \ | |
mkdir -p "$installation_dir" | |
printf "\n\nExtracting Android Studio archive..." && \ | |
tar -xzf "$filename" -C "$installation_dir" --strip-components=1 && \ | |
launcher="$installation_dir/bin/studio.sh" && \ | |
chmod +x "$launcher" && \ | |
rm -f $filename && \ | |
$launcher & | |
printf "\n\nAndroid Studio has been installed successfully.\n\nFinished\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage of this script:
bash <(curl -s https://gist.githubusercontent.com/cyfrost/c7138bc0d28ca241340ff49fc71f12e3/raw/install-latest-android-studio.sh)