#!/bin/bash

# Puppet functional testing
# Starts a Vagrant instance after applying classification data

# Accept classification from the user
ROLE=$1
ENVIRONMENT=$2

show_usage_and_quit () {
  echo "Usage:"
  echo "  bash tests/functional <ROLE> <ENVIRONMENT>"
  exit 1
}

# Input validation
if [ -z ${ROLE} ]; then show_usage_and_quit; fi
if [ -z ${ENVIRONMENT} ]; then show_usage_and_quit; fi

# Write the classification data
if [ ! -d .facts ]; then
  mkdir .facts;
fi
echo "twitch_role=${ROLE}" > .facts/twitch_role.txt
echo "twitch_environment=${ENVIRONMENT}" > .facts/twitch_environment.txt

# For bare metal, we need to include any proxy configuration
test -f /etc/profile.d/proxy.sh && {
  echo "Detected /etc/profile.d/proxy.sh, sourcing it now"
  source /etc/profile.d/proxy.sh
}
