cert_replace.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. #Cert replacement script
  3. orig_cert_loc=/etc/pki/tls/certs/6628673501320294007.crt
  4. orig_key_loc=/etc/pki/tls/private/6628673501320294007.key
  5. orig_mellon_file1=/etc/httpd/mellon/monitoring-rp_idp_metadata.xml
  6. orig_mellon_file2=/etc/httpd/mellon/monitoring-rp_sp.xml
  7. new_cert_loc=/home/recovery/csiwildcard2022.crt
  8. new_key_loc=/home/recovery/csiltd2022.key.new
  9. new_mellon_file1=/home/recovery/monitoring-rp_idp_metadata.xml.new
  10. new_mellon_file2=/home/recovery/monitoring-rp_sp.xml.new
  11. timestamp=$(date +%Y%m%d-%k%M%S)
  12. if [ "$EUID" -ne 0 ]
  13. then echo "Please run as root"
  14. exit
  15. fi
  16. echo "Backing up old keys and certificate"
  17. cp $orig_cert_loc $orig_cert_loc.$timestamp
  18. echo "Saved "$orig_cert_loc" to "$orig_cert_loc.$timestamp
  19. cp $orig_key_loc $orig_key_loc.$timestamp
  20. echo "Saved "$orig_cert_loc" to "$orig_cert_loc.$timestamp
  21. echo "Putting new Keys/certs in place"
  22. cp -f $new_cert_loc $orig_cert_loc
  23. chmod 644 $orig_cert_loc
  24. cp -f $new_key_loc $orig_key_loc
  25. chmod 600 $orig_key_loc
  26. echo Apache keys/cert updated
  27. echo "Do you want to restart Apache (Y/N)"
  28. read reply
  29. answer=$(echo $reply|tr "[:lower:]" "[:upper:]")
  30. if [ $answer = 'Y' ] || [ $answer = 'YES' ]
  31. then systemctl restart httpd
  32. if [ $? <> 0 ]
  33. then echo 'Error restarting Apache please investigate'
  34. #exit
  35. fi
  36. else
  37. exit
  38. fi
  39. echo "Backing up and applying mod_auth_merllon changes"
  40. cp $orig_cert_loc $orig_cert_loc.$timestamp
  41. echo "Saved "$orig_mellon_file1" to "$orig_mellon_file1.$timestamp
  42. cp $orig_mellon_file1 $orig_mellon_file1.$timestamp
  43. echo "Saved "$orig_mellon_file2" to "$orig_mellon_file2.$timestamp
  44. echo "Putting new Keys/certs in place"
  45. cp -f $new_mellon_file1 $orig_mellon_file1
  46. chmod 644 $orig_mellon_file1
  47. cp -f $new_mellon_file2 $orig_mellon_file2
  48. chmod 644 $orig_mellon_file2
  49. echo "mod_auth_merllon files updated"
  50. echo "Do you want to restart Apache (Y/N) (Only do this once Wintel have replaced the cert in Pingfederate)"
  51. read reply
  52. answer=$(echo $reply|tr "[:lower:]" "[:upper:]")
  53. if [ $answer = 'Y' ] || [ $answer = 'YES' ]
  54. then systemctl restart httpd
  55. if [ $? <> 0 ]
  56. then echo 'Error restarting Apache please investigate'
  57. #exit
  58. fi
  59. else
  60. exit
  61. fi