executable_godaddy 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #!/usr/bin/env bash
  2. set -e
  3. set -o pipefail
  4. GODADDY_KEY="${GODADDY_KEY:-$(pass show godaddy.com/api/key)}"
  5. GODADDY_SECRET="${GODADDY_SECRET:-$(pass show godaddy.com/api/secret)}"
  6. GODADDY_COMMAND="${GODADDY_COMMAND:-lexicon godaddy}"
  7. help_main()
  8. {
  9. echo "\
  10. Usage: godaddy COMMANDS ARGS...
  11. Run COMMANDS with ARGS
  12. COMMAND must be one of the sub-commands listed below:
  13. add
  14. list
  15. Report bugs to: go.wigust@gmail.com."
  16. }
  17. help_add()
  18. {
  19. echo "\
  20. Usage: godaddy add COMMANDS ARGS...
  21. Run COMMANDS with ARGS
  22. COMMAND must be one of the sub-commands listed below:
  23. a
  24. cname godaddy add cname githunt guix.duckdns.org
  25. mx
  26. Report bugs to: go.wigust@gmail.com."
  27. }
  28. help_add_a()
  29. {
  30. echo "\
  31. Usage: godaddy add a subdomain.example.com 1.2.3.4
  32. Run COMMANDS with ARGS
  33. Report bugs to: go.wigust@gmail.com."
  34. }
  35. help_add_cname()
  36. {
  37. echo "\
  38. Usage: godaddy add cname subdomain.example.com target.domain.com
  39. Run COMMANDS with ARGS
  40. Report bugs to: go.wigust@gmail.com."
  41. }
  42. help_add_mx()
  43. {
  44. echo "\
  45. Usage: godaddy add mx vm12345 vm12345.wugi.info 10
  46. or: godaddy add mx vm12345
  47. Run COMMANDS with ARGS
  48. Report bugs to: go.wigust@gmail.com."
  49. }
  50. help_delete()
  51. {
  52. echo "\
  53. Usage: godaddy delete COMMANDS ARGS...
  54. Run COMMANDS with ARGS
  55. COMMAND must be one of the sub-commands listed below:
  56. a
  57. cname godaddy delete cname githunt guix.duckdns.org
  58. Report bugs to: go.wigust@gmail.com."
  59. }
  60. help_delete_a()
  61. {
  62. echo "\
  63. Usage: godaddy delete a subdomain.example.com 1.2.3.4
  64. Run COMMANDS with ARGS
  65. Report bugs to: go.wigust@gmail.com."
  66. }
  67. help_delete_cname()
  68. {
  69. echo "\
  70. Usage: godaddy delete cname subdomain.example.com target.domain.com
  71. Run COMMANDS with ARGS
  72. Report bugs to: go.wigust@gmail.com."
  73. }
  74. help_list()
  75. {
  76. echo "\
  77. Usage: godaddy list COMMANDS ARGS...
  78. Run COMMANDS with ARGS
  79. COMMAND must be one of the sub-commands listed below:
  80. a
  81. cname
  82. mx
  83. ns
  84. Report bugs to: go.wigust@gmail.com."
  85. }
  86. case "$1" in
  87. --help)
  88. help_main
  89. ;;
  90. add)
  91. case "$2" in
  92. --help)
  93. help_add
  94. ;;
  95. a)
  96. if [[ -z "$3" ]]
  97. then
  98. help_add_a
  99. exit 1
  100. fi
  101. $GODADDY_COMMAND create --auth-key "$GODADDY_KEY" --auth-secret "$GODADDY_SECRET" "$GODADDY_DOMAIN_NAME" A --name "$3" --content "$4"
  102. ;;
  103. cname)
  104. if [[ -z "$3" ]]
  105. then
  106. help_add_cname
  107. exit 1
  108. fi
  109. $GODADDY_COMMAND create --auth-key "$GODADDY_KEY" --auth-secret "$GODADDY_SECRET" "$GODADDY_DOMAIN_NAME" CNAME --name "$3" --content "$4"
  110. ;;
  111. mx)
  112. if [[ -z "$3" ]]
  113. then
  114. help_add_mx
  115. exit 1
  116. fi
  117. $GODADDY_COMMAND create --auth-key "$GODADDY_KEY" --auth-secret "$GODADDY_SECRET" "$GODADDY_DOMAIN_NAME" MX --name "$3" --content "${4:-$3.wugi.info}" --priority "${5:-10}"
  118. ;;
  119. *)
  120. help_add
  121. ;;
  122. esac
  123. ;;
  124. delete)
  125. case "$2" in
  126. --help)
  127. help_delete
  128. ;;
  129. a)
  130. if [[ -z "$3" ]]
  131. then
  132. help_delete_a
  133. exit 1
  134. fi
  135. $GODADDY_COMMAND delete --auth-key "$GODADDY_KEY" --auth-secret "$GODADDY_SECRET" "$GODADDY_DOMAIN_NAME" A --name "$3" --content "$4"
  136. ;;
  137. cname)
  138. if [[ -z "$3" ]]
  139. then
  140. help_delete_cname
  141. exit 1
  142. fi
  143. $GODADDY_COMMAND delete --auth-key "$GODADDY_KEY" --auth-secret "$GODADDY_SECRET" "$GODADDY_DOMAIN_NAME" CNAME --name "$3" --content "$4"
  144. ;;
  145. *)
  146. help_delete
  147. ;;
  148. esac
  149. ;;
  150. list)
  151. case "$2" in
  152. --help)
  153. help_list
  154. ;;
  155. a)
  156. $GODADDY_COMMAND list --auth-key "$GODADDY_KEY" --auth-secret "$GODADDY_SECRET" "$GODADDY_DOMAIN_NAME" A "${@:3}"
  157. ;;
  158. cname)
  159. $GODADDY_COMMAND list --auth-key "$GODADDY_KEY" --auth-secret "$GODADDY_SECRET" "$GODADDY_DOMAIN_NAME" CNAME "${@:3}"
  160. ;;
  161. ns)
  162. $GODADDY_COMMAND list --auth-key "$GODADDY_KEY" --auth-secret "$GODADDY_SECRET" "$GODADDY_DOMAIN_NAME" NS "${@:3}"
  163. ;;
  164. mx)
  165. $GODADDY_COMMAND list --auth-key "$GODADDY_KEY" --auth-secret "$GODADDY_SECRET" "$GODADDY_DOMAIN_NAME" MX "${@:3}"
  166. ;;
  167. *)
  168. help_list
  169. ;;
  170. esac
  171. ;;
  172. *)
  173. help_main
  174. ;;
  175. esac