From 40f53476567eb12b307c7cc8b55fd56717752b06 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Tue, 30 Aug 2016 18:44:20 +0400 Subject: [PATCH] =?UTF-8?q?pr=C3=A9parer=20le=20calcul=20automatique=20des?= =?UTF-8?q?=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