;;;; Hey Emacs, this script might as well be -*- lisp -*-
;;;;
;;;; Config_AmiTCP - AmiTCP/IP configuration script for Installer
;;;;
;;;; Copyright © 1994 AmiTCP/IP Group,
;;;;                  NSDi - Network Solutions Development Inc., Finland
;;;;                  All rights reserved.
;;;;
;;;; $Id: Config_AmiTCP,v 4.3 1994/12/23 08:34:51 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 the " @app-name " 4.1 configuration.\n")
;;;;
;;;; What we are?
;;;;
(set app-name (cat @app-name " 4.1"))

;;;
;;; Destination directories of the AmiTCP/IP
;;;
(set 
 atcp-name "AmiTCP"
 atcp-assign (cat atcp-name ":")	; Assign to AmiTCP
 ;; 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")
 ;; AmigaGuide documentation
 help-dir (tackon atcp-assign "help")
 ;; DOS handlers
 l-dir (tackon atcp-assign "l")
 ;; libraries
 libs-dir (tackon atcp-assign "libs")
 ;; daemons
 serv-dir (tackon atcp-assign "serv")
 ;;
 ;; 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")
 apipe-mount (cat 
	      "Assign APIPE: Exists > NIL:\n" 
	      "IF Warn\n"
	      "  Mount APIPE: from AmiTCP:devs/APipe-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"))
; )
 )

