;;;; Hey Emacs, this script might as well be -*- lisp -*-
;;;;
;;;; Install_AmiTCP - AmiTCP/IP installation script for Installer
;;;;
;;;; Copyright  1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
;;;;
;;;; $Id: Install_AmiTCP,v 2.7 1993/11/19 23:29:13 jraja Exp $
;;;;
;;;; This script has been tested with Installer 1.24:
;;;;
;;;;     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=AmiTCP/IP
;;;; MINUSER=AVERAGE
;;;;
(welcome "    Welcome to " @app-name " 2.2 installation.\n"
	 "    We hope that after this installation your world of "
	 "communication will be much more broader than before.")
;;;;
;;;; What we are?
;;;;
(set app-name (cat @app-name " 2.2"))

;;;;
;;;; "Needs"
;;;;
(set need-version 37  ; version of operating system need by AmiTCP/IP
     need-memory (* 512 1024))
;;;
;;; Destination directories of the AmiTCP/IP
;;;
(set 
 atcp-name "AmiTCP"
 atcp-assign (cat atcp-name ":")	; Assign to AmiTCP
 ;; Application libraries etc.
 appl-dir (tackon atcp-assign "appl")
 ;; Configuration
 conf-dir (tackon atcp-assign "db")
 ;; User binaries
 bin-dir (tackon atcp-assign "bin")
 ;; documentation
 doc-dir (tackon atcp-assign "doc")
 ;; devices directory
 devs-dir (tackon atcp-assign "devs")
 networks-dir (tackon devs-dir "networks")
 ;; DOS handlers
 l-dir (tackon atcp-assign "l")
 ;; source
 src-dir (tackon atcp-assign "src")
 ;; includes for net applications
 include-dir (tackon atcp-assign "netinclude")
 ;; network link libraries
 lib-dir (tackon atcp-assign "netlib")
 ;; daemons
 serv-dir (tackon atcp-assign "serv")
 ;;
 ;; If you add directories above, then also add the name of the variable below.
 ;; This is to have "for i in a b c d ..." construct
 ;;
 ;; These directories are always present
 dir-pat (cat "(" "appl" "|" "db" "|" "bin" "|" "doc" "|" "l" "|" "serv" ")")
 ;; Optional directories
 dir-pat-opt (cat "(" "devs" "|" "netinclude" "|" "netlib" "|" "src" ")")
 ;; The source directory name
 source-dir (if (= 1 (exists @icon))
		    (pathonly (expandpath @icon))
		  (expandpath @icon))
 ;; Mounts
 tcp-mount (cat 
	    "Assign TCP: Exists > NIL:\n" 
	    "IF Warn\n"
	    "  Mount TCP: from AmiTCP:devs/Inet-Mountlist\n"
	    "EndIf\n")
 )
 ;; How to get needed information?
(set
 net-setup-help
     "    You can get this information from your network administration.\n")

;;; copy "more" to ram: to be able to use it
(set
 pager-cmd (if (exists "ENV:PAGER" (noreq)) (getenv "PAGER"))
 pager-cmd 
 (if pager-cmd 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"))))

;; Return old AmiTCP: assign if we are aborting
(onerror
 (if old-atcp-directory
     (makeassign atcp-name old-atcp-directory)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ask-ip-address
 ;;  Procedure to ask an IP address
 ;;
 ;; arguments:
 ;;  ::ask-ip-prompt   - Prompt text
 ;;  ::ask-ip-help     - help text
 ;;  ::ask-ip-need     - empty result allowed if not true
 ;;
 ;; locally used names:
 ;;  ::ask-ip-result
 (set ::ask-ip-result "<none>")
 (while
     ((set ::ask-ip-result
	   (askstring
	    (prompt ::ask-ip-prompt
		    (if (NOT ::ask-ip-need)
			(cat "\nGive an empty string if you want to "
			     "by-pass this option."))
		    (if (NOT (= ::ask-ip-result "<none>"))
			(cat "\n\nYou entered an invalid value\n\""
			     ::ask-ip-result "\".\n"
			     "Enter a valid IP address.")))
	    (default (if (<> ::ask-ip-result "<none>") ::ask-ip-result ""))
	    (help net-setup-help
		  ::ask-ip-help
		  "\n    Internet address is a string of at most four "
		  "decimal numbers separated by dots. For example, "
		  "\"130.233.161.40\" is a valid internet address.\n"
		  "    You will be asked again for the address, "
		  "if the address you entered is invalid.")))
      ;; loop while answer is unacceptable
      (if ::ask-ip-result
	  (NOT (patmatch "# #(1|2|3|4|5|6|7|8|9|0).#(1|2|3|4|5|6|7|8|9|0|.)# "
			 ::ask-ip-result))
	 ::ask-ip-need)))
 ::ask-ip-result)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 check-system-version
 ;; is your Exec recent enough?
 (set exec-version (/ (getversion) 65536))
 (transcript "Running on exec version " exec-version ".")
 (if (< exec-version need-version)	; check operating system version
     ((message @app-name " needs at least Exec version " need-version
	       " to run.\nYou have only version " exec-version ".\n"
	       "You can proceed with the installation, but consider "
	       "installing the " @app-name " with proper version of "
	       "the operating system."
	       (help
		"    The " @app-name " uses some system functions "
		"that are not present or functional in earlier system "
		"versions. Consider updating your system.\n"
		"    If you have a later version of operating system "
		"and are only now using older version: be sure to use "
		"only release 2.04 or newer with " @app-name ". "
		"No damage happens if you run " @app-name " with an "
		"earlier operating system, however. It just "
		"refuses to start.\n"
		"    If you decide to continue, no changes will be made to "
		"system startup files, so you must edit them yourself. "
		"Refer instructions for manual installation."))
      (transcript "User decided to continue installation while running "
		  "on operating system release earlier than 2.04."))))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 check-available-memory
 ;;
 (transcript "Checking available memory.")
 (set avail-mem (+ (database "total-mem")))
 (if (< avail-mem need-memory)
     ((message "Your system has only " (/ avail-mem 1024) " kilobytes of "
	       "free memory, while " @app-name " needs at least "
	       (/ need-memory 1024) " to be useful.\n"
	       "You can continue the installation but be warned!")
      (transcript "User decided to continue installation while available "
		  "memory was below the recommended minimum."))))

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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 check-old-assign
 ;; If there is already the AmiTCP/IP installed, store the assign
 ;; to old-atcp-directory
 (transcript "Checking for already installed AmiTCP.")
 (if (exists atcp-assign (noreq))
     (set old-atcp-directory (getassign atcp-name)))
 (if old-atcp-directory
     (transcript "Existing AmiTCP detected at directory " 
		 old-atcp-directory ".")))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 select-destination-directory
 ;; Select destination directory for the installation. We suggest the user
 ;; to install to the place from where the installer was started. This is
 ;; since normally this software will be unarchived to its proper location
 ;; and the files don't have to be copied any more.
 ;;
 (transcript "Selecting destination directory for the installation.")
 (while
     ((set @default-dest
	   (askdir
	    (prompt "Select directory where to install " @app-name ".\n"
		    "Most of the files don't have to be copied, if you accept "
		    "the offered default.")
	    (help "    Here you can specify location where to install "
		  "the " @app-name ".\n"
		  "    Installation can be made on-place. "
		  "This is recommended if you have already unarchived "
		  "the " @app-name " archive to its final location. "
		  "In this case "
		  "most of the files are left where they are. "
		  "Only necessary files are copied to different "
		  "positions.\n"
		  "    Installation must NOT be made on top of the 1.0 "
		  "version of the " @app-name)
	    (newpath)
	    (default source-dir)))
      (if (= 2 (exists @default-dest))
	  ;; check that installation is not tried over the old version
	  (if (OR (exists (tackon @default-dest "bin/AmiTCP")) ; version 1.0
		  (> (getversion (tackon source-dir "AmiTCP"))
		     (if (exists (tackon @default-dest "AmiTCP"))
			 (getversion (tackon @default-dest "AmiTCP"))
		       $7FFFFFFF)))
	      ((message "You are possibly trying to install " @app-name " "
			"over an old version of it.\n"
			"It is not allowed.\n"
			"You should select some other directory or abort "
			"the installation.")
	       1)
	    0)
	((makedir @default-dest
		 (infos))
	 0))))

 ;; Make the AmiTCP: assign
 (makeassign atcp-name @default-dest))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 copy-files-to-destination ;;; Copy all files if not installing on-place
 ;;
 (if (= source-dir
	(expandpath @default-dest))
     (message "\nSource and destination directories are the same, "
	      "not copying."
	      (help "    The " @app-name " files don't have to be copied, "
		    "since the source and destination directory are "
		    "the same"))
   ((transcript "Copying " @app-name " files from " source-dir " to "
		@default-dest ".")
    (set dir-information
	 (cat
	  (if (exists "devs")
	      "devs - SANA-II device drivers\n")
	  (if (exists "netinclude")
	      (cat "netinclude - include files needed for networking "
		   "applications development\n"))
	  (if (exists "netlib")
	     "netlib - link libraries for networking program development\n")
	  (if (exists "src/appl")
	      "src/amitcp - source code for applications\n")
	  (if (exists "src/amitcp")
	      "src/amitcp - source code for AmiTCP/IP\n")
	  (if (exists "src/devs")
	      "src/util - source code for network device drivers\n")
	  (if (exists "src/util")
	      "src/util - source code for utilities\n")
	  ))
    (if (< 0 (strlen dir-information))
	(if (askbool
	     (prompt "\nDo you want directories needed only with development "
		     "of " @app-name " or applications to be copied?")
	     (help "    These directories (and their contents) is "
		   "not needed to use AmiTCP/IP. "
		   "You need to copy them only when you plan to "
		   "make network programs by yourself.\n"
		   "    Description of directories:\n"
		   dir-information
		   (if (= @user-level 1)
		       "    If you select EXPERT level at start, you "
		     "    You ")
		   "will be prompted for each directory.\n"))
	    (foreach
	     source-dir dir-pat-opt
	     (copyfiles
	      (source source-dir)
	      (choices (fileonly @each-name))
	      (confirm)
	      (dest @default-dest)
	      (prompt
	       (if (= @user-level 1)
		   "Copying files to selected location."
		 "Copy this directory?"))
	      (help "    Description of directories:\n"
		    dir-information)
	      (optional "askuser")))))
    (foreach source-dir dir-pat
	     ((set dest-dir (tackon @default-dest @each-name))
	      (if (NOT (exists dest-dir))
		  (makedir dest-dir))
	      (copyfiles (all)
			 (source (expandpath @each-name))
			 (dest dest-dir)
			 (prompt "Copying files to the selected location.")
			 (optional "askuser"))))
    (copyfiles (source source-dir)
	       (dest @default-dest)
	       (prompt "Copying files to the selected location.")
	       (pattern "#?")
	       (files)
	       (infos)
	       (optional "askuser"))))
 ;;
 ;; Add script flags to the scripts, pure flags to pure programs
 ;;
 (protect (tackon bin-dir "netstat") "+s +e")
 (protect (tackon bin-dir "SynClock") "+s +e")
 (if (exists src-dir)
     (protect (tackon src-dir "compile") "+s +e"))
 (protect (tackon bin-dir "NapsaTerm") "+p +e")
 (protect (tackon serv-dir "in.fingerd") "+p +e")
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ask-hostname ;; Get host name and default domain
 ;;
 (procedure
  setenv-hostname ;; Store hostname to the environment variable
  ;;
  ;; Tell the user that the environment variable HOSTNAME will be used.
  ;;
  (if
      (askbool
       (prompt "\nThe host name \"" my-full-name "\" will be stored to the "
	       "environment variable HOSTNAME where networking code "
	       "assumes it to be found.\n"
	       "This can be done in two ways: Either the variable is "
	       "stored to the ENV: and ENVARC: or a \"setenv\" command "
	       "is put to the s:user-startup.\n\n"
	       "Choose which to do:")
       (choices "Store to ENV(ARC):" "Use \"setenv\"")
       (default 1)
       (help "    This variable must be set for the applications "
	     "to work correctly.\n"
	     "    The ENVARC: is the standard place to store environment "
	     "variables which must not peridh on a re-boot. "
	     "Select \"setenv\" only if you are sure that it is needed."))
      ((set use-setenv-to-set-hostname 0)
       (if (= 2 (exists "ENV:"))
	   (textfile (dest "ENV:HOSTNAME")
		     (append my-full-name)))
       (if (= 2 (exists "ENVARC:"))
	   (textfile (dest "ENVARC:HOSTNAME")
		     (append my-full-name))))
    ;; this variable will be used when the user-startup is updated
    (set use-setenv-to-set-hostname 1)))
 ;;
 ;; Get the hostname from environment variable
 ;;
 (set def-full-name (if (exists "ENV:HOSTNAME")
			(getenv "HOSTNAME")
		      "")
      my-host-name ""
      my-domain-name "")
 ;;
 ;; Break the name into the host and domain parts
 ;;
 (set ::index 0
      ::length (strlen def-full-name))
 (while (AND (< ::index ::length)
	     (NOT (= (substr def-full-name ::index 1) ".")))
   (set ::index (+ ::index 1)))
 (if (= ::index ::length)
     (set def-host-name ""
	  def-domain-name "")
   (set def-host-name (substr def-full-name 0 ::index)
	def-domain-name (substr def-full-name (+ ::index 1))))
 ;;
 ;; Ask the host name from the user
 ;;
 (while (OR (= my-host-name "")
	    ;; check that name has no dots
	    ((set ::index 0
		  ::length (strlen my-host-name))
	     (while (AND (< ::index ::length)
			 (NOT (= (substr my-host-name ::index 1) ".")))
	       (set ::index (+ ::index 1)))
	     (NOT (= ::index ::length))))
   (set my-host-name
	(askstring
	 (prompt
	  (cat "\nEnter the host name of your computer (not including "
	       "domain)"
	       (if (= my-host-name "")
		   ":"
		 (cat ".\nThe value " my-host-name " is illegal, since it "
		      "contains a dot."))))
	 (help net-setup-help
	       "    Host name is a string NOT containing dots (.), "
	       "example: \"my-amiga\".\n"
	       "    Domain specifies the administrative domain of the "
	       "network where your host is connected. For example, "
	       "\"hut.fi\" is the domain name of the Helsinki "
	       "University of Technology in Finland.\n")
	 (default def-host-name))))
 ;;
 ;; ask the domain name from the user
 ;;
 (while (= my-domain-name "")
   (set my-domain-name
	(askstring
	 (prompt "\nEnter the domain part of your host name:")
	 (help net-setup-help
	       "    Domain specifies the administrative domain of the "
	       "network where your host is connected. For example, "
	       "\"hut.fi\" is the domain name of the Helsinki "
	       "University of Technology in Finland.\n")
	 (default def-domain-name))))
 (set my-full-name (cat my-host-name "." my-domain-name))
 (setenv-hostname))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ask-aliases
 ;;
 (set my-host-aliases my-host-name)
 (while
     (set new-host-name
	  (askstring
	   (prompt "Give aliases to your computer " my-full-name
		   " one at a time."
		   (if my-host-aliases
		       (cat "\n\nAliases are:\n" my-host-aliases)))
	   (default (if my-host-aliases "" my-host-name))
	   (help net-setup-help
		 "    Your computer may have additional names "
		 "(aliases) to its official name. It is a customary "
		 "to have at least one alias, which "
		 "is the official host name without the domain part.\n")))
   (set my-host-aliases (cat my-host-aliases " " new-host-name))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ask-domains
 ;;
 (set domain-list ""
      text-domain-list "")
 (while
     (set domain
	  (askstring
	   (prompt
	    "Give domain names (one at a time) to search.\n"
	    "Press proceed after you have given each domain.\n"
	    "Give empty domain after you have finished.\n"
	    (if text-domain-list
		(cat "\nIncluded domains are:"
		    text-domain-list)))
	  (help
	   net-setup-help
	   "    In many environments more than one search domain "
	   "is needed for name resolution.\n"
	   "    For example, most of computers in the Helsinki "
	   "University of Technology are under single domain: "
	   "\"hut.fi\", so the full name of computer named "
	   "\"vipu\" would be \"vipu.hut.fi\". If the default "
	   "domain is \"hut.fi\", then this computer can be "
	   "referred without the domain part of the name (just "
	   "\"vipu\"). However, the computer science department "
	   "has its own domain \"cs.hut.fi\". When computers of "
           "the computer science department "
	   "are referred, the full name must be supplied, e.g. "
	   "\"colossus.cs.hut.fi\". This can be avoided by "
	   "providing \"cs.hut.fi\" as a secondary search domain. "
	   "The domains are searched in the given order. It is "
	   "fastest to give the most used domain first.\n"
	   "    In Unix systems the domain names are "
	   "usually stored into the file `/etc/resolv.conf`.\n")
	  (default (if domain-list "" my-domain-name))))
  (set domain-list ("%sDOMAIN %s\n" domain-list domain)
       text-domain-list (cat text-domain-list "\n" domain)
       default-domain "")))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 update-devices
 (transcript "Updating Sana-II device drivers.")
 ;;
 ;; Create directory DEVS:Networks if it does not exist already
 ;;
 (if (NOT (= 2 (exists "DEVS:Networks")))
     (makedir "DEVS:Networks"))
 ;;
 ;; Copy each driver in the distribution to the DEVS:Networks if necessary
 ;;
 (working "Checking Sana-II device drivers...")
 (set dist-networks-dir (tackon source-dir "devs/networks"))
 (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)))
	;;
	;; Check if the driver should be copied over
	;;
	(if (NOT copy-it)
	    (set copy-it
	             ; or if the driver in DEVS:Networks is of older version
		 (< (set devs-version (getversion devs-name)) dist-version)))
	(if (NOT copy-it)
	    (set copy-it
		     ; or if the files are of the same version but different
		 (set sum-differs (if (= dist-version devs-version)
				      (<> (getsum dist-name)
					  (getsum devs-name))
				    0))))
	(if copy-it
	    (copyfiles
	     (prompt "Confirm the copy.\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. Some other software may be able to use the "
	      "drivers, if they are copied over.")
	     (source (pathonly dist-name))
	     (choices (fileonly dist-name))
	     (dest "DEVS:Networks")
	     (files)
	     (optional "nofail" "askuser")
	     (confirm "average"))))))

 ;;; ask user which env/sana2 files should be copied
 (if (= 2 (exists (tackon source-dir "env/sana2")))
     (if
	 (askbool (prompt "\nDo you want to install example Sana-II "
			  "configuration files?\n"
			  "Copies will be confirmed.")
		  (help "    This release contains example configuration "
			"files for the SLIP devices and Agnet (a Sana-II "
			"pseudo device).\n"
			"    The copying of each file will confirmed.")
		  (default 1))
	 (copyfiles
	  (prompt "Select Sana-II configuration files to be copied:")
	  (help "    These configuration files are for example only. "
		"You need to edit them for them to be useful. Refer to "
		"the documentation of the Sana-II device in question. "
		"The AmiTCP:doc directory contains documentation for "
		"the drivers included in this release.\n"
		"    The files will be copied to the ENVARC: by default. "
		"Normally they will be copied to ENV: on next reboot.")
	  (source (tackon source-dir "env/sana2"))
	  (dest "ENVARC:sana2")
	  (all)
	  (files)
	  (optional "nofail" "askuser")
	  (confirm "average")))
   ))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Ask network interfaces
