#!/bin/rc
########################################################################
#  This is the system wide source file for setting up modules
########################################################################

if(! ~ yes yes)
  { ! test -z $USER_IS_ROOT || ~ `{/usr/bin/id -u} 0 } && exit 0


if(~ $#MODULEPATH_ROOT 0) {
  if(~ $#USER 0) USER=$LOGNAME # make sure $USER is set
  LMOD_sys=`{/usr/bin/uname}

  MODULEPATH_ROOT=/usr/share/modulefiles
  if(test -z $LMOD_MODULEPATH_INIT) {
     if(test -f /etc/lmod/.modulespath) {
        LMOD_MODULEPATH_INIT=/etc/lmod/.modulespath
     } else {
        LMOD_MODULEPATH_INIT=/usr/share/lmod/lmod/init/.modulespath
     }
  }
  if(test -f $LMOD_MODULEPATH_INIT) {
     for(dir in `{cat $LMOD_MODULEPATH_INIT | sed 's/#.*$//'}) { # Allow end-of-line comments.
        if(test -d $dir)
           MODULEPATH=`{/usr/share/lmod/lmod/libexec/addto --append MODULEPATH $dir}
     }
  }
  if not {
     MODULEPATH=`{/usr/share/lmod/lmod/libexec/addto --append MODULEPATH $MODULEPATH_ROOT/$LMOD_sys $MODULEPATH_ROOT/Core}
     MODULEPATH=`{/usr/share/lmod/lmod/libexec/addto --append MODULEPATH /usr/share/lmod/lmod/modulefiles/Core}
  }

  #################################################################
  # Prepend any directories in LMOD_SITE_MODULEPATH to $MODULEPATH
  #################################################################
  if(! ~ $#LMOD_SITE_MODULEPATH 0) {
    MODULEPATH=`{/usr/share/lmod/lmod/libexec/addto MODULEPATH $LMOD_SITE_MODULEPATH}
  }


  if( test -z $BASH_ENV) {
     BASH_ENV=/usr/share/lmod/lmod/init/bash
  }

  #
  # If MANPATH is empty, Lmod is adding a trailing ":" so that
  # the system MANPATH will be found
  if(~ $#MANPATH 0)
    MANPATH=:
  MANPATH=`{/usr/share/lmod/lmod/libexec/addto MANPATH /usr/share/lmod/lmod/share/man}
}

fn findExec {
  Nm=$1
  confPath=$2
  execNm=$3
  $Nm=$confPath
  if( ! test -x $confPath) {
    if(test -x /bin/$execNm)
       $Nm=/bin/$execNm
    if not {
      if(test -x /usr/bin/$execNm)
       $Nm=/usr/bin/$execNm
    }
  }
  Nm=(); confPath=(); execNm=()
}

findExec PS_CMD       /usr/bin/ps        ps
findExec EXPR_CMD     /usr/bin/expr      expr
findExec BASENAME_CMD /usr/bin/basename  basename

fn findExec

if(test -f /usr/share/lmod/lmod/init/rc)
   . /usr/share/lmod/lmod/init/rc >/dev/null # Module Support
my_shell=()
MODULEPATH_INIT=()

# Local Variables:
# mode: shell-script
# indent-tabs-mode: nil
# End:
