;;;; Hey Emacs, this script might as well be -*- lisp -*-
;;;;
;;;; Config AmiTCP - AmiTCP/IP configuration script for Installer
;;;;
;;;; Copyright © 1996 AmiTCP/IP Group,
;;;;                  NSDi - Network Solutions Development Inc., Finland
;;;;                  All rights reserved.
;;;;
;;;; $Id: Config\040AmiTCP,v 4.14 1996/03/29 02:27:47 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
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; What we are?
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(set app-name (cat @app-name " 4.3"))

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

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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Initialization
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(set 
 ;;
 ;; The name of the source directory
 ;;
 source-dir (if (= 1 (exists @icon))
		(pathonly (expandpath @icon))
	      (expandpath @icon))
 ;;
 ;; Destination directories of the AmiTCP/IP installation
 ;;
 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")
 
 ;;
 ;; How to get needed information?
 ;;
 net-setup-help
 "    You can get this information from your network administration.\n"
 
 ;;
 ;; copy "more" to ram: to be able to use it
 ;;
 pager-cmd 
 (if (exists "SYS:Utilities/More")
     ((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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Common subroutines
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(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 four "
		  "decimal numbers of range 0-255 separated by dots. "
		  "For example, "
		  "\"130.233.161.40\" is a formally valid internet address.\n"
		  "    You will be asked again for the address, "
		  "if the address you entered is of wrong format.")))
      ;; 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/IP from the installation disks."
	   ))))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Provider profile support
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 parse-provider-config
 ;;
 ;; Parse existing interface configuration using external tool "parseconfig"
 ;; initialize options known by us based on the results.
 ;; If interface is not configured, initialize to reasonable defaults.
 ;;
 ;; The provider file name is taken in pro_FileName
 ;;
 (set base-name ""
      ;;
      ;; Set reasonable defaults
      ;;
      pro_Name		"Default"
      pro_DialUp	1
      pro_Interface	"slip"
      pro_ICVJCMode     0
      pro_ICNoVJC	0
      pro_ICRest	""
      pro_NeedSerial	1
      pro_IPDynamic	0
      pro_IPAddr	""		;ask
      pro_DestIP	""		;ask
      pro_Gateway	""		;ask
      pro_Netmask	""		;ask
      pro_NSDynamic	0
      pro_UseBootP	0
      pro_MTU		576
      pro_Phone		""
      pro_HdrCompress   "AUTO"
      )
 (if (<> pro_FileName "")
     (if (exists pro_FileName)
	 (if (= (run (cat "AmiTCP:util/parseconfig PROVIDERFILE " pro_FileName) (safe)) 0)
	     (set env-base-name "ENV:Config_AmiTCP/Provider/"
		  base-name "Config_AmiTCP/Provider/"
		  pro_Name (if (exists (cat env-base-name "Name"))
			       (getenv (cat base-name "Name")) "")
		  pro_DialUp (if (exists (cat env-base-name "DialUp"))
				 (+ (getenv (cat base-name "DialUp")) 0))
		  pro_Interface (if (exists (cat env-base-name "Interface"))
				    (getenv (cat base-name "Interface")) "")
		  pro_ICVJCMode (if (exists (cat env-base-name "InterfaceConfig/VJCMode"))
				    (+ (getenv (cat base-name "InterfaceConfig/VJCMode")) 0))
		  pro_ICNoVJC (if (exists (cat env-base-name "InterfaceConfig/NoVJC"))
				  (getenv (cat base-name "InterfaceConfig/NoVJC")) "")
		  pro_ICRest (if (exists (cat env-base-name "InterfaceConfig/Rest"))
				 (getenv (cat base-name "InterfaceConfig/Rest")) "")
		  pro_NeedSerial (if (exists (cat env-base-name "NeedSerial"))
				     (+ (getenv (cat base-name "NeedSerial")) 0))
		  pro_IPDynamic (if (exists (cat env-base-name "IPDynamic"))
				    (+ (getenv (cat base-name "IPDynamic")) 0))
		  pro_IPAddr (if (exists (cat env-base-name "IPAddr"))
				 (getenv (cat base-name "IPAddr")) "")
		  pro_DestIP (if (exists (cat env-base-name "DestIP"))
				 (getenv (cat base-name "DestIP")) "")
		  pro_Gateway (if (exists (cat env-base-name "Gateway"))
				 (getenv (cat base-name "Gateway")) "")
		  pro_Netmask (if (exists (cat env-base-name "Netmask"))
				 (getenv (cat base-name "Netmask")) "")
		  pro_NSDynamic (if (exists (cat env-base-name "NSDynamic"))
				    (+ (getenv (cat base-name "NSDynamic")) 0))
		  pro_UseBootP (if (exists (cat env-base-name "UseBootP"))
				   (+ (getenv (cat base-name "UseBootP"))0))
		  pro_MTU (if (exists (cat env-base-name "MTU"))
			      (+ (getenv (cat base-name "MTU")) 0))
		  pro_Phone (if (exists (cat env-base-name "Phone"))
				(getenv (cat base-name "Phone")) "")
		  pro_HdrCompress (if pro_ICNoVJC
				      "NO"
				    (if pro_ICVJCMode
					"YES"
				      "AUTO"))
		  ))))

 )

