;$VER: Squirrel SCSI 1.11 (26.3.95)

;;-
;;- $Id: SCSI-Install,v 1.11 1995/03/26 15:13:04 alex Rel $
;;-
;;- Squirrel SCSI Installation Script
;;-
;;- Copyright © 1994, 1995 HiSoft. All Rights Reserved.
;;-

;;-
;;- Selectors for the installation options
;;-
(set kCOMPONENTSCSI 0)
(set kCOMPONENTCD 1)
(set kCOMPONENTCD32DISK 2)
(set kCOMPONENTCDONLYDISK 3)
(set kCOMPONENTHDDISK 4)
(set kCOMPONENTWBCOPY 5)

;;-
;;- Library routines
;;-

;;-
;;- SetDrive - select additional drive for use during installation
;;-
;;- Inputs:
;;-		None
;;-
;;- Outputs:
;;-		DRIVE - drive number of extra drive
;;-
(procedure SetDrive
	(user 2)
	(set DEFAULTDRIVE 0)
	(set df0 (getassign "DF0" "d"))
	(set df1 (getassign "DF1" "d"))
	(set df2 (getassign "DF2" "d"))
	(set df3 (getassign "DF3" "d"))

	(if (= df0 SOURCEPATH) ( (set DEFAULTDRIVE "DF0:") (set df0 "")))
	(if (= df1 SOURCEPATH) ( (set DEFAULTDRIVE "DF1:") (set df1 "")))
	(if (= df2 SOURCEPATH) ( (set DEFAULTDRIVE "DF2:") (set df2 "")))
	(if (= df3 SOURCEPATH) ( (set DEFAULTDRIVE "DF3:") (set df3 "")))

	(set NDRIVES 0)
	(if (<> df0 "")
		(	(select NDRIVES
				(set d0 "DF0:")
				(set d1 "DF0:")
				(set d2 "DF0:")
				(set d3 "DF0:")
			)
			(set NDRIVES (+ NDRIVES 1))
		)
	)
	(if (<> df1 "")
		(	(select NDRIVES
				(set d0 "DF1:")
				(set d1 "DF1:")
				(set d2 "DF1:")
				(set d3 "DF1:")
			)
			(set NDRIVES (+ NDRIVES 1))
		)
	)
	(if (<> df2 "")
		(	(select NDRIVES
				(set d0 "DF2:")
				(set d1 "DF2:")
				(set d2 "DF2:")
				(set d3 "DF2:")
			)
			(set NDRIVES (+ NDRIVES 1))
		)
	)
	(if (<> df3 "")
		(	(select NDRIVES
				(set d0 "DF3:")
				(set d1 "DF3:")
				(set d2 "DF3:")
				(set d3 "DF3:")
			)
			(set NDRIVES (+ NDRIVES 1))
		)
	)

	(set XDPROMPT "Select the floppy drive to use during installation and formatting")
	(select
		(select NDRIVES
			(+ 4)
			(askchoice (prompt XDPROMPT) (help @askchoice-help) (choices d0))
			(askchoice (prompt XDPROMPT) (help @askchoice-help) (choices d0 d1))
			(askchoice (prompt XDPROMPT) (help @askchoice-help) (choices d0 d1 d2))
			(askchoice (prompt XDPROMPT) (help @askchoice-help) (choices d0 d1 d2 d3))
		)
		(set DRIVE d0)
		(set DRIVE d1)
		(set DRIVE d2)
		(set DRIVE d3)
		(set DRIVE DEFAULTDRIVE)
	)
	(user DEFAULT-USER)
)

