# !/bin/bash

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.csv
   ./modules.py > anselm.md
else
   ml --show-hidden -t av 2>&1 > /dev/null| awk '{print $1 ",2"}' | grep -v -e '/,\|:' > salomon.csv
   ./modules.py > salomon.md 
fi

DATE=`date -R`
git diff --exit-code || git commit -am "$DATE"
git push origin master
