# --- ROCK-COPYRIGHT-NOTE-BEGIN ---
# 
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# Please add additional copyright information _after_ the line containing
# the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
# the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
# 
# ROCK Linux: rock-src/package/base/sysvinit/parse-config
# ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
# 
# 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; either version 2 of the License, or
# (at your option) any later version. A copy of the GNU General Public
# License can be found at Documentation/COPYING.
# 
# Many people helped and are helping developing ROCK Linux. Please
# have a look at http://www.rocklinux.org/ and the Documentation/TEAM
# file for details.
# 
# --- ROCK-COPYRIGHT-NOTE-END ---


if [ "$ROCKCFG_PKG_SYSVINIT_INITSTYLE" = "sysv_text" ] ||
   [ "$ROCKCFG_PKG_SYSVINIT_INITSTYLE" = "sysv_nice" ]
then
    install_init() {
	name=$1 ; file=$2 ; set `grep '# Runlevel: ' $file | cut -f3- -d' '`
	spri=$1 ; kpri=`expr 100 - $spri` ; initdir="$root/etc/rc.d" ; shift

	echo -n "Install SysV Init script '$name' ($spri/$kpri): "
	m4 -Dinitstyle=$ROCKCFG_PKG_SYSVINIT_INITSTYLE \
	   -D"D_prefix=/$prefix"  -D"D_sysconfdir=$sysconfdir" \
	   -D"D_docdir=$docdir"   -D"D_localstatedir=$localstatedir" \
	   -D"D_datadir=$datadir" -D"D_infodir=$infodir" \
	   -D"D_mandir=$mandir"   $base/package/base/sysvinit/init_macros.m4 \
	   $file > $initdir/init.d/$name
	chmod +x $initdir/init.d/$name
	#
	for runlevel ; do
		echo -n " $runlevel"
		if [ "$runlevel" != rcX ] ; then
			ln -sf ../init.d/$name $initdir/$runlevel.d/S$spri$name
			ln -sf ../init.d/$name $initdir/$runlevel.d/K$kpri$name
		else
			echo "The script '$name' has the priority $pri." \
					> $initdir/rcX.d/X$spri$name
		fi
	done
	#
	echo " done."
    }
fi
