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
__runsmod_get -a baseurls BASEURL
have_repolistfile=
for baseurl in "${baseurls[@]}"; do
setx repolistfile=__runsmod_get_repolistfile "$baseurl"
# si le fichier n'existe pas, il faut mettre à jour
[ -f "$repolistfile" ] || return 0
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,11 +267,12 @@ 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
__runsmod_get -a baseurls BASEURL
for baseurl in "${baseurls[@]}"; do
setx repolistfile=__runsmod_get_repolistfile "$baseurl"
update="$force"
@ -258,6 +285,8 @@ function runsmod_update_repolists() {
setx mtime=stat -c %Y "$repolistfile"
[ $(($now - $mtime)) -lt 86400 ] || update=1
fi
error=
if [ -n "$update" ]; then
local list
ebegin "$baseurl"
@ -265,10 +294,15 @@ function runsmod_update_repolists() {
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,7 +407,8 @@ 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
__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
@ -430,6 +465,7 @@ function runsmod_clone_or_pull() {
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
@ -447,6 +483,7 @@ function runsmod_clone_or_pull() {
done
done
done
done
## Ensuite, traiter les dépôts de module
@ -458,7 +495,8 @@ function runsmod_clone_or_pull() {
modules=("$@")
for RUNSMOD_PROFILE in "${RUNSMOD_PROFILES[@]}"; do
setx baseurl=__runsmod_get BASEURL || continue
__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
@ -540,6 +578,7 @@ function runsmod_clone_or_pull() {
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
@ -562,6 +601,7 @@ function runsmod_clone_or_pull() {
done
done
done
done
for module in "${modules[@]}"; do
[ "$module" == "*" ] && continue

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