#!/bin/bash
# vim:set sw=4 ts=4:
#
# $Id: make_runlevels,v 1.5 2005/06/14 14:11:05 fabian Exp $
#
#############################################################################
#
# ALICE
# Automatic Linux Installation and Configuration Environment
#
# Copyright (c) 2000-2002 SuSE Linux Solutions AG, Eschborn, Germany
#               2002-2004 SuSE Linux AG, Eschborn, Germany
#               2005           SUSE GmbH, Nuernberg, Germany
#
# 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.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#############################################################################
#
# Author: Fabian Herschel
#
#############################################################################
#
# make_runlevels
#
# Sections: sys
# Tags:     SYS_DEFAULT_RUNLEVEL, SYS_SERVICES  
#
##########################################
# NOTES:
#    ONLY FOR alice2 (SLES8 and above)
#
usage()
{
   echo "$_self -h | --help | -?"
   echo "$_self -fqhn"
}

test -n "$alice_dir" || alice_dir="/usr/lib/alice2/"
export alice_dir


while [ $# -gt 0 ]
do
   case $1 in
       -h | --help | -? ) usage
                          exit 1
                          ;;
       -fqhn | --fqhn ) export fqhn=$2; shift
            ;;

   esac
   shift
done

. $alice_dir/lib/alicerc
WELCOME
GET_CONFIGURATION sys
#
# SET SYSTEM DEFAULT RUN LEVEL
# 
std_inittab=/etc/inittab
if [ "${SYS_DEFAULT_RUNLEVEL}" ];
then
	BACKUP --error "${std_inittab}"
	mv "${std_inittab}" "${std_inittab}.org"
	sed -e "s+^id:.*:\\(.*\\):\\(.*\\)$+id:${SYS_DEFAULT_RUNLEVEL}:\\1:\\2+" "${std_inittab}.org" > "${std_inittab}"
	rm "${std_inittab}.org"
fi
#
# SWITCH SOME SERVICES
#
if [ -n "$SYS_SERVICES" ]
then
	echo "$SYS_SERVICES" | while read line
	do
	    echo "$line" | ( IFS=: read name up down switch
			#
			# we can only handle either "enable" or "disable" (both switch field) or a runlevel-list (up field)
			#  the down field is ignored. Don't know how to give this param to chkconfig
			#
			case "$switch" in
				enable )
					chkconfig -a $name
					;;
				disable )
					chkconfig -d $name
					;;
				""	)
					if [ -n "$up" ] 
					then
						chkconfig -s $name "$up"
					fi
					;;
			esac
	    )
	done
fi
GOOD_BYE
