;---------------------------------------------------------------------
;Install-pi script ------ version 1.05 ------- written for the 2.04 OS
;---------------------------------------------------------------------
;Written by Ben Williams - January 23rd, 1992
;           Last updated - April 29th, 1992
;
;This exec file installs the Public Interface Executive for
;Black Belt Systems' image processing tools.
;
;Pre-existing Requirements:
;--------------------------
;1 - ARexx must be installed; 2.04 comes with ARexx installed normally
;    so this shouldn't be a problem
;
;2 - There must be room to hold the new commands (1 meg or so)
;    If you don't have enough room, the script will fail
;
;3 - The rename, delete, cd and copy commands must be in the user's PATH
;    We use these to complete the operations in the script
;
;4 - There must be sufficient ram available (also about 1 meg)
;    The files are temporarily held in ram:
;
;5 - REXX: and C: must be assigned to somewhere on a hard disk with 1M free.
;    This is the 2.04 system default; although some *idiot* at CBM made
;    the "s:" directory the rexx: directory
;
;The archive contains:
;---------------------
; - A number of PI .rexx scripts
; - A number of PI command components
; - The list.list text file
; - The picmdpath text file
; - The Launch.rexx script
; - The Default.ipmcr macro startup file
; - The Default.immcr macro startup file
; - The Default.iimcr macro startup file
;
;Operations Performed by this script:
;------------------------------------
; - A temporary directory called "ram:pitdir" is created
; - The permanent directories c:cmpi and rexx:rxpi are created IF they
;   don't already exist and RXPI and CMPI don't already exist
; - Volatile assignments CMPI: and RXPI: are made to these directories unless
;   they were already made
; - The launch.rexx script and the text file "picmdpath" are copied to REXX:
; - The small textfile "list.list" is copied to CMPI:
; - A number of ARexx scripts are copied to RXPI:
; - A number of command components are copied to CMPI:
; - New default files for the image processors are copied to s:
; - The temporary directory in ram is removed
;
;Remaining jobs for the user to do:
;----------------------------------
;add these two lines to their s:user-startup file:
;
;   assign RXPI: rexx:rxpi
;   assign CMPI: c:cmpi
;---------------------------------------------------------------------

;-----------------------------------------
;Check that everything we need is in place
;-----------------------------------------
assign >nil: exists REXX:
If WARN
  Echo "ARexx REXX: assignment not found - Cannot install!"
  Quit
  endif

assign >nil: exists c:
If WARN
  Echo "System C: assignment not found - Cannot install!"
  Quit
  Endif

assign >nil: exists s:
If WARN
  Echo "System S: assignment not found - Cannot install!"
  Quit
  Endif

If NOT EXISTS ram:piarc.lzh
  Echo "RAM:PIARC.LZH file not found - Cannot install!"
  Quit
  Endif

If NOT EXISTS ram:extract
  Echo "RAM:EXTRACT file not found - Cannot install!"
  Quit
  Endif

If NOT EXISTS ram:VolFree
  Echo "RAM:VOLFREE file not found - Cannot install!"
  Quit
  Endif

If NOT EXISTS ram:RamFree
  Echo "RAM:RAMFREE file not found - Cannot install!"
  Quit
  Endif

;--------------------------------------------------
;Make sure user has enough memory for us to operate
;--------------------------------------------------
RamFree total 1000000
If WARN
  Echo "Not enough memory to run install! We need a megabyte to do the"
  Echo "installation, which we will return to the system afterwards."
  Quit
  EndIf

;-------------------------------------------------------
;Check disk(s) to see if we have enough space to install
;-------------------------------------------------------
assign >nil: exists CMPI:
If WARN
  VolFree c: 1000000
  If WARN
    Echo "Not enough disk space on Volume where ``c:'' is located"
    Echo "We need about a megabyte of free disk space there."
    Quit
    EndIf
  EndIf

assign >nil: exists RXPI:
If WARN
  VolFree rexx: 100000
  If WARN
    Echo "Not enough disk space on Volume where ``rexx:'' is located"
    Echo "We need about 100k bytes of free disk space there."
    Quit
    EndIf
  EndIf

VolFree s: 15000
If WARN
  Echo "Not enough disk space on Volume where ``s:'' is located"
  Echo "We need about 15k bytes of free disk space there."
  Quit
  EndIf