(procedure
 save-provider-config
 (set
  pro_InterfaceConfig (cat (if pro_ICVJCMode
			       (cat "VJCMode " pro_ICVJCMode " "))
			   (if pro_ICNoVJC
			       "NoVJC ")
			   pro_ICRest)
  append-default-script (and (not (exists "ENV:Config_AmiTCP/Provider/DialScript"))
			     pro_NeedSerial))
 (if append-default-script
     (set append-default-script
	  (askbool
	   (prompt "Your serial configuration might need "
		   "a dialing script to be included into the "
		   "provider profile file " pro_FileName ".\n\n"
		   "Do you want the default dialing script for manual "
		   "dial-in to be automatically attached?")
	   (help "    If your serial line is a dedicated one (null "
		 "modem cable etc.), and does not need a dialing "
		 "script, then answer \"No\".")
	   )))
 (textfile (dest pro_FileName)
	   (append
	    (cat "/* Provider Configuration Follows:"
		 "\nName            " pro_Name
		 "\nDialUp          " pro_DialUp
		 "\nInterface       " pro_Interface
		 "\nInterfaceConfig \"" pro_InterfaceConfig "\""
		 "\nNeedSerial      " pro_NeedSerial
		 "\nIPDynamic       " pro_IPDynamic
		 "\nIPAddr          " pro_IPAddr
		 "\nDestIP          " pro_DestIP
		 "\nGateway         " pro_Gateway
		 "\nNetmask         " pro_Netmask
		 "\nNSDynamic       " pro_NSDynamic
		 "\nUseBootP        " pro_UseBootP
		 "\nMTU             " pro_MTU
		 "\nPhone           " pro_Phone
;		 "\nHdrCompress     " pro_HdrCompress
		 "\n*/\n"))
	   (if (exists "ENV:Config_AmiTCP/Provider/DialScript")
	       (include "ENV:Config_AmiTCP/Provider/DialScript")
	     (if append-default-script 
		 (include "AmiTCP:ssrx/Default.ssrx")
	       )
	     )
	   )
 (if append-default-script
     (message
      "\n"
      "  The default (manual) dialing script was appended to your "
      "provider profile file " pro_FileName "."))
 )


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; db/(auto)interfaces support
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 parse-if-config
 ;;
 ;; Parse existing interface configuration using external tool "parseconfig"
 ;; initialize options known by us based on the results.
 ;; If interface is not configured, initialize to reasonable defaults.
 ;;
 ;; The interface name is taken in pro_Interface
 ;;
 (set base-name ""
      ;;
      ;; Set reasonable default values
      ;;
      ifc_Device	""
      ifc_Unit		0
      ifc_Serial	0
      ifc_SerDevName	"serial.device"
      ifc_SerUnitNum	0
      ifc_SerBaud	9600
      ifc_CD		0
      ifc_7Wire		1
      ifc_UseODU	0
      ifc_Shared	1
      ifc_Rest		""
      )
 (if (<> pro_Interface "")
     (if (= (run (cat "AmiTCP:util/parseconfig INTERFACE " pro_Interface) (safe)) 0)
	 ((set env-base-name (cat "ENV:Config_AmiTCP/if/" pro_Interface "/")
	       base-name (cat "Config_AmiTCP/if/" pro_Interface "/")
	       ifc_Device (if (exists (cat env-base-name "Device"))
			      (getenv (cat base-name "Device")) "")
	       ifc_Unit (if (exists (cat env-base-name "Unit"))
			    (+ (getenv (cat base-name "Unit")) 0))
	       )
	  (if (= 2 (exists (cat env-base-name "SerialConfig")))
	      (set
	       ifc_Serial 1
	       env-base-name (cat env-base-name "SerialConfig/")
	       base-name (cat base-name "SerialConfig/")
	       ifc_SerDevName (if (exists (cat env-base-name "SerDevName"))
				  (getenv (cat base-name "SerDevName")) "")
	       ifc_SerUnitNum (if (exists (cat env-base-name "SerUnitNum"))
				  (+ (getenv (cat base-name "SerUnitNum")) 0))
	       ifc_SerBaud (if (exists (cat env-base-name "SerBaud"))
			       (+ (getenv (cat base-name "SerBaud")) 0))
	       ifc_CD (if (exists (cat env-base-name "CD")) 1 0)
	       ifc_7Wire (if (exists (cat env-base-name "7Wire")) 1 0)
	       ifc_UseODU (if (exists (cat env-base-name "UseODU")) 1 0)
	       ifc_Shared (if (exists (cat env-base-name "Shared")) 1 0)
	       ifc_Rest (if (exists (cat env-base-name "Rest"))
				  (getenv (cat base-name "Rest")) "")
	       )))))
 )


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Serial device configuration
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ask-serial-config

 ;;
 ;; parse-if-config has to be called before this
 ;;
 ;; The device configuration is stored in the interfaces entry on the
 ;; db/interfaces. This procedure handles the SERIAL specific options and
 ;; returns them in if-serial-config.
 ;;
 ;; The options we support are:
 ;;
 ;; ifc_SerDevName - serial device
 ;; ifc_SerUnitNum - serial device unit
 ;; ifc_SerBaud - serial line bit rate
 ;; ifc_CD - Carrier detect
 ;; ifc_7Wire - Hardware flow control (recommended)
 ;; ifc_UseODU - Use OwnDevUnit.library to regulate serial device access
 ;; ifc_Shared - use serial in shared mode
 ;; ifc_Rest - additional serial options
 
 (transcript "Asking SERIAL options.")
 ;;
 ;; Subroutine to check if the device exists
 ;;
 (procedure
  serial-device-exists
  ;;
  ;; Check if serial device (ifc_SerDevName) exists either as a file or
  ;; as a resident device.
  ;;
  (if (<> ifc_SerDevName "")
      (if (= 1 (exists ifc_SerDevName)) ;; file exists?
	  (<> (getversion ifc_SerDevName) 0) ;; file version available?
	(if (<> (getversion (fileonly ifc_SerDevName) (resident)) 0)
					;; resident version available?
	    ((set ifc_SerDevName (fileonly ifc_SerDevName)) ;; remove path
	     1) ;; true, exists
	  ))
    )
  )

 ;;
 ;; Loop until the user is satisfied
 ;;
 (while
     ((set ifc_SerDevName
	   (askfile (prompt "Select the SERIAL device driver for "
			    pro_Interface ":\n"
			    "NOTE: See Help."
			    )
		    (default (if (patmatch "#?:#?" ifc_SerDevName)
				 ifc_SerDevName
			       (expandpath (cat "DEVS:" (fileonly ifc_SerDevName)))))
		    (help "    You should select the serial device driver to "
			  "be used for the transport of " pro_Interface ". "
			  "You will be separately asked for the unit number.\n"
			  "    This list lists all devices in DEVS:. "
			  "Normally you would want to select "
			  "`serial.device', but "
			  "if your serial device is ROM resident, "
			  "e.g. gvpser.device, "
			  "you should enter its name manually.\n"
			  "    You can cancel this operation by giving an "
			  "empty string.")))
      (if (NOT (serial-device-exists))
	  (if (<> ifc_SerDevName "")
	      ((message "\n"
			"   The serial device " ifc_SerDevName " 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 (= (pathonly (expandpath ifc_SerDevName))
		(expandpath "DEVS:"))
	     (set ifc_SerDevName (fileonly ifc_SerDevName)))

	 (set ifc_SerUnitNum
	      (asknumber
	       (prompt "\nSelect unit number for the " ifc_SerDevName ":")
	       (default ifc_SerUnitNum)
	       (help "    Select the unit number for the device "
		     ifc_SerDevName " to use. This is 0 for the "
		     "internal serial port, but might be other for "
		     "other serial devices."))

	      ifc_SerBaud
	      (asknumber
	       (prompt "\nGive the baud rate for the " ifc_SerDevName
		       " unit " ifc_SerUnitNum ".\n"
		       "\nPlease start with a low value like 9600, "
		       "if you are not absolutely sure that your serial "
		       "line works at higher speeds.\n")
	       (default ifc_SerBaud)
	       (help "    The baud rate MUST match the one used while "
		     "dialing to the IP 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 setup "
		     "works, try out the higher speeds."))

	      current-bitmap
	      (bitor (if ifc_CD %0001 0)
		     (bitor (if ifc_7Wire %0010 0)
			    (bitor (if ifc_UseODU %0100 0)
				   (bitor (if ifc_Shared %1000 0)
					  0)
				   )
			    )
		     )
	      my-serial-options-bitmap
	      (askoptions
	       (prompt "\nSelect additional options to be used with the "
		       pro_Interface ":\n"
		       "\nPlease see Help for explanations for each option.")
	       (choices "Carrier Detect" "Hardware-handshake (CTS/RTS)"
			"Use ODU" "Shared mode")
	       (default current-bitmap)
	       (help "    Carrier Detect (CD): "
		     "If selected, causes the " pro_Interface " 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"
		     "    Use ODU (UseODU): "
		     "Tells " pro_Interface " 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 " pro_Interface " to "
		     "use a serial port opened by some one else.\n"
		     "    Shared mode (Shared): "
		     "Tells " pro_Interface " to open the serial port in "
		     "shared mode. Using this mode allows AmiTCP/IP "
		     "Dialer to keep serial open until the " pro_Interface
		     " opens it. This will keep the DTR signal on, and "
		     "allows modem to hangup automatically when you "
		     "stop using AmiTCP/IP. This option may also be "
		     "useful with "
		     "some \"getty\"-type of programs together with "
		     "the USEODU option.\n"
		     ))
	      ifc_CD (in my-serial-options-bitmap 0)
	      ifc_7Wire (in my-serial-options-bitmap 1)
	      ifc_UseODU (in my-serial-options-bitmap 2)
	      ifc_Shared (in my-serial-options-bitmap 3)

	      my-serial-options
	      (cat
	       (if ifc_CD        "CD ")
	       (if ifc_7Wire     "7Wire ")
	       (if ifc_UseODU    "UseODU ")
	       (if ifc_Shared    "Shared ")
	       )

	      ifc_Rest
	      (askstring
	       (prompt "\nGive any additional serial options for the "
		       "interface " pro_Interface ":\n"
		       "\nSee help for additional instructions!\n"
		       )
	       (default ifc_Rest)
	       (help
		"    Only set here options that affect your serial interface "
		"locally. IP provider specific options can be given elsewhere.\n"
		"    Additional options must be given in format specified in "
		"the Sana2 device documentation. Multiple options are separated "
		"with spaces.\n"
		"    Please do NOT add any of the following options, since they "
		"are handled by this script elsewhere:\n\n"
		"SERNAME, SERUNIT, SERBAUD, IPSTR, CD, 7WIRE, USEODU, SHARED, MTU, "
		"VJCMODE, NOVJC, DIALSCRIPT\n\n"
		"    These options are stored into db/autointerfaces file. "
		"Bootpconfig utility will then "
		"add these to the Sana2 device configuration file.\n"))

	      ) ;; set

	 (if (not (askbool
		   (prompt
		    "This is the serial configuration you gave:\n"
		    "\nSerial device: " ifc_SerDevName
		    "\nSerial unit: " ifc_SerUnitNum
		    "\nSerial baud rate: " ifc_SerBaud
		    "\nSerial options: " my-serial-options
		    "\nAdditional serial options: " ifc_Rest
		    "\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 configuration string
	    (set if-serial-config
		 (cat ifc_SerDevName " "
		      ifc_SerUnitNum " "
		      ifc_SerBaud " "
		      "0.0.0.0 "
		      my-serial-options
		      "MTU=1500"	; Maximum Receive Unit
		      (if ifc_Rest (cat " " ifc_Rest))
		      ))
	    0				; no need to ask again
	    ))))
      )
   )
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 configure-serial
 (if (not pro_NeedSerial)
     (message "The interface " pro_Interface " does not need a serial device. "
	      "If you have selected a wrong interface, please configure again "
	      "with another interface.")
   ((while
	((ask-serial-config)
	 (= ifc_SerDevName ""))
      0)
    (create-db-autointerfaces))
   )
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Interface Configuration
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ask-configuration-style
 ;;
 ;; Ask dialup configuration style
 ;;
 ;; parse-provider-config must be called before this
 ;;
 ;; This function sets following variables:
 ;;
 ;; cs-style-name - name of the configuration style
 ;; cs-use-servers- ask user whether servers should be used?
 ;; pro_Interface - name of the network interface
 ;; pro_NeedSerial- 0 or 1
 ;; pro_IPDynamic - 0 or 1
 ;; pro_UseBootP  - 0 or 1
 ;; pro_IPAddr    - IP address if not static (0.0.0.0 if dynamic)
 ;; pro_DialUp    - if this is an dialup configuration
 ;;
 ;; pro_Interface, pro_NeedSerial, pro_IPAddr, pro_DestIP, pro_Gateway,
 ;; pro_Netmask
 ;; are intentionally NOT set if they do not have fixed values
 ;;
 (transcript "Asking dialup configuration style.")

 ;;
 ;; Compute index for the current configuration
 ;;
 (set cs-style-current
      (if (not pro_DialUp)
	  (if pro_UseBootP
	      2 ;; Fixed with BOOTP
	    (if pro_IPDynamic 1 ;; Fixed dynamic IP
	      0) ;; Fixed without BOOTP
	    )
	(if (= pro_Interface "slip")
	    (if (= pro_IPAddr "192.0.2.1")
		9	;; TIA
	      (if (not pro_IPDynamic)
		  3	;; static SLIP
		(if pro_UseBootP
		    5	;; Dynamic SLIP with BOOTP
		  4	;; Dynamic SLIP without BOOTP
		  )))
	  (if (not pro_IPDynamic)
	      6	;; static PPP
	    (if pro_UseBootP
		8	;; Dynamic PPP with BOOTP
	      7	;; Dynamic PPP without BOOTP
	      ))
	  )))

 (set cs-style-id
      (askchoice
       (prompt "Select one of the following configuration styles:\n"
	       "(See help for explanations.)\n")
       (help
	"Explanations for the different configuration styles:\n"
	"\n"
	"* \"Fixed Network Connection\" should be used when you have a "
	"non-dial-up "
	"network connection, like Ethernet, or fixed serial line.\n\n"

	"* \"Fixed Connection, Dynamic IP\" should be used with fixed "
	"connections with dynamic IP address assignment.\n\n"
	"* \"Fixed Connection, BOOTP\" should be used with fixed "
	"connections providing BOOTP service.\n\n"
	"* \"Static SLIP DialUp\" should be used when you have been given "
	"your own IP address.\n\n"
	"* \"Dynamic SLIP DialUp\" is provided for "
	"dynamic SLIP configuration without BOOTP. If the dial script does "
	"not parse the IP address from the server output, you will be "
	"prompted for the IP address each time you start " @app-name ".\n\n"
	"* \"Dynamic SLIP DialUp, 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 some other style.\n\n"
	"* \"Static PPP\" should be used when you have been given "
	"your own IP address.\n\n"
	"* \"Dynamic PPP DialUp\" is provided for "
	"generic dynamic PPP configuration.\n\n"
	"* \"Dynamic PPP DialUp, 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 some other style.\n\n"
	"* \"TIA DialUp\" should be used if TIA (The Internet "
	"Adapter, a commercial product for Unix) is used to provide the "
	"SLIP access."
        )
       (choices
	"Fixed Network Connection"	; 0
	"Fixed Connection, Dynamic IP"	; 1
	"Fixed Connection, BOOTP"	; 2
	"Static SLIP DialUp"		; 3
	"Dynamic SLIP DialUp"		; 4
	"Dynamic SLIP DialUp, BOOTP"	; 5
	"Static PPP DialUp"		; 6
	"Dynamic PPP DialUp"		; 7
	"Dynamic PPP DialUp, BOOTP"	; 8
	"TIA DialUp"			; 9
	)
       (default cs-style-current)
       ))
 ;;
 ;; set style options according to the user's choice
 ;;
 (select cs-style-id
	 ;; (0, Fixed Network Connection)
	 (set
	  cs-style-name "Fixed Network Connection"
	  pro_DialUp 0
;;	  pro_Interface ""	;; use current
;;	  pro_NeedSerial 0	;; use current
;;	  pro_IPAddr ""		;; use current
	  pro_IPDynamic 0
	  pro_UseBootP 0
	  cs-use-servers 1
	  )
	 ;; (1, Fixed Network, Dynamic IP)
	 (set
	  cs-style-name "Fixed Connection, Dynamic IP"
	  pro_DialUp 0
;;	  pro_Interface ""	;; use current
;;	  pro_NeedSerial 0	;; use current
	  pro_IPAddr "0.0.0.0"	;; dynamic
	  pro_IPDynamic 1
	  pro_UseBootP 0
	  cs-use-servers 1
	  )
	 ;; (2, Fixed Connection, BOOTP)
	 (set
	  cs-style-name "Fixed Connection, BOOTP"
	  pro_DialUp 0
;;	  pro_Interface ""	;; use current
;;	  pro_NeedSerial 0	;; use current
	  pro_IPAddr "0.0.0.0"	;; dynamic
	  pro_IPDynamic 1
	  pro_UseBootP 1
	  cs-use-servers 1
	  )
	 ;; (3, Static SLIP DialUp)
	 (set
	  cs-style-name "Static SLIP DialUp"
	  pro_DialUp 1
	  pro_Interface "slip"
	  pro_NeedSerial 1
;;	  pro_IPAddr ""		;; remember old address
	  pro_IPDynamic 0
	  pro_UseBootP 0
	  cs-use-servers 0
	  )
	 ;; (4, Dynamic SLIP DialUp)
	 (set
	  cs-style-name "Dynamic SLIP DialUp"
	  pro_DialUp 1
	  pro_Interface "slip"
	  pro_NeedSerial 1
	  pro_IPAddr "0.0.0.0"		;; default IP address (not known)
	  pro_IPDynamic 1
	  pro_UseBootP 0
	  cs-use-servers 0
	  )
	 ;; (5, Dynamic SLIP DialUp, BOOTP)
	 (set
	  cs-style-name "Dynamic SLIP DialUp, BOOTP"
	  pro_DialUp 1
	  pro_Interface "slip"
	  pro_NeedSerial 1
	  pro_IPAddr "0.0.0.0"		;; default IP address (not known)
	  pro_IPDynamic 1
	  pro_UseBootP 1
	  cs-use-servers 0
	  )
	 ;; (6, Static PPP DialUp)
	 (set
	  cs-style-name "Static PPP DialUp"
	  pro_DialUp 1
	  pro_Interface "ppp"
	  pro_NeedSerial 1
;;	  pro_IPAddr ""		;; remember old address
	  pro_IPDynamic 0
	  pro_UseBootP 0
	  cs-use-servers 0
	  )
	 ;; (7, Dynamic PPP DialUp)
	 (set
	  cs-style-name "Dynamic PPP DialUp"
	  pro_DialUp 1
	  pro_Interface "ppp"
	  pro_NeedSerial 1
	  pro_IPAddr "0.0.0.0"		;; default IP address (not known)
	  pro_IPDynamic 1
	  pro_UseBootP 0
	  cs-use-servers 0
	  )
	 ;; (8, Dynamic PPP DialUp, BOOTP)
	 (set
	  cs-style-name "Dynamic PPP DialUp, BOOTP"
	  pro_DialUp 1
	  pro_Interface "ppp"
	  pro_NeedSerial 1
	  pro_IPAddr "0.0.0.0"		;; default IP address (not known)
	  pro_IPDynamic 1
	  pro_UseBootP 1
	  cs-use-servers 0
	  )
	 ;; (9, TIA DialUp)
	 (set
	  cs-style-name "TIA DialUp"
	  pro_DialUp 1
	  pro_Interface "slip"
	  pro_NeedSerial 1
	  pro_IPAddr "192.0.2.1"	;;; The dummy IP for TIA
	  pro_IPDynamic 0
	  pro_UseBootP 0
	  cs-use-servers 0
	  )
	 )
 (set ifc_Name pro_Interface) ;; direct mapping this time
 )


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; parse-provider-config has to be called before this
;;
;; The provider configuration is stored in db/Provider.conf
;; This procedure edits this configuration.
;;
;; The options we support are:
;;
;; pro_Interface  - slip or ppp
;; pro_IPDynamic - 0 or 1
;; pro_UseBootP - 0 or 1
;; pro_IPAddr - IP address if not static (0.0.0.0 if dynamic)
;;
;; pro_NSDynamic - YES|NO
;; pro_MTU       - 72 to 1500
;; pro_Phone     - provider phone number
;; pro_HdrCompress - YES|NO|AUTO (if changed, set pro_ICVJCMode and pro_ICNoVJC)
;;
(procedure
 ask-provider-config
 (transcript "Asking PROVIDER options.")
 ;;
 ;; Loop until the user is satisfied
 ;;
 (while
     ((ask-configuration-style)
      (not
       (if pro_DialUp
	   (ask-dialup-provider-config)
	 (ask-fixed-provider-config))))
   )
 )

(procedure
 ask-dialup-provider-config
 ;;
 ;; Confirm/update DialUp Provider options.
 ;; We return true if the user is satisfied with the values.
 ;;
 ;; pro_Name, pro_DialUp, pro_Interface, pro_NeedSerial, pro_IPDynamic and
 ;; pro_UseBootP are already set.
 ;;
 (transcript "Asking DIALUP PROVIDER options.")

 (set
  pro_IPAddr
  (if pro_IPDynamic "0.0.0.0"
    (if-ask-address))
  pro_DestIP (if-ask-destination)
  pro_Netmask ""	;; serial is p-to-p, mask not needed
  pro_Gateway (if-ask-gateway)
      
  pro_NSDynamic
  (askchoice
   (prompt "\nIs your name server configuration static or are the"
	   " name servers configured dynamically?")
   (default pro_NSDynamic)
   (choices "Static" "Dynamic")
   (help "    If the addresses of the name servers are known in advance"
	 " then the configuration is static. In this case you will "
	 "be prompted for the name server addresses during the "
	 "configuration phase.\n"
	 "    If the addresses of the name servers may be different "
	 "on different logins, then the configuration is dynamic. "
	 "In this case the name servers must be configured by the "
	 "dial script or they must be gotten via BOOTP.\n"
	 )
   )
  pro_MTU
  (asknumber
   (prompt "\nGive the Maximum Transfer Unit (MTU) for the "
	   pro_Interface ":\n")
   (range 72 1500)
   (default pro_MTU)
   (help "    This option affects only outgoing data. "
	 "Maximum Receive Unit size is not configurable.\n"
	 "    Smaller values give better interactive response "
	 "during file transfers, while larger values give better "
	 "throughput."
	 ))
  pro_Phone
  (askstring
   (prompt "\nGive the phone number for your IP provider:\n"
	   "Please enter JUST numbers, or your modem will not accept "
	   "the number.")
   (default pro_Phone)
   (help "   The phone number should countain JUST numbers!\n"))
  
  new_pro_HdrCompress
  (select
   (askchoice
    (prompt "\nSelect IP header compression mode:")
    (default (if (= pro_HdrCompress "YES")
		 0
	       (if (= pro_HdrCompress "NO")
		   1
		 2)))
    (choices "YES"
	     "NO"
	     "AUTO")
    (help "    You should ask your IP service provider for the correct "
	  "choice for the header compression. However, \"AUTO\" is always "
	  "a safe choice.\n"
	  "    If you select \"YES\", header "
	  "compression is allways applied.\n"
	  "    The option \"NO\", header "
	  "compression is not applied to outgoing data, but if "
	  "incoming headers are compressed they are still "
	  "uncompressed.\n"
	  "    In \"AUTO\" mode header "
	  "compression is off by default, but after a "
	  "compressed packet is received, outgoing headers "
	  "are compressed as well.\n"))
   "YES" "NO" "AUTO")
  pro_ICRest
  (askstring
   (prompt "\nGive any additional options for the interface " pro_Interface ":\n"
	   "\nSee help for additional instructions!\n"
	   )
   (default pro_ICRest)
   (help
    "    Only set here options that affect your IP provider. "
    "Local serial interface specific options can be given elsewhere.\n"
    "    Additional options must be given in format specified in the "
    "Sana2 device documentation. Multiple options are separated with "
    "spaces.\n"
    "    Please do NOT add any of the following options, since they are "
    "handled by this script elsewhere:\n\n"
    "SERNAME, SERUNIT, SERBAUD, IPSTR, CD, 7WIRE, USEODU, SHARED, MTU, "
    "VJCMODE, NOVJC, DIALSCRIPT\n\n"
    "    If you are using ppp.device, please consult the PPP.guide "
    "for allowed options (PAP, CHAP, etc.)\n"
    "    These options are stored into the InterfaceConfig entry into the "
    "provider profile (db/Provider.conf). Bootpconfig utility will then "
    "add these to the Sana2 device configuration file.\n"))
  ) ;; set

 (if (AND (<> new_pro_HdrCompress "")
	  (<> new_pro_HdrCompress pro_HdrCompress))
     ((set pro_HdrCompress new_pro_HdrCompress)
      (set pro_ICVJCMode (if (= "YES" pro_HdrCompress) 2 0))
      (set pro_ICNoVJC (if (= "NO" pro_HdrCompress) 1 0))))
 
 (askbool
  (prompt
   "Your " cs-style-name " configuration is:\n"
   "\nInterface: " pro_Interface
   "\nIP Address: " (if pro_IPDynamic "<dynamic>" pro_IPAddr)
   "\nUseBootP: " (if pro_UseBootP "YES" "NO")
   "\nDynamic Name Servers: " (if pro_NSDynamic "YES" "NO")
   "\nMTU: " pro_MTU
   "\nPhone number: " pro_Phone
   "\nTCP header compression: " pro_HdrCompress
   "\nAdditional options: " pro_ICRest
   "\n\nIs this correct?")
  (help
   "    Check the information shown. If you do not "
   "confirm it, all of it will be asked again."))
 )

(procedure
 ask-fixed-provider-config
 ;;
 ;; Confirm/update Fixed Provider options.
 ;; We return true if the user is satisfied with the values.
 ;;
 ;; pro_Name, pro_DialUp, pro_IPDynamic, pro_UseBootP are already set.
 ;;
 (transcript "Asking FIXED PROVIDER options.")

 (procedure
  if-ask-interface
  ;;
  ;; Ask if want to change the interface if already set
  ;;
  (set do-ask-if
       (if (= pro_Interface "")
	   1
	 (not (askbool 
	       (prompt "Do you want to keep the current interface?\n\n"
		       "Current interface is: \"" pro_Interface "\".")
	       (help "The current interface name will be kept if you do not want "
		     "to change it.")))))

  (if do-ask-if
      ;;
      ;; Sets pro_Interface if one is selected
      ;;
      (set
       if-type-choice
       ;;
       ;; Select the interface type
       ;;
       (askchoice
	(prompt (cat "Select the 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")
	(choices
	 "SLIP/PPP"		; 0
	 "X.25"		; 1
	 "Ethernet"		; 2
	 "Arcnet"		; 3
	 "GGBus+ Ethernet"	; 4
	 "PLIP/Liana"	; 5
	 )
	(default 0))
       ;;
       ;; SLIP/PPP needs serial
       ;;
       pro_NeedSerial (= if-type-choice 0)
       pro_MTU (if (= if-type-choice 0) 576 0) ;; default MTU

       ;;
       ;; Select the specific interface of the type
       ;;
       if-choice
       (askchoice
	(prompt (cat "Select the 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 if-type-choice
		(			; type 0 (SLIP/PPP)
		 (choices "SLIP"		; 0
			  "PPP"			; 1
			  ))
		(			; type 1 (AX.25)
		 (choices "axdm"		; 0
			  ))
		(			; type 2 (Ethernet)
		 (choices "CBM A2065"		; 0
			  "Hydra Ethernet"	; 1
			  "ASDG EB920"		; 2
			  "Village Tronic Ariadne" ; 3
			  "Ameristar a4066" 	; 4
			  "QuickNet"		; 5
			  )
		 (default 3))
		(			; type 3 (Arcnet)
		 (choices "CBM A2060"		; 0
			  ))
		(			; type 4 (GGBus+ Ethernet)
		 (choices "3COM 3C503"		; 0
			  "NE1000" 		; 1
			  "NE2000" 		; 2
			  "WD80x3"		; 3
			  )
		 (default 2))
		(			; type 5 (PLIP/Liana)
		 (choices "PLIP unit 0"			; 0
			  "PLIP unit 1"			; 1
			  "Liana unit 0"		; 2
			  "Liana unit 1"		; 3
			  "Ariadne Liana unit 0"	; 4
			  "Ariadne Liana unit 1"	; 5
			  ))
		))
       ;;
       ;; Set the interface name according to the selection
       ;;
       ;; The names int the table must match the ones defined in db/interfaces
       ;;
       pro_Interface
       (select (+ (* if-type-choice 8) if-choice)
					; type 0 (SLIP/PPP)
	       "slip"	; (0) 
	       "ppp"	; (1)
	       ""		; (2)
	       ""		; (3)
	       ""		; (4)
	       ""		; (5)
	       ""		; (6)
	       ""		; (7)
					; type 1 (AX.25)
	       "ax25"	; (0) 
	       ""		; (1)
	       ""		; (2)
	       ""		; (3)
	       ""		; (4)
	       ""		; (5)
	       ""		; (6)
	       ""		; (7)
					; type 2 (Ethernet)
	       "a2065"	; (0) 
	       "hydra"	; (1)
	       "eb920"	; (2)
	       "ariadne"	; (3)
	       "a4066"	; (4)
	       "quicknet"	; (5)
	       "wd80xx"	; (6)
	       ""		; (7)
					; type 3 (Arcnet)
	       "a2060"	; (0) 
	       ""		; (1)
	       ""		; (2)
	       ""		; (3)
	       ""		; (4)
	       ""		; (5)
	       ""		; (6)
	       ""		; (7)
					; type 4 (GGBus+ Ethernet)
	       "gg_3c503"	; (0) 
	       "gg_ne1000"	; (1)
	       "gg_ne2000"	; (2)
	       "gg_smc"	; (3)
	       ""		; (4)
	       ""		; (5)
	       ""		; (6)
	       ""		; (7)
					; type 5 (Village Tronic Liana)
	       "plip0"	; (0) 
	       "plip1"	; (1)
	       "liana0"	; (2)
	       "liana1"	; (3)
	       "ariadneliana0" ; (4)
	       "ariadneliana1" ; (5)
	       ""		; (6)
	       ""		; (7)
	       ))))
 ;;
 ;; Sets:
 ;; pro_NeedSerial
 ;; pro_Interface
 (if-ask-interface)

 (set
  pro_IPAddr (if pro_IPDynamic "0.0.0.0"
	       (if-ask-address))
  pro_DestIP (if (not pro_NeedSerial) "";; only p-to-p might need dest
	     (if-ask-destination))
  pro_Netmask (if pro_NeedSerial ""	;; serial is p-to-p, mask not needed
		(if-ask-netmask))
  pro_Gateway (if-ask-gateway)
  
  pro_NSDynamic
  (askchoice
   (prompt "\nIs your name server configuration static or are the"
	   " name servers configured dynamically?")
   (default pro_NSDynamic)
   (choices "Static" "Dynamic")
   (help "    If the addresses of the name servers are known in advance"
	 " then the configuration is static. In this case you will "
	 "be prompted for the name server addresses during the "
	 "configuration phase.\n"
	 "    If the addresses of the name servers may be different "
	 "on different logins, then the configuration is dynamic. "
	 "In this case the name servers must be configured by the "
	 "dial script or they must be gotten via BOOTP.\n"
	 )
   )
  pro_MTU
  (asknumber
   (prompt "\nGive the Maximum Transfer Unit (MTU) for interface "
	   "\"" pro_Interface "\":\n\n"
	   "0 represents the interface default (maximum).")
   (range 0 1500)
   (default pro_MTU)
   (help "    This option affects only outgoing data. "
	 "Maximum Receive Unit size is not configurable.\n"
	 "    Smaller values give better interactive response "
	 "during file transfers, while larger values give better "
	 "throughput."
	 "For other than serial device using interfaces you should "
	 "select 0, which causes the hardware default MTU to be used."
	 ))
  pro_Phone ""
  new_pro_HdrCompress
  (if (not pro_NeedSerial) ""
    (select
     (askchoice
      (prompt "\nSelect IP header compression mode:")
      (default (if (= pro_HdrCompress "YES")
		   0
		 (if (= pro_HdrCompress "NO")
		     1
		   2)))
      (choices "YES"
	       "NO"
	       "AUTO")
      (help "    You should ask your IP service provider for the correct "
	    "choice for the header compression. However, \"AUTO\" is always "
	    "a safe choice.\n"
	    "    If you select \"YES\", header "
	    "compression is allways applied.\n"
	    "    The option \"NO\", header "
	    "compression is not applied to outgoing data, but if "
	    "incoming headers are compressed they are still "
	    "uncompressed.\n"
	    "    In \"AUTO\" mode header "
	    "compression is off by default, but after a "
	    "compressed packet is received, outgoing headers "
	    "are compressed as well.\n"))
     "YES" "NO" "AUTO"))
  pro_ICRest
  (if (not pro_NeedSerial) pro_ICRest
    (askstring
     (prompt "\nGive any additional options for the interface " pro_Interface ":\n"
	     "\nSee help for additional instructions!\n"
	     )
     (default pro_ICRest)
     (help
      "    Only set here options that affect your IP provider. "
      "Local serial interface specific options can be given elsewhere.\n"
      "    Additional options must be given in format specified in the "
      "Sana2 device documentation. Multiple options are separated with "
      "spaces.\n"
      "    Please do NOT add any of the following options, since they are "
      "handled by this script elsewhere:\n\n"
      "SERNAME, SERUNIT, SERBAUD, IPSTR, CD, 7WIRE, USEODU, SHARED, MTU, "
      "VJCMODE, NOVJC, DIALSCRIPT\n\n"
      "    If you are using ppp.device, please consult the PPP.guide "
      "for allowed options (PAP, CHAP, etc.)\n"
      "    These options are stored into the InterfaceConfig entry into the "
      "provider profile (db/Provider.conf). Bootpconfig utility will then "
      "add these to the Sana2 device configuration file.\n")))
  ) ;; set

 (if (AND (<> new_pro_HdrCompress "")
	  (<> new_pro_HdrCompress pro_HdrCompress))
     ((set pro_HdrCompress new_pro_HdrCompress)
      (set pro_ICVJCMode (if (= "YES" pro_HdrCompress) 2 0))
      (set pro_ICNoVJC (if (= "NO" pro_HdrCompress) 1 0))))
 
 (askbool
  (prompt
   "This is the configuration you gave:\n"
   "\nInterface: " pro_Interface
   "\nIP Address: " (if pro_IPDynamic "<dynamic>" pro_IPAddr)
   "\nNetmask: " (if (= pro_Netmask "") "<default>" pro_Netmask)
   "\nGateway Address: " pro_Gateway
   "\nUseBootP: " (if pro_UseBootP "YES" "NO")
   "\nDynamic Name Servers: " (if pro_NSDynamic "YES" "NO")
   "\nMTU: " (if (= pro_MTU 0) "<default>" pro_MTU)
   (if pro_NeedSerial (cat "\nTCP header compression: " pro_HdrCompress
			   "\nAdditional options: " pro_ICRest))
   "\n\nIs this correct?")
  (help
   "    Check the information shown. If you do not "
   "confirm it, all of it will be asked again."))
 )


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Ask for the IP address of this host
;;
(procedure
 if-ask-address
 (if (= pro_IPAddr "0.0.0.0")
     (set pro_IPAddr ""))
 (set ::ask-ip-prompt
      (cat "Give IP address for the interface " pro_Interface ":\n")
      ::ask-ip-help
      (cat "    IP address must be configured now for a static configuration.\n"
	   "    WARNING: Only ONE of the possible values is legal, random IP "
	   "addresses must NOT "
	   "be used, it might cause harm for you and your IP provider.\n\n"
	   "    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 pro_IPAddr
      pro_IPAddr (ask-ip-address))
 )

 
(procedure
 if-ask-gateway ;;; Ask the default gateway address
 ;;
 ;; Returns the gateway address
 ;;
 (set ::ask-ip-prompt 
      (cat
       "Give the IP address of the default gateway:\n"
       "\n"
       (if pro_NeedSerial
	   (cat "If you have only ONE network connection, then this "
		"setting is OPTIONAL and SHOULD NOT be given."))
       )
      ::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.\n"
       (if pro_NeedSerial
	   (cat
	    "    If you have only one network interface, then the default "
	    "gateway does NOT need to be configured, since all packets "
	    "have to be sent over the serial line anyway."))
       )
      ::ask-ip-need 0
      ::ask-ip-default pro_Gateway
      )
 (ask-ip-address))

(procedure
 if-ask-destination ;;; Ask the destination ip address
 ;;
 ;; Returns the destination address
 ;;
 (set ::ask-ip-prompt 
      (cat
       "Give the destination IP address:\n"
       "(Destination is the OTHER END of the line.)\n"
       "\n"
       "NOTE: This is needed ONLY IF you are using MULTIPLE "
       "network interfaces."
       )
      ::ask-ip-help
      (cat
       "    If you have only one network interface, then it is "
       "irrelevant which machine is at the other end of the line, "
       "since all packets will be routed to that interface anyway.\n"
       "    If you are going to use multiple network interfaces, "
       "then you need to tell the other end of each of the "
       "point-to-point interfaces.\n"
       "    PLEASE NOTE that this utility can manage one interface "
       "only. See the \"Read Me First\" file for instructions "
       "for configuring multiple interfaces.\n"
       )
      ::ask-ip-need 0
      ::ask-ip-default pro_DestIP
      )
 (ask-ip-address))

(procedure
 if-ask-netmask
 ;;
 ;; Returns the netmask
 ;;
 (set ::ask-ip-prompt
      (cat "Give netmask of the network on the interface "
	   pro_Interface ".\n"
	   "Address of the interface is "
	   (if pro_IPDynamic
	       "<dynamic>"
	     pro_IPAddr)
	   ".\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 pro_Netmask
      )
 (ask-ip-address))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 create-db-autointerfaces
 ;;
 (textfile (dest (tackon conf-dir "autointerfaces"))
	   (append "# This file is generated automatically by 'Config AmiTCP'\n")
	   (append
	    (cat "slip DEV=DEVS:Networks/aslip.device UNIT=0 DoOffline "
		 "ConfigFileName=ENV:Sana2/aslip0.config "
		 "ConfigFileContents=\"" if-serial-config "\"\n"))
	   (append
	    (cat "ppp DEV=DEVS:Networks/ppp.device UNIT=0 DoOffline "
		 "ConfigFileName=ENV:Sana2/ppp0.config "
		 "ConfigFileContents=\"" if-serial-config "\"\n"))
	   )
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; 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 "")))
   (set domain-list ("%sDOMAIN %s\n" domain-list domain)
	text-domain-list (cat text-domain-list "\n" domain)
	default-domain ""))
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ask-resolv-conf
 ;;
 ;; Show existing information first and ask if should change
 ;;
 (if
     (if (exists (tackon conf-dir "resolv.conf"))
	 (
	  (textfile (dest "ENV:resolv.conf.tmp")
		    (include (tackon conf-dir "resolv.conf"))
		    (safe))
	  (set tmp-resolv-conf (getenv "resolv.conf.tmp"))
	  (not (askbool
		(prompt
		 "Your current name resolver configuration is:\n\n"
		 tmp-resolv-conf
		 "\nDo you want to keep it?")
		(choices "Keep" "Change")
		(help
		 "    If you select \"Change\" you will be asked for "
		 "name server addresses and search domain names.")
		)))
       1)
     (
      (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
 store-default-user-name
 ;;
 ;; Store default user name into ENV:LOGNAME (ENVARC: too)
 ;;
 ;; user name is passed in default-user-name
 ;;
 (transcript "Storing default user name " default-user-name
	     " to ENV:LOGNAME.")
 (textfile (dest "ENVARC:LOGNAME")
	   (append ::user-name))
 (textfile (dest "ENV:LOGNAME")
	   (append ::user-name))
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(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'.\n"
		  "    Give an empty name to bypass this operation.")))
      (set ::user-name anu::username)
      (if (<> ::user-name "")
	  (if (does-user-exist)
	      ((set anu::username "")
	       (askbool
		(prompt "User " ::user-name " already exists.\n"
			"Do you want to add another user?")
		(help "")))
	    0)
	0)))
 (if (<> anu::username "")
     (
      (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 (full) 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 "Give the home directory of the user " anu::username ":\n"
		    pretend-extra)
	    (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 the 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))
	   (if (= @pretend 0)
	       (copyfiles (source anu::passwd)
			  (dest conf-dir)
			  (newname "passwd.old")
			  (optional "askuser")))
	   (if (= @pretend 0)
	       (copyfiles (source anu::passwd-new)
			  (dest conf-dir)
			  (newname "passwd")
			  (optional "askuser")))
	   (if (askbool 
		(prompt "Do you want to set the password of the user " 
			anu::username "?\n"
			"If you do not set it, it will be left empty.")
		(help "    If you do not run server programs, then you can "
		      "leave the user's password empty. But if you run server "
		      "programs, such as ftp service, then you need to set "
		      "the user password.\n"
		      "    In any case, you can login locally without giving "
		      "the password, if you choose so later during the "
		      "configuration (system startup options).\n"
		      "    Setting the password will launch a new shell process "
		      "with proper commands to set the password. These commands "
		      "are:\n\n"
		      "    1> avail flush\n"
		      "    2> login " anu::username "\n"
		      "    3> passwd " anu::username "\n"
		      "\n"))
	       ((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")))
		(run (cat "newshell from " anu::tempfile)))
	     )
	   (set anu::username ""
		anu::UID (+ anu::UID 1)
		anu::realname "")
	   1))
      ))
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 ;;
 ;; Ask for the default user
 ;;
 ask-default-user
 (if (= adu::setdefaults 0)
     (set
      adu::setdefaults 1
      default-user-umask "022"
      default-user-name (if (exists "ENV:LOGNAME")
			    (getenv "LOGNAME")
			  "")
      ))
 (while
     ((set default-user-name
	   (askstring
	    (default default-user-name)
	    (prompt "Enter the default user name:\n")
	    (help "    Default user name is the login name of the user that "
		  "is logged in automatically at AmiTCP/IP startup. "
		  "Networking programs can use this name when they need to "
		  "find the login name of the current user.\n"
		  "    The default user name is stored in "
		  "ENV:LOGNAME, which is used by the login command "
		  "in the AmiTCP:bin/startnet to set the default user name."
		  "    AmiTCP/IP can handle currently only one user "
		  "at a time. "
		  )))
      (set ::user-name default-user-name)
      (if (= ::user-name "")
	  1 ;; ask again
	(if (NOT (does-user-exist))
	    ((message
	      "\nYou will now be prompted for user information.")
	     (NOT (add-new-user)))))))
 (store-default-user-name)
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;
;;;
(procedure
 configure-modem
 (if (not pro_DialUp)
     (message "Your IP setup does not need a modem. If this is not true, select "
	      "one of the non-fixed configuration styles.")
   ((set mod_InitString
	 (askstring
	  (prompt
	   "Give the modem initialization string, including the leading \"AT\":")
	  (help "    Modem initialization string should bring the modem to the "
		"state compatible with configured serial options. For example, "
		"if you specify CTS/RTS flow control, you should specify the "
		"command \"&K3\" in the initialization string (this may vary "
		"from modem to modem).\n"
		"    Please consult your modem documentation to find correct "
		"initialization string.\n")
	  (default (if (exists "ENV:ModemInitString")
		       (getenv "ModemInitString")
		     "AT&F&C1&D2")))
	 mod_DialPrefix
	 (askstring
	  (prompt
	   "Give the modem dial prefix, including the leading \"AT\":")
	  (help "    Modem dial prefix specifies whether your phone line has "
		"pulse dial (ATDP) or tone dial (ATDT). Also, if your phone line "
		"is not directly connected to the public telephone network, "
		"you might need to add leading 0 and then wait for a dialtone "
		"(ATDT0w).\n")
	  (default (if (exists "ENV:ModemDialPrefix")
		       (getenv "ModemDialPrefix")
		     "ATDT")))
	 )
    ;; store the values to ENVARC: AND ENV:
    (textfile (dest "ENVARC:ModemInitString")
	      (append mod_InitString))
    (textfile (dest "ENV:ModemInitString")
	      (append mod_InitString))
    (textfile (dest "ENVARC:ModemDialPrefix")
	      (append mod_DialPrefix))
    (textfile (dest "ENV:ModemDialPrefix")
	      (append mod_DialPrefix))
    ))
 )



