### 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="sc-gotify"
EFF_USER="sc-gotify"

# Service port
SERVICE_PORT="7152"

# 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 GOTIFY_SERVER_PORT=7152
export GOTIFY_DATABASE_CONNECTION=${SYNOPKG_PKGVAR}/gotify.db
export GOTIFY_SERVER_SSL_LETSENCRYPT_CACHE=${SYNOPKG_PKGVAR}/certs
export GOTIFY_UPLOADEDIMAGESDIR=${SYNOPKG_PKGVAR}/images
export GOTIFY_PLUGINSDIR=${SYNOPKG_PKGVAR}/plugins

# Load custom variables. Those may overwrite variables above
ENV_VARIABLES="${SYNOPKG_PKGVAR}/environment-variables"
if [ -r "${ENV_VARIABLES}" ]; then
    . "${ENV_VARIABLES}"
fi

SERVICE_COMMAND="${SYNOPKG_PKGDEST}/bin/gotify-server"
SVC_BACKGROUND=yes
SVC_WRITE_PID=yes
