Created
August 27, 2014 09:42
-
-
Save hihellobolke/b4ef1b4034b4ce4e06ea to your computer and use it in GitHub Desktop.
Downloading JDK via script
This file contains hidden or 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 | |
URL=http://www.oracle.com/technetwork/java/javase/downloads/index.html | |
PAGE=$(mktemp) | |
echo "Downloading $URL" | |
elinks --dump $URL >> $PAGE | |
echo " + webpage for JDK 7" | |
PAGE_JDK7=$(sed -n '/Java se 7u[0-9]\+/I s/^.*\[\([0-9]\+\)]java se.*$/\1/Ip' $PAGE | head -1 ) | |
UPDATE_JDK7=$(sed -n '/Java se 7u[0-9]\+/I s/^.*java se 7u\([0-9]\+\).*$/\1/Ip' $PAGE | head -1 ) | |
PAGE_JDK7=$(awk "/ ${PAGE_JDK7}\. / {print \$2}" $PAGE) | |
URL_JDK7=$(curl -s $PAGE_JDK7 | grep -i 'Linux x64' | grep 'tar.gz' | grep -v 'demo' | sed -e 's/.*"\(http:[^"]\+\)".*$/\1/') | |
echo " + webpage for JDK 8" | |
PAGE_JDK8=$(sed -n '/Java se 8u[0-9]\+/I s/^.*\[\([0-9]\+\)]java se.*$/\1/Ip' $PAGE | head -1 ) | |
UPDATE_JDK8=$(sed -n '/Java se 8u[0-9]\+/I s/^.*java se 8u\([0-9]\+\).*$/\1/Ip' $PAGE | head -1 ) | |
PAGE_JDK8=$(awk "/ ${PAGE_JDK8}\. / {print \$2}" $PAGE) | |
URL_JDK8=$(curl -s $PAGE_JDK8 | grep -i 'Linux x64' | grep 'tar.gz' | grep -v 'demo' | sed -e 's/.*"\(http:[^"]\+\)".*$/\1/') | |
[ -f $PAGE ] && rm -f ${PAGE} | |
echo "Downlading JDK 7 \& 8" | |
for i in $(seq 7 8); do | |
( | |
DOWNLOAD_URL=$(eval echo \${URL_JDK${i}}) | |
wget -q --no-check-certificate \ | |
--no-cookies \ | |
--header "Cookie: oraclelicense=accept-securebackup-cookie" \ | |
--output-document jdk$i.tar.gz $DOWNLOAD_URL 2>/dev/null && \ | |
echo " + Downloaded file jdk$i.tar.gz" || \ | |
echo " + Failed downloading $DOWNLOAD_URL" | |
)& | |
done | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment