.KEY dest,help/s
.BRA {
.KET }

; :ts=3
; HDInstall - Install Page onto a hard drive.
;
; Inputs:
;    dest   Directory to install Page into
;    help   Print instructions
;

;
; Some preliminary setup.
;
ASSIGN PSInstUtil: PSUtil:    ; Hook we can use when disk has been removed
ASSIGN PSInstOrig: ""         ; Save initial directory

; Make sure he's running WB 1.3!
; Under 1.3, the "1 gt 2" test fails; we proceed to "FAILAT 10".
; Under 1.2, however, the IF command itself dies, since GT is not defined;
; execution is not suspended, and the ECHO and SKIP are seen.
FAILAT 21
IF >NIL: 1 gt 2
	ECHO "*NVersion 1.3 of the Amiga Workbench software *E[;1mmust*E[m be"
	ECHO "present before this installation can proceed.*N"
   SKIP wrapup
ENDIF
FAILAT 10

; Start with a fresh copy, to avoid any screwups
IF EXISTS RAM:PSInstall
   DELETE RAM:PSInstall/#? quiet
ELSE
   MAKEDIR RAM:PSInstall
ENDIF


C:COPY		   C:Copy	  RAM:PSInstall
RAM:PSInstall/Copy C:Assign	  RAM:PSInstall
RAM:PSInstall/Copy C:Echo	  RAM:PSInstall
RAM:PSInstall/Copy C:FailAt	  RAM:PSInstall
RAM:PSInstall/Copy C:If 	  RAM:PSInstall
RAM:PSInstall/Copy C:Else	  RAM:PSInstall
RAM:PSInstall/Copy C:Endif	  RAM:PSInstall
RAM:PSInstall/Copy C:Makedir	  RAM:PSInstall
RAM:PSInstall/Copy C:Execute	  RAM:PSInstall
CD ram:PSInstall	      ; Search it without adding it to path

COPY PSInstUtil:misc/DiskMount	  RAM:PSInstall
COPY PSInstUtil:misc/InstUtil	  RAM:PSInstall
COPY PSInstUtil:Misc/Install-Proc RAM:PSInstall

Assign PSInstPgm:	      ; Make sure these start fresh, too.

;
; Make sure needed system assignments exist.
;
INSTUTIL isdir T:
IF WARN
   INSTUTIL isdir RAM:T
   IF WARN
      MAKEDIR ram:T
   ENDIF
   ASSIGN T: ram:T
ENDIF

INSTUTIL isdir ENV:
IF WARN
   INSTUTIL isdir RAM:ENV
   IF WARN
      MAKEDIR ram:ENV
   ENDIF
   ASSIGN ENV: ram:ENV
ENDIF


;
; HELP processing
;
IF "{help}" eq "HELP"
   SKIP showme
ENDIF

INSTUTIL ask -dy "Do you need instructions [Y/N]? Y"
IF WARN
   SKIP noshow
ENDIF

LAB showme
;   EXECUTE RAM:PSInstall/DiskMount Program Page: PSInstPgm:
   PSInstUtil:showme PSInstUtil:Misc/HELP-Install
LAB noshow


;
; Make sure that the destination exists, that its name is
; in a useable form (ie. that it ends with a '/' if it's a directory),
; and that the user in fact wants to install into it.
;
IF NOT EXISTS {dest$SYS:}
   ECHO "*N ********** Couldn't find Hard Disk drawer {dest$SYS:} **********"
   SKIP forhelp
ENDIF

INSTUTIL isdir {dest$SYS:}
IF WARN
   CD RAM:PSInstall
   ECHO "*N ********** {dest$SYS:} is not a drawer! **********"
LAB forhelp
   ECHO "*N For help, type"
   ECHO "      EXECUTE PSUtil:Misc/HDInstall help"
   ECHO "*N or double-click on the *"Help*" icon in this drawer*N"
   SKIP wrapup
ENDIF
CD RAM:PSInstall

ECHO "*N Answering *"No*" to the following question will cancel"
ECHO " the installation.  Your hard drive will not be changed.*N"
INSTUTIL ask -dy "Install Page onto {dest$SYS:} [Y/N]? Y"
IF warn
   ECHO " Installation aborted!*N"
   SKIP wrapup
ENDIF

ECHO >ram:PSInstall/DestPath1 "{dest$SYS:}"
INSTUTIL <ram:PSInstall/DestPath1 >ram:PSInstall/DestPath2 fixdir


ECHO "*N*N ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*N"
ECHO " Begin installation of Page onto {dest$SYS:}*N"

EXECUTE <ram:PSInstall/DestPath2 >nil: ram:PSInstall/Install-Proc ?

ECHO "*N*N --------------------------------------------------------------------"
ECHO "  Please add the following command to the file s:Startup-sequence:"
ECHO "*N    Execute s:Page-Startup"
ECHO "*N    or"
ECHO "*N    Double Click on the `PageAssigns' icon"
ECHO "    before you run Page"

ECHO "*N --------------------------------------------------------------------"
ECHO "*N*N Installation of Page complete."
ECHO "*N Please remove all Page floppy disks from the drives."
ECHO "*N ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*N"

;
; Clean up after ourselves
; Can't depend on anything but PSInstOrig: and PSInstUtil:,
; since we can come here from right after their definition.
;
LAB wrapup

CD PSInstOrig:
Assign PSInstOrig:
Assign PSInstPgm:
DELETE >NIL: RAM:PSInstall all quiet

PSInstUtil:Misc/InstUtil ask "Press RETURN."
Assign PSInstUtil:
