#!/bin/sh

###
# Live never ending Tale
#
# live-net-service script
#
# Copyright: (C) 2009-2013 Jordi Pujol <jordi_pujol@telefonica.net>
# License:   GPLv2
#
# Live never ending Tale Project Homepage:
# http://livenet.selfip.com
###

# this script should not be executed directly,
# but must be included in a service script
#
# The purpose of this development is to manage all services in /etc/init.d
# using an unique parametrized program, that standarizes routines to do the
# corresponding service actions.
# A service script will contain the LSB headers and after include this file,
# An example of /etc/init.d/service-name follows:
# #!/bin/sh
# ...
# ### END INIT INFO
# . /etc/init.d/lnet-service

###
# source lsb functions
###
. /lib/lsb/init-functions
#
# NON-LSB HELPER FUNCTIONS
#
# int get_lsb_header_val (char *scriptpathname, char *key)
get_lsb_header_val () {
	[ -s "${1}" ] && [ -n "${2:-}" ] || return 1
	sed -rne "/^### BEGIN INIT INFO/,/^### END INIT INFO/ \
s/[[:blank:]]*$//;s/^# ${2}:[[:blank:]]*([^[:blank:]]+.*)/\1/p" "${1}"
}

export NAME="$(basename "${0}" | sed -re 's|^[SK][[:digit:]]{2}(.*)|\1|')"

export SERVICE="/etc/init.d/${NAME}"
DAEMON_DESC="$(get_lsb_header_val "${SERVICE}" "Short-Description")"
DAEMON_START="$(get_lsb_header_val "${SERVICE}" "Default-Start")"
DAEMON_STOP="$(get_lsb_header_val "${SERVICE}" "Default-Stop")"

unset DAEMON
unset DAEMON_ACTIONS_CMD
unset DAEMON_ACTIONS_EXTRA
unset DAEMON_START_OPTS
unset DAEMON_RELOAD_OPTS
unset DAEMON_RELOAD_SIG
unset DAEMON_STOP_OPTS
unset DAEMON_STOP_SIG
unset DAEMON_STATUS_OPTS
unset DAEMON_BACKGROUND
unset DAEMON_LOG
unset DAEMON_PIDFILE
unset DAEMON_PIDFILE_CREATE
unset DAEMON_DISABLED
unset DAEMON_VERBOSE
export DAEMON
export DAEMON_DESC
export DAEMON_ACTIONS_CMD
export DAEMON_ACTIONS_EXTRA
export DAEMON_START
export DAEMON_START_OPTS
export DAEMON_STOP
export DAEMON_STOP_OPTS
export DAEMON_STOP_SIG
export DAEMON_RELOAD_OPTS
export DAEMON_RELOAD_SIG
export DAEMON_STATUS_OPTS
export DAEMON_BACKGROUND
export DAEMON_LOG
export DAEMON_PIDFILE
export DAEMON_PIDFILE_CREATE
export DAEMON_DISABLED
export DAEMON_VERBOSE
