From c43cda0f4e3bb7309c2b9c38eec052e755fb579b Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Mon, 22 Jun 2015 00:47:43 +0400 Subject: [PATCH] =?UTF-8?q?les=20r=C3=A9pertoires=20de=20profil=20sont=20s?= =?UTF-8?q?p=C3=A9cifiques=20au=20nom=20de=20la=20machine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bashrc | 2 +- lib/ulib/uenv | 12 ++++++------ lib/ulib/uenv_update | 34 ++++++++++++++++++++++++++++------ profile | 2 +- uenv | 4 ++-- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/bashrc b/bashrc index a98d548..ffcd428 100644 --- a/bashrc +++ b/bashrc @@ -2,5 +2,5 @@ function uprovide() { :; } source @@dest@@/lib/ulib/uenv || return -__uenv_source_dirs @@dest@@/bashrc.d "$HOME/etc/bashrc.d" +__uenv_source_dirs @@dest@@/bashrc.d "$HOME/etc/bashrc.d" "$HOME/etc/${HOSTNAME%%.*}-bashrc.d" __uenv_cleanup diff --git a/lib/ulib/uenv b/lib/ulib/uenv index 4a1fe6d..7925dd8 100644 --- a/lib/ulib/uenv +++ b/lib/ulib/uenv @@ -13,7 +13,7 @@ function __uenv_check_file() { # ignorer les fichiers qui ont l'extension .ignore [ "${file%%.ignore}" != "$file" ] && return 1 - + # tester si le fichier est spécifique à une plateforme local system system="$(expr "$file" : ".*\\.\\[\\([^.]*\\)\\]")" @@ -23,16 +23,16 @@ function __uenv_check_file() { # tester si le fichier est spécifique à une machine local host - host="$(expr "$file" : ".*\\.on_\\([^.]*\\)")" + host="$(expr "$file" : ".*\\.host-\\([^.]*\\)")" [ -n "$host" -a "$host" != "$__myhostname" ] && return 1 - host="$(expr "$file" : ".*\\.noton_\\([^.]*\\)")" + host="$(expr "$file" : ".*\\.nothost-\\([^.]*\\)")" [ -n "$host" -a "$host" == "$__myhostname" ] && return 1 # tester si le fichier est spécifique à un utilisateur local user - user="$(expr "$file" : ".*\\.for_\\([^.]*\\)")" + user="$(expr "$file" : ".*\\.user-\\([^.]*\\)")" [ -n "$user" -a "$user" != "$USER" ] && return 1 - user="$(expr "$file" : ".*\\.notfor_\\([^.]*\\)")" + user="$(expr "$file" : ".*\\.notuser-\\([^.]*\\)")" [ -n "$user" -a "$user" == "$USER" ] && return 1 return 0 @@ -57,7 +57,7 @@ function __uenv_source_dirs() { source "$sio" else for file in "$dir/"*; do - if __uenv_check_file "$(dirname "$file")" "$(basename "$file")"; then + if __uenv_check_file "$(dirname -- "$file")" "$(basename -- "$file")"; then source "$file" fi done diff --git a/lib/ulib/uenv_update b/lib/ulib/uenv_update index 0530298..83767fc 100644 --- a/lib/ulib/uenv_update +++ b/lib/ulib/uenv_update @@ -119,6 +119,7 @@ function uenv_update_dir() { local __myhostname="$MYHOSTNAME" >"$sio" for file in "$dir/"*; do + [ -f "$file" ] || continue file="$(basename "$file")" files=("${files[@]}" "$file") __uenv_check_file "$dir" "$file" && echo "$file" >>"$sio" @@ -156,9 +157,13 @@ function uenv_update_dir() { } function uenv_set_destdirs() { - profiledestdir="$HOME/etc/profile.d" - bashrcdestdir="$HOME/etc/bashrc.d" - defaultdestdir="$HOME/etc/default" + local hostname="${HOSTNAME%%.*}" + shared_profiledestdir="$HOME/etc/profile.d" + shared_bashrcdestdir="$HOME/etc/bashrc.d" + shared_defaultdestdir="$HOME/etc/default" + profiledestdir="$HOME/etc/${hostname}-profile.d" + bashrcdestdir="$HOME/etc/${hostname}-bashrc.d" + defaultdestdir="$HOME/etc/${hostname}-default" } function uenv_sourced_in() { @@ -227,23 +232,40 @@ function uenv_install_profiles() { for prefix in profile bashrc default; do envsrcdir="${prefix}dir"; envsrcdir="$projdir/${!envsrcdir}" envdestdir="${prefix}destdir"; envdestdir="${!envdestdir}" + shadestdir="shared_${prefix}destdir"; shadestdir="${!shadestdir}" [ -n "$envsrcdir" -a -d "$envsrcdir" ] || continue array_from_lines envfiles "$(list_files "$envsrcdir")" for envfile in "${envfiles[@]}"; do envsrc="$envsrcdir/$envfile" envdest="$envdestdir/$envfile" + shadest="$shadestdir/$envfile" - mkdir -p "$envdestdir" + mkdir -p "$envdestdir" "$shadestdir" + if [ ! -f "$envdest" -a -f "$shadest" ]; then + # Si déjà installé en partagé, continuer à mettre à jour ce + # fichier-là + envdest="$shadest" + fi if [ ! -f "$envdest" ]; then estep "Installation du profil par défaut $envfile dans $(ppath "$envdestdir")" /bin/cp -f "$envsrc" "$envdestdir" - elif [ "$prefix" != "default" ] && ! endswith "$envfile" ".userconf" && testdiff "$envdest" "$envsrc"; then + elif [ "$prefix" == "default" ]; then + # ne jamais mettre à jour dans default + if testdiff "$envdest" "$envsrc"; then + estepi "Le profil $(ppath "$envdest") a été conservé" + fi + elif endswith "$envfile" ".userconf"; then + # ne jamais mettre à jour les fichiers .userconf + if testdiff "$envdest" "$envsrc"; then + estepi "Le profil $(ppath "$envdest") a été conservé" + fi + elif testdiff "$envdest" "$envsrc"; then estep "Le profil par défaut $envfile dans $(ppath "$envdestdir") a été modifié" if show_info; then eecho "Voici les différences détectées:" eecho "" - diff -u "$envdest" "$envsrcdir" 1>&2 + diff -u "$envdest" "$envsrc" 1>&2 eecho "" fi diff --git a/profile b/profile index 4176d45..9dcfadc 100644 --- a/profile +++ b/profile @@ -4,5 +4,5 @@ function uprovide() { :; } source @@dest@@/lib/ulib/uenv || return -__uenv_source_dirs @@dest@@/profile.d "$HOME/etc/profile.d" +__uenv_source_dirs @@dest@@/profile.d "$HOME/etc/profile.d" "$HOME/etc/${HOSTNAME%%.*}-profile.d" __uenv_cleanup diff --git a/uenv b/uenv index 05a7a48..231aa6e 100755 --- a/uenv +++ b/uenv @@ -73,7 +73,7 @@ if [ -n "$update" ]; then continue fi - etitle -s "$(ppath "$projdir")" + etitle "$(ppath "$projdir")" install_profiles=false profiledir=lib/profile.d @@ -100,7 +100,7 @@ if [ -n "$update" ]; then else ## Mettre uniquement à jour l'ordre de chargement des fichiers ## ~/etc/{profile.d,bashrc.d} - for dir in "$profiledestdir" "$bashrcdestdir"; do + for dir in "$shared_profiledestdir" "$shared_bashrcdestdir" "$profiledestdir" "$bashrcdestdir"; do [ -d "$dir" ] || continue estep "Mise à jour de $(ppath "$dir")" uenv_update_dir "$dir" "$envsetup_tmpfile"