; VARIABLES:
;  is_update	- means that a previous install is being written over.  Do not
;		  mess with user-editables.
;  	envoy_dest   - where to copy it all to.  We default to inet:, if assigned
;		  (but only if assigned, not if a device has that name.)
;

;
;  Make sure that we are running under 2.04 or better
;
(if (< (/ (getversion) 65536) 37)
	(abort "You must be using Kickstart 2.04 or higher to install Envoy.")
)
(if (exists "inet:libs/inet.library")
	(if (< (/ (getversion "inet:libs/inet.library") 65536) 3.6)
		(abort 
		 	"If using AS225, you must be using inet.library 3.6"
			"or higher to install Envoy."
		)
	)
)
;
;  Say hi!  (these are from the 2.1 script.  what do they do?)
;
(welcome)
(set old_level @user-level)
(message
	"\nEnvoy installation ALPHA v0.1.\n"
	"The entire contents of this disk are\n"
	"COMMODORE CONFIDENTIAL\n"
	"Do not distribute.  For internal use only.\n\n"
)
;
;  Figure out where to put it
;
(set envoy_dest
	(tackon
		(askdir
			(prompt 
				"\nIn which disk (or drawer) should Envoy "
				"be installed (or updated)?"
			)
			(help @askdir-help)
			(default @default-dest)
		)
		"Envoy"
	)
)
;
;  See if this is really an update
;
(set is_update 0)
(if (exists envoy_dest)
	(if (askbool
		(prompt 
			"\nYou seem to already have a (partial) installation of "
			"Envoy in \"" envoy_dest ".\"  Do you wish to update a "
			"complete existing installation?  (Answer NO to install "
			"from scratch or to update a partial installation.)"
		)
		(help
			"\nThe installer has determined that you may already "
			"have a copy of Envoy correctly installed on your "
			"system.  If this is incorrect or if you want to "
			"update from scratch select 'No' as an answer.  "
			"Otherwise, select 'Yes.'"
		)
		(default 1)
	    )
	(set is_update 1)	; if user wants in same place
	)
)
;
; See if they meant to update but got it wrong
;	I suppose I could check for the rest of the libraries and for prefs 
;	files in ENV: or ENVARC:, too, but that seems like overkill.
;
(if (AND (exists "libs:nipc.library") (NOT (exists envoy_dest)) )
	(message
		"\nYou have some of the Envoy shared libraries in your "
		"libs: drawer.  This implies that you have a "
		"(partial) installation of Envoy and are just "
		"performing an update.  The drawer which "
		"you've asked Envoy to be installed in, however "
		"\"" envoy_dest "\""
		", does not exist.  This implies that you are "
		"performing a new installation.\n"
		"Unless you abort, installation will proceede on "
		"the assumption that you are perfroming a new "
		"installation."
	)
)
;
;  Now that we know where it goes and whether we are overwriting it:
;
(if (NOT is_update)
	(makedir envoy_dest (infos))
)
(if (NOT @pretend)
	(set @default-dest envoy_dest)
)
;
;  do the main copying.  Because pattern and all are mutually exclusive,
;  I have to copy each freaking directory separately!!!  Copylib is used
;  for each library individually so that no smaller version is overwritten
;  by a higher version.  Last time I checked though, this feature was broken.
;
(copylib
	(prompt "Copy nipc.library.")
	(source "EnvoyInstall:libs/nipc.library")
	(dest "libs:")
	(help
		"\nfill"
	)
)
(copylib
	(prompt "Copy services.library.")
	(source "EnvoyInstall:libs/services.library")
	(dest "libs:")
	(help
		"\nfill"
	)
)
(copylib
	(prompt "Copy authentication.library.")
	(source "EnvoyInstall:libs/authentication.library")
	(dest "libs:")
	(help
		"\nfill"
	)
)
(copyfiles
	(prompt "Copy Envoy tools.")
	(source "EnvoyInstall:Tools")
	(dest (tackon envoy_dest "Tools"))
	(all)
	(infos)
	(help
		"\nfill"
	)
)
(copyfiles
	(prompt "Copy Envoy Preferences Editors.")
	(source "EnvoyInstall:Prefs")
	(dest (tackon envoy_dest "Prefs"))
	(all)
	(infos)
	(help
		"\nfill"
	)
)
(copyfiles
	(prompt "Copy ReadMe file.")
	(source "EnvoyInstall:ReadMe")
	(dest envoy_dest)
	(infos)
	(help
		"\nfill"
	)
)
(copyfiles  /*  This should do some version checking!!!! *******************/
	(prompt "Copy updated c: commands.")
	(source "EnvoyInstall:c")
	(dest "c:")
	(all)
	(help
		"\nfill"
	)
)
(copyfiles
	(prompt "Copy EFS Filesystem client.")
	(source "EnvoyInstall:l")
	(dest "l:")
	(all)
	(help
		"\nfill"
	)
)
(if (askbool
	(prompt
		"\nWould you like the Envoy server programs installed?"
	)
	(help
		"\nMost networking applications are split into to halves -- "
		"a client and a server.  The client side contacts the server "
		"side which "
	))
	(copyfiles
		(prompt "Copy Envoy services.")
		(source "EnvoyInstall:Services")
		(dest (tackon envoy_dest "Services"))
		(all)
		(infos)
		(optional)
	)
)
;
;   Need to delete old drivers located in devs: rather than devs:Networks.
;   Need to ask which SANA-II drivers to install
;   Note that this also copies mount examples to devs:DOSDrivers
;
(copyfiles 
	(prompt "Copy SANA-II Network Device Drivers, EFS Mount Examples.")
	(source "EnvoyInstall:devs/")
	(all)
	(infos)
	(dest "devs:")
	(optional)
	(confirm)
	(help
		"\nfill"
	)
)
(if (askbool
	(prompt
		"\nDo you want the ALPHA toys installed? "
		"Most of these binaries will not be supported or "
		"included in the release.  They are warranted to have "
		"defects and to be less than pretty.  The toys include a "
		"shared clipboard, remote control commodity, and others."
		"We haven't yet decided whether we'll even include them in "
		"the BETA."
	)
	(help
		"\nDamn it, these are unsupported.  We don't give help!"
	))
	(copyfiles
		(prompt "Beta toys.")
		(source "EnvoyInstall:BetaToys")
		(dest (tackon envoy_dest "BetaToys"))
		(all)
		(optional)
		(infos)
		(help
			"fill"
		)
	)
)
(if (askbool
	(prompt
		"\nThe includes, autodocs and example code will not "
		"be a part of the Envoy public release.  (They will likely be "
		"available on a networking developer's disk.)  Would you "
		"like them installed for you now?"
	)
	(help
		"\nYou don't really need help."
	))
	((copyfiles
		(prompt "Copy Envoy includes (May not be in final release.)")
		(source "EnvoyInstall:include")
		(dest (tackon envoy_dest "include"))
		(all)
		(help
			"\nfill"
		)
	)
	(copyfiles
		(prompt "Copy Envoy autodocs.  (May not be in final release.)")
		(source "EnvoyInstall:doc")
		(dest (tackon envoy_dest "doc"))
		(all)
		(help
			"\nfill"
		)
	))
)
;
;  We're all done if this was just an update!
;
(if is_update (exit))
;
;  Get configuration information from the user:
;
;(message
;	"\nIf you will be using a SANA-II device which has not yet been "
;	"copied to devs: yet, copy it there now manually.  Come back to "
;	"installer when you are done."
;)
;
;  This is really just temporary.  We want to ask the user a series of questions
;  rather than forcing him to use NIPCConfig and guess which fields are relevant
;  to his network.
;
;(makedir "Env:Envoy")
;(makedir "EnvArc:Envoy")
(if (NOT (exists Env:Envoy))
	((copyfiles
		(prompt "Copy Envoy 'default' configuration.")
		(source "EnvoyInstall:Env")
		(dest "EnvArc:")
		(all)
		(help
			"\nfill"
		)
	)
	(copyfiles
		(prompt "Copy Envoy 'default' configuration.")
		(source "EnvoyInstall:Env")
		(dest "Env:")
		(all)
		(help
			"\nfill"
		)
	))
) 

;  No Internet: 
; 
;  Hostname 
;  Address (1-254) 
;  SANA-II Device  (no need to support multiple devices if not internet) 
;		(don't need subnet mask)


;  Internet:
;
;  Hostname
;  Address (full IP number)
;  SANA-II Devices (with all the fixin's)
;  Realm name
;  Realm Server
;  Realms
;  Gateway config
;
;  Let's configure what the user will do at boot time
;
(if (askbool
	(prompt
		"\nRun Authentication Server from your s:user-startup?"
	)
	(help
		"\nfill"
	))
	(set authserv ("Run >NIL: \"%s/services/AuthenticationServer\"\n" envoy_dest))
)
(if (askbool
	(prompt
		"\nRun Services Manager from your s:user-startup?"
	)
	(help
		"\nfill"
	))
	(set manager ("Run >NIL: \"%s/services/manager\"\n" envoy_dest))
)
(startup "Envoy"
	(prompt 
		"\nSome instructions need to be added to the \"s:user-startup\" "
		"so that your system will be properly configured to use Envoy."
	)
	(command
		("PATH \"%s%s\" \"%s%s\" ADD\n%s%s" envoy_dest "/Tools"
  		                            envoy_dest "/Config"
		                             manager 
		                             authserv
		)
	)
	(help
		"\nDo this to make Envoy work."
	)
)
(run ("%s/prefs/NIPCConfig" envoy_dest) )
