# !/bin/bash

#test

PWD="/home/easybuild/GIT/it4i-modules"
cd $PWD

STATE=$(git fetch 2>&1 | grep master)
if [ ! -z "$STATE" ]; then
   git pull
   ./get_modules.sh
   exit 0
fi

if [ ! -z `hostname -f | grep "bullx"` ]; then
   ml --show-hidden -t av 2>&1 > /dev/null| awk '{print $1 ",1"}' | grep -v -e '/,\|:' > ANSELM.csh
   ./modules.py > ANSELM.md
else
   ml --show-hidden -t av 2>&1 > /dev/null| awk '{print $1 ",2"}' | grep -v -e '/,\|:' > SALOMON.csh
   ./modules.py > SALOMON.md 

   MODULEBASE="/appsuv/modules"
   MODULEPATH=""

    for dir in `ls $MODULEBASE`
    do
        # Exclude following directories
        if [[ ($dir == "all") ]]; then
            continue
        fi
        # In case that it's directory
        if [ -d $MODULEBASE/$dir ]; then
            if [ -z $MODULEPATH ]; then
                MODULEPATH="$MODULEBASE/$dir"
            else
                MODULEPATH="$MODULEPATH:$MODULEBASE/$dir"
            fi
        fi
    done

   export MODULEPATH
   
   ml --show-hidden -t av 2>&1 > /dev/null| awk '{print $1 ",3"}' | grep -v -e '/,\|:' > UV2000.csh
   ./modules.py > UV2000.md

fi
