mystic/dbp/cron.sh
2023-01-14 11:32:27 +01:00

104 lines
4.1 KiB
Bash
Executable File

#!/bin/bash
usage() { echo "Usage: $0 [-f dbp.ini]" 1>&2; exit 1; }
while getopts ":f:" o; do
case "${o}" in
f)
INIFILE=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${INIFILE}" ]; then
usage
fi
MYSTIC_DIR="@MYSTIC_DIR@"
TMP_DIR=$(mktemp -d)
MIS_ENABLE=`${MYSTIC_DIR}/inimod r ${INIFILE} -S GeneralDbP -k MisLog --silent`
MIS_KEEP=`${MYSTIC_DIR}/inimod r ${INIFILE} -S MisLog -k RetentionTime --silent`
MUTIL_ENABLE=`${MYSTIC_DIR}/inimod r ${INIFILE} -S GeneralDbP -k MutilLog --silent`
MUTIL_KEEP=`${MYSTIC_DIR}/inimod r ${INIFILE} -S MutilLog -k RetentionTime --silent`
ERROR_ENABLE=`${MYSTIC_DIR}/inimod r ${INIFILE} -S GeneralDbP -k ErrorLog --silent`
ERROR_KEEP=`${MYSTIC_DIR}/inimod r ${INIFILE} -S ErrorLog -k RetentionTime --silent`
MRCCHAT_ENABLE=`${MYSTIC_DIR}/inimod r ${INIFILE} -S GeneralDbP -k MrcChatLog --silent`
MRCCHAT_KEEP=`${MYSTIC_DIR}/inimod r ${INIFILE} -S MrcChatLog -k RetentionTime --silent`
NODE_ENABLE=`${MYSTIC_DIR}/inimod r ${INIFILE} -S GeneralDbP -k NodeLog --silent`
NODE_COUNT=`${MYSTIC_DIR}/inimod r ${INIFILE} -S NodeLog -k MaxNodes --silent`
NODE_KEEP=`${MYSTIC_DIR}/inimod r ${INIFILE} -S NodeLog -k RetentionTime --silent`
NODE_START=0
IP2L_ENABLE=`${MYSTIC_DIR}/inimod r ${INIFILE} -S GeneralDbP -k Ip2Location --silent`
IP2L_TOKEN=`${MYSTIC_DIR}/inimod r ${INIFILE} -S Ip2Location -k Token --silent`
IP2L_DB=`${MYSTIC_DIR}/inimod r ${INIFILE} -S Ip2Location -k Database --silent`
YESTERDAY=$(date '+%Y%m%d' -d "-1days")
NOW=$(date '+%Y%m%d')
TOMORROW=$(date '+%Y%m%d' -d "+1days")
if [ $MIS_ENABLE = "true" ]; then
touch ${MYSTIC_DIR}/logs/mis.${NOW}.log
touch ${MYSTIC_DIR}/logs/mis.${TOMORROW}.log
ln -sf mis.${NOW}.log ${MYSTIC_DIR}/logs/mis.log
[ -f /${MYSTIC_DIR}/logs/mis.${YESTERDAY}.log ] && gzip -9 ${MYSTIC_DIR}/logs/mis.${YESTERDAY}.log
find ${MYSTIC_DIR}/logs/ -type f -mtime +${MIS_KEEP} -name 'mis.*' -exec rm {} \;
fi
if [ $MUTIL_ENABLE = "true" ]; then
touch ${MYSTIC_DIR}/logs/mutil.${NOW}.log
touch ${MYSTIC_DIR}/logs/mutil.${TOMORROW}.log
ln -sf mutil.${NOW}.log ${MYSTIC_DIR}/logs/mutil.log
[ -f /${MYSTIC_DIR}/logs/mutil.${YESTERDAY}.log ] && gzip -9 ${MYSTIC_DIR}/logs/mutil.${YESTERDAY}.log
find ${MYSTIC_DIR}/logs/ -type f -mtime +${MUTIL_KEEP} -name 'mutil.*' -exec rm {} \;
fi
if [ $ERROR_ENABLE = "true" ]; then
touch ${MYSTIC_DIR}/logs/errors.${NOW}.log
touch ${MYSTIC_DIR}/logs/errors.${TOMORROW}.log
ln -sf errors.${NOW}.log ${MYSTIC_DIR}/logs/errors.log
[ -f /${MYSTIC_DIR}/logs/errors.${YESTERDAY}.log ] && gzip -9 ${MYSTIC_DIR}/logs/errors.${YESTERDAY}.log
find ${MYSTIC_DIR}/logs/ -type f -mtime +${ERROR_KEEP} -name 'error.*' -exec rm {} \;
fi
if [ $MRCCHAT_ENABLE = "true" ]; then
touch ${MYSTIC_DIR}/logs/mrcchat.${NOW}.log
touch ${MYSTIC_DIR}/logs/mrcchat.${TOMORROW}.log
mkdir -p ${MYSTIC_DIR}/data/mrc/
ln -sf ../../logs/mrcchat.${NOW}.log ${MYSTIC_DIR}/data/mrc/mrcchat.log
ln -sf mrcchat.${NOW}.log ${MYSTIC_DIR}/logs/mrcchat.log
[ -f /${MYSTIC_DIR}/logs/mrcchat.${YESTERDAY}.log ] && gzip -9 ${MYSTIC_DIR}/logs/mrcchat.${YESTERDAY}.log
find ${MYSTIC_DIR}/logs/ -type f -mtime +${MRCCHAT_KEEP} -name 'mrcchat.*' -exec rm {} \;
fi
if [ $NODE_ENABLE = "true" ]; then
for i in $(eval echo "{$NODE_START..$NODE_COUNT}")
do
touch ${MYSTIC_DIR}/logs/node${i}.${NOW}.log
touch ${MYSTIC_DIR}/logs/node${i}.${TOMORROW}.log
ln -sf node${i}.${NOW}.log ${MYSTIC_DIR}/logs/node${i}.log
[ -f ${MYSTIC_DIR}/logs/node${i}.${YESTERDAY}.log ] && gzip -9 ${MYSTIC_DIR}/logs/node${i}.${YESTERDAY}.log
find ${MYSTIC_DIR}/logs/ -type f -mtime +${NODE_KEEP} -name 'node*' -exec rm {} \;
done
fi
if [ $IP2L_ENABLE = "true" ]; then
${MYSTIC_DIR}/ip2location -package ${IP2L_DB} -token ${IP2L_TOKEN} -output ${TMP_DIR}/IP2LOCATION.ZIP
unzip -o ${TMP_DIR}/IP2LOCATION.ZIP -x *.TXT -d ${TMP_DIR}
unzip -o ${TMP_DIR}/IP2LOCATION.ZIP -x *.BIN -d ${MYSTIC_DIR}/docs
mv ${TMP_DIR}/IP2LOCATION-*.BIN ${MYSTIC_DIR}/data/iplocation.bin
rm -rf ${TMP_DIR}
fi
exit 0