# --- T2-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# 
# T2 SDE: package/.../sancp/sancp.conf
# Copyright (C) 2004 - 2006 The T2 SDE Project
# 
# 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.
# --- T2-COPYRIGHT-NOTE-END ---

if [ "$prefix_auto" == 1 ]; then
        prefix=opt/sancp 
        set_confopt
fi

makeinstopt=""

pkg_sancp_prelude_prepatch() {
	# creating a temporary directory 
	tempdir=`mktemp -d`

	# getting the full path of the original patch
	orig_sancp_prelude_patch="`match_source_file -p prelude`"

	# name of the patch we will include
	sancp_prelude_patch="sancp-$ver-prelude-3.patch"

	# removing "/root/" from the path of the effected files in the original patch
	# and creating the sanitized patch in tempdir
	sed -e "s/^\(\+\+\+\ \)\/root\//\1/g" $orig_sancp_prelude_patch > $tempdir/$sancp_prelude_patch 

	# including the sanitized patch 
	echo_status "Enabling Prelude-IDS Support by including ($sancp_prelude_patch)"
	var_append patchfiles ' ' "$tempdir/$sancp_prelude_patch"
}

pkg_sancp_premake() {

	# adjusting default config file location 
	sed -i "/CONFIG_DIR/s,/.*,$sysconfdir\"," sancp.h
}

pkg_sancp_install() {

	# copying sancp binary 
        mkdir -p $root/$prefix/bin	
	cp -v sancp $root/$prefix/bin/sancp
	
	# copying default config file
	mkdir -p $root/$sysconfdir 
	cp -v etc/sancp/sancp.conf $root/$sysconfdir/

	# creating log directory 
	mkdir -p $root/$localstatedir/log
}

hook_add premake 5 'pkg_sancp_premake' 
hook_add postmake 5 'pkg_sancp_install'

# including the officially released sancp patches from our package 
var_append patchfiles ' ' "`match_source_file -p patch | tr '\n' ' '`"

# if libprelude is available patch sancp to become a prelude sensor
if pkginstalled libprelude ; then 
	hook_add prepatch 5 'pkg_sancp_prelude_prepatch'
fi