;;;
;;; Loop until no device is given.
;;;
(procedure
 ask-interfaces
 ;;
 ;; Procedure to ask the network device driver name
 ;;
 ;; (Returns TRUE if an interface file exists..)
 ;;
 (procedure
  if-ask-device
  (while
      ((set my-host-if
	    (askfile
	     (prompt
	      "Select a SANA-II device driver. If you have set "
	      "up all your interfaces, just press proceed.")
	     (default "Devs:Networks")
	     (help
	      "    Select the name of a SANA-II device to be used, "
	      "like \"a2065.device\" or \"rhslip.device\" for the "
	      "A2065 ethernet adapter or SLIP driver, respectively.\n"
	      "    Primary address of your computer is the one "
	      "with which your computer will most often be referenced.\n"
	      "    If you are going to attach your computer to "
	      "several networks (by using many network "
	      "adapters), different address must be assigned to "
	      "each adapter.\n"
	      "    When you have configured all your network "
	      "interfaces, select no file to continue. This can be done by "
	      "entering nothing to the \"file\" gadget.")))
       ;;
       ;; Try to ensure that we get at least 1 SANA-II network interface
       ;;
       (if (AND (= address-list "")
		(= 2 (exists my-host-if)))
	   (askbool
	    (prompt
	     "\nYou have not defined any SANA-II network interface for "
	     "the " @app-name ". You should define at least one "
	     "external interface. It is crucial for the correct "
	     "operation even if you are using " @app-name " "
	     "locally with internal loopback device.\n"
	     "    For the moment you can give "
	     "the interface a random IP address (eg. 126.1). "
	     "Reinstall " @app-name " when you get a real "
	     "network connection.\n\n"
	     "Do you want to define a network interface for "
	     @app-name "?")
	    (help
	     "    Each IP packet must be given a source address. "
	     "AmiTCP/IP stamps each packet which it sends with an "
	     "address of some external interface. "
	     "Because of an internal design of the AmiTCP/IP, "
	     "the source address can not be local. (Local address is "
	     "any address configured to the internal loopback "
	     "interface, normally 127.1).\n")))))
  ;; If user gives no file, a directory is actually given
  (if (= 2 (exists my-host-if))
      ""
    my-host-if))

 ;;
 ;; Ask for the unit number
 ;;
 (procedure
  if-ask-unit
  (set my-host-if-unit
       (asknumber
	(prompt "\nSelect unit number for the " my-host-if ":")
	(default 0)
	(help "    Select the unit number for the SANA-II device driver "
	      my-host-if " to use. This is usually 0 for the first "
	      "unit of that particular device. "
	      "Refer your device driver documentation for "
	      "correct number to use."))))

 ;;
 ;; Ask for the IP address of this host
 ;;
 (procedure
  if-ask-address
  (set ::ask-ip-prompt (cat "IP address for the interface " my-host-if
			    "/" my-host-if-unit ".\n"
			    "Each interface must have an unique\n"
			    "Internet Protocol address.")
       ::ask-ip-help (cat "    If you have no actual network connection, "
			  "you may give a nonexistent IP number for "
			  "your external interface.")
       ::ask-ip-need 1
       my-host-addr (ask-ip-address)))

 ;;
 ;; Ask for the optional destination address
 ;;
 (procedure
  if-ask-dest-address
  (set ::ask-ip-prompt (cat "Give the destination address for the "
			    my-host-if "/" my-host-if-unit ".\n"
			    "Address of interface is " my-host-addr ".\n"
			    "This is should give the destination address "
			    "ONLY if you have a point-to-point interface "
			    "(e.g. SLIP). You should give NO destination "
			    "address for broadcast interface (e.g. Ethernet)."
			    "\n")
       ::ask-ip-help (cat
		      "    A point-to-point device is one that is connected"
		      " to a medium which only two devices can attach, for "
		      "example the normal serial line: your computer is in "
		      "other end and the other computer is on the other "
		      "end (maybe via modem, that does not change it).\n"
		      "    Ethernet, for example, is not a "
		      "point-to-point device because several devices "
		      "can connect to single physical medium.")
       ::ask-ip-need 0
       dest-host (ask-ip-address)))

 ;;
 ;; Ask for the netmask for this interface. If nothing is given,
 ;; a default value will be used by the ifconfig.
 ;;
 (procedure
  if-ask-netmask
  (set ::ask-ip-prompt (cat "Netmask of network on interface " my-host-if
			    "/" my-host-if-unit ".\n"
			    "Address of interface is " my-host-addr
			    (if dest-host
				(cat ",\ndestination address is " dest-host ".\n")
			      (cat ".\n")))
       ::ask-ip-help (cat "    Netmask is a dot separated string of four "
			  "decimal numbers (similar "
			  "to an internet address), which specifies which "
			  "bits of the host address are used as the "
			  "network address.\n"
			  "    For example, \"255.255.255.0\" "
			  "is a possible netmask.\n"
			  "    The netmask must be same for all interfaces "
			  "connected to the same network.\n"
			  "    If you do NOT give a netmask (i.e. leave it "
			  "empty), it will be computed from your interface "
			  "address. This is correct only if the network "
			  "is not divided into subnets.")
       ::ask-ip-need 0
       my-host-netmask (ask-ip-address)))

 ;;
 ;; Ask for confirmation on given information
 ;;
 (procedure
  if-confirmation
  (askbool
   (prompt "This is the information you gave for this interface:\n"
	   "\nSANA-II driver: " my-host-if
	   "\nUnit number: " my-host-if-unit
	   "\nInterface address: " my-host-addr
	   "\nDestination address: " (if (= dest-host "") "<none>"
				       dest-host)
	   "\nNetmask: " (if (= my-host-netmask "") "<use default>"
			   my-host-netmask)
	   "\n\nIs this correct?")
   (help "    Check the information shown. If you do not confirm it, "
	 "all of it will be asked again.")))

 ;;
 ;; Set startup string to contain configuration for the loopback device
 ;; (Other information will be later appeneded to this string variable).
 ;;
 (set su-script
      (cat "; configure loop-back device\n"
	   (tackon bin-dir "ifconfig") " lo/0 localhost\n")
      ;; a complete list for IP address to host name mappings..
      address-list "")
 ;;
 ;; Ask for interfaces
 ;;
 (while
     (if-ask-device)
   (if-ask-unit)
   (if-ask-address)
   (if-ask-dest-address)
   (if-ask-netmask)
   (if (if-confirmation)
       ((transcript "Adding interface " my-host-if "/" my-host-if-unit )
	(set
	 ;; Add this interface to the script string
	 su-script
	 (cat su-script
	      "; Configure " my-host-if " unit " my-host-if-unit "\n"
	      (tackon bin-dir "ifconfig") " "
	      my-host-if "/" my-host-if-unit " " my-host-addr " "dest-host
	      (if my-host-netmask
		  (cat " netmask " my-host-netmask))
	      "\n")
	 ;; Add IP address entry for this IP number
	 address-list
	 (cat address-list
	      "HOST " my-host-addr " " my-full-name " " my-host-aliases "\n")
	 )))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ask-gateway ;;; Ask the default gateway address
 ;;
 (set ::ask-ip-prompt "Enter the IP address of the default gateway:"
      ::ask-ip-help (cat
		     "    All network packets for destinations for which "
		     "there is no defined route, are sent to the default "
		     "gateway, which (hopefully) can send them towards "
		     "the destination host.\n"
		     "    The IP address (instead of a name) is needed, "
		     "because the name may not be resolved without the "
		     "gateway, if the name server is not "
		     "in your local network.")
      ::ask-ip-need 0
      def-gateway-addr (ask-ip-address))
 ;;
 (set su-script
      (cat su-script
	   "; Add route to this host\n"
	   (tackon bin-dir "route") " add " my-full-name " localhost\n"
	   (if def-gateway-addr
	       (cat "; Add route to the default gateway\n"
		    (tackon bin-dir "route")
		    (" add default %s\n" def-gateway-addr))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ask-nameservers ;;; Ask addresses to the name servers
 ;;
 (set name-server-list ""
      name-server-text-list "")
 (while
     (set ::ask-ip-prompt
	  (cat "Enter the IP addresses of the name servers (one at a time). "
	       "The name servers will be searched in the given order.\n"
	       (if name-server-text-list
		   ("\nIncluded name servers are: %s\n"
		    name-server-text-list)))
	  ::ask-ip-help
	  (cat "    A name server is used to resolve host "
	       "names to internet addresses. This allows you "
	       "to use symbolic names for the hosts instead "
	       "of internet addresses.\n"
	       "    In Unix systems the name server addresses are "
	       "usually stored into the file `/etc/resolv.conf`.\n")
	  ::ask-ip-need 0
	  name-server-addr (ask-ip-address))
   (set name-server-list (cat name-server-list
			      "NAMESERVER " name-server-addr "\n")
	name-server-text-list (cat name-server-text-list "\n"
				   name-server-addr))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 create-config-file
 ;;
 (textfile (dest (tackon conf-dir "netdb-myhost"))
	   (append
	    (if address-list (cat "; This host\n" address-list)))
	   (append
	    (if domain-list (cat "; Domain names\n" domain-list)))
	   (append
	    (if name-server-list (cat "; Name servers\n" name-server-list)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 create-startup-script
 ;;
 ;; Create the network startup-script (AmiTCP:bin/startnet)
 ;;
 (textfile (dest (tackon bin-dir "startnet"))
	   (append
	    "run AmiTCP:AmiTCP\n"
	    "WaitForPort AMITCP\n"
	    "Wait 2 secs\n")
	   (append su-script)
	   (append tcp-mount)
	   (append
	    (if (askbool
		 (prompt "\nDo you want the Inetd to be started at the "
			 @app-name " startup?\n")
		 (help "    Inetd is the Internet `Super Server', which "
		       "listens for connections on behalf of other "
		       "servers. When a connection request for a port, "
		       "for which Inetd is configured to listen, arrives "
		       "Inetd accepts the connections and starts the "
		       "server in question.\n"
		       "    The file " (tackon conf-dir "inetd.conf")
		       " contains the configuration information for the "
		       "Inetd, which you will want to edit.\n"
		       "    Currently only finger daemon is distributed "
		       "with " @app-name ".\n"
		       "    Refer to the documentation for more information."))
		(cat "; Start the internet `super server'\n"
		     "run AmiTCP:bin/inetd\n")
	      "\n")))
 (protect (tackon bin-dir "startnet") "+s +e"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 update-user-startup
 ;;
 (set to-be-added-to-startup
      (cat (if use-setenv-to-set-hostname
	       (cat "setenv HOSTNAME " my-full-name "\n")
	     "")
	   "assign " atcp-assign " " @default-dest "\n"
	   "path " bin-dir " add\n"
	   (if (askbool
		(prompt
		 "\nDo you want the " @app-name
		 " to be started at the system startup?")
		(help
		 "    If you decide not to start " @app-name " at startup, "
		 "you can later start it by giving command\n\n"
		 "run " (tackon bin-dir "startnet")
		 "\n\n at the command shell."))
	       ((set started-at-boot 1)
		(cat "run " (tackon bin-dir "startnet\n")))
	     ((set started-at-boot 0)
	      ""))
	   (if (AND
		(= 2 (exists include-dir))
		(= 2 (exists lib-dir)))
	       (if (askbool
		    (prompt "\nDo you want to add assigns to "
			    "netinclude and netlib directories?")
		    (help "    These assigns are only needed for compiling "
			  "programs using the " @app-name "."))
		   (cat "; assigns for programmers\n"
			"assign netinclude: " include-dir "\n"
			"assign netlib: " lib-dir "\n"))))
      complete-to-be-added-to-startup (cat ";BEGIN " @app-name "\n"
					   to-be-added-to-startup
					   ";END " @app-name "\n"))
 ;; Ask for confirmation to add
 (if (>= exec-version 37)
     (if
	 (askbool
	  (prompt "\nDo you want Installer to make the required changes to "
		  "your s:user-startup script?\n"
		  "\n(There is a problem with Installer making these "
		  "changes if you do not have the original boot volume "
		  "mounted. Installer may crash or corrupt your system "
		  "in that case.)")
	  (help "If you do not want Installer make the changes, it will "
		"create a script file containing commands which you should "
		"add to the s:user-startup file."))
	 ;; Do the addition
	 (startup
	  @app-name
	  (command to-be-added-to-startup)
	  (prompt "Installer will modify your S:User-Startup file. "
		  "Following lines will be appended to it:\n\n"
		  complete-to-be-added-to-startup)
	  (help "   Installer needs to make indicated modifications to "
		"your user startup file to make sure that everything is "
		"correctly set up to run " @app-name ".\n"
		"   You should make modifications later by hand "
		"if you skip this part."))
       ;; Let user add commands
       ((set addition-to-user-startup
	     (tackon atcp-assign "addition-to-user-startup"))
	(textfile (dest addition-to-user-startup)
		  (append complete-to-be-added-to-startup))
	(message "Installer created file " addition-to-user-startup
		 ", which you can add to your startup file by hand. "
		 "The file includes following changes:\n\n"
		 complete-to-be-added-to-startup)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ask-copy-old-configuration
 ;;
 ;; Copy old configuration files
 ;;
 (set
  edit-change-fingerd "t:edit-change-fingerd"
  old-conf-dir (tackon old-atcp-directory "db")
  old-netdb-myhost (tackon old-conf-dir "netdb-myhost")
  old-startnet (tackon old-atcp-directory "bin/startnet"))
 ;;
 (procedure 
  copy-myhost-config 
  (if (>= @user-level 2)
      (message "\nCopying files\n\n"
	       old-netdb-myhost "\n"
	       old-startnet "   \n"
	       "\nto directory \"" @default-dest "\"."))
  (copyfiles
   (source old-netdb-myhost)
   (dest conf-dir)
   (files))
  (copyfiles
   (source old-startnet)
   (dest bin-dir)
   (files)))
 ;;
 (procedure 
  copy-rest-config
  (copyfiles
   (prompt
    "Select configuration files you want to copy from old configuration")
   (help
    "    You may copy your old configuration files or use untouched files "
    "came with the new distribution.")
   (source old-conf-dir) 
   (dest conf-dir)
   (files)
   (confirm)
   (if (exists (tackon old-conf-dir "passwd"))
       (choices
	"AmiTCP.config"
	"inetd.conf"
	"netdb"
	"hosts"
	"services"
	"protocols"
	"passwd"
	"group")
     (choices 
      "AmiTCP.config"
      "inetd.conf"
      "netdb"
      "hosts"
      "services"
      "protocols"))
   (optional "nofail" "force" "askuser")))
 ;;
 (procedure 
  update-startnet
  (set startnet-file (tackon bin-dir "startnet"))
  (if (run (cat "search search \"Mount TCP:\" quiet from " startnet-file)
	   (safe))
      ((textfile (dest startnet-file)
		 (include startnet-file)
		(append tcp-mount "\n")
		(prompt 
		 "\nDo you want to mount TCP: device at network startup?")
		(help 
		 @app-name " includes a DOS handler for TCP communications. "
		 "This DOS handler will usually be mounted at network "
		 "startup.")
		(confirm))
       (protect (tackon bin-dir "startnet") "+s +e"))))
 (procedure
  update-services
  (set service-file (tackon conf-dir "services"))
  (if (run (cat "search search \""amiganetfs"\" quiet from " service-file)
	   (safe))
      (;; Not found, add it 
       (textfile (dest service-file)
		 (include service-file)
		(append ";\n; Amiga specific services\n;\n"
			"amiganetfs      2500/tcp\n")
		(prompt 
		 "Do you want to add AmigaNetFS service to your "
		 "service database?")
		(help 
		 @app-name " includes NetFS, network file system between "
		 "Amigas, by Timo Rossi. It is a TCP based protocol which "
		 "requires both ends of connection have same service "
		 "(TCP port) entries. If you already had NetFS installed "
		 "you probably do not want to update your service "
		 "database.")
		(confirm)))))
 (procedure
  update-inetd-conf
  ;; Change fingerd to serv/in.fingerd
  (set inetd-conf (tackon atcp-assign "db/inetd.conf"))
  (if (run (cat "search search \"serv/in.fingerd\" quiet from " inetd-conf)
	   (safe))
      ((textfile 
	(dest edit-change-fingerd)
	(append
	 "f b/finger    stream/\n"
	 "e -amitcp:bin/fingerd-amitcp:serv/in.fingerd-\n"
	 "m+"
	 "i"
	 "# NetFS, a networking support between Amigas"
	 "# Remove # from the next line to enable NetFS"
	 "#amiganetfs stream    tcp nowait root amitcp:serv/netfs-server"
	 "Z"
	 "w\n")
	(safe))
       (run (cat "c:edit from " inetd-conf " with "
		 edit-change-fingerd " >t:what-changed")
	    (confirm)
	    (prompt "\nUpdate \"inetd.conf\" to use " @app-name " services?")
	    (help "    The fingerd service daemon is moved to directory "
		  "\"AmiTCP:serv\", and \"inetd.conf\" must be updated to use "
		  "it. Also the NetFS must be added to old configuration")))))
 ;;
 (procedure 
  update-napsaprefs
  (set old-napsaprefs
       (if (exists (tackon old-atcp-directory "db/NapsaPrefs") (noreq))
	   (tackon old-atcp-directory "db/NapsaPrefs")
	 (if (exists "s:NapsaPrefs")
	     "s:NapsaPrefs")
	 ""))
  (if old-napsaprefs
      (;;
       (copyfiles 
	(source old-napsaprefs)
	(dest conf-dir)
	(files)
	(confirm)
	(prompt "\nUse your old Napsaterm preferences?")
	(help  "    Installer have found an existing NapsaPrefs file "
	       old-napsaprefs ". You can copy it to new configuration "
	       "directory.")))))
 (procedure 
  copy-extra-binaries
  "")
 (transcript "Ready to copy old configuration.")
 (if (askbool
      (default 1)
      (prompt
       "\nDo you want to use settings from earlier installation?")
      (help
       "    Installer have detected existing configuration "
       "directory \"" old-conf-dir "\" which "
       "can be used to configure " @app-name ". You can keep most "
       "of your previous configuration. This is important if you have "
       "installed extra applications.\n"
       "    Installer will copy your \"" old-startnet "\" script and "
       "\"" old-netdb-myhost "\" configuration "
       (if (> @user-level 1) 
	   "and optionally "
	 "then ")
       "other configuration files" (if "" "and binaries") ".\n"))
     ((copy-myhost-config)
      (copy-rest-config)
      (update-inetd-conf)
      (update-services)
      (update-startnet)
      (update-napsaprefs)
      (copy-extra-binaries)
      "Already configured")
   ""))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 install-emacstcp
 ;; is GNU Emacs is installed?
 (if (exists "GNUEmacs:" (noreq)) ; check if GNUEmacs is installed
     (if (exists (tackon source-dir "appl/EmacsTCP"))
	 ((transcript "Installing EmacsTCP.")
	  (copyfiles
	   (source (tackon source-dir "appl/EmacsTCP/lisp"))
	   (prompt "Copying GNU Emacs lisp files to GNUEmacs:lisp")
	   (help "   Emacs lisp files implement the Emacs side of the "
		 "Gnu Emacs TCP support.")
	   (pattern "#?.el#?")
	   (dest "GNUEmacs:lisp")
	   (optional "nofail" "askuser")
	   (confirm))
	  (copyfiles
	   (source (tackon source-dir "appl/EmacsTCP/etc"))
	   (choices "tcp_AmiTCP")
	   (prompt "Copying tcp_AmiTCP (program) to GNUEmacs:etc")
	   (help "   tcp_AmiTCP implements the " @app-name " side of the "
		 "Gnu Emacs TCP support.")
	   (dest "GNUEmacs:etc")
	   (optional "nofail" "askuser")
	   (confirm))
	  (if (exists "GNUEmacs:etc/tcp_AmiTCP")
	      (protect "GNUEmacs:etc/tcp_AmiTCP" "+p")) ; tcp is pure
	  ;; Tell user what to do with .emacs
	  (run (cat "run " pager-cmd)
	       (tackon source-dir "appl/EmacsTCP/add_to_.emacs")
	       (safe)))
       (message "EmacsTCP not present in " source-dir "."))
   (message "GNU Emacs must be installed before EmacsTCP.")))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ask-install-emacstcp
 ;; is GNU Emacs is installed?
 (if (exists "GNUEmacs:" (noreq)) ; check if GNUEmacs is installed
     (if (exists (tackon source-dir "appl/EmacsTCP"))
	 (if (askbool
	      (prompt "\nDo you want to install needed files for GNU Emacs "
		      "support?")
	      (help
	       "    Installer has noticed that you have GNUEmacs: assigned "
	       "in your system. Normally this means that you have the "
	       "GNU Emacs installed.\n"
	       "    AmiTCP/IP provides an Emacs extension, which makes "
	       "it possible to run networking programs with it. To enable "
	       "this feature some files need to be installed "
	       "in to directories under \"GNUEmacs:\".\n"
	       "    If you select \"Yes\", files will be installed and you "
	       "will be able to use TCP/IP applications written for "
	       "GNU Emacs."))
	     (install-emacstcp)
	   (transcript "User denied adding AmiTCP/IP support for GNU Emacs."))
       (transcript "EmacsTCP not present on " source-dir "."))
   (transcript "No GNU Emacs detected in system.")))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 install-napsaterm
 ;;
 ;; Install Napsaterm fonts
 ;;
 ;; Ask for directory to install fonts.
 (procedure
  ask-napsa-font-dir
  (askdir
   (prompt "Select directory where to install Napsaterm fonts.\n")
   (help "    Here you can specify 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:")))
 (copyfiles
  (source (tackon source-dir "appl/napsaterm/fonts"))
  (prompt "Copying font `napsa' to " napsa-font-dir ".")
  (dest (ask-napsa-font-dir))
  (optional "nofail")
  (fonts)
  (all)))

(procedure
 ask-install-napsaterm
 ;; Optionally intall Napsafonts
 (if (askbool
      (prompt "Do you want to install Napsaterm fonts, napsa?\n"
       "\n    (Napsaterm uses the special fonts in its window "
       "if they are installed. "
       "They are sized 611 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 Napsa and use Topaz/8.)\n")
      (help
       "    Napsaterm is a VT102 terminal emulator which uses the rlogin "
       "protocol. You can have a remote login to many hosts in Internet "
       "with Napsaterm.\n"
       "    Napsaterm is based on the Niftyterm 1.2 written by "
       "Todd Williamson and Christopher J. Newman."))
     (install-napsaterm)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ;;
 ;; Install passwd and group databases
 ;;
 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 (tackon source-dir "db"))
	     (newname "passwd")
	     (optional "nofail")))
 (procedure group-create
	    (copyfiles
	     (prompt "Copying " group-source " to AmiTCP:db/group.")
	     (source group-source)
	     (dest (tackon source-dir "db"))
	     (newname "group")
	     (optional "nofail")))
 ;; If we are running multiuser 1.4, do some special
 (get-mufs-version)
 (if mufs-vernum
     (transcript ("Multiuser.library %ld.%ld found" mufs-ver mufs-rev)))
 (if (or (> mufs-ver 39)
	 (and (= mufs-ver 39) (>= mufs-rev 151)))
     ((transcript "multiuser.library 1.4 or newer detected")
      (message
       "\n    You seem to have MultiUser 1.4 installed. In order to ensure "
       "the most seamless operation between MultiUser 1.4 and "
       @app-name " you should do following:\n")
      (message
       "\nEither make a link from \"AmiTCP:db/passwd\" to "
       "MultiUser 1.4 \"passwd\" file, for example with command\n\n"
       "makelink AmiTCP:db/passwd :multiuser/config/passwd\n\n"
       "or copy MultiUser 1.4 \"passwd\" file and \"MultiUser.config\" to "
       "directory \"AmiTCP:db/\", then recreate keyfiles with command\n\n"
       "makekeyfiles AmiTCP:db/ AmiTCP:db/ vol1: vol2:    \n")))
 (set passwd-source
      (if (exists "Inet:db/passwd" (noreq)) ; check for AS225r2 compatible
	  "Inet:db/passwd"
	(tackon source-dir "db/passwd-example")))
 (set group-source (tackon source-dir "db/group-example"))
 (if (>= @user-level 2)
     (message 
      "\n"
      "Copying 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))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Installatation sequence
;;;
(complete 00) (transcript "On making " @app-name ".")
(complete 01) (check-user-level)
(complete 02) (check-system-version)
(complete 03) (check-available-memory)
(complete 04) (check-old-assign)
(complete 05) (select-destination-directory)

(if (exists (tackon conf-dir "netdb-myhost"))
    ( ;; Already configured, ask user what s/he wants to do
     (transcript @app-name " already configured, presenting options")
     (while
	 ((complete 10)
	  (set choice
	       (askchoice
		(prompt @app-name " seems to be already installed. Select "
			"one of following:")
		(help "    Installer has detected that the file "
		      "\"AmiTCP:db/netdb-myhost\" exists already. Normally "
		      "this means that the installation has been "
		      "successfully completed.\n"
		      "    You can now select what part of the full "
		      "installation you want to repeat. This selection will "
		      "be repeatedly presented, until \"Done\" is choosed.")
		(choices "Update Sana-II drivers"	; 0
			 "Install EmacsTCP"		; 1
			 "Install NapsaTerm fonts"	; 2
			 "Install user databases"       ; 3
			 "Reconfigure AmiTCP/IP"	; 4
			 "Done")			; 5
		(default 5)))
	  (<> choice 5))
       (select choice
	       ;; (0)
	       (update-devices)
	       ;; (1)
	       (install-emacstcp)
	       ;; (2)
	       (install-napsaterm)
	       ;; (3)
	       (install-user-databases)
	       ;; (4)
	       ((transcript "Reconfiguring " @app-name ".")
		(complete 20) (ask-hostname)
		(complete 25) (ask-aliases)
		(complete 30) (ask-interfaces)
		(complete 65) (ask-gateway)
		(complete 70) (ask-domains)
		(complete 75) (ask-nameservers)
		(complete 85) (update-user-startup)
		(complete 90) (create-startup-script)
		(complete 95) (create-config-file) ; This must be the last one!
		))
       )
     )
  ( 
   (complete 10) (copy-files-to-destination) ; copy AmiTCP/IP files
   (complete 20) (update-devices)	     ; update Sana-II drivers
   (complete 30) (ask-install-emacstcp)	     ; install EmacsTCP
   (complete 35) (ask-install-napsaterm)     ; install NapsaTerm
   (if (if (if old-atcp-directory
	       (exists (tackon old-atcp-directory "db/netdb-myhost") 
			(noreq)))
	   ((complete 40)
	    (ask-copy-old-configuration)))
       ((if (exists (tackon conf-dir "passwd"))
	    (transcript "There is already user database.")
	  ((complete 70)
	   (install-user-databases))) ; install passwd/group
	(complete 90) (update-user-startup)
	)
     (;; First time installation, do it all
      (complete 45) (install-user-databases)	; install passwd/group

      ;; Configure AmiTCP/IP
      (complete 50) (ask-hostname)
      (complete 55) (ask-aliases)
      (complete 60) (ask-interfaces)
      (complete 75) (ask-gateway)
      (complete 80) (ask-domains)
      (complete 85) (ask-nameservers)
      (complete 90) (update-user-startup)
      (complete 95) (create-startup-script)
      (complete 96) (create-config-file)))	; This must be the last one!
   ;; show something
   (run (cat "run " pager-cmd) (tackon atcp-assign "README.FIRST") (safe))
   )
  )
;;; All done!
(complete 100)
(exit "You should reboot your Amiga to make sure that everything is set "
      "up properly for the " @app-name ". After the reboot, "
      (if started-at-boot
	  (cat @app-name " should be running. If this is not a case, "))
      "type \"run AmiTCP:bin/startnet\" in a command shell to start "
      @app-name ".")
