#!/bin/sh
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../blackdown-jre/java-blackdown-conf.in
# Copyright (C) 2008 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE Project
# Copyright (C) 1998 - 2005 Clifford Wolf
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---

# Prevent normal package extraction. However since auto package
# extraction is turned off, so are the pre and post patch hooks.
# Instead we abuse the preconf hook to do the necessary patching.
autoextract=0

# Prevent executing normal make and install build steps.
# This package has custom make and install.
makeopt=
makeinstopt=

# Make prefix same a java_home. This way artifacts like the bin, lib
# and doc directory are created at the proper level.
. $base/package/*/*/java-jdk-conf.in $1

java_install_opt=
java_home_original=

# Check if installing needs to be done with or without X11.
if ! pkginstalled xorg; then
	var_append java_install_opt ' ' "--nox11"
fi

# The archive to be installed/patched depends on the
# current architecture.
java_srctar=
case $arch in
	x86)	java_srctar="`match_source_file -p -i586`" ;;
	x86-64)	java_srctar="`match_source_file -p -amd64`" ;;
esac

# Make sure there is a file to be patched. If not we
# apparently do not support the current architecture.
[ "$java_srctar" ] || abort "No binary for this architecture ($arch) detected!"


# Custom pre patching.
java_preconf() {
	# eliminate interactivity and integrity checks.
	cp -v $java_srctar .
	sed -i 's/MD5=.*$/MD5=\\"00000000000000000000000000000000\\"; SETUP_NOCHECK=1/' ${java_srctar##*/}
	sed -i 's/more <</agreed=1; cat <</' ${java_srctar##*/}

	# Retrieve the original JAVAHOME name from the archive.
	tempvar="`head -n15 ${java_srctar##*/} | grep JAVAHOME`"
	java_home_original=${tempvar/*=/}

	# Ready to unpack/install the archive.
	sh ${java_srctar##*/}
}

# Custom installation.
java_postmake() {
	# Copy all stuff from the original home to our java-home.
	# But to make sure any possible links stay intact we use
	# tar | untar instead of cp.
	( cd $builddir/$java_home_original; tar -c * | tar -x -C /$prefix )
}

hook_add preconf 5 java_preconf
hook_add postmake 5 java_postmake