#!/usr/bin/sh

##  Copyright 2012-2026 Carnegie Mellon University
##  See license information in LICENSE.txt.
##
##  etc/systemd/super_mediator_startup.  Generated from super_mediator_startup.in by configure.
##
#
# super_mediator start/control script
#
# chkconfig: - 18 96
# description:  Control super_mediator as a live capture daemon

##  ------------------------------------------------------------------------
##  Authors: Emily Sarneso, Dwight Beaver
##  ------------------------------------------------------------------------
##  @DISTRIBUTION_STATEMENT_BEGIN@
##  super_mediator-1.13
##
##  Copyright 2025 Carnegie Mellon University.
##
##  NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING
##  INSTITUTE MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON
##  UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
##  AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR
##  PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF
##  THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF
##  ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT
##  INFRINGEMENT.
##
##  Licensed under a GNU GPL 2.0-style license, please see LICENSE.txt or
##  contact permission@sei.cmu.edu for full terms.
##
##  [DISTRIBUTION STATEMENT A] This material has been approved for public
##  release and unlimited distribution.  Please see Copyright notice for
##  non-US Government use and distribution.
##
##  This Software includes and/or makes use of Third-Party Software each
##  subject to its own license.
##
##  DM25-1447
##  @DISTRIBUTION_STATEMENT_END@
##  ------------------------------------------------------------------------

RETVAL=0

MYNAME="super_mediator"

# autoconf stuff
prefix=/usr
exec_prefix=/usr

# super_mediator.conf must be located in the SCRIPT_CONFIG_LOCATION directory to work.
# Edit this line or set the SCRIPT_CONFIG_LOCATION environment variable if
# super_mediator.conf is not located in the default location.
if [ "x$SCRIPT_CONFIG_LOCATION" = "x" ] ; then
    SCRIPT_CONFIG_LOCATION=/etc
fi

if [ "x$SM_STATEDIR" = "x" ] ; then
    SM_STATEDIR=/var
fi

# Determine whether our name has an addendum
BASENAME='s:\(.*/\)*\([^/]*\)$:\2:'
SEDEXT1='s/\(.*\)\.init\.d$/\1/'
SEDEXT2='s/\(.*\)\.sh$/\1/'
SCRIPTNAME=`echo $0 | sed ${BASENAME} | sed ${SEDEXT1} | sed ${SEDEXT2}`
PRETEST="\\(${MYNAME}\\)\\(-.*\\)*\$"
SUFTEST="${MYNAME}\\(-.*\\)\$"
PREFIX=`expr "x${SCRIPTNAME}" : "x${PRETEST}"`
SUFFIX=`expr "x${SCRIPTNAME}" : "x${SUFTEST}"`

if [ "x$PREFIX" != "x$MYNAME" ] ; then
    SUFFIX=
fi

if [ -n "$1" ] ; then
    SCRIPT_CONFIG=${SCRIPT_CONFIG_LOCATION}/${MYNAME}${SUFFIX}.$1.conf
else
    SCRIPT_CONFIG=${SCRIPT_CONFIG_LOCATION}/${MYNAME}${SUFFIX}.conf
fi

check_executable()
{
    if [ ! -x $1 ] ; then
        echo "$0: $1 is not executable or not found."
        exit 1
    fi
}

SMBIN=/usr/bin/super_mediator

check_executable ${SMBIN}

# verify we have a good configuration

check_varempty()
{
    if [ "x$2" = "x" ] ; then
        echo "$0: the $1 parameter in ${SCRIPT_CONFIG} is not set."
        exit 1
    fi
}

# build the argument lists

SMARGS=""

SMARGS="$SMARGS -c ${SCRIPT_CONFIG}"

exec $SMBIN $SMARGS

