#!/bin/sh

  test -n "$FIRST_ARG" || FIRST_ARG=$1 
  FORCE_YES=0 
  REMOVED_START=no 
  set --  jonas 
  PNAME=jonas 
  INSSRV_ARRAY="" 
  while [ ${#*} -gt 0 ] ; do 
    SCRIPTNAME=$1 
    shift 
     
    STARTVAR=START_`echo $SCRIPTNAME | tr a-z.- A-Z__` 
    SV_B='^### BEGIN INIT INFO' 
    SV_E='^### END INIT INFO' 
    SV_KW=X-UnitedLinux-Default-Enabled 
    SV_VAL=`sed -n -e "/$SV_B/,/$SV_E/{/^# $SV_KW:[[:space:]]*\([^[:space:]]*\).*/s//\1/p;}" < etc/init.d/$SCRIPTNAME` 
    test -n "$SV_VAL" || SV_VAL="no" 
    eval $STARTVAR=$SV_VAL 
    test -n "$STARTVAR" -a -n "$SCRIPTNAME" || { 
	echo "STARTVARIABLE or SCRIPTNAME unknown" 
	exit 1 
    } 
    INSSRV_ARRAY="$INSSRV_ARRAY $SCRIPTNAME $STARTVAR" 
     
  done 
   
   
   set --  $INSSRV_ARRAY 
    while [ ${#*} -gt 0 ] ; do 
	SCRIPTNAME=$1 
	STARTVAR=$2 
	shift 2 
	test -n "$STARTVAR" -a -n "$SCRIPTNAME" || { 
	    echo "STARTVAR or SCRIPTNAME unknown" 
	    exit 1 
	} 
	if test "$FIRST_ARG" = "1" -o "$REMOVED_START" = "yes" -o "$FORCE_YES" = "1" ; then 
	  if test -n "$YAST_IS_RUNNING" ; then 
	    INSSERV_FORCE="-f" 
	  else 
	    INSSERV_FORCE="" 
	  fi 
	  if test "${!STARTVAR}" = "yes" -o "$FORCE_YES" = "1" ; then 
	    sbin/insserv $INSSERV_FORCE etc/init.d/$SCRIPTNAME 
	  else 
	    sbin/insserv $INSSERV_FORCE -r etc/init.d/$SCRIPTNAME 
	  fi 
	fi 
    done 

  PNAME=j2ee 
  SUBPNAME=-jonas 
    TEMPLATE_DIR=var/adm/fillup-templates 
    SYSC_TEMPLATE=$TEMPLATE_DIR/sysconfig.$PNAME$SUBPNAME 
    RC_TEMPLATE=$TEMPLATE_DIR/rc.config.$PNAME 
    SD_NAME="" 
     
    if [ -x bin/fillup ] ; then 
	
	if [ -f $SYSC_TEMPLATE ] ; then 
	    echo "Updating etc/sysconfig/$SD_NAME$PNAME..." 
	    if [ ! -d etc/sysconfig/$SD_NAME ] ; then 
		mkdir -p etc/sysconfig/$SD_NAME 
	    fi 
	    if [ -f etc/rc.config.d/$PNAME.rc.config ] ; then 
		if [ -f etc/sysconfig/$SD_NAME$PNAME ] ; then 
		    bin/fillup -q etc/sysconfig/$SD_NAME$PNAME etc/rc.config.d/$PNAME.rc.config 
		    rm -f etc/rc.config.d/$PNAME.rc.config 
		else 
		    mv etc/rc.config.d/$PNAME.rc.config etc/sysconfig/$SD_NAME$PNAME 
		fi 
	    fi 
	    if [ ! -f etc/rc.config ] ; then 
		test -f etc/sysconfig/$SD_NAME$PNAME || touch etc/sysconfig/$SD_NAME$PNAME 
		bin/fillup -q etc/sysconfig/$SD_NAME$PNAME $SYSC_TEMPLATE 
	    else 
	        if [ ! -f etc/sysconfig/$SD_NAME$PNAME ] ; then 
		    bin/fillup -q -r -i etc/rc.config $SYSC_TEMPLATE etc/sysconfig/$SD_NAME$PNAME 
	        else 
		    bin/fillup -q -r -i etc/rc.config $SYSC_TEMPLATE etc/sysconfig/$SD_NAME$PNAME.tmp 
		    bin/fillup -q etc/sysconfig/$SD_NAME$PNAME etc/sysconfig/$SD_NAME$PNAME.tmp 
		    rm -f etc/sysconfig/$SD_NAME$PNAME.tmp 
	        fi 
	        if [ -f etc/rc.config.new ] ; then 
		    mv etc/rc.config.new etc/rc.config 
	        fi 
	    fi
	fi 
	
	# maybe the fillup template for rc.config is old, make sure we do not readd stuff here 
	if [ -f $SYSC_TEMPLATE -a -f $RC_TEMPLATE ] ; then 
	  bin/fillup -q -r -i $RC_TEMPLATE $SYSC_TEMPLATE /dev/null 
	  mv $RC_TEMPLATE.new $RC_TEMPLATE 
	fi 
	# do the normal fillup for the rc.config variables 
	if [ -f $RC_TEMPLATE ] ; then 
	  bin/fillup -q -d = etc/rc.config $RC_TEMPLATE 
	fi 
    else 
	echo "ERROR: fillup not found. This should not happen. Please compare" 
	echo "etc/rc.config and $RC_TEMPLATE and" 
	echo "update by hand." 
    fi