#!/bin/sh

#   Curdir=`cd ../;pwd`
#   Curdir="/c/unix/6.1.2p10"


  tmpdir=`cat /tmp/tmpdir@`
  export tmpdir

  if test "$tmpdir" = ""; then
     tmpdir=`cd ../;pwd`
  else
     cd $tmpdir
  fi


#  if test -s /bin/gawk-3.1.5; then
#     cp /bin/gawk-3.1.5 /bin/gawk
#  fi

#  if test -s /bin/gawk; then  
#     cp /bin/gawk /bin/gawk.org
#  fi
  
# check gawk's version
#if test !-s /bin/gawk; then  
#   Nogawk="y"
#else
#  gawk --version> v1
#  Newgawk=`
#  gawk '
#  {n=n+1
#   if (n==1)
#      {if (index($0,"3.1.5")>0)
#          {print "New"} 
#      }     
#  } ' v1 `
#fi
  
#  if test "$Newgawk" = "New" -o Nogawk="y"; then
#     gunzip -dc $Curdir/gawk-3.1.4.tar.gz|tar xvf -
#     cd gawk-3.1.4
#     ./configure 
#     make
#     
#     exit
#     
#     if test -s /bin/gawk; then
#        cp -f /bin/gawk /bin/gawk-3.1.5
#     fi    
#     cp -f gawk /bin/gawk     
#  fi

  if test ! -s /usr/bin/gawk -a ! -s /usr/local/bin/gawk; then
     gunzip -dc $Curdir/gawk-3.1.6.tar.gz|tar xvf -
     cd gawk-3.1.6
     ./configure 
     make
#     exit
     
     make install
#     if test -s /bin/gawk; then
#        cp -f /bin/gawk /bin/gawk-3.1.5
#     fi    
#     cp -f gawk /usr/bin/gawk     
  fi


gawkloc=`which gawk|grep "no gawk"`
if test "$gawkloc" != ""; then
   Nogawk="y"
   gawkbin="awk"
else
   gawkbin="gawk"
fi



##### ֞ 23 (parts) ÿһһ function 
#     еڶ column  function 
#     ȶx 25 functions Ȼһ@ 25 functions?
# Setenvironment                 # Part1
# FindUnixSystem                 # Part1.1

# FindpathofFmtTexmfVartexBinary # Part3
# ModifyReadme                 # Part4
# InstallAcrobatReader         # Part5.1
# MakeChineseFmt               # Part5.2

# Copytfmppkttf                # Part6
                               # Part6.1
                               # Part6.2
# ModifyTexmf                  # Part6.3
# ModifyConfigps               # Part7
# ModifySpecialmap             # Part8
# CopyPfbTtftfmfiles           # Part9.1

# Modifyttfontsmap             # Part10
# CopySfdAfm                   # Part11
# CopyPstfiles                 # Part12
# Backupbinaryfiles            # Part13
# Copybinaryfiles              # Part14
# Compileandcopycfiles         # Part15
# CopyTeXfdfpngstyfiles        # Part16
# Configurescfilechitexfdf     # Part17
# Updatepsfontsmappdftexmap    # Part18
# Set600dpi                    # Part19
# InstallLatex2html            # Part19.1
# Modifylyx                    # Part20
# TexhashandRmtmpfiles         # Part21
# MakeVARTEXFONTSsubdir        # Part22
# GiveMessage                  # Part23
#


###### Part1
Setenvironment(){
# set SAVEPWD to current dir. and set PATH to contain current dir.

SAVEPWD=`pwd`
PATH=.:$PATH:$SAVWPWD
export PATH

SAVEPWDOLD=`pwd`


gawkbin=awk
export gawkbin

# QQ 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

#


#   gawkbin=awk
#   export gawkbin
#   unixname="linux"

} # End of Setenvironment

###### Part1.1
FindUnixSystem(){
# Find name of unix system
#unixname=`uname|$gawkbin '{print $0}'|tr '[A-Z]' '[a-z]'`
unixname=`uname|awk '{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 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 "        unix ϵy:"
echo " "
echo "       1. Linux"
echo "       2. FreeBSD"
echo "       3. Solaris"
echo "       4. SunOS"
echo "       q. ֹͣb"
echo " "
echo $echomode "         ՈIĔ 1,..,4  q ֹͣb: "$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" -a "$unixname" != "freebsd"; then
# if test "$unixname" != "linux"; then
#   if test "$unixname" = "freebsd"; then
#     cp chitex612/data/gawk.freebsd gawk
#   else
#     cp chitex612/data/gawk."$unixname".gz .
#     gunzip gawk."$unixname".gz
#   fi
#   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 ! -s /usr/bin/gawk -a ! -s /bin/gawk; then
#   Nogawk="y"
#fi


#if test "$unixname" = "linux" -o "$unixname" = "freebsd"; then
if test "$unixname" = "freebsd"; then
#   gawkbin=awk
#   export gawkbin
   if test "$Nogawk" = "y"; then
      ln -s /usr/bin/awk /usr/bin/gawk
#!/bin/csh      
      /bin/sh rehash
#!/bin/sh            
   fi
fi
}



##### Part2
WelcomeandVerifysupuser(){

welcomea=""
if test "$welcomea" = "y"; then
#######    Welcome      #######
clear
echo " ";echo " ";echo " "
echo " "
echo "         ******************************************"
echo "         *                                        *"
echo "         *   gӭʹ  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.2p15, August 9, 2008"
echo " "
echo $echomode "         Press enter key to continue "$echocr
read inkey
fi

if test ! -s /usr/bin/gcc; then
   Nogcc="y"
fi

#ls /usr/lib/libmath* 2> libmathmsg > /dev/nul

#libmath=`grep "No such" libmathmsg`

#if test "$libmath" != ""; then
if test ! -s /usr/lib/libm.so; then
   Nomathlib="y"
else
:
fi

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@ `


if test ! -s /usr/bin/gawk -a ! -s /bin/gawk -a ! -s /usr/local/bin/gawk; then
   Nogawk="y"
fi
if test ! -s $bindir/xdvi -a ! -s $bindir/xdvi-xaw3d.bin -a ! -s $bindir/xdvi-motif.bin -a ! -s $bindir/xdvi-xaw3d; then
   Noxdvi="y"
fi

clear
echo " ";echo " "
echo " "
echo "         ***************************************************"
echo "         *                                                 *"
echo "         *   bʽ㰲b 6.1.2p15                 *"
echo "         *                                                 *"
echo "         *   b ChiTeX6.1.2p15 ֮ǰ, ϵy      *"
echo "         *   b teTeX, teTeX ֮汾  >= 1.0            *"
echo "         *   (FreeBSD b latex-cjk*** ͕b teTeX)    *"
echo "         *   b texlive                                *"
#echo "         *                                                 *"
if test "$Nogcc" = "y"; then
echo "         *     b gcc                                  *"
fi
if test "$Nogawk" = "y"; then
echo "         *     b gawk                                 *"
fi

if test "$Nomathlib" = "y"; then
echo "         *     b mathlib                             *"
fi

if test "$Noxdvi" = "y"; then
echo "         *     b xdvi                                 *"
fi

if test ! -s $bindir/dvipdfmx; then
echo "         *     b dvipdfmx                             *"
fi

#if test ! -s $bindir/gv -a ! -s /usr/bin/ghostview; then
#echo "         *     b gv                                   *"
#fi

#echo "         *   Ұb gcc, gawk, mathlib, xdvi,            *"
#echo "         *     b dvipdfmx  gv ( ghostview)        *"
echo "         *   (δb, Ҳɰ Ctrl+C x_b           *"
echo "         *    ^mb)                                *"
echo "         *                                                 *"
echo "         ****************************************************"
echo $echomode "         Press enter key to continue "$echocr
read inkey


if test "$Nogawk" = "y" -o "$Noxdvi" = "y" -o "$Nomathlib" = "y"; then
InputYes="y"
while test "$InputYes" = "y"
do
clear
echo " ";echo " "
echo " "

if test "$Nogcc" = "y"; then
   echo "             δb gcc, Ո^mֹͣb: "
fi   

if test "$Nomathlib" = "y"; then
   echo "             δb mathlib (libmathlib*) , Ո^mֹͣb: "
fi   
if test "$Nogawk" = "y"; then
   echo "             δb gawk, Ո^mֹͣb: "
fi   
if test "$Noxdvi" = "y"; then
   echo "             δb xdvi, Ո^mֹͣb: "
fi   
echo " "
echo "             c. Ѱb gcc, mathlib, gawk   xdvi, Ҫ^mb chitex"
echo "             q. ֹͣb chitex" 
echo " "
echo $echomode "             ՈI 'c'  'q' : "$echocr
read inkey

case $inkey in
  "c") InputYes="n";;
  "q") InputYes="n"; rm -f *@;exit;;
    *) InputYes="y";;
esac
done

fi

if test ! -s /usr/bin/gcc; then
InputYes="n"
while test "$InputYes" = "y"
do
clear
echo " ";echo " "
echo " "
echo "             δb gcc, ֹͣb"
echo "             (Ҳ /usr/bin)"
echo " "
echo " "
echo $echomode "             Ո Enter Iֹͣb: "$echocr
read inkey

