#!/bin/sh
#
# $Id: service_restore,v 1.2 2005/12/13 16:30:15 gleissner Exp $
#
#
# Project     :  SCPM (System Configuration Profile Management)
# Module      :  SCPM Utilities
# File        :  service_restore
# Description :  Restores service for given runlevels
# Author      :  Joachim Gleissner <jg@suse.de>
#
# Copyright 2002-2004 SuSE Linux AG
#
# Released under the terms of the GNU General Public License
# (see file COPYRIGHT in project root directory).
#

test -z "$1" && { echo "no init script given" >&2 ; exit 1 ; }
test -z "$2" && { echo "no runlevels given" >&2 ; exit 1 ; }

. /etc/sysconfig/scpm || exit 1
. $LIBDIR/resource_types/service/common || exit 1

test -f $INITD/$1 || { echo "no such file $INITD/$1" >&2 ; exit 2 ; }

SERVICE=$1
shift

while [ -n "$1" ]; do
    RL=$( echo ${1%:*} )
    ACTIVE=$( echo ${1#*:} )
    test "$ACTIVE" = "on" && RUNLEVELS="${RUNLEVELS}${RL}"
    shift
done

test -z "$RUNLEVELS" && RUNLEVELS="off"

# NOTE: this does not work with Red Hat chkconfig
/sbin/chkconfig -f $SERVICE $RUNLEVELS

exit 0