;;-
;;- Walk - traverse directories performing an action on all files
;;-
;;- Inputs:
;;-		WALKACTION:
;;-			0 => delete target files encountered
;;-			1 => perform swapcolors on files
;;-			2 => copylib file
;;-		WALKROOT: initial directory (including trailing slash/colon)
;;-		WALKPAT: required matching pattern
;;-		WALKPROMPT: prompt to use (if required)
;;-		WALKDEST: destination location
;;- Outputs:
;;-		None
;;-
(procedure Walk
	(procedure WalkDown
		(select WALKACTION
			("")
			(tooltype
				(dest CURRENTNAME)
				(swapcolors)
			)
			(copylib
				(source CURRENTNAME)
				(dest (tackon WALKDEST CURRENTDRAWER))
				(optional "askuser")
				(infos)
				(confirm)
				(prompt (WALKPROMPT @each-name))
				(help @copylib-help)
			)
		)
	)
	(procedure WalkUp
		(select WALKACTION
			(delete CURRENTNAME
				(optional "force")
				(safe)
			)
			("")
			("")
		)
	)
	(set EN0 WALKROOT)
	(set EP0 "")
	(set ED0 "")
	(foreach EN0 WALKPAT
		(	(set EP1 (cat EP0 @each-name))
			(set EN1 (cat EN0 @each-name))
			(set CURRENTPATH EP1)
			(set CURRENTNAME EN1)
			(set CURRENTDRAWER ED0)
			(WalkDown)
			(if (>= @each-type 0)
				(	(set ED1 (cat ED0 @each-name))
					(foreach EN1 WALKPAT
						(	(set EP2 (cat EP1 "/" @each-name))
							(set EN2 (cat EN1 "/" @each-name))
							(set CURRENTPATH EP2)
							(set CURRENTNAME EN2)
							(set CURRENTDRAWER ED1)
							(WalkDown)
							(if (>= @each-type 0)
								(	(set ED2 (cat ED1 "/" @each-name))
									(foreach EN2 WALKPAT
										(	(set EP3 (cat EP2 "/" @each-name))
											(set EN3 (cat EN2 "/" @each-name))
											(set CURRENTPATH EP3)
											(set CURRENTNAME EN3)
											(set CURRENTDRAWER ED2)
											(WalkDown)
											(if (>= @each-type 0)
												(	(set ED3 (cat ED2 "/" @each-name))
													(foreach EN3 WALKPAT
														(	(set EP4 (cat EP3 "/" @each-name))
															(set EN4 (cat EN3 "/" @each-name))
															(set CURRENTPATH EP4)
															(set CURRENTNAME EN4)
															(set CURRENTDRAWER ED3)
															(WalkDown)
															(if (>= @each-type 0)
																(	(set ED4 (cat ED3 "/" @each-name))
																	(foreach EN4 WALKPAT
																		(	(set EP5 (cat EP4 "/" @each-name))
																			(set EN5 (cat EN4 "/" @each-name))
																			(set CURRENTPATH EP5)
																			(set CURRENTNAME EN5)
																			(set CURRENTDRAWER ED4)
																			(WalkDown)
																			(set CURRENTPATH EP5)
																			(set CURRENTNAME EN5)
																			(set CURRENTDRAWER ED4)
																			(WalkUp)
																		)
																	)
																)
															)
															(set CURRENTPATH EP4)
															(set CURRENTNAME EN4)
															(set CURRENTDRAWER ED3)
															(WalkUp)
														)
													)
												)
											)
											(set CURRENTPATH EP3)
											(set CURRENTNAME EN3)
											(set CURRENTDRAWER ED2)
											(WalkUp)
										)
									)
								)
							)
							(set CURRENTPATH EP2)
							(set CURRENTNAME EN2)
							(set CURRENTDRAWER ED1)
							(WalkUp)
						)
					)
				)
			)
			(set CURRENTPATH EP1)
			(set CURRENTNAME EN1)
			(set CURRENTDRAWER ED0)
			(WalkUp)
		)
	)
)

;;-
;;- UpdateSetPatch
;;-		Update C:SetPatch to the latest version
;;-
;;- Inputs:
;;-		SOURCEPATH: Path to SetPatch directory
;;- Outputs:
;;-		None
;;-
(procedure UpdateSetPatch
	(set uspSETPATCH37REVISION 39)
	(set uspSETPATCH40REVISION 16)
	(set uspSOURCE "")
	(if (>= (/ (getversion "LIBS:version.library") 65536) 37)
		(if (>= (/ (getversion "C:IPrefs") 65536) 38)
			(set uspSOURCE ("Updates/SetPatch_40.%ld" uspSETPATCH40REVISION))
		)
		(set uspSOURCE ("Updates/SetPatch_37.%ld" uspSETPATCH37REVISION))
	)
	(if (strlen uspSOURCE)
		(copylib
			(source uspSOURCE)
			(dest "SYS:C")
			(newname "SetPatch")
			(confirm)
			(prompt "Update \"C:SetPatch\"?")
			(help @copylib-help)
		)
	)
)

;;-
;;- SetNVLocation
;;-		Set up location for nonvolatile storage
;;-
;;- Inputs:
;;-		None
;;- Outputs:
;;-		snvlDRAWERPATH
;;-
(procedure SetNVLocation
	(set snvlDRAWERPATH
		(tackon
			(askdir
				(prompt "Select the location for the \"nonvolatile\" Drawer")
				(help
					(cat "When running CD32 titles which wish to save the state of the title "
						"(high scores, progress, state of play etc.) a directory containing "
						"the information is used, rather than the non-volatile RAM on a CD32. "
						"You should choose a drawer in which you wish to create the "
						"\"nonvolatile\" drawer, where all the files used by the CD32 titles "
						"will be placed.\n\n"
						@askdir-help
					)
				)
				(default "SYS:")
			)
			"nonvolatile"
		)
	)
)

;;-
;;- UnconditionalSystemUpdates:
;;-		Perform system updates which are independent of what is being
;;-		installed
;;-
;;- Inputs:
;;-		None
;;- Outputs:
;;-		None
;;-
(procedure UnconditionalSystemUpdates
	(if (= (exists "SYS:Utilities/Installer") 0)
		(copyfiles
			(source "Utilities/Installer")
			(dest "SYS:Utilities")
		)
	)
)

;;-
;;- CreateDevsDrawers
;;-		Create Devs drawers if missing (Devs, DOSDrivers & Storage)
;;-
;;- Inputs:
;;-		None
;;- Outputs:
;;-		None
;;-
;;-
(procedure CreateDevsDrawers
	(makedir "SYS:Devs" (infos))
	(if (not (exists "SYS:Devs.info"))
		(copyfiles
			(source "WB-3/Devs.info")
			(dest "SYS:")
		)
	)
	(makedir "SYS:Devs/DOSDrivers" (infos))
	(if (not (exists "SYS:Devs/DOSDrivers.info"))
		(copyfiles
			(source "WB-3/Devs/DOSDrivers.info")
			(dest "SYS:Devs")
		)
	)
	(makedir "SYS:Storage" (infos))
	(if (not (exists "SYS:Storage.info"))
		(copyfiles
			(source "WB-3/Devs.info")
			(dest "SYS:")
			(newname "Storage.info")
		)
	)
	(makedir "SYS:Storage/DOSDrivers" (infos))
	(if (not (exists "SYS:Storage/DOSDrivers.info"))
		(copyfiles
			(source "WB-3/Devs/DOSDrivers.info")
			(dest "SYS:Devs")
			(newname "DOSDrivers.info")
		)
	)
)