exit

done


fi



if test "$LOGNAME" != "root"; then
rootmessage="y"
while test "$rootmessage" = "y"
do
clear
echo " ";echo " "
echo " "
echo "         **********************************************"
echo "         *                                            *"
echo "         *   㲻 super user \"root\"                 *"   
echo "         *    teTeX ĿЌę, t  *"
echo "         *   oMаb                             *"
echo "         *                                            *"
echo "         **********************************************"
echo " "
echo "             c. ^mb"
echo "             q. ֹͣb" 
echo " "
echo $echomode "         ՈI 'c'  'q' : "$echocr
read inkey

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



install="all"

#updatemenu ( ) {
#######    Welcome      #######
clear
echo " ";echo " "
echo " "
echo "         ******************************************"
echo "         *                                        *"
echo "         *   Fڌ_ʼb  6.1.2p15             *"
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.2p15, August 9, 2008"
echo " "
echo $echomode "         Press enter key to continue "$echocr
read inkey
#}

newttf2pk="y"

} # End of WelcomeandVerifysupuser


###### Part3
FindpathofFmtTexmfVartexBinary(){
echo "yes" > tmp@
# Find path of
#  (1) fmt  (2) TEXMF (3) VARTEXFONTS (4) binary files
#

# (1)  find path of fmt #
#

echo "yes" > tmp@
texmfcnffile=`kpsexpand -w cnf texmf.cnf`
TEXMFCNF=`
$gawkbin  '
{texmfcnfloc=index(texmfcnffile,"/texmf.cnf")
 print substr(texmfcnffile,1,texmfcnfloc-1)
}' texmfcnffile=$texmfcnffile tmp@ `


echo $TEXMFCNF > tmp@
TEXMF=`
awk '
{
  inline=$0
  if (index(inline,"web2c")>0)
   {
    gsub(/web2c/,"",inline)
    inline=substr(inline,1,length(inline)-1)
   }
  else
   {tcnf=index(inline,"/texmf.cnf")
    if (tcnf>0) 
       {inline=substr(inline,1,tcnf-1)}
   } 
  print inline
}' tmp@ `

fmt=$TEXMF/web2c
fmtname=$TEXMF/web2c
texmf=$TEXMF

#echo "         fmtdir=$fmt found"
#echo "         texmf=$texmf found"

export TEXMF

#if test "$texmffound" = ""; then
# (2) find path of TEXMF #
#
#kpsexpand=`which kpsexpand`

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

texmf=$texmfdir

 if test -d "/usr/share/texmf-texlive"; then
    texmf="/usr/share/texmf-texlive"
 fi

texmffile=`kpsexpand '$TEXMFDIST' `

if test "$texmffile" != ""; then
TEXMF=` gawk '
   {lbr=index(texmffile,"{")
    sep=index(texmffile,",")
    dash=index(texmffile,"-")
    texmfpre=substr(texmffile,1,dash)
    if (lbr > 0)
       {texlive=substr(texmffile,lbr+1,sep-lbr-1) 
        texmf =texmfpre texlive
       }
    else
       {if (dash > 0)
           {texlive=substr(texmffile,dash+1) 
            texmf =texmfpre texlive
           } 
        else
           {texmf=texmffile}   
       }    
    print texmf
   }' texmffile=$texmffile tmp@ `
fi

if test "$TEXMF" != "" -a -d "$TEXMF"; then
   texmf=$TEXMF
else
   TEXMF=$texmf   
fi

export texmf
export TEXMF

TEXMFMAIN=`kpsexpand '$TEXMFMAIN' `

if test -d $TEXMF/web2c; then
   fmt=$TEXMF/web2c
else
   if test -d $TEXMFMAIN/web2c; then  
      fmt=$TEXMFMAIN/web2c 
   fi
fi  

#fi

# (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+wx $VARTEXFONTS
   chmod +t $VARTEXFONTS   
   mkdir $VARTEXFONTS/tfm
   chmod a+wx $VARTEXFONTS/tfm
   chmod +t $VARTEXFONTS/tfm   
   mkdir $VARTEXFONTS/pk    
   chmod a+wx $VARTEXFONTS/pk
   chmod +t $VARTEXFONTS/pk   
else
   if test ! -d $VARTEXFONTS; then
      mkdir -p $VARTEXFONTS
   fi   
   chmod a+wx $VARTEXFONTS
   chmod +t $VARTEXFONTS
   if test ! -d $VARTEXFONTS/tfm; then
      mkdir $VARTEXFONTS/tfm
   fi   
   chmod a+wx $VARTEXFONTS/tfm
   chmod +t $VARTEXFONTS/tfm
   if test ! -d "$VARTEXFONTS/pk"; then
      mkdir $VARTEXFONTS/pk    
   fi
   chmod a+wx $VARTEXFONTS/pk
   chmod +t $VARTEXFONTS/pk
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"

if test ! -d /usr/local/bin; then
   mkdir /usr/local/bin
fi
#if test ! -s /usr/local/bin/gawk; then

   if test "$unixname" = "freebsd"; then
   :
#     cp $SAVEPWDOLD/chitex612/chitex612/data/gawk.freebsd /usr/local/bin/gawk
#      chmod +x /usr/local/bin/gawk
#      mv -f /usr/bin/gawk /usr/bin/gawk.bak
#      awk '{system("rehash")}' tmp@
   fi
#fi


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

checkmenu="y"
while test "$checkmenu" = "y"
do
clear
echo "         ќyݔĿ:  "
echo "         1.  texmf Ŀ (һ /usr/.../texmf) :"
echo "               $texmf"
echo "         2.  *.fmt nڵĿ (һ /usr/.../texmf/web2c) :"
echo "               $fmt"
echo "         3.  .../texfonts Ŀ (tetex һ /var/tmp/texfonts "
echo "           /var/lib/texmf  /var/texfonts,  texlive һ "
echo "           /root/.texlive2007/texmf-var/fontsfonts) :"
echo "               $VARTEXFONTS"
echo "            oĿ, ܱ run 'texmfconfig' ȥOĿ"
echo "         4.  ɈЙn latex ڵĿ䛞: "
echo "               $bindir "
echo " "
echo "         ϜyĿǿĿ䛾_. "
echo "         "
echo "         ȫ_I "y" I, tՈI '1'  '2',.. "
echo "         (ԱݔԓĿ֮e`Ŀ)"
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 nڵĿ䛞($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 "         ɈЙn latex ڵĿ䛞($bindir)"
       echo $echomode "         :" $echocr
       read keydir
       if test "$keydir" != ""; then 
          bindir=$keydir
       fi
       ;;
   "y") 

   checksubmenu="y"
   while test "$checksubmenu" = "y"
   do
     echo " "
     echo "         fĿȫ_."
     echo "         ՈI "y" I _J, tՈI 'n' ݔ"
     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

InputYes="y"
while test "$InputYes" = "y"
do
clear
echo " ";echo " "
echo " "
echo "             b latex2html Ҳx񲻰b)"
echo "             (b latex2html І}, ɰ Ctrl+C ֹͣb,"
echo "              ˕r chitex bY, ٴΰb chitex) "
echo " "
echo "             c. ^mb latex2html"
echo "             q. ֹͣb latex2html" 
echo " "
echo $echomode "             ՈI 'c'  'q' : "$echocr
read inkey

case $inkey in
  "c") InputYes="n";;
  "q") InputYes="n"; rm -f *@;;
    *) InputYes="y";;
esac
done

if test "$inkey" = "c";then
   Instlatex2html="y"
   export Instlatex2html
fi


Askstop="n"
while test "$Askstop" = "y"
do
clear
echo " "
echo "         ɷNbʽ:"
echo "         1.  ͣʽ"
echo "         2.  b׵ķʽ(ͣǷb latex2html )" 
echo " "
echo "         ՈI '1'  '2' "
echo " "
echo $echomode "         : " $echocr
read inkey
   case "$inkey" in
   "1") stopask="y"; Askstop="";;
   "2") stopask=""; Askstop="";;
   "*")  :  ;;
   esac
done


#done


} # End of FindpathofFmtTexmfVartexBinary


