#!/bin/sh
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../sun-jre-142/java-sun-conf.in
# Copyright (C) 2007 - 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_home_original=

# Gnome support is only turned on when gnome is installed.
if pkginstalled libgnome; then
	pkgprefix -t libgnome
	GNOME_DIR=$root/$( pkgprefix libgnome )
	export GNOME_DIR
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`" ;;
	ia64)	java_srctar="`match_source_file -p -ia64`" ;;
	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,more <<,cat <<,' ${java_srctar##*/}
	sed -i 's,agreed=,agreed=1,' ${java_srctar##*/}
	sed -i 's,`agree`,yes,' ${java_srctar##*/}

	if [[ $pkg == *-150 ]]; then
		patch -p0 ${java_srctar##*/} $confdir/../sun-jre-150/mime-type-remove.diff
	fi

	# Retrieve the original javahome name from the archive.
	tempvar="`head -n60 ${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