(procedure
 configure-provider
 (ask-provider-config)
 (save-provider-config))

(procedure
 save-as-provider-config
 (while
     ((set save-pro-file
	   (askfile
	    (prompt "Give a name for the backup provider configuration:")
	    (help "   This display provides preconfigured IP provider entries. "
		  "You should type a new name into the file name box.\n")
	    (default (expandpath "AmiTCP:Providers"))))
      (<> (expandpath "AmiTCP:Providers") (expandpath (pathonly save-pro-file))))
   0)
 (set save-file 1)
 (if (exists save-pro-file)
     (set save-file
	  (askbool
	   (prompt "The file \"" save-pro-file "\" already exists.\n"
		   "Do you want to overwrite it?")
	   (help "   Overwriting an existing configuration makes it "
		 "unavailable later.\n"))))
 (if save-file
     (textfile (dest save-pro-file)
	       (include pro_FileName))))

(procedure
 select-provider-config
 (set temp-pro-file
      (askfile
       (prompt "Select the provider to use:")
       (help "   This display provides preconfigured IP provider entries. "
	     "If your provider is listed here, you will not need to configure "
	     "IP provider specific information.\n")
       (default (expandpath "AmiTCP:Providers/Other"))))
 (if (<> temp-pro-file "")
     (if (= (exists temp-pro-file) 1)
	 ((if (exists pro_FileName)
	      (if (askbool (prompt "Do you want to save the old configuration "
				   "before replacing it with the new one?")
			   (help "   The new provider information will "
				 "overwrite the existing information. It is "
				 "recommended that you save the old "
				 "configuration before replacing it with a "
				 "new one."))
		  (save-as-provider-config)))
	  ((textfile (dest pro_FileName)
		     (include temp-pro-file))
	   (parse-provider-config)
	   (message
	    "\n   Parameters in following dialogs show the values "
	    "defined in the "
	    "selected provider profile.  If you agree with provided "
	    "options, just \"Proceed\" in each dialog.\n")
	   (configure-provider)
	   )
	  )
       (message "\nThe selected file \"" temp-pro-file "\" is not a file."))
   )
 )

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

