#!/bin/sh
#set -e

. $KUMATUXBIN/kumatux.org-vars

## To strip out prior exports of $KUMATUXPATH from $PATH to get a clean $PATH to append the new export to
KUMATUXPATHESCAPED=`$KUMATUXBIN/kumatux.org-sed-escape $KUMATUXPATH`
KUMATUXBINESCAPED=`$KUMATUXBIN/kumatux.org-sed-escape $KUMATUXBIN`

if [ "$KUMATUXPATHESCAPED" ]
then
    SYSTEMPATH=`echo $PATH | sed "s/$KUMATUXPATHESCAPED://"`
else
    SYSTEMPATH=$PATH
fi
if [ "$KUMATUXBINESCAPED" ]
then
    SYSTEMPATH=`echo $SYSTEMPATH | sed "s/$KUMATUXBINESCAPED://"`
fi

export KUMATUXPATH=`cat $KUMATUXETC/$KUMATUXETCBIN/*.conf 2>/dev/null | sed 's/:$//'`

if [ "$KUMATUXPATH" ]
then
    export PATH=$KUMATUXBIN:$KUMATUXPATH:$SYSTEMPATH
else
    export PATH=$KUMATUXBIN:$SYSTEMPATH
fi
