#!/bin/sh

# set SAVEPWD to current dir. and set PATH to contain current dir.
SAVEPWD=`pwd`
#PATH=.:$PATH:$SAVWPWD:.
PATH=.:$PATH:$SAVWPWD
export PATH

# Test whether it has 'gawk'
gawkloc=`which gawk|grep ":"`
if test "$gawkloc" = ""; then
   gawkloc=`which gawk|grep "no gawk"`
fi
if test "$gawkloc" != ""; then
   gawkbin="awk"
else
   gawkbin="gawk"
fi

gawkbin=awk
export gawkbin

# Mw script
  echoprompt=`echo -n "."`
  if test "$echoprompt" = "."; then
     echomode="-n "; echocr=""
  else
     echoprompt=`echo  ".\c"`
     if test "$echoprompt" = "."; then
        echomode=""; echocr="\c"
     else 
        echomode="-e "; echocr="\c"
     fi
  fi

#

chooseredhat="n"
while test "$chooseredhat" = "y"
do
clear
echo " ";echo " ";echo " "
echo " "
echo "       unix tά:"
echo " "
#echo "       0. Redhat7.0+CLE1.0  Linux "
echo "       1. Redhat  Linux (ΨLw˦D)"
echo "       2. L"
echo "       q. w"
echo " "
echo $echomode "         J̹Ʀr 1,2  q w: "$echocrread
read inkey              

chooseredhat=""
case "$inkey" in
#  "0") Redhat="70";;
  "1") Redhat="62";;
  "2") Redhat="";;
  "q") exit ;;
   *) chooseredhat="y"
esac
done

#if test "$Redhat" = "y"; then
   gawkbin=awk
   export gawkbin
#fi


# Find name of unix system
unixname=`uname|$gawkbin '{print $0}'|tr '[A-Z]' '[a-z]'`
unixver=`uname -r|cut -d. -f 1`
if test "$unixname" = "sunos"; then
   if test "$unixver" = "5" -o "$unixver" != "4" -a "$unixver" != "3"; then
      unixname="solaris"
   else
      unixname="sunos" 
   fi
fi

if test "$unixname" = "linux"; then
   chsetupbig5Linux
   exit
fi


# if autodetection of unix system's name fails then ask users about ...

if test "$unixname" != "linux" -a "$unixname" != "freebsd" \
  -a "$unixname" != "solaris" -a "$unixname" != "sunos"; then


chooseunix="y"
while test "$chooseunix" = "y"
do
clear
echo " ";echo " ";echo " "
echo " "
echo "       A unix tά:"
echo " "
echo "       1. Linux"
echo "       2. FreeBSD"
echo "       3. Solaris"
echo "       4. SunOS"
echo "       q. w"
echo " "
echo $echomode "         J̹Ʀr 1,..,4  q w: "$echocrread
read inkey              

chooseunix=""
case "$inkey" in
  "1") unixname="linux";;
  "2") unixname="freebsd";;
  "3") unixname="solaris";;
  "4") unixname="sunos";;
  "q") exit ;;
   *) chooseunix="y"
esac
done

fi
##########
#
if test "$unixname" = "linux"; then
   chsetupbig5Linux
   exit
fi


# To unzip to have file 'gawk'
 if test "$unixname" != "linux"; then
  gunzip -dc chitex612/data/gawk."$unixname".gz > gawk
  chmod +x gawk
 fi

# To test if exist file 'gawk'
gawkloc=`which gawk|grep ":"`
if test "$gawkloc" = ""; then
   gawkloc=`which gawk|grep "no gawk"`
fi
if test "$gawkloc" != ""; then
   gawkbin="awk"
else
   gawkbin="gawk"
fi


if test "$Redhat" = "y"; then
   gawkbin=awk
   export gawkbin
fi


testmessage="n"

if test "$testmessage" = "n"; then 
###### Make new dir. temp and change dir. to it
if test ! -d temp; then
   mkdir temp
fi
cd temp



##### check tetex version #####
texmf=`kpsexpand '$TEXMF'|cut -d! -f 3`
echo "yes" > tmp@

if test -s $texmf/doc/tetex/README; then
tetexver=`grep "teTeX-" $texmf/doc/tetex/README|cut -d- -f 2|cut -f 1`
tetexver=`
$SAVEPWD/$gawkbin '{comma=index(tetexver,",")
 print substr(tetexver,1,comma-1)}' tetexver="$tetexver"  tmp@ `
tetexverold=`
$SAVEPWD/$gawkbin  \
'{if (tetexver < "1.0") {print "old"}}' tetexver="$tetexver" tmp@ `
else
  :
fi

#######    Welcome      #######
clear
echo " ";echo " ";echo " "
echo " "
echo "         ******************************************"
echo "         *                                        *"
echo "         *   wϥ  ChiTeX/ChiLaTeX (UNIX )  *"
echo "         *                                        *"
echo "         ******************************************"
echo " "
echo " "
echo " "   
echo "         ChiTeX (ChiTeX/ChiLaTeX) written by:"
echo "             Hung-Yih Chen () (yih@math.ncu.edu.tw) "
echo " "
echo "         This version: ChiTeX 6.1.2p7.9, March 19, 2002"
echo " "
echo $echomode "         Press enter key to continue "$echocr
read inkey

clear
echo " ";echo " "
echo " "
echo "         *************************************************"
echo "         *                                               *"
echo "         *   w˵{NAw ChiTeX 6.1.2p7.9       *"
#echo "         *   N ChiTeX 6.0.9-6.1.2p6 s 6.1.2p7    *"
echo "         *                                               *"
echo "         *   w ChiTeX 6.1.2p7.9 e, Atζw  *"
echo "         *   ˦ teTeX, teTeX  ̦n >= 1.0        *"
echo "         *    < 1.0 , ChiTeX YǷs\NL      *"
echo "         *   k{. ƱAN teTeX ss       *"
echo "         *                                               *"
echo "         *************************************************"
echo $echomode "         Press enter key to continue "$echocr
read inkey

if test "$LOGNAME" != "root"; then
rootmessage="y"
while test "$rootmessage" = "y"
do
clear
echo " ";echo " "
echo " "
echo "         **********************************************"
echo "         *                                            *"
echo "         *   AO super user \"root\"                 *"   
echo "         *   DAb teTeX ؿWgvQ, _h  *"
echo "         *   Lkiw                             *"
echo "         *                                            *"
echo "         **********************************************"
echo " "
echo "             c. ~w"
echo "             q. w" 
echo " "
echo $echomode "         J 'c'  'q' : "$echocr
read inkey

case $inkey in
  "c") rootmessage="n";;
  "q") rootmessage="n";rm -rf  $SAVEPWD/temp;rm -f *@;exit;;
    *) rootmessage="y";;
esac
done

fi


texversionmess="n"
if test "$texversionmess" = "y"; then
clear
echo " ";echo " "
echo " "
echo "         **********************************************"
echo "         *                                            *"
echo "         *   Atθ̪ teTeX  $tetexver          *"
if test "$tetexverold" = "old"; then
  echo "         *    < 1.0, ChiTeX YǷs\NLk    *"
  echo "         *   {. ƱAN teTeX ss      *"
  echo "         *   s, iw˨ϥ ChiTeX              *"
else
  echo "         *    >= 1.0, ChiTeX s\Ni         *"
  echo "         *   {. Ai~w ChiTeX                *"
fi

echo "         *                                            *"
echo "         **********************************************"
echo " "
echo $echomode "         Press enter key to continue "$echocr
read inkey
#fi
fi


choosemenu ( ) {
clear
echo " "
echo " "
echo " "
echo "             1. w ChiTeX 6.1.2p7.9 (All) "
echo "             2. s ChiTeX 6.0.9-6.1.2p5  6.1.2p7.9  "
echo "             q. w               "
echo "                                              "

echo $echomode "         J̹Ʀr 1,2  q w: "$echocr
read inkey
}

choosemenu


choosemenuno="y"
while test "$choosemenuno" = "y"
do
   case "$inkey" in
   "1") install="all"; choosemenuno="n";;
   "2") install="update"; choosemenuno="n";;
   "q") exit;;
   *) choosemenu;;
   esac
done


#updatemenu ( ) {
#######    Welcome      #######
clear
echo " ";echo " "
echo " "
if test "$install" = "update"; then
echo "         ******************************************"
echo "         *                                        *"
echo "         *   {bN}lsA  ChiTeX         *"
echo "         *   ChiTeX 6.1.2p7.9                     *"
echo "         *                                        *"
echo "         ******************************************"
else
echo "         ******************************************"
echo "         *                                        *"
echo "         *   {bN}lw  ChiTeX 6.1.2p7.9     *"
echo "         *                                        *"
echo "         ******************************************"
fi
echo " "
echo " "
echo " "
echo "         ChiTeX (ChiTeX/ChiLaTeX) written by:"
echo "             Hung-Yih Chen () (yih@math.ncu.edu.tw) "
echo " "
echo "         This version: ChiTeX 6.1.2p7.9, March 19, 2002"
echo " "
echo $echomode "         Press enter key to continue "$echocr
read inkey
#}

newttf2pk="y"




echo "yes" > tmp@
# In the following, we'll find path of
#  (1) fmt  (2) TEXMF (3) VARTEXFONTS (4) binary files
#

# (1)  find path of fmt #
#
fmt=`kpsexpand '$WEB2C' `
if test "$fmt" = ""; then
   fmt=`kpsexpand '$TEXFORMATS' `
fi
fmt=`
$gawkbin '
BEGIN{}
{
 exc=index(fmt,"!!")
 if (exc > 0)
    {fmt=substr(fmt,exc+2,length(fmt)-exc-1)}
 print fmt   
}
END{} ' fmt="$fmt" tmp@ `

fmtname=$fmt
echo "         fmtdir=$fmt found"

# (2) find path of TEXMF #
#
#kpsexpand=`which kpsexpand`

texmfdir=`kpsexpand '$TEXMF'|cut -d! -f 3`

texmf=$texmfdir
echo "         texmfdir=$texmfdir found"

# (3) Find path of VARTEXFONTS
#
VARTEXFONTS=`kpsexpand '$VARTEXFONTS' `
if test "$VARTEXFONTS" = ""; then
   VARTEXFONTS=`kpsexpand '$VARFONTS' `
fi
if test "$VARTEXFONTS" = ""; then
   VARTEXFONTS="/var/tmp/texfonts"
   mkdir -p $VARTEXFONTS
   chmod a+rwx $VARTEXFONTS
fi
export VARTEXFONTS

# (4) find path of binary files #
#
cd $SAVEPWD
if test -d .temp00$$;then
   /bin/rm -rf .temp00$$
fi
mkdir .temp00$$
cd .temp00$$
echo "yes" > tmp@

latex=`which latex`
bindir=`
$gawkbin '
BEGIN{}
{texloc=index(latex,"/latex")
 bindir=substr(latex,1,texloc-1)
 print bindir
}
END{} ' latex="$latex" tmp@ `

echo "         bindir=$bindir found"

#####################

checkmenu="y"
while test "$checkmenu" = "y"
do
clear
echo "         wΧAJؿ:  "
echo "         1.  texmf ؿ (@묰 /usr/.../texmf) :"
echo "               $texmf"
echo "         2.  *.fmt ɩҦbؿ (@묰 /usr/.../texmf/web2c) :"
echo "               $fmt"
echo "         3.  .../texfonts ؿ (@묰 /var/tmp/texfonts "
echo "           /var/lib/texmf  /var/texfonts 䤤tlؿ tfm, pk ) :"
echo "               $VARTEXFONTS"
echo "            YLؿ, Aiॲ run 'texmfconfig' h]wXؿ"
echo "         4.  i latex Ҧbؿ: "
echo "               $bindir "
echo " "
echo "         HW쪺ؿYOťؿNOT. "
echo "         "
echo "         YTJ "y" , _hJ '1'  '2',.. "
echo "         (HKsJӶؤ~ؿ)"
echo $echomode "         : " $echocr
read inkey

  
   case "$inkey" in
   "1") 
       echo " "
       echo "         texmf ؿ($texmf)"
       echo $echomode "         :" $echocr
       read keydir
       if test "$keydir" != ""; then 
          texmf=$keydir
       fi
       ;;
   "2") 
       echo " "
       echo "         *.fmt ɩҦbؿ($fmt)"
       echo $echomode "         :" $echocr
       read keydir
       if test "$keydir" != ""; then 
          fmt=$keydir
       fi
       ;;
   "3") 
       echo " "
       echo "          .../texfonts ؿ($VARTEXFONTS)"

       echo $echomode "         :" $echocr
       read keydir
       if test "$keydir" != ""; then 
          VARTEXFONTS=$keydir
       fi
       ;;
   "4") 
       echo " "
       echo "         i latex Ҧbؿ($bindir)"
       echo $echomode "         :" $echocr
       read keydir
       if test "$keydir" != ""; then 
          bindir=$keydir
       fi
       ;;
   "y") 

   checksubmenu="y"
   while test "$checksubmenu" = "y"
   do
     echo " "
     echo "         AؿT."
     echo "         ЦAJ "y"  T{, _hJ 'n' HAJ"
     echo $echomode "         : " $echocr
     read inkeya

     case "$inkeya" in
       "y")  checkmenu="n"; checksubmenu="n";;
       "n") checkmenu="y"; checksubmenu="n";;
       *)   checkmenu="y"; checksubmenu="y"; break ;;
     esac    
   done

     ;;
   *)  checkmenu="y"  ;;

   esac
done

Askstop="y"
while test "$Askstop" = "y"
do
clear
echo " "
echo "         ئwˤ覡:"
echo "         1.  ݤ覡"
echo "         2.  w˨쩳覡(|Uդ fmt files)"
echo "         "
echo "         J '1' M '2' "
echo " "
echo $echomode "         : " $echocr
read inkey
   case "$inkey" in
   "1") stopask="y"; Askstop="";;
   "2") stopask=""; Askstop="";;
   "*")  :  ;;
   esac
done


step2="y"
if test "$step2" = "y"; then
# In the following we'll modify files of README*,... given by
# $SAVEPWD/chitex612/doc

cd $SAVEPWD

step21="y"
if test "$step21" = "y"; then

# first made dir. 'docdir' and then put modified files (modified from 
#  $SAVEPWD/chitex612/doc) into  dir. 'docdir'

if test ! -d docdir; then
   mkdir docdir
fi
cd $SAVEPWD/chitex612/doc
# Move *.ps to ../ for the time being since we need not modify them

mv -f  *.ps $SAVEPWD/chitex612 2> /dev/null
docfiles=`/bin/ls `

for readmefile in $docfiles
do
 sed "s#/usr/local/TeX/share/texmf#$texmf#g" $readmefile > $readmefile".tmp"
 mv $readmefile".tmp" $SAVEPWD/docdir/$readmefile
 if test -s $SAVEPWD/docdir/README.adv; then
    mv $SAVEPWD/docdir/README.adv $SAVEPWD/docdir/README.install.advance
 fi
 if test -s $SAVEPWD/docdir/README.adv.gb; then
     mv $SAVEPWD/docdir/README.adv.gb $SAVEPWD/docdir/README.install.advance.gb
 fi
done

# Move $SAVEPWD/chitex612/*.ps to  $SAVEPWD/chitex612/doc
mv -f $SAVEPWD/chitex612/*.ps $SAVEPWD/chitex612/doc 2> /dev/null

cd $SAVEPWD

# Make dir. $texmf/doc/chitex and put modified 'README*' files on it
#
if test ! -d $texmf/doc/chitex; then
   mkdir -p $texmf/doc/chitex
fi
chmod +w $texmf/doc/chitex/*    # Add Mar. 26, 2000

cp -f docdir/* $texmf/doc/chitex
/bin/rm -rf $SAVEPWD/doc
mv docdir doc
cp chitex612/doc/*.ps $texmf/doc/chitex 2> /dev/null


echo "       End of modifying README*"
#echo $echomode "       Press any key to continue " $echocr
#read inkey

if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echocr
   read inkey
fi


fi # step21

############


echo "yes" > tmp@

# In the following we'll find directory of binary files 'chitex',... 
# which may exist before this installtion of chitex 
# The new binary files will be overwritten on them
# If not, it may have new and old binary files in the system and 
# old binary files may first be called...
#

cd $SAVEPWD/chitex612/bin
bindirfiles=`ls `
cd $SAVEPWD

for cmd in $bindirfiles \
    chitran0 chitran1 chitran2 chitran3 chitran3a chitran4 chitran5 \
    chitran6 chitran7 chitranp1 chitranp2 chitranp3 \
    chitexsub1 chicodelistc \
    chicode chifilt chadd chaddpfbname chicoder
do
latexfold=`which $cmd`
latexfoldchk=`which $cmd|grep ":"`
if test "$latexfoldchk" = ""; then
   latexfoldchk=`which $cmd|grep "no $cmd"`
fi


if test "$latexfoldchk" = ""; then
   if test -s $latexfold; then
      latex=`basename "$latexfold"`
   else
      latex=""
   fi
else
   latex=""
fi

if test "$latex" = ""; then
   latextmp=$bindir
else
latextmp=`
$gawkbin '
BEGIN{}
{texloc=index(latexdir,"/"latex)
 bindir=substr(latexdir,1,texloc-1)
 llen=length(bindir)
 if (substr(bindir,llen,1) == "/")
    {bindir=substr(bindir,1,llen-1)}
 print bindir
}
END{} ' latex="$latex" latexdir="$latexfold" tmp@ `
 eval $cmd"dir"=$latextmp
# eval echo \$$cmd"dir" 

fi
done

###### End of finding dir. binary files ######
fi # step2

step22="y"
if test "$step22" = "y"; then

####### backup old dvips and mv dvips to dvips.bin
######  Important
if test ! -s $dvipsdir/dvips.bin; then
   cp $dvipsdir/dvips $dvipsdir/dvips.bin
   if test ! -s $dvipsdir/dvips.bak; then
      cp $dvipsdir/dvips $dvipsdir/dvips.bak
   fi
fi
#########


echo " "
echo "         It will detect the environments. Wait!  "

# 

cd $SAVEPWD

echo "    "
#echo -e "         Press enter key to continue\c"
#echo $echomode "         Press enter key to continue" $echocr
#read inkey

if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echocr
   read inkey
fi


clear
echo " "
echo " ";echo " "
echo " "
echo "         ******************************************"
echo "         *                                        *"
if test "$install" = "update"; then
echo "         *            }ls, y              *"
else
echo "         *            }lw, y              *"
fi
echo "         *                                        *"
echo "         ******************************************"
echo " "


fi # step22
#fi # step2  

##### Make chinese fmt files and 
##### copy ttf2tfm, ttf2pk, ttf2pfb to $bindir or where it is in #####

step1="y"
if test "$step1" = "y"; then
   if test -s $ttf2tfmdir/ttf2tfm -a ! -s $ttf2tfmdir/ttf2tfm.bak; then 
       cp $ttf2tfmdir/ttf2tfm $ttf2tfmdir/ttf2tfm.bak
   fi
   if test -s $ttf2pkdir/ttf2pk -a ! -s $ttf2pkdir/ttf2pk.bak; then 
       cp $ttf2pkdir/ttf2pk $ttf2pkdir/ttf2pk.bak
   fi
   if test -s $ttf2pfbdir/ttf2pfb -a ! -s $ttf2pfbdir/ttf2pfb.bak; then 
       cp $ttf2pfbdir/ttf2pfb $ttf2pfbdir/ttf2pfb.bak
   fi

   if test "$unixname" = "linux" -o "$unixname" = "freebsd"; then
      cp $SAVEPWD/chitex612/data/t1asm.$unixname $bindir/t1asm
   fi


   echo $echomode "." $echocr       
#   if test "$unixname" != "solaris"; then
#       gunzip -dc chitex612/fmt/chggfile.$unixname.tgz|tar xvf - 2>&2 >/dev/null
#   else
#       gunzip -dc chitex612/fmt/chggfile.sunos.tgz|tar xvf - 2>&2 >/dev/null
#   fi

   if test "$unixnamea" = "Redhat70"; then
       gunzip -dc chitex612/fmt/chggfile.Redhat70.tgz|tar xvf - 2>&2 >/dev/null
   else
      if test "$unixname" != "solaris"; then
         gunzip -dc chitex612/fmt/chggfile.$unixname.tgz|tar xvf - 2>&2 >/dev/null
      else
         gunzip -dc chitex612/fmt/chggfile.sunos.tgz|tar xvf - 2>&2 >/dev/null
      fi
   fi


   echo $echomode "." $echocr       
   gunzip -dc chitex612/data/ttf2tfm.$unixname.gz> ttf2tfm
   chmod +x ttf2tfm
   cp -f ttf2tfm $ttf2tfmdir/ttf2tfm
   cp -f ttf2tfm $bindir
   /bin/rm -f ttf2tfm

   echo $echomode "." $echocr       
   gunzip -dc chitex612/data/ttf2pk.$unixname.gz> ttf2pk
   chmod +x ttf2pk
   cp -f ttf2pk $ttf2pkdir/ttf2pk
   cp -f ttf2pk $bindir

   /bin/rm -f ttf2pk
   echo $echomode "." $echocr       
   if test "$unixname" = "linux" -o "$unixname" = "freebsd"; then
      gunzip -dc chitex612/data/ttf2pfb.$unixname.gz> ttf2pfb
      chmod +x ttf2pfb
      cp -f ttf2pfb $ttf2pfbdir/ttf2pfb
      cp -f ttf2pfb $bindir
      /bin/rm -f ttf2pfb
      echo $echomode "." $echocr       
   fi


# To make chinese fmt files
#  
   ./chmkfmtp; ./chmkfmt
   echo $echomode "." $echocr       

   cp -f chitex.fmt $fmtname/chitex.fmt
   cp -f chitexl.fmt $fmtname/chitexl.fmt
   cp -f chitexg.fmt $fmtname/chitexg.fmt
   cp -f chitexlg.fmt $fmtname/chitexlg.fmt
   /bin/rm -f *.fmt

   ./chmkfmtp; ./chmkfmt2 2>/dev/nul
   echo $echomode "." $echocr          

#   if test "$tetexverold" != "old"; then
      cp -f pdfchitex.fmt $fmtname
      cp -f pdfchitexl.fmt $fmtname
      cp -f pdfchitexg.fmt $fmtname
      cp -f pdfchitexlg.fmt $fmtname
     /bin/rm -f *.fmt
#   fi

   echo $echomode "." $echocr       
   cp -f chmkfmt* $bindir      # move later
   /bin/rm -f chmkfmt*


echo "       End of make fmt files "
#echo $echomode "       Press any key to continue " $echoc
#read inkey                         

if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echocr
   read inkey
fi

#fi


#####  copy tfm. pk, ttf files ########
#
# if test "$install" = "all" -o "$install" = "update" ; then
#                 # Remove  May 7, 2000

##### Makedir .../texmf/fonts/chinese/...  #####
#     .../texmf/fonts/chinese/ttf link to .../texmf/fonts/ttf/chinese
#     if the latter exist otherwise make 'revervse ......' 


for texdir in tex/chinese fonts/chinese/ttf fonts/tfm/chinese/ntukai \
  fonts/tfm/chinese/fxntukai fonts/pk/chinese/fxntukai \
  fonts/tfm/chinese/fxntuli  fonts/tfm/chinese/fxntufs \
  fonts/tfm/chinese/nuwpstj fonts/pk/chinese/nuwpstj \
  fonts/tfm/chinese/moe_kai fonts/tfm/chinese/id030
do
   if test ! -d $texmf/$texdir; then
      if test "$texdir" = "fonts/chinese/ttf"; then
         if test -d "$texmf/fonts/ttf/chinese"; then
            ln -s $texmf/fonts/ttf/chinese $texmf/fonts/chinese/ttf 
         else
             mkdir -p $texmf/$texdir
         fi
      else
         mkdir -p $texmf/$texdir
      fi
   fi
#   if test  "$texdir" = "fonts/chinese/ttf"; then
#      if test ! -d $texmf/fonts/ttf/chinese; then
#        if test ! -d $texmf/fonts/ttf; then
#            mkdir -p $texmf/fonts/ttf
#        fi
#        ln -s $texmf/$texdir $texmf/fonts/ttf/chinese
#      fi
#   fi

done

#exit

##### Copy tfm files ########
cd $SAVEPWD
/bin/rm -rf tfm
mkdir tfm 
cd tfm
rm -rf pbktfm
mkdir pbktfm
cd pbktfm
gunzip -dc $SAVEPWD/chitex612/data/pbktfm.tgz|tar xvf -
if test ! -d $texmf/fonts/tfm/adobe/bookman; then
  mkdir -p $texmf/fonts/tfm/adobe/bookman
fi
cp *.tfm $texmf/fonts/tfm/adobe/bookman
cd ..
/bin/rm -rf pbktfm

gunzip -dc $Curdir/nuwpstfm.tgz|tar xvf -
cp -f nuwpstj*.tfm $texmf/fonts/tfm/chinese/nuwpstj
/bin/rm -f nuwpstj*.tfm
gunzip -dc $Curdir/moekatfm.tgz|tar xvf -
cp -f moe_kai*.tfm $texmf/fonts/tfm/chinese/moe_kai
/bin/rm -f moe_kai*.tfm

gunzip -dc $Curdir/idttftfm.tgz|tar xvf -
cp -f id030*.tfm $texmf/fonts/tfm/chinese/id030
/bin/rm -f id030*.tfm


cd $SAVEPWD
rmdir tfm
##### Copy pk files and ttf file ########
/bin/rm -rf pk
mkdir pk
cd pk
gunzip -dc $SAVEPWD/chitex612/data/fxntukai.tar.gz|tar xvf -
cp -f fxntukai*.*pk $texmf/fonts/pk/chinese/fxntukai
/bin/rm -f fxntukai*.*pk

cd $SAVEPWD
rmdir pk

###### Copy fx*'s tfm and link ttf files #######
tfm=$texmf/fonts/tfm
ttf=$texmf/fonts/chinese/ttf
/bin/cp chitex612/data/linkkai $tfm/chinese/fxntukai 
/bin/cp chitex612/data/linkfs $tfm/chinese/fxntufs
/bin/cp chitex612/data/linkli $tfm/chinese/fxntuli
#/bin/cp chitex612/data/fxntukai03.tfm $tfm/chinese/fxntukai 
/bin/cp chitex612/data/fxntukai03.tfm $tfm/chinese/fxntufs
/bin/cp chitex612/data/fxntukai03.tfm $tfm/chinese/fxntuli
/bin/cp chitex612/data/linkttf $ttf
#rm -f fxntukai03.tfm


cd $tfm/chinese/fxntukai 
/bin/rm -f fxntukai*.tfm
/bin/cp $SAVEPWD/chitex612/data/fxntukai03.tfm $tfm/chinese/fxntukai  
./linkkai 
/bin/rm -f linkkai
cd $tfm/chinese/fxntufs
/bin/rm -f fxntufs*.tfm
./linkfs
/bin/rm -f linkfs
cd $tfm/chinese/fxntuli
/bin/rm -f fxntuli*.tfm
./linkli
/bin/rm -f linkli

cd $ttf
/bin/rm -f fxntu*.ttf
./linkttf
/bin/rm -f linkttf

#exit

echo "       End of make copy tfm files "
#echo $echomode "       Press any key to continue " $echoc
#read inkey                         

if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echocr
   read inkey
fi


cd $SAVEPWD
##### Modify config.ps ######
#configps=$texmf/dvips/config/config.ps
configps=$texmf/dvips/config
$gawkbin '
BEGIN{}
{
   lpraloc=index($0,"o")
   vertloc=index($0,"|")
   lprbloc=index($0,"lpr")
   D600loc=index($0, "D 600")
   Modeloc=index($0, "M ljfour")
   D300loc=index($0, "D 300")
   Modeloca=index($0, "M cx")
  
   if (vertloc == 0 && lpraloc == 0 && lprbloc == 0 && D600loc == 0 \
       && Modeloc == 0 && D300loc == 0 && Modeloca == 0)
      {print $0 >  "config.ps.300"
       print $0 >  "config.ps.600"}
   else
    {
     if (lpraloc > 0 && lprbloc > 0 && vertloc > 0)
        {print "% " $0 > "config.ps.300"
         print "% " $0 > "config.ps.600"}
     else
        {if (D600loc > 0 || Modeloc > 0 || D300loc > 0 || Modeloca > 0)
            {print "% " $0 > "config.ps.300"
             print "% " $0 > "config.ps.600"
             if ((D600loc > 0 || D300loc > 0) && Dmodified == 0)
                {print "D 300" > "config.ps.300"
                 print "D 600" > "config.ps.600"
                 Dmodified=1}
             if ((Modeloc > 0 || Modeloca >0) && Mmodified == 0)
                {print "M cx" > "config.ps.300"
                 print "M ljfour" > "config.ps.600"
                 Mmodified=1
                 }
            }
         else
            {print $0 > "config.ps.300"
             print $0 > "config.ps.600"}
        }
    } 
}
END{}' $configps/config.ps



/bin/cp -f config.ps.300 config.ps.600 $configps
/bin/rm -f config.ps.300 config.ps.600
cd chitex612/data
/bin/cp -f XDvi.300 XDvi.600 $texmf/xdvi
cd $SAVEPWD

###### Modify specila.map ############
fontname=$texmf/fontname
chinesename=`grep "@c chinese fonts" $fontname/special.map`
if test "$chinesename" = ""; then
   cat chitex612/data/special.map.add >> $fontname/special.map
fi
/bin/rm -f chinesname@
###### end of modify specila.map  ###########

# fi   # Remove  May 7, 2000


echo "       End of modifying files "
#echo $echomode "       Press any key to continue " $echoc
#read inkey                         

if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echocr
   read inkey
fi



##### end of copying tfm. pk, ttf files

#exit

#####  copy adding ttf and pfb files #####  
##### 
cd $SAVEPWD

# Make dir. for save chineses pfb fonts  #########
if test ! -d $VARTEXFONTS/type1/fonts; then
   mkdir -p  $VARTEXFONTS/type1/fonts
fi
chmod a+rwx $VARTEXFONTS/type1/fonts

# for old teTeX 
if test ! -d $texmf/fonts/type1/chinese; then
   mkdir -p $texmf/fonts/type1/chinese
   ln -s $VARTEXFONTS/type1/fonts $texmf/fonts/type1/chinese/fonts \
       2>&2 >/dev/null
fi


# symbolic link files in $VARTEXFONTS/ttf/nbkai00mp.ttf to
# corr. files in $texmf/fonts/chinese/ttf

if test ! -d $VARTEXFONTS/ttf; then
   mkdir -p $VARTEXFONTS/ttf
fi
chmod a+rw $VARTEXFONTS/ttf

for nttffile in nbkai00mp nbsmi00lp ngkai00mp ngbsn00lp \
    nuwcxmf nCyberbit ncyberbit nuwpstj
do
 lnno=`ls -l $texmf/fonts/chinese/ttf/$nttffile".ttf"|$gawkbin '{print substr($1,1,1)}'`
 if test "$lnno" = "l" -a ! -s $texmf/fonts/chinese/ttf/$nttffile".ttf"; then
   /bin/rm -f $texmf/fonts/chinese/ttf/$nttffile".ttf"
   ln -s $VARTEXFONTS/ttf/$nttffile".ttf" $texmf/fonts/chinese/ttf/$nttffile".ttf"\
       2>/dev/null 
 else
   if test -s $texmf/fonts/chinese/ttf/$nttffile".ttf" -a \
       ! -s $VARTEXFONTS/ttf/$nttffile".ttf";then
      ln -s $texmf/fonts/chinese/ttf/$nttffile".ttf" \
          $VARTEXFONTS/ttf/$nttffile".ttf"  2>/dev/null 
   else
      if test ! -s $VARTEXFONTS/ttf/$nttffile".ttf";then
         /bin/rm -f $VARTEXFONTS/ttf/$nttffile".ttf" 
         ln -s $texmf/fonts/chinese/ttf/$nttffile".ttf" \
           $VARTEXFONTS/ttf/$nttffile".ttf"  2>/dev/null  
      fi
   fi
fi
done
#

fi # step1



cd $SAVEPWD

step3="y"
if test "$step3" = "y"; then
#############
# unzip TrueType files in ../ and copy them into
# .../texmf/fonts/chinese/ttf
#

ttfgzfiles=`ls $Curdir/*.ttf.gz`

clear
echo " "
echo "           It will unzip TrueType files: "
echo " "
cd ..
ls $Curdir/*.ttf.gz
cd $SAVEPWD
#echo "              $ttfgzfiles "
echo " "
echo "           in $Curdir/ and move them into      "
echo "              $texmf/fonts/chinese/ttf"
echo " "
#echo $echomode "           Press any enter key to continue" $echocr
#read inputkey

if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echocr
   read inkey
fi



echo " "
for cmd in $ttfgzfiles
do
 #   cmda=`echo "$cmd"|cut -d/ -f 2|cut -d. -f 1`
 #   cmdnogz=$cmda".ttf"
    echo "unzip $cmd"
#    gunzip -dc $cmd > $cmdnogz
    cp -f $cmd .
    gunzip *.gz
#    echo "mv -f $cmdnogz $texmf/fonts/chinese/ttf"
#    /bin/rm -f $texmf/fonts/chinese/ttf$cmdnogz
#    cp -f $cmdnogz $texmf/fonts/chinese/ttf
    cp -f *.ttf $texmf/fonts/chinese/ttf
    /bin/rm -f *.ttf
done

##### Use name of "moe_kai.ttf" instead of old "moekai.ttf" ,...
if test -s $texmf/fonts/chinese/ttf/moe_kai.ttf; then
   if test -s $texmf/fonts/chinese/ttf/moekai.ttf; then
      /bin/rm -f $texmf/fonts/chinese/ttf/moekai.ttf
#      ln -s $texmf/fonts/chinese/ttf/moe_kai.ttf \
#         $texmf/fonts/chinese/ttf/moekai.ttf 
   fi
   ln -s $texmf/fonts/chinese/ttf/moe_kai.ttf $texmf/fonts/chinese/ttf/moekai.ttf 
fi
if test -s $texmf/fonts/chinese/ttf/moe_sung.ttf; then
   if test -s $texmf/fonts/chinese/ttf/moesung.ttf; then
      /bin/rm -f $texmf/fonts/chinese/ttf/moesung.ttf
   fi
       ln -s $texmf/fonts/chinese/ttf/moe_sung.ttf \
           $texmf/fonts/chinese/ttf/moesung.ttf 
fi
   


########


###############
# unzip *tgz files in $Curdir/ into pfb and tfm files and copy them into
# and move pfb files into $VARTEXFONTS/type1/fonts
# and move tfm files into $VARTEXFONTS/tfm/chinese/...
#                             
#if test ! -d pfb; then
   /bin/rm -rf pfb
#fi
mkdir pfb
cd pfb
moekaifiles=`/bin/ls $Curdir/moekai*.tgz`
for tgzfile in $moekaifiles
do
   gunzip -dc $tgzfile|tar xvf -
   cp -f *.pfb $VARTEXFONTS/type1/fonts
   /bin/rm -f *.pfb
   if test ! -d $VARTEXFONTS/tfm/chinese/moe_kai_pfb; then
      mkdir -p $VARTEXFONTS/tfm/chinese/moe_kai_pfb
   fi
   chmod a+w $VARTEXFONTS/tfm/chinese
   chmod a+w $VARTEXFONTS/tfm/chinese/moe_kai_pfb
   cp -f *.tfm $VARTEXFONTS/tfm/chinese/moe_kai_pfb
   /bin/rm -f *.tfm
done

nwdsungfiles=`/bin/ls $Curdir/nwdsung*.tgz`
for tgzfile in $nwdsungfiles
do
   gunzip -dc $tgzfile|tar xvf -
   cp *.pfb $VARTEXFONTS/type1/fonts
   /bin/rm -f *.pfb
   if test ! -d $VARTEXFONTS/tfm/chinese/nbsmi00lp_pfb; then
      mkdir -p $VARTEXFONTS/tfm/chinese/nbsmi00lp_pfb
   fi
   chmod a+w $VARTEXFONTS/tfm/chinese/nbsmi00lp_pfb
   cp -f *.tfm $VARTEXFONTS/tfm/chinese/nbsmi00lp_pfb
   /bin/rm -f *.tfm
done

#ngbfiles=`/bin/ls $Curdir/nwdgkai.tgz;/bin/ls ../../nuwgsung.tgz`
ngbfiles="$Curdir/nwdgkai.tgz  $Curdir/nuwgsung.tgz"
for tgzfile in $ngbfiles
do
   if test "$tgzfile" = "$Curdir/nuwgsung.tgz"; then
      ngbdir="nuwpstj_pfb"
   else
      ngbdir="ngkai00mp_pfb"
   fi
   gunzip -dc $tgzfile|tar xvf -
   cp -f *.pfb $VARTEXFONTS/type1/fonts
   /bin/rm -f *.pfb
   if test ! -d $VARTEXFONTS/tfm/chinese/$ngbdir; then
      mkdir -p $VARTEXFONTS/tfm/chinese/$ngbdir
   fi
   cp -f *.tfm $VARTEXFONTS/tfm/chinese/$ngbdir
   /bin/rm -f *.tfm
done

#kaifiles=`/bin/ls $Curdir/kaipfb.tgz;/bin/ls ../../nuwgsung.tgz`
kaifiles="$Curdir/kaipfb.tgz $Curdir/lipfb.tgz $Curdir/fspfb.tgz \ 
 $Curdir/mrpfb.tgz $Curdir/idpfb.tgz"
for tgzfile in $kaifiles
do
   case $tgzfile in
     "$Curdir/kaipfb.tgz") kaidir="ntukai_pfb" ;;
     "$Curdir/lipfb.tgz") kaidir="ntuli_pfb" ;;
     "$Curdir/fspfb.tgz") kaidir="ntufs_pfb" ;;
     "$Curdir/mrpfb.tgz") kaidir="ntumr_pfb" ;;
     "$Curdir/idpfb.tgz") kaidir="id030_pfb" ;;
   esac

   gunzip -dc $tgzfile|tar xvf -
   cp -f *.pfb $VARTEXFONTS/type1/fonts
   /bin/rm -f *.pfb
   if test ! -d $VARTEXFONTS/tfm/chinese/$kaidir; then
      mkdir -p $VARTEXFONTS/tfm/chinese/$kaidir
   fi
   cp -f *.tfm $VARTEXFONTS/tfm/chinese/$kaidir
   /bin/rm -f *.tfm
done



echo "       End of copying pfb files "
#echo $echomode "       Press any key to continue " $echoc
#read inkey                         

if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echocr
   read inkey
fi


fi # step3



cd $SAVEPWD


#####

##### Modify specila.map more ############
fontname=$texmf/fontname
chinesename=`grep "@c chinese2 fonts" $fontname/special.map`
if test "$chinesename" = ""; then
   cat chitex612/data/special.map.add2 >> $fontname/special.map
fi
/bin/rm -f chinesname@
###### end of modify specila.map more ###########


step31="y"
if test "$step31" = "y"; then
##### Modify chitex.fdf ######
if test -s $texmf/tex/chinese/chitex.fdf; then
$gawkbin '
{ inline=$0
  choosepos=0; chfntscalepos=0
  choosepos=index(inline,"\\choosechfontadv")
  chfntscalepos=index(inline,"\\chfntscale")
 if (chfntscalepos>0)
    {dblpos=index(inline,"}{")
     print substr(inline,1,dblpos) "{935}{945}{945}{945}{935}{935}%" \
       > "chitexfdf@"
    }
 else 
  {if (choosepos == 0)
     {print $0 > "chitexfdf@"}
   else
     {llen=length(inline)
      k=1
      for (k; k<=llen; k++)
        {ch=substr(inline,llen-k+1,1)
         if (ch == "}")
            {lastbr=llen-k+1; break}
        }

      choosestr=substr(inline,choosepos,length(inline)-choosepos+1)
      dblpos=1; choosestrtmp=choosestr; dblno=0
      while (dblpos > 0 && choosestrtmp != "")
        {dblpos=index(choosestrtmp,"}{")
         if (dblpos > 0)
          {dblno=dblno+1
           choosestrtmp=substr(choosestrtmp,dblpos+2,length(choosestrtmp)-dblpos-1)
          } 
        }


      if (dblno == 4)
         {print $0 > "chitexfdf@"; next}

      dblpos=index(choosestr,"}{")
      remchoosestr=substr(choosestr,dblpos+2,length(choosestr)-dblpos-1)
      br=index(remchoosestr,"}")
      if (br >0)
         {extfile=substr(remchoosestr,1,br-1)
          extfilehead=substr(extfile,1,1)
          extfiletail=substr(extfile,length(extfile),1)
         } 

      if (extfilehead=="b" && extfiletail=="u" \
           ||extfile=="bkai00mp"||extfile=="bsmi00lp" )
         {raisemod="{-60}"}
      else
        if (extfile=="uwcxmf"||extfile=="Cyberbit"||extfile=="cyberit")
         {raisemod="{0}"}
        else
         {raisemod="{70}"}
        fi
      fi

      outline=substr(inline,1,lastbr) raisemod \
         substr($0,lastbr+1,length($0)-lastbr)
      print outline > "chitexfdf@"
     }
  }
}' $texmf/tex/chinese/chitex.fdf

##### Add to chitex.fdf ###########
  
   cp chitex612/data/chitex.fdf  chitex612/tex/chitex.fdf

$gawkbin '
BEGIN{
chitexfdf="chitexfdf@"
while (getline inline < chitexfdf > 0)
  {
   per=index(inline,"%")
   inline=substr(inline,1,per-1)
   inlinea=inline; inlinea=gsub(" ", "",inlinea)
   if (inlinea != "")
   {
   choosepos=index(inline,"\\choosechfont")
   if (choosepos != 0)
     {++k
      lbr=index(inline,"{");rbr=index(inline,"}")
      ttfnamesys[k]=substr(inline,lbr+1,rbr-lbr-1)
#     print ttfnamesys[k] > "chitexas@"
     }
   }
  }
  ttfnamenosys=k; k=0
  close(chitexfdf)
}
{  inline=$0
   per=index(inline,"%")
   inline=substr(inline,1,per-1)
   inlinea=inline; inlinea=gsub(" ", "",inlinea)
   if (inlinea != "")
    {
     choosepos=index(inline,"\\choosechfont")
     if (choosepos != 0)
     {++k
      lbr=index(inline,"{");rbr=index(inline,"}")
      ttfname[k]=substr(inline,lbr+1,rbr-lbr-1)
      wholeline[k]=$0
#     print ttfname[k] > "chitexa@"
     }
     else
     {chfntscale=index(inline,"\\chfntscale")
      if (chfntscale > 0)
         {++k;ttfname[k]="*&@#!?&*%";wholeline[k]=$0}
     }
    }
   ttfnameno=k
}
END{
   i=1;j=0
   for (i; i<=ttfnameno; i++)
     {k=1; meet=0
      for (k; k<=ttfnamenosys; k++)
        {if (ttfname[i] == ttfnamesys[k])
            {meet=1; break}
        }
      if (meet == 0)
        {j=j+1; addline[j]=wholeline[i]}
     }
   addlineno=j
   while (getline inline < chitexfdf >0)   
     {
      if (endinput == 0)
       {   inlinea=inline; per=index(inlinea,"%")
           if (per >0)
              {inlinea=substr(inlinea,1,per-1)}
           endinput=index(inlinea,"\\endinput")
           catcode=index(inlinea,"\\catcode")
           if (endinput == 0)
              {
               mingpos=index(inlinea,"\\let\\ming\\nwdming")
               mingapos=index(inlinea,"\\let\\MING\\NWDMING")
               moekaipos=index(inlinea,"\\moekai")
               chfntscale=index(inlinea,"\\chfntscale")
               if (mingpos==0 && mingapos==0 && moekaipos==0&&catcode==0 \
                   && chfntscale==0)
                  {print inline > "chitexfdfl@"}
               else
                  if (chfntscale > 0)
                     {print "%" inline > "chitexfdfl@"}
              }
           else
              {
               i=1
               for (i;i<=addlineno;i++)
                 {print addline[i] > "chitexfdfl@"}
               break
              }
       }
     }

   print " " > "chitexfdfl@"   
   print "\\choosechfontadv{moekai}{moe_kai}{28}{110}{70}" > "chitexfdfl@"
   print "\\let\\ming\\nwdming" > "chitexfdfl@"
   print "\\let\\MING\\NWDMING" > "chitexfdfl@"
   print "\\moekai " > "chitexfdfl@"
   print " " > "chitexfdfl@"
   print "\\endinput" > "chitexfdfl@"

}' chitex612/tex/chitex.fdf

cp -f chitexfdfl@ $texmf/tex/chinese/chitex.fdf
/bin/rm -f chitexfdfl@
else
#  cp chitex612/tex/chitex.fdf $texmf/tex/chinese/chitex.fdf
  cp chitex612/data/chitex.fdf $texmf/tex/chinese/chitex.fdf
fi # end of if test -s $texmf/tex/chinese/chitex.fdf

warning=`egrep "Warning!" $texmf/tex/chinese/chitex.fdf`
shouldo=`egrep "After modifying this file, you should give command:" \
   $texmf/tex/chinese/chitex.fdf `
if test "$warning" = "" -o "$shouldo" = ""; then
   echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" > appendfiles@
   echo "%                                       " >> appendfiles@
   echo "%  Warning! Warning!              " >> appendfiles@
   echo "%  After modifying this file, you should give command:" >> appendfiles@
   echo "%      chitexconfig -chitex.fdf " >> appendfiles@
   echo "%                                       " >> appendfiles@
   echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" >> appendfiles@
   echo " "
   echo "% Do not modify the above message" >> appendfiles@
   echo " " >> appendfiles@

   cat $texmf/tex/chinese/chitex.fdf >> appendfiles@ 
   cp -f appendfiles@ $texmf/tex/chinese/chitex.fdf
   /bin/rm -f appendfiles@
fi

##### Modify chitexg.fdf or copy it ######

if test -s $texmf/tex/chinese/chitexg.fdf; then
$gawkbin '
{ inline=$0
  choosepos=0; chfntscalepos=0
  choosepos=index(inline,"\\chooseGBfontadv")
  chfntscalepos=index(inline,"\\chfntscale")
 if (chfntscalepos>0)
    {dblpos=index(inline,"}{")
     print substr(inline,1,dblpos) "{935}{945}{945}{945}{935}{935}%" \
       > "chitexfdfg@"
    }
 else 
  {if (choosepos == 0)
     {print $0 > "chitexfdfg@"}
   else
     {llen=length(inline)
      k=1
      for (k; k<=llen; k++)
        {ch=substr(inline,llen-k+1,1)
         if (ch == "}")
            {lastbr=llen-k+1; break}
        }

      choosestr=substr(inline,choosepos,length(inline)-choosepos+1)
      dblpos=1; choosestrtmp=choosestr; dblno=0
      while (dblpos > 0 && choosestrtmp != "")
        {dblpos=index(choosestrtmp,"}{")
         if (dblpos > 0)
          {dblno=dblno+1
           choosestrtmp=substr(choosestrtmp,dblpos+2,length(choosestrtmp)-dblpos-1)
          } 
        }


      if (dblno == 4)
         {print $0 > "chitexfdfg@"; next}

      dblpos=index(choosestr,"}{")
      remchoosestr=substr(choosestr,dblpos+2,length(choosestr)-dblpos-1)
      br=index(remchoosestr,"}")
      if (br >0)
         {extfile=substr(remchoosestr,1,br-1)
          extfilehead=substr(extfile,1,1)
          extfiletail=substr(extfile,length(extfile),1)
         } 

      if (extfilehead=="g" && extfiletail=="u" \
           ||extfile=="gkai00mp"||extfile=="gbsn00lp" )
         {raisemod="{-60}"}
      else
        if (extfile=="uwpstj")
         {raisemod="{0}"}
        else
         {raisemod="{70}"}
        fi
      fi

      outline=substr(inline,1,lastbr) raisemod \
         substr($0,lastbr+1,length($0)-lastbr)
      print outline > "chitexfdfg@"
     }
  }
}' $texmf/tex/chinese/chitexg.fdf

##### Add to chitexg.fdf ###########
$gawkbin '
BEGIN{
chitexfdf="chitexfdfg@"
while (getline inline < chitexfdf > 0)
  {
   per=index(inline,"%")
   inline=substr(inline,1,per-1)
   inlinea=inline; inlinea=gsub(" ", "",inlinea)
   if (inlinea != "")
   {
   choosepos=index(inline,"\\chooseGBfont")
   if (choosepos != 0)
    {++k
     lbr=index(inline,"{");rbr=index(inline,"}")
     ttfnamesys[k]=substr(inline,lbr+1,rbr-lbr-1)
#    print ttfnamesys[k] > "chitexas@"
    }
   }
  }
  ttfnamenosys=k; k=0
  close(chitexfdf)
}
{  inline=$0
   per=index(inline,"%")
   inline=substr(inline,1,per-1)
   inlinea=inline; inlinea=gsub(" ", "",inlinea)
   if (inlinea != "")
    {
     choosepos=index(inline,"\\chooseGBfont")
     if (choosepos != 0)
     {++k
      lbr=index(inline,"{");rbr=index(inline,"}")
      ttfname[k]=substr(inline,lbr+1,rbr-lbr-1)
      wholeline[k]=$0
       }
    }
   ttfnameno=k
}
END{
   i=1;j=0
   for (i; i<=ttfnameno; i++)
     {k=1; meet=0
      for (k; k<=ttfnamenosys; k++)
        {if (ttfname[i] == ttfnamesys[k])
            {meet=1; break}
        }
      if (meet == 0)
        {j=j+1; addline[j]=wholeline[i]}
     }
   addlineno=j
   while (getline inline < chitexfdf >0)   
     {
      if (endinput == 0)
       {   inlinea=inline; per=index(inlinea,"%")
           if (per >0)
              {inlinea=substr(inlinea,1,per-1)}
           endinput=index(inlinea,"\\endinput")
           catcode=index(inlinea,"\\catcode")
           if (endinput == 0)
              {if (catcode == 0)
                  {print inline > "chitexfdflg@"}
              }
           else
              {
               i=1
               for (i;i<=addlineno;i++)
                 {print addline[i] > "chitexfdflg@"}
               break
              }
       }
     }

   print " "  > "chitexfdflg@"
   print "\\let\\nwdkaiGB\\kaiGB"  > "chitexfdflg@"
   print "\\let\\NWDKAIGB\\KAIGB"  > "chitexfdflg@"
   print " "  > "chitexfdflg@"
   print "\\endinput" > "chitexfdflg@"

}' chitex612/tex/chitexg.fdf

cp -f chitexfdflg@ $texmf/tex/chinese/chitexg.fdf
/bin/rm -f chitexfdflg@
else
  cp -f chitex612/tex/chitexg.fdf $texmf/tex/chinese/chitexg.fdf
fi # end of if test -s $texmf/tex/chinese/chitexg.fdf

warning=`egrep "Warning!" $texmf/tex/chinese/chitexg.fdf`
shouldo=`egrep "After modifying this file, you should give command:" \
   $texmf/tex/chinese/chitexg.fdf `
if test "$warning" = "" -o "$shouldo" = ""; then
   echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" > appendfiles@
   echo "%                                       " >> appendfiles@
   echo "%  Warning! Warning!              " >> appendfiles@
   echo "%  After modifying this file, you should give command:" >> appendfiles@
   echo "%      chitexconfig -chitex.fdf " >> appendfiles@
   echo "%                                       " >> appendfiles@
   echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" >> appendfiles@
   echo " "
   echo "% Do not modify the above message" >> appendfiles@
   echo " " >> appendfiles@

   cat $texmf/tex/chinese/chitexg.fdf >> appendfiles@ 
   cp -f appendfiles@ $texmf/tex/chinese/chitexg.fdf
   /bin/rm -f appendfiles@
fi

echo "       End of modifying chitex*.fdf files "
#echo $echomode "       Press any key to continue " $echoc
#read inkey                         

if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echocr
   read inkey
fi



##### Modify ttfonts.map or copy it #############
modifyttfontsmap="n"
#if test "$modifyttfontsmap = "y"; then

if test ! -s $texmf/ttfonts.map; then
  cp -f chitex612/data/ttfonts.map $texmf/ttfonts.map
fi

$gawkbin '
BEGIN{
#ttfontsmap=texmf "/ttfonts.map"
#while (getline inline < ttfontsmap > 0)
#  {inlinea=inline; inlinea=gsub(" ", "",inlinea)
#   if (inlinea != "")
#   {
#   atpos=index(inline,"@")
#   if (atpos != 0)
#    {++k
#     ttfnamesys[k]=substr(inline,1,atpos-1)
#    }
#   }
#  }
#  ttfnamenosys=k; k=0
#  close(ttfontsmap)
}
{
if (NR==1)
{
ttfontsmap=texmf "/ttfonts.map"
while (getline inline < ttfontsmap > 0)
  {inlinea=inline; inlinea=gsub(" ", "",inlinea)
   if (inlinea != "")
   {
   atpos=index(inline,"@")
   if (atpos != 0)
    {++k
     ttfnamesys[k]=substr(inline,1,atpos-1)
    }
   }
  }
  ttfnamenosys=k; k=0
  close(ttfontsmap)
} # end of if (NR==1)


  inlinea=$0
   gsub(" ","",inlinea)
   if (inlinea != "")
    {
     atpos=index($1,"@")
     if (atpos != 0)
       {++k; 
        ttfname[k]=substr($1,1,atpos-1)
        wholeline[k]=$0
       }
    }
   ttfnameno=k
}
END{
   i=1
   for (i; i<=ttfnameno; i++)
     {k=1; meet=0
      for (k; k<=ttfnamenosys; k++)
        {if (ttfname[i] == ttfnamesys[k])
            {meet=1; break}
        }
      if (meet == 0)
        {gsub("/usr/local/TeX/share/texmf",texmf,wholeline[i])
         gsub("/var/tmp/texfonts",vartexfonts,wholeline[i])
        print wholeline[i] >> ttfontsmap}
     }

}' texmf=$texmf vartexfonts=$VARTEXFONTS chitex612/data/ttfonts.map

if test ! -s $texmf/ttfonts.bak;then
   cp -f $texmf/ttfonts.map $texmf/ttfonts.bak
fi

warning=`egrep "Warning!" $texmf/ttfonts.map `
shouldo=`egrep "After modifying this file, you should give command:" \
   $texmf/ttfonts.map `
if test "$warning" = "" -o "$shouldo" = ""; then
   echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" > appendfiles@
   echo "#                                       " >> appendfiles@
   echo "#  Warning! Warning!              " >> appendfiles@
   echo "#  After modifying this file, you should give command:" >> appendfiles@
   echo "#      chitexconfig -chitex.fdf " >> appendfiles@
   echo "#                                       " >> appendfiles@
   echo "#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" >> appendfiles@
   echo " "
   echo "# Do not modify the above message" >> appendfiles@
   echo " " >> appendfiles@

   cat $texmf/ttfonts.map >> appendfiles@ 
   cp -f appendfiles@ $texmf/ttfonts.map
   /bin/rm -f appendfiles@
fi

  sed "s#/usr/local/TeX/share/texmf#$texmf#g" $texmf/ttfonts.map >ttfonts.map@
  cp -f ttfonts.map@ $texmf/ttfonts.map
  /bin/rm -f ttfonts.map@


echo "       End of modifying ttfonts.map files "
#echo $echomode "       Press any key to continue " $echoc
#read inkey                         


if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echocr
   read inkey
fi


fi # step31



#fi
##### end of modifying ttfonts.map


##### copy *.sfd  to $texmf, copy *.afm to $texmf/tex/chinese #####
cp -f chitex612/data/*.sfd $texmf
cp -f chitex612/data/*.afm $texmf/tex/chinese

cd $SAVEPWD

step5="y"
if test "$step5" = "y"; then
if test "$install" = "all"; then
##### copy pst's files 
/bin/rm -rf pst
mkdir pst
cd pst
gunzip -dc ../chitex612/data/pst.tar.gz|tar xvf -
cp -f *.sty *.tex *.con $texmf/tex/chinese
cp -f *.pro $texmf/dvips/base
/bin/rm -f *.sty *.tex *.con *.pro
cd $SAVEPWD
fi

cd $SAVEPWD
##### update pstricks if tetex version <= .09 #####
echo "yes" > tmp@

#if test "$tetexverold" = "old"; then
#   echo "old"
   /bin/rm -rf pstricks
   mkdir pstricks
   cd pstricks
   gunzip -dc $SAVEPWD/chitex612/data/pstricks.tgz|tar xvf -
  if test ! -d $texmf/tex/generic/pstricks; then
      mkdir -p $texmf/tex/generic/pstricks
#   fi
   cp -f * $texmf/tex/generic/pstricks
  fi
   /bin/rm -f *
   cd $SAVEPWD
   rmdir pstricks
#else 
#  echo "new"
#fi


######## Modify mktextfm #########
if test "$newtextex" = "yes" -a "$newttf2pk" = "y"; then
  if test ! -s "$bindir/mktextfm.bak"; then
     cp $bindir/mktextfm $bindir/mktextfm.bak
  fi
#     cp -f chitex612/bin/mktextfm $bindir
fi

######## Modify mktexpk #########
if test "$newtextex" = "yes" -a "$newttf2pk" = "y"; then
  if test ! -s "$bindir/mktexpk.bak"; then
     cp $bindir/mktexpk $bindir/mktexpk.bak
  fi
#     cp -f chitex612/bin/mktexpk $bindir
fi

fi # step5


###### Copy chitex612/bin/* $bindir and binary files where it is
/bin/rm -rf chitex612/bin/temp

#cd chitex612/bin

# Copy 'gawk' to $bindir if it has not it
cd $SAVEPWD
   if test ! -s $bindir/gawk -a -f $bindir/gawk; then
      mv $bindir/gawk $bindir/gawk".old"
#      /bin/rm -f $bindir/gawk 
   fi

   if test ! -s $bindir/gawk; then
      cp -f $SAVEPWD/gawk $bindir
   fi

# Copy chitex612/bin/* to $bindir
cp -f chitex612/bin/* $bindir

cp -f chitex612/data/chitran0.awk $bindir
cp -f chitex612/data/chitran1.awk $bindir

sed "s#chitran0.awk#$bindir/chitran0.awk#g" $bindir/chitranc > chitranc@
sed "s#chitran1.awk#$bindir/chitran1.awk#g" chitranc@ > chitranc@@
mv -f chitranc@@ $bindir/chitranc
chmod +x  $bindir/chitranc

cd $SAVEPWD

# In the following it will compile '.c' files
# first copy $SAVEPWD/chitex612/data/*.c to  $SAVEPAWD and
# then unzip $SAVEPAWD/chitex612/data/cfile.tgz which have '.c' files
# into $SAVEPWD 
#

#cd .temp00$$
#cp -f $SAVEPWD/chitex612/data/*.c .
#gunzip -dc $SAVEPWD/chitex612/data/cfile.tgz|tar xvf -


# Find 'gcc' and use 'cc' if not have 'gcc'
#

gccdir=`which gcc`
gccloc=`which gcc|grep ":"`

if test "$gccloc" = ""; then
  gawkloc=`which gawk|grep "no gcc"`
fi
if test "$gccloc" != ""; then
   CC="cc"
else
   CC="gcc"
fi


# Start to compile 'chitran0.c',...
# and move the resulted files into $bindir and its original place

#cp $SAVEPWD/chitex612/data/libawka.a."$unixname" libawka.a
#cp $SAVEPWD/chitex612/data/libawka.h."$unixname" libawka.h

# First it will compile awka

  gunzip -dc $SAVEPWD/chitex612/data/awka.tgz |tar xvf -
  cd awka-0.3b-50
  configure
  make
  make install
  cp -f $SAVEPWD/awka-0.3b-50/lib/libawka.a .
  cp -f $SAVEPWD/awka-0.3b-50/lib/libawka.h .
#  /bin/rm -rf awka-0.3b-50

echo "       End of compiling awka"
#echo $echomode "       Press any key to continue " $echoc
#read inkey                         
  
if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echocr
   read inkey
fi


mkdir .temp00$$
cd .temp00$$
mv ../libawka.* .
cp -f $SAVEPWD/chitex612/data/*.c .
gunzip -dc $SAVEPWD/chitex612/data/cfile.tgz|tar xvf -
#cp -f chitran1.awk $texmf/tex/chinese
cp -f $SAVEPWD/chitex612/data/chitran3a.awk $texmf/tex/chinese




step6="y"
if test "$step6" = "y"; then
for cmd in chitran00 chitran01 chitran0 chitran1 chitran2 chitran3 chitran3a chitran4 \
   chitran5 chitran5b chitran6 chitran7 chicodelistc  \
   chitranp1 chitranp2 chitranp3 chitexsub1 \
#   chicode chifilt chadd chaddpfbname chicoder
do 
   eval $CC $cmd".c" -I./ -L./ -lawka -lm -o $cmd
   eval cmddir=\$$cmd"dir"
   if test "$cmddir" != ""; then 
      eval cp -f $cmd \$$cmd"dir"
      eval echo "cp -f $cmd" \$$cmd"dir"
   else
      eval echo "cp -f $cmd $bindir"
   fi
   
   eval cp -f $cmd $bindir
#   /bin/rm -f $cmd
done


fi  # end of step6


for cmd in chicode chifilt chadd chaddpfbname chicoder
do 
   $CC -o $cmd $cmd".c" 
   eval cmddir=\$$cmd"dir"
   if test "$cmddir" != ""; then 
      eval cp -f $cmd \$$cmd"dir"
      eval echo "cp -f $cmd" \$$cmd"dir"
   else
      eval echo "cp -f $cmd $bindir"
   fi
   eval cp -f $cmd $bindir
#   /bin/rm -f $cmd
done

/bin/rm -f *.c


cd $SAVEPWD

rm -rf .temp*

# Copy binary files 'chitex',... to its original place

# for cmd in \
#  chitex chitexdvi chitexpsv chilatex chilatexb  \
#  chitran chitranp chitranu ttf2tfm ttf2pk ttf2pfb \
#  xdvi dvips \
#  mktextfm mktexpk rmchpk chitexhelp chitexconfig cmakeindex cbibtex \
#  ccbibtex ccmakeindex chitranc chitranpc \
#  ctran ctranbb

for cmd in $bindirfiles
do
  eval cmddir=\$$cmd"dir"
  if test "$cmddir" != ""; then 
     eval cp -f $SAVEPWD/chitex612/bin/$cmd \$$cmd"dir"
     eval echo "cp -f $SAVEPWD/chitex612/bin/$cmd" \$$cmd"dir"
  fi
done                           


if test "$unixname" != "linux"; then
   /bin/rm -f $bindir/ttf_edit $bindir/genttf
fi

#if test "$tetexverold" != "old"; then
#   /bin/rm -f $bindir/MakeTeXPK $bindir/MakeTeXTFM
#fi

if test -s $bindir/chiplaintex; then
   /bin/rm -f $bindir/chiplaintex
fi
###### End of Copy chitex612/bin/* 

echo "       End of compiling some c files and copy to $bindir"
#echo $echomode "       Press any key to continue " $echoc
#read inkey                         

if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echocr
   read inkey
fi


  
cd $SAVEPWD


cd $bindir
chmod +x *
chmod +s chaddpfbname
chmod +s chadd
cd $SAVEPWD


#exit

##### copy (update) *.tex files #######
mkdir textmp
# chitex*.fdf have been modified and copy into $texmf/tex/chinese
# should not copy the old into $texmf/tex/chinese
# so move them to a temperary dir.
  mv -f chitex612/data/chitex.fdf textmp
  mv -f chitex612/tex/chitexg.fdf textmp
chmod +w $texmf/tex/chinese/*.tex
chmod +w $texmf/tex/chinese/*.png
chmod +w $texmf/tex/chinese/*.bib
chmod +w $texmf/tex/chinese/*.sty
cp -f chitex612/tex/* $texmf/tex/chinese
if test ! -d $SAVEPWD/tex; then
   mkdir $SAVEPWD/tex
fi
cp -f chitex612/tex/math*.tex $SAVEPWD/tex
cp -f chitex612/tex/samp*.tex $SAVEPWD/tex
cp -f chitex612/tex/char*.tex $SAVEPWD/tex
cp -f chitex612/tex/*.png $SAVEPWD/tex
cp -f chitex612/tex/*.bib $SAVEPWD/tex
chmod a-w $texmf/tex/chinese/*.tex
chmod a-w $texmf/tex/chinese/*.png
chmod a-w $texmf/tex/chinese/*.bib
chmod a-w $texmf/tex/chinese/*.sty

mv -f textmp/chitex*.fdf chitex612/tex

rmdir textmp


echo "       End of copy files to $texmf/tex/chinese "
#echo $echomode "       Press any key to continue " $echoc
#read inkey                         

if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echocr
   read inkey
fi


$gawkbin '
BEGIN{}
{
  per=index($0,"%")
  if (per>0)
     {inline=substr($0,1,per-1)}
  else
     {inline=$0}

  choose=index(inline,"\\choose")
  let=index(inline,"\\let")
    
  endinput=index(inline,"\\endinput")
  if (endinput>0)
     {print "\134MOEKAI" > "chitexfdf@"}

  if (choose>0 || let>0 || per>0 || endinput>0)
         {print $0 > "chitexfdf@"}

} ' $texmf/tex/chinese/chitex.fdf


cp -f chitexfdf@ $texmf/tex/chinese/chitex.fdf

##### Configure chitex, chitexdvi,... ######
##### A. Make .../texmf/tex/chinese/chitex.fdfile from
#####     .../texmf/tex/chinese/chitex.fdf 
##### B. Configure chitex, chitexdvi,... such that TEXMF, VARTXFONTS
#####    to be set to speed the excution of those scripts chitex,.....


echo "at 1"

read xxxxxxxxx

#if test "$Redhat" = ""; then
if test "$Redhat" !=  "n"; then
   chitexconfig -scfile
   chitexconfig -chitex.fdf
   /bin/rm -f chitex*.fdfile
else
   echo "  ****************************************************************"
   echo "  *                                                              *"
   echo "  * ФUO:                                                    *"
   echo "  *      ./chsetuppost                                             *"
   echo "  * H~򧹦w                                               *"
   echo "  *                                                              *"
   echo "  * (ȶWzO _hw˵Lk)                          *"
   echo "  * (YѰOWzOФUO:   Redhathelp                        *"
   echo "  ****************************************************************"
   exit
fi
#######

##### Update psfonts.map, pdftex.map ######
if test -s $texmf/dvips/config/psfonts.map; then
wafonts=`grep "%Wafonts begin" $texmf/dvips/config/psfonts.map`
wafonts=`grep "%Wafontsa begin" $texmf/dvips/config/psfonts.map`
if test "$wafonts" = ""; then
   cat chitex612/data/pfbadd.map >> $texmf/dvips/config/psfonts.map
fi
if test "$wafontsa" = ""; then
   cat chitex612/data/pfbadda.map >> $texmf/dvips/config/psfonts.map
fi
fi

if test -s $texmf/dvips/base/psfonts.map; then
wafonts=`grep "%Wafonts begin" $texmf/dvips/base/psfonts.map`
wafontsa=`grep "%Wafontsa begin" $texmf/dvips/base/psfonts.map`
if test "$wafonts" = ""; then
   cat chitex612/data/pfbadd.map >> $texmf/dvips/base/psfonts.map
fi
if test "$wafontsa" = ""; then
   cat chitex612/data/pfbadda.map >> $texmf/dvips/config/psfonts.map
fi
fi

wafonts=`grep "%Wafonts begin" $texmf/dvips/config/pdftex.map`
wafontsa=`grep "%Wafontsa begin" $texmf/dvips/config/pdftex.map`
if test "$wafonts" = ""; then
  cat chitex612/data/pdfadd.map >> $texmf/dvips/config/pdftex.map
fi
if test "$wafontsa" = ""; then
  cat chitex612/data/pfbadda.map >> $texmf/dvips/config/pdftex.map
fi


echo "       End of update  psfonts.map, pdftex.map "
#echo $echomode "       Press any key to continue " $echoc
#read inkey                         

if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echocr
   read inkey
fi


##### end of Update psfonts.map, pdftex.map

chmod -w $texmf/doc/chitex/README* 
chmod -w $texmf/doc/chitex/ANNOUNCE*
chmod -w $texmf/doc/chitex/ChangeLog*
chmod -w $texmf/doc/chitex/*.ps
#fi


###### set 600dpi for xdvi and dvips 
 
set600

#echo "It will modify configure of lyx"
#echo "Press enter key to continue"
#read xxxxx

##### Modify configure of lyx #########
rm -f config@
mkdir tmp
cd tmp
clyx=`which clyx`

if test "$clyx" != ""; then    #1st if
   echo " "
   echo  "It will find lyxrc.defaults" 
   echo  "Wait!"

   find /usr -path '*/lyx/lyxrc.defaults' > config@

