From bf90cbb28effc9f40d8c00255b7037b6f5d624f4 Mon Sep 17 00:00:00 2001 From: pvincent Date: Wed, 9 Oct 2024 08:58:11 +0400 Subject: [PATCH] discourse --- recipes/discourse/crud.sh | 111 +++++++++++++++++++++++++++++++++++ recipes/discourse/install.sh | 35 +++++++++++ scripts/miaou | 4 +- templates/nginx/hosts.j2 | 7 +++ 4 files changed, 155 insertions(+), 2 deletions(-) create mode 100755 recipes/discourse/crud.sh create mode 100755 recipes/discourse/install.sh diff --git a/recipes/discourse/crud.sh b/recipes/discourse/crud.sh new file mode 100755 index 0000000..38ff692 --- /dev/null +++ b/recipes/discourse/crud.sh @@ -0,0 +1,111 @@ +#!/bin/bash + +function _read() { + return 0 +} + +function _create() { + echo "creating discourse-docker instance for <$shortname> ... " + echo "initialize discourse-docker $shortname $longname ... OK" +} + +function _update() { + echo "update" +} + +function _delete() { + echo "delete" +} + +function usage() { + echo "Usage: $COMMAND_NAME -c|r|u|d --port PORT --container CONTAINER --name NAME" + exit 2 +} + +### MAIN + +# init_strict + +COMMAND_NAME=$(basename "$0") + +# read the options + +TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,data: -- "$@") +# shellcheck disable=SC2181 +[[ "$?" -eq 0 ]] || usage +eval set -- "$TEMP" + +action="unset" +port="unset" +container="unset" +shortname="unset" +longname="unset" +fqdn="unset" +data="unset" + +# extract options and their arguments into variables. +while true; do + case "$1" in + --port) + port=$2 + shift 2 + ;; + --fqdn) + fqdn=$2 + shift 2 + ;; + --container) + container=$2 + shift 2 + ;; + --name) + shortname=$2 + longname="cagettepei-$shortname" + shift 2 + ;; + --data) + data=$2 + shift 2 + ;; + -c) + [[ "$action" == "unset" ]] || usage + action="_create" + shift 1 + ;; + -r) + [[ "$action" == "unset" ]] || usage + action="_read" + shift 1 + ;; + -u) + [[ "$action" == "unset" ]] || usage + action="_update" + shift 1 + ;; + -d) + [[ "$action" == "unset" ]] || usage + action="_delete" + shift 1 + ;; + --) + shift + break + ;; + *) + echo "Internal error!" + exit 1 + ;; + esac +done + +[[ + "$action" != unset && + "$port" != unset && + "$container" != unset && + "$fqdn" != unset && + "$data" != unset && + "$shortname" != unset ]] || usage + +. "$MIAOU_BASEDIR/lib/init.sh" + +$action diff --git a/recipes/discourse/install.sh b/recipes/discourse/install.sh new file mode 100755 index 0000000..1278bb5 --- /dev/null +++ b/recipes/discourse/install.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +### CHECK + +function check() { + PREFIX="recipe:discourse:check" + + container_exists "$CONTAINER" || return 1 + container_running "$CONTAINER" || return 2 + + echo "container <$CONTAINER> approved successfully!" +} + +### INSTALL + +function install() { + PREFIX="recipe:discourse:install" + : $PREFIX + + launch_container "$CONTAINER" + echo "initializing discourse ... " + PREFIX="" echo "OK" +} + +### MAIN + +. "$MIAOU_BASEDIR/lib/init.sh" + +arg1_required "$@" +readonly CONTAINER="$1" + +check || ( + install + check +) diff --git a/scripts/miaou b/scripts/miaou index e52d5f7..d397dab 100755 --- a/scripts/miaou +++ b/scripts/miaou @@ -140,7 +140,7 @@ function expand_conf() { index=0 for i in "${services[@]}"; do read -r -a item <<<"$i" - exp=${item[7]} + exp=${item[-1]} # the last item if [[ "$exp" == true ]]; then domain=${item[0]} subdomain=${item[1]} @@ -284,7 +284,7 @@ function monit_show() { else builtin echo -ne "${RED}✘${NC}" fi - printf "\t%10.10s\thttps://%-40s\thttp://%s\n" "$app" "$fqdn" "$container:$port" + printf "\t%16.16s\thttps://%-40s\thttp://%s\n" "$app" "$fqdn" "$container:$port" done } diff --git a/templates/nginx/hosts.j2 b/templates/nginx/hosts.j2 index f3eff54..7aba829 100644 --- a/templates/nginx/hosts.j2 +++ b/templates/nginx/hosts.j2 @@ -22,8 +22,15 @@ server { proxy_set_header Host $http_host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; + + {%- if services[service.domain][service.subdomain]['data']['nginx']['extra'] %} + + # From ... data.nginx.extra + {{ services[service.domain][service.subdomain]['data']['nginx']['extra'] }} + {%- endif %} {%- if target != 'prod' %} + include snippets/banner_{{ target }}.conf; {%- endif %} }