#!/bin/bash
# vim: set fileencoding=utf-8 :
#
#       remove_old_puppet_ca.sh
#       Copyright 2010 - 2020 Sapian SAS <sebastian.rojo@sapian.com.co>, arpagon <arpagon@gmail.com.co>
#
#       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 2 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, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

PUPPET_CA_FILES="/var/lib/puppet/ssl/certs/ca.pem /etc/puppetlabs/puppet/ssl/certs/ca.pem"
OLD_MD5_CA='891aec304f91dff08147aa2f30eff7b3'
for ca_file in $PUPPET_CA_FILES
do
  echo $ca_file
  md5=($(md5sum $ca_file))
  if [ "$md5" = "$OLD_MD5_CA" ]; then
    echo "Old CA errasing old CA..."
    rm --interactive=always $ca_file
  else
    echo "pass"
  fi
done
