;;;; DC'97 AMITCP/NETCONNECT INSTALLER SCRIPT BY LeXus
;;;; NOTE TO NIGHT^DC - - REPACK FILES FROM A ROOT DIRECTORY FOR THIS TO WORK
;;;; (A SIDE EFFECT OF UNLZX)
;;;; Install NetConnect & AmiTCP - installation script for Installer
;;;;
;;;; Based on the original AmiTCP installation script:
;;;; Copyright © 1996 AmiTCP/IP Group,
;;;;                  NSDi - Network Solutions Development Inc., Finland
;;;;                  All rights reserved.
;;;;
;;;; This script has been tested with Installer.
;;;;
;;;;     Installer and Installer project icon
;;;;     (c) Copyright 1991-93 Commodore-Amiga, Inc.  All Rights Reserved.
;;;;     Reproduced and distributed under license from Commodore.
;;;;
;;;;     INSTALLER SOFTWARE IS PROVIDED "AS-IS" AND SUBJECT TO CHANGE;
;;;;     NO WARRANTIES ARE MADE.  ALL USE IS AT YOUR OWN RISK.  NO LIABILITY
;;;;     OR RESPONSIBILITY IS ASSUMED.
;;;;
;;;; Use following Icon tooltypes / Command line options:
;;;; APPNAME=NetConnect
;;;; MINUSER=AVERAGE
;;;;
;;;;

(set app-name		(cat @app-name " Demo"))
(set netconnect-name	(cat "NetConnect"))
(set atcp-name		(cat "AmiTCP"))
(set app-dir-name	(cat "NetConnect"))
(set atcp-dir-name	(cat "AmiTCP-DialUpDemo-4.5"))

(welcome "    Welcome to the " app-name " installation.\n")

(if (= @pretend 1)
	(set pretend-extra "\nNote: `Make New Drawer' will make new drawer even in PRETEND mode")
	(set pretend-extra ""))

;;;;
;;;; "Needs"
;;;;
(set
 need-version		37
 need-memory		(* 512 1024)
 AmiTCP-release-number	4

 install-disk1-name	""
 AmiTCP-pkt-file	(tackon install-disk1-name "AmiTCP/AmiTCP-DialUpDemo.lzx")
 NapsaFonts-pkt-file	(tackon install-disk1-name "AmiTCP/NapsaFonts.lzx")
 dist-networks-dir	(tackon install-disk1-name "AmiTCP/Devs/Networks")
 dist-data-dir		(tackon install-disk1-name "Data")
 dist-programs-dir	(tackon install-disk1-name "Programs")
 dist-docs-dir		(tackon install-disk1-name "Docs")
 dist-handler-dir	(tackon install-disk1-name "L")
 dist-env-file		(tackon install-disk1-name "ENV/NetConnectPrefs")
 UnPkt-file		(tackon install-disk1-name "AmiTCP/unlzx")
 atcp-LICENSE-file	(tackon install-disk1-name "AmiTCP/LICENSE")
 atcp-README-FIRST-file	(tackon install-disk1-name "AmiTCP/Read Me First")
 info-file		(tackon install-disk1-name "AmiTCP.info")

 netconnect-assign	(cat netconnect-name ":")
 atcp-assign		(cat atcp-name ":")

 conf-dir	(tackon atcp-assign "db")
 bin-dir	(tackon atcp-assign "bin")
 doc-dir	(tackon atcp-assign "doc")
 devs-dir	(tackon atcp-assign "devs")
 help-dir	(tackon atcp-assign "help")
 l-dir		(tackon atcp-assign "l")
 libs-dir	(tackon atcp-assign "libs")
 ssrx-dir	(tackon atcp-assign "ssrx")

 apipe-mount (cat 
	"Assign APIPE: Exists > NIL:\n" 
	"IF Warn\n"
	"  Mount APIPE: from AmiTCP:devs/APipe-Mountlist\n"
	"EndIf\n")
)

(set pager-cmd 
 (if (exists "SYS:Utilities/More" (noreq))
	((copyfiles
	(prompt "Copying sys:utilities/more to ram: for use")
	(source "SYS:Utilities/More")
	(dest   "RAM:")
	(safe)
	(optional "nofail"))
	"RAM:More")
	("more"))
)