if test -s config@; then   # 2nd if
lyxdir=`
awk '
BEGIN{}
{
  lyxrc=index($0,"/lyxrc.defaults")
  if (lyxrc > 0)
     {print substr($0,1,lyxrc-1)}
}
END{} ' config@ `

   echo "lyxdir=$lyxdir found"

if test ! -s $lyxdir/configure.bak; then
   cp -f $lyxdir/configure  $lyxdir/configure.bak
fi

modify=`
awk '
BEGIN{}
{
  if (modify==0) 
     {modify=index($0, "Modify to use with chitex")}
}
END{
  if (modify>0)
     {print "yes"}
} ' $lyxdir/configure `

rm -f tmp@

if test "$modify" = ""; then  # 3rd if
awk '
BEGIN{}
{ 
  inline=$0
  llen=length($0)
  haveexit=""
  if (index(inline,"exit") > 0)
     {for (i; i<=llen; i++)
          {ch=substr(inline,i,1)
           if (ch == " ")
              {continue}
           else
              {inlinenew=inlinenew ch}
          }
      if (inlinenew=="exit")
         {haveexit="y"}
     }
  if (haveexit == "")
     {print $0 > "tmp@"}
}
END{ } ' $lyxdir/configure

cat $SAVEPWD/chitex612/data/configure.add >> tmp@
cp -f tmp@ $lyxdir/configure
chmod +x $lyxdir/configure

 echo  'configure'  "has been modified"
 echo "The old  $lyxdir/configure have been backup as $lyxdir/configure.bak"

