
extdesc="the afrepo (audio-fingerprinting) Extension"

full_setup=`pwd`/${BASH_SOURCE}
fulldir=${full_setup%/*}
fulldir=${fulldir%/.}

# Dependency of AMP extension => source first
if [ "x$GEXTAMP" = "x" ] ; then
  pushd $fulldir > /dev/null
  if [ -d ../amp/ ] ; then
    store_extdesc=$extdesc
    cd ../amp/ && source ./setup.bash
    extdesc=$store_extdesc
  fi
  popd > /dev/null
fi

if test -z $GSDLOS ; then
  GSDLOS=`uname -s | tr '[A-Z]' '[a-z]'`
  # check for running bash under Cygwin
  if test "`echo $GSDLOS | sed 's/cygwin//'`" != "$GSDLOS" ;
  then
    GSDLOS=windows
  fi
  # check for running bash under MinGW/MSys
  if test "`echo $GSDLOS | sed 's/mingw//'`" != "$GSDLOS" ;
  then
    GSDLOS=windows
  fi
  echo "GSDLOS was not set.  Setting it to '$GSDLOS'"
  export GSDLOS
fi
	

if [ "x$GEXT_AFREPO" = "x" ] ; then
  export GEXT_AFREPO=`pwd`
  export GEXT_AFREPO_INSTALLED=$GEXT_AFREPO/$GSDLOS

  if [ -d "$GEXT_AFREPO_INSTALLED/bin/script" ] ; then
    export PATH=$GEXT_AFREPO_INSTALLED/bin/script:$PATH
  fi

  if [ -d "$GEXT_AFREPO_INSTALLED/bin" ] ; then
    export PATH=$GEXT_AFREPO_INSTALLED/bin:$PATH
  fi

  export PATH=$GEXT_AFREPO/bin/script:$PATH

  if [ -d "$GEXT_AFREPO_INSTALLED/lib" ] ; then
    if [ "$GSDLOS" = "linux" ] ; then
      export LD_LIBRARY_PATH=$GEXT_AFREPO_INSTALLED/lib:$GEXT_AFREPO_INSTALLED/lib64:$LD_LIBRARY_PATH
    elif [ "$GSDLOS" = "darwin" ] ; then
      export DYLD_LIBRARY_PATH=$GEXT_AFREPO_INSTALLED/lib:$GEXT_AFREPO_INSTALLED/lib64:$DYLD_LIBRARY_PATH
    fi
  fi

  extdir=${GEXT_AFREPO##*/}

  if [ "x$GSDLEXTS" = "x" ] ; then
    export GSDLEXTS=$extdir
  else 
    export GSDLEXTS=$GSDLEXTS:$extdir
  fi


  echo "+Your environment is now setup for $extdesc"
else
  echo "+Your environment is already setup for $extdesc"
fi

found_php_bin=0
if [ "x$GEXTAMP" != "x" ] ; then

  if [ -d "$GEXTAMP_INSTALLED/htdocs/afrepo/bin" ] ; then
    export PATH=$GEXTAMP_INSTALLED/htdocs/afrepo/bin:$PATH
    echo "+Your environment is now setup to run PHP scripts for $extdesc"
    found_php_bin=1
  fi
fi

if [ "$found_php_bin" = "0" ] ; then
  echo "+ *** Warning: failed to find Apache's htdocs directory through GEXTAMP_INSTALLED"
  echo "+ ***          to add 'htdocs/afrepo/bin' to PATH to be able to run PHP scripts"
  echo "+ ***          from the command line"
  echo "+ ***          Assuming these scripts are somehow already on your PATH"
fi
