apacheconfig: support des hôtes dynamiques ou statiques
This commit is contained in:
parent
93ac7ea005
commit
27592d4450
61
apacheconfig
61
apacheconfig
|
@ -50,12 +50,15 @@ OPTIONS
|
|||
déployer."
|
||||
}
|
||||
|
||||
TEMPLATE_STATIC_VARS=()
|
||||
# toujours placer une variable dépendante AVANT la variable maitre
|
||||
TEMPLATE_STATIC_VARS=(
|
||||
hostname aliases host
|
||||
)
|
||||
TEMPLATE_DYNAMIC_VARS=(
|
||||
host hostname aliases
|
||||
ips ips_default_namevirtualhost ips_namevirtualhosts ips_listens
|
||||
ips_namevirtualhosts ips_listens ips
|
||||
dhostname daliases dhost
|
||||
admin certsdir caname certname keyname configdir)
|
||||
TEMPLATE_NOWRITE_VARS=(hostname aliases configdir)
|
||||
TEMPLATE_NOWRITE_VARS=(hostname aliases dhostname daliases configdir)
|
||||
|
||||
__TEMPLATE_DEFAULTF_host=__template_defaultf_host
|
||||
__TEMPLATE_UPDATEF_host=__template_updatef_host
|
||||
|
@ -74,36 +77,49 @@ __TEMPLATE_DEFAULTF_ips=__template_defaultf_ips
|
|||
__TEMPLATE_UPDATEF_ips=__template_updatef_ips
|
||||
function __template_defaultf_ips() {
|
||||
local -a ips
|
||||
resolv_ips ips "$host"
|
||||
if [ "$host" != "@@dhost@@" ]; then
|
||||
resolv_ips ips "$host"
|
||||
else
|
||||
resolv_ips ips "$dhost"
|
||||
fi
|
||||
echo "${ips[*]}"
|
||||
}
|
||||
function __template_updatef_ips() {
|
||||
local -a ipports; local ipport ip port
|
||||
local dnvh nvhs ls
|
||||
local nvhs ls
|
||||
nvhs=
|
||||
ls=
|
||||
array_split ipports "$ips" " "
|
||||
for ipport in "${ipports[@]}"; do
|
||||
splitpair "$ipport" ip port
|
||||
[ -n "$port" ] || port=443
|
||||
[ -n "$dnvh" ] || dnvh="#ips_default_namevirtualhost
|
||||
NameVirtualHost *:80"
|
||||
[ -n "$nvhs" ] || nvhs="#ips_namevirtualhosts"
|
||||
[ -n "$ls" ] || ls="#ips_listens"
|
||||
|
||||
nvhs="$nvhs
|
||||
NameVirtualHost $ip:$port"
|
||||
[ -n "$ls" ] || ls="#ips_listens"
|
||||
ls="$ls
|
||||
Listen $ip:$port"
|
||||
done
|
||||
[ -n "$dnvh" ] && __template_set_var ips_default_namevirtualhost "$dnvh"
|
||||
[ -n "$nvhs" ] && __template_set_var ips_namevirtualhosts "$nvhs"
|
||||
[ -n "$ls" ] && __template_set_var ips_listens "$ls"
|
||||
}
|
||||
|
||||
__TEMPLATE_DEFAULTF_dhost=__template_defaultf_dhost
|
||||
__TEMPLATE_UPDATEF_dhost=__template_updatef_dhost
|
||||
function __template_defaultf_dhost() {
|
||||
myhost
|
||||
}
|
||||
function __template_updatef_dhost() {
|
||||
local update_daliases
|
||||
[ "$daliases" == "$dhostname" ] && update_daliases=1
|
||||
__template_set_var dhostname "${dhost%%.*}"
|
||||
[ -n "$update_daliases" ] && __template_set_var daliases "$dhostname"
|
||||
[ -n "$ips" ] || __template_set_var ips ""
|
||||
}
|
||||
|
||||
TEMPLATECTL_NAME=apacheconfig
|
||||
TEMPLATECTL_SRCDIRS=(apacheconfig)
|
||||
TEMPLATECTL_CONFIG=".$TEMPLATECTL_NAME"
|
||||
TEMPLATECTL_CONFIG="$TEMPLATECTL_NAME"
|
||||
TEMPLATECTL_DEFAULTS=(
|
||||
admin=supervision-gdrsi@listes.univ-reunion.fr
|
||||
certsdir=renater
|
||||
|
@ -112,12 +128,15 @@ TEMPLATECTL_VARS=()
|
|||
|
||||
action=
|
||||
destdir=
|
||||
nohideconfig=
|
||||
templateopt=
|
||||
certsdir=
|
||||
args=(
|
||||
--help '$exit_with display_help'
|
||||
-c,--create action=create
|
||||
-d:,--destdir: destdir=
|
||||
--no-hideconfig nohideconfig=1
|
||||
--hideconfig nohideconfig=
|
||||
-t::,--template:: '$set@ templateopt; action=template'
|
||||
--help-template '$templateopt=-help; action=template'
|
||||
-l,--list '$templateopt=l; action=template'
|
||||
|
@ -137,7 +156,7 @@ args=(
|
|||
parse_args "$@"; set -- "${args[@]}"
|
||||
|
||||
__template_set_destdir destdir autocreate "$TEMPLATECTL_NAME" || die
|
||||
setx config=templatectl_config "$destdir"
|
||||
setx config=templatectl_config "$destdir" ${nohideconfig:+nohideconfig}
|
||||
modified=
|
||||
templatectl_loadvars "$config" && modified=1
|
||||
|
||||
|
@ -168,18 +187,26 @@ if [ "$action" == create ]; then
|
|||
fi
|
||||
[ -d "$destdir" ] || die "$destdir: répertoire introuvable"
|
||||
|
||||
if [ -n "$host" ]; then
|
||||
read_value -i "Veuillez entrer le nom d'hôte" host "$host"
|
||||
else
|
||||
check_interaction -c && einfo "Vous pouvez entrer un nom d'hôte spécifique pour la nouvelle configuration, ou laisser la valeur par défaut @@dhost@@ pour qu'il soit calculé dynamiquement lors du déploiement"
|
||||
read_value "Veuillez entrer le nom d'hôte" host @@dhost@@
|
||||
fi
|
||||
__template_set_var host "$host"
|
||||
|
||||
if [ -f "$config" ]; then
|
||||
ask_yesno "Le fichier $(ppath "$config") existe. Voulez-vous l'écraser?" O || die
|
||||
ask_yesno "Le fichier $(ppath "$config") sera écrasé. Voulez-vous continuer?" O || die
|
||||
rm -f "$config" || die
|
||||
fi
|
||||
templatectl -d "$destdir" --no-load-vars -m --write-vars
|
||||
templatectl -d "$destdir" --config "$config" --no-load-vars -m --write-vars
|
||||
|
||||
################################################################################
|
||||
elif [ "$action" == template ]; then
|
||||
__TEMPLATECTL_HELP="USAGE: $scriptname -t -- args...
|
||||
|
||||
$__TEMPLATECTL_HELP"
|
||||
templatectl -d "$destdir" --no-load-vars ${templateopt:+-$templateopt} "$@"
|
||||
templatectl -d "$destdir" --config "$config" --no-load-vars ${templateopt:+-$templateopt} "$@"
|
||||
|
||||
################################################################################
|
||||
elif [ "$action" == deploy ]; then
|
||||
|
@ -197,6 +224,6 @@ elif [ "$action" == deploy ]; then
|
|||
for __name in "${TEMPLATE_DYNAMIC_VARS[@]}"; do
|
||||
array_add args "$__name=${!__name}"
|
||||
done
|
||||
apache_autoconf "${args[@]}" "$@" || die
|
||||
apache_autoconf --ignore "$(basename -- "$config")" "${args[@]}" "$@" || die
|
||||
eend
|
||||
fi
|
||||
|
|
|
@ -85,7 +85,12 @@ function pconf() {
|
|||
}
|
||||
|
||||
if [ -n "$UTOOLS_USSH_ALIAS" ]; then
|
||||
function ssh() { "@@dest@@/ussh" "$@"; }
|
||||
function ssh() {
|
||||
local dest="@@dest@@"
|
||||
if [ "$dest" == "@@"dest"@@" ]; then "$(which ssh)" "$@"
|
||||
else "@@dest@@/ussh" "$@"
|
||||
fi
|
||||
}
|
||||
fi
|
||||
|
||||
# Configuration
|
||||
|
|
|
@ -212,11 +212,14 @@ __APACHE_AUTOCONF_HELP="\
|
|||
function __display_apache_autoconf_help() { eecho "$__APACHE_AUTOCONF_HELP"; }
|
||||
function apache_autoconf() {
|
||||
eval "$(utools_local)"
|
||||
local autoconfdir certsdir confdir modulesdir sitesdir cgibindir wwwdir certsconfdir rrdir
|
||||
local -a ignores
|
||||
local autoconfdir certsdir confdir confsdir modulesdir sitesdir cgibindir wwwdir certsconfdir rrdir
|
||||
local restart=1
|
||||
parse_opts "${PRETTYOPTS[@]}" \
|
||||
--help '$exit_with __display_apache_autoconf_help' \
|
||||
--ignore: ignores \
|
||||
--confdir: confdir= \
|
||||
--confsdir: confsdir= \
|
||||
--modulesdir: modulesdir= \
|
||||
--sitesdir: sitesdir= \
|
||||
--cgibindir: cgibindir= \
|
||||
|
@ -240,15 +243,16 @@ function apache_autoconf() {
|
|||
return 1
|
||||
}
|
||||
certsdir="$1"; shift
|
||||
if [ -z "$confdir" -o -z "$modulesdir" -o -z "$sitesdir" \
|
||||
-o -z "$cgibindir" -o -z "$wwwdir" -o -z "$certsconfdir" \
|
||||
-o -z "$rrdir" ]; then
|
||||
if [ -z "$confdir" -o -z "$confsdir" -o -z "$modulesdir" \
|
||||
-o -z "$sitesdir" -o -z "$cgibindir" -o -z "$wwwdir" \
|
||||
-o -z "$certsconfdir" -o -z "$rrdir" ]; then
|
||||
[ -d "$autoconfdir" ] || {
|
||||
eerror "$autoconfdir: répertoire invalide"
|
||||
return 1
|
||||
}
|
||||
fi
|
||||
[ -n "$confdir" ] || confdir="$autoconfdir"
|
||||
[ -n "$confsdir" ] || confsdir="$autoconfdir/confs"
|
||||
[ -n "$modulesdir" ] || modulesdir="$autoconfdir/modules"
|
||||
[ -n "$sitesdir" ] || sitesdir="$autoconfdir/sites"
|
||||
[ -n "$cgibindir" ] || cgibindir="$autoconfdir/cgi-bin"
|
||||
|
@ -298,7 +302,22 @@ function apache_autoconf() {
|
|||
eend
|
||||
fi
|
||||
|
||||
# Configuration des modules
|
||||
# Gestion des configurations
|
||||
if [ -d "$confsdir" ]; then
|
||||
local -a confs
|
||||
local conf
|
||||
etitle "Installation des configurations"
|
||||
array_from_lines confs "$(list_files "$confsdir" "*.conf")"
|
||||
for conf in "${confs[@]}"; do
|
||||
estep "$conf"
|
||||
__apache_autoconf_fillcopy \
|
||||
"$confsdir/$conf" \
|
||||
"$APACHECONFDIR/conf-available/$conf" && modified=1
|
||||
done
|
||||
eend
|
||||
fi
|
||||
|
||||
# Gestion des modules
|
||||
if [ -d "$modulesdir" ]; then
|
||||
local -a confs
|
||||
local conf
|
||||
|
@ -383,14 +402,31 @@ s#@@ca@@#$APACHESSLCERTSDIR/$(basename "$ca")#g
|
|||
etitle "Configuration de base"
|
||||
array_from_lines confs "$(list_files "$confdir")"
|
||||
for conf in "${confs[@]}"; do
|
||||
array_contains ignores "$conf" && continue
|
||||
case "$conf" in
|
||||
modules.conf|sites.conf) continue;;
|
||||
confs.conf|modules.conf|sites.conf) continue;;
|
||||
esac
|
||||
estep "$conf"
|
||||
__apache_autoconf_fillcopy \
|
||||
"$confdir/$conf" \
|
||||
"$APACHECONFDIR/$conf" && modified=1
|
||||
done
|
||||
if [ -f "$confdir/confs.conf" ]; then
|
||||
local -a confs
|
||||
local conf
|
||||
array_from_lines confs "$(<"$confdir/confs.conf" filter_conf)"
|
||||
for conf in "${confs[@]}"; do
|
||||
if [ "${conf#-}" != "$conf" ]; then
|
||||
conf="${conf#-}"
|
||||
estep "Désactivation de la configuration $conf"
|
||||
a2disconf "$conf" && modified=1
|
||||
else
|
||||
conf="${conf#+}"
|
||||
estep "Activation de la configuration $conf"
|
||||
a2enconf "$conf" && modified=1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
if [ -f "$confdir/modules.conf" ]; then
|
||||
local -a modules
|
||||
local module
|
||||
|
|
|
@ -28,6 +28,8 @@ function qseds() {
|
|||
local s="$*"
|
||||
s="${s//\\/\\\\}"
|
||||
s="${s//\//\\/}"
|
||||
s="${s//
|
||||
/\\n}"
|
||||
recho "$s"
|
||||
}
|
||||
function _qform() {
|
||||
|
|
|
@ -146,7 +146,7 @@ function __template_fillvars() {
|
|||
[ -n "$__found" ] || { echo "$1"; return; }
|
||||
|
||||
# construire le script sed pour le remplacement des variables
|
||||
local __script __first=1
|
||||
local __script __first=1 __repl
|
||||
for __var in "${TEMPLATE_STATIC_VARS[@]}"; do
|
||||
[ -n "$__first" ] || __script="$__script"$'\n'
|
||||
__first=
|
||||
|
@ -360,9 +360,10 @@ function template_unmerge() {
|
|||
function template_cleandest() {
|
||||
# Supprimer dans le répertoire de destination $1 tous les répertoires vides.
|
||||
# Cette fonction est habituellement utilisée après template_unmerge()
|
||||
# Ignorer les chemins qui contiennent .git/ et .svn/
|
||||
local -a dirs
|
||||
[ -d "$1" ] || return 1
|
||||
array_from_lines dirs "$(cd "$1"; find . -type d | __template_plsort -r)"
|
||||
array_from_lines dirs "$(cd "$1"; find . -type d | grep -v .git/ | grep -v .svn/ | __template_plsort -r)"
|
||||
array_del dirs .
|
||||
(cd "$1"; rmdir "${dirs[@]}" 2>/dev/null)
|
||||
}
|
||||
|
@ -414,7 +415,14 @@ function template_srcdir() {
|
|||
|
||||
function templatectl_config() {
|
||||
# Obtenir le chemin vers le fichier de configuration pour le répertoire $1
|
||||
echo "$1/$(basename -- "$TEMPLATECTL_CONFIG")"
|
||||
# Si $2==nohideconfig, utiliser le nom CONFIG.conf, sinon utiliser par défaut
|
||||
# .CONFIG sauf si le fichier CONFIG.conf existe
|
||||
local config="$(basename -- "$TEMPLATECTL_CONFIG")"
|
||||
if [ -f "$1/$config.conf" -o "$2" == nohideconfig ]; then
|
||||
echo "$1/$config.conf"
|
||||
else
|
||||
echo "$1/.$config"
|
||||
fi
|
||||
}
|
||||
|
||||
function templatectl_loadvars() {
|
||||
|
@ -467,18 +475,20 @@ function templatectl_writevars() {
|
|||
# Ecrire les variables dans le fichier $1
|
||||
local __t_var
|
||||
echo "# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8" >"$1"
|
||||
echo "__template_vars=(" >>"$1"
|
||||
if [ ${#TEMPLATE_DYNAMIC_VARS[*]} -gt 0 ]; then
|
||||
echo "__dynamic_vars=(" >>"$1"
|
||||
for __t_var in "${TEMPLATE_DYNAMIC_VARS[@]}"; do
|
||||
array_contains TEMPLATE_NOWRITE_VARS "$__t_var" && continue
|
||||
echo_setv "$__t_var=${!__t_var}" >>"$1"
|
||||
done
|
||||
echo ")" >>"$1"
|
||||
fi
|
||||
echo "__template_vars=(# ne pas modifier" >>"$1"
|
||||
for __t_var in "${TEMPLATE_STATIC_VARS[@]}"; do
|
||||
array_contains TEMPLATE_NOWRITE_VARS "$__t_var" && continue
|
||||
echo_setv "$__t_var=${!__t_var}" >>"$1"
|
||||
done
|
||||
echo ")" >>"$1"
|
||||
echo "__dynamic_vars=(" >>"$1"
|
||||
for __t_var in "${TEMPLATE_DYNAMIC_VARS[@]}"; do
|
||||
array_contains TEMPLATE_NOWRITE_VARS "$__t_var" && continue
|
||||
echo_setv "$__t_var=${!__t_var}" >>"$1"
|
||||
done
|
||||
echo ")" >>"$1"
|
||||
}
|
||||
|
||||
function templatectl_list_vars() {
|
||||
|
@ -539,6 +549,9 @@ function templatectl() {
|
|||
# - TEMPLATECTL_CONFIG est le nom de base du fichier à partir duquel sont
|
||||
# chargées les variables et dans lequel sont écrites les variables avec
|
||||
# l'option --write-vars
|
||||
# Si le nom de base est CONFIG, le fichier s'appelera .CONFIG si l'option
|
||||
# --hide-config est utilisée (par défaut) ou CONFIG.conf si l'option
|
||||
# --no-hide-config est utilisée
|
||||
# Les variables de template_loadvars() sont aussi prises en compte
|
||||
local -a __tc_srcdirs; local __tc_srcdir
|
||||
if [ ${#TEMPLATECTL_SRCDIRS[*]} -gt 0 ]; then
|
||||
|
@ -556,11 +569,15 @@ function templatectl() {
|
|||
|
||||
local -a __tc_args
|
||||
local __tc_auto=1 __tc_load_vars=1
|
||||
local __tc_destdir __tc_list __tc_merge __tc_unmerge __tc_clean __tc_diff __tc_list_vars __tc_write_vars
|
||||
local __tc_destdir __tc_config __tc_nohideconfig
|
||||
local __tc_list __tc_merge __tc_unmerge __tc_clean __tc_diff __tc_list_vars __tc_write_vars
|
||||
parse_opts "${PRETTYOPTS[@]}" \
|
||||
--help '$exit_with __display_templatectl_help' \
|
||||
-d:,--destdir: __tc_destdir= \
|
||||
-s:,--srcdir: __tc_srcdirs \
|
||||
--config: __tc_config= \
|
||||
--no-hide-config __tc_nohideconfig=1 \
|
||||
--hide-config __tc_nohideconfig= \
|
||||
--load-vars __tc_load_vars=1 \
|
||||
--no-load-vars __tc_load_vars= \
|
||||
--noop __tc_auto= \
|
||||
|
@ -582,7 +599,7 @@ function templatectl() {
|
|||
__template_check_srcdir "$__tc_srcdir" || return 1
|
||||
done
|
||||
|
||||
local __tc_config="$__tc_destdir/$(basename -- "$TEMPLATECTL_CONFIG")"
|
||||
[ -n "$__tc_config" ] || __tc_config="$(templatectl_config "$destdir" ${__tc_nohideconfig:+nohideconfig})"
|
||||
if [ -n "$__tc_load_vars" ]; then
|
||||
templatectl_loadvars "$__tc_config"
|
||||
fi
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
# have to change the VirtualHost statement in
|
||||
# /etc/apache2/sites-enabled/000-default.conf
|
||||
|
||||
#@@ips_default_namevirtualhost@@
|
||||
Listen 80
|
||||
|
||||
<IfModule ssl_module>
|
||||
|
|
|
@ -77,7 +77,7 @@ function __template_updatef_host() {
|
|||
|
||||
TEMPLATECTL_NAME=runs
|
||||
TEMPLATECTL_SRCDIRS=(runsconfig)
|
||||
TEMPLATECTL_CONFIG=".runsconfig"
|
||||
TEMPLATECTL_CONFIG=runsconfig
|
||||
TEMPLATECTL_DEFAULTS=()
|
||||
TEMPLATECTL_VARS=()
|
||||
|
||||
|
|
Loading…
Reference in New Issue