les répertoires de profil partagé et de machine sont traités comme un seul répertoire
This commit is contained in:
parent
e3f76cdcbc
commit
e9089d86d6
2
bashrc
2
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
|
||||
|
|
|
@ -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 "$@"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
@ -287,7 +318,7 @@ function uenv_install_profiles() {
|
|||
|
||||
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"
|
||||
|
|
2
profile
2
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
|
||||
|
|
13
uenv
13
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
|
||||
|
|
Loading…
Reference in New Issue