myspell-dictionaries/update.sh

160 lines
5.1 KiB
Bash
Raw Normal View History

#!/bin/bash
DOWNLOAD='yes'
GIT_DIR='dictionaries'
VERBOSE='no'
function directories()
{
ls $GIT_DIR/*/dictionaries.xcu | sed -e 's:dictionaries/::' -e 's:/dictionaries.xcu::' | tr '\n' ' '
}
function locale_to_file_map()
{
cd $GIT_DIR
rm -f locale_to_file_map.txt
for dir in $dirs; do
cat $dir/dictionaries.xcu \
| grep -v '<!--' \
| grep -A1 'Locations\|Locales' \
| grep -v '\-\-\|Locations\|Locales' \
| sed s:%origin%:$dir:g \
| sed 's:.*<value>\(.*\)</value>.*:\1:' \
| while read files; do
read locs
echo $dir: $locs @ $files | tr '-' '_' >> locale_to_file_map.txt
done
done
cd ..
}
function dir_locales()
{
dir=$1
grep "^$dir:" $GIT_DIR/locale_to_file_map.txt | sed 's/.*: //' | sed 's/ @.*//' | tr ' ' '\n' | sort -u | tr '\n' ' '
}
function locale_files()
{
loc=$1
grep $loc $GIT_DIR/locale_to_file_map.txt | sed 's:.*@ ::' | tr ' ' '\n' | sort -u | tr '\n' ' '
}
function description()
{
dir=$1
grep '<name lang="en.*">' dictionaries/$dir/description.xml | sed -e 's:.*<name lang="en.*">::' -e 's:</name>.*::' | tr '\n' ' ' | sed 's:[ \t]*$::'
}
#
# download present git version, remove .git, unify layout
# and create locale symlinks
#
if [ $DOWNLOAD == "yes" ]; then
rm -rf $GIT_DIR
git clone git://anongit.freedesktop.org/libreoffice/$GIT_DIR
rm -rf $GIT_DIR/.git
for dir in ca gd_GB; do
cp --force $GIT_DIR/$dir/dictionaries/* dictionaries/$dir
sed -i 's:dictionaries/::' dictionaries/$dir/dictionaries.xcu
done
elif [ ! -e $GIT_DIR ]; then
echo "ERROR: DOWNLOAD=$DOWNLOAD and $GIT_DIR doesn't exist"
exit 1
fi
#
# create dir <-> locales <-> files mapping
# in $GIT_DIR/locale_to_file_map.txt
#
dirs=$(directories)
[ "$VERBOSE" == "yes" ] && echo directiories: $dirs
locale_to_file_map
# create symlinks in $GIT_DIR/$dir, e. g. es_GT -> es_ANY
for dir in $dirs; do
dir_locs=$(dir_locales $dir)
[ "$VERBOSE" == "yes" ] && echo "DICTIONARY: $dir ($dir_locs)"
for l in $dir_locs; do
loc_files=$(locale_files $l)
[ "$VERBOSE" == "yes" ] && echo " $l: $loc_files"
for f in $loc_files; do
f=`basename $f`
prefix=""
if [[ $f == hyph* ]] || [[ $f == th* ]]; then
# nice collision with th_ for thesaurus
if [ "$f" != "th_TH.aff" ] && [ "$f" != "th_TH.dic" ]; then
prefix=`echo $f | sed 's:_.*:_:'`
fi
fi
#echo FILE: $f
ext=`echo $f | sed 's:.*\.::'`
# file or link for this locale/extension exist yet, do not create symlink
if ls $GIT_DIR/$dir/$prefix*$l*.$ext &> /dev/null; then
continue;
fi
# work around which is bug imho in dictionaries.xcu.
# It references file that doesn't exist.
if [ ! -e "$GIT_DIR/$dir/$f" ]; then
continue;
fi
linkname=$prefix$l.$ext
ln -sf $f $GIT_DIR/$dir/$linkname
done
done
done
#
# generate myspell-dictionaries.spec
#
cp myspell-dictionaries.spec.in myspell-dictionaries.spec
sed -i "s:@DO_NOT_EDIT_COMMENT@:DO NOT EDIT THIS SPEC FILE:" myspell-dictionaries.spec
date=`date +%Y%m%d`
sed -i "s:@VERSION@:$date:" myspell-dictionaries.spec
for subpackage in $dirs; do
desc=$(description $subpackage)
sum="MySpell $subpackage Dictionary"
dir_locs=$(dir_locales $subpackage)
sed -i "s#@METADATA@#%package -n myspell-$subpackage\n@METADATA@#" myspell-dictionaries.spec
sed -i "s#@METADATA@#Summary: $sum\n@METADATA@#" myspell-dictionaries.spec
sed -i "s#@METADATA@#Group: Productivity/Text/Spell\n@METADATA@#" myspell-dictionaries.spec
sed -i "s#@METADATA@#Requires: myspell-dictionaries\n@METADATA@#" myspell-dictionaries.spec
sed -i "s#@METADATA@#Provides: myspell-dictionary\n@METADATA@#" myspell-dictionaries.spec
for l in $dir_locs; do
sed -i "s#@METADATA@#Provides: locale(OpenOffice_org:$l)\n@METADATA@#" myspell-dictionaries.spec
sed -i "s#@METADATA@#Provides: locale(libreoffice:$l)\n@METADATA@#" myspell-dictionaries.spec
sed -i "s#@METADATA@#Provides: locale(seamonkey-spellchecker:$l)\n@METADATA@#" myspell-dictionaries.spec
done
sed -i "s#@METADATA@#\n@METADATA@#" myspell-dictionaries.spec
sed -i "s#@METADATA@#%description -n myspell-$subpackage\n@METADATA@#" myspell-dictionaries.spec
sed -i "s#@METADATA@#$desc.\n@METADATA@#" myspell-dictionaries.spec
sed -i "s#@METADATA@#\n@METADATA@#" myspell-dictionaries.spec
done
sed -i "s:@METADATA@::" myspell-dictionaries.spec
sed -i "s:@LANG_DIRS@:$dirs:" myspell-dictionaries.spec
for subpackage in $dirs; do
sed -i "s:@FILES@:%files -n myspell-$subpackage -f $subpackage.list\n@FILES@:" myspell-dictionaries.spec
sed -i "s:@FILES@:\n@FILES@:" myspell-dictionaries.spec
done
sed -i "s:@FILES@::" myspell-dictionaries.spec
#
# creating source archive
#
[ $DOWNLOAD == "yes" ] && tar cJf dictionaries.tar.xz dictionaries
[ $DOWNLOAD == "yes" ] && rm -r dictionaries
echo OK
#
# advice at the end ..
#
echo
echo With osc diff, figure out if there is a new package.
echo If yes, add its license in License: tag of both
echo *.spec and *.spec.in
echo if this license is not there yet.
echo