fi  # endof if test "$modify@: ...

else
   echo "can not find  lyxrc.defaults"
fi # end of if test "$config@" ...
fi # end of if test "$clyx" ...

if test "$clyx" != ""; then
##### Modify clyx ######
havecheck=`grep "check lyxrc.defaults" $clyx`

rm -f tmp@

 if test "$havecheck" = ""; then 

awk '
BEGIN{}
{ inline=""
  lyx=index($0,"lyx")
  if (lyx>0)
  {
    llen=length($0)
    i=1
    for (i; i<=llen; i++)
      {ch=substr($0,i,1)
       if (ch !=" ")
          {inline=inline ch}
      } 
  }

  if (lyx>0 && inline=="lyx")
     {
      print "# check lyxrc.defaults" > "tmp@"
      print "if test -s $HOME/.lyx/lyxrc.defaults; then" > "tmp@"
      print "   chilatexb=\`grep \"\\\\latex_command \\\"chilatexb\\\"\" $HOME/.lyx/lyxrc.defaults\`" > "tmp@"
      print "   usecjk=\`grep \"\\\\use_cjk\" $HOME/.lyx/lyxrc.defaults\`" > "tmp@"
      print "   if test \"$chilatexb\" = \"\" -o \"$usecjk\" != \"\"; then " > "tmp@"
      print "      rm -rf $HOME/.lyx" > "tmp@"
      print "   fi" > "tmp@"
      print "else" > "tmp@"   
      print "   rm -rf $HOME/.lyx" > "tmp@"
      print "fi" > "tmp@"
     }
  print $0 > "tmp@"    
}
END{}' $clyx

 cp tmp@ $clyx
 fi  # if test "$havecheck" = ""; then  
