### Generic variables and functions
### -------------------------------

if [ -z "${SYNOPKG_PKGNAME}" ] || [ -z "${SYNOPKG_DSM_VERSION_MAJOR}" ]; then
  echo "Error: Environment variables are not set." 1>&2;
  echo "Please run me using synopkg instead. Example: \"synopkg start [packagename]\"" 1>&2;
  exit 1
fi

USER="ZeroNews"
EFF_USER="ZeroNews"

# start-stop-status script redirect stdout/stderr to LOG_FILE
LOG_FILE="${SYNOPKG_PKGVAR}/${SYNOPKG_PKGNAME}.log"

# Service command has to deliver its pid into PID_FILE
PID_FILE="${SYNOPKG_PKGVAR}/${SYNOPKG_PKGNAME}.pid"


### Package specific variables and functions
### ----------------------------------------

export ZERONEWS_DIR="${SYNOPKG_PKGVAR}"

SERVICE_COMMAND="${SYNOPKG_PKGDEST}/bin/zeronews start --workdir ${ZERONEWS_DIR}"
SVC_BACKGROUND=y
SVC_WRITE_PID=y

service_postinst ()
{
    # Register token to ZeroNews account
    if [ -n "${wizard_token}" ]; then
        ${SYNOPKG_PKGDEST}/bin/zeronews authtoken ${wizard_token} --workdir ${ZERONEWS_DIR}
    fi
}
