;       $VER: Installation TPP V4.10E (17.01.93)

.BRA {
.KET }

; default root directory

Set DefaultDir "work:tpp"

; set some internal flags
Set ARexxIsInstalled Yes
Set PaxTeXIsInstalled Yes
Set MakeIndexIsInstalled Yes
Set Update No
Set LHAbin "c/LHA -q -m -a x"
Set LangArc TPPEnglish.lha
Set GlobArc TPPGlobal.lha

Lab Start

; get the root directory of `TeXt Plus Professional'

Echo "TeXt Plus Professional V4.10*n"

Echo "If this is an update from 4.00 to 4.10,"
Echo "*.Config and *.parse files are not"
Echo "overwritten.*n"

Echo "Please, enter a name for the TeXt"
Echo "Plus Professional root-directory."
Echo "Directory (<Return> = $DefaultDir) ? " NoLine

; unset previous value

UnSet Directory

; get target directory

Set >NIL: Directory ?

; If only <Return> has been pressed, use <DefaultDir>

If "$Directory" EQ "*$Directory"
        Set Directory $DefaultDir
EndIf

; remember the original path

Set OrigDir $Directory

; check wether a '/' is to be appended to the directory name

FailAt 21

Assign >NIL: ${Directory} Exists

If FAIL
    FailAt 10

    ; directory already exists

    If NOT EXISTS $Directory
        FailAt 21

        ; okay, try to make the directory

        MakeDir "$Directory"

        ; Das war nichts ...

        If FAIL
            Echo "*NUnable to make $Directory"

            FailAt 10

            ; back where we started

            Skip Back Start
        EndIf
    EndIf

    ; append a '/' to the directory-name

    Set Temp "$Directory/"

    Set Directory $Temp

    UnSet Temp
EndIf

; Fist all english programs are installed

; unpack main binaries

$LHAbin $LangArc bin/TeXtPlusProfessional(.info|%) "${Directory}"

; unpack documentation

$LHAbin $LangArc doc/#? "${Directory}"

Set DocDefaultDir "S:"

Lab DocStart

; Where to place 'TPP.guide'?

Echo "*NPlease, enter the directory-name, where"
Echo "the HyperText-documentation is to be installed to."
Echo "Directory (<Return> = $DocDefaultDir) ? " NoLine

; unset previously set value

UnSet DocDirectory

; get target directory

Set >NIL: DocDirectory ?

; if only <Return> has been pressed, use <DocDefaultDir>

If "$DocDirectory" EQ "*$DocDirectory"
        Set DocDirectory $DocDefaultDir
EndIf

; check wether a '/' is to be appended to the directory name

FailAt 21

Assign >NIL: ${DocDirectory} Exists

If FAIL
    FailAt 10

    ; directory already exists?

    If NOT EXISTS $DocDirectory
        FailAt 21

        ; okay, try to make a directory

        MakeDir "$DocDirectory"

        ; failed

        If FAIL
            Echo "*NUnable to make $DocDirectory"

            FailAt 10

            ; back where be started

            Skip Back DocStart
        EndIf
    EndIf
EndIf

; copy hypertext documentation
Copy ${Directory}doc/TPP.guide(.info|%) $DocDirectory Quiet Clone
; and delete
Delete >NIL: ${Directory}doc/TPP.guide(.info|%)

; copy handler
$LHAbin $LangArc l/TeXtPlus-Handler L:

; install configuration files
; save old configration files
If $Update EQ Yes
    If Exists ${Directory}config
        Rename >NIL: ${Directory}config ${Directory}config.old
    Endif
Endif

; install
$LHAbin $LangArc config/#? ${Directory}

; ------------------------------------------------------------

; install all global files

; save old parse files
If $Update EQ Yes
    If Exists ${Directory}parse
        Rename >NIL: ${Directory}parse ${Directory}parse.old
    Endif
Endif

; decrunch everything
$LHAbin $GlobArc #? ${Directory}

; copy the readme file
Copy ReadMe(.info|%) ${Directory}doc Quiet Clone

; copy the history file
Copy History(.info|%) ${Directory}doc Quiet Clone

; Copy Nico Fran�ois' powerpacker.library (35.344) and
; reqtools.library (38.961)
; They are only installed if no newer version is
; already installed

FailAt 21

Version >NIL: reqtools.library 38 961
If Warn
    Copy ${Directory}libs/reqtools.library libs: Quiet Clone
endif

Version >NIL: powerpacker.library 35 344
If Warn
    Copy ${Directory}libs/powerpacker.library libs: Quiet Clone
endif

; and clean up
Delete >NIL: ${Directory}libs All

; is there a 'rexx:'-directory

If NOT EXISTS REXX:

    ; unfortunately not

    Echo "*NThere is no REXX:-directory!"
    Echo "The ARexx-macros are not going to be installed."
    Echo "If you nevertheless want to install them, you"
    Echo "have to invoke this script for a second time,"
    Echo "AFTER you have installed ARexx!"
    Echo "Working with TPP without ARexx is not sensible!"

    Set ARexxIsInstalled No

EndIf

; not everybody gets macros ...

If NOT $ARexxIsInstalled EQ No

    ; copy the arexx macros
    Copy ${Directory}rexx/tpl rexx:tpl All Quiet Clone
    Copy ${Directory}rexx/#?.tpl rexx: All Quiet Clone
    Copy ${Directory}rexx/#?.sd rexx: All Quiet Clone

    ; and clean up
    Delete >NIL: ${Directory}rexx All

EndIf

; Is PaxTeX installed?

IF NOT EXISTS TeX:macros

    ; unfortunately not

    Echo "*NThere is no directory 'TeX:macros'!"
    Echo "The TeX-macros are not going to be installed."
    Echo "If you nevertheless want to install them, you"
    Echo "have to invoke this script for a second time,"
    Echo "AFTER you have installed PasTeX!"
    Echo "You cannot compile or print documents without"
    Echo "the TeX-macros!"

    Set PasTeXIsInstalled No

EndIf

; Without TeX we are lost

If NOT $PasTeXIsInstalled EQ No

    ; copy the tex-macros
    Copy ${Directory}tex/macros TeX:macros All Quiet Clone

    ; and clean up
    Delete >NIL: ${Directory}tex/macros All

EndIf

; Can MakeIndex be installed?

IF NOT EXISTS TeX:bin

    ; unfortunately not

    Echo "*NThere is no directory 'TeX:bin'!"
    Echo "MakeIndex is not installed."
    Echo "If you nevertheless want to install it, you"
    Echo "have to invoke this script for a second time,"
    Echo "AFTER you have installed PasTeX!"
    Echo "You create a sorted index without MakeIndex!*n"

    Set MakeIndexIsInstalled No

EndIf

; lost again?

If NOT $MakeIndexIsInstalled EQ No

    ; copy MakeIndex
    Copy ${Directory}tex/bin/#? TeX:bin All Quiet Clone

    ; and clean up
    Delete >NIL: ${Directory}tex/bin All

EndIf

; this is the end of the script as I know it ...

Echo "*NTeXt Plus Professional has been installed."
Echo "You only have to add the following line"
Echo "to your S:Startup-Sequence or S:User-Startup:"

Echo "*NAssign TPP: $OrigDir"

; bitch a bit
IF $ARexxIsInstalled EQ No

Echo "*NDo not forget to install the ARexx macros!"

EndIf

IF $PasTeXIsInstalled EQ No

Echo "*NDo not forget to install the PasTeX macros!"

EndIf

IF $MakeIndexIsInstalled EQ No

Echo "*NDo not forget to install MakeIndex!"

EndIf

; execute the assign for prophylactical reasons
Assign >NIL: TPP: "$OrigDir"

Echo "*NEnjoy TeXt Plus Professional!"