fi # 
##### end of modify configure for clyx #####

cd ..


###### Must 'texhash' to take effect for all TeX setting
texhash

########### The main setup has been  completed ############


/bin/rm -f *.c
/bin/rm -rf temp
/bin/rm -rf tfm
if test -s gawk; then
   /bin/rm -f gawk
fi
/bin/rm -f *@
/bin/rm -rf fonts pfb pk pst tmp
/bin/rm -rf chitex612/bin/temp.*

fi # testmessage

##### Make VARTEXFONTS/tfm/chinese, VARTEXFONTS/type1/fonts writable 
chmod a+w $VARTEXFONTS/tfm/chinese
chmod a+w $VARTEXFONTS/type1/fonts
if test -f $VARTEXFONTS/ttf; then
   rm -f $VARTEXFONTS/ttf 
fi
if test ! -d $VARTEXFONTS/ttf; then
   mkdir $VARTEXFONTS/ttf 
   chmod a+rw $VARTEXFONTS/ttf
fi



############# The messages of end of upadte ##################

message ( ) {

menua (){
clear
echo " "
#echo " "
#echo "        If there are no error messages, then "
if test "$install" = "update"; then
   echo "        The 'update' must have been completed."
else
   echo "        The 'installation' must have been completed."
fi
echo " "
echo "        s ChiTeX UCs\:"
echo "        1. iΤɦW TeX/LaTeX "
echo "        2. ѷs mymacros.tex i input ӳ]wۤvߦn"
echo "           Bѷs samp2*.tex դ"
echo "        3. T䴩 ϥΤ chapterbib.sty  bibunits.sty"
echo "           BѴժҤl 'ƾ_bibunits.tex', ƾ_chapbib.tex"
echo "        4. ץ cmakeindex  ץ[j cbibtex Ϥ key ]QT sort"
echo "           Ӧb \"alpha\"  style  author-year  key ]ABz"
echo "        5. iTaϥΩҦw verbatim O"
echo "        6. Modify \"camsbook.sty\" ϥ \\documentclass{amsbook} "
echo "           T title"
echo "        7. 䴩 pdftex/pdflatex, Ϊkp: chitex -pdftex math2_pdftex"
echo "           䤤 math2_pdftex.tex it pdftex O(Ԩ README.use* )"
echo "        8. Could have chinese \"boldface(r)\" and \
 \"outline(Ŧr)\","
echo "           if one use chinese Adobe type1 fonts commands."
echo "        9. Could have fascinating \"grading color's \
 effects(C⺥hĪG)\""
echo "        More ....."
echo " "
echo $echomode "        Press enter key to continue" $echocr
read inkeya
menubno="y"
while test "$menubno" = "y"
do
    menub
    case $inkeyb in
    "b") menubno="n"; menuano="y";;
    "c") menubno="n"; menuano="n";;
      *) menubno="y";;
    esac
