domain + subdomain

This commit is contained in:
pvincent
2024-10-09 11:38:59 +04:00
parent 5ac2e4842d
commit ac7268731a
10 changed files with 179 additions and 28 deletions
+22
View File
@@ -0,0 +1,22 @@
#!/bin/bash
function check_db_maria_exists() {
db-maria list | grep -q "$1"
}
function check_db_postgres_exists() {
db-psql list | grep -q "$1"
}
function extract_domain_from_fqdn() {
fqdn=$1
part1=$(builtin echo "$fqdn" | rev | cut -d'.' -f1 | rev)
part2=$(builtin echo "${fqdn%."$part1"}" | rev | cut -d'.' -f1 | rev)
builtin echo "$part2.$part1"
}
function extract_subdomain_from_fqdn() {
fqdn=$1
domain=$(extract_domain_from_fqdn "$fqdn")
builtin echo "${fqdn%."$domain"}"
}
+10 -7
View File
@@ -1,9 +1,5 @@
#!/bin/bash
function check_database_exists() {
db-maria list | grep -q "$longname"
}
function check_port_used() {
# shellcheck disable=SC2034
usedport=$(lxc exec "$container" -- bash -c "grep Listen /etc/apache2/sites-enabled/$longname.conf | cut -d' ' -f2")
@@ -21,7 +17,7 @@ function check_config_defined() {
function _read() {
disable_trace
check_database_exists
check_db_maria_exists "$longname"
check_container "$container"
check_port_used
check_config_defined
@@ -139,11 +135,12 @@ function usage() {
# init_strict
source "$(dirname "$0")/../base/common.sh"
COMMAND_NAME=$(basename "$0")
# read the options
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn: -- "$@")
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,domain:,subdomain: -- "$@")
# shellcheck disable=SC2181
[[ "$?" -eq 0 ]] || usage
eval set -- "$TEMP"
@@ -175,6 +172,12 @@ while true; do
longname="cagettepei-$shortname"
shift 2
;;
--domain)
shift 2
;;
--subdomain)
shift 2
;;
-c)
[[ "$action" == "unset" ]] || usage
action="_create"
@@ -200,7 +203,7 @@ while true; do
break
;;
*)
echo "Internal error!"
echo "Internal error: unrecognized option: <$1>"
exit 1
;;
esac
+33 -9
View File
@@ -1,12 +1,26 @@
#!/bin/bash
function check_service_running() {
lxc exec "$container" -- bash -c "docker ps --format {{.Names}} | grep $1"
}
function _read() {
disable_trace
check_db_postgres_exists "$longname"
check_container "$container"
check_service_running "$shortname"
enable_trace
return 0
}
function _create() {
echo "creating discourse-docker instance for <$shortname> ... "
echo "initialize discourse-docker $shortname $longname ... OK"
echo "creating discourse instance for <$shortname> ... "
echo "initialize discourse $shortname $longname ... OK"
mkdir -p "$MIAOU_CONFIGDIR/apps/discourse"
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"
echo "creating templates ... OK"
}
function _update() {
@@ -25,12 +39,12 @@ function usage() {
### MAIN
# init_strict
source "$(dirname "$0")/../base/common.sh"
COMMAND_NAME=$(basename "$0")
# read the options
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,data: -- "$@")
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,domain:,subdomain:,data: -- "$@")
# shellcheck disable=SC2181
[[ "$?" -eq 0 ]] || usage
eval set -- "$TEMP"
@@ -41,7 +55,8 @@ container="unset"
shortname="unset"
longname="unset"
fqdn="unset"
data="unset"
domain="unset"
subdomain="unset"
# extract options and their arguments into variables.
while true; do
@@ -60,11 +75,19 @@ while true; do
;;
--name)
shortname=$2
longname="cagettepei-$shortname"
longname="discourse-$shortname"
shift 2
;;
--domain)
domain=$2
shift 2
;;
--subdomain)
subdomain=$2
shift 2
;;
--data)
data=$2
# don't care
shift 2
;;
-c)
@@ -92,7 +115,7 @@ while true; do
break
;;
*)
echo "Internal error!"
echoerr "Internal error: unrecognized option: <$1>"
exit 1
;;
esac
@@ -103,7 +126,8 @@ done
"$port" != unset &&
"$container" != unset &&
"$fqdn" != unset &&
"$data" != unset &&
"$domain" != unset &&
"$subdomain" != unset &&
"$shortname" != unset ]] || usage
. "$MIAOU_BASEDIR/lib/init.sh"
+8 -2
View File
@@ -108,7 +108,7 @@ COMMAND_NAME=$(basename "$0")
# read the options
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn: -- "$@")
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,domain:,subdomain: -- "$@")
# shellcheck disable=SC2181
[[ "$?" -eq 0 ]] || usage
eval set -- "$TEMP"
@@ -138,6 +138,12 @@ while true; do
longname="dolibarr-$shortname"
shift 2
;;
--domain)
shift 2
;;
--subdomain)
shift 2
;;
-c)
[[ "$action" == "unset" ]] || usage
action="_create"
@@ -163,7 +169,7 @@ while true; do
break
;;
*)
echo "Internal error!"
echo "Internal error: unrecognized option: <$1>"
exit 1
;;
esac
+8 -2
View File
@@ -111,7 +111,7 @@ COMMAND_NAME=$(basename "$0")
# read the options
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,data: -- "$@")
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,domain:,subdomain:,data: -- "$@")
# shellcheck disable=SC2181
[[ "$?" -eq 0 ]] || usage
eval set -- "$TEMP"
@@ -144,6 +144,12 @@ while true; do
longname="odoo12-$shortname"
shift 2
;;
--domain)
shift 2
;;
--subdomain)
shift 2
;;
--data)
data=$2
shift 2
@@ -173,7 +179,7 @@ while true; do
break
;;
*)
echoerr "Internal error!"
echoerr "Internal error: unrecognized option: <$1>"
exit 1
;;
esac
+8 -2
View File
@@ -127,7 +127,7 @@ COMMAND_NAME=$(basename "$0")
# read the options
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,data: -- "$@")
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,domain:,subdomain:,data: -- "$@")
# shellcheck disable=SC2181
[[ "$?" -eq 0 ]] || usage
eval set -- "$TEMP"
@@ -164,6 +164,12 @@ while true; do
data=$2
shift 2
;;
--domain)
shift 2
;;
--subdomain)
shift 2
;;
-c)
[[ "$action" == "unset" ]] || usage
action="_create"
@@ -189,7 +195,7 @@ while true; do
break
;;
*)
echoerr "Internal error!"
echoerr "Internal error: unrecognized option: <$1>"
exit 1
;;
esac
+3 -3
View File
@@ -30,7 +30,7 @@ COMMAND_NAME=$(basename "$0")
# read the options
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn: -- "$@")
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,domain:,subdomain: -- "$@")
# shellcheck disable=SC2181
[[ "$?" -eq 0 ]] || usage
eval set -- "$TEMP"
@@ -87,8 +87,8 @@ while true; do
break
;;
*)
echo "Internal error!"
exit 1
builtin echo "useless option $1"
shift 2
;;
esac
done
+8 -2
View File
@@ -132,7 +132,7 @@ COMMAND_NAME=$(basename "$0")
# read the options
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn: -- "$@")
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,domain:,subdomain: -- "$@")
# shellcheck disable=SC2181
[[ "$?" -eq 0 ]] || usage
eval set -- "$TEMP"
@@ -162,6 +162,12 @@ while true; do
longname="wp-$shortname"
shift 2
;;
--domain)
shift 2
;;
--subdomain)
shift 2
;;
-c)
[[ "$action" == "unset" ]] || usage
action="_create"
@@ -187,7 +193,7 @@ while true; do
break
;;
*)
echo "Internal error!"
echoerr "Internal error: unrecognized option: <$1>"
exit 1
;;
esac