3
0
Fork 0
forked from mirrors/nixpkgs

dict-dbs: fmt

This commit is contained in:
Felix Buehler 2021-07-25 00:18:13 +02:00
parent ca9212b56c
commit 9b6c409fb4

View file

@ -1,79 +1,82 @@
{stdenv, lib, dict}: { stdenv, lib, dict }:
({dictlist, allowList ? ["127.0.0.1"], denyList ? []}: ({ dictlist, allowList ? [ "127.0.0.1" ], denyList ? [ ] }:
/* /*
dictlist is a list of form dictlist is a list of form
[ { filename = /path/to/files/basename; [ { filename = /path/to/files/basename;
name = "name"; } ] name = "name"; } ]
basename.dict.dz and basename.index should be basename.dict.dz and basename.index should be
dict files. Or look below for other options. dict files. Or look below for other options.
allowList is a list of IP/domain *-wildcarded strings allowList is a list of IP/domain *-wildcarded strings
denyList is the same.. denyList is the same..
*/ */
let let
link_arguments = map link_arguments = map
(x: '' "${x.filename}" '') (x: '' "${x.filename}" '')
dictlist; dictlist;
databases = lib.concatStrings (map (x : databases = lib.concatStrings (map
"${x.name} ${x.filename}\n") dictlist); (x:
allow = lib.concatStrings (map (x: "allow ${x}\n") allowList); "${x.name} ${x.filename}\n")
deny = lib.concatStrings (map (x: "deny ${x}\n") denyList); dictlist);
accessSection = " allow = lib.concatStrings (map (x: "allow ${x}\n") allowList);
access { deny = lib.concatStrings (map (x: "deny ${x}\n") denyList);
${allow} accessSection = "
${deny} access {
} ${allow}
"; ${deny}
installPhase = '' }
mkdir -p $out/share/dictd ";
cd $out/share/dictd installPhase = ''
echo "${databases}" >databases.names mkdir -p $out/share/dictd
echo "${accessSection}" > dictd.conf cd $out/share/dictd
for j in ${toString link_arguments}; do echo "${databases}" >databases.names
name="$(egrep ' '"$j"\$ databases.names)" echo "${accessSection}" > dictd.conf
name=''${name% $j} for j in ${toString link_arguments}; do
if test -d "$j"; then name="$(egrep ' '"$j"\$ databases.names)"
if test -d "$j"/share/dictd ; then name=''${name% $j}
echo "Got store path $j" if test -d "$j"; then
j="$j"/share/dictd if test -d "$j"/share/dictd ; then
fi echo "Got store path $j"
echo "Directory reference: $j" j="$j"/share/dictd
i=$(ls "$j""/"*.index) fi
i="''${i%.index}"; echo "Directory reference: $j"
else i=$(ls "$j""/"*.index)
i="$j"; i="''${i%.index}";
fi else
echo "Basename is $i" i="$j";
locale=$(cat "$(dirname "$i")"/locale) fi
base="$(basename "$i")" echo "Basename is $i"
echo "Locale is $locale" locale=$(cat "$(dirname "$i")"/locale)
export LC_ALL=$locale base="$(basename "$i")"
export LANG=$locale echo "Locale is $locale"
if test -e "$i".dict.dz; then export LC_ALL=$locale
ln -s "$i".dict.dz export LANG=$locale
else if test -e "$i".dict.dz; then
cp "$i".dict . ln -s "$i".dict.dz
dictzip "$base".dict else
fi cp "$i".dict .
ln -s "$i".index . dictzip "$base".dict
dictfmt_index2word --locale $locale < "$base".index > "$base".word || true fi
dictfmt_index2suffix --locale $locale < "$base".index > "$base".suffix || true ln -s "$i".index .
dictfmt_index2word --locale $locale < "$base".index > "$base".word || true
dictfmt_index2suffix --locale $locale < "$base".index > "$base".suffix || true
echo "database $name {" >> dictd.conf echo "database $name {" >> dictd.conf
echo " data $out/share/dictd/$base.dict.dz" >> dictd.conf echo " data $out/share/dictd/$base.dict.dz" >> dictd.conf
echo " index $out/share/dictd/$base.index" >> dictd.conf echo " index $out/share/dictd/$base.index" >> dictd.conf
echo " index_word $out/share/dictd/$base.word" >> dictd.conf echo " index_word $out/share/dictd/$base.word" >> dictd.conf
echo " index_suffix $out/share/dictd/$base.suffix" >> dictd.conf echo " index_suffix $out/share/dictd/$base.suffix" >> dictd.conf
echo "}" >> dictd.conf echo "}" >> dictd.conf
done done
''; '';
in in
stdenv.mkDerivation { stdenv.mkDerivation {
name = "dictd-dbs"; name = "dictd-dbs";
buildInputs = [dict]; buildInputs = [ dict ];
inherit installPhase; inherit installPhase;
}) })