;;-
;;- Gestalt - generate system configuration information
;;-
;;- Inputs:
;;-		None
;;-
;;- Outputs:
;;-		PROCESSOR - 0=>68000/68010, 1=>68020/68030/68040/68060
;;-		SOURCEPATH - path name of installation disk (w/ :)
;;-		SOURCEVOLUME - path name of installation disk (w/o :)
;;-		SYSPATH - full path name of SYS: (w/ :)
;;-
(procedure Gestalt
	(if (or (= (database "cpu") "68000") (= (database "cpu") "68010"))
		(set PROCESSOR 0)
		(set PROCESSOR 1)
	)

	(set SOURCEPATH (expandpath (pathonly @icon)))
	(set SOURCEPATH (pathonly (pathonly SOURCEPATH)))
	(set SOURCEVOLUME (substr SOURCEPATH 0 (- (strlen SOURCEPATH) 1)))

	(set SYSPATH (expandpath "SYS:"))
	(set SYSPATH (pathonly (pathonly SYSPATH)))
)

;;-
;;- StashOldFiles:
;;-		Move old files which should not be overwritten
;;-
;;- Inputs:
;;-		None
;;- Outputs:
;;-		None
;;-
(procedure StashOldFiles
	(set sofS-STARTUP-SEQUENCE "SYS:S/Startup-Sequence")
	(set sofDEVS-CD0 "SYS:Devs/DOSDrivers/CD0")
	(set sofSTORAGE-CD0 "SYS:Storage/DOSDrivers/CD0")
	(set sofOLDFILES "")
	(if (in COMPONENTS kCOMPONENTCD)
		(if (exists sofS-STARTUP-SEQUENCE)
			(set sofOLDFILES (cat sofOLDFILES sofS-STARTUP-SEQUENCE "\n"))
		)
	)
	(if (exists sofDEVS-CD0)
		(set sofOLDFILES (cat sofOLDFILES sofDEVS-CD0 "\n"))
	)
	(if (exists sofSTORAGE-CD0)
		(set sofOLDFILES (cat sofOLDFILES sofSTORAGE-CD0 "\n"))
	)
	(if (strlen sofOLDFILES)
		(if
			(askbool
				(prompt	"\n\nShould the following files be moved to the \"SYS:OLD\" drawer?\n\n"
					sofOLDFILES)
				(help "Installation of the Squirrel SCSI software updates several system "
					"files. If you have made changes to these that might be lost during the "
					"installation process they will be moved to the \"SYS:OLD\" drawer "
					"where you can find them after the installation has completed."
				)
				(choices "Proceed with Move" "Skip This Part")
				(default 1)
			)
			(	(makedir "SYS:OLD" (infos))
				(if (in COMPONENTS kCOMPONENTCD)
					(if (exists sofS-STARTUP-SEQUENCE)
						(	(makedir "SYS:OLD/S")
							(copyfiles
								(source sofS-STARTUP-SEQUENCE)
								(dest "SYS:OLD/S")
								(optional "force")
								(nogauge)
							)
						)
					)
				)
				(if (exists sofDEVS-CD0)
					(	(makedir "SYS:OLD/Devs" (infos))
						(makedir "SYS:OLD/Devs/DOSDrivers" (infos))
						(delete "SYS:OLD/Devs/DOSDrivers/CD0")
						(delete "SYS:OLD/Devs/DOSDrivers/CD0.info")
						(rename sofDEVS-CD0 "SYS:OLD/Devs/DOSDrivers/CD0")
						(rename (cat sofDEVS-CD0 ".info") "SYS:OLD/Devs/DOSDrivers/CD0.info")
					)
				)
				(if (exists sofSTORAGE-CD0)
					(	(makedir "SYS:OLD/Devs" (infos))
						(makedir "SYS:OLD/Devs/DOSDrivers" (infos))
						(delete "SYS:OLD/Devs/DOSDrivers/CD0")
						(delete "SYS:OLD/Devs/DOSDrivers/CD0.info")
						(rename sofSTORAGE-CD0 "SYS:OLD/Devs/DOSDrivers/CD0")
						(rename (cat sofSTORAGE-CD0 ".info") "SYS:OLD/Devs/DOSDrivers/CD0.info")
					)
				)
			)
		)
	)
)

;;-
;;- CopyCD0
;;-		Copy suitable CD0 driver either to Devs or Storage
;;-
;;- Inputs:
;;-		None
;;- Outputs:
;;-		None
;;-
;;-
(procedure CopyCD0
	(if (in COMPONENTS kCOMPONENTCD)
		(	(set WALKROOT "Parts/DOSDrivers.CD32/")
			(set WALKACTION 2)
			(set WALKPAT "#?")
			(set WALKPROMPT "Updating Workbench File \"%s\"")
			(set WALKDEST "SYS:Devs/DOSDrivers")
			(Walk)
		)
		(if (in COMPONENTS kCOMPONENTSCSI)
			(	(CreateDevsDrawers)
				(set WALKROOT "Parts/DOSDrivers.SCSI/")
				(set WALKACTION 2)
				(set WALKPAT "#?")
				(set WALKPROMPT "Updating Workbench File \"%s\"")
				(set WALKDEST "SYS:Storage/DOSDrivers")
				(Walk)
			)
		)
	)
)

;********************request a disk******************************
(procedure REQUESTINSTALL
	(askdisk
		(Prompt "\n\nPlease insert the Squirrel SCSI\n\nMaster disk in any drive")
		(help @askdisk-help)
		(DEST "SquirrelSCSI")
	)
)