;; Restore old configuration on error
(onerror
 0) ; not implemented yet

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(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
 ;;  ::ask-ip-default  - default value for the asked IP address
 ;;
 ;; locally used names:
 ;;  ::ask-ip-result
 (set ::ask-ip-result "")
 (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 ::ask-ip-result
			(cat "\n\nYou entered an invalid value\n\""
			     ::ask-ip-result "\".\n"
			     "Enter a valid IP address.")))
	    (default ::ask-ip-default)
	    (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-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-atcp-assign
 ;; Check that AmiTCP is installed
 (transcript "Checking for already installed AmiTCP.")
 (if (exists atcp-assign (noreq))
     (set current-atcp-directory (getassign atcp-name))
   ((transcript "Installation aborted due to lacking AmiTCP: assign.")
    (abort "AmiTCP/IP configuration requires that AmiTCP/IP is installed on "
	   "your system. The configuration tool could not find the AmiTCP: "
	   "assign, so the configuration cannot be completed. "
	   "Please install AmiTCP: from the AmiTCP/IP installation disk."
	   ))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 serial-device-exists
 ;;
 ;; Check if serial device (my-serial-device) exists either as a file or
 ;; as a resident device.
 ;;
 (if (<> my-serial-device "")
     (if (= 1 (exists my-serial-device)) ; file exists?
	 (<> (getversion my-serial-device) 0) ; file version available?
       (if (<> (getversion (fileonly my-serial-device) (resident)) 0)
					; resident version available?
	   ((set my-serial-device (fileonly my-serial-device)) ; remove path
	    1) ; true, exists
	 ))
   )
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ask-slip-config
 ;;
 ;; the my-host-if has to be set before this is called
 ;;
 ;; This sets the if-config-file on return ("" if not applicaple).
 ;; The config file is returned without the path and it will be put to the 
 ;; ENV:Sana2 directory by the generated startnet script.
 ;; The contents is stored in if-config.
 ;;
 (transcript "Creating configuration file for SLIP/CSLIP devices.")
 ;;
 ;; Loop until the user is satisfied
 ;;
 (while
     ((set my-serial-device
	   (askfile (prompt "Select the SERIAL device driver to be used with "
			    my-host-if ":\n"
			    "NOTE: This list lists all devices in DEVS:.\n"
			    "Normally you would want to select "
			    "`serial.device'."
			    )
		    (default "DEVS:serial.device")
		    (help "    You should select the serial device driver to "
			  "be used for the transport of " my-host-if ". "
			  "You will be separately asked for the unit number.\n"
			  "    You can cancel this operation by giving an "
			  "empty string.")))
      (if (NOT (serial-device-exists))
	  (if (<> my-serial-device "")
	      ((message "   The serial device " my-serial-device " does not "
		       "exist. You will be prompted again for the serial "
		       "device.")
	       1 ; ask again
	       )
	    0 ; empty string was given, do not ask again
	    )
	;;
	;; remove the prefix from the file name
	;;
	((if (patmatch "DEVS:#?" my-serial-device)
	     (set my-serial-device (substr my-serial-device 5)))
	 
	 (set my-serial-unit
	      (asknumber
	       (prompt "\nSelect unit number for the " my-serial-device ":")
	       (default 0)
	       (help "    Select the unit number for the device "
		     my-serial-device " to use. This is 0 for the "
		     "internal serial port, but might be other for "
		     "other serial devices."))
	      my-serial-baud
	      (asknumber
	       (prompt "\nGive the baud rate for the " my-serial-device 
		       " unit " my-serial-unit ".\n"
		       "\nPlease start with a low value like 9600, "
		       "if you are not absolutely sure that your SLIP "
		       "line works at higher speeds.\n")
	       (default 9600)
	       (help "    The baud rate MUST match the one used while "
		     "dialling to the SLIP provider.\n"
		     "    Since higher speeds may have some problems, you "
		     "should always start with some reasonably low baud "
		     "rate (like 9600) and then, when your SLIP setup "
		     "works, try out the higher speeds."))
	      my-slip-mtu-raw
	      (asknumber
	       (prompt "\nGive the Maximum Transfer Unit (MTU) for the "
		       my-host-if ":\n")
	       (range 576 4096)
	       (default 1006)
	       (help "    The MTU MUST match the one used by your SLIP "
		     "provider.\n"
		     "    The value 1006 bytes is the most common, but 1500 "
		     "bytes is also used often.\n"
		     "    You should consult your SLIP provider for the "
		     "correct value to use."))
	      ;; Force the MTU to be even
	      my-slip-mtu
	      (* (/ (+ 1 my-slip-mtu-raw) 2) 2)
	      my-slip-options-bitmap
	      (askoptions
	       (prompt "\nSelect additional options to be used with the "
		       my-host-if ":\n"
		       "\nPlease see Help for explanations for each option.")
	       (choices "Carrier Detect" "Hardware-handshake (CTS/RTS)"
			"EOF-mode")
	       (default %110)
	       (help "    Carrier Detect (CD): "
		     "If selected, causes the " my-host-if " to pay "
		     "attention to the status of the carrier detect line. "
		     "If this isn't selected, the CD signal will be "
		     "ignored.\n"
		     "    Hardware-handshake (7WIRE): "
		     "If selected, the seven wire (or hardware, i.e., "
		     "CTS/RTS) handshaking is used with the modem. "
		     "This option is strongly recommended for high baud "
		     "rates.\n"
		     "    EOF-mode (EOFMODE): "
		     "If selected, causes " my-host-if " to use EOFMODE. "
		     "This reduces the CPU load considerably, but it "
		     "won't work with all different (buggy) serial "
		     "devices (like the a2232)."))
	      my-slip-options
	      (cat (if (in my-slip-options-bitmap 0)
		       "CD ")
		   (if (in my-slip-options-bitmap 1)
		       "7WIRE ")
		   (if (in my-slip-options-bitmap 2)
		       "EOFMODE"))
	      )
	 
	 (if (not (askbool
		   (prompt
		    "This is the information you gave for the configuration "
		    "for the " my-host-if ":\n"
		    "\nSerial device: " my-serial-device
		    "\nSerial unit: " my-serial-unit
		    "\nSerial baud rate: " my-serial-baud
		    "\nSLIP MTU: " my-slip-mtu
		    "\nSLIP options: " my-slip-options
		    "\n\nIs this correct?")
		   (help
		    "    Check the information shown. If you do not "
		    "confirm it, all of it will be asked again.")))
	     1			; ask it all again
	   (
	    ;; store the file name and the configuration string
	    (set if-config-file my-host-if)
	    (if (= my-host-if "rhcslip0") ;; special case
		(set if-config-file "rhslip0"))
	    (set if-config-file
		 (cat if-config-file ".config"))
	    (set if-config
		 (cat my-serial-device " "
		      my-serial-unit " "
		      my-serial-baud " "
		      "0.0.0.0 "
		      "MTU=" my-slip-mtu " "
		      my-slip-options))
	    0				; no need to ask again
	    ))))
      )
   )
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ask-ppp-config
 ;;
 ;; the my-host-if has to be set before this is called
 ;;
 ;; This sets the if-config-file on return ("" if not applicaple).
 ;; The config file is returned without the path and it will be put to the 
 ;; ENV:Sana2 directory by the generated startnet script.
 ;; The contents is stored in if-config.
 ;;
 (transcript "Creating configuration file for PPP device.")
 ;;
 ;; Loop until the user is satisfied
 ;;
 (while
     ((set my-serial-device
	   (askfile (prompt "Select the SERIAL device driver to be used with "
			    my-host-if ":\n"
			    "NOTE: This list lists all devices in DEVS:.\n"
			    "Normally you would want to select "
			    "`serial.device'."
			    )
		    (default "DEVS:serial.device")
		    (help "    You should select the serial device driver to "
			  "be used for the transport of " my-host-if ". "
			  "You will be separately asked for the unit number.\n"
			  "    You can cancel this operation by giving an "
			  "empty string.")))
      (if (NOT (serial-device-exists))
	  (if (<> my-serial-device "")
	      ((message "   The serial device " my-serial-device " does not "
		       "exist. You will be prompted again for the serial "
		       "device.")
	       1 ; ask again
	       )
	    0 ; empty string was given, do not ask again
	    )
	;;
	;; remove the prefix from the file name
	;;
	((if (patmatch "DEVS:#?" my-serial-device)
	     (set my-serial-device (substr my-serial-device 5)))
	 
	 (set my-serial-unit
	      (asknumber
	       (prompt "\nSelect unit number for the " my-serial-device ":")
	       (default 0)
	       (help "    Select the unit number for the device "
		     my-serial-device " to use. This is 0 for the "
		     "internal serial port, but might be other for "
		     "other serial devices."))
	      my-serial-baud
	      (asknumber
	       (prompt "\nGive the baud rate for the " my-serial-device 
		       " unit " my-serial-unit ".\n"
		       "\nPlease start with a low value like 9600, "
		       "if you are not absolutely sure that your PPP "
		       "line works at higher speeds.\n")
	       (default 9600)
	       (help "    The baud rate MUST match the one used while "
		     "dialling to the PPP provider.\n"
		     "    Since higher speeds may have some problems, you "
		     "should always start with some reasonably low baud "
		     "rate (like 9600) and then, when your PPP setup "
		     "works, try out the higher speeds."))
	      my-ppp-mtu-raw
	      (asknumber
	       (prompt "\nGive the Maximum Transfer Unit (MTU) for the "
		       my-host-if ":\n"
		       "NOTE: This option is functional on registered "
		       "version of ppp.device only.")
	       (range 0 1500)
	       (default 1500)
	       (help "    The MTU used is negotiated at the PPP connection "
		     "startup phase. If you want the other end to select "
		     "the used MTU, give the MTU as zero (0).\n"
		     "    NOTE: This option is functional on registered "
		     "version of ppp.device only. On evaluation version "
		     "the MTU is always 1500 regardless of the one "
		     "mentioned on the configuration file."))
	      ;; Force the MTU to be even
	      my-ppp-mtu
	      (* (/ (+ 1 my-ppp-mtu-raw) 2) 2)
	      my-ppp-dial-script-file
	      (askfile
	       (prompt "Select the optional dial script file to be used "
		       "with " my-host-if ":\n"
		       "(See help for instructions.)"
		       )
	       (default "")
	       (help "NOTE: This option is not available on older "
		     "ppp.device versions!\n"
		     "    You can select the dial script file to be "
		     "with the ppp.device.\n"
		     "    If the file you select does not exist, you must "
		     "create it before trying to start " app-name ".\n"
		     "    You can cancel this operation by giving an "
		     "empty string."))
	      my-ppp-warning		; not used anywhere
	      (if (<> my-ppp-dial-script-file "")
		  (if (<> 1 (exists my-ppp-dial-script-file))
		      (message
		       "Warning: The selected PPP dial script file "
		       my-ppp-dial-script-file " does not exist. "
		       "You should create the file following the "
		       "instructions laid down on the ppp.device "
		       "documentation.\n")))
	      my-ppp-options-bitmap
	      (askoptions
	       (prompt "\nSelect options to be used with the "
		       my-host-if ":\n"
		       "\nPlease see Help for explanations for each option.")
	       (choices "Carrier Detect" "Hardware-handshake (CTS/RTS)"
			"no EOF-mode" "Use ODU" "shared mode")
	       (default %00010)
	       (help "NOTE: ppp.device has far more configuration options "
		     "than presented here. After this option selection "
		     "you can enter any additional options. "
		     "Refer to the ppp.device "
		     "documantation for full reference of all the "
		     "available options.\n"
		     "    Carrier Detect (CD): "
		     "Causes the " my-host-if " to pay "
		     "attention to the status of the carrier detect line. "
		     "If this isn't selected, the CD signal will be "
		     "ignored.\n"
		     "    Hardware-handshake (7WIRE): "
		     "If selected, the seven wire (or hardware, i.e., "
		     "CTS/RTS) handshaking is used with the modem. "
		     "This option is strongly recommended for high baud "
		     "rates.\n"
		     "    no EOF-mode (NOEOFMODE): "
		     "Causes " my-host-if " not to use EOF-"
		     "mode with the serial device. "
		     "This increases the CPU load somewhat, but allows "
		     "ppp.device to work with buggy serial "
		     "devices (like the a2232).\n"
		     "    use ODU (USEODU): "
		     "Tells ppp.device to use OwnDevUnit.library to "
		     "coordinate access to the selected serial device "
		     "unit. This option could be used in conjunction "
		     "with SHARED option to allow the ppp.device to "
		     "use a serial port opened by some one else.\n"
		     "    shared mode (SHARED): "
		     "Tells ppp.device to open the serial port in "
		     "shared mode. This option may be useful with "
		     "some \"getty\"-type of programs together with "
		     "the USEODU option. NOTE: This option is not "
		     "available on older ppp.device versions"
		     ))
	      my-ppp-options
	      (cat (if (in my-ppp-options-bitmap 0)
		       "CD ")
		   (if (in my-ppp-options-bitmap 1)
		       "7WIRE ")
		   (if (in my-ppp-options-bitmap 2)
		       "NOEOFMODE ")
		   (if (in my-ppp-options-bitmap 3)
		       "USEODU ")
		   (if (in my-ppp-options-bitmap 4)
		       "SHARED ")
		   )
	      my-ppp-additional-options
	      (askstring
	       (prompt "Enter additional options for the ppp.device:\n\n"
		       "NOTE: Refer to the ppp.device documentation! "
		       "Incorrect options will prevent the ppp.device "
		       "from functioning correctly.\n"
		       "Give an empty string to by-pass this option.")
	       (default "")
	       (help "    Here you can enter those options of the "
		     "ppp.device, which are not directly supported "
		     "by this configuration.\n"
		     "    Enter the desired options separated by spaces.\n"
		     "    See the ppp.device documentation for the "
		     "reference of the valid options."))
	      )
	 
	 (if (not (askbool
		   (prompt
		    "This is the information you gave for the configuration "
		    "for the " my-host-if ":\n"
		    "\nSerial device: " my-serial-device
		    "\nSerial unit: " my-serial-unit
		    "\nSerial baud rate: " my-serial-baud
		    "\nPPP MTU: " my-ppp-mtu
		    (if (<> my-ppp-dial-script-file "")
			(cat "\nPPP dial script file: "
			     my-ppp-dial-script-file))
		    (if (<> my-ppp-options "")
			(cat "\nPPP options: " my-ppp-options))
		    (if (<> my-ppp-additional-options "")
			(cat "\nPPP additional options: "
			     my-ppp-additional-options))
		    "\n\nIs this correct?")
		   (help
		    "    Check the information shown. If you do not "
		    "confirm it, all of it will be asked again.")))
	     1			; ask it all again
	   (
	    ;; store the file name and the configuration string
	    (set if-config-file (cat my-host-if ".config"))
	    (set if-config
		 (cat my-serial-device " "
		      my-serial-unit " "
		      my-serial-baud " "
		      "0.0.0.0 "
		      "MTU=" my-ppp-mtu " "
		      (if (<> my-ppp-dial-script-file "")
			  (cat "DIALSCRIPT=" my-ppp-dial-script-file " "))
		      my-ppp-options
		      my-ppp-additional-options))
	    0				; no need to ask again
	    ))))
      )
   )
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ask-ggbus-config
 ;;
 ;; the my-host-if has to be set before this is called
 ;;
 ;; this sets the if-config-file on return ("" if not applicaple)
 ;; the contents is stored in if-config
 ;;
 (transcript "Creating configuration file for GGBus+ devices.")
 ;;
 ;; Common help
 ;;
 (set isa-help (cat "    Refer to the ISA board and GGBus+ manuals for more "
		    "information."))

 ;;
 ;; Loop until the user is satisfied
 ;;
 (while
     ((set my-isa-irq
	   (asknumber
	    (prompt "\nGive the ISA IRQ number for the " my-host-if ":")
	    (default 3)
	    (if (= my-host-if "gg_smc")
		(range 3 5)
	      (range 1 15)
	      )
	    (help "    Give the ISA IRQ number for the interface "
		  my-host-if " to use. The given number must match "
		  "with the setting on the board.\n" isa-help))
	   my-isa-ioaddr
	   (askstring
	    (prompt "\nGive the ISA I/O-address of the " my-host-if ".\n"
		    "\nThe address must be entered in hex, starting with "
		    "\"0x\".\n")
	    (default "0x300")
	    (help "    The given I/O-address must match with the setting "
		  "on the board.\n" isa-help))
	   my-isa-memaddr
	   (if (= my-host-if "gg_smc")
	       (askstring
		(prompt "\nGive the ISA memory base address for the "
			my-host-if ".\n" 
			"\nThe address must be entered in hex, starting with "
			"\"0x\".\n")
		(default "0xd0000")
		(help "    The given base address must match with the setting "
		      "on the board.\n" isa-help))))
	   
      (if (not (askbool
		(prompt
		 "This is the information you gave for the configuration "
		 "for the " my-host-if ":\n"
		 "\nISA IRQ number: " my-isa-irq
		 "\nISA I/O-address: " my-isa-ioaddr
		 (if my-isa-memaddr
		     (cat "\nISA memory base address: " my-isa-memaddr))
		 "\n\nIs this correct?")
		(help
		 "    Check the information shown. If you do not "
		 "confirm it, all of it will be asked again.")))
	  1			; ask it all again
	(
	 ;; store the file name and the configuration string
	 (set if-config-file (cat my-host-if ".config_0"))
	 (set if-config
	      (cat "IRQ=" my-isa-irq " "
		   "IOADDR=" my-isa-ioaddr " "
		   (if my-isa-memaddr
		       (cat "MEMADDR=" my-isa-memaddr " "))
		   ))
	 0				; no need to ask again
	 )))
   )
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;(procedure
; ask-if-dynamic ;; Ask if the network connection is dynamic
; (set is-if-dynamic
;      (askbool (prompt "\nIs your network connection dynamic?")
;	       (help "    If your network connection is dynamic, your IP "
;		     "address will change each time you connect to the "
;		     "network. Because of this you can not have a "
;		     "fixed host name either. If this is the case, "
;		     "you will not be asked for the host name.\n"
;		     "    If your network connection is not "
;		     "dynamic, then you should have a fixed IP address.\n"
;		     "    The \"startnet\" script produced by this "
;		     "configuration script will have an optional IP "
;		     "address argument, which you should use if your "
;		     "network connection is dynamic.\n")
;	       (default 0)))
; )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ask-hostname ;; Get host name, domain and aliases
 ;;
 ;; Get the hostname from environment variable
 ;;
 (set def-full-name (if (exists "ENV:HOSTNAME")
			(getenv "HOSTNAME")
		      "")
      my-host-name ""
      my-host-aliases ""
      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))))
 ;;
 ;; If the network connection is dynamic, do not ask the host name, but leave
 ;; it empty.
 ;;
 (if (not cs-is-if-dynamic)
     ;;
     ;; 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, "
		   "\"nsdi.fi\" is the domain name of the Network "
		   "Solutions Development Inc., Finland.\n")
	     (default def-host-name))))
   )
 ;;
 ;; ask the domain name from the user
 ;;
 (set my-domain-name
      (askstring
       (prompt (if cs-is-if-dynamic 
		   "\nEnter your domain name:"
		 "\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, "
	     "\"nsdi.fi\" is the domain name of the Network "
	     "Solutions Development Inc., Finland.\n"
	     "    If you do not have a domain name server, then you might "
	     " not have a domain, either. In this case you can leave the "
	     "domain empty.\n")
       (default def-domain-name)))
 ;;
 ;; Set the full name of this host. 
 ;;
 (set my-full-name (if my-host-name
		       (cat my-host-name
			    (if my-domain-name
				(cat "." my-domain-name)
			      ""))))
 ;;
 ;; ask alias names for this host if the host name is not empty
 ;;
 (if 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 "")
	       (help net-setup-help
		     "    Your computer may have additional names "
		     "(aliases) to its official name.\n"
		     "    The plain host name (" my-host-name ") will "
		     "be understood by the " app-name " automatically, so "
		     "you do not need to include that as an alias. "
		     )))
       (set my-host-aliases (cat my-host-aliases " " new-host-name))))
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Ask network interfaces
;;;
;;; Loop until no device is given.
;;;
(procedure
 ask-interfaces

 (set number-of-interfaces 0)

 ;;
 ;; Procedure to ask the network device driver name
 ;;
 ;; (Returns TRUE if an interface was selected)
 ;;
 ;; NOTE: Currently only 8 choises within each interface type are allowed
 ;;       (excluding the "none" entry).
 ;; 
 (procedure
  if-ask-device
  (set my-host-if-type
       ((set choice
	     (if (<> cs-if-type 0)
		 cs-if-type
	       (askchoice
		(prompt (cat "Select "
			     (if (= number-of-interfaces 0)
				 "the"
			       "another")
			     " network interface type to be used:")
			(help "    You should select your network interface "
			      "type from the given choices. If your device "
			      "type is "
			      "not listed select some other (which matches "
			      "closest to your device) and alter "
			      "the configuration (and db/interfaces file) "
			      "by hand.\n"
			      "    Select \"None\" if you do not want to "
			      "configure "
			      (if (= number-of-interfaces 0)
				  "an"
				"another")
			      " interface.")
			(choices "None"			; 0
				 "SLIP/CSLIP"		; 1
				 "PPP"			; 2
				 "X.25"			; 3
				 "Ethernet"		; 4
				 "Arcnet"			; 5
				 "GGBus+ Ethernet"	; 6
				 "PLIP/Liana"		; 7
				 )
			(default 0)))))
	;;;
	;;; Destination IP address is asked for p-to-p interfaces only
	;;; also, the destination IP address suffices as the default 
	;;; gateway address in most cases.
	;;;
; this is currently not used at all
	(set my-host-if-point-to-point (select choice
					       0	; None
					       1	; slip/cslip
					       1	; ppp
					       0	; x.25
					       0	; ethernet
					       0	; arcnet
					       0	; GGBus+ Ethernet
					       1	; PLIP/Liana
					       ))
	choice)
       
       my-host-if
       (if (= my-host-if-type 0)
	   ""
	 ((set choice
	       (if (<> cs-if-choice 0)
		   cs-if-choice
		 (askchoice
		  (prompt (cat "Select "
			       (if (= number-of-interfaces 0)
				   "the"
				 "another")
			       " network interface to be used:"))
		  (help "    You should select your network interface "
			"from the given choices. If your device is "
			"not listed select some other (which matches "
			"closest to your device) and alter "
			"the configuration (and db/interfaces file) "
			"by hand.\n"
			"    Select \"None\" if you do not want to "
			"configure "
			(if (= number-of-interfaces 0)
			    "an"
			  "another")
			" interface.")
		  (select (- my-host-if-type 1)
			  (			; type 1 (SLIP/CSLIP)
			   (choices "None"	; 0
				    "rhslip"	; 1
				    "rhcslip"	; 2
				    )
			   (default 1))
			  (			; type 2 (PPP)
			   (choices "None"	; 0
				    "ppp"	; 1
				    )
			   (default 1))
			  (			; type 3 (AX.25)
			   (choices "None"	; 0
				    "axdm"	; 1
				    )
			   (default 1))
			  (			; type 4 (Ethernet)
			   (choices "None"	; 0
				    "CBM A2065"	; 1
				    "Hydra Ethernet" ; 2
				    "ASDG EB920"	; 3
				    "Village Tronic Ariadne" ; 4
				    "Ameristar a4066" ; 5
				    "QuickNet"	; 6
;				    "Golden Gate wd80xx (trossi)" ; 7
				    )
			   (default 1))
			  (			; type 5 (Arcnet)
			   (choices "None"	; 0
				    "CBM A2060"	; 1
				    )
			   (default 1))
			  (			; type 6 (GGBus+ Ethernet)
			   (choices "None"	; 0
				    "3COM 3C503"	; 1
				    "NE1000" 	; 2
				    "NE2000" 	; 3
				    "WD80x3"	; 4
				    )
			   (default 3))
			  (			; type 7 (PLIP/Liana)
			   (choices "None"	; 0
				    "PLIP unit 0" ; 1
				    "PLIP unit 1" ; 2
				    "Liana unit 0" ; 3
				    "Liana unit 1" ; 4
				    "Ariadne Liana unit 0" ; 5
				    "Ariadne Liana unit 1" ; 6
				    )
			   (default 1))
			  )
		  )))
	  (if (= choice 0)
	      ""
	    ;;;
	    ;;; Following names must match the ones defined in db/interfaces
	    ;;;
	    (select (+ (* (- my-host-if-type 1) 8) (- choice 1))
					; type 1 (SLIP/CSLIP)
		    "slip0"	; (1) 
		    "cslip0"	; (2)
		    ""		; (3)
		    ""		; (4)
		    ""		; (5)
		    ""		; (6)
		    ""		; (7)
		    ""		; (8)
					; type 2 (PPP)
		    "ppp0"	; (1) 
		    ""		; (2)
		    ""		; (3)
		    ""		; (4)
		    ""		; (5)
		    ""		; (6)
		    ""		; (7)
		    ""		; (8)
					; type 3 (AX.25)
		    "ax25"	; (1) 
		    ""		; (2)
		    ""		; (3)
		    ""		; (4)
		    ""		; (5)
		    ""		; (6)
		    ""		; (7)
		    ""		; (8)
					; type 4 (Ethernet)
		    "a2065"	; (1) 
		    "hydra"	; (2)
		    "eb920"	; (3)
		    "ariadne"	; (4)
		    "a4066"	; (5)
		    "quicknet"	; (6)
		    "wd80xx"	; (7)
		    ""		; (8)
					; type 5 (Arcnet)
		    "a2060"	; (1) 
		    ""		; (2)
		    ""		; (3)
		    ""		; (4)
		    ""		; (5)
		    ""		; (6)
		    ""		; (7)
		    ""		; (8)
					; type 6 (GGBus+ Ethernet)
		    "gg_3c503"	; (1) 
		    "gg_ne1000"	; (2)
		    "gg_ne2000"	; (3)
		    "gg_smc"	; (4)
		    ""		; (5)
		    ""		; (6)
		    ""		; (7)
		    ""		; (8)
					; type 7 (Village Tronic Liana)
		    "plip0"	; (1) 
		    "plip1"	; (2)
		    "liana0"	; (3)
		    "liana1"	; (4)
		    "ariadneliana0" ; (5)
		    "ariadneliana1" ; (6)
		    ""		; (7)
		    ""		; (8)
		    ))))))

 ;;
 ;; Ask for the unit number
 ;;
 ;; NOTE: Currently not used
 ;;
 (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 interface "
	      my-host-if " to use. This is usually 0 for the first "
	      "unit of that particular network interface. "
	      "The network interface unit numbers are normally directly "
	      "mapped to the Sana-II device driver unit numbers. "
	      "Refer your device driver documentation for "
	      "correct number to use."))))

 ;;
 ;; Ask for the IP address of this host
 ;;
 (procedure
  if-ask-address
  (if (= cs-IP-address "")
      (set ::ask-ip-prompt 
	 (cat "IP address for the interface " my-host-if ".\n")
	 ::ask-ip-help 
	 (cat "    If you have no connection to the global "
	      "Internet and are configuring a private network, "
	      "you can select your IP addresses from following "
	      "ranges: (see RFC1597)\n\n"
	      "10.0.0.0 - 10.255.255.255\n"
	      "172.16.0.0 - 172.31.255.255\n"
	      "192.168.0.0 - 192.168.255.255\n\n"
	      "NOTE: The addresses at the end of the ranges are "
	      "NOT usable IP addresses for a host! So select your "
	      "address from INSIDE the range (for example: "
	      "10.1.1.1).")
	 ::ask-ip-need 1
	 ::ask-ip-default ""
	 cs-IP-address (ask-ip-address))))