(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.\n"
		   "\nThe loopback interface will also be configured.")
	   (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"
		 "    Configuring the loopback device allows you to "
		 "communicate locally within your machine using "
		 "TCP/IP protocols. This is important if you are "
		 "testing server programs, for example.\n"
		 "    Refer to the documentation for more "
		 "information on server configuration."
		 )))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 create-startup-script
 ;;
 ;; Create the network startup-script (AmiTCP:bin/startnet)
 ;;
 (textfile
  (dest (tackon bin-dir "startnet"))
  (append
   (cat
    ".key DEBUG/S,SRV/S\n"
    ".bra {\n"
    ".ket }\n"
    ";\n"
    "; \"SRV\" if servers are used, _nothing_ otherwise\n"
    ".def SRV   " (if cs-use-servers "SRV") "\n"
    ";\n"
    "; AmiTCP/IP 4.3 startnet script\n"
    ";\n"
    "; Copyright © 1996 AmiTCP/IP Group,\n"
    ";                  NSDi - Network Solutions Development Inc., Finland\n"
    ";                  All rights reserved.\n"
    ";\n"
    "; *NOTE*  YOU SHOULD NOT NEED TO EDIT ANYTHING BELOW. IF YOU NEED TO START\n"
    "; *NOTE*  UTILITIES, DO IT IN THE AmiTCP:db/User-Startnet.\n"
    "; *NOTE*  YOU CAN STOP THESE UTILITIES IN AmiTCP:db/User-Stopnet.\n"
    ";\n"
    "; Set the failat level so that the errors can be handled by the script\n"
    "FailAt 21\n"
    "\n"
    "If NOT Exists AmiTCP:db/provider.conf\n"
    "  Echo AmiTCP/IP is not configured\n"
    "  Echo Starting the configuration tool...\n"
    "  Stack 20000	; Installer needs this\n"
    "  Run >nil: <nil: AmiTCP:bin/Installer SCRIPT \"AmiTCP:Config AmiTCP\" APPNAME AmiTCP/IP MINUSER AVERAGE\n"
    "  Quit 20\n"
    "EndIf\n"
    "\n"
    "Version bsdsocket.library >nil:\n"
    "If NOT Warn \n"
    "  Echo AmiTCP/IP is already running\n"
    "  Echo Exiting...\n"
    "  Quit 20\n"
    "EndIf\n"
    "\n"
    "Cpu Check 68020 >nil:\n"
    "If NOT Warn\n"
    "  If Exists AmiTCP:AmiTCP.020\n"
    "    If X EQ \"X{DEBUG}\"\n"
    "      Run >nil: <nil: AmiTCP:AmiTCP.020 {DEBUG}\n"
    "    Else\n"
    "      Run AmiTCP:AmiTCP.020 {DEBUG}\n"
    "    EndIf\n"
    "    Skip started\n"
    "  EndIf\n"
    "EndIf\n"
    "If X EQ \"X{DEBUG}\"\n"
    "  Run >nil: <nil: AmiTCP:AmiTCP {DEBUG}\n"
    "Else\n"
    "  Run AmiTCP:AmiTCP {DEBUG}\n"
    "EndIf\n"
    "Lab started\n"
    "WaitForPort AMITCP\n"
    "If NOT Warn\n"
    "  ; Log in with the default user name (ENV:LOGNAME)\n"
    "  AmiTCP:bin/login -f\n"
    "  ; Configure AmiTCP, configure lo0 if using servers\n"
    "  If X EQ \"X{SRV}\"\n"
    "    Set LOOPBACK \"\"\n"
    "  Else\n"
    "    Set LOOPBACK LOOPBACK\n"
    "  EndIf\n"
    "  AmiTCP:bin/bootpconfig $LOOPBACK {DEBUG}\n"
    "  If NOT Warn\n"
    "    ;\n"
    "    ; Mount TCP:\n"
    "    ;\n"
    "    Assign TCP: Exists >NIL:\n"
    "    IF Warn\n"
    "      Mount TCP: from AmiTCP:devs/Inet-Mountlist\n"
    "    EndIf\n"
    "    ;\n"
    "    ; Start inetd if requested\n"
    "    ;\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"
    "    ; Start utilities in AmiTCP:db/User-Startnet\n"
    "    ;\n"
    "    If Exists AmiTCP:db/User-Startnet\n"
    "      Execute AmiTCP:db/User-Startnet\n"
    "    EndIf\n"
    "    ;\n"
    "    ; Successfull end\n"
    "    ;\n"
    "    Echo AmiTCP/IP 4.3 is now on-line. Your host name is $HOSTNAME.\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 make-inet-assign 0 ; assume no
      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\", but preserve ENV:LOGNAME\n"
		"login -f nobody\n"
		"Copy ENVARC:LOGNAME ENV:\n"))
       (if (exists (tackon libs-dir "socket.library"))
	   (if (askbool
		(prompt
		 "\nThis " @app-name " release includes AS225 compatible "
		 "socket.library. Do you want an assign (INET:) to be made "
		 "so that AS225 programs can find the library?")
		(help
		 "    AS225 is another TCP/IP implementation for the Amiga. "
		 "With socket.library you can run AS225 programs on top of "
		 @app-name ".\n"
		 "    AS225 programs use the \"INET:\" assign to locate "
		 "the socket.library. AS225 programs will generally not work "
		 "without the assign."))
	       ((set make-inet-assign 1)
		(cat "; Assign for AS225 compatibility\n" 
		     "Assign INET: " atcp-assign "\n"))))
       (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."))
	   (cat "; Start AmiTCP/IP\n"
		"startnet\n"))
       )
      complete-add-to-startup-conf
      (cat ";BEGIN " @app-name " Configuration\n"
	   add-to-startup-conf
	   ";END " @app-name " Configuration\n"))
 ;;
 ;; Make the INET assign now also, if instructed so
 ;;
 ;; NOTE: makeassign cannot be done inside "cat". It had spurious side effects
 ;;       to the cat result string.
 ;;
 (if make-inet-assign
     (makeassign "INET" atcp-assign))
 ;;
 ;; Do the addition
 ;;
 (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."))
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Reconfigure AmiTCP/IP
;;;
(procedure
 reconfigure-with-new-provider
 ;;
 ;; Set prompting mode shown to the user
 ;;
 (set rwnp-mode (if initial-configuration
		    "asked for"
		  "confirmed"))
 ;;
 ;; select-provider-config asks user to
 ;; - select provider configuration and confirm it's values
 (select-provider-config)
 ;;
 ;; Ask for name service configuration, if not dynamic
 ;;
 (if (not pro_NSDynamic)
     ((message "\nNext your name service configration will be " rwnp-mode
	       ".\n")
      (ask-resolv-conf))
   (textfile (dest (tackon conf-dir "resolv.conf"))
	     (append "; will be overwritten, do not modify\n")))
 ;;
 ;; Ask for serial configuration, if needed
 ;;
 (if pro_NeedSerial
     ((message "\nNext your serial line configuration will be " rwnp-mode
	       ".\n")
      (configure-serial)))
 ;;
 ;; Ask for modem configuration, if needed
 ;;
 (if pro_DialUp
     ((message "\nNext your modem configuration will be " rwnp-mode
	       ".\n\n"
	       "You might need your modem manual for reference.\n")
      (configure-modem)))
 ;;
 ;; Ask for login name
 ;;
 (message "\nNext your login name will be " rwnp-mode ".\n")
 (ask-default-user)
 ;;
 ;; Ask for startup-options
 ;;
 (message "\nNext the system startup options will be " rwnp-mode ".\n")
 (ask-run-servers)
 (update-user-startup-conf)
 (create-startup-script)
 )

 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Linear, first time configuration of AmiTCP/IP
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure
 linear-configuration
 (transcript "First time installation of " @app-name ".")

 ;;
 ;; First time installation ("linear" installation)
 ;;
 (message
  "\n"
  "    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."
  )
 ;;
 ;;
 (transcript "Configuring " @app-name ".")

 (reconfigure-with-new-provider)
 )

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

