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.

60 lines
1.7 KiB

  1. #!/usr/bin/env bash
  2. linode_cmd="/usr/bin/linode"
  3. ######## Public functions #####################
  4. #Usage: dns_linode_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  5. dns_linode_add() {
  6. fulldomain="${1}"
  7. txtvalue="${2}"
  8. _info "Using Linode"
  9. _debug "Calling: dns_linode_add() '${fulldomain}' '${txtvalue}'"
  10. domain=$(printf "%s" "${fulldomain}" | cut -d . -f 3-999)
  11. name=$(printf "%s" "${fulldomain}" | cut -d . -f 1-2)
  12. _debug name "${name}"
  13. _debug domain "${domain}"
  14. _Linode_CLI && _Linode_addTXT
  15. }
  16. #Usage: dns_linode_rm _acme-challenge.www.domain.com
  17. dns_linode_rm() {
  18. fulldomain="${1}"
  19. _info "Using Linode"
  20. _debug "Calling: dns_linode_rm() '${fulldomain}'"
  21. domain=$(printf "%s" "${fulldomain}" | cut -d . -f 3-999)
  22. name=$(printf "%s" "${fulldomain}" | cut -d . -f 1-2)
  23. _debug name "${name}"
  24. _debug domain "${domain}"
  25. _Linode_CLI && _Linode_rmTXT
  26. }
  27. #################### Private functions below ##################################
  28. _Linode_CLI() {
  29. if [ ! -f "${linode_cmd}" ]; then
  30. _err "Please install the Linode CLI package and set it up accordingly before using this DNS API."
  31. return 1
  32. fi
  33. }
  34. _Linode_addTXT() {
  35. _debug "$linode_cmd domain record-update ${domain} TXT ${name} --target ${txtvalue}"
  36. $linode_cmd domain record-update ${domain} TXT ${name} --target ${txtvalue}
  37. if [ $? -ne 0 ]; then
  38. _debug "$linode_cmd domain record-create ${domain} TXT ${name} ${txtvalue}"
  39. $linode_cmd domain record-create ${domain} TXT ${name} ${txtvalue}
  40. fi
  41. }
  42. _Linode_rmTXT() {
  43. _debug "$linode_cmd domain record-delete ${domain} TXT ${name}"
  44. $linode_cmd domain record-delete ${domain} TXT ${name}
  45. }