done
}

menub (){
clear
echo "       10. @ script { c y, t״@@HW()"
echo "       11. Ѧ cbibtex, cmakeindex  kay b \\label, "
echo "           \\cite, \\ref ϥΪҤl: mabibind.tex Ѵ"
echo "           (iUO chitex -chitexhelp Ūδ mabibind.tex)"
echo "       12. iϥ  Adobe Type1 r, Linux P FreeBSD\
 tΪ̥ib compile"
echo "           ɹ Big5  GB sX TrueType rβͥn\
 Adobe Type1"
echo "           r(ϥ ttf2pfb). Linux tΪ̥i۰ʱN unicode sX\
 TrueType"
echo "           r, ഫX Big5  GB sX TrueType r"
echo "       11. wˮɤ~ compile X fmt , iKLktX teTeX "
echo "           ]ѵ{ chitexconfig iΨӭs configure A ChiTeX "
echo "           ]ibAw ChiTeX , As teTeX , ӦAsA teTeX "
echo "           s, UO:"
echo "               chitexconfig -makefmt"
echo "           is chitex*.fmt  pdfchitex*.fmt ӨϯtXs teTeX"

echo " "
echo "        Give me messages if have problems"
echo "        "
echo "        Hung-Yih Chen ()"
echo "        Dept. of Mathematics, Nat'l Central Univ."
echo "        email: yih@math.ncu.edu.tw " 
echo " "
echo "        Type \"b\" to back"
echo "        or Type \"c\" to continue"
echo $echomode "        : " $echocr
read inkeyb
}

