#!/bin/bash
# Maintainer: Martin Weise <martin.weise@tuwien.ac.at>
# Short:      Creates a user if not exist
# Synopsis:   ./bin/user-create full_name username organization email phone
function usage () {
  echo "USAGE: $0 'full_name' 'username' organization email phone"
}

if [ $# -ne 5 ]; then
  usage
  exit 1
fi

echo -e "USER CREATE [Start] ************************************************************"
ansible-playbook "./create-user.yml" -e "full_name='$1'" -e "username='$2'" -e "organization='$3'" -e "email='$4'" -e "phone='$5'"

if [ $? -eq 0 ]; then
  echo -e "USER CREATE [Done] *************************************************************"
  echo -e "\e[92mok: [localhost]\e[39m"
  cat /tmp/vpn.txt
  exit 0
else
  echo -e "USER CREATE [Done] *************************************************************"
  echo -e "\e[91mfailed: playbook returned non-zero exit code\e[39m"
  exit 1
fi