(onerror
 (if old-atcp-directory
     (makeassign atcp-name old-atcp-directory))
 (if old-netconnect-directory
     (makeassign netconnect-name old-netconnect-directory))
)



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure check-system-version

 (set exec-version (/ (getversion) 65536))
 (transcript "Running on exec version " exec-version ".")
 (if (< exec-version need-version)
	((transcript "Installation aborted due too old operating system.")
	(abort "NetConnect requires at least operating system 2.04")))
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 check-user-level

 (transcript "Checking user level.")
 (if (< @user-level 1)
	((transcript "Installation aborted due to too low user level.")
	(abort "NetConnect installation requires at least the \"average\" "
		"user level. Restart installation and select appropriate user "
		"level.")))
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure check-old-assign

 (transcript "Checking for already installed NetConnect.")
 (set old-netconnect-directory 
	(if (exists netconnect-assign (noreq))
		(getassign netconnect-name)
		""))
 (if old-netconnect-directory
	(transcript "Existing NetConnect detected at directory " old-netconnect-directory "."))

 (transcript "Checking for already installed AmiTCP.")
 (set old-atcp-directory 
	(if (exists atcp-assign (noreq))
		(getassign atcp-name)
		""))
 (if old-atcp-directory
	(transcript "Existing AmiTCP detected at directory " old-atcp-directory "."))
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(procedure check-cpu-type

 (set cpu-type (database "cpu"))
 (set cpu-is-020-or-better
	(AND (<> cpu-type "68000")
	(<> cpu-type "68010")))
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure ask-accept-license

 (transcript "Asking if the user accepts the AmiTCP license conditions.")
 (run (cat "run " pager-cmd) atcp-LICENSE-file (safe))
 (message "\nAmiTCP/IP is a copyrighted propiertary software of "
	"\"Network Solutions Development Inc.\"\n"
        "\nPlease read the shown license text carefully.\n"
        "\nBy proceeding the installation of this software you "
	"indicate that you accept the license conditions.\n"
 )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure select-ndestination-directory

 (transcript "Selecting destination directory for the installation of NetConnect.")
 (set netconnect-dest
	(askdir
		(prompt "Select directory where to install " app-name "."
			pretend-extra)
		(help "Here you can specify the location where to install the " app-name ".\n"
			"Installer will create a subdirectory called `"
			app-dir-name "' in the selected directory and copy the " @app-name " files to it.")
		(newpath)
		(default @default-dest)
	)
 )
 (textfile (dest (tackon netconnect-dest (cat app-dir-name ".info")))
	(include info-file))
 (set netconnect-dest (tackon netconnect-dest app-dir-name))
 (if (= pretend 0) (set @default-dest netconnect-dest))
 (makedir netconnect-dest (infos))

 (if (= @pretend 0)
	((makeassign netconnect-name netconnect-dest)))
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure select-adestination-directory

 (transcript "Selecting destination directory for the installation of AmiTCP.")
 (set atcp-dest
	(askdir
		(prompt "Select directory where to install " atcp-name "." pretend-extra)
		(help "Here you can specify the location where to install " atcp-name ".\n"
			"Installation must NOT be made on top of an older version of " atcp-name ".\n"
			"Installer will create a subdirectory called `" atcp-dir-name "' to the selected "
			"directory and copy the " atcp-name " files to it.\n\nIt is suggested that you select the just"
			" created direcotry \"" @default-dest "\" so the AmiTCP files are within the NetConnect Package.")
		(newpath)
		(default @default-dest)
	)
 )
 (textfile (dest (tackon atcp-dest (cat atcp-dir-name ".info")))
	(include info-file))
 (set atcp-dest (tackon atcp-dest atcp-dir-name))
 (makedir atcp-dest (infos))

 (if (= @pretend 0)
	((makeassign atcp-name atcp-dest)
	(if (NOT (= 2 (exists (tackon atcp-assign "devs"))))
		(makedir (tackon atcp-assign "devs")))))
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; arguments:
;;
;;   unpkt-source      - the source archive
;;   unpkt-destination - the destination directory
;;   unpkt-sdp         - number of directories to strip
;;   unpkt-title-name  - descriptive name of the archive
;;   unpkt-title-not   - installation unit name

(procedure run-unpkt 

 (if (exists unpkt-source)
	((transcript "Dearchiving " unpkt-source " files to " unpkt-destination ".")
		(working "Writing files to " unpkt-destination "...")
		(if (= @pretend 0) 
			((if (run (cat unpkt-cmd" ""x"" "unpkt-source" "unpkt-destination"/"))
		))))
	1)
	
 )


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure copy-netc-files-to-destination

(copyfiles
	(prompt "Copy the NetConnect Controller & Prefs")
	(source install-disk1-name)
	(choices "NetConnect" "NetConnectPrefs" "AmiTCPPrefs")
	(dest netconnect-assign)
	(infos)
	(optional "nofail")
)

 (transcript "Copying provider and data files.")

 (set tmp-var (tackon netconnect-assign "Data"))
 (if (NOT (= 2 (exists tmp-var)))
	(makedir tmp-var))
 (copyfiles
	(prompt "Copying provider files, images and other data files to:\n\n" tmp-var)
	(source dist-data-dir)
	(dest tmp-var)
	(all)
	(infos)
	(optional "nofail"))

 (set tmp-var (tackon netconnect-assign "Programs"))
 (if (NOT (= 2 (exists tmp-var)))
	(makedir tmp-var))
 (copyfiles
	(prompt "Copying programs to:\n\n" tmp-var)
	(source dist-programs-dir)
	(dest tmp-var)
	(all)
	(infos)
	(optional "nofail"))

 (set tmp-var (tackon netconnect-assign "Docs"))
 (if (NOT (= 2 (exists tmp-var)))
	(makedir tmp-var))
 (copyfiles
	(prompt "Copying documentation to:\n\n" tmp-var)
	(source dist-docs-dir)
	(dest tmp-var)
	(all)
	(infos)
	(optional "nofail"))

 (if (NOT (exists "ENV:NetConnectPrefs"))
	(copyfiles
		(prompt "Copying default NetConnect\npreference file to:\n\nENV:")
		(source dist-env-file)
		(dest "ENV:")
		(optional "nofail"))
 )
 (if (NOT (exists "ENVARC:NetConnectPrefs"))
	 (copyfiles
		(prompt "Copying default NetConnect\npreference file to:\n\nENVARC:")
		(source dist-env-file)
		(dest "ENVARC:")
		(optional "nofail"))
 )

 (if (askbool
	(prompt "Would you like the \"NetConnect Controller\" to be copied into your WBStartup drawer ?")
	(help "If you choose to copy NetConnect into your WBStartup drawer it will be started automatically everytime you reboot your Amiga.\n"))
	(copyfiles
		(prompt "Copy the NetConnect Controller to:\n\nSYS:WBStartup")
		(source install-disk1-name)
		(choices "NetConnect")
		(dest "SYS:WBStartup")
		(infos)
		(optional "nofail")
	)
 )

 (foreach dist-handler-dir "#?"
	((set dist-name (tackon dist-handler-dir @each-name)
		l-name (tackon "L:" @each-name)
		dist-version (getversion dist-name)
		copy-it (NOT (exists l-name)))

	(if (NOT copy-it)
		(set copy-it (< (set l-version (getversion l-name)) dist-version)))
	(if (NOT copy-it)
		(set copy-it (set sum-differs (if (= dist-version l-version) (<> (getsum dist-name) (getsum l-name)) 0))))
	(if copy-it
		(copyfiles
			(prompt (cat "Should " l-name " be installed in L: ?\n"
				(if l-version
					(cat "A handler with the same name exists already"
						(if sum-differs
							(cat ", it has the same version, but the files are not the same.")
							(cat ", but the driver in the L: is of older version.")
						)
					)
					""
				)
			))
			(help "You should copy all handlers if you want NetConnect to work correctly.")
			(source (pathonly dist-name))
			(choices (fileonly dist-name))
			(dest "L:")
			(files)
			(optional "nofail" "askuser")
			(confirm "average")
		)
	))
 )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure copy-atcp-files-to-destination
 
 (if (exists atcp-README-FIRST-file)
		((run (cat "run " pager-cmd " \"" atcp-README-FIRST-file "\" ") (safe))
			(message "    Please read the shown \"Read Me First\" file carefully before continuing the installation.")))
 (ask-accept-license)

 (set 
  unpkt-source		AmiTCP-pkt-file
  unpkt-destination	atcp-dest
  unpkt-sdp		1
  unpkt-title-name	"AmiTCP/IP program"
  unpkt-title-not	"AmiTCP/IP"
  )
 (if (run-unpkt)
 (
	(if (NOT (= 2 (exists (tackon atcp-assign "log"))))
		(makedir (tackon atcp-assign "log")))
	(if (NOT (= 1 (exists (tackon atcp-assign "log/wtmp"))))
		(textfile (dest (tackon atcp-assign "log/wtmp"))))
	(protect (tackon bin-dir "netstat") "+s +e")
	(protect (tackon bin-dir "SynClock") "+s +e")
	(protect (tackon bin-dir "stopnet") "+s +e")
	(protect (tackon bin-dir "NapsaTerm") "+p +e")

;;; set default user to "root" since it is already defined in AmiTCP:db/passwd

(textfile (dest "ENVARC:LOGNAME")
	(append (cat "root"))
	(safe)
)
(textfile (dest "ENV:LOGNAME")
	(append (cat "root"))
	(safe)
)

	(if (>= exec-version 39)
		((set multiview-path
			(if (exists "SYS:Utilities/multiview")
				"SYS:Utilities/MultiView"
				(askfile
					(prompt "Please show where the MultiView utility can be found:")
					(help "The MultiView utility could not be located from it's normal location "
						"(\"SYS:Utilities/MultiView\"), so you need "
						"to tell the location of the utility. Give "
						"an empty name to cancel the operation.\n")
					(default "SYS:Utilities/")
				)
			)
		)
		(if (= 1 (exists multiview-path))
		(
			(if (> @user-level 1)
				(message "Installer has detected that your operating "
					"system requires you to use MultiView to "
					"browse the online documentation.\n"
					"Installer will set the tooltypes accordingly.")
				(working "Setting guide tooltypes.")
			)
			(foreach help-dir "#?.info"
				(tooltype
					(dest (tackon help-dir (substr @each-name 0 (- (strlen @each-name) 5))))
					(setdefaulttool multiview-path))))
					(transcript "Could not set MultiView as default tooltype for guide files.")
		))
	)
  1)
  0)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure update-devices

 (transcript "Updating Sana-II device drivers.")

 (if (NOT (= 2 (exists "DEVS:Networks")))
	(makedir "DEVS:Networks"))

 (working "Checking Sana-II device drivers...")

 (if (= 2 (exists dist-networks-dir))
	(foreach dist-networks-dir "#?.device"
		((set dist-name (tackon dist-networks-dir @each-name)
			devs-name (tackon "DEVS:Networks" @each-name)
			dist-version (getversion dist-name)
			copy-it (NOT (exists devs-name)))

		(if (NOT copy-it)
			(set copy-it (< (set devs-version (getversion devs-name)) dist-version)))
		(if (NOT copy-it)
			(set copy-it (set sum-differs (if (= dist-version devs-version) (<> (getsum dist-name) (getsum devs-name)) 0))))
		(if copy-it
			(copyfiles
				(prompt "Should this Sana-II driver be installed in Devs:Networks?\n"
					(if devs-version
						(cat "A driver with the same name exists already"
							(if sum-differs
								(cat ", it has the same version, but the files are not the same.")
								(cat ", but the driver in the DEVS:Networks is of older version.")
							)
						)
						""
					)
				)
				(help "    The Sana-II drivers should be located in the DEVS:Networks directory.\n"
					"    This directory is the official location for the Sana-II device drivers.")
				(source (pathonly dist-name))
				(choices (fileonly dist-name))
				(dest "DEVS:Networks")
				(files)
				(optional "nofail" "askuser")
				(confirm "average")
			)
		))
	)
	(message "No Sana-II drivers found on the installation disk")
 )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure ask-update-devices

 (if (= 2 (exists dist-networks-dir))
	(if (askbool
		(prompt "\nDo you want to update your Sana-II network device drivers?\nEach copy will be confirmed.")
		(help "    Each new AmiTCP/IP distribution usually contains updated versions of some of the provided Sana-II network "
			"device drivers. If you choose \"Yes\", this installation script will check for each device, if this is the case."))

		(update-devices)
		(transcript "User did not want to update Sana-II drivers.")
	)
	(transcript "Directory " dist-networks-dir " not found.")
 )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
;; arguments:
;;
;; uus::commands - commands to add
;; uus::section  - section name
;; uus::file     - file name into which to save the changes if needed
;;
(procedure update-user-startup

 (set uus::complete (cat ";BEGIN " uus::section "\n"
	uus::commands
	";END " uus::section "\n"))

 (set startup-changed 1)
 (startup
	uus::section
	(command uus::commands)
	(prompt "Installer will modify your S:User-Startup file. "
		"Following lines will be appended to it:\n\n"
		uus::complete)
	(help "   Installer needs to make indicated modifications to "
		"your user startup file.\n"
		"   You should make modifications later by hand if you skip this part.")
 )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure install-napsaterm

 (procedure ask-napsa-font-dir
  (askdir
	(prompt "Select directory where to install Napsaterm fonts.\n")
	(help "Here you can specify the location where to install the Napsaterm font called `napsa'. "
		"This directory should be in your font path (i.e. some directory in the assign fonts:).")
	(newpath)
	(default "fonts:")
  )
 )

 (set 
  unpkt-source		NapsaFonts-pkt-file
  unpkt-destination	(ask-napsa-font-dir)
  unpkt-sdp		1
  unpkt-title-name	"NapsaTerm fonts"
  unpkt-title-not	"NapsaTerm special fonts"
  )
 (run-unpkt)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(procedure install-user-databases

 (transcript "Installing user databases")

 (procedure get-mufs-version
	(set mufs-vernum	(getversion "multiuser.library" (resident)))
	(set mufs-ver		(/ mufs-vernum 65536))
	(set mufs-rev		(- mufs-vernum (* ver 65536)))
 )
 (procedure passwd-create
	(copyfiles
		(prompt "Copying " passwd-source " to AmiTCP:db/passwd.")
		(source passwd-source)
		(dest conf-dir)
		(newname "passwd")
		(optional "nofail"))
 )
 (procedure group-create
	    (copyfiles
	     (prompt "Copying " group-source " to AmiTCP:db/group.")
	     (source group-source)
	     (dest conf-dir)
	     (newname "group")
	     (optional "nofail")))
       
 (set passwd-source	(tackon conf-dir "passwd-example"))
 (set group-source	(tackon conf-dir "group-example"))
 (if (>= @user-level 2)
	(message "\nCopying user database from file\n\n\"" passwd-source "\"\n\n"
		"and group database from file\n\n\"" group-source "\"\n\n")
 )
 (passwd-create)
 (group-create)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(procedure set-must-reboot

 (if (<> (getversion "netinf<o.device" (resident)) 0)
	((set netinfo-temp-file "t:netinfo-expunge-script")
		(textfile (dest netinfo-temp-file)
			(append (cat 
				"failat 5000\n"
				"avail flush >nil:\n"
				"avail flush >nil:\n")
			)
			(safe)
		)
	(execute netinfo-temp-file))
 )
 (set netinfo-version (getversion "netinfo.device" (resident)))
 (if (AND (<> netinfo-version 0) (< netinfo-version 4))
	((set must-reboot-after-install 1)
	(message "You seem to have some parts of an old " atcp-name 
		" installation running.  Because of this the user "
		"database updating will have no effect before you reboot "
		"your Amiga.\n\nFor this reason you _must_ reboot after the installation "
		"and before the \"AmiTCP Prefs\" is run.")
	)
 )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Ask which parts to install
;;;
;;; on return following variables will have boolean values:
;;;
;;;  do-install-amitcp
;;;  do-install-drivers
;;;  do-install-napsafonts
;;;
(procedure ask-install-options
 (set install-options-bitmap
	(askoptions
		(prompt "Select parts to install:\n\nSee the help for explanation on each item.")
		(choices "NetConnect"
			"AmiTCP/IP"
			"Updated Sana-II network drivers"
			"NapsaTerm fonts")
		(default %1111)
		(help "NetConnect:\n"
			"Tools for launching Internet applications and for configuring AmiTCP/IP easily with a GUI.\n\n"
			"AmiTCP/IP:\n"
			"The AmiTCP/IP protocol stack. This includes binaries, documentation, help files and example configuration files.\n\n"
			"Updated Sana-II network drivers:\n"
			"If this option is checked, the Sana-II drivers in Devs:Networks will be updated. You will be asked for confirmation for each driver.\n\n"
			"NapsaTerm fonts:\n"
			"NapsaTerm has special fonts, that are sized 6×11 pixels and contain some special VT102 characters. They are suitable for interlaced "
			"screens. If you have normal NTSC or PAL screen, it might be better to not install these fonts but use Topaz/8 instead.\n")
	)

	do-install-netconnect	(in install-options-bitmap 0)
	do-install-amitcp	(in install-options-bitmap 1)
	do-install-drivers	(in install-options-bitmap 2)
	do-install-napsafonts	(in install-options-bitmap 3)
  )
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure install-netconnect

 (select-ndestination-directory)
 (if (copy-netc-files-to-destination)
	(set uus::commands (cat uus::commands
		"assign " netconnect-assign " \"" netconnect-dest "\"\n"))
 )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure install-amitcp

 (select-adestination-directory)
 (if (copy-atcp-files-to-destination)
	(set uus::commands (cat uus::commands
		"assign " atcp-assign " \"" atcp-dest "\"\n"
		"path " bin-dir " add\n"
		apipe-mount))
 )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure set-unpkt-cmd
 (set unpkt-cmd
	(if (exists UnPkt-file)
		((copyfiles
			(prompt "Copying packet dearchiver to RAM:")
			(source UnPkt-file)
			(dest   "RAM:")
			(safe)
			(optional "nofail"))
	"RAM:unlzx")
	"")
 )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure run-config-amitcp

 (set start-config-script "t:start-config-script")
 (textfile 
	(dest start-config-script)
	(append ".key foo\n.bra {\n.ket }\n\n"
		"cd " netconnect-assign "\n"
		"AmiTCPPrefs")
	(safe))
  (protect start-config-script "+s +e")
  (if (askbool
	(prompt "\nStart \"AmiTCP Prefs\" to configure the just installed " atcp-name "?")
	(help atcp-name " should be configured now. "
		"If you do not want to do the configuration now, you must "
		"do it later by starting the \"AmiTCP Prefs\" from the "
		"WorkBench icon.\n"))
	(execute start-config-script)
 )
)




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Installatation sequence
;;;

;;
;; Initialize "global" variables to default values (not complete)
;;
(set
 startup-changed		0
 must-reboot-after-install	0
 uus::commands			""
)

(complete 00) (transcript "On making " app-name ".")
(complete 01) (check-user-level)
(complete 02) (check-system-version)
(complete 03) (check-old-assign)
(complete 04) (check-cpu-type)

(set-unpkt-cmd)
(if (= unpkt-cmd "")
	(abort "    UnPkt command not present on the installation disk!"))

(set @default-dest (cat (if (= 2 (exists "Work:" (noreq)))
	"Work:" 
	(cat (getdevice "SYS:") ":"))))

(complete 10) (ask-install-options)
(complete 15) (if do-install-netconnect	(install-netconnect))
(complete 35) (if do-install-amitcp	(install-amitcp))
(complete 60) (if do-install-napsafonts	(install-napsaterm))
(complete 75) (if do-install-drivers	(update-devices))

(set uus::section	@app-name)
(set uus::file		(tackon netconnect-assign "addition-to-user-startup"))
(update-user-startup)

(if do-install-amitcp	;; Ask if old configuration should be copied
	(
		(set-must-reboot)

		(if (exists (tackon conf-dir "passwd"))
			(transcript "There is already a user database.")
			((complete 80)
			(install-user-databases)))

		(complete 90)
		(if (NOT must-reboot-after-install)
			(run-config-amitcp))
	)
)

(foreach netconnect-assign "#?.readme"
	(run (cat "run " pager-cmd) (tackon netconnect-assign @each-name)
	(safe))
)

(if do-install-netconnect 
  (if (askbool
	(prompt "\nStart \"NetConnect\" now ?")
	(help "Launches the NetConnect controller so you can get a first impression.\n\n"
		"You could - well you should - drag the \"NetConnect\" icon into SYS:WBStartup/ so it will be launched everytime you reboot."))
	(run (cat "run " netconnect-assign "NetConnect"))))

(complete 100)
(exit (if startup-changed 
	(cat "You should reboot your Amiga to enable the changes made to system startup files.")
	(cat "You must add the contents of the file(s) \"addition-to-user-startup\" to your S:User-Startup and "
		"reboot before you can use " atcp-name ".\n"))
	(if must-reboot-after-install
		(cat "\nYou MUST reboot before configuring " atcp-name ". Start \"AmiTCP Prefs\" from WorkBench after the reboot "
			"to configure your new " atcp-name " installation.\n")
	)
)
;; EOF
;;
