#!/bin/sh
#
# procedure to install xtem, see "Installation&Maintenance Guide" 
#                                 (file Install.tex) fo details
# call this shell script directly form this directory!
#
# Copyright(C) 1996  G. Lamprecht, W. Lotz, R. Weibezahn; IWD, Bremen University


# check and modify the following lines:

umask 022			; # prevents group/other-write permission
				  # for new files (e.g. at program compilation)

INSTPATH=""			; # normally empty, will then be set to `pwd`
				  # (see below)
				  # must be set if used with "mount NFS"
				  # and using different export and mount pathes

BINPATH="/usr/local/bin"	; # into this directory executeables and shell 
				  # scripts are copied; must be included in 
				  # search path variable $PATH

MANPATH="/usr/local/man/man1"	; # into this directory the man-page 
				  # is to be installed
    
WISHCALL="/usr/local/bin/wishx"	; # command to call wishx 
				  # (must include Tcl, Tk and TclX)

TCLCALL="/usr/local/bin/tcl"	; # command to call tcl 
				  # (pure Tcl, without Tk)

XTERMCALL="xterm -sb -sl 1024 -T xtem -n xtem"
				  # command to create an xterm window
				  # (normally "xterm", maybe "aixterm" 
				  #  under AIX etc.)

LANGUAGES="{german deutsch} {english}"
				  # list of languages and possibly synonyms;
				  # the number of languages is not limited,
				  # each language is enclosed in braces and can 
				  # be followed by any number of synonyms

DEFAULTLANGUAGE="german"	; # specifies the defaultlanguage

CC="gcc"			; # C-compiler for translation of C Programs

CC_OPTS=""			; # options for C-compiler (e.g. "-DAIX")

XiMaxBoxWidth=120		; # maximum box width (characters) 
				  # for (large) select boxes

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

# don't modify the following lines

if [ ! -f "xV.tcl" ]
then echo "error: file \"xV.tcl\" doesn't exist in the current directory!"; exit
fi
grepVersion=`grep "set version " xV.tcl`
XTEMVERSION=`echo $grepVersion | cut -c14-17`

if [ "$INSTPATH" = "" ]
then       path=`pwd`;   cd ..;   INSTPATH=`pwd`;   cd $path
fi

XTEMVPATH="$INSTPATH/xtem-$XTEMVERSION"



# check if file xtem.tcl exists & has correct version number, 
# directory write permissions O.K.
#
error=0
if [ ! -d "$XTEMVPATH" ]
then echo "error: directory \"$XTEMVPATH\" doesn't exist";     error=1
fi
if [ ! -w "$XTEMVPATH" ]
then echo "error: no write permission for \"$XTEMVPATH\"";     error=1
fi
if [ ! -f "$XTEMVPATH/xtem.tcl" ]
then echo "error: file \"$XTEMVPATH/xtem.tcl\" doesn't exist"; error=1
fi
if [ "$error" = "1" ]
then echo; echo "check \"xteminstall\" and Installation Guide!"; echo;   exit
fi
#


# now installation can start
#

echo "start installation in: `pwd`   at: `date`" 	| tee xteminstall.log

echo "First xteminstall looks for changecode, hyphen_show and pages_show." \
							| tee xteminstall.log
echo "(C compilation if necessary)." 			| tee xteminstall.log

#
set `ls -t changecode*`
if [ "$1" != "changecode" ]
then       # changecode doesn't exist or exists and is older than changecode.c
  echo "  compilation of changecode.c" 			| tee xteminstall.log
  $CC $CC_OPTS -o changecode changecode.c
  if [ -f changecode ]; then  chmod a+rx changecode;  fi
fi
#
set `ls -t hyphen_show*`
if [ "$1" != "hyphen_show" ]
then       # hyphen_show doesn't exist or exists and is older than hyphen_show.c
  echo "  compilation of hyphen_show.c"			| tee xteminstall.log
  $CC $CC_OPTS -o hyphen_show hyphen_show.c
  if [ -f hyphen_show ]; then  chmod a+rx hyphen_show;  fi
fi
#
set `ls -t pages_show*`
if [ "$1" != "pages_show" ]
then       # pages_show doesn't exist or exists and is older than pages_show.c
  echo "  compilation of pages_show.c" 			| tee xteminstall.log
  $CC $CC_OPTS -o pages_show pages_show.c
  if [ -f pages_show ]; then  chmod a+rx pages_show;  fi
fi

echo 							| tee xteminstall.log
echo "Now installation window is called; if window doesn't come up:" \
							| tee xteminstall.log
echo "    set DISPLAY variable etc. or look at file xteminstall" \
							| tee xteminstall.log
echo "    (variable WISHCALL set correctly?), see \"Installation Guide\"." \
							| tee xteminstall.log
echo "***********************************************************" \
							| tee xteminstall.log
echo exec $WISHCALL -f $XTEMVPATH/xi.tcl -n xtem_installation \
	 "$INSTPATH" "$BINPATH" "$MANPATH" "$WISHCALL" "$TCLCALL" "$XTERMCALL" \
	 "$XTEMVERSION" "$LANGUAGES" "$DEFAULTLANGUAGE" "$XiMaxBoxWidth" \
							| tee xteminstall.log
echo "***********************************************************" \
							| tee xteminstall.log
echo "transcript written to xteminstall.log"
exec $WISHCALL -f $XTEMVPATH/xi.tcl -n xtem_installation \
	 "$INSTPATH" "$BINPATH" "$MANPATH" "$WISHCALL" "$TCLCALL" "$XTERMCALL" \
	 "$XTEMVERSION" "$LANGUAGES" "$DEFAULTLANGUAGE" "$XiMaxBoxWidth" \
	>> xteminstall.log
################################################################################
