Created
June 18, 2016 07:06
-
-
Save zachbrowne/d5020f5400e48daf80306059209700c8 to your computer and use it in GitHub Desktop.
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 | |
echo 'Checking for a new Java Version...' | |
kern_arch=$(uname -r | sed 's/.*-\(.*\)/\1/') | |
if [ "$kern_arch" = amd64 ]; then | |
java_ver=' x64' | |
fi | |
current_version=$(java -version 2>&1 >/dev/null | sed -n '1s/.*"\([^"]*\)"/\1/p') | |
latest_version_url=$(curl https://www.java.com/en/download/manual.jsp 2>/dev/null | grep -Po -m 1 "href=\"\K[^\"]*(?=.*Linux${java_ver} en JRE)" | |
) | |
latest_version=$(curl $latest_version_url 2>/dev/null | sed -n 's/.*File=jre-\([0-9]\)u\([0-9]\{2\}\).*/1.\1.0_\2/p') | |
if [ "$current_version" = "$latest_version" ]; then | |
echo 'No new Java version available. Aborting.' | |
exit 1 | |
fi | |
read -n 1 -p "A new Java version is available (${latest_version})! Would you like to download it (y)? " download | |
echo | |
if [ "$download" = y ]; then | |
filename="$(curl "$latest_version_url" 2> /dev/null | sed -n 's/.*File=\([^&]*\).*/\1/p')" | |
wget -q -O "$filename" --show-progress "$latest_version_url" | |
echo 'Download completed.' | |
exit 0 | |
fi | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment