Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

init-letsencrypt.sh 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash
  2. if ! [ -x "$(command -v docker-compose)" ]; then
  3. echo 'Error: docker-compose is not installed.' >&2
  4. exit 1
  5. fi
  6. URL_HOST=$(grep URL_HOST .env | cut -d '=' -f2)
  7. echo $URL_HOST
  8. domains=($URL_HOST)
  9. rsa_key_size=4096
  10. data_path="./data/certbot"
  11. email="$LETSENCRYPT_EMAIL" # Adding a valid address is strongly recommended
  12. staging=${LETSENCRYPT_STAGING:-0} # Set to 1 if you're testing your setup to avoid hitting request limits
  13. if [ -d "$data_path" ]; then
  14. read -p "Existing data found for $domains. Continue and replace existing certificate? (y/N) " decision
  15. if [ "$decision" != "Y" ] && [ "$decision" != "y" ]; then
  16. exit
  17. fi
  18. fi
  19. if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ssl-dhparams.pem" ]; then
  20. echo "### Downloading recommended TLS parameters ..."
  21. mkdir -p "$data_path/conf"
  22. curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf > "$data_path/conf/options-ssl-nginx.conf"
  23. curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem > "$data_path/conf/ssl-dhparams.pem"
  24. echo
  25. fi
  26. echo "### Creating dummy certificate for $domains ..."
  27. path="/etc/letsencrypt/live/$domains"
  28. mkdir -p "$data_path/conf/live/$domains"
  29. docker-compose run --rm --entrypoint "\
  30. openssl req -x509 -nodes -newkey rsa:1024 -days 1\
  31. -keyout '$path/privkey.pem' \
  32. -out '$path/fullchain.pem' \
  33. -subj '/CN=localhost'" certbot
  34. echo
  35. echo "### Starting scalelite-nginx ..."
  36. docker-compose up --force-recreate -d scalelite-nginx
  37. echo
  38. echo "### Deleting dummy certificate for $domains ..."
  39. docker-compose run --rm --entrypoint "\
  40. rm -Rf /etc/letsencrypt/live/$domains && \
  41. rm -Rf /etc/letsencrypt/archive/$domains && \
  42. rm -Rf /etc/letsencrypt/renewal/$domains.conf" certbot
  43. echo
  44. echo "### Requesting Let's Encrypt certificate for $domains ..."
  45. #Join $domains to -d args
  46. domain_args=""
  47. for domain in "${domains[@]}"; do
  48. domain_args="$domain_args -d $domain"
  49. done
  50. # Select appropriate email arg
  51. case "$email" in
  52. "") email_arg="--register-unsafely-without-email" ;;
  53. *) email_arg="--email $email" ;;
  54. esac
  55. # Enable staging mode if needed
  56. if [ $staging != "0" ]; then staging_arg="--staging"; fi
  57. docker-compose run --rm --entrypoint "\
  58. certbot certonly --webroot -w /var/www/certbot \
  59. $staging_arg \
  60. $email_arg \
  61. $domain_args \
  62. --rsa-key-size $rsa_key_size \
  63. --agree-tos \
  64. --debug-challenges \
  65. --force-renewal" certbot
  66. echo
  67. echo "### Reloading scalelite-nginx ..."
  68. docker-compose exec scalelite-nginx nginx -s reload