#menuno="y"
menuano="y";menubno="y"
#while test "$menu" = "y"
#do
  while test "$menuano" = "y"
  do
     menua
  done  
#done

submenuc (){
clear
echo " "
echo " "
   echo "        *** Is message ФUO:  message "
   echo " "
   echo "        bɭ, nnDDn chitex O, unUO:"
   echo "               chitex"
   echo " "
   echo "        bɭ, nDiϥΤؤrΫO, unUO:"
   echo "               chitex -fonts "
   echo " "
   echo "        bɭ, pn \"թҪ TeX Ҥl\", \"DU(help)\","
   echo "        \"\Ū README* \", unUO:"
   echo "               chitex -chitexhelp"
   echo " "
   echo "        {bAiH \"\Ūδ TeX Ҥl\", \"DU\"  \
\"\""
   echo " "
   echo "        1. \Ūδ TeX Ҥl"
   echo "        2. DU( ChiTeX) "
   echo "        b. ^̫e "
   echo "        q. "
   echo "     "
   echo $echomode "        Type '1', '2', 'b' or 'q' to choose one of the above: " $echocr
   
   read inkeyc
#   export inkeyc
}

submenucno="y"
while test "$submenucno" = "y"
do
  submenuc 
   case "$inkeyc" in
      "1")  chitexhelp -big5 -test; submenucno="y";;
      "2")  chitexhelp; submenucno="y" ;;
      "b")  messageno="y"; submenucno="n";;
      "q")  messageno="n"; submenucno="n"
           echo " "
           echo "        At any time give command:"
           echo "               chitex -help"
           echo "        to get help "
           echo " "
           exit;;
        *) messageno="n"; submenucno="y";;
   esac            
done
}


messageno="y"

while test "$messageno" = "y";     
  do
   message
  done

exit

##################

