valeur par défaut de host

This commit is contained in:
Jephte CLAIN 2014-11-29 23:52:17 +04:00
parent 16f5486157
commit 9fdb0d1d4c
2 changed files with 36 additions and 23 deletions

View File

@ -127,12 +127,9 @@ OPTIONS AVANCEES
function __templatectl_display_help() { display_help; }
# Valeurs par défaut des variables de template
setx host=myhost
hostname="${host%%.*}"
DEFAULT_TEMPLATE_VARS=(
host="$host"
hostname="$hostname"
aliases="$hostname"
hostname= aliases= # mettre ces variables AVANT host
host=
admin=supervision-gdrsi@listes.univ-reunion.fr
certsdir=renater
caname=terena.crt
@ -170,14 +167,23 @@ function update_var() {
# hostname.
local __orig_value="${!1}"
array_contains DYNAMIC_VARS "$1" || array_addu TEMPLATE_VARS "$1"
# Valeurs par défaut
case "$1" in
host) [ -n "$2" ] || set -- "$1" "$(myhost)";;
esac
# Mettre à jour la variable
setv "$1" "$2"
# Mettre à jour des variables dépendantes
local __update_aliases
case "$1" in
host)
# attention à ne pas créer de boucle infinies :-)
[ "$aliases" == "$hostname" ] && __update_aliases=1
hostname="${host%%.*}"
[ -n "$__update_aliases" ] && aliases="$hostname"
update_var hostname "${host%%.*}"
[ -n "$__update_aliases" ] && update_var aliases "$hostname"
;;
esac
@ -268,7 +274,7 @@ if [ -n "$__write_vars" ]; then
[ -f "$__apacheconfig_vars" ] &&
die "Refus d'écraser le fichier existant $(ppath "$__apacheconfig_vars")"
>"$__apacheconfig_vars"
echo "# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8" >"$__apacheconfig_vars"
echo "__template_vars=(" >>"$__apacheconfig_vars"
for __var in "${TEMPLATE_VARS[@]}"; do
echo_setv "$__var=${!__var}" >>"$__apacheconfig_vars"

View File

@ -50,34 +50,33 @@ function __templatectl_display_help() { display_help; }
set_defaults runs
# essayer de déterminer l'hôte à partir du répertoire courant
host=
DEFAULT_HOST=
array_split __hostsdirs "$RUNSHOSTSPATH" :
setx __cwd=pwd
for __hostsdir in "${__hostsdirs[@]}"; do
setx __hostsdir=abspath "$__hostsdir"
if [ "${__cwd#$__hostsdir/}" != "$__cwd" ]; then
host="${__cwd#$__hostsdir/}"
host="${host%%/*}"
DEFAULT_HOST="${__cwd#$__hostsdir/}"
DEFAULT_HOST="${DEFAULT_HOST%%/*}"
break
fi
done
# sinon lire l'environnement
if [ -z "$host" ]; then
if [ -z "$DEFAULT_HOST" ]; then
runs_initdomains
setx host=myhost
splithost "$host" hostname domain
if [ -z "$domain" ]; then
host="$(runs_find_host "$host")"
splithost "$host" hostname domain
setx DEFAULT_HOST=myhost
splithost "$DEFAULT_HOST" __hostname __domain
if [ -z "$__domain" ]; then
DEFAULT_HOST="$(runs_find_host "$DEFAULT_HOST")"
splithost "$DEFAULT_HOST" __hostname __domain
fi
[ -n "$domain" ] || host="$(runs_add_domain "$host")"
[ -n "$__domain" ] || DEFAULT_HOST="$(runs_add_domain "$DEFAULT_HOST")"
fi
hostname="${host%%.*}"
DEFAULT_TEMPLATE_VARS=(
host="$host"
hostname="$hostname"
hostname= # mettre cette variables AVANT host
host=
)
TEMPLATE_VARS=()
@ -87,10 +86,18 @@ function update_var() {
# hostname.
local __orig_value="${!1}"
array_addu TEMPLATE_VARS "$1"
# Valeurs par défaut
case "$1" in
host) [ -n "$2" ] || set -- "$1" "$(myhost)";;
esac
# Mettre à jour la variable
setv "$1" "$2"
# Mettre à jour des variables dépendantes
case "$1" in
host) hostname="${host%%.*}";;
host) update_var hostname "${host%%.*}";;
esac
[ "$2" != "$__orig_value" ]
@ -137,7 +144,7 @@ if [ -n "$__write_vars" ]; then
[ -f "$__runsconfig_vars" ] &&
die "Refus d'écraser le fichier existant $(ppath "$__runsconfig_vars")"
>"$__runsconfig_vars"
echo "# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8" >"$__runsconfig_vars"
echo "__template_vars=(" >>"$__runsconfig_vars"
for __var in "${TEMPLATE_VARS[@]}"; do
echo_setv "$__var=${!__var}" >>"$__runsconfig_vars"