#!/bin/sh
# @description forbid rudder-agent to be run by cron or service
# @man This is useful when you want to temporarily prevent your Rudder agent
# @man from doing any modification to your system.
# @man +
# @man *Options*:
# @man +
# @man *-s*: stop rudder-agent in addition to disabling it
# @man +
# @man *-k*: keep cf-serverd when stopping agent
# @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 "qcsk" opt; do
  case $opt in
    s)
      STOP=y
      ;;
    k)
      OPTIONS="${OPTIONS} -k"
      ;;
    q)
      QUIET=true
      OPTIONS="${OPTIONS} -q"
      ;;
    c)
      clear_colors
      OPTIONS="${OPTIONS} -c"
      ;;
  esac
done

touch ${RUDDER_DIR}/etc/disable-agent

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

[ "$QUIET" = false ] && printf "${GREEN}ok${NORMAL}: Rudder agent is now disabled.\n"
if [ "${STOP}" = "y" ]; then
  rudder agent stop ${OPTIONS}
fi
