Intégration de la branche runs

This commit is contained in:
Jephté Clain 2015-12-09 22:57:22 +04:00
commit ebe45998ab
2 changed files with 60 additions and 24 deletions

View File

@ -99,7 +99,7 @@ function runs_initdir() {
# d'abord chercher si le répertoire existe déjà # d'abord chercher si le répertoire existe déjà
for runshostdir in "${RUNSHOSTSDIRS[@]}"; do for runshostdir in "${RUNSHOSTSDIRS[@]}"; do
found= found=
for dir in "$runshostdir/$domain/$hostname" "$runshostdir/$host"; do for dir in "$runshostdir/$host/runs" "$runshostdir/$domain/$hostname/runs" "$runshostdir/$host" "$runshostdir/$domain/$hostname"; do
if [ -d "$dir" ]; then if [ -d "$dir" ]; then
found=1 found=1
break break
@ -121,18 +121,18 @@ function runs_initdir() {
found= found=
for dir in "$runshostdir/$host" "$runshostdir/$domain/$hostname"; do for dir in "$runshostdir/$host" "$runshostdir/$domain/$hostname"; do
if [ -d "$dir" ]; then if [ -d "$dir" ]; then
runshostdir="$dir" runshostdir="$dir/runs"
found=1 found=1
break break
fi fi
done done
[ -n "$found" ] || runshostdir="$runshostdir/$host" [ -n "$found" ] || runshostdir="$runshostdir/$host/runs"
else else
runshostdir="${RUNSHOSTSDIRS[0]}/$host" runshostdir="${RUNSHOSTSDIRS[0]}/$host/runs"
fi fi
else else
host="$hostname" host="$hostname"
runshostdir="${RUNSHOSTSDIRS[0]}/$host" runshostdir="${RUNSHOSTSDIRS[0]}/$host/runs"
fi fi
local rscriptt runsconft sysinfost defaultt configt servicest local rscriptt runsconft sysinfost defaultt configt servicest
@ -158,24 +158,24 @@ function runs_initdir() {
echo "$sysinfost" >"$runshostdir/sysinfos.conf" echo "$sysinfost" >"$runshostdir/sysinfos.conf"
fi fi
if [ ! -f "$runshostdir/default" ]; then if [ ! -f "$runshostdir/default" ]; then
estep "Création de $(ppath "$runshostdir/default")" estep "Création de $(ppath "$runshostdir/default.rr")"
echo "$defaultt" >"$runshostdir/default" echo "$defaultt" >"$runshostdir/default.rr"
edit_default=1 edit_default=1
fi fi
if [ ! -f "$runshostdir/config" ]; then if [ ! -f "$runshostdir/config" ]; then
estep "Création de $(ppath "$runshostdir/config")" estep "Création de $(ppath "$runshostdir/config.rr")"
echo "$configt" >"$runshostdir/config" echo "$configt" >"$runshostdir/config.rr"
fi fi
if [ ! -f "$runshostdir/services" ]; then if [ ! -f "$runshostdir/services" ]; then
estep "Création de $(ppath "$runshostdir/services")" estep "Création de $(ppath "$runshostdir/services.rr")"
echo "$servicest" >"$runshostdir/services" echo "$servicest" >"$runshostdir/services.rr"
fi fi
if [ ! -f "$runshostdir/userdefault" ]; then if [ ! -f "$runshostdir/userdefault" ]; then
estep "Création de $(ppath "$runshostdir/userdefault")" estep "Création de $(ppath "$runshostdir/userdefault.rr")"
echo "$userdefaultt" >"$runshostdir/userdefault" echo "$userdefaultt" >"$runshostdir/userdefault.rr"
fi fi
[ -n "$edit_default" ] && "${EDITOR:-vi}" "$runshostdir/default" [ -n "$edit_default" ] && "${EDITOR:-vi}" "$runshostdir/default.rr"
return 0 return 0
} }
@ -189,9 +189,9 @@ function __runs_create_rscript() {
template="$runsconft" template="$runsconft"
elif [ "$rscriptname" == "sysinfos.conf" ]; then elif [ "$rscriptname" == "sysinfos.conf" ]; then
template="$sysinfost" template="$sysinfost"
elif [ "$rscriptname" == "default" ]; then elif [ "$rscriptname" == "default" -o "$rscriptname" == "default.rr" ]; then
template="$defaultt" template="$defaultt"
elif [ "$rscriptname" == "userdefault" ]; then elif [ "$rscriptname" == "userdefault" -o "$rscriptname" == "userdefault.rr" ]; then
template="$userdefaultt" template="$userdefaultt"
else else
withext "$rscript" || rscript="$rscript.rs" withext "$rscript" || rscript="$rscript.rs"
@ -241,7 +241,7 @@ function runs_create_rscript() {
splithost "$host" hostname domain splithost "$host" hostname domain
for runsdir in "${RUNSHOSTSDIRS[@]}"; do for runsdir in "${RUNSHOSTSDIRS[@]}"; do
found= found=
for dir in "$runsdir/$host" "$runsdir/$domain/$hostname"; do for dir in "$runsdir/$host/runs" "$runsdir/$domain/$hostname/runs" "$runsdir/$host" "$runsdir/$domain/$hostname"; do
if [ -d "$dir" ]; then if [ -d "$dir" ]; then
runsdir="$dir" runsdir="$dir"
found=1 found=1
@ -370,6 +370,8 @@ function runs_find_hostfile() {
splithost "$__runshost" __hostname __domain splithost "$__runshost" __hostname __domain
for __runsdir in "${!__runshostsdirs}"; do for __runsdir in "${!__runshostsdirs}"; do
for __runsfile in \ for __runsfile in \
"$__runsdir/$__runshost/runs/$__hostfile" \
"$__runsdir/$__domain/$__hostname/runs/$__hostfile"\
"$__runsdir/$__runshost/$__hostfile" \ "$__runsdir/$__runshost/$__hostfile" \
"$__runsdir/$__domain/$__hostname/$__hostfile"; do "$__runsdir/$__domain/$__hostname/$__hostfile"; do
if [ -e "$__runsfile" ]; then if [ -e "$__runsfile" ]; then
@ -417,6 +419,8 @@ function runs_find_datafile() {
splithost "$__runshost" __hostname __domain splithost "$__runshost" __hostname __domain
for __runsdir in "${!__runshostsdirs}"; do for __runsdir in "${!__runshostsdirs}"; do
for __runsfile in \ for __runsfile in \
"$__runsdir/$__runshost/runs/$__datafile" \
"$__runsdir/$__domain/$__hostname/runs/$__datafile"\
"$__runsdir/$__runshost/$__datafile" \ "$__runsdir/$__runshost/$__datafile" \
"$__runsdir/$__domain/$__hostname/$__datafile"; do "$__runsdir/$__domain/$__hostname/$__datafile"; do
if [ -e "$__runsfile" ]; then if [ -e "$__runsfile" ]; then
@ -475,6 +479,8 @@ function runs_find_scriptfile() {
# initialiser les variables RUNSDIR, RUNSSCRIPT, RUNSSCRIPTDIR, # initialiser les variables RUNSDIR, RUNSSCRIPT, RUNSSCRIPTDIR,
# RUNSSCRIPTNAME, RUNSDIRPATH et RUNSSCRIPTPATH. Retourner 0 en cas de # RUNSSCRIPTNAME, RUNSDIRPATH et RUNSSCRIPTPATH. Retourner 0 en cas de
# succès, 1 en cas d'échec. # succès, 1 en cas d'échec.
# $6 vaut ".rs" par défaut est c'est une extension à rajouter au nom
# spécifié si le fichier sans l'extension n'existe pas
# RUNSDIR est le répertoire dans lequel a été trouvé le script (parmi les # RUNSDIR est le répertoire dans lequel a été trouvé le script (parmi les
# valeurs fournies dans les tableaux RUNSSCRIPTSDIRS, RUNSMODULESDIRS, # valeurs fournies dans les tableaux RUNSSCRIPTSDIRS, RUNSMODULESDIRS,
# RUNSHOSTSDIRS), RUNSDIRPATH est le répertoire à partir duquel est exprimé # RUNSHOSTSDIRS), RUNSDIRPATH est le répertoire à partir duquel est exprimé
@ -489,6 +495,7 @@ function runs_find_scriptfile() {
local __runsscriptsdirs="${3:-RUNSSCRIPTSDIRS}[@]" local __runsscriptsdirs="${3:-RUNSSCRIPTSDIRS}[@]"
local __runsmodulesdirs="${4:-RUNSMODULESDIRS}[@]" local __runsmodulesdirs="${4:-RUNSMODULESDIRS}[@]"
local __runshostsdirs="${5:-RUNSHOSTSDIRS}[@]" local __runshostsdirs="${5:-RUNSHOSTSDIRS}[@]"
local __runsext="${6:-.rs}"
local __domain __hostname local __domain __hostname
local __runsdir __runsfile local __runsdir __runsfile
@ -497,10 +504,12 @@ function runs_find_scriptfile() {
splithost "$__runshost" __hostname __domain splithost "$__runshost" __hostname __domain
for __runsdir in "${!__runshostsdirs}"; do for __runsdir in "${!__runshostsdirs}"; do
for __runsfile in \ for __runsfile in \
"$__runsdir/$__runshost/runs/$__scriptfile" \
"$__runsdir/$__domain/$__hostname/runs/$__scriptfile" \
"$__runsdir/$__runshost/$__scriptfile" \ "$__runsdir/$__runshost/$__scriptfile" \
"$__runsdir/$__domain/$__hostname/$__scriptfile"; do "$__runsdir/$__domain/$__hostname/$__scriptfile"; do
if [ ! -f "$__runsfile" -a -f "$__runsfile.rs" ]; then if [ "${__runsfile%$__runsext}" == "$__runsfile" ]; then
__runsfile="$__runsfile.rs" [ ! -f "$__runsfile" -a -f "$__runsfile$__runsext" ] && __runsfile="$__runsfile$__runsext"
fi fi
if [ -e "$__runsfile" ]; then if [ -e "$__runsfile" ]; then
runs_initvars "$__runsfile" "$__runsdir" "$__runsdirpath" "$__scriptfile" runs_initvars "$__runsfile" "$__runsdir" "$__runsdirpath" "$__scriptfile"
@ -512,8 +521,8 @@ function runs_find_scriptfile() {
# puis chercher dans les répertoires des scripts et des modules # puis chercher dans les répertoires des scripts et des modules
for __runsdir in "${!__runsscriptsdirs}" "${!__runsmodulesdirs}"; do for __runsdir in "${!__runsscriptsdirs}" "${!__runsmodulesdirs}"; do
__runsfile="$__runsdir/$__scriptfile" __runsfile="$__runsdir/$__scriptfile"
if [ ! -f "$__runsfile" -a -f "$__runsfile.rs" ]; then if [ "${__runsfile%$__runsext}" == "$__runsfile" ]; then
__runsfile="$__runsfile.rs" [ ! -f "$__runsfile" -a -f "$__runsfile$__runsext" ] && __runsfile="$__runsfile$__runsext"
fi fi
if [ -e "$__runsfile" ]; then if [ -e "$__runsfile" ]; then
runs_initvars "$__runsfile" "$__runsdir" "$__runsdir" "$__scriptfile" runs_initvars "$__runsfile" "$__runsdir" "$__runsdir" "$__scriptfile"
@ -541,6 +550,16 @@ function runs_find_scriptfile_reverse() {
if [ -n "$__runshost" ]; then if [ -n "$__runshost" ]; then
splithost "$__runshost" __hostname __domain splithost "$__runshost" __hostname __domain
for __runsdir in "${!__runshostsdirs}"; do for __runsdir in "${!__runshostsdirs}"; do
__prefix="$__runsdir/$__runshost/runs/"
if [ "${__runsscript#$__prefix}" != "$__runsscript" ]; then
runs_initvars "$__runsscript" "$__runsdir" "$__prefix" "${__runsscript#$__prefix/}"
return 0
fi
__prefix="$__runsdir/$__domain/$__hostname/runs/"
if [ "${__runsscript#$__prefix}" != "$__runsscript" ]; then
runs_initvars "$__runsscript" "$__runsdir" "$__prefix" "${__runsscript#$__prefix/}"
return 0
fi
__prefix="$__runsdir/$__runshost/" __prefix="$__runsdir/$__runshost/"
if [ "${__runsscript#$__prefix}" != "$__runsscript" ]; then if [ "${__runsscript#$__prefix}" != "$__runsscript" ]; then
runs_initvars "$__runsscript" "$__runsdir" "$__prefix" "${__runsscript#$__prefix/}" runs_initvars "$__runsscript" "$__runsdir" "$__prefix" "${__runsscript#$__prefix/}"
@ -613,10 +632,25 @@ function runs_recipe() {
recipe="$(abspath "$1")" recipe="$(abspath "$1")"
if [ -d "$recipe" ]; then if [ -d "$recipe" ]; then
if is_root; then if is_root; then
if [ -f "$recipe/default.rr" ]; then
recipe="$recipe/default.rr"
elif [ -f "$recipe/default" ]; then
recipe="$recipe/default" recipe="$recipe/default"
else else
recipe="$recipe/userdefault" recipe="$recipe/default.rr"
fi fi
else
if [ -f "$recipe/userdefault.rr" ]; then
recipe="$recipe/userdefault.rr"
elif [ -f "$recipe/userdefault" ]; then
recipe="$recipe/userdefault"
else
recipe="$recipe/userdefault.rr"
fi
fi
fi
if [ "${recipe%.rr}" == "$recipe" ]; then
[ ! -f "$recipe" -a -f "$recipe.rr" ] && recipe="$recipe.rr"
fi fi
if [ ! -f "$recipe" ]; then if [ ! -f "$recipe" ]; then
eerror "$(ppath "$recipe"): fichier introuvable" eerror "$(ppath "$recipe"): fichier introuvable"
@ -708,7 +742,7 @@ function runs_recipepath() {
# pas été trouvé, sinon retourner la valeur de retour de runs_recipe() # pas été trouvé, sinon retourner la valeur de retour de runs_recipe()
local RUNSDIR RUNSSCRIPT RUNSSCRIPTDIR RUNSSCRIPTNAME RUNSDIRPATH RUNSSCRIPTPATH local RUNSDIR RUNSSCRIPT RUNSSCRIPTDIR RUNSSCRIPTNAME RUNSDIRPATH RUNSSCRIPTPATH
local RUNSSCRIPTSDIRS RUNSMODULESDIRS RUNSHOSTSDIRS; __runs_setpath local RUNSSCRIPTSDIRS RUNSMODULESDIRS RUNSHOSTSDIRS; __runs_setpath
if ! runs_find_scriptfile "$1"; then if ! runs_find_scriptfile "$1" "" "" "" "" ".rr"; then
eerror "$1: fichier introuvable. Vérifiez les valeurs suivantes: eerror "$1: fichier introuvable. Vérifiez les valeurs suivantes:
RUNSSCRIPTSPATH=$RUNSSCRIPTSPATH RUNSSCRIPTSPATH=$RUNSSCRIPTSPATH
RUNSMODULESPATH=$RUNSMODULESPATH RUNSMODULESPATH=$RUNSMODULESPATH

2
runs
View File

@ -277,6 +277,8 @@ elif [ "$action" == "list" ]; then
rscriptpaths=() rscriptpaths=()
if [ -n "$runshost" ]; then if [ -n "$runshost" ]; then
for runsdir in "${RUNSHOSTSDIRS[@]}"; do for runsdir in "${RUNSHOSTSDIRS[@]}"; do
find_items rscriptpaths "$runsdir/$runshost/runs"
find_items rscriptpaths "$runsdir/$domain/$hostname/runs"
find_items rscriptpaths "$runsdir/$runshost" find_items rscriptpaths "$runsdir/$runshost"
find_items rscriptpaths "$runsdir/$domain/$hostname" find_items rscriptpaths "$runsdir/$domain/$hostname"
done done