diff --git a/.udir b/.udir index b8ace89..c816bf3 100644 --- a/.udir +++ b/.udir @@ -18,7 +18,7 @@ kvm_service= openvz_service= configure_variables=(dest uninst_utools rm_utools kvm_service openvz_service) -configure_dest_for=(bashrc profile lib/uinst/conf lib/uinst/rootconf lib/profile.d/nutools lib/bashrc.d/bash_completion lib/init.d/kvm-stop-all legacy/sysinc/utools legacy/sysinc/system_caps legacy/sysinc/private/init) +configure_dest_for=(bashrc profile lib/uinst/conf lib/uinst/rootconf lib/profile.d/nutools.shared lib/bashrc.d/bash_completion.shared lib/init.d/kvm-stop-all legacy/sysinc/utools legacy/sysinc/system_caps legacy/sysinc/private/init) config_scripts=(lib/uinst/conf lib/uinst/system_caps.legacy) install_profiles=true profiledir=lib/profile.d diff --git a/CHANGES.txt b/CHANGES.txt index b212449..814901a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,11 @@ +## Version 2.1.0 du 22/06/2015-10:25 + +2a3eb76 Intégration de la branche uenv-modifs +bd8c7f8 correction d'un bug avec le nom final +d73c929 correction d'un bug avec le choix du répertoire de destination +e9089d8 les répertoires de profil partagé et de machine sont traités comme un seul répertoire +e3f76cd possibilité de spécifier si un profil doit être installé dans le répertoire de profil partagé + ## Version 2.0.0 du 22/06/2015-00:48 8286b29 Intégration de la branche uenv-modifs diff --git a/VERSION.txt b/VERSION.txt index 227cea2..7ec1d6d 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -2.0.0 +2.1.0 diff --git a/bashrc b/bashrc index ffcd428..bca2482 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" "$HOME/etc/${HOSTNAME%%.*}-bashrc.d" +__uenv_source_dirs @@dest@@/bashrc.d "$HOME/etc/bashrc.${HOSTNAME%%.*}.d" __uenv_cleanup diff --git a/lib/bashrc.d/bash_completion b/lib/bashrc.d/bash_completion.shared similarity index 100% rename from lib/bashrc.d/bash_completion rename to lib/bashrc.d/bash_completion.shared diff --git a/lib/bashrc.d/color_ls.[Darwin] b/lib/bashrc.d/color_ls.[Darwin].shared similarity index 100% rename from lib/bashrc.d/color_ls.[Darwin] rename to lib/bashrc.d/color_ls.[Darwin].shared diff --git a/lib/bashrc.d/color_ls.[Linux] b/lib/bashrc.d/color_ls.[Linux].shared similarity index 100% rename from lib/bashrc.d/color_ls.[Linux] rename to lib/bashrc.d/color_ls.[Linux].shared diff --git a/lib/bashrc.d/color_ls.[SunOS] b/lib/bashrc.d/color_ls.[SunOS].shared similarity index 100% rename from lib/bashrc.d/color_ls.[SunOS] rename to lib/bashrc.d/color_ls.[SunOS].shared diff --git a/lib/bashrc.d/confirm_rm,mv,cp b/lib/bashrc.d/confirm_rm,mv,cp.shared similarity index 100% rename from lib/bashrc.d/confirm_rm,mv,cp rename to lib/bashrc.d/confirm_rm,mv,cp.shared diff --git a/lib/bashrc.d/ls_options b/lib/bashrc.d/ls_options.shared similarity index 100% rename from lib/bashrc.d/ls_options rename to lib/bashrc.d/ls_options.shared diff --git a/lib/profile.d/bash_prompt b/lib/profile.d/bash_prompt.shared similarity index 100% rename from lib/profile.d/bash_prompt rename to lib/profile.d/bash_prompt.shared diff --git a/lib/profile.d/bin_in_path b/lib/profile.d/bin_in_path.shared similarity index 100% rename from lib/profile.d/bin_in_path rename to lib/profile.d/bin_in_path.shared diff --git a/lib/profile.d/dbus b/lib/profile.d/dbus.shared similarity index 100% rename from lib/profile.d/dbus rename to lib/profile.d/dbus.shared diff --git a/lib/profile.d/histcontrol b/lib/profile.d/histcontrol.shared similarity index 100% rename from lib/profile.d/histcontrol rename to lib/profile.d/histcontrol.shared diff --git a/lib/profile.d/local_bin_in_path.[Darwin] b/lib/profile.d/local_bin_in_path.[Darwin].shared similarity index 100% rename from lib/profile.d/local_bin_in_path.[Darwin] rename to lib/profile.d/local_bin_in_path.[Darwin].shared diff --git a/lib/profile.d/nutools b/lib/profile.d/nutools.shared similarity index 100% rename from lib/profile.d/nutools rename to lib/profile.d/nutools.shared diff --git a/lib/profile.d/proxy b/lib/profile.d/proxy.shared similarity index 100% rename from lib/profile.d/proxy rename to lib/profile.d/proxy.shared diff --git a/lib/profile.d/webobjects b/lib/profile.d/webobjects.shared similarity index 100% rename from lib/profile.d/webobjects rename to lib/profile.d/webobjects.shared diff --git a/lib/ulib/base b/lib/ulib/base index 711cb8b..c6218ef 100644 --- a/lib/ulib/base +++ b/lib/ulib/base @@ -3962,7 +3962,10 @@ function get_defaults_files() { __gd_fs=("${__gd_fs[@]}" "/etc/default/$__gd_f") __gd_found=1 fi - if [ -r "$HOME/etc/default/$__gd_f" ]; then + if [ -r "$HOME/etc/default.${HOSTNAME%%.*}/$__gd_f" ]; then + __gd_fs=("${__gd_fs[@]}" "$HOME/etc/default.${HOSTNAME%%.*}/$__gd_f") + __gd_found=1 + elif [ -r "$HOME/etc/default/$__gd_f" ]; then __gd_fs=("${__gd_fs[@]}" "$HOME/etc/default/$__gd_f") __gd_found=1 fi @@ -3976,9 +3979,9 @@ function get_defaults_files() { } function set_defaults() { -# Pour chaque argument, sourcer /etc/default/$arg *et* ~/etc/default/$arg si -# ceux-ci existent. *Sinon*, lire $scriptdir/lib/default/$arg si ce fichier -# existe +# Pour chaque argument, sourcer /etc/default/$arg *et* (en priorité +# ~/etc/default.$HOSTNAME/$arg ou à défaut ~/etc/default/$arg) si ceux-ci +# existent. *Sinon*, lire $scriptdir/lib/default/$arg si ce fichier existe local -a __sd_fs local __sd_f get_defaults_files __sd_fs "$@" diff --git a/lib/ulib/uenv b/lib/ulib/uenv index 7925dd8..e7de9ea 100644 --- a/lib/ulib/uenv +++ b/lib/ulib/uenv @@ -57,7 +57,8 @@ function __uenv_source_dirs() { source "$sio" else for file in "$dir/"*; do - if __uenv_check_file "$(dirname -- "$file")" "$(basename -- "$file")"; then + [ -f "$file" ] || continue + if __uenv_check_file "$dir" "$(basename -- "$file")"; then source "$file" fi done diff --git a/lib/ulib/uenv_update b/lib/ulib/uenv_update index 83767fc..4a7a01b 100644 --- a/lib/ulib/uenv_update +++ b/lib/ulib/uenv_update @@ -7,18 +7,20 @@ uprovide uenv_update urequire base uenv function __uenv_move_after() { - # Dans le fichier $1, déplacer la ligne $2 après la ligne $3. + # Dans le fichier $1, déplacer la ligne $2 après la ligne commençant par + # l'expression régulière '^$3:' # Si la ligne $2 n'existe pas, ne rien faire # Si la ligne $3 n'existe pas ou vaut '*', mettre la ligne $2 en dernier. # Si $4 est spécifié, l'utiliser comme fichier temporaire. local tmpfile="$4" [ -n "$tmpfile" ] || ac_set_tmpfile tmpfile - # XXX Il faudrait quoter $2 et $3 pour éviter les caractères spéciaux de - # grep! - if quietgrep "^$2$" "$1"; then - if [ "$3" != "*" ] && quietgrep "^$3$" "$1"; then - awkrun line="$2" after="$3" ' + # XXX Il faudrait quoter $3 pour éviter les caractères spéciaux de grep! + if quietgrep -F "$2" "$1"; then + local re_after="$3" + [ "$re_after" != "*" ] && re_after="^$re_after:" + if [ "$re_after" != "*" ] && quietgrep "$re_after" "$1"; then + awkrun line="$2" re_after="$re_after" ' BEGIN { found_line = 0 found_after = 0 @@ -29,10 +31,10 @@ BEGIN { next } } -! found_after && $0 == after { +! found_after && $0 ~ re_after { found_after = 1 if (found_line) { - # si nous avons trouvé la ligne avant after, la mettre juste après + # si nous avons trouvé la ligne avant re_after, la mettre juste après # sinon, pas la peine de faire de modification print print line @@ -41,7 +43,7 @@ BEGIN { } { print } END { - if (! found_after && after == "*") { + if (! found_after && re_after == "*") { if (found_line) { print line } @@ -49,7 +51,7 @@ END { }' <"$1" >"$tmpfile" && cat "$tmpfile" >"$1" else - grep -v "^$2$" "$1" >"$tmpfile" + grep -vF "$2" "$1" >"$tmpfile" echo "$2" >>"$tmpfile" cat "$tmpfile" >"$1" fi @@ -57,18 +59,20 @@ END { } function __uenv_move_before() { - # Dans le fichier $1, déplacer la ligne $2 avant la ligne $3. + # Dans le fichier $1, déplacer la ligne $2 avant la ligne commençant par + # l'expression régulière '^$3:' # Si la ligne $2 n'existe pas, ne rien faire # Si la ligne $3 n'existe pas ou vaut '*', mettre la ligne $2 en premier. # Si $4 est spécifié, l'utiliser comme fichier temporaire. local tmpfile="$4" [ -n "$tmpfile" ] || ac_set_tmpfile tmpfile - # XXX Il faudrait quoter $2 et $3 pour éviter les caractères spéciaux de - # grep! - if quietgrep "^$2$" "$1"; then - if [ "$3" != "*" ] && quietgrep "^$3$" "$1"; then - awkrun line="$2" before="$3" ' + # XXX Il faudrait quoter $3 pour éviter les caractères spéciaux de grep! + if quietgrep -F "$2" "$1"; then + local re_before="$3" + [ "$re_before" != "*" ] && re_before="^$re_before:" + if [ "$re_before" != "*" ] && quietgrep "$re_before" "$1"; then + awkrun line="$2" re_before="$re_before" ' BEGIN { found_line = 0 found_before = 0 @@ -79,7 +83,7 @@ BEGIN { next } } -! found_before && ($0 == before || before == "*") { +! found_before && ($0 ~ re_before || re_before == "*") { found_before = 1 if (! found_line) { print line @@ -92,7 +96,7 @@ BEGIN { cat "$tmpfile" >"$1" else echo "$2" >"$tmpfile" - grep -v "^$2$" "$1" >>"$tmpfile" + grep -vF "$2" "$1" >>"$tmpfile" cat "$tmpfile" >"$1" fi fi @@ -107,36 +111,47 @@ function uenv_update_dir() { # $3(=$1) est le répertoire de destination. Si $1 est un répertoire de # préparation temporaire, on peut spécifier grâce à $3 quel est le # répertoire final après préparation. - local dir="$(abspath "$1")" - local destdir="${3:-$dir}" - local tmpfile="$2" - [ -n "$tmpfile" ] || ac_set_tmpfile tmpfile + # S'ils sont spécifiés, les arguments $4..* sont des répertoires contenant + # des fichiers de profils supplémentaires qu'il faut considérer aussi. Dans + # ce cas, $3 est ignoré. + local dir="$(abspath "$1")"; shift + local tmpfile="$1"; shift + local destdir="${1:-$dir}"; shift local sio="$dir/.source_in_order" - local before after file + local before after file filename local -a files + [ -n "$tmpfile" ] || ac_set_tmpfile tmpfile + [ $# -gt 0 ] && destdir= + set -- "$dir" "$@" + local __uname_system="$UNAME_SYSTEM" 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" + for dir in "$@"; do + for file in "$dir/"*; do + [ -f "$file" ] || continue + files=("${files[@]}" "$file") + filename="$(basename -- "$file")" + __uenv_check_file "$dir" "$filename" && echo "$filename:$file" >>"$sio" + done done # traiter d'abord les fichiers qui ont '@before *' ou '@after *' local -a nfiles for file in "${files[@]}"; do - before="$(<"$dir/$file" awk '$0 ~ /^##@before / { print $2; exit 0 }')" + filename="$(basename -- "$file")" + + before="$(<"$file" awk '$0 ~ /^##@before / { print $2; exit 0 }')" if [ "$before" == "*" ]; then - __uenv_move_before "$sio" "$file" "$before" "$tmpfile" + __uenv_move_before "$sio" "$filename:$file" "$before" "$tmpfile" else array_set nfiles "$file" fi - after="$(<"$dir/$file" awk '$0 ~ /^##@after / { print $2; exit 0 }')" + + after="$(<"$file" awk '$0 ~ /^##@after / { print $2; exit 0 }')" if [ "$after" == "*" ]; then - __uenv_move_after "$sio" "$file" "$after" "$tmpfile" + __uenv_move_after "$sio" "$filename:$file" "$after" "$tmpfile" else array_set nfiles "$file" fi @@ -146,13 +161,29 @@ function uenv_update_dir() { # est avant *, si A est traité avant B, A risque de se trouver après B si B # est déplacé au début de la liste. for file in "${nfiles[@]}"; do - before="$(<"$dir/$file" awk '$0 ~ /^##@before / { print $2; exit 0 }')" - [ -n "$before" -a "$before" != "*" ] && __uenv_move_before "$sio" "$file" "$before" "$tmpfile" - after="$(<"$dir/$file" awk '$0 ~ /^##@after / { print $2; exit 0 }')" - [ -n "$after" -a "$after" != "*" ] && __uenv_move_after "$sio" "$file" "$after" "$tmpfile" + filename="$(basename -- "$file")" + + before="$(<"$file" awk '$0 ~ /^##@before / { print $2; exit 0 }')" + [ -n "$before" -a "$before" != "*" ] && __uenv_move_before "$sio" "$filename:$file" "$before" "$tmpfile" + + after="$(<"$file" awk '$0 ~ /^##@after / { print $2; exit 0 }')" + [ -n "$after" -a "$after" != "*" ] && __uenv_move_after "$sio" "$filename:$file" "$after" "$tmpfile" done - awkrun destdir="$destdir" '{ print "source " destdir "/" $0 }' <"$sio" >"$tmpfile" && + awkrun destdir="$destdir" '{ + pos = match($0, /:/) + if (pos != 0) { + filename = substr($0, 1, pos - 1) + file = substr($0, pos + 1) + if (destdir != "") { + print "source " destdir "/" filename + } else { + print "source " file + } + } else { + print "source " destdir "/" $0 + } +}' <"$sio" >"$tmpfile" && cat "$tmpfile" >"$sio" } @@ -161,9 +192,9 @@ function uenv_set_destdirs() { 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" + profiledestdir="$HOME/etc/profile.${hostname}.d" + bashrcdestdir="$HOME/etc/bashrc.${hostname}.d" + defaultdestdir="$HOME/etc/default.${hostname}" } function uenv_sourced_in() { @@ -224,7 +255,8 @@ cas, il faut décommenter la ligne dans ~/.bash_profile qui source ~/.profile" function uenv_install_profiles() { local projdir="$1" profiledir="$2" bashrcdir="$3" defaultdir="$4" local tmpfile - local prefix envsrcdir envdestdir envfiles envfile envsrc envdest + local prefix envsrcdir envdestdir shadestdir envfiles envfile envsrc envdest shadest + local shared_profiledestdir shared_bashrcdestdir shared_defaultdestdir local profiledestdir bashrcdestdir defaultdestdir uenv_set_destdirs @@ -234,22 +266,32 @@ function uenv_install_profiles() { envdestdir="${prefix}destdir"; envdestdir="${!envdestdir}" shadestdir="shared_${prefix}destdir"; shadestdir="${!shadestdir}" [ -n "$envsrcdir" -a -d "$envsrcdir" ] || continue + mkdir -p "$envdestdir" "$shadestdir" array_from_lines envfiles "$(list_files "$envsrcdir")" for envfile in "${envfiles[@]}"; do - envsrc="$envsrcdir/$envfile" - envdest="$envdestdir/$envfile" - shadest="$shadestdir/$envfile" - - mkdir -p "$envdestdir" "$shadestdir" - if [ ! -f "$envdest" -a -f "$shadest" ]; then - # Si déjà installé en partagé, continuer à mettre à jour ce - # fichier-là + if [ "${envfile%.shared}" != "$envfile" ]; then + # Avec l'extension .shared, toujours installer dans le + # répertoire des profils partagés + envsrc="$envsrcdir/$envfile" + envfile="${envfile%.shared}" + shadest="$shadestdir/$envfile" envdest="$shadest" + else + envsrc="$envsrcdir/$envfile" + envdest="$envdestdir/$envfile" + shadest="$shadestdir/$envfile" + if [ ! -f "$envdest" -a -f "$shadest" ]; then + # Si déjà installé en partagé, continuer à mettre à jour ce + # fichier-là + envdest="$shadest" + fi fi + + local actual_envdestdir="$(dirname -- "$envdest")" if [ ! -f "$envdest" ]; then - estep "Installation du profil par défaut $envfile dans $(ppath "$envdestdir")" - /bin/cp -f "$envsrc" "$envdestdir" + estep "Installation du profil par défaut $envfile dans $(ppath "$actual_envdestdir")" + /bin/cp -f "$envsrc" "$envdest" elif [ "$prefix" == "default" ]; then # ne jamais mettre à jour dans default if testdiff "$envdest" "$envsrc"; then @@ -261,7 +303,7 @@ function uenv_install_profiles() { 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é" + estep "Le profil par défaut $envfile dans $(ppath "$actual_envdestdir") a été modifié" if show_info; then eecho "Voici les différences détectées:" eecho "" @@ -269,15 +311,15 @@ function uenv_install_profiles() { eecho "" fi - if ask_yesno "Faut-il remplacer $(ppath "$envdestdir/$envfile") par le profil par défaut?" O; then - /bin/cp -f "$envsrc" "$envdestdir" + if ask_yesno "Faut-il remplacer $(ppath "$envdest") par le profil par défaut?" O; then + /bin/cp -f "$envsrc" "$envdest" fi fi done if [ "$prefix" != "default" ]; then estep "Mise à jour de l'ordre de lecture de $(ppath "$envdestdir")" - uenv_update_dir "$envdestdir" "$tmpfile" + uenv_update_dir "$envdestdir" "$tmpfile" "" "$shadestdir" fi done ac_clean "$tmpfile" diff --git a/profile b/profile index 9dcfadc..7311591 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" "$HOME/etc/${HOSTNAME%%.*}-profile.d" +__uenv_source_dirs @@dest@@/profile.d "$HOME/etc/profile.${HOSTNAME%%.*}.d" __uenv_cleanup diff --git a/uenv b/uenv index 231aa6e..610fa1d 100755 --- a/uenv +++ b/uenv @@ -100,9 +100,14 @@ if [ -n "$update" ]; then else ## Mettre uniquement à jour l'ordre de chargement des fichiers ## ~/etc/{profile.d,bashrc.d} - 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" + ac_set_tmpfile tmpfile + for prefix in profile bashrc; do + envdir="${prefix}dir"; envdir="${!envdir}" + shadir="shared_${prefix}dir"; shadir="${!shadir}" + + [ -d "$envdir" ] || continue + estep "Mise à jour de $(ppath "$envdir")" + uenv_update_dir "$envdir" "$tmpfile" "" "$shadir" done + ac_clean "$tmpfile" fi