#!/bin/sh

# /********************************************
# LiteSpeed Web Cache Management Plugin for cPanel
#
# @author LiteSpeed Technologies, Inc. (https://www.litespeedtech.com)
# @copyright (c) 2020
# @since 2.1
# *********************************************/

PLUGIN_DIR='/usr/local/cpanel/base/frontend/paper_lantern/ls_web_cache_manager'
SETTING_FILE="${PLUGIN_DIR}/data/lswcm.conf"

if [ ! -f "$SETTING_FILE" ] ; then
    #cPanel user-end plugin is not installed, manually remove this cron job.
    /bin/rm -f '/etc/cron.daily/ls-renew-ec-cert'
    exit 1
fi

EC_SUPPORT_SETTING=$(grep -oP '(?<=GENERATE_EC_CERTS = )(\d)' "$SETTING_FILE")

if [ "$EC_SUPPORT_SETTING" = "0" ] ; then
    # EC certificate support is off, run removal script.
    /bin/sh "${PLUGIN_DIR}/scripts/cert_support_remove.sh" >/dev/null 2>&1
    exit 1
else
    "${PLUGIN_DIR}/scripts/cert_action_entry" renewcert --all >/dev/null 2>&1
fi