#!/bin/bash
#-----------------------------------------------------------------------------#
# eFa 4.0.0 eFa-Weekly-DMARC script
#-----------------------------------------------------------------------------#
# Copyright (C) 2013~2021 https://efa-project.org
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#-----------------------------------------------------------------------------#
sleep $[ ( $RANDOM % 3600 )  + 1 ]s

rm -f /etc/opendmarc/public_suffix_list.dat.old >/dev/null 2>&1
mv -f /etc/opendmarc/public_suffix_list.dat /etc/opendmarc/public_suffix_list.dat.old >/dev/null 2>&1

curl -s https://publicsuffix.org/list/public_suffix_list.dat > /etc/opendmarc/public_suffix_list.dat
if [[ $? -ne 0 ]]; then
  rm -f /etc/opendmarc/public_suffix_list.dat >/dev/null 2>&1
  mv -f /etc/opendmarc/public_suffix_list.dat.old /etc/opendmarc/public_suffix_list.dat
elif [[ ! $(tail -n1 /etc/opendmarc/public_suffix_list.dat) =~ END\ PRIVATE\ DOMAINS ]]; then
  rm -f /etc/opendmarc/public_suffix_list.dat >/dev/null 2>&1
  mv -f /etc/opendmarc/public_suffix_list.dat.old /etc/opendmarc/public_suffix_list.dat
fi

systemctl reload opendmarc

exit 0