(procedure REQUESTCD32BOOT
	(askdisk
		(Prompt "\n\nPlease insert the CD32 boot floppy \n\nwhich is being prepared in any drive")
		(help @askdisk-help)
		(DEST "CD32Boot")
	)
)

(procedure REQUESTCDONLYBOOT
	(askdisk
		(Prompt "\n\nPlease insert the CD only boot floppy \n\nwhich is being prepared in any drive")
		(help @askdisk-help)
		(DEST "CDBoot")
	)
)

(procedure REQUESTSCSIHDBOOT
	(askdisk
		(Prompt "\n\nPlease insert the SCSI hard disk boot \n\nfloppy which is being prepared in any drive")
		(help @askdisk-help)
		(DEST "SCSIHDBoot")
	)
)


;*********************************COMPONENTS*********************************
(procedure PARTS
	(USER 2)
	(procedure RESELECT
		(if (= (database "chiprev") "AA")
			(set pDEFAULT 3)
			(set pDEFAULT 1)
		)
		(set COMPONENTS
			(askoptions
				(Prompt "Which parts of the package would you like to install?\n\nSee Help for more details")
				(help (cat
					"Install Squirrel SCSI software to hard disk\n"
					"-------------------------------------------\n"
					"This option will copy the files need for using SCSI devices "
					"to your internal IDE hard disk. In addition the software required "
					"to use CD's will be copied.\n\n"

					"Install CD32 emulator files to hard disk\n"
					"----------------------------------------\n"
					"This option will copy the files required to use CD32 titles onto "
					"your internal IDE hard drive; you should also select the "
					"\n\"Install Squirrel SCSI software to hard disk\"\n"
					"option when using this option.\n"
					"This option requires that you have plugged the interface "
					"into the computer and that the CD-ROM is connected properly "
					"and switched on - Check Now!\n\n"

					"Create CD/CD32 boot floppy (A1200)\n"
					"----------------------------------\n"
					"This option will create a boot disk that you can use to run CD32 titles. The disk contains"
					" the minimum files required to use CD32 titles. This option also requires that"
					" that the CD-ROM you are using is correctly plugged into the interface and is"
					" switched on. To use the CD32 boot disk, insert your CD32 CD-ROM into the drive and"
					" reboot the machine with the boot disk.\n\n"

					"Create CD only boot floppy (A1200/A600)\n"
					"---------------------------------------\n"
					"This option will create a boot disk that you can use to mount CDs. The disk contains"
					" the minimum files required to use CDs. To use the CD only boot disk,"
					" reboot the machine with the boot disk and insert a suitable CD.\n\n"

					"Create SquirrelSCSI hard disk boot floppy\n"
					"-----------------------------------------\n"
					"This option will create a boot disk that you can use to boot from an external"
					" SquirrelSCSI hard disk. The disk contains the minimum files required to pass"
					" control from the boot disk to the SCSI hard disk.\n\n"

					"Setup a SCSI hard disk\n"
					"----------------------\n"
					"This option can be used in conjunction with the "
					"\n\"Create SquirrelSCSI hard disk boot floppy\"\n"
					"This option will simply copy all the necessary Workbench files to "
					"an external SCSI hard disk.\n"
					"NOTE:\nThis option requires all the original Workbench disk supplied"
					" with your computer.\n\n"
					@askoptions-help)
				)
				(choices
					"Install Squirrel SCSI software to hard disk"
					"Install the CD32 files to hard disk"
					"Create CD/CD32 boot floppy (A1200)"
					"Create CD only boot floppy (A1200/A600)"
					"Create SquirrelSCSI hard disk boot floppy"
					"Setup a SCSI hard disk to use with a boot disk"
				)
				(default pDEFAULT)
			)
		)
	)
	(RESELECT)
	(while (= COMPONENTS 0)
		(RESELECT)
	)
	(USER default-user)

)

;************************set up locations****************************
(procedure LOCATIONS
	(if (IN COMPONENTS kCOMPONENTSCSI)
		(	(set SCSI_DEST
				(tackon
					(askdir
						(prompt "Select the location for the SquirrelSCSI Drawer")
						(help @askdir-help)
						(default "SYS:")
					)
					"SquirrelSCSI")
			)
			(if (<> (exists SCSI_DEST) 2)
				(Makedir SCSI_DEST (infos))
			)

		)
	)
	(if (IN COMPONENTS kCOMPONENTCD)
		(	(set CD32_DEST
				(tackon
					(askdir
						(prompt "Select the location for the CD32 drawer")
						(help @askdir-help)
						(default "SYS:")
					)
					"CD32"
				)
			)
			(if (<> (exists CD32_DEST) 2)
				(Makedir CD32_DEST (infos))
			)
		)
	)
)

;*******************clean ram*************************
(procedure CLEANRAM
	(if (= (exists "RAM:Boot") 2)
		(	(set WALKROOT "RAM:Boot/")
			(set WALKACTION 0)
			(set WALKPAT "#?")
			(Walk)
			(Delete "RAM:Boot")
		)
	)

	(if (= (exists "RAM:CD32DISK") 2)
		(	(set WALKROOT "RAM:CD32DISK/")
			(set WALKACTION 0)
			(set WALKPAT "#?")
			(Walk)
			(Delete "RAM:CD32DISK")
		)
	)

	(if (= (exists "RAM:HDDISK") 2)
		(	(set WALKROOT "RAM:HDDISK/")
			(set WALKACTION 0)
			(set WALKPAT "#?")
			(Walk)
			(Delete "RAM:HDDISK")
		)
	)
)