; ;;
; ;; Ask for the destination address for the point-to-point interfaces
; ;;
; (procedure
;  if-ask-dest-address
;  (if (= cs-dest-IP-address "")
;      (set cs-dest-IP-address
;	   (if my-host-if-point-to-point
;	       ((set ::ask-ip-prompt 
;		     (cat "Give the destination address for the "
;			  "point-to-point interface " my-host-if ".\n"
;			  "Address of interface is "
;			  (if cs-is-if-dynamic
;			      "<dynamic>"
;			    cs-IP-address)
;			  ".\n"
;			  "\n"
;			  "Normally this is the same as the default gateway "
;			  "address.\n"
;			  )
;		     ::ask-ip-help 
;		     (cat "    A point-to-point interface is one that is "
;			  "connected to a medium which only two hosts can "
;			  "attach, for example the normal serial line: "
;			  "your computer is in other end and the other "
;			  "computer is on the other end.\n"
;			  "    The destination address of an point-to-point "
;			  "interface is the IP address of the host (or "
;			  "terminal server) at the other end of the link.\n"
;			  "    If the destination address is not known for "
;			  "some reason, and you are going to configure only "
;			  "one interface, you can use the default gateway "
;			  "address as your p-to-p destination address.")
;		     ::ask-ip-need 1
;		     ::ask-ip-default ""
;		     )
;		(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
  (if (= cs-netmask "")
      (set cs-netmask
	   ((set ::ask-ip-prompt
		 (cat "Give netmask of the network on the interface "
		      my-host-if ".\n"
		      "Address of the interface is "
		      (if cs-is-if-dynamic
			  "<dynamic>"
			cs-IP-address)
;		      (if cs-dest-IP-address
;			  (cat ",\ndestination address is "
;			       cs-dest-IP-address ".\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's IP address "
		      "are used to identify the network "
		      "(the network address).\n"
		      "    For example, \"255.255.255.0\" "
		      "is a possible netmask.\n"
		      "    The netmask must be the same for all the "
		      "interfaces connected to the same network.\n"
		      "    If you do NOT know the netmask, then leave "
		      "it empty, a default value will be computed from "
		      "your interface's IP address. This is correct only if "
		      "the network is not divided into subnets.")
		 ::ask-ip-need 0
		 ::ask-ip-default ""
		 )
	    (ask-ip-address)))))

 ;;
 ;; Ask for confirmation on given information
 ;;
 (procedure
  if-confirmation
  (askbool
   (prompt "This is the information you gave for this interface:\n"
	   "\nConfiguration style: " cs-style-name
	   "\nInterface: " my-host-if
	   "\nInterface address: "
	   (if cs-is-if-dynamic
	       "<dynamic>"
	     cs-IP-address)
;	   (if my-host-if-point-to-point
;	       (cat "\nDestination address: " 
;		    (if cs-dest-IP-address
;			cs-dest-IP-address
;		      "<dynamic>"))
;	     "")
	   "\nNetmask: " (if cs-netmask
			     cs-netmask
			   "<use default>")
	   "\n\nIs this correct?")
   (help "    Check the information shown. If you do not confirm it, "
	 "all of it will be asked again.")))

 ;;
 ;; Ask if user wants to Config another interface
 ;;
; (procedure
;  if-ask-another
;  (askbool
;   (prompt "Do you want to install another interface?")
;   (help "    You have already configured " number-of-interfaces 
;	 " interfaces. Select \"Yes\" if you want to configure yet "
;	 "another interface.")))

 (set 
      ;; a complete list for IP address to host name mappings..
      ;; (only one mapping for now)
      address-mapping "")
 ;;
 ;; Ask for interfaces
 ;;
 (if-ask-device)
 (if cs-need-if-information
     ((if-ask-address)
;      (if-ask-dest-address)
      (if-ask-netmask)))
 (if (if-confirmation)
     ((transcript "Adding interface " my-host-if)
      ;;
      ;; Ask interface configuration. First the 'if-config-file'
      ;; is cleared. Following calls change it if necessary. Later
      ;; the config file is created if this variable is non-nil
      ;;
      (set if-config ""
	   if-config-file "")
      (if (= my-host-if-type 1)
	  (ask-slip-config))
      (if (= my-host-if-type 2)
	  (ask-ppp-config))
      (if (= my-host-if-type 6)
	  (ask-ggbus-config))
      (set
       number-of-interfaces (+ number-of-interfaces 1)
       )
      1) ;; (if-ask-another) only one interface for now
   0) ;;; confirmation not given, ask again
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ask-gateway ;;; Ask the default gateway address
 ;;
 (if cs-need-if-information
     (if (= cs-gateway "")
	 (set ::ask-ip-prompt 
	      (cat
	       "Enter the IP address of the default gateway"
	       (if (AND (= number-of-interfaces 1)
			my-host-if-point-to-point)
		   (cat 
		    ". Since your interface is of point-to-point type, "
		    "the default gateway address will also be used as the "
		    "interface destination address."
;		    ". Since you have configured only one interface, "
;		    "and that interface is of point-to-point type, "
;		    "the destination address of the interface is "
;		    "offered as default value. Generally you can "
;		    "accept this default."
		    )
		 ":"
		 )
	       )
	      ::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
	      ::ask-ip-default ""
;	      (if (AND (= number-of-interfaces 1)
;		       my-host-if-point-to-point)
;		  cs-dest-IP-address
;		"")
	      cs-gateway (ask-ip-address))
       )
   )
 )

(procedure
 ask-run-servers ;;; Ask if servers programs should be run
 (if cs-use-servers
     (set cs-use-servers
	  (askbool
	   (prompt "\nDo you intend to run server programs?\n\n"
		   "If you select \"Yes\", the Internet `Super Server' "
		   "inetd will be started at the " @app-name " startup. "
		   "The loop-back interface (\"lo0\") will also be "
		   "configured.\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. The inetd is thus essential for "
		 "most of the server programs.\n"
		 "    The loop-back interface allows you to test the server "
		 "programs locally.\n"
		 "    Refer to the documentation for more "
		 "information on server configuration.")))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; resolv.conf configuration
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
(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
	  ::ask-ip-default ""
	  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
 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
 ask-resolv-conf
 (set do-resolv.conf
      (if (exists (tackon conf-dir "resolv.conf"))
	  ;; ask if current settings are ok
	  (askbool
	   (prompt "Do you want to re-configure your name servers "
		   "and domains?")
	   (help "    The name server and domain configuration file "
		 "\"resolv.conf\" exists already.\n"
		 "    If you select Yes, you will be prompted for name server "
		 "IP addresses and search domain names.\n"
		 "    If you select No, the existing configuration is kept."
	    ))
	1) ; resolv.conf does not exist, ask for the configuration
      )
 (if do-resolv.conf
     (create-resolv-conf)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 create-resolv-conf
 ;;
 (ask-nameservers)
 (ask-domains)
 (textfile (dest (tackon conf-dir "resolv.conf"))
	   (append
	    (if name-server-list 
		(cat "; Name servers\n" name-server-list)))
	   (append
	    (if domain-list
		(cat "; Domain names\n" domain-list)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 create-startup-script
 ;;
 ;; Create the network startup-script (AmiTCP:bin/startnet)
 ;;
 (textfile
  (dest (tackon bin-dir "startnet"))
  (append
   (cat
    ".key IP,HN/K,DEST/K,MASK/K,GW/K,USER/K,SRV/S,BOOTP/S,UMASK/K,S2CF/K,S2OPT/K,IFACE/K,DEBUG/S\n"
    ".bra {\n"
    ".ket }\n"
    ";\n"
    "; AmiTCP/IP startnet script\n"
    ";\n"
    "; Copyright © 1994 AmiTCP/IP Group,\n"
    ";                  NSDi - Network Solutions Development Inc., Finland\n"
    ";                  All rights reserved.\n"
    ";\n"
    "; *NOTE*  NORMALLY YOU SHOULD USE THE PROVIDED CONFIGURATION UTILITY\n"
    "; *NOTE*  TO CHANGE THE CONFIGURATION.  IF YOU NEED TO CHANGE THE \n"
    "; *NOTE*  CONFIGURATION MANUALLY, RESTRICT ANY MODIFICATIONS TO THIS \n"
    "; *NOTE*  \"DEF\" SECTION.\n"
    ";\n"
    "; IP address if known, _nothing_ otherwise\n"
    ".def IP    " cs-IP-address "\n"
    "; Our full host name and aliases if known, _nothing_ otherwise\n"
    "; (if this is set, the IP _must_ be set, too)\n"
    ".def HN    "
    (if (AND (<> my-full-name "") (<> cs-IP-address ""))
	(cat "\"" my-full-name 
	     (if (<> my-host-aliases "")
		 (cat " " my-host-aliases))
	     "\"\n")
      "\n")
    "; The destination address, needed only if GW is not good destination\n"
    ".def DEST  \n"
    "; netmask if known, _nothing_ otherwise\n"
    ".def MASK  " cs-netmask "\n"
    "; IP address of the default gateway if known, _nothing_ otherwise\n"
    ".def GW    " cs-gateway "\n"
    "; Default login name\n"
    ".def USER  " default-user-name "\n"
    "; User's file creation mask\n"
    ".def UMASK " default-user-umask "\n"
    "; \"SRV\" if servers are used, _nothing_ otherwise\n"
    ".def SRV   " (if cs-use-servers "SRV") "\n"
    "; \"BOOTP\" if bootstrap protocol is used, _nothing_ otherwise\n"
    ".def BOOTP " (if cs-use-bootp "BOOTP") "\n"
    "; Interface name\n"
    ".def IFACE " my-host-if "\n"
    "; Sana-II device configuration file, _nothing_ otherwise\n"
    ".def S2CF  " if-config-file "\n"
    "; Sana-II device configuration to be stored into the configuration file\n"
    ".def S2OPT \"" if-config "\"\n"
    ";\n"
    "; *NOTE*  YOU SHOULD NOT NEED TO EDIT ANYTHING BELOW. IF YOU NEED TO ADD\n"
    "; *NOTE*  CONFIGURATIONS OF ADDITIONAL INTERFACES OR TO START UTILITIES,\n"
    "; *NOTE*  DO IT IN THE AmiTCP:db/User-Startnet.\n"
    ";\n"
    "; Set the failat level so that the errors can be handled by the script\n"
    "FailAt 21\n"
    "; Log in\n"
    "echo\n"
    "echo login: {USER}\n"
    "AmiTCP:bin/login -f {USER}\n"
    "AmiTCP:bin/umask {UMASK}\n"
    "run AmiTCP:AmiTCP {DEBUG}\n"
    "WaitForPort AMITCP\n"
    "If NOT Warn\n"
    "  ; Create Sana2 configuration file if used\n"
    "  If NOT X EQ \"X{S2CF}\"\n"
    "    ; Assure that ENV:Sana2 exists\n"
    "    If NOT Exists ENV:Sana2\n"
    "      MakeDir ENV:Sana2\n"
    "    EndIf\n"
    "    ; Create configuration file\n"
    "    Echo \"{S2OPT}\" >ENV:Sana2/{S2CF}\n"
    "  EndIf\n"
    "  ; Do we need loopback?\n"
    "  If X EQ \"X{SRV}\"\n"
    "    Set LOOPBACK=\"\"\n"
    "  Else\n"
    "    Set LOOPBACK=\"LOOPBACK\"\n"
    "  EndIf\n"
    "  ; Configure interface\n"
    "  AmiTCP:bin/bootpconfig {IFACE} IP {IP$*} DEST {DEST$*} MASK {MASK$*} GW {GW$*} $LOOPBACK {BOOTP} {DEBUG}\n"
    "  If NOT Warn\n"
    "    If NOT X EQ \"X{HN}\"\n"
    "      rx \"address AMITCP; 'ADD HOST {IP} {HN}'\"\n"
    "    Else\n"
    "      If NOT X EQ \"X{DEBUG}\"\n"
    "        echo \"Quering Name Server for the host name...\"\n"
    "      EndIf\n"
    "    EndIf\n"
    "    setenv HOSTNAME `AmiTCP:bin/hostname`\n"
    "    Assign TCP: Exists >NIL:\n"
    "    IF Warn\n"
    "      Mount TCP: from AmiTCP:devs/Inet-Mountlist\n"
    "    EndIf\n"
    "    ; Start the internet `super server' if wanted\n"
    "    If NOT X EQ \"X{SRV}\"\n"
    "      If X EQ \"X{DEBUG}\"\n"
    "        Run <NIL: >NIL: AmiTCP:bin/inetd\n"
    "      Else\n"
    "        Run AmiTCP:bin/inetd {DEBUG}\n"
    "      EndIf\n"
    "    EndIf\n"
    "    ;\n"
    "    ; Configure any additional interfaces & start utilities in \n"
    "    ; AmiTCP:db/User-Startnet\n"
    "    ;\n"
    "    If Exists AmiTCP:db/User-Startnet\n"
    "      Execute AmiTCP:db/User-Startnet\n"
    "    EndIf\n"
    "  Else\n"
    "    Echo Interface {IFACE} configuration failed!\n"
    "    Echo Stopping AmiTCP\n"
    "    AmiTCP:bin/stopnet FLUSH\n"
    "  EndIf\n"
    "Else\n"
    "  Echo AmiTCP couldn't be started!\n"
    "EndIf\n"
    "\n"
    "; EOF\n"
    )))
 (protect (tackon bin-dir "startnet") "+s +e"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 update-user-startup-conf
 ;;
 (set add-to-startup-conf
      (cat 
       "; These must be placed after the AmiTCP/IP section\n"
       (if (askbool
	    (prompt "\nDo you want the password of the default user to be "
		    "asked when " @app-name " is started after a reboot?")
	    (help "    On system startup, the \"root\" is the default user. "
		  "This makes it possible to login with a user name without "
		  "password validation. If you need the password to be asked, "
		  "the user will be changed to \"nobody\" on the system "
		  "startup. This causes the password to be asked when a user "
		  "logs in.\n"))
	   (cat "; change the default user to \"nobody\"\n"
		"login -f nobody\n"))
       (if (not (AND (<> cs-IP-address "") cs-is-if-dynamic)) ; manual dynamic?
	   (if (askbool
		(prompt
		 "\nDo you want the " @app-name
		 " to be started at the system startup?")
		(help
		 "    If you decide not to start the " @app-name " at "
		 "startup, you can later start it by giving command "
		 "\"startnet\" "
		 "at the command shell."))
	       ((set started-at-boot 1)
		(tackon bin-dir "startnet\n"))
	     ((set started-at-boot 0)
	      ""))))
      complete-add-to-startup-conf
      (cat ";BEGIN " @app-name " Configuration\n"
	   add-to-startup-conf
	   ";END " @app-name " Configuration\n"))
 ;; Ask for confirmation to add
 (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
     ((set startup-changed 1)
      (startup
       (cat @app-name " Configuration")
       (command add-to-startup-conf)
       (prompt "Installer will modify your S:User-Startup file. "
	       "Following lines will be appended to it:\n\n"
	       complete-add-to-startup-conf)
       (help "   Installer needs to make indicated modifications to "
	     "your user startup file to make sure that everything is "
	     "correctly set up to run the " @app-name ".\n"
	     "   You should make the modifications later manually "
	     "if you skip this part.")))
   ;; Let user add commands
   ((set addition-to-user-startup-conf
	 (tackon atcp-assign "addition-to-user-startup-conf"))
    (textfile (dest addition-to-user-startup-conf)
	      (append complete-add-to-startup-conf))
    (message "Installer created file " addition-to-user-startup-conf
	     ", which you can append to your s:User-Startup file manually. "
	     "The file contents is:\n\n"
	     complete-add-to-startup-conf))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ;;
 ;; Check if user exists in the user database
 ;;
 ;; takes the user name in ::user-name
 ;;
 does-user-exist
 (if (run (cat "search " (tackon conf-dir "passwd") " \"" ::user-name "|\" NONUM ")
	  (safe))
     0
   1)
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure 
 ;;
 ;; Add a new user into AmiTCP:db/passwd
 ;;
 add-new-user
 (if (= anu::setdefaults 0)
     (set   
      anu::passwd (tackon conf-dir "passwd")
      anu::passwd-new (cat anu::passwd ".new")
      anu::passwd-old (cat anu::passwd ".old")
      anu::tempfile "t:run-the-password"
      anu::helptext (cat "    You must give an login name, user ID, group ID "
			 "real name and home directory for each user.\n")
      anu::setdefaults 1
      anu::username (cat default-user-name)
      anu::UID 200
      anu::GID 100
      anu::realname ""
      anu::homedir "HOME:"
      anu::shell "shell"))
 (while
     ((set anu::username
	   (askstring
	    (default anu::username)
	    (prompt "Enter the login name of the new user:\n")
	    (help anu::helptext
		  "    The login name consists of lowercase letters a-z "
		  "and numbers.  Its recommended maximum length is 8 "
		  "characters.\n"
		  "    Examples of acceptable login names are `ppessi' "
		  "and `an345'.")))
      (set ::user-name anu::username)
      (if (does-user-exist)
	  ((message "User " anu::username " already exists.")
	   1))))
 (set anu::UID
      (asknumber
       (default anu::UID)
       (prompt (cat "Enter the user ID of the user " anu::username ":\n"))
       (help anu::helptext
	     "    The user ID is a numeric unique identifier for each "
	     "user. "
	     "It is a number between 200 - 32767 for ordinary users.\n")))
 (set anu::GID
      (asknumber
       (default anu::GID)
       (prompt (cat "Enter the primary group ID of the user " 
		    anu::username ":\n"))
       (help anu::helptext
	     "    The group ID is a numeric identifier of groups. "
	     "Each user has a primary group, which is usually 100, "
	     "group \"users\".\n")))
 (set anu::realname
      (askstring
       (default anu::realname)
       (prompt (cat "Enter the real name of the user " anu::username ":\n"))
       (help anu::helptext
	     "    The real name can contain any characters except "
	     "comma (`,'), colon (`:') or bar (`|').")))
 (set anu::homedir
      (askdir
       (default anu::homedir)
       (prompt (cat "Give the home directory of the user " anu::username ":\n"))
       (help anu::helptext
	     "    When user logs in, the current directory is changed to"
	     "her home directory.  Also, the finger information (.plan"
	     "and .project) is retrieved from home directory.")
       (newpath)))
 (set anu::shell
      "shell")
;      (askstring
;       (default anu::shell)
;       (prompt (cat "Enter the name of command interpreter for the user "
;		    anu::username ":\n"))
;       (help anu::helptext
;	     "    The command interpreter value can be either "
;	     "`shell' or `cli'.")))
 (set anu::passwd-entry 
      (cat anu::username "||" anu::UID "|" anu::GID "|" 
	   anu::realname "|" anu::homedir "|" anu::shell "\n"))
 (if (askbool 
      (prompt (cat "Are you sure you want to add following user:\n\n"
		   "Login name: " anu::username "\n"
		   "User ID: " anu::UID "\n"
		   "Group ID: " anu::GID "\n"
		   "Real name: " anu::realname "\n"
		   "Home directory: " anu::homedir "\n"
;		   "Shell: " anu::shell "\n"
		   ))
      (choices (cat "Add " anu::username) (cat "Skip " anu::username))
      (help "You can still skip creating the new user."))
     ((textfile (dest anu::passwd-new)
		(include anu::passwd)
		(append anu::passwd-entry))
      (copyfiles (source anu::passwd)
		 (dest conf-dir)
		 (newname "passwd.old")
		 (optional "askuser"))
      (copyfiles (source anu::passwd-new)
		 (dest conf-dir)
		 (newname "passwd")
		 (optional "askuser"))
      (textfile (dest anu::tempfile)
		(append (cat 
			 "failat 5000\n"
			 "avail flush >nil:\n"
			 "avail flush >nil:\n"
			 (tackon bin-dir "login") " " anu::username "\n"
			 (tackon bin-dir "passwd") " " anu::username "\n"
			 "endshell\n"))
		(safe))
      (run (cat "newshell from " anu::tempfile))
      (set anu::username ""
	   anu::UID (+ anu::UID 1)
	   anu::realname "")
      1))
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ;;
 ;; Add a new users into AmiTCP:db/passwd
 ;;
 add-new-users
 (while
     (askbool (prompt "\nDo you want to create a new user account?\n"
		      "\nYou will be logged in with the new account "
		      "immediately to set the password.")
	      (choices "Proceed" "Cancel")
	      (help "    You are about to add a new users into user database. "
		    "Remember that the user id of each user must be unique! "
		    "You will be logged in with the new user account to "
		    "set the password for the new user.\n"))
   (add-new-user))
 )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure 
 ;;
 ;; Ask for the default user
 ;;
 ask-default-user
 (if (= adu::setdefaults 0)
     (set   
      adu::setdefaults 1
      default-user-umask "022"
      default-user-name ""))
 (while (= default-user-name "")
   (while
       ((set default-user-name
	     (askstring
	      (default default-user-name)
	      (prompt "Enter the default user name\n")
	      (help "    The AmiTCP/IP can handle currently only one user "
		    "at a time.  The default user is selected with `login' "
		    "command by system startup script. ")))
	(set ::user-name default-user-name)
	(if (NOT (does-user-exist))
	  (NOT (add-new-user))))))
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Ask configuration style
;;;
(procedure
 ask-configuration-style
 (transcript "Asking configuration style.")
 (set choice
      (askchoice
       (prompt "Select one of the following configuration styles:\n"
	       "(See help for explanations.)\n")
       (help
	"    Explanations for the different configuration styles:\n"
	"\n"
	"    \"Normal configuration\" should be used when none of the "
	"other configuration styles is appropriate. It asks for all the "
	"needed configation information, while on the other cases some of the "
	"information can be determined otherwise.\n"
	"    \"TIA configuration\" should be used if TIA (The Internet "
	"Adapter, a commercial product for Unix) is used to provide the SLIP "
	"access to Internet.\n"
	"    \"PPP configuration\" is provided to be used with the ppp.device "
	"by Holger Kruse. The PPP protocol includes IP address negotiaition, "
	"so those have not to be asked during configuration.\n"
	"    \"Automatic dynamic IP configuration (BOOTP)\". This should be "
	"selected if your IP address is dynamic AND your network provides "
	"BOOTP service. Most terminal servers with dynamic IP addressing do "
	"have the BOOTP service. If you select to use BOOTP and there is no "
	"BOOTP service on your network, you will notice the case from the "
	"error messages when starting " app-name ". If this is the case, "
	"you should configure again with the manual dynamic IP option.\n"
	"    \"Manual dynamic IP configuration\" is provided for "
	"dynamic IP configuration without PPP or BOOTP. You will have to "
	"give the current IP address as an argument to the \"startnet\" "
	"each time you start " @app-name " if you select this option.\n"
	)
       (choices
	"Normal configuration"		; 0
	"TIA configuration"		; 1
	"PPP configuration"		; 2
	"Automatic dynamic IP configuration (BOOTP)"	; 3
	"Manual dynamic IP configuration"	; 4
	)
       (default 0)))
 ;; 
 ;; reset all relevant variables ("cs" == configuration style)
 ;;
 (set
  cs-if-type 0
  cs-if-choice 0
  cs-need-if-information 1
  cs-IP-address ""
;  cs-dest-IP-address ""
  cs-gateway ""
  cs-netmask ""
  cs-is-if-dynamic 0
  cs-use-servers 1                      ;; will be confirmed from the user
  cs-use-bootp 0
  cs-style-name "none"			;; should be overridden
  )
 ;;
 ;; set style options according to the user's choice
 ;;
 (select choice
	 ;; (0, normal)
	 (set
	  cs-style-name "Normal"
	  )
	 ;; (1, TIA configuration)
	 (set
	  cs-style-name "TIA"
	  cs-if-type 1		;;; SLIP/CSLIP
	  cs-if-choice 1	;;; default SLIP driver
	  cs-IP-address "192.0.2.1"	;;; The dummy IP for TIA
;	  cs-dest-IP-address "192.0.2.2" ;;; Another dummy for the destination
	  cs-gateway "192.0.2.2"	;;; The same for the gateway
	  cs-netmask "255.255.255.0"	;;; 192 is class C network
	  cs-use-servers 0		;;; do not install anything for servers
	  )
	 ;; (2, PPP configuration)
	 (set
	  cs-style-name "PPP"
	  cs-if-type 2		;;; PPP
	  cs-if-choice 1	;;; default PPP driver
	  cs-need-if-information 0	;;; PPP negotiates
;	  cs-IP-address "0.0.0.0"	;;; default dynamic IP address
	  cs-is-if-dynamic 1
	  )
	 ;; (3, dynamic IP with BOOTP)
	 (set
	  cs-style-name "Dynamic with BOOTP"
	  cs-need-if-information 0	;;; BOOTP negotiates
;	  cs-IP-address "0.0.0.0"	;;; default dynamic IP address
	  cs-is-if-dynamic 1
	  cs-use-bootp 1
	  )
	 ;; (4, manual dynamic IP)
	 (set
	  cs-style-name "Manual dynamic"
	  cs-IP-address "0.0.0.0"	;;; default manual dynamic IP address
	  cs-is-if-dynamic 1
	  )
	 )
 )
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; (Re-)configure AmiTCP/IP
;;;
(procedure
 configure-amitcp
 (transcript "Reconfiguring " @app-name ".")
 (ask-default-user)
 (while 
     ((ask-configuration-style)
      (NOT (ask-interfaces)))
   0) ; dummy statement
 (ask-gateway)
 (ask-hostname)
 (ask-run-servers)
 (create-startup-script)
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Installatation sequence
;;;
(message "    Please read the chapter \"Installing and Configuring AmiTCP/IP\" "
	 "of the AmiTCP/IP User's Manual before continuing further.\n"
	 "    Read the instructions provided behind the \"Help\" "
	 "buttons, if you are not absolutely sure what you are doing.\n"
	 "    Please read the \"readme\" files from the installation "
	 "directory. They contain valuable info you cannot afford to miss."
	 )

;
; Initialize "global" variables to default values (not complete)
;
(set  my-host-name ""
      my-host-aliases ""
      my-domain-name ""
      my-full-name ""

      startup-changed 0
      started-at-boot 0

      cs-if-type 0
      cs-if-choice 0
      cs-need-if-information 1
      cs-IP-address ""
      cs-gateway ""
      cs-netmask ""
      cs-is-if-dynamic 0
      cs-use-servers 1                      ;; will be confirmed from the user
      cs-use-bootp 0
      cs-style-name "none"			;; should be overridden

      )

(complete 00) (transcript "On configuring " app-name ".")
(complete 01) (check-user-level)
(complete 04) (check-atcp-assign)
(complete 05) 

(set @default-dest current-atcp-directory)

;
; Check if all the files generated by this script are on place or not
;
(if (OR (NOT (exists (tackon conf-dir "resolv.conf")))
	(NOT (exists (tackon bin-dir "startnet"))))
    (
     ;;
     ;; First time installation ("linear" installation)
     ;;
     (configure-amitcp)
     (ask-resolv-conf)
     (update-user-startup-conf)
     )
  (	;; Configuration files existed already
   ((transcript @app-name " already configured, presenting options")
    (while
	((complete 50)
	 (set choice
	      (askchoice
	       (prompt "The " app-name " seems to be already configured. "
		       "Select one of following:")
	       (help "    The AmiTCP/IP configuration files were found on your "
		     "disk.  Usually this means that AmiTCP/IP is already "
		     "configured.\n"
		     "    Now you can change your configuration. If you "
		     "want to re-install " app-name " you need to start "
		     "the \"Install_AmiTCP\" from the original installation "
		     "disk. This selection will "
		     "be repeatedly presented until \"Done\" is selected.\n"
		     "    The choices are:\n"
		     "\"Add new users\" -- allows you to add new users to "
		     "the user database (AmiTCP:db/passwd).\n"
		     "\"Change Name Service configuration\" -- allows you to "
		     "reconfigure the name servers and search domains.  See "
		     "documentation for the file AmiTCP:db/resolv.conf for "
		     "more information.\n"
		     "\"Change AmiTCP/IP configuration\" -- reconfigure the "
		     @app-name " startup. This creates a new "
		     AmiTCP:bin/startup " file.\n"
		     "\"Change system startup options\" -- configuration "
		     "options that change to \"AmiTCP/IP Configuration\" "
		     "section on the S:User-Startup.\n")
	       (choices
		"Add new users"				; 0
		"Change Name Service configuration"	; 1
		"Change AmiTCP/IP configuration"	; 2
		"Change system startup options"		; 3
		"Done")					; 4
	       (default 4)))
	 (<> choice 4))
      (select choice
	      ;; (0)
	      (add-new-users)
	      ;; (1)
	      (create-resolv-conf)
	      ;; (2)
	      (configure-amitcp)
	      ;; (3)
	      (update-user-startup-conf)
	      )
      )
    )
   )
  )

;;; All done!
(complete 100)
(message "\nConfiguration complete!\n\n"
	 (if startup-changed
	     (cat "The changes you made to system startup-options will take "
		  "effect only after the next reboot.\n"
		  (if started-at-boot
		      (cat "After the reboot " @app-name " should be running.")
		    (cat "Use \"startnet\" from CLI after the reboot to start "
			 @app-name ".\n")))
	   (cat "Use \"startnet\" from CLI to start " @app-name ".\n"))
	 )

(exit (quiet))
; EOF
