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.

218 lines
3.3 KiB

  1. #!/bin/bash
  2. exname=$(basename $0)
  3. prefix_cmd="
  4. . /etc/shlib
  5. include common
  6. include parse
  7. . ../lib/common
  8. get_dc_env() {
  9. local i
  10. echo \"Calling get_dc_env\" >&2
  11. ((i=0))
  12. for arg in \"\$@\"; do
  13. echo \" arg\$((i++)):\"
  14. echo \"\$arg\" | prefix \" | \"
  15. done >&2
  16. echo \"\$GET_DC_ENV\"
  17. }
  18. export -f get_dc_env
  19. will_need_http_access() {
  20. local i
  21. echo \"Calling will_need_http_access\" >&2
  22. ((i=0))
  23. for arg in \"\$@\"; do
  24. echo \" arg\$((i++)):\"
  25. echo \"\$arg\" | prefix \" | \"
  26. done >&2
  27. [ \"\$WILL_NEED_HTTP_ACCESS\" == 'yes' ]
  28. }
  29. export -f will_need_http_access
  30. "
  31. ##
  32. ## Mocks
  33. ##
  34. cfg-get-value() {
  35. local key="$1"
  36. shyaml get-value "$key" 2>/dev/null
  37. }
  38. export -f cfg-get-value
  39. file_put() {
  40. echo "file_put $1"
  41. cat - | prefix " | "
  42. }
  43. export -f file_put
  44. docker() {
  45. local i
  46. echo "Calling: docker" >&2
  47. ((i=0))
  48. for arg in "$@"; do
  49. echo " arg$((i++)):"
  50. echo "$arg" | prefix " | "
  51. done >&2
  52. if [ "$1" == "ps" ]; then
  53. echo "$DOCKER_PS"
  54. fi
  55. }
  56. export -f docker
  57. yaml_key_val_str() {
  58. printf "%s:\n%s" "$1" "$(echo "$2" | prefix " ")"
  59. }
  60. export -f yaml_key_val_str
  61. compose() {
  62. local i
  63. echo "Calling: compose" >&2
  64. ((i=0))
  65. for arg in "$@"; do
  66. echo " arg$((i++)):"
  67. echo "$arg" | prefix " | "
  68. done >&2
  69. }
  70. export -f compose
  71. try "
  72. SERVICE_NAME='\$SERVICE_NAME'
  73. WILL_NEED_HTTP_ACCESS=
  74. crt '' create www.example.com
  75. "
  76. is err reg 'Calling get_dc_env
  77. arg0:
  78. |
  79. arg1:
  80. | create
  81. arg2:
  82. | www.example.com
  83. Calling will_need_http_access
  84. arg0:
  85. |
  86. arg1:
  87. | create
  88. arg2:
  89. | www.example.com
  90. Calling: compose
  91. .*
  92. | run
  93. .*
  94. | letsencrypt
  95. .*
  96. | crt
  97. .*
  98. | create
  99. .*
  100. | www.example.com' RTRIM
  101. is errlvl 0
  102. is out ''
  103. try "
  104. SERVICE_NAME='\$SERVICE_NAME'
  105. GET_DC_ENV='
  106. \$SERVICE_NAME:
  107. environment:
  108. LETSENCRYPT_USER_MAIL: foo@example.com
  109. LEXICON_OVH_FOO: 1
  110. LEXICON_PROVIDER: wiz
  111. '
  112. WILL_NEED_HTTP_ACCESS=
  113. crt '' create www.example.com
  114. "
  115. is err reg 'Calling: compose
  116. .*
  117. | --add-compose-content
  118. .*
  119. | docker-compose:
  120. | $SERVICE_NAME:
  121. | environment:
  122. | LETSENCRYPT_USER_MAIL: foo@example.com
  123. | LEXICON_OVH_FOO: 1
  124. | LEXICON_PROVIDER: wiz
  125. .*
  126. | run
  127. .*
  128. | letsencrypt
  129. .*
  130. | crt
  131. .*
  132. | create
  133. .*
  134. | www.example.com' RTRIM
  135. is errlvl 0
  136. try "
  137. SERVICE_NAME='\$SERVICE_NAME'
  138. GET_DC_ENV='
  139. \$SERVICE_NAME:
  140. environment:
  141. LETSENCRYPT_USER_MAIL: foo@example.com
  142. LEXICON_OVH_FOO: 1
  143. LEXICON_PROVIDER: wiz
  144. '
  145. WILL_NEED_HTTP_ACCESS=yes
  146. DOCKER_PS=
  147. crt '' create www.example.com
  148. " "need http acces, no docker on port 80"
  149. is err part 'Calling: docker
  150. arg0:
  151. | ps' RTRIM
  152. is errlvl 0
  153. is out ''
  154. try "
  155. GET_DC_ENV='
  156. \$SERVICE_NAME:
  157. environment:
  158. LETSENCRYPT_USER_MAIL: foo@example.com
  159. LEXICON_OVH_FOO: 1
  160. LEXICON_PROVIDER: wiz
  161. '
  162. WILL_NEED_HTTP_ACCESS=yes
  163. DOCKER_PS='
  164. docker_1
  165. docker_2
  166. '
  167. crt '' create www.example.com
  168. " "need http acces, 2 dockers on port 80"
  169. is err reg 'II Attempting to clear port 80 by stopping docker_1
  170. Calling: docker
  171. arg0:
  172. . stop
  173. .*
  174. . docker_1
  175. II Attempting to clear port 80 by stopping docker_2
  176. Calling: docker
  177. arg0:
  178. . stop
  179. .*
  180. . docker_2
  181. Calling: compose
  182. .*
  183. II Attempting restart docker_1
  184. Calling: docker
  185. arg0:
  186. . start
  187. .*
  188. . docker_1
  189. II Attempting restart docker_2
  190. Calling: docker
  191. arg0:
  192. . start
  193. .*
  194. . docker_2' RTRIM
  195. is errlvl 0
  196. is out ''