;**********************copy tools******************************************
(procedure COPYTOOLS
	(set n 0)
	(while
		(set file
			(select n "C/Install" "C/Edit" "C/Wait" "System/Format" "S/Startup-Sequence" "")
		)
		(set n (+ n 1))
		(copyfiles
			(source file)
			(dest "T:")
		)
	)
)

;;-
;;- InstallComponentSCSI - install SCSI component to hard disk
;;-
;;- Inputs:
;;-		None
;;-
;;- Outputs:
;;-		None
;;-

(procedure InstallComponentSCSI
	(REQUESTINSTALL)
	(UnconditionalSystemUpdates)
	;; first process the system files which we need to update
	(set WALKROOT "Packs/WB-SCSI/")
	(set WALKACTION 2)
	(set WALKPAT "#?")
	(set WALKPROMPT "Updating Workbench File \"%s\"")
	(set WALKDEST "SYS:")
	(Walk)

	(if (= PROCESSOR 1)
		(copylib
			(source "Parts/Devs.68020/squirrelscsi.device")
			(dest "DEVS:")
			(optional "askuser")
			(confirm)
			(prompt "Copying 68020 optimised SCSI driver")
			(help @copylib-help)
		)
		(copylib
			(source "Parts/Devs.68000/squirrelscsi.device")
			(dest "DEVS:")
			(optional "askuser")
			(confirm)
			(prompt "Copying 68000 compatible SCSI driver")
			(help @copylib-help)
		)
	)
	(copyfiles
		(source "SquirrelSCSI/")
		(dest SCSI_DEST)
		(all)
		(optional "force")
	)
	(startup "SCSIMounter"
		(Prompt "Place SCSIMounter path/commands to automount devices in user-startup?")
		(help @startup-help)
		(Command
			("Path \"%s/SCSIMounter\" ADD\n" SCSI_DEST)
			"SCSIMounter >NIL: DEVICE=squirrelscsi.device UNIT=0 NOUNMOUNT QUIET\n"
			"SCSIMounter >NIL: DEVICE=squirrelscsi.device UNIT=1 NOUNMOUNT QUIET\n"
			"SCSIMounter >NIL: DEVICE=squirrelscsi.device UNIT=2 NOUNMOUNT QUIET\n"
			"SCSIMounter >NIL: DEVICE=squirrelscsi.device UNIT=3 NOUNMOUNT QUIET\n"
			"SCSIMounter >NIL: DEVICE=squirrelscsi.device UNIT=4 NOUNMOUNT QUIET\n"
			"SCSIMounter >NIL: DEVICE=squirrelscsi.device UNIT=5 NOUNMOUNT QUIET\n"
			"SCSIMounter >NIL: DEVICE=squirrelscsi.device UNIT=6 NOUNMOUNT QUIET\n"
		)
	)
)

;;-
;;- InstallComponentCD32 - install CD32 component to hard disk
;;-
;;- Inputs:
;;-		None
;;-
;;- Outputs:
;;-		None
;;-

(procedure InstallComponentCD32
	(REQUESTINSTALL)
	(UnconditionalSystemUpdates)
	;; first process the system files which we need to update
	(set WALKROOT "Packs/WB-CD32/")
	(set WALKACTION 2)
	(set WALKPAT "#?")
	(set WALKPROMPT "Updating Workbench File \"%s\"")
	(set WALKDEST "SYS:")
	(Walk)

	;; then the Squirrel files
	(set WALKROOT "Packs/CD32/")
	(set WALKACTION 2)
	(set WALKPAT "#?")
	(set WALKPROMPT "Updating CD32 File \"%s\"")
	(set WALKDEST "SYS:")
	(Walk)

	;; for reasons best known to the installer this file doesn't copy...
	(copyfiles
		(source "Packs/CD32/Devs/cd.device.config")
		(dest "DEVS:")
		(optional "force")
	)
	(copyfiles
		(source "Parts/CD32/")
		(dest CD32_DEST)
		(all)
	)

	(textfile
		(dest "ENVARC:CD32-Path")
		(append ("%s" CD32_DEST))
	)

	(makedir snvlDRAWERPATH)
	(textfile
		(dest "SYS:Prefs/Env-Archive/Sys/nv_location")
		(append (expandpath snvlDRAWERPATH))
	)

	(set FILETOBEPATCHED "S:Startup-Sequence")
	(if
		(>=
			(run ("C/Search >NIL: FROM \"%s\" SEARCH \";CD32\" QUIET" FILETOBEPATCHED))
			5
		)
		(	(set PATCHFILE "RAM:Patchfile")

			(textfile
				(dest ("%s" PATCHFILE))
				(append "TR+; M1; F U/SetPatch/; N; I\n\n")
				(append ";CD32 Startup added by Squirrel SCSI Installation\n")
				(append "IF EXISTS S:CD32-Startup\n")
				(append "  C:Assign T: RAM:\n")
				(append "  Execute S:CD32-Startup\n")
				(append "EndIF\n")
				(append ";End CD32 Startup\n\n")
				(append "Z\n")
			)

			(run
				("C/Edit FROM \"%s\" WITH \"%s\" OPT W5000" FILETOBEPATCHED PATCHFILE)
				(confirm)
				(prompt "Place CD32 auto-start modifications in \"S:Startup-Sequence\"")
				(help
					"In order to auto-start CD32 titles the installation process adds the "
					"lines:\n\n"
					"IF EXISTS S:CD32-Startup\n"
					"  C:Assign T: RAM:\n"
					"  Execute S:CD32-Startup\n"
					"EndIF\n\n"
					"immediately after the SetPatch line in your Startup-Sequence. "
					"Note that without these changes you will not be able to auto-start "
					"CD32 titles."
				)
			)
			(delete PATCHFILE)
		)
	)

	(startup "Squirrel CD32"
		(Prompt "Place Squirrel CD32 paths/assigns in S:User-Startup?")
		(help @startup-help)
		(Command
			("Path \"%s/Prefs\" ADD\n" CD32_DEST)
			("Path \"%s/C\" ADD\n" CD32_DEST)
		)
	)
)