;
; Initialize "global" variables to default values (not complete)
;
(set
 cs-use-servers 1
 pro_Interface ""
 pro_Interface ""
 pro_IPAddr ""
 pro_IPDynamic 0
 pro_UseBootP 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)

;;
;; Either read configuration files or reset to defaults
;;
(set pro_FileName "AmiTCP:db/Provider.conf")
(parse-provider-config)
(parse-if-config)

;
; Check if all the files generated by this script are on place or not
;
(set initial-configuration
     (OR (OR (NOT (exists (tackon conf-dir "resolv.conf")))
	     (NOT (exists pro_FileName)))
	 (OR (OR (NOT (exists "ENV:LOGNAME"))
		 (AND pro_DialUp
		      (= pro_Phone "")))
	     (OR (OR (= pro_Interface "")
		     (= pro_IPAddr ""))
		 (AND (= pro_IPAddr "0.0.0.0")
		      (not pro_IPDynamic))))))

(if initial-configuration
    (linear-configuration)
  (	;; 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. "
		     "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"
		     "\"Modify 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"
		     "\"Modify modem configuration\" -- change the modem "
		     "specific setup information. This selection is effective "
		     "only with DialUp (Non-fixed) configurations.\n"
		     "\"Modify serial configuration\" -- change the serial line "
		     "specific setup. This selection is effective only with "
		     "interfaces utilizing a serial device\n"
		     "\"Modify IP provider configuration\" -- change the setup "
		     "profile for your IP provider. You can reconfigure your "
		     "IP setup with this.\n"
		     "\"Select a new provider configuration\" -- select a new "
		     "IP provider profile.\n"
		     "\"Save provider configuration\" -- save the current "
		     "setup as a IP provider profile.\n"
		     "\"Done\" -- exit the configuration tool.\n"
		     )
	       (choices
		"Add new user to the user data base"	; 0
		"Change default user"			; 1
		"Modify Name Service configuration"	; 2
		"Modify modem configuration"		; 3
		"Modify serial configuration"		; 4
		"Modify IP provider configuration"	; 5
		"Select a new provider configuration"	; 6
		"Save provider configuration"		; 7
		"Update system startup options"		; 8
		"Done")					; 9
	       (default 9)))
	 (<> choice 9))
      (select choice
	      ;; (0)
	      (add-new-user)
	      ;; (1)
	      (ask-default-user)
	      ;; (2)
	      (ask-resolv-conf)
	      ;; (3)
	      (configure-modem)
	      ;; (4)
	      (configure-serial)
	      ;; (5)
	      (configure-provider)
	      ;; (6)
	      (reconfigure-with-new-provider)
	      ;; (7)
	      (save-as-provider-config)
	      ;; (8)
	      ((ask-run-servers)
	       (update-user-startup-conf)
	       (create-startup-script))
	      )
      )
    )
   )
  )

;;; All done!
(complete 100)

(if initial-configuration
    (message "\nConfiguration complete!\n\n"
	     "Use \"Start AmiTCP\" from WorkBench to start " @app-name ".\n")
  (message "\nReconfiguration complete!\n\n"
	   "You need to (re)start " @app-name
	   " for all changes to take effect.\n")
  )

(exit (quiet))
; EOF
