#!/bin/sh

fmtdir=/etc/texmf/fmt.d
ucf_sourcedir=/usr/share/tex-common
#UCF="ucf --verbose -d --debconf-ok"
UCF="ucf --debconf-ok"

oldfile=00tetex.cnf
newfile=01tetex.cnf

# rename 00tetex.cnf to 01tetex.cnf
if [ -f $fmtdir/$oldfile ]; then 
  if [ ! -f $fmtdir/$newfile ]; then
    # not yet transitioned
    mv $fmtdir/$oldfile $fmtdir/$newfile
  else
    # some older experimental version has installed the new file, but not 
    # transitioned the old one.
    current_md5sum=`md5sum $fmtdir/$oldfile | cut -d ' ' -f 1`
    if [ "$current_md5sum" = "55811af3562faf342261dbc3b5e060a2" ]; then
      rm $fmtdir/$oldfile
    else
      # we do nothing; experimental users should be able to solve this
      :
    fi
  fi
fi

# an older version of tetex-bin ucf-registered the file with double
# slashes, this breaks ucf
if grep -q "/etc/texmf/fmt.d//01tetex.cnf" /var/lib/ucf/hashfile; then
  $UCF --purge "/etc/texmf/fmt.d//01tetex.cnf"
fi

$UCF $ucf_sourcedir/$newfile $fmtdir/$newfile