;;-
;;- CreateComponentCDOnly - create CD only boot floppy
;;-
;;- Inputs:
;;-		None
;;-
;;- Outputs:
;;-		None
;;-

(procedure CreateComponentCDOnly
	(REQUESTINSTALL)
	(copyfiles
		(source "Packs/CDONLYDISK/")
		(dest "RAM:CDONLYDISK")
		(all)
	)

	(REQUESTCDONLYBOOT)
	(copyfiles
		(source "RAM:CDONLYDISK/")
		(dest "CDBoot:")
		(all)
	)
	(set WALKROOT "RAM:CDONLYDISK/")
	(set WALKACTION 0)
	(set WALKPAT "#?")
	(Walk)
	(Delete "RAM:CDONLYDISK")
)


;;-
;;- CreateComponentCD32Disk - create CD32 boot floppy
;;-
;;- Inputs:
;;-		None
;;-
;;- Outputs:
;;-		None
;;-

(procedure CreateComponentCD32Disk
	(REQUESTINSTALL)
	(copyfiles
		(source "Packs/CD32DISK/")
		(dest "RAM:CD32DISK")
		(all)
	)

	(REQUESTCD32BOOT)
	(copyfiles
		(source "RAM:CD32DISK/")
		(dest "CD32Boot:")
		(all)
	)
	(cleanram)
)

;;-
;;- CreateComponentHDDisk - create HD boot floppy
;;-
;;- Inputs:
;;-		None
;;-
;;- Outputs:
;;-		None
;;-

(procedure CreateComponentHDDisk
	(REQUESTINSTALL)
	(copyfiles
		(source "Packs/HDDISK/")
		(dest "RAM:HDDISK")
		(all)
	)
	(if (= PROCESSOR 1)
		(copyfiles
			(source "Parts/Devs.68020/squirrelscsi.device")
			(dest "RAM:HDDISK/Devs")
		)
		(copyfiles
			(source "Parts/Devs.68000/squirrelscsi.device")
			(dest "RAM:HDDISK/Devs")
		)
	)

	(REQUESTSCSIHDBOOT)
	(copyfiles
		(Source "RAM:HDDISK/")
		(dest "SCSIHDBoot:")
		(all)
	)
	(cleanram)
)

;***********************check if Workbench************************
(procedure WORKBENCH
(if (<> QUICKFORMAT 2)
(
(USER 2)
(message ("\nPlease insert your Workbench disk in drive %s " DRIVE)
"\n\n\n\n Select Proceed to continue")
(procedure SCANDISK
(set WBDisk (expandpath DRIVE))
(set WBDisk1 (substr WBDisk 0 9))
(set WBDisk2 (substr WBDisk 8 9))
(if (OR (= WBDisk1 "Workbench") (= WBDisk2 "Workbench"))
	(set WBDisk3 0)
	(set WBDisk3 1)
)
)
(procedure NOTWBDISK
(SCANDISK)
(set TESTDISK 0)
(if (= WBDisk3 1)
	(set TESTDISK
	(askbool
	(Prompt "This does not look like a Workbench disk\n\n\nPlease insert an"
	(" original (unaltered in any way) Workbench disk in drive %s " DRIVE)
	"\n\n\n Select Retry to scan the disk or Ignore to carry on regardless")
	(Help ("The disk you have inserted in drive %s does not look like a" DRIVE)
	" Workbench disk to the installer.\n\nPlease insert an original Amiga"
	(" Workbench disk in drive %s select Retry for the installer to" DRIVE)
	" scan the disk again.\n\nYou can proceed without a Workbench disk but"
	" the disks created may not work correctly and the installation"
	" may stop due to an incorrect file/directory structure! \n\nIf you"
	" wish to carry on regardless of the warnings, select Ignore.")
	(Choices "Retry" "Ignore")
	)
	)
)
)
(NOTWBDISK)
(While (= TESTDISK 1)
	(NOTWBDISK)
)
(SCANDISK)
(user DEFAULT-USER)
)
)
)

