Intégration de la branche update-apacheconfig

This commit is contained in:
Jephté Clain 2017-03-24 15:06:47 +04:00
commit 95aa12fb25
3 changed files with 73 additions and 6 deletions

View File

@ -59,6 +59,11 @@ OPTIONS
Lors du déploiement de la configuration, les valeurs des variables
dynamiques sont remplacées dans les fichiers destination.
Les arguments qui restent sont passés tels quels à apache_autoconf
-p, --fix-ip
Corriger les lignes de la forme '<VirtualHost *:PORT>#*ip:IP' et les
remplacer par '<VirtualHost IP:PORT>'
Cela permet de déployer une version de production des fichiers de
configuration.
-N, --network-config
Mettre aussi à jour la configuration réseau.
-r, --certsdir CERTSDIR
@ -101,6 +106,7 @@ destdir=
nohideconfig=auto
templateopt=
FULLCONF=
fixip=
netconf=
aac_certsdir=
bits=
@ -133,6 +139,7 @@ args=(
-8,--jessie '$array_add TEMPLATECTL_VARS sysver=jessie'
--bits: bits=
-u,--update,--deploy action=deploy
-p,--fix-ip fixip=1
-N,--network-config netconf=1
-r:,--certsdir: aac_certsdir=
--localhosts action=localhosts
@ -188,6 +195,7 @@ elif [ "$action" == deploy -o "$action" == localhosts ]; then
args=(
-d "$destdir" --$action
${fixip:+--fix-ip}
${netconf:+--network-config}
${aac_certsdir:+-r "$aac_certsdir"}
${oneconf:+--one-conf "$oneconf"}
@ -208,7 +216,7 @@ elif [ "$action" == deploy -o "$action" == localhosts ]; then
"$destdir" "$aac_certsdir" \
"$config" "$oneconf" "$onemodule" "$onesite" \
"$custom_sysinfos" "$sysname" "$sysdist" "$sysver" "$bits" \
"$netconf" || die
"$netconf" "$fixip" || die
eend
elif [ "$action" == localhosts ]; then
etitle "Mise à jour de /etc/hosts"
@ -273,6 +281,44 @@ elif [ "$action" == new-site ]; then
die "$host n'est pas un nom d'hôte pleinement qualifié"
fi
hostip=
for i in "$clrtempl" "$ssltempl"; do
[ -n "$i" -a -f "$templdir/$i" ] || continue
quietgrep SITE_IP "$templdir/$i" && { hostip=1; break; }
done
if [ -n "$hostip" ]; then
# Il y a un champ SITE_IP, il faut demander à l'utilisateur l'adresse ip
# correspondante
[[ "$host" == *.* ]] && hostdomain="${host#*.}" || hostdomain=
pri=
hostip=
i=0
while [ $i -lt ${#PUBDOMAINS[*]} ]; do
if [ "${PUBDOMAINS[$i]}" == "$hostdomain" ]; then
pri="$VSPREFIX${host%$hostdomain}${PRIDOMAINS[$i]}"
resolv_ips ips "$pri"
if [ -n "$ips" ]; then
hostip="${ips[0]}"
break
fi
fi
i=$(($i + 1))
done
if [ -z "$hostip" ]; then
pri="$VSPREFIX$host"
resolv_ips ips "$pri"
[ -n "$ips" ] && hostip="${ips[0]}"
fi
if [ -n "$pri" -a -n "$hostip" ]; then
enote "Correspondance automatique $host --> $pri"
read_value "Veuillez confirmer l'adresse IP d'écoute" hostip "$hostip" N
else
enote "Vous devez saisir l'adresse IP privée correspondant à $host"
read_value "Veuillez entrer l'adresse IP *privée* d'écoute" hostip "" N
fi
[ -n "$hostip" ] || ewarn "Vous avez choisi de ne pas spécifier d'adresse IP d'écoute. Il faudra corriger manuellement les fichiers générés"
fi
etitle "$host"
hostname="${host%%.*}"
clrconf="${clrtempl/SITE/$hostname}"
@ -283,7 +329,10 @@ elif [ "$action" == new-site ]; then
mkdir -p "$destdir/certsconf"
mkdir -p "$destdir/sites"
sedscript="\
sedscript=
[ -n "$hostip" ] && sedscript="$sedscript
s/SITE_IP/$hostip/g"
sedscript="$sedscript
s/SITE.TLD/$host/g
s/SITE/$hostname/g"

View File

@ -4,3 +4,12 @@
#DEFAULT_ADMIN=supervision-gdrsi@listes.univ-reunion.fr
#DEFAULT_CERTSDIR=1507-renater
#DEFAULT_CANAME=1507-DigiCertCA.crt
# Valeurs des domaines publics et privés ainsi que préfixe pour les adresses de
# service. Chaque élément du tableau PUBDOMAINS doit avoir un correspondant dans
# le tableau PRIDOMAINS.
# Avec la configuration par défaut suivante, on considère que l'adresse
# privée correspondant à HOST.univ-reunion.fr est vs-HOST.univ.run
#PUBDOMAINS=(univ-reunion.fr)
#PRIDOMAINS=(univ.run)
#VSPREFIX=vs-

View File

@ -325,6 +325,7 @@ function apache_autoconf() {
local sitesdir onesite cgibindir wwwdir certsconfdir rrdir onecms
local sysname sysdist sysver bits
local netconf destconfsdir a2xconf
local fixip
local restart=1
parse_opts "${PRETTYOPTS[@]}" \
--help '$exit_with __display_apache_autoconf_help' \
@ -349,6 +350,7 @@ function apache_autoconf() {
-8,--jessie sysver=jessie \
--bits: bits= \
--network-config netconf=1 \
--fix-ip fixip=1 \
@ args -- "$@" && set -- "${args[@]}" || die "$args"
if [ -n "$sysname" -o -n "$sysdist" -o -n "$sysver" ]; then
@ -400,6 +402,10 @@ function apache_autoconf() {
# valeur dans les fichiers
local -a FILLVARS; local FILLSCRIPT FILLTEMP
__apache_autoconf_fillxxx "$@"
if [ -n "$fixip" ]; then
FILLSCRIPT="$FILLSCRIPT
"'s/<VirtualHost \*:\([0-9][0-9]*\)>#\*ip:\(.*\)$/<VirtualHost \2:\1>/'
fi
# Installation des packages système
if [ -f "$confdir/syspkgs.conf" ]; then
@ -884,6 +890,9 @@ function apacheconfig_initvars() {
DEFAULT_ADMIN=supervision-gdrsi@listes.univ-reunion.fr
DEFAULT_CERTSDIR=1507-renater
DEFAULT_CANAME=1507-DigiCertCA.crt
PUBDOMAINS=(univ-reunion.fr)
PRIDOMAINS=(univ.run)
VSPREFIX=vs-
set_defaults apacheconfig
TEMPLATE_NOWRITE_VARS=("${APACHECONFIG_TEMPLATE_NOWRITE_VARS[@]}")
@ -951,7 +960,7 @@ function apacheconfig_deploy() {
local destdir="$1" certsdir="$2"; shift; shift
local config="$1" oneconf="$2" onemodule="$3"; onesite="$4"; shift; shift; shift; shift
local custom_sysinfos="$1" sysname="$2" sysdist="$3" sysver="$4" bits="$5"; shift; shift; shift; shift; shift
local netconf="$1"; shift
local netconf="$1" fixip="$2"; shift; shift
local -a args
args=(--ignore "$(basename -- "$config")")
@ -960,6 +969,7 @@ function apacheconfig_deploy() {
[ -n "$onesite" ] && array_add args --one-site "$(basename -- "$onesite")"
[ -n "$custom_sysinfos" ] && array_add args --sysname "$sysname" --sysdist "$sysdist" --sysver "$sysver" --bits "$bits"
[ -n "$netconf" ] && array_add args --network-config
[ -n "$fixip" ] && array_add args --fix-ip
array_add args "$destdir" "$certsdir"
for __name in "${TEMPLATE_DYNAMIC_VARS[@]}"; do
array_add args "$__name=${!__name}"
@ -970,8 +980,7 @@ function apacheconfig_deploy() {
function apacheconfig_qs() {
# fonction pour simplifier l'utilisation de apacheconfig_deploy pour un
# répertoire spécifique
# $1=destdir $2=certsdir $3=netconf
local destdir="$1" certsdir="$2" netconf="$3"
# $1=destdir $2=certsdir $3=netconf $4=fixip
local config modified destdir autocreate
apacheconfig_initvars
apacheconfig_loadconf "$1"
@ -979,7 +988,7 @@ function apacheconfig_qs() {
"$destdir" "$2" \
"$config" "" "" "" \
"" "" "" "" "" \
"$3"
"$3" "$4"
}
function apacheconfig_localhosts() {