autocertbot.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. # script convert end make ssl sert for https
  3. # info - script auto update cert for sites
  4. # version 1.10.1
  5. # author Koshuba V.O.- 2021
  6. # master@qbpro.ru
  7. #
  8. path_certbot="/etc/letsencrypt/live";
  9. path_ssl="/etc/ssl/private";
  10. source certbot.conf;
  11. log="/var/log/syslog";
  12. #
  13. cmd=$1;
  14. #
  15. ## if keys update certbot - recreate keys for sites
  16. function makekeys() {
  17. valtrue=0;
  18. rdate=$(date +%Y-%m-%d);
  19. rtime=$(date +%H:%M);
  20. for ((dmn=0; dmn != ${#domains[@]}; dmn++))
  21. do
  22. keydate=$(ls -l --time-style=long-iso $path_certbot/${domains[$dmn]}/cert.pem |awk {'print$6'});
  23. keytime=$(ls -l --time-style=long-iso $path_certbot/${domains[$dmn]}/cert.pem |awk {'print$7'});
  24. if [ "$keydate" = "$rdate" ] && [ "$keytime" = "$rtime" ];
  25. then
  26. ((valtrue++));
  27. cat $path_certbot/${domains[$dmn]}/cert.pem > $path_ssl/${domains[$dmn]}.pem;
  28. cat $path_certbot/${domains[$dmn]}/chain.pem >> $path_ssl/${domains[$dmn]}.pem;
  29. cat $path_certbot/${domains[$dmn]}/fullchain.pem >> $path_ssl/${domains[$dmn]}.pem;
  30. cat $path_certbot/${domains[$dmn]}/privkey.pem >> $path_ssl/${domains[$dmn]}.pem;
  31. echo "$rdate - $rtime - autocertbot: recreate cert for ${domains[$dmn]}">> $log;
  32. fi
  33. done
  34. if [ $valtrue != 0 ];
  35. then
  36. :>/etc/ssl/crt-list.txt
  37. for ((icrt=0; icrt != ${#domains[@]}; icrt++))
  38. do
  39. echo "$path_ssl/${domains[$icrt]}.pem">>/etc/ssl/crt-list.txt
  40. done
  41. fi
  42. }
  43. function renew() {
  44. /etc/init.d/haproxy stop;
  45. certbot renew;
  46. makekeys;
  47. /etc/init.d/haproxy start;
  48. }
  49. function createCert() {
  50. certbot register --agree-tos -m $adminmail;
  51. /etc/init.d/haproxy stop;
  52. for ((dmn=0; dmn != ${#domains[@]}; dmn++))
  53. do
  54. certbot certonly --preferred-challenges http --standalone -d ${domains[$dmn]};
  55. done
  56. /etc/init.d/haproxy start;
  57. }
  58. case "$cmd" in
  59. ## create cert
  60. "--create" | "--create" )
  61. createCert;
  62. ;;
  63. ## update cert
  64. "--update" | "--update" )
  65. renew;
  66. ;;
  67. ## start defaults
  68. * )
  69. echo "please input pameters: autocertbot.sh --create | --update";
  70. echo "autocertbot.sh --create; create new certificate"
  71. echo "autocertbot.sh --update; update certificates;"
  72. ;;
  73. esac