;**************************copy workbench files********************************
(procedure PART5
	(if (IN COMPONENTS kCOMPONENTWBCOPY)
		(	(USER 2)
			(Message
				"The installation of the Workbench files to a Squirrel SCSI external hard disk"
				" requires that you have already partitioned and formatted the hard disk"
				" and that it is visible on the Workbench as a device. If you cannot access the"
				" the hard disk then you must repartition or format the drive."
			)
			(WORKBENCH)

			(set wbdiskver (getversion ("%sLibs/version.library" DRIVE)))
			(set ver (/ wbdiskver 65536))
			(set rev (- wbdiskver (* ver 65536) ) )

			(if (>= ver 40)
				;wb 3.1
				(set WBVERSION 4)
			)

			(if (= ver 39)
				;wb 3
				(set WBVERSION 3)
			)

			(if (= ver 38)
				;wb 2.10
				(set WBVERSION 2)
			)

			(if (= ver 37)
				(	(if (= rev 71)
						;wb 2.05
						(set WBVERSION 1)
					)
					(if (< rev 71)
						;wb 2.04
						(set WBVERSION 0)
					)
				)
			)

			(procedure SELECTDEVICE
				(USER 2)

				(set device
					(askdir
						(prompt "Select the SCSI device to copy\nWorkbench files to.")
						(help @askdir-help)
						(default "Workbench:")
						(disk)
					)
				)

				(set devicename (expandpath device))

				(set n 0)

				(while (<> x ":")
					(	(set x (substr devicename n 1))

						(set WBCOPYDEST (substr devicename 0 (+ n 1)))

						(set n (+ n 1))
					)
				)

				(set reselect
					(askbool
						(prompt ("Copy Workbench files to \"%s\"" WBCOPYDEST))
						(help @askbool-help)
						(choices "Yes" "No (Reselect)")
					)
				)
			)

			(SELECTDEVICE)

			(while (= reselect 0)
				(SELECTDEVICE)
			)

			(procedure COPYDISKS
				(set floppyname (substr diskname 0 (- (strlen diskname) 1)))
				(askdisk
					(Prompt ("\n\nPlease insert the %s disk in any drive" diskname))
					(help @askdisk-help)
					(DEST floppyname)
				)

				(copyfiles
					(source diskname)
					(dest diskdest)
					(all)
				)
			)

			(set n 0)
			(if (or (= WBVERSION 0) (= WBVERSION 1))
				(	(while (set diskname (select n "Workbench2.0:" "AmigaFonts2.0:" "Extras2.0:" ""))
						(	(set diskdest WBCOPYDEST)
							(COPYDISKS)
							(set n (+ n 1))
						)
					)
				)
			)

			(if (= WBVERSION 2)
				(	(while (set diskname (select n "Workbench2.1:" "Fonts:" "Extras2.1:" "Locale:" ""))
						(	(set diskdest (select n WBCOPYDEST ("%sFonts" WBCOPYDEST) WBCOPYDEST ("%sLocale" WBCOPYDEST) ""))
							(COPYDISKS)
							(set n (+ n 1))
						)
					)
				)
			)

			(if (= WBVERSION 3)
				(	(while (set diskname (select n "Workbench3.0:" "Fonts:" "Extras3.0:" "Locale:" "Storage3.0:" ""))
						(	(set diskdest (select n WBCOPYDEST ("%sFonts" WBCOPYDEST) WBCOPYDEST ("%sLocale" WBCOPYDEST) ("%sStorage" WBCOPYDEST) ""))
							(if (<> (exists ("%sStorage" WBCOPYDEST)) 2)
								(makedir ("%sStorage" WBCOPYDEST) (infos))
							)
							(COPYDISKS)
							(set n (+ n 1))
						)
					)
				)
			)

			(if (= WBVERSION 4)
				(	(while	(set diskname (select n "Workbench3.1:" "Fonts:" "Extras3.1:" "Locale:" "Storage3.1:" ""))
						(	(set diskdest (select n WBCOPYDEST ("%sFonts" WBCOPYDEST) WBCOPYDEST ("%sLocale" WBCOPYDEST) ("%sStorage" WBCOPYDEST) ""))
							(if (<> (exists ("%sStorage" WBCOPYDEST)) 2)
								(makedir ("%sStorage" WBCOPYDEST) (infos))
							)
							(COPYDISKS)
							(set n (+ n 1))
						)
					)
				)
			)

			(user default-user)
		)
	)
)

;*************************run cd config program ****************************
(procedure CDCONFIG
	(user 2)
	(if (in COMPONENTS kCOMPONENTCD)
		(	(Message "About to run the CD configuration program check everything"
				" is plugged in and switched on")
			(run
				("%s/Prefs/CDDevice FROM DEVS:cd.device.config" CD32_DEST)
			)
		)
	)

	(if (in COMPONENTS kCOMPONENTCD32DISK)
		(	(Message "About to run the CD configuration program check everything"
				" is plugged in and switched on")
			(REQUESTCD32BOOT)
			(RUN "CD32Boot:CD32/Prefs/CDDevice FROM CD32Boot:Devs/cd.device.config")
		)
	)
	(user default-user)
)

