préparer le calcul automatique des chemins
This commit is contained in:
parent
2fbc599113
commit
40f5347656
150
lib/ulib/runsmod
150
lib/ulib/runsmod
|
@ -140,22 +140,24 @@ function __runsmod_fixurl() {
|
||||||
function __runsmod_mapdir() {
|
function __runsmod_mapdir() {
|
||||||
# mapper le répertoire $1, avec $2 est le répertoire de base à partir
|
# mapper le répertoire $1, avec $2 est le répertoire de base à partir
|
||||||
# desquels les mappings sont définis
|
# desquels les mappings sont définis
|
||||||
|
# retourner vrai si un mapping a eu lieu
|
||||||
local dir="$1" basedir="$2"
|
local dir="$1" basedir="$2"
|
||||||
local -a maps
|
local -a maps
|
||||||
local map from to
|
local map from to
|
||||||
dir="${dir#$basedir/}"
|
[ -n "$basedir" ] && dir="${dir#$basedir/}"
|
||||||
__runsmod_get -a maps MAP
|
__runsmod_get -a maps MAP
|
||||||
for map in "${maps[@]}"; do
|
for map in "${maps[@]}"; do
|
||||||
splitpair "$map" from to
|
splitpair "$map" from to
|
||||||
if [ "$dir" == "$from" ]; then
|
if [ "$dir" == "$from" ]; then
|
||||||
echo "$to"
|
echo "$to"
|
||||||
return
|
return 0
|
||||||
elif [ "${dir#$from/}" != "$dir" ]; then
|
elif [ "${dir#$from/}" != "$dir" ]; then
|
||||||
echo "$to/${dir#$from/}"
|
echo "$to/${dir#$from/}"
|
||||||
return
|
return 0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
echo "$dir"
|
echo "$dir"
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function __runsmod_getpath_from_baseurl() {
|
function __runsmod_getpath_from_baseurl() {
|
||||||
|
@ -219,11 +221,13 @@ function __runsmod_fixinfo() {
|
||||||
|
|
||||||
function runsmod_checkenv() {
|
function runsmod_checkenv() {
|
||||||
# vérifier l'environement. créer les répertoires nécessaires.
|
# 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
|
if [ -z "$RUNSMOD_BASEDIR" ]; then
|
||||||
eerror "Vous devez définir RUNSMOD_BASEDIR"
|
[ -z "$check_only" ] && eerror "Vous devez définir RUNSMOD_BASEDIR"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if [ ! -d "$RUNSMOD_BASEDIR" ]; then
|
if [ ! -d "$RUNSMOD_BASEDIR" -a -z "$check_only" ]; then
|
||||||
estep "Création de $(ppath "$RUNSMOD_BASEDIR")"
|
estep "Création de $(ppath "$RUNSMOD_BASEDIR")"
|
||||||
mkdir -p "$RUNSMOD_BASEDIR" || return 1
|
mkdir -p "$RUNSMOD_BASEDIR" || return 1
|
||||||
fi
|
fi
|
||||||
|
@ -432,6 +436,7 @@ function runsmod_clone_or_pull() {
|
||||||
edebug "...... repospec=$repospec"
|
edebug "...... repospec=$repospec"
|
||||||
__runsmod_has_vmodule "$repospec" && continue
|
__runsmod_has_vmodule "$repospec" && continue
|
||||||
if [[ "$repospec" == *//* ]]; then
|
if [[ "$repospec" == *//* ]]; then
|
||||||
|
reposuffixes=()
|
||||||
reposuffix="${repospec#*//}"
|
reposuffix="${repospec#*//}"
|
||||||
[ -n "$reposuffix" ] && reposuffix="/$reposuffix"
|
[ -n "$reposuffix" ] && reposuffix="/$reposuffix"
|
||||||
repospec="${repospec%%//*}"
|
repospec="${repospec%%//*}"
|
||||||
|
@ -451,19 +456,19 @@ function runsmod_clone_or_pull() {
|
||||||
reposuffixes=("$reposuffix")
|
reposuffixes=("$reposuffix")
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
reposuffix=
|
reposuffixes=("")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
reponames=()
|
reponames=()
|
||||||
if __runsmod_has_vhost "$repospec"; then
|
if __runsmod_has_vhost "$repospec"; then
|
||||||
if [ -n "$all_hosts" ]; then
|
if [ -n "$all_hosts" ]; then
|
||||||
setx repospec=__runsmod_replace1 "$repospec" "*"
|
setx rs1=__runsmod_replace1 "$repospec" "*"
|
||||||
__runsmod_match_repo_add repolist "$repospec" reponames
|
__runsmod_match_repo_add repolist "$rs1" reponames
|
||||||
elif [ -n "$host" ]; then
|
elif [ -n "$host" ]; then
|
||||||
setx reponame=__runsmod_replace1 "$repospec" "$host"
|
setx rs1=__runsmod_replace1 "$repospec" "$host"
|
||||||
array_contains repolist "$reponame" && array_add reponames "$reponame"
|
array_contains repolist "$rs1" && array_add reponames "$rs1"
|
||||||
setx reponame=__runsmod_replace2 "$repospec" "$host"
|
setx rs2=__runsmod_replace2 "$repospec" "$host"
|
||||||
array_contains repolist "$reponame" && array_add reponames "$reponame"
|
array_contains repolist "$rs2" && array_add reponames "$rs2"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
array_contains repolist "$repospec" && array_add reponames "$repospec"
|
array_contains repolist "$repospec" && array_add reponames "$repospec"
|
||||||
|
@ -530,6 +535,7 @@ function runsmod_clone_or_pull() {
|
||||||
edebug "........ repospec=$repospec"
|
edebug "........ repospec=$repospec"
|
||||||
__runsmod_has_vmodule "$repospec" || continue
|
__runsmod_has_vmodule "$repospec" || continue
|
||||||
if [[ "$repospec" == *//* ]]; then
|
if [[ "$repospec" == *//* ]]; then
|
||||||
|
reposuffixes=()
|
||||||
reposuffix="${repospec#*//}"
|
reposuffix="${repospec#*//}"
|
||||||
[ -n "$reposuffix" ] && reposuffix="/$reposuffix"
|
[ -n "$reposuffix" ] && reposuffix="/$reposuffix"
|
||||||
repospec="${repospec%%//*}"
|
repospec="${repospec%%//*}"
|
||||||
|
@ -549,36 +555,36 @@ function runsmod_clone_or_pull() {
|
||||||
reposuffixes=("$reposuffix")
|
reposuffixes=("$reposuffix")
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
reposuffix=
|
reposuffixes=("")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
reponames=()
|
reponames=()
|
||||||
if [ -n "$all_modules" ]; then
|
if [ -n "$all_modules" ]; then
|
||||||
if __runsmod_has_vhost "$repospec"; then
|
if __runsmod_has_vhost "$repospec"; then
|
||||||
if [ -n "$all_hosts" ]; then
|
if [ -n "$all_hosts" ]; then
|
||||||
setx repospec=__runsmod_replace1 "$repospec" "*" "*"
|
setx rs1=__runsmod_replace1 "$repospec" "*" "*"
|
||||||
__runsmod_match_repo_add repolist "$repospec" reponames
|
__runsmod_match_repo_add repolist "$rs1" reponames
|
||||||
elif [ -n "$host" ]; then
|
elif [ -n "$host" ]; then
|
||||||
setx repospec=__runsmod_replace1 "$repospec" "$host" "*"
|
setx rs1=__runsmod_replace1 "$repospec" "$host" "*"
|
||||||
__runsmod_match_repo_add repolist "$repospec" reponames
|
__runsmod_match_repo_add repolist "$rs1" reponames
|
||||||
setx repospec=__runsmod_replace2 "$repospec" "$host" "*"
|
setx rs2=__runsmod_replace2 "$repospec" "$host" "*"
|
||||||
__runsmod_match_repo_add repolist "$repospec" reponames
|
__runsmod_match_repo_add repolist "$rs2" reponames
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
setx repospec=__runsmod_replace1 "$repospec" "" "*"
|
setx rs1=__runsmod_replace1 "$repospec" "" "*"
|
||||||
__runsmod_match_repo_add repolist "$repospec" reponames
|
__runsmod_match_repo_add repolist "$rs1" reponames
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if __runsmod_has_vhost "$repospec"; then
|
if __runsmod_has_vhost "$repospec"; then
|
||||||
if [ -n "$host" ]; then
|
if [ -n "$host" ]; then
|
||||||
setx reponame=__runsmod_replace1 "$repospec" "$host" "$module"
|
setx rs1=__runsmod_replace1 "$repospec" "$host" "$module"
|
||||||
array_contains repolist "$reponame" && array_add reponames "$reponame"
|
array_contains repolist "$rs1" && array_add reponames "$rs1"
|
||||||
setx reponame=__runsmod_replace2 "$repospec" "$host" "$module"
|
setx rs2=__runsmod_replace2 "$repospec" "$host" "$module"
|
||||||
array_contains repolist "$reponame" && array_add reponames "$reponame"
|
array_contains repolist "$rs2" && array_add reponames "$rs2"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
setx reponame=__runsmod_replace1 "$repospec" "" "$module"
|
setx rs1=__runsmod_replace1 "$repospec" "" "$module"
|
||||||
array_contains repolist "$reponame" && array_add reponames "$reponame"
|
array_contains repolist "$rs1" && array_add reponames "$rs1"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -620,8 +626,98 @@ function runsmod_clone_or_pull() {
|
||||||
return $r
|
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() {
|
function runsmod_teardown_vars() {
|
||||||
setx RUNSSCRIPTSPATH=array_join SCRIPTSDIRS :
|
setx RUNSSCRIPTSPATH=array_join SCRIPTSDIRS :
|
||||||
setx RUNSMODULESPATH=array_join MODULESDIRS :
|
setx RUNSMODULESPATH=array_join MODULESDIRS :
|
||||||
setx RUNSHOSTSPATH=array_join HOSTSDIRS :
|
setx RUNSHOSTSPATH=array_join HOSTSDIRS :
|
||||||
|
[ -n "$RUNSSCRIPTSPATH" ] || RUNSSCRIPTSPATH=:
|
||||||
|
[ -n "$RUNSMODULESPATH" ] || RUNSMODULESPATH=:
|
||||||
|
[ -n "$RUNSHOSTSPATH" ] || RUNSHOSTSPATH=:
|
||||||
}
|
}
|
||||||
|
|
18
runs
18
runs
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
# -*- 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
|
source "$(dirname "$0")/lib/ulib/ulib" || exit 1
|
||||||
urequire DEFAULTS runs
|
urequire DEFAULTS runs runsmod
|
||||||
|
|
||||||
function display_help() {
|
function display_help() {
|
||||||
uecho "$scriptname: Lancer un script avec le protocole runs
|
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"
|
ewarn "La variable $1 n'est pas définie dans ~/etc/default/runs"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto_runsmod=1
|
||||||
action=runs
|
action=runs
|
||||||
create_verbose=
|
create_verbose=
|
||||||
init_sysinfos=--NOT-SET--
|
init_sysinfos=--NOT-SET--
|
||||||
|
@ -105,6 +106,7 @@ runsvarsfile= # fichier contenant des définitions à charger
|
||||||
runs_init "$scriptdir"
|
runs_init "$scriptdir"
|
||||||
parse_opts "${PRETTYOPTS[@]}" \
|
parse_opts "${PRETTYOPTS[@]}" \
|
||||||
--help '$exit_with display_help' \
|
--help '$exit_with display_help' \
|
||||||
|
--no-auto-runsmod auto_runsmod= \
|
||||||
--i '$action=init;create_verbose=false' \
|
--i '$action=init;create_verbose=false' \
|
||||||
--init '$action=init;create_verbose=true' \
|
--init '$action=init;create_verbose=true' \
|
||||||
--verify action=verify \
|
--verify action=verify \
|
||||||
|
@ -170,9 +172,21 @@ if [ "$action" == runs \
|
||||||
fi
|
fi
|
||||||
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
|
if ! is_root && [ -n "$run_as_root" ]; then
|
||||||
# reconstruire la ligne de commande
|
# reconstruire la ligne de commande
|
||||||
args=()
|
args=(--no-auto-runsmod)
|
||||||
if [ "$action" == "init" ]; then
|
if [ "$action" == "init" ]; then
|
||||||
args=("${args[@]}" --init)
|
args=("${args[@]}" --init)
|
||||||
elif [ "$action" == "verify" ]; then
|
elif [ "$action" == "verify" ]; then
|
||||||
|
|
Loading…
Reference in New Issue