multiconf: rajouter conf_upgrade() dans conf_auto()
This commit is contained in:
parent
eeef48dfe1
commit
1e576da4ae
|
@ -25,6 +25,7 @@ function conf_auto() {
|
||||||
# est équivalent à:
|
# est équivalent à:
|
||||||
# conf_init VARS...
|
# conf_init VARS...
|
||||||
# conf_find_files __CONF_FILES ~/etc/default/NAME.conf ~/etc/NAME.d/*.conf
|
# conf_find_files __CONF_FILES ~/etc/default/NAME.conf ~/etc/NAME.d/*.conf
|
||||||
|
# conf_upgrade ~/etc/default/NAME.conf
|
||||||
# conf_load_files "${__CONF_FILES[@]}"
|
# conf_load_files "${__CONF_FILES[@]}"
|
||||||
# Pour supporter les scénarii où les fichiers de configuration sont ailleurs
|
# Pour supporter les scénarii où les fichiers de configuration sont ailleurs
|
||||||
# que dans ~/etc/default, l'argument NAME peut être un chemin:
|
# que dans ~/etc/default, l'argument NAME peut être un chemin:
|
||||||
|
@ -32,16 +33,20 @@ function conf_auto() {
|
||||||
# est équivalent à:
|
# est équivalent à:
|
||||||
# conf_init VARS...
|
# conf_init VARS...
|
||||||
# conf_find_files __CONF_FILES PATH/TO/NAME.conf PATH/TO/NAME.d/*.conf
|
# conf_find_files __CONF_FILES PATH/TO/NAME.conf PATH/TO/NAME.d/*.conf
|
||||||
|
# conf_upgrade PATH/TO/NAME.conf
|
||||||
# conf_load_files "${__CONF_FILES[@]}"
|
# conf_load_files "${__CONF_FILES[@]}"
|
||||||
local __name="$1"; shift
|
local __name="$1"; shift
|
||||||
[ -n "$__name" ] || return 1
|
[ -n "$__name" ] || return 1
|
||||||
[ $# -gt 0 ] && conf_init "$@"
|
[ $# -gt 0 ] && conf_init "$@"
|
||||||
local -a __CONF_FILES
|
local -a __CONF_FILES
|
||||||
if [[ "$__name" == */* ]]; then
|
if [[ "$__name" == */* ]]; then
|
||||||
conf_load "$__name.conf" "$__name.d/*.conf"
|
conf_find_files __CONFS_FILES "$__name.conf" "$__name.d/*.conf"
|
||||||
|
[ $# -gt 0 ] && conf_upgrade "$__name.conf"
|
||||||
else
|
else
|
||||||
conf_load "$HOME/etc/default/$__name.conf" "$HOME/etc/$__name.d/*.conf"
|
conf_find_files __CONFS_FILES "$HOME/etc/default/$__name.conf" "$HOME/etc/$__name.d/*.conf"
|
||||||
|
[ $# -gt 0 ] && conf_upgrade "$HOME/etc/default/$__name.conf"
|
||||||
fi
|
fi
|
||||||
|
conf_load_files "${__CONFS_FILES[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function conf_init() {
|
function conf_init() {
|
||||||
|
@ -281,10 +286,11 @@ function conf_upgrade() {
|
||||||
if [ ! -f "$dest" ]; then
|
if [ ! -f "$dest" ]; then
|
||||||
local prefix
|
local prefix
|
||||||
for desc in "${__CONF_DESCS[@]}"; do
|
for desc in "${__CONF_DESCS[@]}"; do
|
||||||
[ "${desc:0:1}" == "#" ] && echo "$desc" >"$dest"
|
[ "${desc:0:1}" == "#" ] && prefix="$desc"
|
||||||
break
|
break
|
||||||
done
|
done
|
||||||
>>"$dest"
|
[ ${#prefix} -gt 0 ] || prefix="# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8"
|
||||||
|
echo "$prefix" >"$dest"
|
||||||
fi
|
fi
|
||||||
# vérifier la présence de chaque variable
|
# vérifier la présence de chaque variable
|
||||||
for desc in "${__CONF_DESCS[@]}"; do
|
for desc in "${__CONF_DESCS[@]}"; do
|
||||||
|
|
Loading…
Reference in New Issue