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.

135 lines
2.7 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=$shortname 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. }
  20. function _update() {
  21. echo "update"
  22. }
  23. function _delete() {
  24. echo "delete"
  25. }
  26. function usage() {
  27. echo "Usage: $COMMAND_NAME -c|r|u|d --port PORT --container CONTAINER --name NAME"
  28. exit 2
  29. }
  30. ### MAIN
  31. # init_strict
  32. source "$(dirname "$0")/../base/common.sh"
  33. COMMAND_NAME=$(basename "$0")
  34. # read the options
  35. TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,domain:,subdomain:,data: -- "$@")
  36. # shellcheck disable=SC2181
  37. [[ "$?" -eq 0 ]] || usage
  38. eval set -- "$TEMP"
  39. action="unset"
  40. port="unset"
  41. container="unset"
  42. shortname="unset"
  43. longname="unset"
  44. fqdn="unset"
  45. domain="unset"
  46. subdomain="unset"
  47. # extract options and their arguments into variables.
  48. while true; do
  49. case "$1" in
  50. --port)
  51. port=$2
  52. shift 2
  53. ;;
  54. --fqdn)
  55. fqdn=$2
  56. shift 2
  57. ;;
  58. --container)
  59. container=$2
  60. shift 2
  61. ;;
  62. --name)
  63. shortname=$2
  64. longname="discourse-$shortname"
  65. shift 2
  66. ;;
  67. --domain)
  68. domain=$2
  69. shift 2
  70. ;;
  71. --subdomain)
  72. subdomain=$2
  73. shift 2
  74. ;;
  75. --data)
  76. # don't care
  77. shift 2
  78. ;;
  79. -c)
  80. [[ "$action" == "unset" ]] || usage
  81. action="_create"
  82. shift 1
  83. ;;
  84. -r)
  85. [[ "$action" == "unset" ]] || usage
  86. action="_read"
  87. shift 1
  88. ;;
  89. -u)
  90. [[ "$action" == "unset" ]] || usage
  91. action="_update"
  92. shift 1
  93. ;;
  94. -d)
  95. [[ "$action" == "unset" ]] || usage
  96. action="_delete"
  97. shift 1
  98. ;;
  99. --)
  100. shift
  101. break
  102. ;;
  103. *)
  104. echoerr "Internal error: unrecognized option: <$1>"
  105. exit 1
  106. ;;
  107. esac
  108. done
  109. [[
  110. "$action" != unset &&
  111. "$port" != unset &&
  112. "$container" != unset &&
  113. "$fqdn" != unset &&
  114. "$domain" != unset &&
  115. "$subdomain" != unset &&
  116. "$shortname" != unset ]] || usage
  117. . "$MIAOU_BASEDIR/lib/init.sh"
  118. $action