###### Part4
ModifyReadme(){
###### Modify files of README* ,...  and alt last put them
#      on $texmf/doc/chinese

# In the following we'll modify files of README*,... given by
# $SAVEPWD/chitex612/doc


cd $tmpdir/chitex612


SAVEPWD=`pwd`


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

if test ! -d $tmpdir/chitex612/docdir; then
   mkdir $tmpdir/chitex612/docdir
fi

 cd $tmpdir/chitex612/chitex612/doc

 NOWPWD="$tmpdir/chitex612"


# Move *.ps to ../ for the time being since we need not modify them
mv -f  *.ps $tmpdir/chitex612/docdir

docfiles=`/bin/ls `

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


# Move $SAVEPWD/docdir/*.ps to  $NOWPWD/chitex612/doc
mv -f $NOWPWD/docdir/*.ps $NOWPWD/chitex612/doc

cd $tmpdir/chitex612

# 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 -R +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

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

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

#clear
#echo " "
#echo " ";echo " "
#echo " "
#echo "         ******************************************"
#echo "         *                                        *"
#echo "         *            _ʼb, Ժ              *"
#echo "         *                                        *"
#echo "         ******************************************"
#echo " "
}  #End of ModifyReadme

installTeXMaker(){
  if test "$unixname" = "linux"; then
   if test ! -s /usr/bin/texmaker; then  
clear
echo " "    
echo "         ****************************************"
echo "         *                                      *"
echo "         *     b TeXMaker                  *"
echo "         *                                      *"
echo "         *     Press Enter key to continue      *"
echo "         *                                      *"
echo "         ****************************************"
echo " "
#echo "         Press Enter key to continue"
echo $echomode "         Press Enter key to continue: " $echocr
#echo $echomode "         : " $echocr
read inkey
   fi
   
   if test -s /usr/bin/texmaker; then
      if test ! -s /usr/bin/texmaker.bin; then
         cp /usr/bin/texmaker /usr/bin/texmaker.bin
         cp -f $tmpdir/chitex612/chitex612/bin/texmaker /usr/bin/texmaker         
      fi
   else
#     PWDDIR=$tmpdir    
#     cd $PWDDIR 
     cp -f $tmpdir/texmaker_linux_installer.gz .
     gunzip texmaker_linux_installer.gz
     chmod +x texmaker_linux_installer
     ./texmaker_linux_installer
#     rm texmaker_linux_installer

     rm -f /usr/bin/texmaker.bin
     ln -s /usr/share/texmaker/texmaker /usr/bin/texmaker.bin
     rm -f /usr/bin/texmaker
#     cp /usr/bin/texmaker  /usr/bin/texmaker.bin
     cp -f $tmpdir/chitex612/chitex612/bin/texmaker /usr/bin/texmaker
     rm -f texmaker_linux_installer
   fi  
   chmod +x /usr/bin/texmaker   

   if test ! -d $TEXMF/tex/chinese; then
      chmod +rwx $TEXMF/tex
      mkdir $TEXMF/tex/chinese
   fi   
   cp -f $tmpdir/chitex612/chitex612/data/texmaker.ini $TEXMF/tex/chinese/texmaker.ini
  fi

}

##### Part5.1
InstallAcrobatReader(){
#if test "$unixname" = "linux" -o "$unixname" = "solaris"; then
rootmessage="y"
while test "$rootmessage" = "y" 
do
clear
echo " ";echo " "
echo " "
echo "         **********************************************"
echo "         *                                            *"
echo "         *   挢b Acrobat Reader 7.0            *"   
echo "         *                                            *"
echo "         **********************************************"
echo " "
echo "             c. ^mb Acrobat Reader 7.0"
echo "             q. ֹͣb Acrobat Reader 7.0" 
echo " "
#echo "             (If the system is Linux and it could not work"
#echo "              after installtion. "
#echo "              Get AdobeReader\cht-7.0.1-1.i386.rpm from"
#echo "              www.adobe.com and Install it.)"
#echo " "
echo $echomode "         ՈI 'c'  'q' : "$echocr
read inkey



case $inkey in
  "c") rootmessage="n"; acroinst="y" ;;
  "q") rootmessage="n";;
    *) rootmessage="y";;
esac
done

#cd $Curdir

PWDDIR=$tmpdir 


  if test "$acroinst" = "y"; then
  
#if test -s $SAVEPWD/utf8@; then
#clear
#echo " ";echo " "
#echo "         **********************************"
#echo "         *                                *"
#echo "         *  Ȍ־aĞ Big5 ֮,   *"
#echo "         *  ٰ EnterI ^mb         *"
#echo "         *                                *"
#echo "         *  (b֮, Ոٌ־a *"
#echo "         *   Ğ UTF-8, ٰ֮ EnterI *"
#echo "         *   ^mһE )               *"
#echo "         *                                *"
#echo "         **********************************"
#echo " "
#echo $echomode "         "
#read xxxxxxxxxxxxxxxx
#fi


     if test ! -d $PWDDIR/Acrobat; then
        mkdir $PWDDIR/Acrobat
     fi
     cd $PWDDIR/Acrobat

#     if test "$unixname" = "linux" -o "$unixname" = "solaris"; then
       if test "$unixname" = "solaris"; then
         gunzip -dc $Curdir/solaris-506.tgz|tar xvf -       
       else
         gunzip -dc $Curdir/AdobeReader_cht-7.0.9-1.i386.tar.gz|tar xvf -
       fi

      if test "$unixname" = "linux" -o "$unixname" = "solaris"; then
         cd AdobeReader
        ./INSTALL
      fi  


#if test -s $SAVEPWD/utf8@; then
#clear
#echo " ";echo " "
#echo "         *****************************************"
#echo "         *                                       *"
#echo "         *  The installation of Adboe Reader is  *"
#echo "         *  finished. Please change code to      *"
#echo "         *  UTF-8 and Press Enter to continue    *"
#echo "         *                                       *"
#echo "         *****************************************"
#echo " "
#echo $echomode "         "
#read xxxxxxxxxxxxxxxx
#fi

#       gunzip -dc $Curdir/chtfont.tgz|tar xvf -
#       cd CHTKIT
#        ./INSTLANG
#     else
#        cd /usr/local
#        gunzip -dc $Curdir/acroread-5.08.tgz|tar xvf -
#        gunzip -dc $Curdir/acroread5-commfont-2002.5.tgz|tar xvf -
#        gunzip -dc $Curdir/zh-acroread5-chtfont-2002.5.tgz|tar xvf -
#        echo "yes" > tmp@
#        awk '{system("rehash")} ' tmp@
#     fi
#
  fi

  cd $tmpdir/chitex612  

clear
echo " ";echo " "
echo " "
echo "         **********************************************"
echo "         *                                            *"
echo "         *                    Wait!                   *"   
echo "         *                                            *"
echo "         **********************************************"
echo " "
echo " "
#echo $echomode "                                                         "$echocr
#read inkey


NN="n"
if test "$NN" = ""; then
 if test ! -s /usr/local/Adobe/Acrobat7.0/bin/acroread; then  

  find /usr -name 'Acrobat7.0' > acroread@

  $gawkbin '
  {
    if (index($0,"Acrobat7.0")>0) then
       {print $0 > "acro@"}
  } ' acroread@

  acroreaddir=`cat acro@`
 else
  acroreaddir="/usr/local/Adobe/Acrobat7.0"
 fi

  if test -s $acroreaddir/bin/acroread; then
     acroread="$acroreaddir/bin/acroread"
     cp -f $acroread $bindir
  fi

  cp -f /usr/local/Adobe/Acrobat7.0/bin/acroread /usr/bin/acroread
fi  
#fi
}





##### Part5.2
MakeChineseFmt(){
##### Make chinese fmt files and copy to $fmtname

### Find date of latex.ltx
TEXMFold=$TEXMF
VARTEXFONTSold=$VARTEXFONTS
TEXMF=""
VARTEXFONTS=""

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

nowdate=`date +%D`
nowtime=`date +%T`
if test -s $texmf/tex/latex/base/latex.ltx; then  #
   gawk -v nowdate=$nowdate '
   BEGIN{
    lyear=substr(nowdate,length(nowdate)-1)
    nowdate="20" lyear "/" substr(nowdate,1,length(nowdate)-3)
  }
  { fmtvpos=index($0,"def\134fmtversion{")
    if (fmtvpos>0)
       {
        rbr=index($0,"}")
        lline=substr($0,1,fmtvpos+14)
        rline=substr($0,rbr)
        outline=lline nowdate rline
       }
    else
       {outline=$0}
    print outline > "latexltx@"
  }
  END{} ' $texmf/tex/latex/base/latex.ltx
  cp -f latexltx@ $texmf/tex/latex/base/latex.ltx
  rm -f latexltx@
fi

if test -s $texmf/tex/latex/base/ltpatch.ltx; then  #
   gawk -v nowdate=$nowdate '
   BEGIN{
    lyear=substr(nowdate,length(nowdate)-1)
    nowdate="20" lyear "/" substr(nowdate,1,length(nowdate)-3)
  }
  { fmtvpos=index($0,"fmtversion@topatch{")
    if (fmtvpos>0)
       {
        rbr=index($0,"}")
        lline=substr($0,1,fmtvpos+18)
        rline=substr($0,rbr)
        outline=lline nowdate rline
       }
    else
       {outline=$0}
    print outline > "ltpatchltx@"
  }
  END{} ' $texmf/tex/latex/base/ltpatch.ltx
  cp -f ltpatchltx@ $texmf/tex/latex/base/ltpatch.ltx
  rm -f ltpatchltx@
fi


#if test "$fmtdate" = ""; then
#  date --set "1998/01/01"
#fi 

### To enlarge memory 
if test -s $texmf/web2c/texmf.cnf; then
$gawkbin '
BEGIN{}
{ per=index($0,"%")
  rline=""
  if (per > 0)
     {inline=substr($0,1,per-1)
      rline=substr($0,per,length($0)-per+1)
     }
  else
     {inline=$0}

  if (inline != "")
     {gsub(/ /,"",inline)}

  mempos=index(inline,"main_memory=")
  if (mempos == 1)
     {print "% " $0 > "texmfcnf@"
      print "main_memory = 20000000 " rline > "texmfcnf@"}
  else
     {print $0 > "texmfcnf@"}
}
END{} ' $texmf/web2c/texmf.cnf
fi

   cp -f texmfcnf@ $texmf/web2c/texmf.cnf
   rm -f texmfcnf@

### Recompile latex,...

#if test -s $texmf/tex/latex/base/latex.ltx; then  #
#   latex -ini latex.ltx
#    echo "texmf=$texmf"
#    read xxxxxxx
#   cp -f *.fmt $texmf/web2c
#   rm -f *.fmt
#fi

fi # if test "$Runmkfmt0" = "y"; .....


#   unixnamea="Redhat70"
  
   echo $echomode "." $echocr       

  ChmkFmtrtn(){
   ./chmkfmtp; ./chmkfmt
   echo $echomode "." $echocr       

      cp chitex.fmt $fmtname/chitex.fmt 2> errlog@
   if test -s chitex.fmt; then
      cp chitexl.fmt $fmtname/chitexl.fmt
      cp chitexg.fmt $fmtname/chitexg.fmt
      cp chitexlg.fmt $fmtname/chitexlg.fmt
      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/null
      echo $echomode "." $echocr          

      cp pdfchitex.fmt $fmtname
      cp pdfchitexl.fmt $fmtname
      cp pdfchitexg.fmt $fmtname
      cp pdfchitexlg.fmt $fmtname
      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       
   if test -s chmkfmt; then
      cp -f chmkfmt* $bindir      # move later
      /bin/rm -f chmkfmt*
   fi
   echo "       End of make fmt files "
  }

# if test "$unixname" != "linux"; then   
#      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

# To make chinese fmt files
#  

#  ChmkFmtrtn
# else

#     gunzip -dc chitex612/fmt/chggfile.linux.tgz|tar xvf - 2>&2 >/dev/null           
#     ChmkFmtrtn 

### Renew date
#  date --set $nowdate 2> /dev/null>/dev/null
#  date --set $nowtime 2> /dev/null>/dev/null

#  cp -f $Curdir/chitex612/chitex612/data/wumap2.tex .
#  cp -f $Curdir/chitex612/chitex612/data/bcwumap.tex .


#  cp -f $tmpdir/chitex612/chitex612/data/wumap2.tex .
#  cp -f $tmpdir/chitex612/chitex612/data/bcwumap.tex .

  if test ! -d $texmf/tex/chinese; then
     mkdir -p $texmf/tex/chinese
  else
     chmod +w $texmf/tex/chinese/*
  fi

#  cp -f $Curdir/chitex/612/chitex612/data/wumap2.tex $texmf/tex/chinese
#  cp -f $Curdir/chitex/612/chitex612/data/bcwumap.tex $texmf/tex/chinese

# if test "$unixname" != "linux"; then
#      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
#      ChmkFmtrtn 
# else
#   gunzip -dc chitex612/fmt/chggfile.Redhat70.tgz|tar xvf - 2>&2 >/dev/null
#    chmod +x chmk*
#    ./chmkfmtp 2> usagefile
#    useage=`cat usagefile`
#    rm -f usagefile
#   if test "$useage" = ""; then
#      ChmkFmtrtn 
#      if test -s err1@; then
#          rm -f err1@
#      fi
#      grep "No such file" errlog@|grep "chitex.fmt" > err1@
#      if test -s err1@; then
#         gunzip -dc chitex612/fmt/chggfile.linux.tgz|tar xvf - 2>&2 >/dev/null 
#         chmod +x chmk*
#         ChmkFmtrtn
#      fi  
#   else
#     gunzip -dc chitex612/fmt/chggfile.linux.tgz|tar xvf - 2>&2 >/dev/null
#     ChmkFmtrtn 
#   fi
# fi

 Runmkfmt="" 

if test "$Runmkfmt" = "y"; then
 cd /tmp
 mkdir .tmp7675
 cd .tmp7675 
# gunzip -dc $tmpdir/chitex612/chitex612/data/ctexl.tgz|tar xvf -  2>&2 >/dev/null 

 cp -f $tmpdir/chitex612/chitex612/data/ctexfile.tgz $texmf/tex/chinese
 gunzip -dc $tmpdir/chitex612/chitex612/data/ctexfile.tgz|tar xvf -  2>&2 >/dev/null 

 latex -ini \&latex chitexl "\dump" 
 mv -f chitexl.fmt $texmf/web2c/chitexl.fmt

 latex -ini \&latex chitexlu "\dump" 
 mv -f chitexlu.fmt $texmf/web2c/chitexlu.fmt

 latex -ini \&latex chitexls "\dump" 
 mv -f chitexls.fmt $texmf/web2c/chitexls.fmt

# latex -ini \&latex chitexlus "\dump" 
# mv -f chitexlus.fmt $texmf/web2c/chitexlus.fmt


 latex -ini  \&latex chitexlg "\dump" 
 mv -f chitexlg.fmt $texmf/web2c/chitexlg.fmt

 pdftex -ini \&pdflatex chitexlu "\dump" 
 mv -f chitexlu.fmt $texmf/web2c/pdfchitexlu.fmt

 pdftex -ini \&pdflatex chitexl "\dump" 
 mv -f chitexl.fmt $texmf/web2c/pdfchitexl.fmt
 pdftex -ini \&pdflatex chitexlg "\dump" 
 mv -f chitexlg.fmt $texmf/web2c/pdfchitexlg.fmt
 
 omega -ini \&lambda ochitexl "\dump" 
 mv -f ochitexl.fmt $texmf/web2c/ochitexl.fmt
 omega -ini \&omega ochitex "\dump" 
 mv -f ochitex.fmt $texmf/web2c/ochitex.fmt

 omega -ini \&lambda ochtexlg "\dump" 
 mv -f ochtexlg.fmt $texmf/web2c/ochtexlg.fmt
 omega -ini \&omega ochtexg "\dump" 
 mv -f ochtexg.fmt $texmf/web2c/ochtexg.fmt
 
# gunzip -dc $tmpdir/chitex612/chitex612/data/ctex.tgz|tar xvf -  2>&2 >/dev/null 
 tex -ini \&plain chitex "\dump" 
 mv -f chitex.fmt $texmf/web2c

 tex -ini \&plain chitexu "\dump" 
 mv -f chitexu.fmt $texmf/web2c

# tex -ini \&plain chitexu "\dump" 
# mv -f chitexu.fmt $texmf/web2c

 tex -ini \&plain chitexg "\dump" 
 mv -f chitexg.fmt $texmf/web2c

 pdftex -ini \&pdftex chitex "\dump" 
 mv -f chitex.fmt $texmf/web2c/pdfchitex.fmt

# pdftex -ini \&pdftex chitexu "\dump" 
# mv -f chitexu.fmt $texmf/web2c/pdfchitexu.fmt

 pdftex -ini \&pdftex chitexg "\dump" 
 mv -f chitexg.fmt $texmf/web2c/pdfchitexg.fmt
 /bin/rm -f *.tex *.log *.fdfile *@
 cd ../
 /bin/rm -rf /tmp/.tmp7675

 rm -f wumap.tex
 rm -f bcwumap.tex

fi

## fi 

# Test 

echo "yes">tmp@

echo $texmf/tex/chinese/chitex.fdf

   chmod +w $texmf/tex/chinese/chitex.fdf

   

#   cp $tmpdir/chitex612/chitex612/data/chitex.fdf $tmpdir/chitex612/chitex612/tex/chitex.fdf
#   cp $tmpdir/chitex612/chitex612/tex/chitex.fdf chitex.fdfile


#  echo "     "
#  echo "   The following is to test whether "
#  echo "   the chinese fmt files work well"
#  echo "  "
#  echo "   If it fails, just type 'x' or 'control z' to exit"
#  echo "   (Messages will contain characters ^^ which are not error message.)"
#  echo "   and then it will try to make up the installation."
#  echo " "
#  echo "   Press Enter key to continue!"
#  read xxxxxxx

gawk '
BEGIN{}
{
print "\134nonstopmode" > "t1.tex"
print "\134makeatletter" > "t1.tex"
print "\134def\134ch@delay{y}" > "t1.tex"
print "\134makeatother" > "t1.tex"
print "\134documentclass{article}" > "t1.tex"
print "\134begin{document}" > "t1.tex"
print "test" > "t1.tex"
print "\134end{document}" > "t1.tex"
}
END{} ' tmp@

if test "$Runmkfmt" = "y"; then
  echo "cp $fmtname/chitexl.fmt" 
  
  cp  $fmtname/chitexl.fmt .
  
#  read xxxxxxx
  
  latex \&chitexl t1


/bin/rm -f t1.* *.fmt

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

TEXMF=$TEXMFold
VARTEXFONTS=$VARTEXFONTSold
export TEXMF
export VARTEXFONTS

if test "$Runmkfmt" = "y"; then
   pdfetex=`ls -l $bindir/pdfetex`
   tex=`ls -l $bindir/tex`
   omega=`ls -l $bindir/omega`
   echo "yes" > tmp@
   
   gawk '
   {chinesedir=texmf "/tex/chinese/latexdate"
    split(pdfetex,a)
    if (length(a[6])==3){a[6]="0" a[6]}
    if (length(a[7])==1){a[7]="0" a[7]}    
    pdfetexdate=a[6] a[7]
    print "pdfetexdate=" pdfetexdate > chinesedir
    split(tex,a)
    if (length(a[6])==3){a[6]="0" a[6]}
    if (length(a[7])==1){a[7]="0" a[7]}    
    texdate=a[6] a[7]
    print "texdate=" texdate > chinesedir    
    split(omega,a)
    if (length(a[6])==3){a[6]="0" a[6]}
    if (length(a[7])==1){a[7]="0" a[7]}    
    omegadate=a[6] a[7]
    print "omegadate=" omegadate > chinesedir    
   }' texmf=$TEXMF pdfetex="$pdfetex" tex="$tex" omega="$omega" tmp@
   
fi

#   latex -ini latex.ini "\dump"
#   tex -ini tex.ini "\dump"
#   pdflatex -ini pdflatex.ini "\dump"
#   pdftex -ini pdftex.ini "\dump"
#   lambda -ini lambda.ini "\dump"
#   omega -ini omega.ini "\dump"
#   mv -f *.fmt $texmf/web2c 

} # End of MakeChineseFmt



##### Part6
Copytfmppkttf(){
#####  Copy tfm. pk, ttf files      
#####  to $texmf/fonts/...  
#
# if test "$install" = "all" -o "$install" = "update" ; then
#                 # Remove  May 7, 2000

##### Part6.0
##### First 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/pk/chinese/moe_kai \
  fonts/tfm/chinese/moe_sung fonts/pk/chinese/moe_sung fonts/tfm/chinese/wafonts
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


##### Part6.1
##### 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/wutfm.tgz|tar xvf -
#cp -f *.tfm $texmf/fonts/tfm/chinese/wafonts
#/bin/rm -f *.tfm

cd $SAVEPWD
rmdir tfm
##### Part6.2
##### 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
##### end of copying tfm. pk, ttf files

echo "       End of make copy tfm files "
if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echoc
   read inkey                         
fi
} # End of copytfmpkttf


##### Part6.3
ModifyTexmf(){
cd $TEXMF
gunzip -dc $Curdir/texmfall.tgz|tar xvf -
gunzip -dc $Curdir/texmffonts.tgz|tar xvf -
cp $TEXMF/dvipdfm/config/cid-x.map $TEXMF/dvipdfm/config/cid-x.map.org
if test -d "$TEXMF/scripts/debian" -o -d /usr/share/doc/xorg-x11-docs-1.3-5.fc11; then
   cp $TEXMF/dvipdfm/config/cid-x_debian.map $TEXMF/dvipdfm/config/cid-x.map 
   cp $TEXMF/dvipdfm/config/cid-x_debian.map $TEXMF/fonts/map/dvipdfm/tetex/cid-x.map
else
   cp $TEXMF/dvipdfm/config/cid-x.map $TEXMF/fonts/map/dvipdfm/tetex/cid-x.map  
fi

cp $TEXMF/dvipdfm/config/config $TEXMF/dvipdfm/config/config.org

cp -f $tmpdir/chitex612/chitex612/data/texmaker.ini $TEXMF/tex/chinese/texmaker.ini
cp -f $tmpdir/chitex612/chitex612/data/kilerc $TEXMF/tex/chinese/kilerc
cp -f $tmpdir/chitex612/chitex612/data/preferences $TEXMF/tex/chinese/preferences

cpfile="y"
if test "$cpfile" = "y"; then
  cp -f $TEXMF/dvipdfm/config/cid-x.map $TEXMF/fonts/map/dvipdfmx/cid-x.map
  cp -f $TEXMF/dvipdfm/CMap/* $TEXMF/fonts/cmap
fi
texhash
}          

##### Part7
ModifyConfigps(){
cd $SAVEPWD
##### Modify config.ps and copy XDvi.300 XDvi.600 $texmf/xdvi
#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  # Delete 9/20/2005
cd $SAVEPWD
} # ModifyConfigps


##### Part8
ModifySpecialmap(){
###### Modify special.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
   cat chitex612/data/special.map.add2 >> $fontname/special.map
fi
/bin/rm -f chinesname@
###### end of modify specila.map  ###########

echo "       End of modifying file special.map  "
if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echoc
   read inkey                         
fi
# End of ModifySpecialmap
}






##### Part9.1
CopyPfbTtftfmfiles(){
#####  Makedir $VARTEXFONTS/type1/fonts
#####      and copy pfb files to here 
#####  Unzip ttf files and copy to $texmf/fonts/chinese/fonts  
##### 
cd $SAVEPWD 

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

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

#   ln $VARTEXFONTS/type1/fonts/* $texmf/fonts/type1/chinese/fonts \
#       2>&2 >/dev/null


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 " "
if test "$stopask" = "y"; then
   echo $echomode "           Press any enter key to continue" $echocr
   read inputkey
fi

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/moekai.ttf; then
   ln -s $texmf/fonts/chinese/ttf/moekai.ttf \
           $texmf/fonts/chinese/ttf/moe_kai.ttf 
fi
if test -s $texmf/fonts/chinese/ttf/moesung.ttf; then
   ln -s $texmf/fonts/chinese/ttf/moesung.ttf \
           $texmf/fonts/chinese/ttf/moe_sung.ttf 
fi
########


   cd $SAVEPWD

} # CopyPfbTtftfmfiles

#####

##### Part10
Modifyttfontsmap(){
##### Modify ttfonts.map or copy it #############
modifyttfontsmap="n"

# if test "$modifyttfontsmap = "y"; then
#cp -f chitex612/data/ttfonts.map $texmf/ttfonts.map
if test ! -d $texmf/ttf2pk; then
   mkdir $texmf/ttf2pk
fi
#cp -f chitex612/data/ttfonts.map $texmf/ttf2pk/ttfonts.map

$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/share/texmf",texmf,wholeline[i])
         gsub("/var/tmp/texfonts",vartexfonts,wholeline[i])
        print wholeline[i] >> "ttfontsmap@"}
     }

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

cp -f ttfontsmap@ $texmf/ttfonts.map
cp -f ttfontsmap@ $texmf/ttf2pk/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@
  sed "s#/usr/share/texmf#$texmf#g" $texmf/ttfonts.map >ttfonts.map@
  cp -f ttfonts.map@ $texmf/ttfonts.map
  cp -f ttfonts.map@ $texmf/ttf2pk/ttfonts.map
  /bin/rm -f ttfonts.map@
  cp -f $texmf/*.sfd $texmf/ttf2pk  

echo "       End of modifying ttfonts.map files "
if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echoc
   read inkey                         
fi
} # End of Modifyttfontsmap


##### Part11 
#CopySfdAfm(){
##### copy *.sfd  to $texmf, copy *.afm to $texmf/tex/chinese #####
#cp -f chitex612/data/*.sfd $texmf
#cp -f chitex612/data/*.sfd $texmf/ttf2pk
#cp -f chitex612/data/*.afm $texmf/tex/chinese
#if test ! -d $texmf/fonts/afm/chinese/wafonts; then
#   mkdir -p $texmf/fonts/afm/chinese/wafonts
#fi
#gunzip -dc $Curdir/wuafm.tgz|tar xvf -
#cp -f *.afm $texmf/fonts/afm/chinese/wafonts
#rm -f *.afm
#} # End of CopySfdAfm


##### Part12
CopyPstfiles(){
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@

   /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
      cp -f * $texmf/tex/generic/pstricks
   fi
   /bin/rm -f *
   cd $SAVEPWD
   rmdir pstricks
} # CopyPstfiles



##### Part13
Backupbinaryfiles(){
##### Backup ttf2tfm, ttf2pk
   if test -s $bindir/ttf2tfm -a ! -s $bindir/ttf2tfm.bak; then 
       cp $bindir/ttf2tfm $bindir/ttf2tfm.bak
   fi
   if test -s $bindir/ttf2pk -a ! -s $bindir/ttf2pk.bak; then 
       cp $bindir/ttf2pk $bindir/ttf2pk.bak
   fi
   if test -s $bindir/ttf2pfb -a ! -s $bindir/ttf2pfb.bak; then 
       cp $bindir/ttf2pfb $bindir/ttf2pfb.bak
   fi


##### Backup binary files
####### backup old dvips and mv dvips to dvips.bin
######  Important
echo "yes" > tmp@
#step22="y"
#if test "$step22" = "y"; then

if test ! -s $bindir/dvips.bin; then
   cp $bindir/dvips $bindir/dvips.bin
   if test ! -s $bindir/dvips.bak; then
      cp $bindir/dvips $bindir/dvips.bak
   fi
fi

if test ! -s $bindir/xdvi.bak; then
   cp $bindir/xdvi $bindir/xdvi.bak
fi

if test ! -s $bindir/xdvi.bin; then
   cp $bindir/xdvi $bindir/xdvi.bin
fi


######## Backup 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
######## Backup 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
} # Backupbinaryfiles

##### Part14
Copybinaryfiles(){
##### Copy binary files
##### Expand chitex612/data/ttf2*.$unixname.gz and copy ttf2tfm, ttf2pk
##### ttf2pfb, t1asm to $bindir
#
   echo $echomode "." $echocr       

if test ! -s $bindir/ttf2tfm; then
   gunzip -dc chitex612/data/ttf2tfm.$unixname.gz> ttf2tfm
   chmod +x ttf2tfm
   if [ "$unixname" != "linux" ]; then
   :
#      cp -f ttf2tfm $bindir
   else
      usage=`ttf2tfm --help|grep "Usage"`
#      if [ "$usage" != "" ]; then
#         :
#      else
         gunzip -dc chitex612/data/ttf2tfm.linux.new.gz> ttf2tfm         
         chmod +x ttf2tfm 
#      fi
      cp -f ttf2tfm $bindir
   fi   
   /bin/rm -f ttf2tfm
fi

   echo $echomode "." $echocr      
 
 if test ! -s $bindir/ttf2pk; then
   gunzip -dc chitex612/data/ttf2pk.$unixname.gz> ttf2pk
   chmod +x ttf2pk
   if [ "$unixname" != "linux" ]; then
   :
#      cp -f ttf2pk $bindir
   else
      usage=`ttf2pk --help|grep "Usage"`
#      if [ "$usage" != "" ]; then
#         :
#      else
         gunzip -dc chitex612/data/ttf2pk.linux.new.gz> ttf2pk
         chmod +x ttf2pk
#      fi
      cp -f ttf2pk $bindir
   fi   
   /bin/rm -f ttf2pk
 fi
   echo $echomode "." $echocr       
   if test "$unixname" = "linux" -o "$unixname" = "freebsd"; then
      gunzip -dc chitex612/data/ttf2pfb.$unixname.gz> ttf2pfb
      chmod +x ttf2pfb
    if [ "$unixname" != "linux" ]; then
    :
#      cp -f ttf2pfb $bindir
    else
      ttf2pfb --help 2> msgtmp
      usage=`grep "Usage" msgtmp`
      if [ test "$usage" != "" ]; then
         :
      else
         gunzip -dc chitex612/data/ttf2pfb.linux.new.gz> ttf2pfb
         chmod +x ttf2pfb
      fi
      cp -f ttf2pfb $bindir
    fi   
    /bin/rm -f ttf2pfb
    /bin/rm -f msgtmp
    echo $echomode "." $echocr       
   fi

   if test "$unixname" = "linux" -o "$unixname" = "freebsd"; then
      if [ "$unixname" != "linux" ]; then
      :
 #        cp $SAVEPWD/chitex612/data/t1asm.$unixname $bindir/t1asm
      else
         t1asm --help 2> msgtmp
         usage=`grep "Usage" msgtmp`
         if [ "$usage" != "" ]; then
            :
         else
            cp $SAVEPWD/chitex612/data/t1asm.linux.new t1asm
            chmod +x t1asm
         fi
         cp -f t1asm $bindir
         /bin/rm -f t1asm
         /bin/rm -f msgtmp
      fi
    echo $echomode "." $echocr       
   fi

######
###### Copy chitex612/bin/* to $bindir 

/bin/rm -rf chitex612/bin/temp

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

echo "yes" > tmp@

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

#cp -f chitex612/bin/chitrancc $chitrancdir
#cp -f chitex612/bin/chitrancc $chitrancdir
#cp -f chitex612/bin/chitranc $chitrancdir

#cp -f chitex612/data/chitran0.awk $chitrancdir
#cp -f chitex612/data/chitran1.awk $chitrancdir
#cp -f chitex612/data/chitran11.awk $chitrancdir
#cp -f chitex612/data/chitran0nn.awk $chitrancdir
#cp -f chitex612/data/chitran0nn3.awk $chitrancdir
#cp -f chitex612/data/chitranutf.awk $chitrancdir
#cp -f chitex612/data/utf2text.awk $chitrancdir
#cp -f chitex612/data/big2uni.awk $chitrancdir

sed "s#chitran0.awk#$bindir/chitran0.awk#g" $chitrancdir/chitranc > chitranc@
sed "s#chitran1.awk#$bindir/chitran1.awk#g" chitranc@ > chitranc@@
sed "s#chitran11.awk#$bindir/chitran11.awk#g" chitranc@@ > chitranc@@@
sed "s#chitran3a.awk#$bindir/chitran3a.awk#g" chitranc@@@ > chitranc@

sed "s#chitran1.awk#$bindir/chitran1.awk#g" $chitrancdir/chitranpc > chitranpc@
sed "s#chitran11.awk#$bindir/chitran11.awk#g" chitranpc@ > chitranpc@@
sed "s#chitranp1.awk#$bindir/chitranp1.awk#g" chitranpc@@ > chitranpc@

mv -f chitranc@ $chitrancdir/chitranc
mv -f chitranpc@ $chitrancdir/chitranpc

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


##### Part15
Compileandcopycfiles(){
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 
#


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


  gunzip -dc $tmpdir/chitex612/chitex612/data/bg.tgz|tar xvf -
  gcc bg5conv.c -o bg5conv
  cp -f bg5conv $bindir/bg5conv



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
# 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"
if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echoc
   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

#cp -f $SAVEPWD/chitex612/data/chitran3a.awk $bindir
#cp -f $SAVEPWD/chitex612/data/chitran11.awk $bindir
#cp -f $SAVEPWD/chitex612/data/chitranp1.awk $bindir

cp -f $SAVEPWD/chitex612/data/*.awk $bindir


#step6="y"
#if test "$step6" = "y"; then
for cmd in chitran00 chitran01 chitran0 chitran1 chitran2 chitran3 chitran4 \
   chitran5 chitran5b chitran6 chitran7 chicodelistc  \
   chitranp2 chitranp3 chitexsub1 chitran0nn chitran0nn3 chitranutf chitranutf2 \
   mkidx1 bibtx1
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
done

#fi  # end of step6

#echo after compile c



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*

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

echo "       End of compiling some c files and copy to $bindir"
if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echoc
   read inkey                         
fi
} # End of Compileandcopycfiles



##### Part16
CopyTeXfdfpngstyfiles(){
cd $SAVEPWD

##### copy (update) *.tex files #######
cp -f $SAVEPWD/chitex612/bin/chitran0nn.awk $bindir
cp -f $SAVEPWD/chitex612/bin/chitran0nn3.awk $bindir
cp -f $SAVEPWD/chitex612/bin/chitranutf.awk $bindir
cp -f $SAVEPWD/chitex612/bin/chitranutf2.awk $bindir

chmod +w $texmf/tex/chinese/*.fdf
chmod +w $texmf/tex/chinese/*.tex
chmod +w $texmf/tex/chinese/*.png
chmod +w $texmf/tex/chinese/*.pdf
chmod +w $texmf/tex/chinese/*.bib
chmod +w $texmf/tex/chinese/*.sty
#cp -f chitex612/tex/* $texmf/tex/chinese
#cp -f chitex612/data/chitex.fdf $texmf/tex/chinese/chitex.fdf


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/*.pdf $SAVEPWD/tex
#cp -f chitex612/tex/*.bib $SAVEPWD/tex

#chmod a-w $texmf/tex/chinese/*.fdf
#chmod a-w $texmf/tex/chinese/*.tex
#chmod a-w $texmf/tex/chinese/*.png
#chmod a-w $texmf/tex/chinese/*.pdf
#chmod a-w $texmf/tex/chinese/*.bib
#chmod a-w $texmf/tex/chinese/*.sty


echo "       End of copy files to $texmf/tex/chinese "
if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echoc
   read inkey                         
fi
} # CopyTeXfdfpngstyfiles


##### Part17
Configurescfilechitexfdf(){
##### 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,.....

#   chitexconfig -scfile
   chitexconfig -chitex.fdf
   /bin/rm -f chitex*.fdfile
} # Configurescfilechitexfdf


##### Part18
Updatepsfontsmappdftexmap(){
##### Update psfonts.map, pdftex.map And cp cwtex.enc ######

if test -d $texmf/fonts/enc; then
#   cp -f $tmpdir/chitex612/chitex612/data/cwtex.enc $texmf/fonts/enc/dvips/tetex
   cp -f $texmf/dvips/base/cwtex.enc $texmf/fonts/enc/dvips/tetex
#else
#   cp -f $tmpdir/chitex612/chitex612/data/cwtex.enc $texmf/dvips/base
fi   

if test -s $texmf/dvips/config/psfonts.map; then
wafonts=`grep "%Wafonts begin" $texmf/dvips/config/psfonts.map`
wafontsa=`grep "%Wafontsa begin" $texmf/dvips/config/psfonts.map`
wafontsb=`grep "%Wafontsb begin" $texmf/dvips/config/psfonts.map`

$gawkbin '{ntupos=index($0,"ntu"); pfbh=index($0,"_pfb")
   if (ntupos == 0 || pfbh == 0)
      {print $0 > "psfonts@"}
}
' $texmf/dvips/config/psfonts.map

cp -f "psfonts@" $texmf/dvips/config/psfonts.map
rm -f "psfonts@" 

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
if test "$wafontsb" = ""; then
   cat chitex612/data/pfbaddb.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`
wafontsb=`grep "%Wafontsb 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/base/psfonts.map
fi
if test "$wafontsb" = ""; then
   cat chitex612/data/pfbaddb.map >> $texmf/dvips/base/psfonts.map
fi
fi


#$gawkbin '{ntupos=index($0,"ntu"); pfbh=index($0,"_pfb")
#   if (ntupos == 0 || pfbh == 0)
#      {print $0 > "pdftex@"}
#}
#' $texmf/dvips/config/pdftex.map
#
# cp -f "pdftex@" $texmf/dvips/config/pdftex.map
#rm -f "pdftex@" 

#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
#if test "$wafontsb" = ""; then
#  cat chitex612/data/pfbaddb.map >> $texmf/dvips/config/pdftex.map
#fi


#echo "       End of update  psfonts.map, pdftex.map "
if test "$stopask" = "y"; then
   echo $echomode "       Press any key to continue " $echoc
   read inkey
fi
##### end of Update psfonts.map, pdftex.map 
} # Updatepsfontsmappdftexmap



##### Part19
Set600dpi(){
###### set 600dpi for xdvi and dvips 
set600
} # End of Set600dpi


##### Part19.1
InstallLatex2html(){


 inkey="c"
 if test "$inkey" = "c"; then
   gunzip -dc $Curdir/latex2html-2002-2-1.tgz|tar xvf -
   prefix=`which tex|sed 's#/tex##'`
   cd latex2html-2002-2-1
   
   echo "   ************************************************************"
   echo "   *  In the following, Press 'Enter key' to continue.        *"
   echo "   *  After donig this, it will appears an messgae:           *"
   echo "   *            checking dvips version...                     *"   
   echo "   *  Then press 'Enter key' several times to continue        *"
   echo "   ************************************************************"
   echo "   Press Enter key to continue "   
   read xxxxxxx
   cp -f $bindir/dvips $bindir/dvips.old
   cp -f $bindir/dvips.bin $bindir/dvips
   ./configure --prefix=$prefix
   make
   make install
   if test -s $texmf/tex/chinese/l2hconfpm; then
      /bin/rm -f $texmf/tex/chinese/l2hconfpm
   fi
   cp -f $bindir/dvips.old $bindir/dvips
  fi 
}

##### Part20
Modifylyx(){
##### Modify configure of lyx #########
rm -f config@

if test ! -s tmp; then
   mkdir tmp
fi   

cd tmp
clyx=`which clyx`

if test "$clyx" != ""; then   #1st if
echo " "
echo "    Find  .../lyx/lyxrc.defaults                                     #"
echo "    Wait!            "
echo " "

   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 ..

cd $tmpdir

} # End of Modifylyx

##### Part20-2
Update(){
#### Update to have facility of dvipdfm and others ######
./UpdateNow
}

##### Part21
TexhashandRmtmpfiles(){ 
###### Must 'texhash' to take effect for all TeX setting

if test -s $bindir/updmap-sys; then
#   cp -f $texmf/dvips/config/chinese.map $texmf/fonts/map/dvips/tetex
   bsung=`grep "bsung" $texmf/fonts/map/dvips/tetex/ps2pk35.map`   
   if test "$bsung" = ""; then   
   :
#      cat $texmf/dvips/config/chinese2.map >> $texmf/fonts/map/dvips/tetex/ps2pk35.map
   fi   
#   cp -f $texm/fonts/map/dvips/tetex/ps2pk/ps2pk35.map $texm/fonts/map/dvips/tetex/ps2pk/ps2pk.map
#   cp -f $texm/fonts/map/dvips/tetex/ps2pk/ps2pk35.map $texm/dvips/config/ps2pk.map
   
#   bsung=`grep "moes05" $texmf/fonts/map/dvips/tetex/ps2pk35.map`      
#   bsunga=`grep "moes05" $texmf/fonts/map/pdftex/updmap/pdftex.map`

#   if test "$bsung" = ""; then      
#      cat $texmf/fonts/map/dvips/tetex/chinese.map >> $texmf/fonts/map/dvips/tetex/ps2pk35.map  
#   fi    
#   if test "$bsunga" = ""; then      
#      cat $texmf/fonts/map/dvips/tetex/chinese.map >> $texmf/fonts/map/pdftex/updmap/pdftex.map
#   fi    
fi

   cp -f $bindir/xdvi $bindir/xdvi.org
#!/bin/csh      
      /bin/sh rehash
#!/bin/sh            
   
#rehash
texhash

cat $texmf/xdvi/xdvi.cfg > tmp@
$gawkbin '
{ inline=$0
  if (index(inline,"dvipsmap") > 0 && index(inline,"ps2pk.map") > 0)
     {print "dvipsmap ps2pk35.map" > "tmp1@"}
  else   
     {print $0 > "tmp1@"}
} ' tmp@

# echo "after xdvi.cfg"
# read xxxxxx

cp $texmf/xdvi/xdvi.cfg $texmf/xdvi/xdvi.cfg.bak
cp tmp1@ $texmf/xdvi/xdvi.cfg

 TEXMFSYSVAR=`kpsexpand '$TEXMFSYSVAR'`


if test -s $TEXMFSYSVAR/web2c/updmap.cfg; then
cat $TEXMFSYSVAR/web2c/updmap.cfg > tmp@
$gawkbin '
{ inline=$0
  print $0 > "tmp1@" 
}
END{print "Map chinese.map" > "tmp1@" 
print "Map chinese.map" > "tmp1@" 
} ' tmp@
 
cp tmp1@ $TEXMFSYSVAR/web2c/updmap.cfg
rm -f tmp1@ 
fi 

 TEXMFSYSCONFIG=`kpsexpand '$TEXMFSYSCONFIG'` 
 


cat $texmf/web2c/updmap.cfg > tmp@
$gawkbin '
{ inline=$0
  print $0 > "tmp1@" 
}
END{print "Map chinese.map" > "tmp1@" 
print "Map chinese.map" > "tmp1@"
print "Map pdftex.map" > "tmp1@"  
} ' tmp@

if test $TEXMFSYSCONFIG != ""; then 
cat $TEXMFSYSCONFIG/web2c/updmap.cfg > tmp@
$gawkbin '
{ inline=$0
  print $0 > "tmp2@" 
}
END{print "Map chinese.map" > "tmp2@" 
print "Map chinese.map" > "tmp2@" 
print "Map pdftex.map" > "tmp2@" 
} ' tmp@
fi


# echo "after updmap.cfg"
# read xxxxxx

if test ! -s $texmf/web2c/mktexdir.opt; then
   cp -f $SAVEPWD/chitex612/data/mktexdir.opt $texmf/web2c/mktexdir.opt
fi

if test ! -s $texmf/web2c/updmap.cfg.bak; then
  cp $texmf/web2c/updmap.cfg $texmf/web2c/updmap.cfg.bak
fi
  
cp tmp1@ $texmf/web2c/updmap.cfg

cp tmp2@ $TEXMFSYSCONFIG/web2c/updmap.cfg

rm -f tmp1@ tmp2@
#if test -s $bindir/updmap-sys; then
#   updmap-sys
#else
#   updmap
#fi

if test -s $SAVEPWD/utf8@; then
cp -f $SAVEPWD/chitex612/bin/chitex $bindir/chitex.big5
cp -f $SAVEPWD/chitex612/bin/chitex.utf8 $bindir/chitex
cp -f $SAVEPWD/chitex612/bin/chitexorg $bindir/chitexorg.big5
cp -f $SAVEPWD/chitex612/bin/chitexorg.utf8 $bindir/chitexorg
#cp -f $SAVEPWD/chitex612/bin/chitexpsv.utf8 $bindir/chitexpsv
#cp -f $SAVEPWD/chitex612/bin/chitexdvi.utf8 $bindir/chitexdvi
cp -f $SAVEPWD/chitex612/bin/chilatex $bindir/chilatex.big5
cp -f $SAVEPWD/chitex612/bin/chilatex.utf8 $bindir/chilatex
rm -f utf8@
fi

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

cp $texmf/big5.sfd $texmf/Big5.sfd 

/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.*
/bin/rm -f /tmp/tmpdir@

#fi # testmessage
} # End of TexhashandRmtmpfiles(){ 


##### Part22
MakeVARTEXFONTSsubdir(){
##### 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
} # End of MakeVARTEXFONTSsubdir


##### Part23a
GiveMessagea(){
clear
#echo " "
echo "        ° ChiTeX ¹:"
echo "        1. , F:"
echo "           \\uming     % Ķw"
echo "           \\ukai     % Ķ"
#echo "           \\idming   % Їw"
echo "           \\moekai   % "
echo "           \\MING     % Ķw"
echo "           \\IDMING   % Їw Adobe Type1 "
echo "           \\MOEKAI   %  Adobe Type1  "
echo "           \\KAI      %  Adobe Type1 "
echo "           \\FS       %  Adobe Type1 "
echo "           \\LI       % ` Adobe Type1 "
echo "           \\MR       % Aw Adobe Type1 "
echo "           \\WUMING   % w (cwtex) Adobe Type1 "
echo "           \\WUFS     % Ƿ (cwtex) Adobe Type1 "
echo "           \\WUHEI    % Ǻw (cwtex) Adobe Type1 "
echo "           \\songGB   %  (GB ȴa,  ¼)"
echo "           \\kaiGB    %  (GB ȴa,  ¼)"
echo "           \\SONGGB   %  (GB ȴa,  ¼) Adobe Type1 "
echo "           \\KAIGB    %  (GB ȴa,  ¼) Adobe Type1 "
echo "           (Srָ chitex -fonts, ֪)"
echo "        2. ʹ pdftex a pdf n 'BY'  '`'"
echo "           (Ҋ math2_pdftex.tex :ָ chitex -pdftex math2_pdftex "
echo "            ɮa math2_pdftex.pdf ( Acrobat Reader  pdf n))"
echo $echomode "        Press any key to continue"$echocr
read inline
}


##### Part23
GiveMessage(){
############# 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 "        , ° ChiTeX Ҳṩй:"
#echo "        1. ęn֮ TeX/LaTeX ļ"
#echo "        2. ṩµ mymacros.tex  input OԼϲõĭh"
#echo "           ṩµ samp2*.tex Ĝyԇļ"
#echo "        3. _֧Ԯ ʹ chapterbib.sty  bibunits.sty"
#echo "           ṩyԇļ 'W_bibunits.tex', W_chapbib.tex"
#echo "        4.  cmakeindex  ӏ cbibtex ʹ key Ҳ_ sort"
#echo "            \"alpha\"  style  author-year ֮ key Ҳm̎"
echo "        5. _ʹ֪ verbatim ָ"
#echo "        6. Modify \"camsbook.sty\" ʹ \\documentclass{amsbook} r"
#echo "           _ title"
echo "        7. ֧Ԯ pdftex/pdflatex, ÷: chitex -pdftex math2_pdftex"
echo "            math2_pdftex.tex ɺ pdftex ָ֮ļ(ԔҊ README.use* )"
#echo "        8. Could have chinese \"boldface(w)\" and \
# \"outline(п)\","
#echo "           if one use chinese Adobe type1 fonts commands."
#echo "        9. Could have fascinating \"grading color's \
# effects(ɫuЧ)\""
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 ZԮa, ٶNһ(Lļ)"
echo "       11. ṩP cbibtex, cmakeindex ֮ʹõļ"
echo "                     mabibind.tex yԇ"
echo "           (ָ chitex -chitexhelp xxyԇ mabibind.tex)"
#echo "       12. ʹ  Adobe Type1 , Linux c FreeBSD\
# ֮ϵy߿ compile"
#echo "           r Big5  GB a֮ TrueType ήaҪ֮\
# Adobe Type1"
#echo "           (ʹ ttf2pfb). Linux ϵy߿Ԅӌ unicode a֮\
# TrueType"
#echo "           , DQ Big5  GB a֮ TrueType "
#echo "       11. br compile  fmt n, o teTeX 汾"
#echo "           Ҳṩʽ chitexconfig Á configure  ChiTeX h"
#echo "           Ҳ㰲b ChiTeX ,  teTeX 汾, ٸ teTeX "
#echo "           °汾֮, ָ:"
#echo "               chitexconfig -makefmt"
#echo "           ɸ chitex*.fmt  pdfchitex*.fmt ʹ° 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  

        clear
        echo "    "; echo " "
        echo "    b!"        
#        echo "  "
        echo "    chitex µĹܼ׃:"
        echo "  "
        echo "    A. µĹ:"
        echo "      1. Č script, Nٶ"
        echo "      2. chitex  omega/lambda ( Knuth TeX  extension "
        echo "         J. Plaice and Y. Haralambous lչ, ʹ unicode ȴa),"
        echo "         ĲDa, g, Ҫ omega/lambda g, ָ:"
        echo "                  chitex -omega math2.tex"
        echo "      3. chitex ʹ utf-8 ȴaļ(ɾgĮwֵ), Ҫg: "
        echo "                  chitex -utf8 testutf.tex"
        echo "        (testutf.tex  utf-8 ȴa֮ļ( gedit ֮ editor))  "
        echo "      4. unix  update, ؏ chitex ԭO"
        echo "      5. chitex ԄӾϸ(ԃ), ҲքӾϸ"
        echo "    "
        echo "    B. ׃:"
        echo "      bibtex   makeindex   keyname ֻܞӢ"
        echo "      (f keyname, °NٶȸĞcӢĵ"
        echo "       latex һ, ֻܞӢ)"
        echo "      (Ҫf澎g chitexold, chilatexold  chitex, chilatex)"
        echo " "
        echo $echomode "     Press Enter key to continue: " $echocr        
        read xxxxxx
   
 
submenuc (){
clear
echo " "
echo " "
#   echo "        *** б message Ոָ:  message "
#   echo "        b!"
   echo " "
   echo "        Ҫ֪ chitex ָ, ֻҪָ:"
   echo "                   chitex"
#   echo " "
   echo "        κΕr, Ҫ֪ʹ֮Ƚָ, ֻҪָ:"
   echo "               chitex -fonts "
#   echo " "
   echo "        κΕr, Ҫ֪wָ, ֻҪָ:"
   echo "               chitex -fontstyle "
 #  echo " "
   echo "        κΕr, Ҫ \"yԇ TeX ļ\", \"(help)\","
   echo "        \"x README* \", ֻҪָ:"
   echo "               chitex -chitexhelp"
   echo " "
   echo "        F \"xyԇ TeX ļ\", \"\"  \
\"Y\""
   echo " "
   echo "        1. xyԇ TeX ļ"
   echo "        2. (P ChiTeX) "
   echo "        b. صǰ "
   echo "        q. Y"
   echo "     "
   echo $echomode "        Type '1', '2', 'b' or 'q' to choose one of the above: " $echocr
   
   read inkeyc
#   export inkeyc
}

mkdir -p /tmp/temp
submenucno="y"
while test "$submenucno" = "y"
do
   submenuc 
   case "$inkeyc" in
      "1")  cd /tmp/temp; chitexhelp -big5 -test;cd $tmpdir; 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
rm -rf /tmp/temp
}


messageno="y"

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

exit
} # End of GiveMessage


Setenvironment                 # Part1


WelcomeandVerifysupuser        # Part2


FindUnixSystem                 # Part1.1

FindpathofFmtTexmfVartexBinary # Part3


#GiveMessagea                 # Part23a
#GiveMessage                  # Part23


ModifyReadme                 # Part4

#installTeXMaker              # Part5.0

# InstallAcrobatReader         # Part5.1

test=""

if test "$test" = ""; then

ModifyTexmf

cp $tmpdir/latex.fmt $texmf/web2c
cp $tmpdir/tex.fmt $texmf/web2c
cp $tmpdir/pdflatex.fmt $texmf/web2c
if test -s $tmpdir/pdftex.fmt; then
   cp $tmpdir/pdftex.fmt $texmf/web2c
else
   cp $tmpdir/pdfetex.fmt $texmf/web2c
fi   
cp $tmpdir/lambda.fmt $texmf/web2c
cp $tmpdir/omega.fmt $texmf/web2c


MakeChineseFmt               # Part5.2

Copytfmppkttf                # Part6


ModifyConfigps               # Part7
ModifySpecialmap             # Part8
CopyPfbTtftfmfiles           # Part9
Modifyttfontsmap             # Part10
CopySfdAfm                   # Part11
CopyPstfiles                 # Part12
Backupbinaryfiles            # Part13
Copybinaryfiles              # Part14

Compileandcopycfiles         # Part15
CopyTeXfdfpngstyfiles        # Part16
Configurescfilechitexfdf     # Part17
Updatepsfontsmappdftexmap    # Part18
Set600dpi                    # Part19

if test "$Instlatex2html" = "y"; then
   InstallLatex2html            # Part19.1
fi

fi   
#Modifylyx                    # Part20

#cd $tmpdir

$tmpdir/chitex612/UpdateNow  # Part20-2

TexhashandRmtmpfiles         # Part21

if test -s $bindir/updmap-sys; then
   updmap-sys
   updmap
else
   updmap
fi




MakeVARTEXFONTSsubdir        # Part22
#GiveMessagea                 # Part23a
GiveMessage                  # Part23
cd $SAVEPWD

exit

#cd $tmpdir

$tmpdir/chitex612/UpdateNow  # Part20-2

TexhashandRmtmpfiles         # Part21

MakeVARTEXFONTSsubdir        # Part22
#GiveMessagea                 # Part23a
GiveMessage                  # Part23
cd $SAVEPWD

exit