;************PROCEDURE - FORMAT (Format Boot/Units and Data disk)***********
(procedure FORMAT
(USER 2)
(Message "\nCD32, CD only and SCSIHD boot disks require blank floppy disks\n"
"\n\nPlease have the blank disks ready.")
(user default-user)
(set QUICKFORMAT 0)
(if (> default-user 0)
	(set QUICKFORMAT
	(Askchoice
	(prompt "If you are using preformatted Amiga floppy"
	" disks would you like to only quick format them?"
	"\n\nIf you are just overwriting or adding to a previous floppy installation"
	" you can choose to not format the disks at all")
	(help @askchoice-help)
	(choices "Full format" "Quick format" "Don't format")
	(default 0))
	)
)
(if (= QUICKFORMAT 0)
(set QUICK "")
(set QUICK "quick")
)
(if (= QUICKFORMAT 0)
(set TIME "2 Minutes")
(set TIME "20 Seconds")
)
(USER 2)
(if (<> QUICKFORMAT 2)
(

(procedure FORMATDISK
(Message ("\nPlease insert a blank disk in drive %s - " DRIVE)
"\n\nWait for the Drive light\n to go off before Proceeding")
(Working ("\nFormatting %s disk\n\n\n This will take aproximately %s..." DESCRIPTION TIME))
(run "T:Wait 10")
(Run ("T:format drive %s name %s noicons ffs %s" DRIVE DISKNAME QUICK) (safe))
(Run ("T:Install %s ffs" DRIVE) (safe))
(message ("\nRemove the disk from %s and label it -\n\n `%s'" DRIVE DESCRIPTION))
)

(if (in COMPONENTS kCOMPONENTHDDISK)
(
(set DISKNAME "SCSIHDBoot")
(set DESCRIPTION "SCSIHD Boot")
(FORMATDISK)
)
)

(if (in COMPONENTS kCOMPONENTCD32DISK)
(
(set DISKNAME "CD32Boot")
(set DESCRIPTION "CD32 Boot")
(FORMATDISK)
)
)

	(if (in COMPONENTS kCOMPONENTCDONLYDISK)
		(	(set DISKNAME "CDBoot")
			(set DESCRIPTION "CD Only")
			(FORMATDISK)
		)
	)


)
)

(delete "T:Format")
(delete "T:Install")
(delete "T:Wait")
(user DEFAULT-USER)

)

;***************************Introduction**************************
(procedure INTRODUCTION
	(message "\n Welcome to the installation utility for \nSquirrel SCSI \n"
		"\n\nTo ensure proper installation on a hard disk, it is important that"
		" you boot from your hard drive before using the installation utility!"
	)
)

;****************************bye bye************************
(procedure BYE
	(REQUESTINSTALL)
	(USER 2)
	(Message "Squirrel SCSI Installation is complete."
		"\nTo obtain your 30 days free technical support and notification of"
		" updates, please complete your registration card and return"
		" it to:-\n\n"
		;* text starts at * and ends at *                   *
		"          North America            Rest of world    \n"
		"         Oregon Research              HiSoft        \n"
		"    16200 S.W. Pacific Highway    The Old School    \n"
		"            Suite 162               Greenfield      \n"
		"             Tigard                 Bedford, UK     \n"
		"            OR 97224                 MK45 5DE       \n"
		"Phone: +1 503 620 4919            +44 1525 718181   \n"
		"FAX:   +1 503 624 2940            +44 1525 713716   \n"
		"EMail: orres@teleport.com hisoft@cix.compulink.co.uk\n"
		)

	(Message "Please remember, UK technical support is\n between 2-3p.m."
			" Mon-Fri\nIf you need technical support, please remember to have when you"
		" phone, your:-\nSerial Number\nSoftware version number\nMachine"
		" configuration (RAM,Processor,Hard disk etc.)\n\n Please also have a"
		" clear and concise description of the problem you are having to ensure"
		" that we can deal with your problem as quickly as possible.\n\n"
		" Select Proceed to quit to Workbench")

	(if (= (exists "SYS:Utilities/Multiview") 1)
		(Run "Run SYS:Utilities/Multiview ReadMe" (safe))
		(Run "Run Utilities/More ReadMe" (safe))
	)
	(Exit (quiet))
)

;**************************do ya stuff*********************************

;*catch any errors and pass dos errors to a message screen
;*if a dos problem occured

(onerror
	(user 2)
	(if (> @ioerr 0)
		(message ("\n\nA Dos Error %ld has occured" @ioerr)
			"\n\n\n\nPlease consult your Workbench manual"
			(" for further details, or type Fault %ld from a shell." @ioerr)
		)
	)
)

(set DEFAULT-USER @user-level)

(if (= (getassign "T") "") (
		(makedir "RAM:T")
		(makeassign "T" "RAM:T")
	)
)
(Gestalt)
(user 2)
(INTRODUCTION)
(PARTS)
(welcome)
(LOCATIONS)
(if (in COMPONENTS kCOMPONENTCD)
	(SetNVLocation)
)
(if (or
		(in COMPONENTS kCOMPONENTHDDISK)
		(in COMPONENTS kCOMPONENTCD32DISK)
		(in COMPONENTS kCOMPONENTCDONLYDISK)
		(in COMPONENTS kCOMPONENTWBCOPY)
	)
	(SetDrive)
)
(if (or
		(in COMPONENTS kCOMPONENTHDDISK)
		(in COMPONENTS kCOMPONENTCD32DISK)
		(in COMPONENTS kCOMPONENTCDONLYDISK)
	)
	(	(COPYTOOLS)
		(FORMAT)
	)
)
(if
	(or
		(in COMPONENTS kCOMPONENTSCSI)
		(in COMPONENTS kCOMPONENTCD)
	)
	(	(StashOldFiles)
		(UpdateSetPatch)
	)
)
(if (IN COMPONENTS kCOMPONENTSCSI)
	(InstallComponentSCSI)
)
(if (IN COMPONENTS kCOMPONENTCD)
	(InstallComponentCD32)
)
(if
	(or
		(in COMPONENTS kCOMPONENTSCSI)
		(in COMPONENTS kCOMPONENTCD)
	)
	(CopyCD0)
)
(if (in COMPONENTS kCOMPONENTCD32DISK)
	(CreateComponentCD32Disk)
)
(if (in COMPONENTS kCOMPONENTCDONLYDISK)
	(CreateComponentCDOnly)
)
(if (in COMPONENTS kCOMPONENTHDDISK)
	(CreateComponentHDDisk)
)
(PART5)
(delete "T:Edit" (optional "force"))
(delete "T:Startup-Sequence" (optional "force"))
(CDCONFIG)
(BYE)
