########################################################
# Sets the environment for the Kolibri system service
# Do not change this script!
#
# This script must always be invoked with set -o allexport
# Ref:
# https://github.com/learningequality/kolibri-installer-debian/issues/84
#
# To configure the system service, please either

# 1) Edit /etc/kolibri/daemon.conf
# 2) Add your own scripts to /etc/kolibri/conf.d/*.conf
#    .conf scripts are loaded in alphanumeric order
########################################################

# This is used in order for calling shells to  read the environment defined by
# the debian environment
set -o allexport

# Set the default values

if [ -f /etc/kolibri/username ]
then
  export KOLIBRI_USER=`cat /etc/kolibri/username`
  if [ "$KOLIBRI_USER" = "" ]
  then
    export KOLIBRI_USER="kolibri"
  fi
else
  export KOLIBRI_USER="kolibri"
fi

export KOLIBRI_INSTALLATION_TYPE="deb"

KOLIBRI_HOME="$(getent passwd $KOLIBRI_USER | awk -F ':' '{print $6}')/.kolibri"
KOLIBRI_COMMAND="kolibri"

# Additional environment variables could be defined here, but be careful
# not to define the environment for the sake of taking control over defaults,
# as the Debian package may be used to package other source distributions
# of Kolibri.
# Ref:
# https://github.com/learningequality/kolibri-installer-debian/issues/84
# Removed:
# DJANGO_SETTINGS_MODULE="kolibri.deployment.default.settings.base"

# Load conf.d directory

if [ -d /etc/kolibri/conf.d ]
then
  for f in /etc/kolibri/conf.d/*.conf
  do
    # Necessary because of empty directories
    if [ -e "$f" ]
    then
      . "$f"
    fi
  done
fi

# Load user configuration

if [ -e /etc/kolibri/daemon.conf ]
then
  . /etc/kolibri/daemon.conf
fi

# Switch off the allexport behavior
set +o allexport
