From a2e863e2160ed1d45f3f321de1dfb74fd71aac86 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 9 Dec 2015 22:25:24 +0400 Subject: [PATCH 1/3] =?UTF-8?q?chercher=20aussi=20les=20scripts=20dans=20l?= =?UTF-8?q?e=20sous-r=C3=A9pertoire=20runs=20dans=20les=20r=C3=A9pertoires?= =?UTF-8?q?=20d'h=C3=B4te?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ulib/runs | 28 ++++++++++++++++++++++------ runs | 2 ++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/ulib/runs b/lib/ulib/runs index 69f7f4e..672bcf6 100644 --- a/lib/ulib/runs +++ b/lib/ulib/runs @@ -99,7 +99,7 @@ function runs_initdir() { # d'abord chercher si le répertoire existe déjà for runshostdir in "${RUNSHOSTSDIRS[@]}"; do 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 found=1 break @@ -121,18 +121,18 @@ function runs_initdir() { found= for dir in "$runshostdir/$host" "$runshostdir/$domain/$hostname"; do if [ -d "$dir" ]; then - runshostdir="$dir" + runshostdir="$dir/runs" found=1 break fi done - [ -n "$found" ] || runshostdir="$runshostdir/$host" + [ -n "$found" ] || runshostdir="$runshostdir/$host/runs" else - runshostdir="${RUNSHOSTSDIRS[0]}/$host" + runshostdir="${RUNSHOSTSDIRS[0]}/$host/runs" fi else host="$hostname" - runshostdir="${RUNSHOSTSDIRS[0]}/$host" + runshostdir="${RUNSHOSTSDIRS[0]}/$host/runs" fi local rscriptt runsconft sysinfost defaultt configt servicest @@ -241,7 +241,7 @@ function runs_create_rscript() { splithost "$host" hostname domain for runsdir in "${RUNSHOSTSDIRS[@]}"; do 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 runsdir="$dir" found=1 @@ -370,6 +370,8 @@ function runs_find_hostfile() { splithost "$__runshost" __hostname __domain for __runsdir in "${!__runshostsdirs}"; do for __runsfile in \ + "$__runsdir/$__runshost/runs/$__hostfile" \ + "$__runsdir/$__domain/$__hostname/runs/$__hostfile"\ "$__runsdir/$__runshost/$__hostfile" \ "$__runsdir/$__domain/$__hostname/$__hostfile"; do if [ -e "$__runsfile" ]; then @@ -417,6 +419,8 @@ function runs_find_datafile() { splithost "$__runshost" __hostname __domain for __runsdir in "${!__runshostsdirs}"; do for __runsfile in \ + "$__runsdir/$__runshost/runs/$__datafile" \ + "$__runsdir/$__domain/$__hostname/runs/$__datafile"\ "$__runsdir/$__runshost/$__datafile" \ "$__runsdir/$__domain/$__hostname/$__datafile"; do if [ -e "$__runsfile" ]; then @@ -497,6 +501,8 @@ function runs_find_scriptfile() { splithost "$__runshost" __hostname __domain for __runsdir in "${!__runshostsdirs}"; do for __runsfile in \ + "$__runsdir/$__runshost/runs/$__scriptfile" \ + "$__runsdir/$__domain/$__hostname/runs/$__scriptfile" \ "$__runsdir/$__runshost/$__scriptfile" \ "$__runsdir/$__domain/$__hostname/$__scriptfile"; do if [ ! -f "$__runsfile" -a -f "$__runsfile.rs" ]; then @@ -541,6 +547,16 @@ function runs_find_scriptfile_reverse() { if [ -n "$__runshost" ]; then splithost "$__runshost" __hostname __domain 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/" if [ "${__runsscript#$__prefix}" != "$__runsscript" ]; then runs_initvars "$__runsscript" "$__runsdir" "$__prefix" "${__runsscript#$__prefix/}" diff --git a/runs b/runs index 9fdea23..329c09c 100755 --- a/runs +++ b/runs @@ -277,6 +277,8 @@ elif [ "$action" == "list" ]; then rscriptpaths=() if [ -n "$runshost" ]; then 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/$domain/$hostname" done From 98ba6268979e1402fa955d5b77115ae7548de7ab Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 9 Dec 2015 22:34:35 +0400 Subject: [PATCH 2/3] =?UTF-8?q?les=20recettes=20ont=20maintenant=20l'exten?= =?UTF-8?q?sion=20.rr=20par=20d=C3=A9faut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ulib/runs | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/lib/ulib/runs b/lib/ulib/runs index 672bcf6..481816e 100644 --- a/lib/ulib/runs +++ b/lib/ulib/runs @@ -158,24 +158,24 @@ function runs_initdir() { echo "$sysinfost" >"$runshostdir/sysinfos.conf" fi if [ ! -f "$runshostdir/default" ]; then - estep "Création de $(ppath "$runshostdir/default")" - echo "$defaultt" >"$runshostdir/default" + estep "Création de $(ppath "$runshostdir/default.rr")" + echo "$defaultt" >"$runshostdir/default.rr" edit_default=1 fi if [ ! -f "$runshostdir/config" ]; then - estep "Création de $(ppath "$runshostdir/config")" - echo "$configt" >"$runshostdir/config" + estep "Création de $(ppath "$runshostdir/config.rr")" + echo "$configt" >"$runshostdir/config.rr" fi if [ ! -f "$runshostdir/services" ]; then - estep "Création de $(ppath "$runshostdir/services")" - echo "$servicest" >"$runshostdir/services" + estep "Création de $(ppath "$runshostdir/services.rr")" + echo "$servicest" >"$runshostdir/services.rr" fi if [ ! -f "$runshostdir/userdefault" ]; then - estep "Création de $(ppath "$runshostdir/userdefault")" - echo "$userdefaultt" >"$runshostdir/userdefault" + estep "Création de $(ppath "$runshostdir/userdefault.rr")" + echo "$userdefaultt" >"$runshostdir/userdefault.rr" fi - [ -n "$edit_default" ] && "${EDITOR:-vi}" "$runshostdir/default" + [ -n "$edit_default" ] && "${EDITOR:-vi}" "$runshostdir/default.rr" return 0 } @@ -189,9 +189,9 @@ function __runs_create_rscript() { template="$runsconft" elif [ "$rscriptname" == "sysinfos.conf" ]; then template="$sysinfost" - elif [ "$rscriptname" == "default" ]; then + elif [ "$rscriptname" == "default" -o "$rscriptname" == "default.rr" ]; then template="$defaultt" - elif [ "$rscriptname" == "userdefault" ]; then + elif [ "$rscriptname" == "userdefault" -o "$rscriptname" == "userdefault.rr" ]; then template="$userdefaultt" else withext "$rscript" || rscript="$rscript.rs" @@ -629,11 +629,24 @@ function runs_recipe() { recipe="$(abspath "$1")" if [ -d "$recipe" ]; then if is_root; then - recipe="$recipe/default" + if [ -f "$recipe/default.rr" ]; then + recipe="$recipe/default.rr" + elif [ -f "$recipe/default" ]; then + recipe="$recipe/default" + else + recipe="$recipe/default.rr" + fi else - recipe="$recipe/userdefault" + 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 + [ ! -f "$recipe" -a -f "$recipe.rr" ] && recipe="$recipe.rr" if [ ! -f "$recipe" ]; then eerror "$(ppath "$recipe"): fichier introuvable" return 1 @@ -724,6 +737,14 @@ function runs_recipepath() { # pas été trouvé, sinon retourner la valeur de retour de runs_recipe() local RUNSDIR RUNSSCRIPT RUNSSCRIPTDIR RUNSSCRIPTNAME RUNSDIRPATH RUNSSCRIPTPATH local RUNSSCRIPTSDIRS RUNSMODULESDIRS RUNSHOSTSDIRS; __runs_setpath + if [ "${1%.rr}" == "$1" ]; then + # essayer d'abord avec l'extension .rr + if runs_find_scriptfile "$1"; then + runs_recipe "$RUNSSCRIPT" + return $? + fi + fi + if ! runs_find_scriptfile "$1"; then eerror "$1: fichier introuvable. Vérifiez les valeurs suivantes: RUNSSCRIPTSPATH=$RUNSSCRIPTSPATH From 35eadc17afc634e1b1cac0c6a21f327247227bda Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 9 Dec 2015 22:54:06 +0400 Subject: [PATCH 3/3] correction d'un bug avec la recherche d'un fichier de recette --- lib/ulib/runs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/ulib/runs b/lib/ulib/runs index 481816e..76091ff 100644 --- a/lib/ulib/runs +++ b/lib/ulib/runs @@ -479,6 +479,8 @@ function runs_find_scriptfile() { # initialiser les variables RUNSDIR, RUNSSCRIPT, RUNSSCRIPTDIR, # RUNSSCRIPTNAME, RUNSDIRPATH et RUNSSCRIPTPATH. Retourner 0 en cas de # 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 # valeurs fournies dans les tableaux RUNSSCRIPTSDIRS, RUNSMODULESDIRS, # RUNSHOSTSDIRS), RUNSDIRPATH est le répertoire à partir duquel est exprimé @@ -493,6 +495,7 @@ function runs_find_scriptfile() { local __runsscriptsdirs="${3:-RUNSSCRIPTSDIRS}[@]" local __runsmodulesdirs="${4:-RUNSMODULESDIRS}[@]" local __runshostsdirs="${5:-RUNSHOSTSDIRS}[@]" + local __runsext="${6:-.rs}" local __domain __hostname local __runsdir __runsfile @@ -505,8 +508,8 @@ function runs_find_scriptfile() { "$__runsdir/$__domain/$__hostname/runs/$__scriptfile" \ "$__runsdir/$__runshost/$__scriptfile" \ "$__runsdir/$__domain/$__hostname/$__scriptfile"; do - if [ ! -f "$__runsfile" -a -f "$__runsfile.rs" ]; then - __runsfile="$__runsfile.rs" + if [ "${__runsfile%$__runsext}" == "$__runsfile" ]; then + [ ! -f "$__runsfile" -a -f "$__runsfile$__runsext" ] && __runsfile="$__runsfile$__runsext" fi if [ -e "$__runsfile" ]; then runs_initvars "$__runsfile" "$__runsdir" "$__runsdirpath" "$__scriptfile" @@ -518,8 +521,8 @@ function runs_find_scriptfile() { # puis chercher dans les répertoires des scripts et des modules for __runsdir in "${!__runsscriptsdirs}" "${!__runsmodulesdirs}"; do __runsfile="$__runsdir/$__scriptfile" - if [ ! -f "$__runsfile" -a -f "$__runsfile.rs" ]; then - __runsfile="$__runsfile.rs" + if [ "${__runsfile%$__runsext}" == "$__runsfile" ]; then + [ ! -f "$__runsfile" -a -f "$__runsfile$__runsext" ] && __runsfile="$__runsfile$__runsext" fi if [ -e "$__runsfile" ]; then runs_initvars "$__runsfile" "$__runsdir" "$__runsdir" "$__scriptfile" @@ -646,7 +649,9 @@ function runs_recipe() { fi fi fi - [ ! -f "$recipe" -a -f "$recipe.rr" ] && recipe="$recipe.rr" + if [ "${recipe%.rr}" == "$recipe" ]; then + [ ! -f "$recipe" -a -f "$recipe.rr" ] && recipe="$recipe.rr" + fi if [ ! -f "$recipe" ]; then eerror "$(ppath "$recipe"): fichier introuvable" return 1 @@ -737,15 +742,7 @@ function runs_recipepath() { # pas été trouvé, sinon retourner la valeur de retour de runs_recipe() local RUNSDIR RUNSSCRIPT RUNSSCRIPTDIR RUNSSCRIPTNAME RUNSDIRPATH RUNSSCRIPTPATH local RUNSSCRIPTSDIRS RUNSMODULESDIRS RUNSHOSTSDIRS; __runs_setpath - if [ "${1%.rr}" == "$1" ]; then - # essayer d'abord avec l'extension .rr - if runs_find_scriptfile "$1"; then - runs_recipe "$RUNSSCRIPT" - return $? - fi - fi - - if ! runs_find_scriptfile "$1"; then + if ! runs_find_scriptfile "$1" "" "" "" "" ".rr"; then eerror "$1: fichier introuvable. Vérifiez les valeurs suivantes: RUNSSCRIPTSPATH=$RUNSSCRIPTSPATH RUNSMODULESPATH=$RUNSMODULESPATH