#
# This script will install the actual plugin, advise the user to read the
# license for Chrome and to re-login to have environment variables set
# properly.
#

BUILD_DIR="./var/tmp/${PKGNAME}.build"

do_install() {
	mkdir -p "$BUILD_DIR"
	wget \
		--header "Cookie: oraclelicense=accept-securebackup-cookie" \
		--progress=bar:force \
		-c -O $BUILD_DIR/jre.tar.gz \
		$ORACLE_JRE_URL
	echo "$ORACLE_JRE_CHECKSUM  $BUILD_DIR/jre.tar.gz" | sha256sum -c || return 1
	tar xf ${BUILD_DIR}/jre.tar.gz || return 1

	if [ -d usr/share/java/$PKGNAME ]; then
		rm -rf usr/share/java/$PKGNAME
	fi
	mv jre$ORACLE_JRE_LONG_VERSION usr/share/java/$PKGNAME || return 1
}

case "${ACTION}" in
post)
	. usr/share/java/oracle-jre-vars.sh
	do_install
	RESULT=$?
	rm -r $BUILD_DIR
	[ $RESULT -ne 0 ] && exit $RESULT
	cat << _EOF
=====================================================================

- The Oracle JRE package is licensed software.

	You MUST read and agree to the license stored in
	/usr/share/licenses/oracle-jre/LICENSE
	before using it.

- Please re-login to update PATH and JAVA_HOME or re-source
  /etc/profile:

	$ source /etc/profile

=====================================================================
_EOF
    ;;
esac

