#!/bin/bash
# Regenerates latex-ucs data directory after modifications of the
# glyph sources in /usr/share/latex-ucs-dev/config
#
# (c) 2003 Martin Pitt <mpitt@debian.org>
#
# This program is distributed under the terms and conditions of the
# GNU General Public License. See /usr/share/common-licenses/GPL for
# details.

set -e

UCSDIR=/usr/share/texmf/tex/latex/ucs
DATADIR=$UCSDIR/data
BACKUPDIR=$DATADIR.old
CFGDIR=/usr/share/latex-ucs-dev/config

COMMENTS='--nocomments'
DOBACKUP=1

# parse command line options
while test "$1"; do
    case "$1" in
	-b|--nobackup) unset DOBACKUP ;;
	-c|--comments) COMMENTS='--comments' ;;
	-h|--help)
	    echo "update-latex-ucs (c) 2003 Martin Pitt <mpitt@debian.org>"
	    echo "This script regenerates the latex-ucs data directory from glyph sources."
	    echo "See the manpage update-latex-ucs(8) page for details."
	    echo
	    echo Options:
	    echo   -b, --nobackup	: do not generate a backup directory
	    echo   -c, --comments	: call makeunidef.pl with --comments
	    echo   -h, --help	: this help message
	    exit 0
	    ;;
	*) 
	    echo Invalid option $1
	    exit 1
	    ;;
    esac
    shift
done

# do backup if requested

if test $DOBACKUP && test -d $BACKUPDIR; then
    echo Removing old data backup dir $BACKUPDIR
    rm -rf $BACKUPDIR
fi

if test $DOBACKUP && test -d $DATADIR; then
    echo Renaming current data directory to $BACKUPDIR
    mv $DATADIR $BACKUPDIR
else
    rm -rf $DATADIR
fi

# call makeunidef.pl

mkdir $DATADIR
echo Generating the data directory from $CFGDIR sources...
/usr/share/latex-ucs-dev/makeunidef.pl -t $DATADIR $COMMENTS \
   -d /usr/share/unidata/UnicodeData*.txt $CFGDIR/*.ucf $CFGDIR/*.ucf.gz

# rehash LaTeX

mktexlsr

if test $DOBACKUP; then echo Done. You may remove the backup directory $BACKUPDIR if everything went well.; fi 

