#!/bin/sh
# @description re-enable a disabled rudder-agent
# @man +
# @man +
# @man *Options*:
# @man +
# @man *-s*: start rudder-agent in addition to enabling it
# @man +
# @man *-q*: run the agent in quiet mode (display only error messages)
# @man +
# @man *-c*: run the agent without color output

. "${BASEDIR}/../lib/common.sh"

QUIET=false
OPTIONS=""

while getopts "sqc" opt; do
  case $opt in
    s)
      START=y
      ;;
    q)
      QUIET=true
      OPTION="${OPTIONS} -q"
      ;;
    c)
      clear_colors
      OPTION="${OPTIONS} -c"
      ;;
  esac
done

rm -f ${RUDDER_DIR}/etc/disable-agent

[ $? -ne 0 ] && printf "${RED}error${NORMAL}: Rudder agent could not be enabled.\n" && exit 1

if [ "${START}" = "y" ]
then
  [ "$QUIET" = false ] && printf "${GREEN}ok${NORMAL}: Rudder agent has been enabled.\n"
  ${RUDDER_BIN} agent start "${OPTIONS}"
else
  if [ "$QUIET" = false ];  then
    printf "${GREEN}ok${NORMAL}: Rudder agent has been enabled but not started, wait for next cron run.\n"
  fi
fi
