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.

59 lines
1.4 KiB

  1. #!/usr/bin/env sh
  2. # MyDevil.net API (2019-02-03)
  3. #
  4. # MyDevil.net already supports automatic Let's Encrypt certificates,
  5. # except for wildcard domains.
  6. #
  7. # This script depends on `devil` command that MyDevil.net provides,
  8. # which means that it works only on server side.
  9. #
  10. # Author: Marcin Konicki <https://ahwayakchih.neoni.net>
  11. #
  12. ######## Public functions #####################
  13. # Usage: mydevil_deploy domain keyfile certfile cafile fullchain
  14. mydevil_deploy() {
  15. _cdomain="$1"
  16. _ckey="$2"
  17. _ccert="$3"
  18. _cca="$4"
  19. _cfullchain="$5"
  20. ip=""
  21. _debug _cdomain "$_cdomain"
  22. _debug _ckey "$_ckey"
  23. _debug _ccert "$_ccert"
  24. _debug _cca "$_cca"
  25. _debug _cfullchain "$_cfullchain"
  26. if ! _exists "devil"; then
  27. _err "Could not find 'devil' command."
  28. return 1
  29. fi
  30. ip=$(mydevil_get_ip "$_cdomain")
  31. if [ -z "$ip" ]; then
  32. _err "Could not find IP for domain $_cdomain."
  33. return 1
  34. fi
  35. # Delete old certificate first
  36. _info "Removing old certificate for $_cdomain at $ip"
  37. devil ssl www del "$ip" "$_cdomain"
  38. # Add new certificate
  39. _info "Adding new certificate for $_cdomain at $ip"
  40. devil ssl www add "$ip" "$_cfullchain" "$_ckey" "$_cdomain" || return 1
  41. return 0
  42. }
  43. #################### Private functions below ##################################
  44. # Usage: ip=$(mydevil_get_ip domain.com)
  45. # echo $ip
  46. mydevil_get_ip() {
  47. devil dns list "$1" | cut -w -s -f 3,7 | grep "^A$(printf '\t')" | cut -w -s -f 2 || return 1
  48. return 0
  49. }