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

# This package is mutually exclusive with cron.
if pkginstalled cron; then
	echo_error "CLASH: cron and $pkg don't go together."
fi

pkgprefix -t bglibs

sysconfdir=$sysconfdir/$pkg

bcron_bglibsconf() {
	echo $root$( pkgprefix libdir bglibs ) > conf-bglibs
	echo $root$( pkgprefix includedir bglibs ) > conf-bgincs
	echo $root$bindir > conf-bin
}

# to get rid of the ./installer we patched the makefile to use
# normal installing procedures
var_append makeinstopt ' ' BINDIR=$root$bindir

bcron_prepare() {
	local spool=$root/var/spool/cron
	mkdir -p $spool/{crontabs,tmp}

	[ -e $spool/trigger ] || mkfifo $spool/trigger
	add_flist $spool/trigger

	for i in crontabs tmp trigger; do
		chown 53:53 $spool/$i
		chmod go-rwx $spool/$i
	done
}

bcron_install_cron() {
	local crondir=$confdir/../cron
	cp $crondir/crontab $root/etc/
	cp $crondir/cron.run.sh $root/usr/sbin/cron.run
	chmod 600 $root/etc/crontab
	chmod 755 $root/usr/sbin/cron.run
}

hook_add preconf 1 'bcron_bglibsconf'
hook_add postmake 5 'bcron_prepare'
hook_add postmake 6 'bcron_install_cron'

for y in $( ls -1 package/*/cron/*.cron 2> /dev/null ); do
	hook_add postinstall 6 "install_cron '$y'"
done