; FTPMount install script
; Date : 7-Aug-95
; Version 0.1

(transcript "Installing FTPMount ...")

(welcome "Greetings!\nYou are about to install FTPMount on your system.  "
			"This is a wise choice.\n")

(set name 
	(askdir
		(prompt "Where should FTPMount be installed?")
		(help
			"All of FTPMount's files will be installed in one directory, "
			"called FTPMountDir, which will be placed in the directory you specify "
			"here.  This directory will have the logical assign of FTPMountDir: "
			"associated with it.  You will probably need to be able to access this "
			"directory fairly often, so don't bury it too deep.\n\n"
			@askdir-help
		)
		(default @default-dest)
	)
)

(makeassign "FTPMountDir" name)

(set @default-dest name)

(makedir "FTPMountDir:FTPMountDir" (infos))

(if @pretend
	(makeassign "FTPMountDir" "T:" (safe))
	(makeassign "FTPMountDir" "FTPMountDir:FTPMountDir")
)

(set @default-dest (getassign "FTPMountDir" "a"))

(if (exists "DEVS:DOSDrivers")
   (
		(startup "FTPMount" 
			(prompt "Adding assign of FTPMountDir: to User-Startup")
			(help 
				"FTPMount uses the FTPMountDir: assign to work out where its files are.\n\n"
				@startup-help
			)
			(command (cat "assign FTPMountDir: " (getassign "FTPMountDir" "a") "\n"))
		)
	)
	; else
	(
		(startup "FTPMount"
		   (prompt "Adding assign of FTPMountDir: and mount of FTP: to User-Startup")
		   (help
		   	"FTPMount uses the FTPMountDir: assign to work out where its files are.\n\n"
		   	@startup-help
		   )
		   (command (cat "assign FTPMountDir: " (getassign "FTPMountDir" "a") "\n"
							"mount FTP: from FTPMountDir:L/FTPMountList\n"))
		)
	)
)

(makedir "FTPMountDir:Hosts" (infos))

(makedir "FTPMountDir:L")

(if (exists "DEVS:DOSDrivers")
	(
; this will be a v39 or v40 system with DEVS:Dosdrivers etc and 
; workbench-launchable mount
		(set ddest
			(askchoice
				(prompt
					"Where do you want to install the DOSDriver mount entry?\n\n"
					"NB:  If the entry is put in DEVS:DOSDrivers it is inadvisable "
					"for it to be activated upon mounting."
				)
				(help
					"This file tells the system where to find FTPMount-Handler and what "
					"to do with it.  The standard places to find DOSDriver mount entries are "
					"DEVS:DOSDrivers and SYS:Storage/DOSDrivers.  "
					"SYS:WBStartup is a little unorthodox, however it seems to be the only "
					"place that is guaranteed to work and mount FTP: safely upon system "
					"startup time.  If you elect to put the FTP: entry in DEVS:DOSDrivers "
					"or SYS:WBStartup it will be mounted at boot time.  If you "
					"put it anywhere else, then you will have to explicitly mount it before "
					"you can reference FTP: ... either by double clicking on the icon, or, if "
					"you have placed the entry in Storage, by typing 'mount FTP:' from a CLI.\n\n"
					"NB:  Mounting from DEVS:DOSDrivers is done at boot time before the assign "
					"of FTPMountDir: is done.  Because of this it is inadvisable for an entry to "
					"be put in DEVS:DOSDrivers if you want it to be activated at boot time.  Put "
					"it in SYS:WBStartup (or equivalent) instead in this case."
				)
				(choices "SYS:WBStartup" "DEVS:DOSDrivers" "SYS:Storage/DOSDrivers" "Elsewhere")
			)
		)

		(if (= ddest 3)
			(set name
				(askdir
					(prompt "Where do you want to put the FTP: DOSDriver mount entry?")
					(help @askdir-help)
					(default "SYS:WBStartup")
				)
			)
		)

		(set dact
			(askbool
				(prompt
					"Do you want the DOSDriver to be activated upon mounting?"
					(if (= ddest 1) 
						(cat
							"\n\nNB: It is inadvisable to say \"Yes\" here since FTPMountDir: will "
							"not have been assigned when DEVS:DOSDrivers/FTP is mounted."
						)
						""
					)
				)
				(help
					(if (<= ddest 1) "FTP: will be mounted at boot time, however, " "When FTP: is mounted ")
					"you have the option of making it active at this time, or leaving it inactive "
					"until you first reference a file or directory on FTP:.  "
					"The main difference is that when FTP: is not active there is no icon associated "
					"with the device, and so it will not appear on Workbench.  Leaving it inactive "
					"means that no memory is used by the device until it is actually referenced.\n\n"
					"NB:  Mounting from DEVS:DOSDrivers is done at boot time before the assign "
					"of FTPMountDir: is done.  Because of this it is inadvisable for an entry in "
					"DEVS:DOSDrivers to be auto-activated."
				)
				(default 1)
			)
		)

		(if (= ddest 0)
			(
				(copyfiles
					(source "DOSDrivers/FTP")
					(dest "SYS:WBStartup")
					(infos)
				)
				(if dact
					(tooltype
						(dest "SYS:WBStartup/FTP")
						(settooltype "ACTIVATE" "1")
					)
				)
			)
		)

		(if (= ddest 1)
			(
				(copyfiles
					(source "DOSDrivers/FTP")
					(dest "DEVS:DOSDrivers")
					(infos)
				)
				(if dact
					(tooltype
						(dest "DEVS:DOSDrivers/FTP")
						(settooltype "ACTIVATE" "1")
					)
				)
			)
		)

		(if (= ddest 2)
			(
				(copyfiles
					(source "DOSDrivers/FTP")
					(dest "SYS:Storage/DOSDrivers")
					(infos)
				)
				(if dact
					(tooltype
						(dest "Sys:Storage/DOSDrivers/FTP")
						(settooltype "ACTIVATE" "1")
					)
				)
			)
		)

		(if (= ddest 3)
		; name will have been set previously
			(
				(copyfiles
					(source "DOSDrivers/FTP")
					(dest name)
					(infos)
				)
				(makeassign "FTPMount_temp" name (safe))
				(if dact
					(tooltype
						(dest "FTPMount_temp:FTP")
						(settooltype "ACTIVATE" "1")
					)
				)
				(makeassign "FTPMount_temp" (safe))
			)
		)
	)
; else
	(
; this is a pre-v39 system and the mount entry has to be in a mountlist file
		(set dact
			(askbool
				(prompt
					"Do you want the DOSDriver to be activated upon mounting?"
				)
				(help
					"FTP: will be mounted at boot time, however, "
					"you have the option of making it active at this time, or leaving it inactive "
					"until you first reference a file or directory on FTP:.  "
					"The main difference is that when FTP: is not active there is no icon associated "
					"with the device, and so it will not appear on Workbench.  Leaving it inactive "
					"means that no memory is used by the device until it is actually referenced.\n"
				)
				(default 1)
			)
		)

		(textfile
			(prompt "Creating the mountlist for FTP:")
			(help "To mount FTP: we need to supply some parameters to mount in the "
					"from of a mountlist.  This file will be FTPMountDir:L/FTPMountList."
			)
			(dest "FTPMountDir:L/FTPMountList")
			(append (cat 
				"FTP:\n"
				"\tHandler = FTPMountDir:L/FTPMount-Handler\n"
				"\tStackSize = 6000\n"
				"\tPriority = 2\n"
				"\tGlobVec = -1\n"
				(if dact "\tMount = 1\n" "")
				"#\n"
			))
		)
	)
)

(if (trap -1 (getenv "USER"))
	(
		(set name
			(askstring
				(prompt
					"The USER environment variable needs to be set to your standard user name:"
				)
				(help
					"For anonymous logins, your email address is required.  FTPMount looks at "
					"the USER and HOST environment variables to construct your email address "
					"as USER@HOST.  Please enter a valid user name here.  This name will be "
					"saved to ENVARC:USER.\n\n"
					@askstring-help
				)
				(default "")
			)
		)
		(textfile
			(dest "ENVARC:USER")
			(append name)
		)
		(textfile
			(dest "ENV:USER")
			(append name)
		)
	)
)

(if (trap -1 (getenv "HOST"))
	(
		(set name
			(askstring
				(prompt
					"The HOST environment variable needs to be set to your email host:"
				)
				(help
					"For anonymous logins, your email address is required.  FTPMount looks at "
					"the USER and HOST environment variables to construct your email address "
					"as USER@HOST.  Please enter a valid email host here.  This name will be "
					"saved to ENVARC:HOST.\n\n"
					@askstring-help
				)
				(default "")
			)
		)
		(textfile
			(dest "ENVARC:HOST")
			(append name)
		)
		(textfile
			(dest "ENV:HOST")
			(append name)
		)
	)
)

(copyfiles
	(prompt "Which catalogs do you want to install?")
	(help 
		"If you want FTPMount to use a language other than English "
		"(or you wish to modify the English used by FTPMount) "
		"then you will need to install the relevant catalogs.  "
		"You don't need to install any catalogs, in which case "
		"FTPMount will use its default English informative information.\n\n"
		@askoptions-help
	)
	(source "Catalogs")
	(dest "FTPMountDir:Catalogs")
	(all)
	(confirm)
)

(copylib
	(source "L/FTPMount-Handler")
	(dest "FTPMountDir:L")
)

(if
	(askbool
		(prompt
			"Do you want the example Hosts installed?"
		)
		(help
			"Some example sub-directories of Hosts are available "
			"to give some idea of how the various tooltype options "
			"can be used."
		)
		(default 1)
	)
; then
	(copyfiles 
		(source "Hosts")
		(dest "FTPMountDir:Hosts")
		(all)
	)
)

(if
	(askbool
		(prompt
			"Do you want the documentation file installed?"
		)
		(help
			"Do you want the documentation file copied over to FTPMountDir: "
			"for future reference?"
		)
		(default 1)
	)
; then
	(copyfiles
		(source "FTPMount.guide")
		(dest "FTPMountDir:")
		(infos)
	)
)

(exit "A reboot now is recommended before you use FTP:")
