#!/bin/bash

[ -n "$ENV" ] || ENV=development

version=0.0.5 # node-sitefile

echo "Configuring project node-sitefile/$version" >&2
echo "PWD (real): $(pwd) ($(pwd -P))" >&2
echo "Host (full): $(hostname) ($(hostname -f))" >&2
echo "User (dir, HOME): $(whoami) ($(cd; pwd -P), $HOME)"
echo "ENV: $ENV"

branch=$(git rev-parse --abbrev-ref HEAD)
echo "Branch: $branch"

echo '{ "sitefilerc": "'$version'" }' > .sitefilerc

(
cat <<HEREDOC
module.exports =
  site: port: 7011
  development: site: port: 7011
  testing: site: port: 7012
  production: site: port: 7013
HEREDOC
) > config/config.coffee


#[ "$ENV" == "testing" ] && {
#}

case "$(whoami)" in

  travis )
      # FIXME: fix pm2 hanging at Tavis
      case "$branch" in
        features/pm2 ) ;;
        * ) 
          sed -i.bak 's/pm2//' Sitefile.yaml
        ;;
      esac
    ;;

esac

