#!/bin/sh
### BEGIN INIT INFO
# Provides:       mscs
# Required-Start: $remote_fs $syslog
# Required-Stop:  $remote_fs $syslog
# Default-Start:  2 3 4 5
# Default-Stop:   0 1 6
# chkconfig:      345 50 50
# Description:    Minecraft Server Control Script
### END INIT INFO

# This is a wrapper to msctl that imitates traditional mscs behaviour:
# uses the same default user, config file and location.

# Get executable name
PROG=$(basename $0)

# Setup the default user name.
USER_NAME="minecraft"

# Setup the default installation location.
LOCATION="/opt/mscs"

# Setup the default location of the mscs.defaults file.
MSCS_DEFAULTS="$LOCATION/mscs.defaults"

# Setup the arguments to the msctl script.
MSCS_ARGS="-p $PROG -l $LOCATION -c $MSCS_DEFAULTS $@"

# Run the msctl script.
if [ "$USER_NAME" = "$(whoami)" ]; then
  msctl $MSCS_ARGS
else
  sudo "PATH=$PATH" -u $USER_NAME -H msctl $MSCS_ARGS
fi
