#!/bin/sh
#
# $Id: service_get_init_script_name,v 1.2 2005/12/13 16:30:15 gleissner Exp $
#
#
# Project     :  SCPM (System Configuration Profile Management)
# Module      :  SCPM utilities
# File        :  service_get_init_script_name
# Description :  Returns name of init script for given Service
# Author      :  Joachim Gleissner <jg@suse.de>
#
# Copyright 2001 SuSE GmbH
#
# Released under the terms of the GNU General Public License
# (see file COPYRIGHT in project root directory).
#

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

show_usage()
{
    echo "$0 [options] service"
    echo
    echo "options may be"
    echo
    echo "-h   shows help (this one)"
}

while test -n "$1" ; do
    case "$1" in
        -h)
	show_usage
	exit 0
	;;

	*)
	test -n "$SERVICE" && { echo "unknown option $1" >&2 ; exit 1 ; }
	SERVICE=$1
	;;
    esac
    shift
done

cd $INITD || exit 1

for i in * ; do
    test -d $i && continue
    for j in $EXCLUDE_FILES ; do
	test "$j" = "$i" && continue
    done
    SERVICE_NAME=$( grep -E "^# Provides:" $i | awk '{ print $3 }' )

    if [ "$SERVICE_NAME" = "$SERVICE" ]; then
	echo $i
	exit 0
    fi

done

exit 0