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


# Service port
SERVICE_PORT="5500"

# 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
### ----------------------------------------


# Kavita service setup
SVC_BACKGROUND=y
SVC_WRITE_PID=y
SVC_WAIT_TIMEOUT=90

# Kavita uses custom Config
HOME_DIR="${SYNOPKG_PKGDEST}/share"
CONFIG_DIR="${SYNOPKG_PKGVAR}/config"

SVC_CWD="${HOME_DIR}"
SERVICE_COMMAND="${SYNOPKG_PKGDEST}/share/Kavita"

service_postinst ()
{
    echo "Setup config directory"
    # Remove default config directory and link to var
    ${RM} "${HOME_DIR}/config"
    ${LN} "${CONFIG_DIR}" "${HOME_DIR}/config"

    if [ "${SYNOPKG_DSM_VERSION_MAJOR}" -lt 7 ]; then
        set_unix_permissions "${CONFIG_DIR}"
    fi
}