;-------------------------------------------------
;Create the temporary directory from which to copy
;-------------------------------------------------
If NOT EXISTS ram:pitdir
  makedir ram:pitdir
Else
  delete ram:pitdir/#? all quiet
  Endif

;------------------------------------------
;Attempt to make the directories we'll need
;unless user has already specified these
;somehow (a techie might do this to us)
;------------------------------------------
assign >nil: exists CMPI:
If WARN
  If NOT EXISTS c:cmpi
    makedir c:cmpi
    Endif
  assign CMPI: c:cmpi
  Endif

assign >nil: exists RXPI:
If WARN
  If NOT EXISTS rexx:rxpi
    makedir rexx:rxpi
    Endif
  assign RXPI: rexx:rxpi
  Endif

;----------------------------
;Recover the files we'll need
;----------------------------
cd ram:pitdir
copy c:delete to ram:pitdir
copy c:copy to ram:pitdir
copy c:rename to ram:pitdir
ram:extract e ram:piarc

;---------------------------------------------
;Save the user's old macro files if they exist
;---------------------------------------------
If EXISTS s:Default.immcr.old
  ram:pitdir/Delete s:Default.immcr.old
  endif
If EXISTS s:Default.immcr
  ram:pitdir/rename s:Default.immcr s:Default.immcr.old
  endif

If EXISTS s:Default.iimcr.old
  ram:pitdir/Delete s:Default.iimcr.old
  endif
If EXISTS s:Default.iimcr
  ram:pitdir/rename s:Default.iimcr s:Default.iimcr.old
  endif

If EXISTS s:Default.ipmcr.old
  ram:pitdir/Delete s:Default.ipmcr.old
  endif
If EXISTS s:Default.ipmcr
  ram:pitdir/rename s:Default.ipmcr s:Default.ipmcr.old
  endif

;-----------------------------
;Copy the special files first:
;-----------------------------
ram:pitdir/copy list.list to CMPI:
ram:pitdir/copy picmdpath to REXX:
ram:pitdir/copy launch.rexx to REXX:
ram:pitdir/copy Default.ipmcr to s:
ram:pitdir/copy Default.iimcr to s:
ram:pitdir/copy Default.immcr to s:
ram:pitdir/Delete launch.rexx list.list picmdpath Default.#?mcr QUIET

;-------------------------------------
;Copy the PI Module ARexx scripts next
;-------------------------------------
ram:pitdir/copy #?.rexx to RXPI:
ram:pitdir/Delete #?.rexx QUIET

;---------------------------------
;Copy all the command modules next
;---------------------------------
ram:pitdir/copy #? to CMPI:
ram:pitdir/Delete CMPI:Delete CMPI:Copy CMPI:Rename QUIET

;-----------------------------------------------
;If old rdjpg or wrjpg commands exist, kill them
;-----------------------------------------------
If EXISTS CMPI:rdjpg
  ram:pitdir/Delete CMPI:rdjpg
  EndIf

If EXISTS CMPI:wrjpg
  ram:pitdir/Delete CMPI:wrjpg
  EndIf

;----------------------------------------------------
;Find out if the user has a 68020 or better processor
;----------------------------------------------------
ask "Do you have a 68020, 68030 or 68040 (Y/N)?"
if WARN
  echo "Installing specially compiled commands for fast CPUs"
  ram:pitdir/rename CMPI:x_JPR030 CMPI:rdjpg
  ram:pitdir/rename CMPI:x_JPW030 CMPI:wrjpg
else
  echo "Installing standard commands"
  ram:pitdir/rename CMPI:x_JPR000 CMPI:rdjpg
  ram:pitdir/rename CMPI:x_JPW000 CMPI:wrjpg
endif

;------------------------------------------------------------------
;Remove all potential commands, we've already picked what we needed
;------------------------------------------------------------------
ram:pitdir/Delete CMPI:x_#? QUIET

;-----------------
;Finally, Clean up
;-----------------
cd ram:
ram:pitdir/Delete ram:extract QUIET
ram:pitdir/Delete ram:VolFree QUIET
ram:pitdir/Delete ram:RamFree QUIET
ram:pitdir/Delete ram:piarc.lzh QUIET
Delete ram:pitdir ALL QUIET

;All Done!
;---------
echo "Installation completed. Have fun!"
