#!/bin/sh
#set -ex
# This script should be run on customer system to enable ecp logging (activation) for support purpose only.
help() {
echo 'This is an script used to enable ecp logging for support purpose only.'
echo
echo 'Usage:'
printf "\t%s \n" "$0"
printf "\t%s -h\n" "$0"
printf "\t%s -e [-f]\n" "$0"
printf "\t%s -d [-f]\n" "$0"
echo
echo 'Options:'
printf "\t-h, --help\n\t\tShow this command-line arguments help\n"
printf "\t-e, --enable\n\t\tEnable ecp logging\n"
printf "\t-d, --disable\n\t\tDisable ecp logging\n"
printf "\t-f, --force\n\t\tRestart product without asking\n"
}
FORCE=0
NEED_RESTART=0
for arg in "$@"; do
case "$arg" in
-h|--help) help 1>&2; exit 0;;
-e|--enable) ENABLE=1;;
-d|--disable) ENABLE=0;;
-f|--force) FORCE=1;;
*) echo "ERROR: Unrecognized command-line option '$arg'" 1>&2; exit 2;;
esac
done
# Print help as default action
if [ -z "${ENABLE}" ]; then
help 1>&2;
exit 0;
fi
# Must be run under root user.
if [ "$(id -u)" -ne 0 ]; then
echo "ERROR: You must run this script as root." >&2
exit 1
fi
# Find security product
if [ -f "/opt/eset/eea/etc/pkgid" ]; then
PRODUCT="eea"
elif [ -f "/opt/eset/efs/etc/pkgid" ]; then
PRODUCT="efs"
else
echo "ERROR: Security product not found." >&2
exit 1
fi
INSTALL_PATH="/opt/eset/${PRODUCT}"
LICENSE_VAR_PATH="/var${INSTALL_PATH}/licensed"
LOGS_PATH="${LICENSE_VAR_PATH}/ecp"
CFG_FILE_MASK="license_cfg*.json"
if ps -ef | grep "${INSTALL_PATH}" | grep -v grep >/dev/null ; then
NEED_RESTART=1
fi
if [ "${NEED_RESTART}" -eq 1 ]; then
if [ "${FORCE}" -eq 0 ]; then
printf 'WARNING: Product will be restarted. Do you want to continue? (y/n) '
read -r r
case $r in
[Yy]|[Yy][Ee][Ss]) ;;
*) echo 'ERROR: Logging cannot be enabled/disabled without restating product. '
exit 1;;
esac
fi
if systemctl --version >/dev/null 2>/dev/null; then
systemctl stop "${PRODUCT}" 2> /dev/null
else
echo "ERROR: systemctl not present on system, please stop product manually." 1>&2
exit 1
fi
fi
if [ "${ENABLE}" -eq 1 ]; then
find "${LICENSE_VAR_PATH}" -name "${CFG_FILE_MASK}" -type f -execdir sed -i 's/"Logging"[ \t]*:[ \t]*false/"Logging":true/g' "{}" +
echo "Logging enabled."
echo "Logs will be collected here: ${LOGS_PATH}"
else
find "${LICENSE_VAR_PATH}" -name "${CFG_FILE_MASK}" -type f -execdir sed -i 's/"Logging"[ \t]*:[ \t]*true/"Logging":false/g' "{}" +
echo "Logging disabled."
fi
if [ "${NEED_RESTART}" -eq 1 ]; then
if systemctl --version >/dev/null 2>/dev/null; then
systemctl start "${PRODUCT}" 2> /dev/null
fi
fi