Skip to content

Instantly share code, notes, and snippets.

@bennet0496
Created April 5, 2017 19:50
Show Gist options
  • Save bennet0496/cafb1d6ec33141d7e80c5537a95ac716 to your computer and use it in GitHub Desktop.
Save bennet0496/cafb1d6ec33141d7e80c5537a95ac716 to your computer and use it in GitHub Desktop.
Java JRE Update Skript Linux. Cloned from https://gitlab.pks.mpg.de/snippets/3
#!/bin/bash -e
INSTALLPATH=/usr/local/lib/jvm
CREATE_ID_HISTORY=true
ID_HISTROY_FILE=/root/AutoBundleIdHistroy
cd $INSTALLPATH
case $1 in
x64|amd64)
link=$(curl -sL http://www.java.com/de/download/manual.jsp | grep --color 'Linux x64 de JRE' | sed -n 's/.*href="\([^"]*\).*/\1/p' | head -n1)
bid=$(echo $link | sed 's#http://javadl.oracle.com/webapps/download/AutoDL?BundleId=##g')
if [ x"$(cat latest_AutoBundleIdx64)" != x"$bid" ] || [ x"$2" = x"-f" ]
then
curl -sSL $link | pv -petrab -s $( curl -sIL $link | grep Content-Length | cut -d ' ' -f 2 | tr -d '\n\r') | tar xz
rm -v latest || true
ln -vs $(ls -dt */ | tr -d '/' | head -n1) latest
echo $bid > latest_AutoBundleIdx64
$CREATE_ID_HISTORY && echo $bid $link $(ls -dt */ | tr -d '/' | head -n1) $1 >> $ID_HISTROY_FILE
chown -R root:root $INSTALLPATH
else
echo Already on Latest Version. Exiting
fi
;;
i386|x86)
link=$(curl -sL http://www.java.com/de/download/manual.jsp | grep --color 'Linux de JRE' | sed -n 's/.*href="\([^"]*\).*/\1/p' | head -n1)
bid=$(echo $link | sed 's#http://javadl.oracle.com/webapps/download/AutoDL?BundleId=##g')
if [ x"$(cat latest_AutoBundleIdx86)" != x"$bid" ] || [ x"$2" = x"-f" ]
then
curl -sSL $link | pv -petrab -s $( curl -sIL $link | grep Content-Length | cut -d ' ' -f 2 | tr -d '\n\r') | tar xz
rm -v latest || true
ln -vs $(ls -dt */ | tr -d '/' | head -n1) latest
echo $bid > latest_AutoBundleIdx86
$CREATE_ID_HISTORY && echo $bid $link $(ls -dt */ | tr -d '/' | head -n1) $1 >> $ID_HISTROY_FILE
chown -R root:root $INSTALLPATH
else
echo Already on Latest Version. Exiting
fi
;;
*)
echo "Usage $0 [x86|x64] [-f]"
exit 1
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment