; VARIABLES:
;  is_update	- means that a previous install is being written over.  Do not
;		  mess with user-editables.
;  as225_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 AS225 "
	       "Release 2.")
))
;
;  Say hi!  (these are from the 2.1 script.  what do they do?)
;
(welcome)
(set old_level @user-level)
;
;  See if this is really an update
;
(set is_update 0)
(set as225_dest (getassign "inet" "a"))
(if as225_dest
	(if (askbool
		(prompt 
			"Your current copy of AS225 appears to be located in "
		        " the drawer named \"" as225_dest "\". Do you want the "
		        "update installed in that drawer?"
		)
		(help
			"The installer has determined that you may already have "
			"a copy of AS225 installed on your system.  If this is "
			"incorrect or if you want the update installed "
			"elsewhere, select 'No' as an answer.  Otherwise, "
			"select 'Yes.'"
		)
		(default 1)
	    )
	(set is_update 1)	; if user wants in same place
	)
)
;
;  If it isn't an update, figure out where to put it
;
(if (NOT is_update)
	(set as225_dest
		(tackon
			(askdir
				(prompt 
					"In which disk or drawer should AS225 "
					"be installed?"
				)
				(help @askdir-help)
				(default @default-dest)
			)
			"inet"
		)
	)
)
;
;  If it isn't an update but the target directory already exists, see if we
;  should call it an update...
;
(if (AND (NOT is_update) (exists as225_dest))
	(if (askbool
		(prompt "You appear to have at least a partial install of AS225 located in the drawer named \""
				as225_dest
				"\". Do you want to update the installation in that drawer?"
		)
		(help
			"The installer has determined that you may already have a "
			"copy of AS225 installed on your system.  If you want to update "
			"that instalation (without overwriting configuration files), "
			"select 'Yes' as an answer.  If you want to overwrite that "
			"installation, select 'No' as an answer."
		)
		(default 1)
	    )
	(set is_update 1)	; if user wants in same place
	)
)
;
;  Now that we know where it goes and whether we are overwriting it:
;
(if (NOT is_update)
	(makedir as225_dest (infos))
)
(if (NOT @pretend)
	(set @default-dest as225_dest)
)
(if (NOT @pretend)
	(makeassign "inet" as225_dest)
)
;
;  do the main copying.  Because pattern and all are mutually exclusive,
;  I have to copy each freaking directory seperately!!!
;
(copyfiles
	(prompt "Copy AS225 shared libraries.")
	(source "AmigaTCP_1:libs")
	(dest (tackon as225_dest "libs"))
	(all)
)
(complete 20)
(copyfiles
	(prompt "Copy AS225 servers.")
	(source "AmigaTCP_1:serv")
	(dest (tackon as225_dest "serv"))
	(all)
	(optional)
)
(complete 40)
(copyfiles
	(prompt "Copy AS225 db files which shouldn't be user-modified.")
	(source "AmigaTCP_1:db")
	(dest (tackon as225_dest "db"))
	(all)
)
(if (NOT is_update)
	(copyfiles
		(prompt "Copy AS225 user-modifyable db (database) files.")
		(source "AmigaTCP_1:db.user")
		(dest (tackon as225_dest "db"))
		(all)
		(optional)
	)
)
(complete 45)
(copyfiles
	(prompt "Copy new AS225 s files (just SANA-II configuration).")
	(source "AmigaTCP_1:s")
	(dest (tackon as225_dest "s"))
	(all)
)
(if (NOT is_update)
	(copyfiles
		(prompt "Copy AS225 user-modifyable s (script/config) files.")
		(source "AmigaTCP_1:s.user")
		(dest (tackon as225_dest "s"))
		(optional)
		(all)
	)
)
(complete 50)
(copyfiles		;ask about which drivers they want to copy, check versions
	(prompt "Copy SANA-II Network Device Drivers.")
	(source "AmigaTCP_1:devs")
	(dest "devs:")
	(all)
	(optional)
)
(complete 60)
;
;  If it's an update, find out whether they want a new inet:s/start-inet:
;
(set newscript 0)
(if is_update
	(set newscript
		(askbool
		(prompt "Should a new inet:s/start-inet be installed?")
		(help
			"AS225 now uses SANA-II Network Device Drivers rather "
			"than internal drivers.  If the inet:s/start-inet "
			"script has not been edited, you can just use the new "
			"one and all will be well.  Otherwise, you'll need to "
			"be aware of the new interface names (i.e., ae0 is now "
			"sanaiiX where X is a number specified in the inet:s/sana2_devs "
			"file) and update your script manually.  Select 'Yes' "
			"to get the new script, select 'No' if you wish to "
			"edit your existing script manaully once the update is "
			"complete."
		)
		(default 1)
	)
	)
)
(if newscript
	(copyfiles
		(prompt "Copy new start-inet.")
		(source "AmigaTCP_1:s.user/start-inet")
		(dest (tackon as225_dest "s/start-inet"))
	)
)
(complete 65)
;
;  Copy all of the c directory commands on the second disk:
;
(askdisk (prompt "Please insert disk AmigaTCP_2")
	(help "The second disk contains the commands for AS225.")
	(dest "AmigaTCP_2")
)
(copyfiles		
	(prompt "Copy AS225 commands.")
	(source "AmigaTCP_2:c")
	(dest (tackon as225_dest "c"))
	(all)
)
(if is_update (complete 90) (complete 80))
;
;  Delete upsupported software (rloginVT, fingerd and tftp(d))
;
(if is_update
	(if (askbool
		(prompt "Delete unsupported software?")
		(help
			"rloginVT, fingerd, tftp and tftpd are no longer "
			"supported.  The daemons are not invokable with the "
			"current inetd at all.  We strongly suggest that you "
			"stop using these programs and remove the clutter from "
			"your harddrive."
		)
		(default 1)
	    	)
	(execute "delete inet:c/rloginvt inet:c/tftp inet:serv/fingerd inet:serv/ftpd")
	)
)
;
;  We're all done if this was just an update!
;
(if is_update (exit))
;
;  Set up config
;-----------------
;  VARIABLES:
;
;  ip_number
;  hostname
;  username
;  uid
;  gid
;  timezone		should come from locale, please make it disappear 
;			  from inet.config
;  tzname		should come from locale, please make it disappear
;			  from inet.config
;  gateway		uses default, should be changed by net admins
;  broadcast		uses default, should be changed by net admins
;  subnetmask		uses default, should be changed by net admins
;  umask		uses default, should be changed by security conscious
;			  who are NFS mounting remote volumes
;
(set hostname (askstring
	(prompt
		"What is the name of this machine?"
 	)
 	(help
 		"Machines must be named with human-understandable names. "
 		"Names should be all lower case.  Most people prefer names of "
 		"less than eight characters, but they can be longer.  You "
 		"should check the name you choose with your network "
 		"administrator since they should be unique within a domain "
 		"and should be known to at least some other machines."
 	))
 )
(set ip_number (askstring
	(prompt
		"What is the IP number of this machine?"
	)
	(help
		"Each machine must be assigned an IP number.  These numbers "
		"are carefully choosen and cannot be arbitrarily assigned. "
		"They are usually expressed in dotted-decimal notation, which "
		"looks like xxx.xxx.xxx.xxx where each xxx is a number between "
		"1 and 254."
	))
)
(set username (askstring 
	(prompt
			"What is your user name?"
	)
	(help
		"Many networking utilities want to know which user is "
		"trying to get service.  Since the Amiga does not have "
		"a log in procedure, you will specify a user name during "
		"configuration which will always be the user \"logged in\" to "
		"the Amiga.  This isn't optimal, especially if there are "
		"multiple users of this Amiga, but there aren't many other "
		"reasonable ways to do it. "
		" You should, if possible, choose the same "
		"name as used in any accounts on machines you will be "
		"communicating with.\nMost utilities will allow you to override "
		"this name with a switch."
	))
)
(set uid (asknumber
	(prompt
		"What is your UID?"
	)
	(help
		"A unique user ID number is associated with a user name. "
		"This number should usually be the same on all machines with "
		"an account for a given user. "
	))
)
(set gid (asknumber
	(prompt
		"What is your GID?"
	)
	(help
		"Some networking utilities need to know which group ID to "
		"assign to newly created objects (i.e., new files created "
		"in an NFS mounted partition)."
	))
)
(set timezone 300)
(set tzname  "EST")
(set umask "002")
(set configfile "")
(set gateway "")
(set broadcast "200.0.0.255")
(set subnetmask "255.255.255.0")
(textfile
	(dest "inet:s/inet.config")
	(append ("uid=%ld\n" uid))
	(append ("gid=%ld\n" gid))
	(append ("tz=%ld\n" timezone))
	(append ("tzname=%s\n" tzname))
	(append ("user=%s\n" username))
	(append ("host=%s\n" hostname))
	(append ("gateway=%s\n" gateway))
	(append ("configfile=%s\n" configfile))
	(append ("broadcast=%s\n" broadcast))
	(append ("subnetmask=%s\n" subnetmask))
	(append ("gids=%ld\n" gid))
)
(textfile
	(dest "inet:db/hosts")
    	(append ("%s\t%s\t\t# Local Host\n" ip_number hostname))
)
(textfile
	(dest "inet:db/passwd")
    	(append ("%s||%ld|%ld|Amiga User|ram:|shell\n" username uid gid))
)
;
;  Set startup
;
(set temp 
	(askbool
	(prompt 
		"Running servers allows incomming communications to your Amiga. "
		"If you don't run servers, noone can connect to it, but you can "
		"still connect to other machines from the Amiga.  You should "
		"run servers unless you have a small amount of RAM or have a "
		"security reason not to run servers."
		"\n\nWould you like to run servers?"
	)
	(help "")
	)
)
(if temp
	(set servers " servers")
	(set servers "")
)
(complete 85)
(set temp 
	(askbool
	(prompt
		"RIP (Route Information Protocol) automatically updates routing "
		"information for your network.  If your machine has multiple "
		"network interfaces (i.e. two ethernet cards or an arcnet card "
		"and an ethernet card), RIP can inform other machines of that "
		"fact.  If there are many gateways on your physical network, RIP "
		"may find them for you allowing you to automatically use them."
		"Most users will be fine not running RIP but just adding a "
		"default route one gateway in the inet:s/start-inet file "
		"If you think that you should be using RIP but aren't sure, "
		"consult with your network administrator."
	 	"\n\nWould you like to run RIP?"
	)
	(help "")
	)
)
(if temp
	(set rip " rip")
	(set rip "")
)
(complete 90)
(set temp 
	(askbool
	(prompt 
		"The syslog daemon records data about incomming connections "
		"and the activities of remote users.  If you are paranoid "
		"about security, you should run syslogd in order to generate "
		"audit trails for use in the event of a problem."
		"\n\nWould you like to run syslogd?"
	)
	(help "")
	)
)
(if temp
	(set syslog " syslog")
	(set syslog "")
)
(complete 95)
(startup "AS225"
	(prompt 
		"Some instructions need to be added to the \"s:user-startup\" "
		"so that your system will be properly configured to use AS225."
	)
	(help "Do this or AS225 won't work.")
	(command
	"ASSIGN inet: \"" as225_dest "\"\n"
	"PATH inet:c ADD\n"
	"EXECUTE inet:s/start-inet" servers rip syslog "\n"
	)
)
(complete 100)
(message
	"Before you can use AS225, you must edit "
	"inet:db/hosts.  If you aren't using one A2065, you'll need to edit "
	"inet:sana2_devs and inet:s/start-inet.  If you aren't running RIP but "
	"are connected to gateways to other networks, you'll want to add routes "
	"to inet:s/start-inet (see the commented line beginging "route").  "
	"If you want to NFS mount remote filesystems, you'll want to edit "
	"inet:db/fstab. "
	"If you are running servers, you'll want to edit inet:db/passwd, "
	"inet:db/hosts.equiv, and maybe inet:db/inetd (the default is "
	"to export all possible services)."
)
