mapping des répertoires de destination

This commit is contained in:
Jephté Clain 2016-08-30 16:15:25 +04:00
parent 4b212d85ba
commit 96afb2a10f
2 changed files with 230 additions and 170 deletions

View File

@ -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é"

View File

@ -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"
)