* Support globbing in the source attribute of environment.etc entries.

svn path=/nixos/trunk/; revision=34158
This commit is contained in:
Eelco Dolstra 2012-05-17 18:43:45 +00:00
parent c10b41ad99
commit 91acb81b11
2 changed files with 32 additions and 13 deletions

View File

@ -90,10 +90,10 @@ in
{ source = jailConf; { source = jailConf;
target = "fail2ban/jail.conf"; target = "fail2ban/jail.conf";
} }
{ source = "${pkgs.fail2ban}/etc/fail2ban/action.d"; { source = "${pkgs.fail2ban}/etc/fail2ban/action.d/*.conf";
target = "fail2ban/action.d"; target = "fail2ban/action.d";
} }
{ source = "${pkgs.fail2ban}/etc/fail2ban/filter.d"; { source = "${pkgs.fail2ban}/etc/fail2ban/filter.d/*.conf";
target = "fail2ban/filter.d"; target = "fail2ban/filter.d";
} }
]; ];

View File

@ -1,23 +1,42 @@
source $stdenv/setup source $stdenv/setup
ensureDir $out/etc mkdir -p $out/etc
set -f
sources_=($sources) sources_=($sources)
targets_=($targets) targets_=($targets)
modes_=($modes) modes_=($modes)
set +f
for ((i = 0; i < ${#targets_[@]}; i++)); do for ((i = 0; i < ${#targets_[@]}; i++)); do
ensureDir $out/etc/$(dirname ${targets_[$i]}) source="${sources_[$i]}"
if ! test -e $out/etc/${targets_[$i]}; then target="${targets_[$i]}"
ln -s ${sources_[$i]} $out/etc/${targets_[$i]};
if [[ "$source" =~ '*' ]]; then
# If the source name contains '*', perform globbing.
mkdir -p $out/etc/$target
for fn in $source; do
ln -s "$fn" $out/etc/$target/
done
else else
echo "Duplicate entry ${targets_[$i]} -> ${sources_[$i]}"
if test "$(readlink $out/etc/${targets_[$i]})" != "${sources_[$i]}"; then mkdir -p $out/etc/$(dirname $target)
echo "Mismatched duplicate entry $(readlink $out/etc/${targets_[$i]}) <-> ${sources_[$i]}" if ! [ -e $out/etc/$target ]; then
exit 1 ln -s $source $out/etc/$target
else
echo "Duplicate entry $target -> $source"
if test "$(readlink $out/etc/$target)" != "$source"; then
echo "Mismatched duplicate entry $(readlink $out/etc/$target) <-> $source"
exit 1
fi
fi fi
fi;
if test "${modes_[$i]}" != symlink; then if test "${modes_[$i]}" != symlink; then
echo "${modes_[$i]}" > $out/etc/${targets_[$i]}.mode echo "${modes_[$i]}" > $out/etc/$target.mode
fi
fi fi
done done