provisioning tool for building opinionated architecture
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.

138 lines
2.8 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. #!/bin/bash
  2. function check_service_running() {
  3. lxc exec "$container" -- bash -c "docker ps --format {{.Names}} | grep $1"
  4. }
  5. function _read() {
  6. disable_trace
  7. check_db_postgres_exists "$longname"
  8. check_container "$container"
  9. check_service_running "$shortname"
  10. enable_trace
  11. return 0
  12. }
  13. function _create() {
  14. echo "creating discourse instance for <$shortname> ... "
  15. echo "initialize discourse $shortname $longname ... OK"
  16. mkdir -p "$MIAOU_CONFIGDIR/apps/discourse"
  17. APP_DOMAIN=$domain APP_SUBDOMAIN=$subdomain APP_FQDN=$fqdn APP_PORT=$port APP_NAME=$longname tera -e --env-key env -t "$MIAOU_BASEDIR/templates/apps/discourse/forum.yml.j2" -o "$MIAOU_CONFIGDIR/apps/discourse/$longname.yml" "$MIAOU_CONFIGDIR/miaou.expanded.yaml"
  18. echo "creating templates ... OK"
  19. #TODO:
  20. 1. copy template to container
  21. 1. rebuild container
  22. }
  23. function _update() {
  24. echo "update"
  25. }
  26. function _delete() {
  27. echo "delete"
  28. }
  29. function usage() {
  30. echo "Usage: $COMMAND_NAME -c|r|u|d --port PORT --container CONTAINER --name NAME"
  31. exit 2
  32. }
  33. ### MAIN
  34. # init_strict
  35. source "$(dirname "$0")/../base/common.sh"
  36. COMMAND_NAME=$(basename "$0")
  37. # read the options
  38. TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,domain:,subdomain:,data: -- "$@")
  39. # shellcheck disable=SC2181
  40. [[ "$?" -eq 0 ]] || usage
  41. eval set -- "$TEMP"
  42. action="unset"
  43. port="unset"
  44. container="unset"
  45. shortname="unset"
  46. longname="unset"
  47. fqdn="unset"
  48. domain="unset"
  49. subdomain="unset"
  50. # extract options and their arguments into variables.
  51. while true; do
  52. case "$1" in
  53. --port)
  54. port=$2
  55. shift 2
  56. ;;
  57. --fqdn)
  58. fqdn=$2
  59. shift 2
  60. ;;
  61. --container)
  62. container=$2
  63. shift 2
  64. ;;
  65. --name)
  66. shortname=$2
  67. longname="discourse-$shortname"
  68. shift 2
  69. ;;
  70. --domain)
  71. domain=$2
  72. shift 2
  73. ;;
  74. --subdomain)
  75. subdomain=$2
  76. shift 2
  77. ;;
  78. --data)
  79. # don't care
  80. shift 2
  81. ;;
  82. -c)
  83. [[ "$action" == "unset" ]] || usage
  84. action="_create"
  85. shift 1
  86. ;;
  87. -r)
  88. [[ "$action" == "unset" ]] || usage
  89. action="_read"
  90. shift 1
  91. ;;
  92. -u)
  93. [[ "$action" == "unset" ]] || usage
  94. action="_update"
  95. shift 1
  96. ;;
  97. -d)
  98. [[ "$action" == "unset" ]] || usage
  99. action="_delete"
  100. shift 1
  101. ;;
  102. --)
  103. shift
  104. break
  105. ;;
  106. *)
  107. echoerr "Internal error: unrecognized option: <$1>"
  108. exit 1
  109. ;;
  110. esac
  111. done
  112. [[
  113. "$action" != unset &&
  114. "$port" != unset &&
  115. "$container" != unset &&
  116. "$fqdn" != unset &&
  117. "$domain" != unset &&
  118. "$subdomain" != unset &&
  119. "$shortname" != unset ]] || usage
  120. . "$MIAOU_BASEDIR/lib/init.sh"
  121. $action