You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.4 KiB

  1. #!/usr/bin/env sh
  2. #Here is a sample custom api script.
  3. #This file name is "stunnel.sh"
  4. #So, here must be a method stunnel_deploy()
  5. #Which will be called by acme.sh to deploy the cert
  6. #returns 0 means success, otherwise error.
  7. ######## Public functions #####################
  8. #domain keyfile certfile cafile fullchain
  9. stunnel_deploy() {
  10. _cdomain="$1"
  11. _ckey="$2"
  12. _ccert="$3"
  13. _cca="$4"
  14. _cfullchain="$5"
  15. _debug _cdomain "$_cdomain"
  16. _debug _ckey "$_ckey"
  17. _debug _ccert "$_ccert"
  18. _debug _cca "$_cca"
  19. _debug _cfullchain "$_cfullchain"
  20. ST_DIR="/etc/stunnel"
  21. _debug STUNNEL "$ST_DIR"
  22. _debug STUNNEL_CRT "$ST_DIR/stunnel.crt"
  23. _debug STUNNEL_KEY "$ST_DIR/stunnel.key"
  24. if [ ! -d "$ST_DIR" ]
  25. then
  26. _info "Creating the stunnel directory..."
  27. mkdir -p "$ST_DIR" || return 1
  28. fi
  29. if [ ! -f "$ST_DIR/stunnel.dh" ]
  30. then
  31. _info "Generating the Diffie-Hellman key..."
  32. openssl gendh 2048 > "$ST_DIR/stunnel.dh"
  33. fi
  34. _info "Saving the certificate..."
  35. cat "$_cfullchain" "$ST_DIR/stunnel.dh" > "$ST_DIR/stunnel.crt"
  36. if [ ! -f "$ST_DIR/stunnel.key" ]
  37. then
  38. _info "Saving the key..."
  39. cat "$_ckey" > "$ST_DIR/stunnel.key"
  40. fi
  41. _info "Setting file permissions..."
  42. chmod 600 "$ST_DIR/stunnel.crt" "$ST_DIR/stunnel.key" "$ST_DIR/stunnel.dh"
  43. chown nobody:root "$ST_DIR/stunnel.crt" "$ST_DIR/stunnel.key" "$ST_DIR/stunnel.dh"
  44. return 0
  45. }