Skip to content

Instantly share code, notes, and snippets.

@gryf
Created August 9, 2016 16:13
Show Gist options
  • Select an option

  • Save gryf/8023f75bc586d97f8d75702e73def28d to your computer and use it in GitHub Desktop.

Select an option

Save gryf/8023f75bc586d97f8d75702e73def28d to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <version> <revision>"
echo "for example for Java 1.8.0.92 it would be:"
echo "$0 8 92"
exit 1
fi
VERSION="$1u$2"
FILENAME="jdk-${VERSION}-linux-x64.tar.gz"
CHECKSUM_ERROR=0
i=0
function get_file () {
local fname="http://download.oracle.com/otn-pub/java/jdk/$1"
wget --header "Cookie: oraclelicense=accept-securebackup-cookie" \
$fname -O /usr/portage/distfiles/$FILENAME
}
function check_file () {
CHECKSUM_ERROR=0
local expexted_sha256=$(grep $FILENAME \
/usr/portage/dev-java/oracle-jdk-bin/Manifest | cut -d " " -f 5)
local actual_sha256=$(sha256sum \
/usr/portage/distfiles/$FILENAME |cut -d " " -f 1)
[[ "${expexted_sha256}" == "${actual_sha256}" ]] && CHECKSUM_ERROR=1 \
|| echo "checksum error"
}
while true; do
[[ $i -lt 10 ]] && DIR_NUMBER="0$i" || DIR_NUMBER="$i"
echo "searching b$DIR_NUMBER"
wget -q --spider --header "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/${VERSION}-b${DIR_NUMBER}/$FILENAME"
if [[ $? == 0 ]]; then
echo "${FILENAME} found in b${DIR_NUMBER}"
get_file "${VERSION}-b${DIR_NUMBER}/$FILENAME"
check_file
if [[ $CHECKSUM_ERROR == 1 ]]; then
echo "all done"
break
fi
fi
[[ $i -gt 100 ]] && echo "giving up" && break
((i++))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment