From 409e4062f1dbe4de9c3ec0b8c8be4e418d44c1c7 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Tue, 24 May 2016 12:32:51 +0400 Subject: [PATCH 01/11] =?UTF-8?q?pr=C3=A9parer=20impl=C3=A9mentation=20de?= =?UTF-8?q?=20%n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ulib/runsmod.defaults | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ulib/runsmod.defaults b/lib/ulib/runsmod.defaults index cdf6fb7..cb5585c 100644 --- a/lib/ulib/runsmod.defaults +++ b/lib/ulib/runsmod.defaults @@ -12,7 +12,7 @@ RUNSMOD_UPDATE=auto RUNSMOD_IDENTITY= RUNSMOD_BASEURL= RUNSMOD_SCRIPTS_URLS=(hosts/%h/runs hosts/%h/all//runs runss) -RUNSMOD_MODULES_URLS=(hosts/%h/modules/%m hosts/%h/all modules/%m) +RUNSMOD_MODULES_URLS=(hosts/%h/modules/%m hosts/%h/all hosts/all/%n/%m modules/%m) RUNSMOD_HOSTS_URLS=(runsh) RUNSMOD_BASEDIR="$HOME/runs" RUNSMOD_PROFILES=(pvcs vcs jclain) From 55c57551ebb6dc87cfc881ff8d81efc661a753c9 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 25 May 2016 20:24:12 +0400 Subject: [PATCH 02/11] support de //...%h... --- lib/ulib/runsmod | 65 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/lib/ulib/runsmod b/lib/ulib/runsmod index 4f8b491..89642d5 100644 --- a/lib/ulib/runsmod +++ b/lib/ulib/runsmod @@ -364,9 +364,8 @@ function runsmod_clone_or_pull() { host="$host.$RUNSDOMAIN" enote "Autocorrection du nom d'hôte en $host" fi - #XXX implémenter all_hosts=1 - local -a repolist reponames repourls + local -a repolist reposuffixes reponames repourls local RUNSMOD_PROFILE baseurl repopath repolistfile local vprefix repospec reposuffix reponame repourl repodir module moduledir local r=0 @@ -392,6 +391,21 @@ function runsmod_clone_or_pull() { reposuffix="${repospec#*//}" [ -n "$reposuffix" ] && reposuffix="/$reposuffix" repospec="${repospec%%//*}" + if __runsmod_has_vhost "$reposuffix"; then + if [ -n "$all_hosts" -o -z "$host" ]; then + reposuffix="${reposuffix//%h\//}" + reposuffix="${reposuffix//\/%h/}" + reposuffixes=("$reposuffix") + elif [ -n "$host" ]; then + local rs1 rs2 + setx rs1=__runsmod_replace1 "$reposuffix" "$host" + setx rs2=__runsmod_replace2 "$reposuffix" "$host" + reposuffixes=("$rs1") + [ "$rs2" != "$rs1" ] && array_add reposuffixes "$rs2" + fi + else + reposuffixes=("$reposuffix") + fi else reposuffix= fi @@ -422,12 +436,13 @@ function runsmod_clone_or_pull() { array_contains REPODIRS "$repodir" && continue array_addu REPODIRS "$repodir" - repodir="$repodir$reposuffix" - case "$vprefix" in - SCRIPTS) array_addu SCRIPTSDIRS "$repodir";; - MODULES) array_addu MODULESDIRS "$repodir";; - HOSTS) array_addu HOSTSDIRS "$repodir";; - esac + for reposuffix in "${reposuffixes[@]}"; do + case "$vprefix" in + SCRIPTS) array_addu SCRIPTSDIRS "$repodir$reposuffix";; + MODULES) array_addu MODULESDIRS "$repodir$reposuffix";; + HOSTS) array_addu HOSTSDIRS "$repodir$reposuffix";; + esac + done done done done @@ -471,6 +486,21 @@ function runsmod_clone_or_pull() { reposuffix="${repospec#*//}" [ -n "$reposuffix" ] && reposuffix="/$reposuffix" repospec="${repospec%%//*}" + if __runsmod_has_vhost "$reposuffix"; then + if [ -n "$all_hosts" -o -z "$host" ]; then + reposuffix="${reposuffix//%h\//}" + reposuffix="${reposuffix//\/%h/}" + reposuffixes=("$reposuffix") + elif [ -n "$host" ]; then + local rs1 rs2 + setx rs1=__runsmod_replace1 "$reposuffix" "$host" + setx rs2=__runsmod_replace2 "$reposuffix" "$host" + reposuffixes=("$rs1") + [ "$rs2" != "$rs1" ] && array_add reposuffixes "$rs2" + fi + else + reposuffixes=("$reposuffix") + fi else reposuffix= fi @@ -517,15 +547,16 @@ function runsmod_clone_or_pull() { array_addu REPODIRS "$repodir" [ -z "$all_modules" ] && array_addu foundmodules "$module" - repodir="$repodir$reposuffix" - case "$vprefix" in - SCRIPTS) array_addu SCRIPTSDIRS "$repodir";; - MODULES) - setx moduledir=dirname -- "$repodir" - array_addu MODULESDIRS "$moduledir" - ;; - HOSTS) array_addu HOSTSDIRS "$repodir";; - esac + for reposuffix in "${reposuffixes[@]}"; do + case "$vprefix" in + SCRIPTS) array_addu SCRIPTSDIRS "$repodir$reposuffix";; + MODULES) + setx moduledir=dirname -- "$repodir$reposuffix" + array_addu MODULESDIRS "$moduledir" + ;; + HOSTS) array_addu HOSTSDIRS "$repodir$reposuffix";; + esac + done done done done From 30e5ddabbbd794c1a957a7dab2e3570bb27b36c9 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 1 Jun 2016 12:07:37 +0400 Subject: [PATCH 03/11] =?UTF-8?q?runs=20et=20rruns:=20am=C3=A9liorer=20le?= =?UTF-8?q?=20calcul=20des=20chemins?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/default/runs | 3 +++ lib/ulib/runs | 1 + rruns | 51 ++++++++++++++++++++++++++++-------- runs | 67 ++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 102 insertions(+), 20 deletions(-) diff --git a/lib/default/runs b/lib/default/runs index d92fb23..5036122 100644 --- a/lib/default/runs +++ b/lib/default/runs @@ -2,12 +2,15 @@ # Liste des répertoires à considérer pour la recherche de scripts runs #RUNSSCRIPTSPATH= +#RUNSSCRIPTSDIRS=() # Liste des répertoires à considérer pour la recherche de modules installables #RUNSMODULESPATH= +#RUNSMODULESDIRS=() # Liste des répertoires à considérer pour la recherche de répertoires d'hôtes #RUNSHOSTSPATH= +#RUNSHOSTSDIRS=() # Liste des domaines à rechercher, si un hôte déjà configuré est donné sans # domaine. Si cette liste est vide, le fichier /etc/resolv.conf est consulté diff --git a/lib/ulib/runs b/lib/ulib/runs index 7b3b0b1..30cfde8 100644 --- a/lib/ulib/runs +++ b/lib/ulib/runs @@ -900,6 +900,7 @@ exit 0 set_var "$runspath" "$(array_join runsdirs :)" done # XXX quelles autres variables doivent être corrigées? + # XXX ==> il faut rajouter rscripts et recipes fi elif [ -n "$runsworkdir" ]; then RUNSWORKDIR="$runsworkdir" diff --git a/rruns b/rruns index 0920594..a1c4c3e 100755 --- a/rruns +++ b/rruns @@ -74,7 +74,21 @@ OPTIONS argument (hors options)." } +RUNSSCRIPTSPATH= +RUNSSCRIPTSDIRS=() +RUNSMODULESPATH= +RUNSMODULESDIRS=() +RUNSHOSTSPATH= +RUNSHOSTSDIRS=() +RUNSDOMAINS=() +RUNSDOMAIN= set_defaults runs +[ -n "$RUNSSCRIPTSPATH" ] && RUNSSCRIPTSDIRS=("$RUNSSCRIPTSPATH" "${RUNSSCRIPTSDIRS[@]}") +array_fix_paths RUNSSCRIPTSDIRS; setx RUNSSCRIPTSPATH=array_to_path RUNSSCRIPTSDIRS +[ -n "$RUNSMODULESPATH" ] && RUNSMODULESDIRS=("$RUNSMODULESPATH" "${RUNSMODULESDIRS[@]}") +array_fix_paths RUNSMODULESDIRS; setx RUNSMODULESPATH=array_to_path RUNSMODULESDIRS +[ -n "$RUNSHOSTSPATH" ] && RUNSHOSTSDIRS=("$RUNSHOSTSPATH" "${RUNSHOSTSDIRS[@]}") +array_fix_paths RUNSHOSTSDIRS; setx RUNSHOSTSPATH=array_to_path RUNSHOSTSDIRS action=deploy confuser= @@ -89,8 +103,11 @@ init=auto init_sysinfos= sysinfos_data= runsscriptspath= +runsscriptsdirs=() runsmodulespath= +runsmodulesdirs=() runshostspath= +runshostsdirs=() parse_opts "${PRETTYOPTS[@]}" \ --help '$exit_with display_help' \ -C action=configure \ @@ -107,13 +124,25 @@ parse_opts "${PRETTYOPTS[@]}" \ --no-init init= \ --sysinfos init_sysinfos=1 \ --runsscriptspath: runsscriptspath= \ + --runsscriptsdir: runsscriptsdirs \ --runsmodulespath: runsmodulespath= \ + --runsmodulesdir: runsmodulesdirs \ --runshostspath: runshostspath= \ + --runshostsdir: runshostsdirs \ @ args -- "$@" && set -- "${args[@]}" || die "$args" +[ -n "$runsscriptspath" ] && runsscriptsdirs=("$runsscriptspath" "${runsscriptsdirs[@]}") +array_fix_paths runsscriptsdirs; setx runsscriptspath=array_to_path runsscriptsdirs [ -n "$runsscriptspath" ] && RUNSSCRIPTSPATH="$runsscriptspath" +[ -n "$runsmodulespath" ] && runsmodulesdirs=("$runsmodulespath" "${runsmodulesdirs[@]}") +array_fix_paths runsmodulesdirs; setx runsmodulespath=array_to_path runsmodulesdirs [ -n "$runsmodulespath" ] && RUNSMODULESPATH="$runsmodulespath" +[ -n "$runshostspath" ] && runshostsdirs=("$runshostspath" "${runshostsdirs[@]}") +array_fix_paths runshostsdirs; setx runshostspath=array_to_path runshostsdirs [ -n "$runshostspath" ] && RUNSHOSTSPATH="$runshostspath" +[ -n "$RUNSSCRIPTSPATH" ] || RUNSSCRIPTSPATH=: +[ -n "$RUNSMODULESPATH" ] || RUNSMODULESPATH=: +[ -n "$RUNSHOSTSPATH" ] || RUNSHOSTSPATH=: __PARSED_HOSTS=() __PARSED_FILES=() @@ -204,11 +233,12 @@ if [ "$action" == "configure" ]; then ${tmproot:+--tmproot "$tmproot"} ${SSH:+-S "$SSH"} \ ${force_make_archive:+--force-make-archive} \ -h "$user@$host" || continue + etitle "Configuration initiale pour runs" \ "$scriptdir/runs" \ - ${runsscriptspath:+--runsscriptspath "$runsscriptspath"} \ - ${runsmodulespath:+--runsmodulespath "$runsmodulespath"} \ - ${runshostspath:+--runshostspath "$runshostspath"} \ + --runsscriptspath "$RUNSSCRIPTSPATH" \ + --runsmodulespath "$RUNSMODULESPATH" \ + --runshostspath "$RUNSHOSTSPATH" \ --init -h "$host" done exit 0 @@ -299,9 +329,9 @@ for userhost in "${hosts[@]}"; do estep "Vérification de la configuration de l'hôte pour runs" "$scriptdir/runs" \ - ${runsscriptspath:+--runsscriptspath "$runsscriptspath"} \ - ${runsmodulespath:+--runsmodulespath "$runsmodulespath"} \ - ${runshostspath:+--runshostspath "$runshostspath"} \ + --runsscriptspath "$RUNSSCRIPTSPATH" \ + --runsmodulespath "$RUNSMODULESPATH" \ + --runshostspath "$RUNSHOSTSPATH" \ $action -h "$host" || { eend; continue; } fi @@ -317,10 +347,11 @@ for userhost in "${hosts[@]}"; do # Création de l'export etitle "Préparation de l'export" - args=(--export --runsexportdir "$exportdir" - ${runsscriptspath:+--runsscriptspath "$runsscriptspath"} - ${runsmodulespath:+--runsmodulespath "$runsmodulespath"} - ${runshostspath:+--runshostspath "$runshostspath"} + args=( + --export --runsexportdir "$exportdir" + --runsscriptspath "$RUNSSCRIPTSPATH" + --runsmodulespath "$RUNSMODULESPATH" + --runshostspath "$RUNSHOSTSPATH" ) [ "$host" != "localhost" ] && args=("${args[@]}" -h "$host") [ -n "$runsreset" ] && args=("${args[@]}" -z) diff --git a/runs b/runs index 329c09c..0378e0b 100755 --- a/runs +++ b/runs @@ -58,11 +58,28 @@ Gestion des scripts -z Forcer la réinstallation des scripts qui se basent sur shouldrun/setdone" } +RUNSSCRIPTSPATH= +RUNSSCRIPTSDIRS=() +RUNSMODULESPATH= +RUNSMODULESDIRS=() +RUNSHOSTSPATH= +RUNSHOSTSDIRS=() +RUNSDOMAINS=() +RUNSDOMAIN= set_defaults runs +[ -n "$RUNSSCRIPTSPATH" ] && RUNSSCRIPTSDIRS=("$RUNSSCRIPTSPATH" "${RUNSSCRIPTSDIRS[@]}") +array_fix_paths RUNSSCRIPTSDIRS; setx RUNSSCRIPTSPATH=array_to_path RUNSSCRIPTSDIRS +[ -n "$RUNSMODULESPATH" ] && RUNSMODULESDIRS=("$RUNSMODULESPATH" "${RUNSMODULESDIRS[@]}") +array_fix_paths RUNSMODULESDIRS; setx RUNSMODULESPATH=array_to_path RUNSMODULESDIRS +[ -n "$RUNSHOSTSPATH" ] && RUNSHOSTSDIRS=("$RUNSHOSTSPATH" "${RUNSHOSTSDIRS[@]}") +array_fix_paths RUNSHOSTSDIRS; setx RUNSHOSTSPATH=array_to_path RUNSHOSTSDIRS function runs_path_required() { die "Vous devez définir $1 dans ~/etc/default/runs" } +function runs_path_undefined() { + ewarn "La variable $1 n'est pas définie dans ~/etc/default/runs" +} action=runs create_verbose= @@ -77,8 +94,11 @@ runssysdist= runssysver= runsbits= runsscriptspath= +runsscriptsdirs=() runsmodulespath= +runsmodulesdirs=() runshostspath= +runshostsdirs=() runsexportdir= # répertoire dans lequel exporter les fichiers runsworkdir= # si runsexportdir n'est pas spécifié, répertoire de travail runsvarsfile= # fichier contenant des définitions à charger @@ -106,16 +126,25 @@ parse_opts "${PRETTYOPTS[@]}" \ --sysver: runssysver= \ --bits: runsbits= \ --runsscriptspath: runsscriptspath= \ + --runsscriptsdir: runsscriptsdirs \ --runsmodulespath: runsmodulespath= \ + --runsmodulesdir: runsmodulesdirs \ --runshostspath: runshostspath= \ + --runshostsdir: runshostsdirs \ --runsexportdir: runsexportdir= \ --runsworkdir: runsworkdir= \ --runsvarsfile: runsvarsfile= \ -z RUNSRESET=1 \ @ args -- "$@" && set -- "${args[@]}" || die "$args" +[ -n "$runsscriptspath" ] && runsscriptsdirs=("$runsscriptspath" "${runsscriptsdirs[@]}") +array_fix_paths runsscriptsdirs; setx runsscriptspath=array_to_path runsscriptsdirs [ -n "$runsscriptspath" ] && RUNSSCRIPTSPATH="$runsscriptspath" +[ -n "$runsmodulespath" ] && runsmodulesdirs=("$runsmodulespath" "${runsmodulesdirs[@]}") +array_fix_paths runsmodulesdirs; setx runsmodulespath=array_to_path runsmodulesdirs [ -n "$runsmodulespath" ] && RUNSMODULESPATH="$runsmodulespath" +[ -n "$runshostspath" ] && runshostsdirs=("$runshostspath" "${runshostsdirs[@]}") +array_fix_paths runshostsdirs; setx runshostspath=array_to_path runshostsdirs [ -n "$runshostspath" ] && RUNSHOSTSPATH="$runshostspath" if [ "$action" == runs \ @@ -171,6 +200,9 @@ if ! is_root && [ -n "$run_as_root" ]; then for recipe in "${recipes[@]}"; do args=("${args[@]}" -r "$recipe") done + [ -n "$RUNSSCRIPTSPATH" ] || RUNSSCRIPTSPATH=: + [ -n "$RUNSMODULESPATH" ] || RUNSMODULESPATH=: + [ -n "$RUNSHOSTSPATH" ] || RUNSHOSTSPATH=: args=("${args[@]}" ${runshost:+-h "$runshost"} ${runssysname:+--sysname "$runssysname"} ${runssysdist:+--sysdist "$runssysdist"} ${runssysver:+--sysver "$runssysver"} ${runsbits:+--bits "$runsbits"} ${RUNSSCRIPTSPATH:+--runsscriptspath "$RUNSSCRIPTSPATH"} @@ -220,8 +252,8 @@ bits=$MYBITS" ################################################################################ elif [ "$action" == "create" ]; then + __runs_setpath if [ -n "$runshost" ]; then - __runs_setpath [ -n "${RUNSHOSTSDIRS[*]}" ] || runs_path_required RUNSHOSTSPATH etitle "$runshost" runs_initdir "$runshost" "$create_verbose" fi @@ -267,9 +299,9 @@ elif [ "$action" == "list" ]; then } __runs_setpath - [ -n "${RUNSSCRIPTSDIRS[*]}" ] || runs_path_required RUNSSCRIPTSPATH - [ -n "${RUNSMODULESDIRS[*]}" ] || runs_path_required RUNSMODULESPATH - [ -z "$runshost" -o -n "${RUNSHOSTSDIRS[*]}" ] || runs_path_required RUNSHOSTSPATH + [ -n "${RUNSSCRIPTSDIRS[*]}" ] || runs_path_undefined RUNSSCRIPTSPATH + [ -n "${RUNSMODULESDIRS[*]}" ] || runs_path_undefined RUNSMODULESPATH + [ -z "$runshost" -o -n "${RUNSHOSTSDIRS[*]}" ] || runs_path_undefined RUNSHOSTSPATH splithost "$runshost" hostname domain @@ -310,12 +342,27 @@ elif [ "$action" == "list" ]; then ################################################################################ elif [ "$action" == "runs" ]; then - if [ -n "${rscripts[*]}" ]; then - # sans l'option -f, il faut définir RUNS*PATH - __runs_setpath - [ -n "${RUNSSCRIPTSDIRS[*]}" ] || runs_path_required RUNSSCRIPTSPATH - [ -n "${RUNSMODULESDIRS[*]}" ] || runs_path_required RUNSMODULESPATH - [ -z "$runshost" -o -n "${RUNSHOSTSDIRS[*]}" ] || runs_path_required RUNSHOSTSPATH + __runs_setpath + if [ -z "${rscripts[*]}" -a -z "${recipes[*]}" ]; then + # sans les options -f et -r, prendre par défaut le répertoire courant + # comme répertoire de script, de module et d'hôtes + refix= + [ -n "${RUNSSCRIPTSDIRS[*]}" ] || { + runs_path_undefined RUNSSCRIPTSPATH + setx RUNSSCRIPTSPATH=pwd + refix=1 + } + [ -n "${RUNSMODULESDIRS[*]}" ] || { + runs_path_undefined RUNSMODULESPATH + setx RUNSMODULESPATH=pwd + refix=1 + } + [ -z "$runshost" -o -n "${RUNSHOSTSDIRS[*]}" ] || { + runs_path_undefined RUNSHOSTSPATH + setx RUNSHOSTSPATH=pwd + refix=1 + } + [ -n "$refix" ] && __runs_setpath fi # initialisation From 4b212d85ba9e798140421f278ca2faaa7e9f4174 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Tue, 30 Aug 2016 14:11:54 +0400 Subject: [PATCH 04/11] ne pas utiliser %n tout de suite --- lib/ulib/runsmod.defaults | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/ulib/runsmod.defaults b/lib/ulib/runsmod.defaults index cb5585c..cace3f9 100644 --- a/lib/ulib/runsmod.defaults +++ b/lib/ulib/runsmod.defaults @@ -12,7 +12,9 @@ RUNSMOD_UPDATE=auto RUNSMOD_IDENTITY= RUNSMOD_BASEURL= RUNSMOD_SCRIPTS_URLS=(hosts/%h/runs hosts/%h/all//runs runss) -RUNSMOD_MODULES_URLS=(hosts/%h/modules/%m hosts/%h/all hosts/all/%n/%m modules/%m) +RUNSMOD_MODULES_URLS=(hosts/%h/modules/%m hosts/%h/all modules/%m) +# quand on supportera %n +#RUNSMOD_MODULES_URLS=(hosts/%h/modules/%m hosts/%h/all hosts/all/%n/%m modules/%m) RUNSMOD_HOSTS_URLS=(runsh) RUNSMOD_BASEDIR="$HOME/runs" RUNSMOD_PROFILES=(pvcs vcs jclain) From 96afb2a10fe5d9ae7a1ccc9edc7ff360104e13a4 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Tue, 30 Aug 2016 16:15:25 +0400 Subject: [PATCH 05/11] =?UTF-8?q?mapping=20des=20r=C3=A9pertoires=20de=20d?= =?UTF-8?q?estination?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ulib/runsmod | 380 +++++++++++++++++++++----------------- lib/ulib/runsmod.defaults | 20 ++ 2 files changed, 230 insertions(+), 170 deletions(-) diff --git a/lib/ulib/runsmod b/lib/ulib/runsmod index 89642d5..017545e 100644 --- a/lib/ulib/runsmod +++ b/lib/ulib/runsmod @@ -137,6 +137,27 @@ function __runsmod_fixurl() { echo "$url$1" } +function __runsmod_mapdir() { + # mapper le répertoire $1, avec $2 est le répertoire de base à partir + # desquels les mappings sont définis + local dir="$1" basedir="$2" + local -a maps + local map from to + dir="${dir#$basedir/}" + __runsmod_get -a maps MAP + for map in "${maps[@]}"; do + splitpair "$map" from to + if [ "$dir" == "$from" ]; then + echo "$to" + return + elif [ "${dir#$from/}" != "$dir" ]; then + echo "$to/${dir#$from/}" + return + fi + done + echo "$dir" +} + function __runsmod_getpath_from_baseurl() { # obtenir le nom correspond à un url de base, utilisable dans un chemin local url="$1" scheme path userhost user host dummy @@ -220,18 +241,23 @@ function runsmod_should_update_repolists() { # tester s'il faut mettre à jour au moins un des fichiers contenant les # listes des dépôts local RUNSMOD_PROFILE - local now baseurl repobase repopath repolistfile mtime - local -a urls + local now baseurl have_repolistfile repolistfile mtime + local -a baseurls setx now=date +%s for RUNSMOD_PROFILE in "${RUNSMOD_PROFILES[@]}"; do - setx baseurl=__runsmod_get BASEURL || continue - setx repolistfile=__runsmod_get_repolistfile "$baseurl" - - # si le fichier n'existe pas, il faut mettre à jour - [ -f "$repolistfile" ] || return 0 - # si le fichier a été modifié depuis plus de 24 heures, mettre à jour - setx mtime=stat -c %Y "$repolistfile" - [ $(($now - $mtime)) -lt 86400 ] || return 0 + __runsmod_get -a baseurls BASEURL + have_repolistfile= + for baseurl in "${baseurls[@]}"; do + setx repolistfile=__runsmod_get_repolistfile "$baseurl" + if [ -f "$repolistfile" ]; then + have_repolistfile=1 + # si le fichier a été modifié depuis plus de 24 heures, mettre à jour + setx mtime=stat -c %Y "$repolistfile" + [ $(($now - $mtime)) -lt 86400 ] || return 0 + fi + done + # si aucun des fichiers n'existe, il faut mettre à jour + [ -n "$have_repolistfile" ] || return 0 done return 1 } @@ -241,34 +267,42 @@ function runsmod_update_repolists() { # Si $1 n'est pas vide, forcer la mise à jour de tous les fichiers local force="$1"; shift local RUNSMOD_PROFILE - local now baseurl repobase repopath repo mtime update - local -a urls + local now baseurl repobase repopath repo mtime update error + local -a baseurls setx now=date +%s for RUNSMOD_PROFILE in "${RUNSMOD_PROFILES[@]}"; do - setx baseurl=__runsmod_get BASEURL || continue - setx repolistfile=__runsmod_get_repolistfile "$baseurl" + __runsmod_get -a baseurls BASEURL + for baseurl in "${baseurls[@]}"; do + setx repolistfile=__runsmod_get_repolistfile "$baseurl" - update="$force" - if [ -z "$update" ]; then - # si le fichier n'existe pas, il faut mettre à jour - [ -f "$repolistfile" ] || update=1 - fi - if [ -z "$update" ]; then - # si le fichier a été modifié depuis plus de 24 heures, mettre à jour - setx mtime=stat -c %Y "$repolistfile" - [ $(($now - $mtime)) -lt 86400 ] || update=1 - fi - if [ -n "$update" ]; then - local list - ebegin "$baseurl" - if setx list=__runsmod_getinfo "$baseurl"; then - echo "$list" | __runsmod_fixinfo >"$repolistfile" - edot 0 - else - edot 1 + update="$force" + if [ -z "$update" ]; then + # si le fichier n'existe pas, il faut mettre à jour + [ -f "$repolistfile" ] || update=1 fi - eend - fi + if [ -z "$update" ]; then + # si le fichier a été modifié depuis plus de 24 heures, mettre à jour + setx mtime=stat -c %Y "$repolistfile" + [ $(($now - $mtime)) -lt 86400 ] || update=1 + fi + + error= + if [ -n "$update" ]; then + local list + ebegin "$baseurl" + if setx list=__runsmod_getinfo "$baseurl"; then + echo "$list" | __runsmod_fixinfo >"$repolistfile" + edot 0 + else + error=1 + edot 1 + fi + eend + fi + [ -n "$error" ] && continue + + break + done done } @@ -326,7 +360,6 @@ function __runsmod_match_repo_add() { function __runsmod_clone_or_pull() { local repourl="$1" repodir="$2" - mkdirof "$repodir" if [ -d "$repodir" ]; then if [ -n "$RUNSMOD_PULL" ]; then estepi "pull $(ppath "$repodir") [$repourl]" @@ -339,6 +372,7 @@ function __runsmod_clone_or_pull() { else if [ -n "$RUNSMOD_CLONE" ]; then estepi "clone $(ppath "$repodir") [$repourl]" + mkdirof "$repodir" git clone ${RUNSMOD_SHALLOW:+--depth 1} "$repourl" "$repodir" return $? else @@ -365,7 +399,7 @@ function runsmod_clone_or_pull() { enote "Autocorrection du nom d'hôte en $host" fi - local -a repolist reposuffixes reponames repourls + local -a baseurls repolist reposuffixes reponames repourls local RUNSMOD_PROFILE baseurl repopath repolistfile local vprefix repospec reposuffix reponame repourl repodir module moduledir local r=0 @@ -373,115 +407,21 @@ function runsmod_clone_or_pull() { # Tout d'abord, traiter les dépôts sans variable %m edebug "Traitement des dépôts sans vmodule" for RUNSMOD_PROFILE in "${RUNSMOD_PROFILES[@]}"; do - setx baseurl=__runsmod_get BASEURL || continue - setx repopath=__runsmod_getpath_from_baseurl "$baseurl" - setx repolistfile=__runsmod_get_repolistfile "$baseurl" - [ -f "$repolistfile" ] || continue - array_from_lines repolist "$(<"$repolistfile")" - - edebug ".. baseurl=$baseurl, repopath=$repopath" - for vprefix in SCRIPTS MODULES HOSTS; do - __runsmod_get -a repourls "${vprefix}_URLS" - edebug ".... vprefix=$vprefix, repourls=(${repourls[*]})" - - for repospec in "${repourls[@]}"; do - edebug "...... repospec=$repospec" - __runsmod_has_vmodule "$repospec" && continue - if [[ "$repospec" == *//* ]]; then - reposuffix="${repospec#*//}" - [ -n "$reposuffix" ] && reposuffix="/$reposuffix" - repospec="${repospec%%//*}" - if __runsmod_has_vhost "$reposuffix"; then - if [ -n "$all_hosts" -o -z "$host" ]; then - reposuffix="${reposuffix//%h\//}" - reposuffix="${reposuffix//\/%h/}" - reposuffixes=("$reposuffix") - elif [ -n "$host" ]; then - local rs1 rs2 - setx rs1=__runsmod_replace1 "$reposuffix" "$host" - setx rs2=__runsmod_replace2 "$reposuffix" "$host" - reposuffixes=("$rs1") - [ "$rs2" != "$rs1" ] && array_add reposuffixes "$rs2" - fi - else - reposuffixes=("$reposuffix") - fi - else - reposuffix= - fi - - reponames=() - if __runsmod_has_vhost "$repospec"; then - if [ -n "$all_hosts" ]; then - setx repospec=__runsmod_replace1 "$repospec" "*" - __runsmod_match_repo_add repolist "$repospec" reponames - elif [ -n "$host" ]; then - setx reponame=__runsmod_replace1 "$repospec" "$host" - array_contains repolist "$reponame" && array_add reponames "$reponame" - setx reponame=__runsmod_replace2 "$repospec" "$host" - array_contains repolist "$reponame" && array_add reponames "$reponame" - fi - else - array_contains repolist "$repospec" && array_add reponames "$repospec" - fi - - edebug "...... reponames=(${reponames[*]})" - for reponame in "${reponames[@]}"; do - repodir="$RUNSMOD_BASEDIR/$repopath/$reponame" - - setx repourl=__runsmod_fixurl "$reponame" "$baseurl" - __runsmod_clone_or_pull "$repourl" "$repodir" || r=1 - - [ -d "$repodir" ] || continue - array_contains REPODIRS "$repodir" && continue - array_addu REPODIRS "$repodir" - - for reposuffix in "${reposuffixes[@]}"; do - case "$vprefix" in - SCRIPTS) array_addu SCRIPTSDIRS "$repodir$reposuffix";; - MODULES) array_addu MODULESDIRS "$repodir$reposuffix";; - HOSTS) array_addu HOSTSDIRS "$repodir$reposuffix";; - esac - done - done - done - done - done - - ## Ensuite, traiter les dépôts de module - - # modules contient la liste des modules qui ont été trouvés, pour ne pas les - # lister en double s'ils existent dans plusieurs sources - edebug "Traitement des dépôts de modules" - local -a modules foundmodules - local all_modules - - modules=("$@") - for RUNSMOD_PROFILE in "${RUNSMOD_PROFILES[@]}"; do - setx baseurl=__runsmod_get BASEURL || continue - setx repopath=__runsmod_getpath_from_baseurl "$baseurl" - setx repolistfile=__runsmod_get_repolistfile "$baseurl" - [ -f "$repolistfile" ] || continue - array_from_lines repolist "$(<"$repolistfile")" - - edebug ".. baseurl=$baseurl, repopath=$repopath" - for module in "${modules[@]}"; do - if [ "$module" == "*" ]; then - module= - all_modules=1 - else - array_contains foundmodules "$module" && continue - all_modules= - fi - edebug ".... module=$module" + __runsmod_get -a baseurls BASEURL + for baseurl in "${baseurls[@]}"; do + setx repopath=__runsmod_getpath_from_baseurl "$baseurl" + setx repolistfile=__runsmod_get_repolistfile "$baseurl" + [ -f "$repolistfile" ] || continue + array_from_lines repolist "$(<"$repolistfile")" + edebug ".. baseurl=$baseurl, repopath=$repopath" for vprefix in SCRIPTS MODULES HOSTS; do __runsmod_get -a repourls "${vprefix}_URLS" - edebug "...... vprefix=$vprefix, repourls=(${repourls[*]})" + edebug ".... vprefix=$vprefix, repourls=(${repourls[*]})" for repospec in "${repourls[@]}"; do - edebug "........ repospec=$repospec" - __runsmod_has_vmodule "$repospec" || continue + edebug "...... repospec=$repospec" + __runsmod_has_vmodule "$repospec" && continue if [[ "$repospec" == *//* ]]; then reposuffix="${repospec#*//}" [ -n "$reposuffix" ] && reposuffix="/$reposuffix" @@ -506,54 +446,36 @@ function runsmod_clone_or_pull() { fi reponames=() - if [ -n "$all_modules" ]; then - if __runsmod_has_vhost "$repospec"; then - if [ -n "$all_hosts" ]; then - setx repospec=__runsmod_replace1 "$repospec" "*" "*" - __runsmod_match_repo_add repolist "$repospec" reponames - elif [ -n "$host" ]; then - setx repospec=__runsmod_replace1 "$repospec" "$host" "*" - __runsmod_match_repo_add repolist "$repospec" reponames - setx repospec=__runsmod_replace2 "$repospec" "$host" "*" - __runsmod_match_repo_add repolist "$repospec" reponames - fi - else - setx repospec=__runsmod_replace1 "$repospec" "" "*" + if __runsmod_has_vhost "$repospec"; then + if [ -n "$all_hosts" ]; then + setx repospec=__runsmod_replace1 "$repospec" "*" __runsmod_match_repo_add repolist "$repospec" reponames + elif [ -n "$host" ]; then + setx reponame=__runsmod_replace1 "$repospec" "$host" + array_contains repolist "$reponame" && array_add reponames "$reponame" + setx reponame=__runsmod_replace2 "$repospec" "$host" + array_contains repolist "$reponame" && array_add reponames "$reponame" fi else - if __runsmod_has_vhost "$repospec"; then - if [ -n "$host" ]; then - setx reponame=__runsmod_replace1 "$repospec" "$host" "$module" - array_contains repolist "$reponame" && array_add reponames "$reponame" - setx reponame=__runsmod_replace2 "$repospec" "$host" "$module" - array_contains repolist "$reponame" && array_add reponames "$reponame" - fi - else - setx reponame=__runsmod_replace1 "$repospec" "" "$module" - array_contains repolist "$reponame" && array_add reponames "$reponame" - fi + array_contains repolist "$repospec" && array_add reponames "$repospec" fi - edebug "........ reponames=(${reponames[*]})" + edebug "...... reponames=(${reponames[*]})" for reponame in "${reponames[@]}"; do repodir="$RUNSMOD_BASEDIR/$repopath/$reponame" setx repourl=__runsmod_fixurl "$reponame" "$baseurl" + setx repodir=__runsmod_mapdir "$repodir" "$RUNSMOD_BASEDIR/$repopath" __runsmod_clone_or_pull "$repourl" "$repodir" || r=1 [ -d "$repodir" ] || continue array_contains REPODIRS "$repodir" && continue array_addu REPODIRS "$repodir" - [ -z "$all_modules" ] && array_addu foundmodules "$module" for reposuffix in "${reposuffixes[@]}"; do case "$vprefix" in SCRIPTS) array_addu SCRIPTSDIRS "$repodir$reposuffix";; - MODULES) - setx moduledir=dirname -- "$repodir$reposuffix" - array_addu MODULESDIRS "$moduledir" - ;; + MODULES) array_addu MODULESDIRS "$repodir$reposuffix";; HOSTS) array_addu HOSTSDIRS "$repodir$reposuffix";; esac done @@ -563,6 +485,124 @@ function runsmod_clone_or_pull() { done done + ## Ensuite, traiter les dépôts de module + + # modules contient la liste des modules qui ont été trouvés, pour ne pas les + # lister en double s'ils existent dans plusieurs sources + edebug "Traitement des dépôts de modules" + local -a modules foundmodules + local all_modules + + modules=("$@") + for RUNSMOD_PROFILE in "${RUNSMOD_PROFILES[@]}"; do + __runsmod_get -a baseurls BASEURL + for baseurl in "${baseurls[@]}"; do + setx repopath=__runsmod_getpath_from_baseurl "$baseurl" + setx repolistfile=__runsmod_get_repolistfile "$baseurl" + [ -f "$repolistfile" ] || continue + array_from_lines repolist "$(<"$repolistfile")" + + edebug ".. baseurl=$baseurl, repopath=$repopath" + for module in "${modules[@]}"; do + if [ "$module" == "*" ]; then + module= + all_modules=1 + else + array_contains foundmodules "$module" && continue + all_modules= + fi + edebug ".... module=$module" + + for vprefix in SCRIPTS MODULES HOSTS; do + __runsmod_get -a repourls "${vprefix}_URLS" + edebug "...... vprefix=$vprefix, repourls=(${repourls[*]})" + + for repospec in "${repourls[@]}"; do + edebug "........ repospec=$repospec" + __runsmod_has_vmodule "$repospec" || continue + if [[ "$repospec" == *//* ]]; then + reposuffix="${repospec#*//}" + [ -n "$reposuffix" ] && reposuffix="/$reposuffix" + repospec="${repospec%%//*}" + if __runsmod_has_vhost "$reposuffix"; then + if [ -n "$all_hosts" -o -z "$host" ]; then + reposuffix="${reposuffix//%h\//}" + reposuffix="${reposuffix//\/%h/}" + reposuffixes=("$reposuffix") + elif [ -n "$host" ]; then + local rs1 rs2 + setx rs1=__runsmod_replace1 "$reposuffix" "$host" + setx rs2=__runsmod_replace2 "$reposuffix" "$host" + reposuffixes=("$rs1") + [ "$rs2" != "$rs1" ] && array_add reposuffixes "$rs2" + fi + else + reposuffixes=("$reposuffix") + fi + else + reposuffix= + fi + + reponames=() + if [ -n "$all_modules" ]; then + if __runsmod_has_vhost "$repospec"; then + if [ -n "$all_hosts" ]; then + setx repospec=__runsmod_replace1 "$repospec" "*" "*" + __runsmod_match_repo_add repolist "$repospec" reponames + elif [ -n "$host" ]; then + setx repospec=__runsmod_replace1 "$repospec" "$host" "*" + __runsmod_match_repo_add repolist "$repospec" reponames + setx repospec=__runsmod_replace2 "$repospec" "$host" "*" + __runsmod_match_repo_add repolist "$repospec" reponames + fi + else + setx repospec=__runsmod_replace1 "$repospec" "" "*" + __runsmod_match_repo_add repolist "$repospec" reponames + fi + else + if __runsmod_has_vhost "$repospec"; then + if [ -n "$host" ]; then + setx reponame=__runsmod_replace1 "$repospec" "$host" "$module" + array_contains repolist "$reponame" && array_add reponames "$reponame" + setx reponame=__runsmod_replace2 "$repospec" "$host" "$module" + array_contains repolist "$reponame" && array_add reponames "$reponame" + fi + else + setx reponame=__runsmod_replace1 "$repospec" "" "$module" + array_contains repolist "$reponame" && array_add reponames "$reponame" + fi + fi + + edebug "........ reponames=(${reponames[*]})" + for reponame in "${reponames[@]}"; do + repodir="$RUNSMOD_BASEDIR/$repopath/$reponame" + + setx repourl=__runsmod_fixurl "$reponame" "$baseurl" + setx repodir=__runsmod_mapdir "$repodir" "$RUNSMOD_BASEDIR/$repopath" + __runsmod_clone_or_pull "$repourl" "$repodir" || r=1 + + [ -d "$repodir" ] || continue + array_contains REPODIRS "$repodir" && continue + array_addu REPODIRS "$repodir" + [ -z "$all_modules" ] && array_addu foundmodules "$module" + + for reposuffix in "${reposuffixes[@]}"; do + case "$vprefix" in + SCRIPTS) array_addu SCRIPTSDIRS "$repodir$reposuffix";; + MODULES) + setx moduledir=dirname -- "$repodir$reposuffix" + array_addu MODULESDIRS "$moduledir" + ;; + HOSTS) array_addu HOSTSDIRS "$repodir$reposuffix";; + esac + done + done + done + done + done + done + done + for module in "${modules[@]}"; do [ "$module" == "*" ] && continue array_contains foundmodules "$module" || ewarn "$module: module non trouvé" diff --git a/lib/ulib/runsmod.defaults b/lib/ulib/runsmod.defaults index cace3f9..470edab 100644 --- a/lib/ulib/runsmod.defaults +++ b/lib/ulib/runsmod.defaults @@ -17,6 +17,7 @@ RUNSMOD_MODULES_URLS=(hosts/%h/modules/%m hosts/%h/all modules/%m) #RUNSMOD_MODULES_URLS=(hosts/%h/modules/%m hosts/%h/all hosts/all/%n/%m modules/%m) RUNSMOD_HOSTS_URLS=(runsh) RUNSMOD_BASEDIR="$HOME/runs" +RUNSMOD_MAP=() RUNSMOD_PROFILES=(pvcs vcs jclain) # pvcs @@ -25,6 +26,13 @@ RUNSMOD_pvcs_devel_BASEURL=pgit@vcs.univ.run RUNSMOD_pvcs_SCRIPTS_URLS=("${RUNSMOD_SCRIPTS_URLS[@]}" si/base-runs) RUNSMOD_pvcs_MODULES_URLS=("${RUNSMOD_MODULES_URLS[@]}") RUNSMOD_pvcs_HOSTS_URLS=("${RUNSMOD_HOSTS_URLS[@]}") +RUNSMOD_pvcs_MAP=( + si/base-runs:"$HOME/wop/legacy-runs" + runss:"$HOME/wop/runs" + modules:"$HOME/wop/pmodules" + hosts:"$HOME/wop/hosts" + runsh:"$HOME/wop/hosts/all/hosts" +) # vcs RUNSMOD_vcs_BASEURL=(http://vcs.univ.run/anongit http://vcs.univ-reunion.fr/anongit) @@ -32,9 +40,21 @@ RUNSMOD_vcs_devel_BASEURL=git@vcs.univ.run RUNSMOD_vcs_SCRIPTS_URLS=("${RUNSMOD_SCRIPTS_URLS[@]}") RUNSMOD_vcs_MODULES_URLS=("${RUNSMOD_MODULES_URLS[@]}") RUNSMOD_vcs_HOSTS_URLS=("${RUNSMOD_HOSTS_URLS[@]}") +RUNSMOD_vcs_MAP=( + runss:"$HOME/wop/pruns" + modules:"$HOME/wop/modules" + hosts:"$HOME/wop/hosts" + runsh:"$HOME/wop/hosts/all/phosts" +) # jclain RUNSMOD_jclain_BASEURL=git@jclain.fr RUNSMOD_jclain_SCRIPTS_URLS=("${RUNSMOD_SCRIPTS_URLS[@]}") RUNSMOD_jclain_MODULES_URLS=("${RUNSMOD_MODULES_URLS[@]}") RUNSMOD_jclain_HOSTS_URLS=("${RUNSMOD_HOSTS_URLS[@]}") +RUNSMOD_jclain_MAP=( + runss:"$HOME/wop/j/runs" + modules:"$HOME/wop/j/modules" + hosts:"$HOME/wop/j/hosts" + runsh:"$HOME/wop/j/hosts/all/hosts" +) From 5bef9b104ab2af73b16f27a21936a90bc618c02f Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Tue, 30 Aug 2016 16:28:08 +0400 Subject: [PATCH 06/11] =?UTF-8?q?utiliser=20la=20m=C3=AAme=20logique=20que?= =?UTF-8?q?=20uproject=20pour=20cloner=20en=20mode=20devel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ulib/runsmod | 8 ++++++-- lib/{ => ulib/support}/ssh-wrapper/rsync | 0 lib/{ => ulib/support}/ssh-wrapper/ssh | 0 lib/ulib/vcs | 10 +++++++++- uproject | 14 +++----------- 5 files changed, 18 insertions(+), 14 deletions(-) rename lib/{ => ulib/support}/ssh-wrapper/rsync (100%) rename lib/{ => ulib/support}/ssh-wrapper/ssh (100%) diff --git a/lib/ulib/runsmod b/lib/ulib/runsmod index 017545e..b2674e9 100644 --- a/lib/ulib/runsmod +++ b/lib/ulib/runsmod @@ -3,7 +3,7 @@ ##@cooked nocomments ##@require base uprovide runsmod -urequire base +urequire base vcs function __runsmod_loadconf() { # Charger le fichier de configuration $1. Les paramètres RUNSMOD_MODE, @@ -373,7 +373,11 @@ function __runsmod_clone_or_pull() { if [ -n "$RUNSMOD_CLONE" ]; then estepi "clone $(ppath "$repodir") [$repourl]" mkdirof "$repodir" - git clone ${RUNSMOD_SHALLOW:+--depth 1} "$repourl" "$repodir" + git clone ${RUNSMOD_SHALLOW:+--depth 1} "$repourl" "$repodir" || return $? + if [ "$RUNSMOD_MODE" == devel ]; then + ( cd "$repodir"; git_have_rbranch develop && git checkout develop ) || return $? + fi + git_annex_initial "$repodir" || return $? return $? else estepe "noclone $(ppath "$repodir")" diff --git a/lib/ssh-wrapper/rsync b/lib/ulib/support/ssh-wrapper/rsync similarity index 100% rename from lib/ssh-wrapper/rsync rename to lib/ulib/support/ssh-wrapper/rsync diff --git a/lib/ssh-wrapper/ssh b/lib/ulib/support/ssh-wrapper/ssh similarity index 100% rename from lib/ssh-wrapper/ssh rename to lib/ulib/support/ssh-wrapper/ssh diff --git a/lib/ulib/vcs b/lib/ulib/vcs index 6c41d9c..e9923dd 100644 --- a/lib/ulib/vcs +++ b/lib/ulib/vcs @@ -3,7 +3,7 @@ ##@cooked nocomments ##@require base uprovide vcs -urequire base +urequire ulib base ################################################################################ # Général @@ -772,6 +772,14 @@ function git_is_merged() { } # fonctions pour git annex +function git_annex_use_ssh_wrapper() { + __UTOOLS_FORCE_PATH="$PATH" + __UTOOLS_FORCE_SSH="${GIT_SSH:-ssh}" + export __UTOOLS_FORCE_PATH __UTOOLS_FORCE_SSH + udelpath "$ULIBDIR/support/ssh-wrapper" __UTOOLS_FORCE_PATH + uinspath "$ULIBDIR/support/ssh-wrapper" PATH +} + function git_annex_initial() { # sur le dépôt $1 fraichement cloné, vérifier s'il faut faire git annex # init. Si oui, l'initialiser avec le nom d'hôte, et récupérer tous les diff --git a/uproject b/uproject index 900a815..9e48dbc 100755 --- a/uproject +++ b/uproject @@ -217,14 +217,6 @@ done ################################################################################ # Traiter les commandes -function use_ssh_wrapper() { - __UTOOLS_FORCE_PATH="$PATH" - __UTOOLS_FORCE_SSH="${GIT_SSH:-ssh}" - export __UTOOLS_FORCE_PATH __UTOOLS_FORCE_SSH - udelpath "$scriptdir/lib/ssh-wrapper" __UTOOLS_FORCE_PATH - uinspath "$scriptdir/lib/ssh-wrapper" PATH -} - if [ "$CMD" == "grep" ]; then ## grep if [ $# -eq 1 -a "$1" == "--help" ]; then @@ -259,7 +251,7 @@ elif array_contains GITANNEX_CMDS "$CMD"; then git annex sync fi } - use_ssh_wrapper + git_annex_use_ssh_wrapper case "$CMD" in annex) git annex "$@";; xsync) xsync;; @@ -280,7 +272,7 @@ elif [ "$CMD" == clone ]; then fi [ -d "$destdir" ] && die "$(ppath "$destdir"): répertoire existant" - use_ssh_wrapper + git_annex_use_ssh_wrapper git clone "$repourl" "$destdir" || die ( cd "$destdir"; git_have_rbranch develop && git checkout develop ) || die git_annex_initial "$destdir" || die @@ -307,7 +299,7 @@ elif [ "$CMD" == crone ]; then userhost="$user@$host" [ -n "$path" ] || die "Vous devez spécifier le chemin du dépôt git" - use_ssh_wrapper + git_annex_use_ssh_wrapper ssh "$userhost" create "$path" || die if [ -n "$tmpdestdir" ]; then setxx destname=abspath "$destdir" // basename From 2fbc599113caa94d2d3488afee135723e1e7dd07 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Tue, 30 Aug 2016 16:46:20 +0400 Subject: [PATCH 07/11] bug avec git clone lors du basculement sur la branche develop --- lib/ulib/runsmod | 9 +++++++-- uproject | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/ulib/runsmod b/lib/ulib/runsmod index b2674e9..7f606a9 100644 --- a/lib/ulib/runsmod +++ b/lib/ulib/runsmod @@ -375,10 +375,15 @@ function __runsmod_clone_or_pull() { mkdirof "$repodir" git clone ${RUNSMOD_SHALLOW:+--depth 1} "$repourl" "$repodir" || return $? if [ "$RUNSMOD_MODE" == devel ]; then - ( cd "$repodir"; git_have_rbranch develop && git checkout develop ) || return $? + ( + cd "$repodir" + if git_have_rbranch develop; then + git checkout develop || exit 1 + fi + ) || return $? fi git_annex_initial "$repodir" || return $? - return $? + return 0 else estepe "noclone $(ppath "$repodir")" return 1 diff --git a/uproject b/uproject index 9e48dbc..9d0e14d 100755 --- a/uproject +++ b/uproject @@ -274,7 +274,12 @@ elif [ "$CMD" == clone ]; then git_annex_use_ssh_wrapper git clone "$repourl" "$destdir" || die - ( cd "$destdir"; git_have_rbranch develop && git checkout develop ) || die + ( + cd "$destdir" + if git_have_rbranch develop; then + git checkout develop || exit 1 + fi + ) || die git_annex_initial "$destdir" || die elif [ "$CMD" == crone ]; then From 40f53476567eb12b307c7cc8b55fd56717752b06 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Tue, 30 Aug 2016 18:44:20 +0400 Subject: [PATCH 08/11] =?UTF-8?q?pr=C3=A9parer=20le=20calcul=20automatique?= =?UTF-8?q?=20des=20chemins?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ulib/runsmod | 150 ++++++++++++++++++++++++++++++++++++++--------- runs | 18 +++++- 2 files changed, 139 insertions(+), 29 deletions(-) diff --git a/lib/ulib/runsmod b/lib/ulib/runsmod index 7f606a9..4411107 100644 --- a/lib/ulib/runsmod +++ b/lib/ulib/runsmod @@ -140,22 +140,24 @@ function __runsmod_fixurl() { function __runsmod_mapdir() { # mapper le répertoire $1, avec $2 est le répertoire de base à partir # desquels les mappings sont définis + # retourner vrai si un mapping a eu lieu local dir="$1" basedir="$2" local -a maps local map from to - dir="${dir#$basedir/}" + [ -n "$basedir" ] && dir="${dir#$basedir/}" __runsmod_get -a maps MAP for map in "${maps[@]}"; do splitpair "$map" from to if [ "$dir" == "$from" ]; then echo "$to" - return + return 0 elif [ "${dir#$from/}" != "$dir" ]; then echo "$to/${dir#$from/}" - return + return 0 fi done echo "$dir" + return 1 } function __runsmod_getpath_from_baseurl() { @@ -219,11 +221,13 @@ function __runsmod_fixinfo() { function runsmod_checkenv() { # vérifier l'environement. créer les répertoires nécessaires. + local check_only + [ "$1" == --check-only ] && check_only=1 if [ -z "$RUNSMOD_BASEDIR" ]; then - eerror "Vous devez définir RUNSMOD_BASEDIR" + [ -z "$check_only" ] && eerror "Vous devez définir RUNSMOD_BASEDIR" return 1 fi - if [ ! -d "$RUNSMOD_BASEDIR" ]; then + if [ ! -d "$RUNSMOD_BASEDIR" -a -z "$check_only" ]; then estep "Création de $(ppath "$RUNSMOD_BASEDIR")" mkdir -p "$RUNSMOD_BASEDIR" || return 1 fi @@ -432,6 +436,7 @@ function runsmod_clone_or_pull() { edebug "...... repospec=$repospec" __runsmod_has_vmodule "$repospec" && continue if [[ "$repospec" == *//* ]]; then + reposuffixes=() reposuffix="${repospec#*//}" [ -n "$reposuffix" ] && reposuffix="/$reposuffix" repospec="${repospec%%//*}" @@ -451,19 +456,19 @@ function runsmod_clone_or_pull() { reposuffixes=("$reposuffix") fi else - reposuffix= + reposuffixes=("") fi reponames=() if __runsmod_has_vhost "$repospec"; then if [ -n "$all_hosts" ]; then - setx repospec=__runsmod_replace1 "$repospec" "*" - __runsmod_match_repo_add repolist "$repospec" reponames + setx rs1=__runsmod_replace1 "$repospec" "*" + __runsmod_match_repo_add repolist "$rs1" reponames elif [ -n "$host" ]; then - setx reponame=__runsmod_replace1 "$repospec" "$host" - array_contains repolist "$reponame" && array_add reponames "$reponame" - setx reponame=__runsmod_replace2 "$repospec" "$host" - array_contains repolist "$reponame" && array_add reponames "$reponame" + setx rs1=__runsmod_replace1 "$repospec" "$host" + array_contains repolist "$rs1" && array_add reponames "$rs1" + setx rs2=__runsmod_replace2 "$repospec" "$host" + array_contains repolist "$rs2" && array_add reponames "$rs2" fi else array_contains repolist "$repospec" && array_add reponames "$repospec" @@ -530,6 +535,7 @@ function runsmod_clone_or_pull() { edebug "........ repospec=$repospec" __runsmod_has_vmodule "$repospec" || continue if [[ "$repospec" == *//* ]]; then + reposuffixes=() reposuffix="${repospec#*//}" [ -n "$reposuffix" ] && reposuffix="/$reposuffix" repospec="${repospec%%//*}" @@ -549,36 +555,36 @@ function runsmod_clone_or_pull() { reposuffixes=("$reposuffix") fi else - reposuffix= + reposuffixes=("") fi reponames=() if [ -n "$all_modules" ]; then if __runsmod_has_vhost "$repospec"; then if [ -n "$all_hosts" ]; then - setx repospec=__runsmod_replace1 "$repospec" "*" "*" - __runsmod_match_repo_add repolist "$repospec" reponames + setx rs1=__runsmod_replace1 "$repospec" "*" "*" + __runsmod_match_repo_add repolist "$rs1" reponames elif [ -n "$host" ]; then - setx repospec=__runsmod_replace1 "$repospec" "$host" "*" - __runsmod_match_repo_add repolist "$repospec" reponames - setx repospec=__runsmod_replace2 "$repospec" "$host" "*" - __runsmod_match_repo_add repolist "$repospec" reponames + setx rs1=__runsmod_replace1 "$repospec" "$host" "*" + __runsmod_match_repo_add repolist "$rs1" reponames + setx rs2=__runsmod_replace2 "$repospec" "$host" "*" + __runsmod_match_repo_add repolist "$rs2" reponames fi else - setx repospec=__runsmod_replace1 "$repospec" "" "*" - __runsmod_match_repo_add repolist "$repospec" reponames + setx rs1=__runsmod_replace1 "$repospec" "" "*" + __runsmod_match_repo_add repolist "$rs1" reponames fi else if __runsmod_has_vhost "$repospec"; then if [ -n "$host" ]; then - setx reponame=__runsmod_replace1 "$repospec" "$host" "$module" - array_contains repolist "$reponame" && array_add reponames "$reponame" - setx reponame=__runsmod_replace2 "$repospec" "$host" "$module" - array_contains repolist "$reponame" && array_add reponames "$reponame" + setx rs1=__runsmod_replace1 "$repospec" "$host" "$module" + array_contains repolist "$rs1" && array_add reponames "$rs1" + setx rs2=__runsmod_replace2 "$repospec" "$host" "$module" + array_contains repolist "$rs2" && array_add reponames "$rs2" fi else - setx reponame=__runsmod_replace1 "$repospec" "" "$module" - array_contains repolist "$reponame" && array_add reponames "$reponame" + setx rs1=__runsmod_replace1 "$repospec" "" "$module" + array_contains repolist "$rs1" && array_add reponames "$rs1" fi fi @@ -620,8 +626,98 @@ function runsmod_clone_or_pull() { return $r } +function runsmod_update_vars() { + local all_hosts host_mode="$1" host="$2" + case "$host_mode" in + none) host=;; + all) host=; all_hosts=1;; + self) host="${RUNSHOST:-$MYHOST}";; + esac + # le nom d'hôte doit être avec un domaine + [ -n "$host" -a "${host%%.*}" == "$host" -a -n "$RUNSDOMAIN" ] && host="$host.$RUNSDOMAIN" + + for RUNSMOD_PROFILE in "${RUNSMOD_PROFILES[@]}"; do + __runsmod_get -a baseurls BASEURL + for baseurl in "${baseurls[@]}"; do + setx repopath=__runsmod_getpath_from_baseurl "$baseurl" + setx repolistfile=__runsmod_get_repolistfile "$baseurl" + [ -f "$repolistfile" ] || continue + + edebug ".. baseurl=$baseurl, repopath=$repopath" + for vprefix in SCRIPTS MODULES HOSTS; do + __runsmod_get -a repourls "${vprefix}_URLS" + edebug ".... vprefix=$vprefix, repourls=(${repourls[*]})" + + for repospec in "${repourls[@]}"; do + edebug "...... repospec=$repospec" + __runsmod_has_vmodule "$repospec" && repospec="${repospec%%/%m*}" + reposuffixes=("") + if [[ "$repospec" == *//* ]]; then + reposuffix="${repospec#*//}" + [ -n "$reposuffix" ] && reposuffix="/$reposuffix" + repospec="${repospec%%//*}" + if __runsmod_has_vhost "$reposuffix"; then + if [ -n "$all_hosts" -o -z "$host" ]; then + reposuffix="${reposuffix//%h\//}" + reposuffix="${reposuffix//\/%h/}" + reposuffixes=("$reposuffix") + elif [ -n "$host" ]; then + local rs1 rs2 + setx rs1=__runsmod_replace1 "$reposuffix" "$host" + setx rs2=__runsmod_replace2 "$reposuffix" "$host" + reposuffixes=("$rs1") + [ "$rs2" != "$rs1" ] && array_add reposuffixes "$rs2" + fi + else + reposuffixes=("$reposuffix") + fi + fi + + repospecs=() + if __runsmod_has_vhost "$repospec"; then + if [ -n "$all_hosts" ]; then + setx rs1=__runsmod_replace1 "$repospec" "*" + array_addu repospecs "$rs1" + elif [ -n "$host" ]; then + setx rs1=__runsmod_replace1 "$repospec" "$host" + array_addu repospecs "$rs1" + setx rs2=__runsmod_replace2 "$repospec" "$host" + array_addu repospecs "$rs2" + fi + else + array_addu repospecs "$repospec" + fi + + edebug "...... repospecs=(${repospecs[*]})" + for repospec in "${repospecs[@]}"; do + if setx repospec=__runsmod_mapdir "$repospec"; then + repodirs=("$repospec") + else + array_lsdirs repodirs "$RUNSMOD_BASEDIR/$repopath" "$repospec" + fi + for repodir in "${repodirs[@]}"; do + edebug "........ repodir=$repodir" + [ -d "$repodir" ] || continue + for reposuffix in "${reposuffixes[@]}"; do + case "$vprefix" in + SCRIPTS) array_addu SCRIPTSDIRS "$repodir$reposuffix";; + MODULES) array_addu MODULESDIRS "$repodir$reposuffix";; + HOSTS) array_addu HOSTSDIRS "$repodir$reposuffix";; + esac + done + done + done + done + done + done + done +} + function runsmod_teardown_vars() { setx RUNSSCRIPTSPATH=array_join SCRIPTSDIRS : setx RUNSMODULESPATH=array_join MODULESDIRS : setx RUNSHOSTSPATH=array_join HOSTSDIRS : + [ -n "$RUNSSCRIPTSPATH" ] || RUNSSCRIPTSPATH=: + [ -n "$RUNSMODULESPATH" ] || RUNSMODULESPATH=: + [ -n "$RUNSHOSTSPATH" ] || RUNSHOSTSPATH=: } diff --git a/runs b/runs index 0378e0b..f140889 100755 --- a/runs +++ b/runs @@ -1,7 +1,7 @@ #!/bin/bash # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 source "$(dirname "$0")/lib/ulib/ulib" || exit 1 -urequire DEFAULTS runs +urequire DEFAULTS runs runsmod function display_help() { uecho "$scriptname: Lancer un script avec le protocole runs @@ -81,6 +81,7 @@ function runs_path_undefined() { ewarn "La variable $1 n'est pas définie dans ~/etc/default/runs" } +auto_runsmod=1 action=runs create_verbose= init_sysinfos=--NOT-SET-- @@ -105,6 +106,7 @@ runsvarsfile= # fichier contenant des définitions à charger runs_init "$scriptdir" parse_opts "${PRETTYOPTS[@]}" \ --help '$exit_with display_help' \ + --no-auto-runsmod auto_runsmod= \ --i '$action=init;create_verbose=false' \ --init '$action=init;create_verbose=true' \ --verify action=verify \ @@ -170,9 +172,21 @@ if [ "$action" == runs \ fi fi +if [ -n "$auto_runsmod" ] && __runsmod_loadconf && runsmod_checkenv --check-only; then + function __runsmod_clone_or_pull() { :; } + runsmod_setup_vars + runsmod_update_vars self "$RUNSHOST" + runsmod_teardown_vars + #XXX + echo === SCRIPTSDIRS ===; array_each SCRIPTSDIRS ppath + echo === MODULESDIRS ===; array_each MODULESDIRS ppath + echo === HOSTSDIRS ===; array_each HOSTSDIRS ppath + #XXX +fi + if ! is_root && [ -n "$run_as_root" ]; then # reconstruire la ligne de commande - args=() + args=(--no-auto-runsmod) if [ "$action" == "init" ]; then args=("${args[@]}" --init) elif [ "$action" == "verify" ]; then From 830a33b96fb606d4ed4b25f2d93481144b04f5c9 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 31 Aug 2016 11:21:09 +0400 Subject: [PATCH 09/11] =?UTF-8?q?rruns=20calcule=20aussi=20les=20chemins?= =?UTF-8?q?=20d'h=C3=B4tes=20automatiquement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ulib/runs | 33 ++++++++ lib/ulib/runsmod | 165 +++++++++++++++++++++++++++++++++++--- lib/ulib/runsmod.defaults | 4 +- rruns | 68 ++++++++-------- runs | 43 +--------- 5 files changed, 227 insertions(+), 86 deletions(-) diff --git a/lib/ulib/runs b/lib/ulib/runs index 30cfde8..ba1ce46 100644 --- a/lib/ulib/runs +++ b/lib/ulib/runs @@ -747,6 +747,39 @@ RUNSHOST=$RUNSHOST" ################################################################################ # Moteur de script +function runs_before_parse_args() { + RUNSSCRIPTSPATH= + RUNSSCRIPTSDIRS=() + RUNSMODULESPATH= + RUNSMODULESDIRS=() + RUNSHOSTSPATH= + RUNSHOSTSDIRS=() + RUNSDOMAINS=() + RUNSDOMAIN= + set_defaults runs + [ -n "$RUNSSCRIPTSPATH" ] && RUNSSCRIPTSDIRS=("$RUNSSCRIPTSPATH" "${RUNSSCRIPTSDIRS[@]}") + array_fix_paths RUNSSCRIPTSDIRS; setx RUNSSCRIPTSPATH=array_to_path RUNSSCRIPTSDIRS + [ -n "$RUNSMODULESPATH" ] && RUNSMODULESDIRS=("$RUNSMODULESPATH" "${RUNSMODULESDIRS[@]}") + array_fix_paths RUNSMODULESDIRS; setx RUNSMODULESPATH=array_to_path RUNSMODULESDIRS + [ -n "$RUNSHOSTSPATH" ] && RUNSHOSTSDIRS=("$RUNSHOSTSPATH" "${RUNSHOSTSDIRS[@]}") + array_fix_paths RUNSHOSTSDIRS; setx RUNSHOSTSPATH=array_to_path RUNSHOSTSDIRS +} + +function runs_after_parse_args() { + [ -n "$runsscriptspath" ] && runsscriptsdirs=("$runsscriptspath" "${runsscriptsdirs[@]}") + array_fix_paths runsscriptsdirs; setx runsscriptspath=array_to_path runsscriptsdirs + [ -n "$runsscriptspath" ] && RUNSSCRIPTSPATH="$runsscriptspath" + [ -n "$runsmodulespath" ] && runsmodulesdirs=("$runsmodulespath" "${runsmodulesdirs[@]}") + array_fix_paths runsmodulesdirs; setx runsmodulespath=array_to_path runsmodulesdirs + [ -n "$runsmodulespath" ] && RUNSMODULESPATH="$runsmodulespath" + [ -n "$runshostspath" ] && runshostsdirs=("$runshostspath" "${runshostsdirs[@]}") + array_fix_paths runshostsdirs; setx runshostspath=array_to_path runshostsdirs + [ -n "$runshostspath" ] && RUNSHOSTSPATH="$runshostspath" + [ -n "$RUNSSCRIPTSPATH" ] || RUNSSCRIPTSPATH=: + [ -n "$RUNSMODULESPATH" ] || RUNSMODULESPATH=: + [ -n "$RUNSHOSTSPATH" ] || RUNSHOSTSPATH=: +} + function runs_init() { RUNSSRCDIR="${1:-$scriptdir}" # répertoire d'où sont copiés les scripts RUNSACTION=runs_action_run diff --git a/lib/ulib/runsmod b/lib/ulib/runsmod index 4411107..05949c1 100644 --- a/lib/ulib/runsmod +++ b/lib/ulib/runsmod @@ -219,6 +219,19 @@ function __runsmod_fixinfo() { sed -n '3,$p' | sed 's/^.*\t//g' } +function runsmod_autoconf() { + if __runsmod_loadconf && runsmod_checkenv --check-only; then + runsmod_setup_vars + runsmod_update_vars "${1:-self}" + runsmod_teardown_vars + if show_debug; then + etitle SCRIPTSDIRS array_each SCRIPTSDIRS ppath + etitle MODULESDIRS array_each MODULESDIRS ppath + etitle HOSTSDIRS array_each HOSTSDIRS ppath + fi + fi +} + function runsmod_checkenv() { # vérifier l'environement. créer les répertoires nécessaires. local check_only @@ -636,6 +649,7 @@ function runsmod_update_vars() { # le nom d'hôte doit être avec un domaine [ -n "$host" -a "${host%%.*}" == "$host" -a -n "$RUNSDOMAIN" ] && host="$host.$RUNSDOMAIN" + # Calcul des répertoires d'hôte for RUNSMOD_PROFILE in "${RUNSMOD_PROFILES[@]}"; do __runsmod_get -a baseurls BASEURL for baseurl in "${baseurls[@]}"; do @@ -643,14 +657,72 @@ function runsmod_update_vars() { setx repolistfile=__runsmod_get_repolistfile "$baseurl" [ -f "$repolistfile" ] || continue - edebug ".. baseurl=$baseurl, repopath=$repopath" + #edebug ".. baseurl=$baseurl, repopath=$repopath" for vprefix in SCRIPTS MODULES HOSTS; do __runsmod_get -a repourls "${vprefix}_URLS" - edebug ".... vprefix=$vprefix, repourls=(${repourls[*]})" + #edebug ".... vprefix=$vprefix, repourls=(${repourls[*]})" for repospec in "${repourls[@]}"; do - edebug "...... repospec=$repospec" - __runsmod_has_vmodule "$repospec" && repospec="${repospec%%/%m*}" + #edebug "...... repospec=$repospec" + if [ "$vprefix" == HOSTS ]; then : + elif __runsmod_has_vhost "$repospec"; then + repospec="${repospec%%/%h*}" + else continue + fi + reposuffixes=("") + if [[ "$repospec" == *//* ]]; then + reposuffix="${repospec#*//}" + [ -n "$reposuffix" ] && reposuffix="/$reposuffix" + repospec="${repospec%%//*}" + reposuffixes=("$reposuffix") + fi + + if setx repospec=__runsmod_mapdir "$repospec"; then + repodirs=("$repospec") + else + array_lsdirs repodirs "$RUNSMOD_BASEDIR/$repopath" "$repospec" + fi + for repodir in "${repodirs[@]}"; do + #edebug "........ repodir=$repodir" + [ -d "$repodir" ] || continue + for reposuffix in "${reposuffixes[@]}"; do + array_addu HOSTSDIRS "$repodir$reposuffix" + done + done + done + done + done + done + + # Calcul des répertoires de module + for RUNSMOD_PROFILE in "${RUNSMOD_PROFILES[@]}"; do + __runsmod_get -a baseurls BASEURL + for baseurl in "${baseurls[@]}"; do + setx repopath=__runsmod_getpath_from_baseurl "$baseurl" + setx repolistfile=__runsmod_get_repolistfile "$baseurl" + [ -f "$repolistfile" ] || continue + + #edebug ".. baseurl=$baseurl, repopath=$repopath" + for vprefix in MODULES HOSTS; do + if [ "$vprefix" == HOSTS ]; then + __runsmod_get -a tmprepourls "${vprefix}_URLS" + repourls=() + for repourl in "${tmprepourls[@]}"; do + if __runsmod_has_vmodule "$repourl"; then + array_add repourls "$repourl" + else + array_add repourls "$repourl/%h/modules" + array_add repourls "$repourl/%h" + fi + done + else + __runsmod_get -a repourls "${vprefix}_URLS" + fi + #edebug ".... vprefix=$vprefix, repourls=(${repourls[*]})" + + for repospec in "${repourls[@]}"; do + #edebug "...... repospec=$repospec" + repospec="${repospec%%/%m*}" reposuffixes=("") if [[ "$repospec" == *//* ]]; then reposuffix="${repospec#*//}" @@ -688,7 +760,7 @@ function runsmod_update_vars() { array_addu repospecs "$repospec" fi - edebug "...... repospecs=(${repospecs[*]})" + #edebug "...... repospecs=(${repospecs[*]})" for repospec in "${repospecs[@]}"; do if setx repospec=__runsmod_mapdir "$repospec"; then repodirs=("$repospec") @@ -696,14 +768,85 @@ function runsmod_update_vars() { array_lsdirs repodirs "$RUNSMOD_BASEDIR/$repopath" "$repospec" fi for repodir in "${repodirs[@]}"; do - edebug "........ repodir=$repodir" + #edebug "........ repodir=$repodir" [ -d "$repodir" ] || continue for reposuffix in "${reposuffixes[@]}"; do - case "$vprefix" in - SCRIPTS) array_addu SCRIPTSDIRS "$repodir$reposuffix";; - MODULES) array_addu MODULESDIRS "$repodir$reposuffix";; - HOSTS) array_addu HOSTSDIRS "$repodir$reposuffix";; - esac + array_addu MODULESDIRS "$repodir$reposuffix" + done + done + done + done + done + done + done + + # Calcul des répertoires de script + for RUNSMOD_PROFILE in "${RUNSMOD_PROFILES[@]}"; do + __runsmod_get -a baseurls BASEURL + for baseurl in "${baseurls[@]}"; do + setx repopath=__runsmod_getpath_from_baseurl "$baseurl" + setx repolistfile=__runsmod_get_repolistfile "$baseurl" + [ -f "$repolistfile" ] || continue + + #edebug ".. baseurl=$baseurl, repopath=$repopath" + for vprefix in SCRIPTS HOSTS; do + __runsmod_get -a repourls "${vprefix}_URLS" + #edebug ".... vprefix=$vprefix, repourls=(${repourls[*]})" + + for repospec in "${repourls[@]}"; do + #edebug "...... repospec=$repospec" + if [ "$vprefix" == HOSTS ]; then + __runsmod_has_vhost "$repospec" || repospec="$repospec/%h/runs" + fi + reposuffixes=("") + if [[ "$repospec" == *//* ]]; then + reposuffix="${repospec#*//}" + [ -n "$reposuffix" ] && reposuffix="/$reposuffix" + repospec="${repospec%%//*}" + if __runsmod_has_vhost "$reposuffix"; then + if [ -n "$all_hosts" -o -z "$host" ]; then + reposuffix="${reposuffix//%h\//}" + reposuffix="${reposuffix//\/%h/}" + reposuffixes=("$reposuffix") + elif [ -n "$host" ]; then + local rs1 rs2 + setx rs1=__runsmod_replace1 "$reposuffix" "$host" + setx rs2=__runsmod_replace2 "$reposuffix" "$host" + reposuffixes=("$rs1") + [ "$rs2" != "$rs1" ] && array_add reposuffixes "$rs2" + fi + else + reposuffixes=("$reposuffix") + fi + fi + + repospecs=() + if __runsmod_has_vhost "$repospec"; then + if [ -n "$all_hosts" ]; then + setx rs1=__runsmod_replace1 "$repospec" "*" + array_addu repospecs "$rs1" + elif [ -n "$host" ]; then + setx rs1=__runsmod_replace1 "$repospec" "$host" + array_addu repospecs "$rs1" + setx rs2=__runsmod_replace2 "$repospec" "$host" + array_addu repospecs "$rs2" + fi + else + array_addu repospecs "$repospec" + fi + + #edebug "...... repospecs=(${repospecs[*]})" + for repospec in "${repospecs[@]}"; do + if setx repospec=__runsmod_mapdir "$repospec"; then + repodirs=("$repospec") + else + array_lsdirs repodirs "$RUNSMOD_BASEDIR/$repopath" "$repospec" + fi + for repodir in "${repodirs[@]}"; do + #edebug "........ repodir=$repodir" + [ -d "$repodir" ] || continue + for reposuffix in "${reposuffixes[@]}"; do + array_addu SCRIPTSDIRS "$repodir$reposuffix" done done done diff --git a/lib/ulib/runsmod.defaults b/lib/ulib/runsmod.defaults index 470edab..c3aee3c 100644 --- a/lib/ulib/runsmod.defaults +++ b/lib/ulib/runsmod.defaults @@ -12,9 +12,9 @@ RUNSMOD_UPDATE=auto RUNSMOD_IDENTITY= RUNSMOD_BASEURL= RUNSMOD_SCRIPTS_URLS=(hosts/%h/runs hosts/%h/all//runs runss) -RUNSMOD_MODULES_URLS=(hosts/%h/modules/%m hosts/%h/all modules/%m) +RUNSMOD_MODULES_URLS=(hosts/%h/modules/%m hosts/%h/%m hosts/%h/all modules/%m) # quand on supportera %n -#RUNSMOD_MODULES_URLS=(hosts/%h/modules/%m hosts/%h/all hosts/all/%n/%m modules/%m) +#RUNSMOD_MODULES_URLS=(hosts/%h/modules/%m hosts/%h/%m hosts/%h/all hosts/all/%n/%m modules/%m) RUNSMOD_HOSTS_URLS=(runsh) RUNSMOD_BASEDIR="$HOME/runs" RUNSMOD_MAP=() diff --git a/rruns b/rruns index a1c4c3e..cddb3d1 100755 --- a/rruns +++ b/rruns @@ -1,7 +1,7 @@ #!/bin/bash # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 source "$(dirname "$0")/lib/ulib/ulib" || exit 1 -urequire DEFAULTS runs +urequire DEFAULTS runs runsmod function display_help() { uecho "$scriptname: Déploiement distant avec runs @@ -74,22 +74,9 @@ OPTIONS argument (hors options)." } -RUNSSCRIPTSPATH= -RUNSSCRIPTSDIRS=() -RUNSMODULESPATH= -RUNSMODULESDIRS=() -RUNSHOSTSPATH= -RUNSHOSTSDIRS=() -RUNSDOMAINS=() -RUNSDOMAIN= -set_defaults runs -[ -n "$RUNSSCRIPTSPATH" ] && RUNSSCRIPTSDIRS=("$RUNSSCRIPTSPATH" "${RUNSSCRIPTSDIRS[@]}") -array_fix_paths RUNSSCRIPTSDIRS; setx RUNSSCRIPTSPATH=array_to_path RUNSSCRIPTSDIRS -[ -n "$RUNSMODULESPATH" ] && RUNSMODULESDIRS=("$RUNSMODULESPATH" "${RUNSMODULESDIRS[@]}") -array_fix_paths RUNSMODULESDIRS; setx RUNSMODULESPATH=array_to_path RUNSMODULESDIRS -[ -n "$RUNSHOSTSPATH" ] && RUNSHOSTSDIRS=("$RUNSHOSTSPATH" "${RUNSHOSTSDIRS[@]}") -array_fix_paths RUNSHOSTSDIRS; setx RUNSHOSTSPATH=array_to_path RUNSHOSTSDIRS +runs_before_parse_args +auto_runsmod=1 action=deploy confuser= tmproot= @@ -110,6 +97,7 @@ runshostspath= runshostsdirs=() parse_opts "${PRETTYOPTS[@]}" \ --help '$exit_with display_help' \ + --no-auto-runsmod auto_runsmod= \ -C action=configure \ --configure: '$set@ confuser;action=configure' \ -T:,--tmproot: tmproot= \ @@ -131,18 +119,7 @@ parse_opts "${PRETTYOPTS[@]}" \ --runshostsdir: runshostsdirs \ @ args -- "$@" && set -- "${args[@]}" || die "$args" -[ -n "$runsscriptspath" ] && runsscriptsdirs=("$runsscriptspath" "${runsscriptsdirs[@]}") -array_fix_paths runsscriptsdirs; setx runsscriptspath=array_to_path runsscriptsdirs -[ -n "$runsscriptspath" ] && RUNSSCRIPTSPATH="$runsscriptspath" -[ -n "$runsmodulespath" ] && runsmodulesdirs=("$runsmodulespath" "${runsmodulesdirs[@]}") -array_fix_paths runsmodulesdirs; setx runsmodulespath=array_to_path runsmodulesdirs -[ -n "$runsmodulespath" ] && RUNSMODULESPATH="$runsmodulespath" -[ -n "$runshostspath" ] && runshostsdirs=("$runshostspath" "${runshostsdirs[@]}") -array_fix_paths runshostsdirs; setx runshostspath=array_to_path runshostsdirs -[ -n "$runshostspath" ] && RUNSHOSTSPATH="$runshostspath" -[ -n "$RUNSSCRIPTSPATH" ] || RUNSSCRIPTSPATH=: -[ -n "$RUNSMODULESPATH" ] || RUNSMODULESPATH=: -[ -n "$RUNSHOSTSPATH" ] || RUNSHOSTSPATH=: +runs_after_parse_args __PARSED_HOSTS=() __PARSED_FILES=() @@ -207,6 +184,17 @@ function fix_hosts() { array_map hosts __dot_is_localhost } +function save_initial_paths() { + RUNSSCRIPTSPATH_BACKUP="$RUNSSCRIPTSPATH" + RUNSMODULESPATH_BACKUP="$RUNSMODULESPATH" + RUNSHOSTSPATH_BACKUP="$RUNSHOSTSPATH" +} +function restore_initial_paths() { + RUNSSCRIPTSPATH="$RUNSSCRIPTSPATH_BACKUP" + RUNSMODULESPATH="$RUNSMODULESPATH_BACKUP" + RUNSHOSTSPATH="$RUNSHOSTSPATH_BACKUP" +} + ################################################################################ # Configuration de l'accès par clé aux hôtes @@ -234,12 +222,15 @@ if [ "$action" == "configure" ]; then ${force_make_archive:+--force-make-archive} \ -h "$user@$host" || continue + save_initial_paths + [ -n "$auto_runsmod" ] && runsmod_autoconf etitle "Configuration initiale pour runs" \ - "$scriptdir/runs" \ - --runsscriptspath "$RUNSSCRIPTSPATH" \ - --runsmodulespath "$RUNSMODULESPATH" \ - --runshostspath "$RUNSHOSTSPATH" \ - --init -h "$host" + "$scriptdir/runs" --no-auto-runsmod \ + --runsscriptspath "$RUNSSCRIPTSPATH" \ + --runsmodulespath "$RUNSMODULESPATH" \ + --runshostspath "$RUNSHOSTSPATH" \ + --init -h "$host" + restore_initial_paths done exit 0 fi @@ -252,6 +243,8 @@ make_archive= ## Hôtes sur lesquels faire le déploiement if array_isempty hosts; then + save_initial_paths + [ -n "$auto_runsmod" ] && runsmod_autoconf all array_split hostsdirs "$RUNSHOSTSPATH" : cwd="$(pwd)" for hostsdir in "${hostsdirs[@]}"; do @@ -264,6 +257,7 @@ if array_isempty hosts; then break fi done + restore_initial_paths fi if array_isempty hosts; then read_value "Entrez une liste d'hôtes séparés par ':'" hosts "localhost" @@ -320,6 +314,9 @@ for userhost in "${hosts[@]}"; do enote "Le nom d'hôte utilisé est $host" fi + save_initial_paths + [ -n "$auto_runsmod" ] && runsmod_autoconf one "$host" + if [ "$host" != "localhost" ]; then if [ -n "$init" ]; then action=--init @@ -328,7 +325,7 @@ for userhost in "${hosts[@]}"; do fi estep "Vérification de la configuration de l'hôte pour runs" - "$scriptdir/runs" \ + "$scriptdir/runs" --no-auto-runsmod \ --runsscriptspath "$RUNSSCRIPTSPATH" \ --runsmodulespath "$RUNSMODULESPATH" \ --runshostspath "$RUNSHOSTSPATH" \ @@ -348,6 +345,7 @@ for userhost in "${hosts[@]}"; do # Création de l'export etitle "Préparation de l'export" args=( + --no-auto-runsmod --export --runsexportdir "$exportdir" --runsscriptspath "$RUNSSCRIPTSPATH" --runsmodulespath "$RUNSMODULESPATH" @@ -455,5 +453,7 @@ bits=$MYBITS"' eend fi + restore_initial_paths + eend done diff --git a/runs b/runs index f140889..99ea08c 100755 --- a/runs +++ b/runs @@ -58,22 +58,6 @@ Gestion des scripts -z Forcer la réinstallation des scripts qui se basent sur shouldrun/setdone" } -RUNSSCRIPTSPATH= -RUNSSCRIPTSDIRS=() -RUNSMODULESPATH= -RUNSMODULESDIRS=() -RUNSHOSTSPATH= -RUNSHOSTSDIRS=() -RUNSDOMAINS=() -RUNSDOMAIN= -set_defaults runs -[ -n "$RUNSSCRIPTSPATH" ] && RUNSSCRIPTSDIRS=("$RUNSSCRIPTSPATH" "${RUNSSCRIPTSDIRS[@]}") -array_fix_paths RUNSSCRIPTSDIRS; setx RUNSSCRIPTSPATH=array_to_path RUNSSCRIPTSDIRS -[ -n "$RUNSMODULESPATH" ] && RUNSMODULESDIRS=("$RUNSMODULESPATH" "${RUNSMODULESDIRS[@]}") -array_fix_paths RUNSMODULESDIRS; setx RUNSMODULESPATH=array_to_path RUNSMODULESDIRS -[ -n "$RUNSHOSTSPATH" ] && RUNSHOSTSDIRS=("$RUNSHOSTSPATH" "${RUNSHOSTSDIRS[@]}") -array_fix_paths RUNSHOSTSDIRS; setx RUNSHOSTSPATH=array_to_path RUNSHOSTSDIRS - function runs_path_required() { die "Vous devez définir $1 dans ~/etc/default/runs" } @@ -81,6 +65,8 @@ function runs_path_undefined() { ewarn "La variable $1 n'est pas définie dans ~/etc/default/runs" } +runs_before_parse_args + auto_runsmod=1 action=runs create_verbose= @@ -139,15 +125,7 @@ parse_opts "${PRETTYOPTS[@]}" \ -z RUNSRESET=1 \ @ args -- "$@" && set -- "${args[@]}" || die "$args" -[ -n "$runsscriptspath" ] && runsscriptsdirs=("$runsscriptspath" "${runsscriptsdirs[@]}") -array_fix_paths runsscriptsdirs; setx runsscriptspath=array_to_path runsscriptsdirs -[ -n "$runsscriptspath" ] && RUNSSCRIPTSPATH="$runsscriptspath" -[ -n "$runsmodulespath" ] && runsmodulesdirs=("$runsmodulespath" "${runsmodulesdirs[@]}") -array_fix_paths runsmodulesdirs; setx runsmodulespath=array_to_path runsmodulesdirs -[ -n "$runsmodulespath" ] && RUNSMODULESPATH="$runsmodulespath" -[ -n "$runshostspath" ] && runshostsdirs=("$runshostspath" "${runshostsdirs[@]}") -array_fix_paths runshostsdirs; setx runshostspath=array_to_path runshostsdirs -[ -n "$runshostspath" ] && RUNSHOSTSPATH="$runshostspath" +runs_after_parse_args if [ "$action" == runs \ -o "$action" == init -o "$action" == verify \ @@ -172,17 +150,7 @@ if [ "$action" == runs \ fi fi -if [ -n "$auto_runsmod" ] && __runsmod_loadconf && runsmod_checkenv --check-only; then - function __runsmod_clone_or_pull() { :; } - runsmod_setup_vars - runsmod_update_vars self "$RUNSHOST" - runsmod_teardown_vars - #XXX - echo === SCRIPTSDIRS ===; array_each SCRIPTSDIRS ppath - echo === MODULESDIRS ===; array_each MODULESDIRS ppath - echo === HOSTSDIRS ===; array_each HOSTSDIRS ppath - #XXX -fi +[ -n "$auto_runsmod" ] && runsmod_autoconf if ! is_root && [ -n "$run_as_root" ]; then # reconstruire la ligne de commande @@ -214,9 +182,6 @@ if ! is_root && [ -n "$run_as_root" ]; then for recipe in "${recipes[@]}"; do args=("${args[@]}" -r "$recipe") done - [ -n "$RUNSSCRIPTSPATH" ] || RUNSSCRIPTSPATH=: - [ -n "$RUNSMODULESPATH" ] || RUNSMODULESPATH=: - [ -n "$RUNSHOSTSPATH" ] || RUNSHOSTSPATH=: args=("${args[@]}" ${runshost:+-h "$runshost"} ${runssysname:+--sysname "$runssysname"} ${runssysdist:+--sysdist "$runssysdist"} ${runssysver:+--sysver "$runssysver"} ${runsbits:+--bits "$runsbits"} ${RUNSSCRIPTSPATH:+--runsscriptspath "$RUNSSCRIPTSPATH"} From f0a71e4598c676aa07abbd5cfe2124e5bf8a47ea Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 31 Aug 2016 12:19:36 +0400 Subject: [PATCH 10/11] =?UTF-8?q?bug=20avec=20la=20g=C3=A9n=C3=A9ration=20?= =?UTF-8?q?de=20sysinfos.conf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ulib/runs | 3 ++- runs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ulib/runs b/lib/ulib/runs index ba1ce46..4fa2f06 100644 --- a/lib/ulib/runs +++ b/lib/ulib/runs @@ -141,7 +141,8 @@ function runs_initdir() { estep "Création de $(ppath "$runshostdir/runs.conf")" echo "$runsconft" >"$runshostdir/runs.conf" fi - if [ ! -f "$runshostdir/sysinfos.conf" ]; then + [ -f "$runshostdir/sysinfos.conf" ] || touch "$runshostdir/sysinfos.conf" + if [ -z "$(<"$runshostdir/sysinfos.conf" filter_comment)" ]; then estep "Création de $(ppath "$runshostdir/sysinfos.conf")" echo "$sysinfost" >"$runshostdir/sysinfos.conf" fi diff --git a/runs b/runs index 99ea08c..89423ba 100755 --- a/runs +++ b/runs @@ -221,8 +221,8 @@ bits=$MYBITS" resolv_ips __runs_ips "$runshost" if [ -z "${__runs_ips[*]}" ]; then - eerror "$runshost ne semble pas être une adresse valide." - ask_yesno "Voulez-vous réellement utiliser cette adresse, bien qu'elle n'existe pas dans le DNS?" N || die + check_interaction -c && eerror "$runshost ne semble pas être une adresse valide." + ask_yesno "Voulez-vous réellement utiliser cette adresse, bien qu'elle n'existe pas dans le DNS?" C || die fi if [ "$action" == "init" ]; then From 8854469a6416a765318ce1f990efde6a7c28a759 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Wed, 31 Aug 2016 22:24:47 +0400 Subject: [PATCH 11/11] =?UTF-8?q?maj=20de=20la=20config=20par=20d=C3=A9fau?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ulib/runsmod.defaults | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/lib/ulib/runsmod.defaults b/lib/ulib/runsmod.defaults index c3aee3c..d75b162 100644 --- a/lib/ulib/runsmod.defaults +++ b/lib/ulib/runsmod.defaults @@ -11,14 +11,36 @@ RUNSMOD_SHALLOW=auto RUNSMOD_UPDATE=auto RUNSMOD_IDENTITY= RUNSMOD_BASEURL= -RUNSMOD_SCRIPTS_URLS=(hosts/%h/runs hosts/%h/all//runs runss) -RUNSMOD_MODULES_URLS=(hosts/%h/modules/%m hosts/%h/%m hosts/%h/all modules/%m) -# quand on supportera %n -#RUNSMOD_MODULES_URLS=(hosts/%h/modules/%m hosts/%h/%m hosts/%h/all hosts/all/%n/%m modules/%m) -RUNSMOD_HOSTS_URLS=(runsh) +RUNSMOD_SCRIPTS_URLS=( + hosts/%h/runs + hosts/%h/all//runs + runss +) +RUNSMOD_MODULES_URLS=( + hosts/%h/modules/%m + hosts/%h/%m + hosts/%h/all//modules + hosts/%h/all + # quand on supportera %n + #hosts/all/%n/%m + modules/%m +) +RUNSMOD_HOSTS_URLS=( + runsh +) RUNSMOD_BASEDIR="$HOME/runs" -RUNSMOD_MAP=() -RUNSMOD_PROFILES=(pvcs vcs jclain) +RUNSMOD_MAP=( + # mapping par défaut + runss:"$HOME/wop/runs" + modules:"$HOME/wop/modules" + hosts:"$HOME/wop/hosts" + runsh:"$HOME/wop/hosts/all/hosts" +) +RUNSMOD_PROFILES=( + pvcs + vcs + jclain +) # pvcs RUNSMOD_pvcs_BASEURL=(http://pvcs.univ.run/anongit http://pvcs.univ-reunion.fr/anongit)