;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                                                    ;;
;;           AmiTCP/IP Installer for Demon Internet users             ;;
;;               -----------------------------------                  ;;
;;                                                                    ;;
;; Alterations/amendments 11/11/96 by phil@stokes.demon.co.uk         ;;
;;                                                                    ;;
;; - fixed conflict between myname and my-name variables              ;;
;; - updated newsserver and several other minor config changes        ;;
;; - amended Link script to work with altered output from             ;;
;;   finger mynode@post                                               ;;
;; - changes to db/inetd.conf and new ARexx fingerd 'rx.fingerd' to   ;;
;;   overcome security loophole in in.fingerd                         ;;
;; - fixed major bug in previous version - I forgot to uncomment      ;;
;;   copyfiles and fixbits procedures after testing and before        ;;
;;   uploading :( <blush>                                             ;;
;; - changes to Startnet script:                                      ;;
;;   - routing fixed                                                  ;;
;;   - Env:Sana2 created if it does not exist                         ;;
;;   - now uses ppp.device's inbuilt dialer                           ;;
;;                                                                    ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; set up variables

(set
   myuser      "percy"
   myname      "Percival Bothwick"
   mypass      "fish"
   mynode      "percybot"
   myip        "194.217.xxx.xxx"
   myorg       "The Home Office"
   myeditor    "Ed"
   myserdev    "serial.device"
   myserunit   "0"
   modeminit   "ATZ0"
   modemdial   "ATDT"
   popno       "01716640666"

   source-dir  (if (= 1 (exists @icon))
                  (pathonly (expandpath @icon))
                  (expandpath @icon)
               )
   pkgname     "AmiTCP"
   pkgdir      (cat pkgname ":")
   bindir      (tackon pkgdir "bin")
   sbindir     (tackon source-dir "bin")
   dbdir       (tackon pkgdir "db")
   sdbdir      (tackon source-dir "db")
   docdir      (tackon pkgdir "doc")
   helpdir     (tackon pkgdir "help")
   servdir     (tackon pkgdir "serv")
   sservdir    (tackon source-dir "serv")
   ldir        (tackon pkgdir "l")
   libsdir     (tackon pkgdir "libs")
   usrdir      (tackon pkgdir "usr")
   susrdir     (tackon source-dir "usr")
   usrsp       (tackon usrdir "spool")
   maildir     (tackon usrdir "mail")
   newsdir     (tackon usrdir "news")
   uudir       (tackon usrdir "lib")
   suudir      (tackon susrdir "lib")
   envdir      "envarc:"
   senvdir     (tackon pkgdir "env")
   sanadir     (tackon envdir "sana2")
   devdir      (tackon pkgdir "devs")
   netsdir     (tackon "devs:" "networks")

   checkok     5

)

(procedure get-user-info
   (message
      "\nFirst we need to know some things about you and your Demon account.\n"
   )
   
   (set myuser
      (askstring
         (prompt "Please enter your username, this will be used as part of your email address.")
         (help "The username makes up part of your email address. If your username was 'fred' your address might be \n\n'fred@bloggs.demon.co.uk'.")
         (default myuser)
      )
   )
   (set myname
      (askstring
         (prompt "Please enter your real name, this will be used when you send mail and news.")
         (help "The real name is shown after your email address. If your real name was 'Frederick P Bloggs' your address might be \n\n'fred@bloggs.demon.co.uk (Fred P Bloggs)'.")
         (default myname)
      )
   )
   (set mynode
      (askstring
         (prompt "Please enter your node name, this will be used as part of your email address.")
         (help "The node name makes up part of your email address. It is the name you chose when you set up your account. If your node name was 'bloggs' your address might be \n\n'fred@bloggs.demon.co.uk'.")
         (default mynode)
      )
   )
   (set myip
      (askstring
         (prompt "Please enter your numeric IP address, this is a number consisting of four parts each separated by"
          " dots which identifies your machine. It should have been supplied to you by Demon when you joined.")
         (help "The numeric address is used by other hosts on the internet to identify your machine. It consists"
          " of four fields each separated by dots. The first two fields will be either \"158.152.\" or \"194.217.\"")
         (default myip)
      )
   )
   (set myorg
      (askstring
         (prompt "Please enter your Organisation, this will be used when you send mail and news.")
         (help "The Organisation is shown in your mail and news postings.")
         (default myorg)
      )
   )
   (set mypass
      (askstring
         (prompt "Please enter your password, this will be used when you log on.")
         (help "The password is used when you log on. You should not tell anybody your password.")
         (default mypass)
      )
   )
   (set checkok
      (askbool
         (prompt
            "You entered the following -\n\n"
            "Username: " myuser "\n"
            "Realname: " myname "\n"
            "Nodename: " mynode "\n"
            "IPAddress: " myip "\n"
            "Password: " mypass "\n"
            "Organisation: " myorg 
         )
         (help @askchoice-help)
         (choices "No, that's wrong" "Okay")
         (default 1)
      )
   )
)

(procedure get-comp-info
   (message
      "\nNow we need to know some things about your computer and modem setup.\n"
   )
   
   (set myeditor
      (askstring
         (prompt "Please enter the command which calls your editor. You must include any command line switches if they are required.")
         (help "This is the command that runs your text editor for composing mail and news posts.")
         (default myeditor)
      )
   )
   
   (set myserdev
      (askstring
         (prompt "Please enter the name of the serial device driver that you intend to use.")
         (help "This is the name of your serial device driver that you will be running your modem on.")
         (default myserdev)
      )
   )
   
   (set myserunit
      (askstring
         (prompt "Please enter the unit number of your serial device.")
         (help "This is the unit number of the serial device driver that you will be running your modem on. It will be 0 if you are using the internal port, but may be different if you are using an I/O interface.")
         (default myserunit)
      )
   )
   
   (set baudnum
      (askchoice
         (prompt "Please choose a baud rate.\n NOTE the Amigas internal port *can not* do 57600 on 68000 driven systems.")
         (help "This is the speed at which the computer will communicate with the modem.")
         (choices "1200" "2400" "9600" "19200" "38400" "57600" "115200")
         (default 3)
      )
   )

   (set modembaud
      (select baudnum
         "1200" 
         "2400" 
         "9600" 
         "19200" 
         "38400" 
         "57600" 
         "115200"
      )
   )

   (set modeminit
      (askstring
         (prompt "Please enter your modem initialisation string.")
         (help "This is the command which initialises or resets your modem into a ready state. It is usually ATZ or ATZ0.")
         (default modeminit)
      )
   )
   
   (set modemdial
      (askstring
         (prompt "Please enter your modem dial string.")
         (help "This is the command the modem will use to dial, but without the number.")
         (default modemdial)
      )
   )

   (set popno
      (askstring
         (prompt "Please enter the telephone number of your local Point of Presence.\nSee POP.txt for a list of numbers.")
         (help "This is the phone number of the Point of Presence you wish to connect to. See POP.txt for a list of numbers.")
         (default popno)
      )
   )

   (set checkok
      (askbool
         (prompt
            "You entered the following -\n\n"
            "Editor: " myeditor "\n"
            "Serial Device: " myserdev "\n"
            "Serial Unit: " myserunit "\n"
            "Baud: " modembaud "\n"
            "Modem Init String: " modeminit "\n"
            "Modem Dial String: " modemdial "\n"
            "PoP number: " popno 
         )
         (help @askchoice-help)
         (choices "No, that's wrong" "Okay")
         (default 1)
      )
   )
)

(procedure create-files
   (working "Generating Configuration Files...")

   (working "Creating db/AmiTCP.Config...")

   (set file (tackon sdbdir "AmiTCP.Config"))
   (delete file)
   (textfile
      (dest file)
      (append 
         (cat 
            "# AmiTCP/IP configuration file.\n"
            "#\n"
            "useloopback=YES\n"
            "debugsana=NO\n"
            "usens=SECOND\n"
            "gateway=NO\n"
            "hostname=" mynode ".demon.co.uk\n"
         )
      )
   )

   (working "Creating db/Hosts...")

   (set file (tackon sdbdir "Hosts"))
   (delete file)
   (textfile
      (dest file)
      (append 
         (cat 
            "#\n"
            "# The hosts database file for AmiTCP/IP.\n"
            "#\n"
            "127.0.0.1 localhost " mynode".demon.co.uk\n"
            myip " " mynode".demon.co.uk " mynode "\n"
            "; \n"
         )
      )
   )

   (working "Creating db/passwd...")

   (set file (tackon sdbdir "passwd"))
   (textfile
      (dest file)
      (append (cat "root||0|0|" myname "|sys:|shell\n"))
      (append (cat myuser "||100|100|" myname "|usr:" myuser "|shell\n"))
   )

   (working "Creating db/inetd.conf...")

   (set file (tackon sdbdir "inetd.conf"))
   (delete file)
   (textfile
      (dest file)
      (append
         (cat
            "#\n"
            "# $Id: inetd.conf,v 4.4 1994/10/05 00:28:04 jraja Exp $\n"
            "#\n"
            "# The inetd configuration file.\n"
            "#\n"
            "# Copyright © 1994 AmiTCP/IP Group,\n"
            "#                  Network Solutions Development Inc.\n"
            "#                  All rights reserved.\n"
            "#\n"
            "# Inetd reads its configuration information from this file upon\n"
            "# execution and at some later time if this file is changed or inetd \n"
            "# is reconfigured in response with a CTRL-F signal.\n"
            "#\n"
            "##\n"
            "#\n"
            "# Configuration lines are parsed with DOS function ReadItem().\n"
            "# Multiple line entries must have a ``+'' char as the last char in the\n"
            "# line. First 6 fields must be present in each entry. The line has\n"
            "# following entries in this order:\n"
            "#\n"
            "# service socket-type protocol wait user server cli-name cli-arguments\n"
            "#\n"
            "##\n"
            "#       inetd internal services\n"
            "##\n"
            "# \n"
            "daytime   stream      tcp nowait root internal\n"
            "daytime   dgram       udp nowait root internal\n"
            "time      stream      tcp nowait root internal\n"
            "time      dgram       udp nowait root internal\n"
            "echo      stream      tcp nowait root internal\n"
            "echo      dgram       udp nowait root internal\n"
            "discard   stream      tcp nowait root internal\n"
            "discard   dgram       udp nowait root internal\n"
            "chargen   stream      tcp nowait root internal\n"
            "chargen   dgram       udp nowait root internal\n"
            "# finger server\n"
            "finger     stream      tcp dos bin - rx amitcp:serv/rx.fingerd\n"
            "# NetFS, a networking support between Amigas\n"
            "# Remove # from the next line to enable NetFS\n"
            "#amiganetfs stream    tcp nowait root amitcp:serv/netfs-server\n"
            "###\n"
            "smtp       stream      tcp nowait root amitcp:serv/in.smtpd -smtpd\n"
            "ftp        stream      tcp nowait root Amitcp:serv/ftpd in.ftpd\n"
            "ntalk      dgram       udp wait   root amitcp:serv/talkd -talkd\n"
            "talk       dgram       udp wait   root amitcp:serv/talkd -talkd\n"
            "## Emacs magic:\n"
            "## Local Variables: **\n"
            "## backup-by-copying:t **\n"
            "## End: **\n"
            "###\n"
         )
      )
   )

   (working "Creating UULIB:Sitename...")

   (set file (tackon suudir "sitename"))
   (delete file)
   (textfile
      (dest file)
      (append
         (cat
            mynode ".demon.co.uk"
         )
      )
   )

   (working "Creating serv/rx.fingerd...")

   (set file (tackon sservdir "rx.fingerd"))
   (textfile
      (dest file)
      (append
         (cat
            "/*\n"
            " *   Arexx Finger Daemon With Connection Logging\n"
            " *   -------------------------------------------\n"
            " *\n"
            " * This script is based in part on a more basic script that I found\n"
            " * last year - original author unknown. I have modified it to work\n"
            " * correctly with both finger client and telnet connections, and made\n"
            " * several other small alterations.\n"
            " *\n"
            " * Philip Stokes <phil@stokes.demon.co.uk> 08/11/96\n"
            " */\n"
            "\n"
            "CR = '0d'x\n"
            "log = \"UULib:fingerlog\"  /* Path to logfile */\n"
            "\n"
            "options results\n"
            "address AMITCP  'QUERY CONNECTIONS';info = result\n"
            "do conn = 1 to 10\n"
            "  hexad = word(info, conn*8-2)\n"
            "  port = x2d(word(info, conn*8-3))\n"
            "  state = word(info, conn*8)\n"
            "  if (port = 79 & hexad ~= 0 & state = 4) then do\n"
            "    address = x2d(substr(hexad, 1, 2)) || \".\" || x2d(substr(hexad, 3, 2))\n"
            "    address = address || \".\" || x2d(substr(hexad, 5, 2)) || \".\"\n"
            "    address = address || x2d(substr(hexad, 7, 2))\n"
            "    open(rslv, 'APIPE:AmiTCP:bin/resolve ' address, R)\n"
            "    address = word(readln(rslv), 3);close(rslv)\n"
            "    tolog = date(E) \"  \" time() \"  \" address\n"
            "  end\n"
            "end\n"
            "if address ~= 'localhost' & address ~= 'ADDRESS' then do\n"
            "  if ~exists(log) then do\n"
            "    call open(lg, log, W);writeln(lg, tolog)\n"
            "  end\n"
            "  else do\n"
            "    open(lg, log, A);writeln(lg, tolog)\n"
            "  end\n"
            "  call writeln(stdout,'Hello '||address||': Your connection is being logged.')\n"
            "end\n"
            "arg = compress(readln(stdin),CR)\n"
            "arg = compress(arg,'`')\n"
            "select\n"
            "  when index(arg,'@') =1 then do\n"
            "    parse var arg '@' host\n"
            "    user = host\n"
            "  end\n"
            "  when index(arg,'@') >1 then do\n"
            "    parse var arg user '@' host\n"
            "  end\n"
            "  otherwise user = arg\n"
            "end\n"
            "if user = '' then do\n"
            "  address COMMAND 'AmiTCP:bin/finger'\n"
            "end\n"
            "else do\n"
            "  address COMMAND 'AmiTCP:bin/finger' user\n"
            "end\n"
            "exit\n"
            "\n"
         )
      )
   )

   (working "Creating UULIB:Aliases...")

   (set file (tackon suudir "Aliases"))
   (delete file)
   (textfile
      (dest file)
      (append
         (cat
            "# Following alias is required by the new mail protocol, RFC 822\n"
            "postmaster: " myuser "\n"
            "\n"
            "# Aliases to handle mail to msgs and news\n\n\n"
            "# System\n"
            "manager: " myuser "\n"
            "operator: " myuser "\n"
            "staff: " myuser "\n"
            "nobody: " myuser "\n"
            "root: " myuser "\n"
            "uucp: " myuser "\n"
            "daemon: " myuser "\n"
            "lp: " myuser "\n"
            "#\n"
            "#   User\n"
            "#\n\n"
            "# End of file\n"
         )
      )
   )

   (working "Creating db/ppp.dial...")

   (set file (tackon sdbdir "ppp.dial"))
   (textfile
      (dest file)
      (append
         (cat
            "# Dialscript for Demon Internet and ppp.device\n"
            "# by Philip Stokes <phil@stokes.demon.co.uk>\n"
            "#\n"
            "# DELAY and TIMEOUT are given in 'ticks' where 50 ticks = 1 second\n"
            "#\n"
            "ECHO OFF\n"
            "TIMEOUT 1500\n"
            "REDIALDELAY 25\n"
            "ABORT \"NO DIAL TONE\",\"ERROR\"\n"
            "REDIAL \"NO CARRIER\",\"BUSY\"\n"
            "#\n"
            "# Init Modem\n"
            "SEND \"" modeminit "\"\n"
            "WAIT \"OK\"\n"
            "DELAY 15\n"
            "#\n"
            "# Dial Commands - only one number can be active at a time.\n"
            "#\n"
            "SEND " modemdial popno "\n"
            "#\n"
            "# wait for connection...\n"
            "TIMEOUT 1000\n"
            "#\n"
            "WAIT \"ogin:\"\n"
            "#\n"
            "# pause before sending nodename\n"
            "# DELAY 25\n"
            "# at login: prompt send nodename\n"
            "SEND \"" mynode "\"\n"
            "DELAY 30\n"
            "TIMEOUT 300\n"
            "# default was 500\n"
            "#\n"
            "#\n"
            "WAIT \"word:\"\n"
            "#\n"
            "# at password: prompt send password\n"
            "SEND \"" mypass "\"\n"
            "DELAY 30\n"
            "TIMEOUT 300\n"
            "#\n"
            "WAIT \"ocol:\"\n"
            "#\n"
            "# at protocol: prompt send PPP\n"
            "SEND \"PPP,idle=600\"\n"
            "DELAY 30\n"
            "TIMEOUT 300\n"
            "#\n"
            "WAIT \"HELLO\"\n"
            "#\n"
            "# The next two bits no longer seem to be needed, but are\n"
            "# left here for reference, just in case...\n"
            "#\n"
            "# Wait @1 sec for remote server to start\n"
            "DELAY 25\n"
            "#\n"
            "# send CR to fire up Ascends\n"
            "SEND \" \"\n"
            "#\n"
            "# EOF\n"
         )
      )
   )

   (working "Creating Startnet...")

   (set file (tackon sbindir "StartNet"))
   (delete file)
   (textfile
      (dest file)
      (append
         (cat
            "; Startnet Script for Demon Internet \n"
            " \n"
            "; Assigns and Env settings \n"
            " \n"
            "assign AmiTCP:    " source-dir " \n"
            " \n"
            "path >Nil: AmiTCP:bin remove \n"
            "path AmiTCP:bin add \n"
            " \n"
            "Assign APIPE: Exists >NIL: \n"
            "IF Warn \n"
            "  Mount APIPE: from AmiTCP:devs/APipe-Mountlist \n"
            "EndIf \n"
            " \n"
            "assign INet:      AmiTCP: \n"
            "assign usr:       AmiTCP:usr \n"
            "assign uumail:    usr:mail \n"
            "assign uulib:     usr:lib \n"
            "assign uuspool:   usr:spool \n"
            "assign uunews:    usr:news \n"
            "assign etc:       AmiTCP:db \n"
            " \n"
            "path AmiTCP:bin usr: uumail: uulib: uuspool: uunews: etc: add \n"
            " \n"
            "; Environmental variables \n"
            " \n"
            "setenv NODENAME      " mynode "\n"
            "setenv HOST          " mynode ".demon.co.uk\n"
            "setenv HOSTNAME      " mynode ".demon.co.uk\n"
            "setenv DOMAINNAME    .demon.co.uk\n"
            "setenv REALNAME      " myname " \n"
            "setenv ORGANIZATION  " myorg " \n"
            "setenv NEWSSERVER    news.demon.co.uk\n"
            "setenv SENDMAIL     AmiTCP:bin/Sendmail %s\n"
            "setenv POSTNEWS     AmiTCP:bin/Postnews\n"
            "setenv TIN_MAIL     AmiTCP:bin/SendMail\n"
            "setenv TIN_POST     AmiTCP:bin/Postnews %s\n"
            "setenv LOGFILE         uuspool:LOGFILE\n"
            "setenv USERNAME     " myuser " \n"
            "setenv AMITCPDIR    " source-dir " \n"
            "setenv EDITOR       " myeditor " \n"
            "setenv NNTPSERVER   news.demon.co.uk \n"
            "setenv CURSESTYPE      SCREEN \n"
            " \n"
            "setenv SOCKETCONFIG  \"UID=100 GID=100 USER=" myuser " DOMAIN=demon.co.uk UMASK=022\" \n"
            " \n"
            "; Set default user \n"
            "; \n"
            "AmiTCP:bin/login -f $USERNAME \n"
            "AmiTCP:bin/umask 022 \n"
            " \n"
            "; Invoke AmiTCP \n"
            "; \n"
            "AmiTCP:AmiTCP \n"
            "WaitForPort AMITCP \n"
            " \n"
            "; Configure loop-back device \n"
            "AmiTCP:bin/ifconfig lo0 localhost \n"
            " \n"
            "if NOT EXISTS Env:Sana2\n"
            "  makedir Env:Sana2\n"
            "endif\n"
            "; Create ppp configuration file-must be 'ppp0.config for ppp.device' \n"
            "echo \"" myserdev " " myserunit " " modembaud " " myip " DIALSCRIPT=AmiTCP:db/ppp.dial 7WIRE CD\" >ENV:Sana2/ppp0.config \n"
            " \n"
            "rx \"address AMITCP 'ADD HOST " myip " " mynode".demon.co.uk'\"\n"
            "\n"
            "AmiTCP:bin/route add " myip " localhost\n"
            "\n"
            "Assign TCP: EXISTS >NIL:\n"
            "if WARN \n"
            "  Mount TCP: FROM AmiTCP:devs/inet-mountlist \n"
            "endif \n"
            " \n"
            "; Start the internet `super server' \n"
            "Run <NIL: >NIL: AmiTCP:bin/inetd \n"
            " \n"
            "if EXISTS AmiTCP:db/user-startnet\n"
            "  execute AmiTCP:db/user-startnet\n"
            "endif\n"
            "cd $HOME \n"
            " \n"
            ";EOF \n"
            " \n"
         )
      )
   )

   (working "Creating Link...")

   (set file (tackon sbindir "Link"))
   (delete file)
   (textfile
      (dest file)
      (append
         (cat
            "/* rx\n"
            " * AmiTCP DIS v4 Amiga Installation\n"
            " * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
            " *\n"
            " * NAME\n"
            " *   link -- Control the state of the AmiTCP connection\n"
            " * USAGE\n"
            " *   link up|down [news|autonews|automail]\n"
            " * PURPOSE\n"
            " *   This script makes using AmiTCP on a dialup to Demon much easier.\n"
            " *   You can connect/disconnect by entering LINK UP or LINK DOWN.\n"
            " * \n"
            " * 07/02/96 - Philip Stokes <phil@stokes.demon.co.uk> \n"
            " *          - fixed error in 'route delete' command. \n"
            " *          - added DropLink() function to avoid recursion of original \n"
            " *            version. \n"
            " * \n"
            " * 11/11/96 - PS: alteration to CheckDISMail() from \n"
            " *            suggestion by james@xmas.demon.co.uk \n"
            " */ \n"
            " \n"
            "if ~exists('libs:rexxsupport.library') then  \n"
            "do \n"
            "  say 'Cannot find rexxsupport.library, aborting..' \n"
            "   exit \n"
            "end \n"
            " \n"
            "if ~show('L','rexxsupport.library') then  \n"
            "do \n"
            "  addlib('rexxsupport.library',0,-30,0) \n"
            "end \n"
            " \n"
            "CALL PRAGMA('priority',3) \n"
            " \n"
            "/* VARIABLES - Modify these for your setup */ \n"
            "mynode = \"" mynode "\"            /* My node name */ \n"
            "fingercmd = \"AmiTCP:bin/finger\" \n"
            "mailhost = \"@post.demon.co.uk\" \n"
            "DISmail = 1 \n"
            "THISmail = 1 \n"
            " \n"
            "address command \n"
            "arg which news \n"
            " \n"
            "/* ----------------- */ \n"
            "/* THE SCRIPT PROPER */ \n"
            "if which='' then \n"
            "do \n"
            "  say '' \n"
            "  say 'Usage: Link Up|Down [News|Autonews|Automail]' \n"
            "  say '' \n"
            "  exit \n"
            "end \n"
            "if which~='UP' & which~='DOWN' then \n"
            "do \n"
            "  say '' \n"
            "  say 'Invalid command: ' || which || ' - try Up or Down' \n"
            "  say '' \n"
            "  exit \n"
            "end \n"
            "if news~='NEWS' & news~='AUTONEWS' & news~='AUTOMAIL' & news~='' then \n"
            "do \n"
            "  say 'Invalid parameter: ' || news || ' - try News, Autonews or Automail' \n"
            "end \n"
            "else  \n"
            "do \n"
            "  if which='UP' then \n"
            "  do \n"
            "     'AmiTCP:bin/online ppp0' \n"
            "     if RC=10 then \n"
            "     do \n"
            "        say '' \n"
            "        say 'Connection/Dial Error' \n"
            "        exit \n"
            "     end \n"
            "     'AmiTCP:bin/ifconfig ppp0 $ppp0IPLocal $ppp0IPRemote' \n"
            "     'AmiTCP:bin/route add default $ppp0IPRemote' \n"
            "     if ~open(log,'uuspool:link.log','A') then  \n"
            "     do \n"
            "        if open(log,'uuspool:link.log','W') then \n"
            "        do \n"
            "           call WriteLog('Connection Opened') \n"
            "        end \n"
            "     end \n"
            "     else \n"
            "     do \n"
            "        call WriteLog('Connection Opened') \n"
            "     end \n"
            "     \n"
            "     signal ON BREAK_C\n"
            "     \n"
            "     'AmiTCP:bin/mailkick post.demon.co.uk handletos logsends' \n"
            "     if exists('AmiTCP:db/LinkMacro') then\n"
            "     do \n"
            "        'execute AmiTCP:db/LinkMacro' \n"
            "     end \n"
            "     if news='NEWS' then \n"
            "     do \n"
            "        say 'Slurping news...' \n"
            "        'execute AmiTCP:bin/nntptransfer mode news' \n"
            "     end \n"
            "     if news='AUTONEWS' then  \n"
            "     do \n"
            "        say 'Slurping news with auto link down...' \n"
            "        'execute AmiTCP:bin/nntptransfer mode news' \n"
            "        do while DISmail = 1 | THISmail = 1 \n"
            "           call checkDISmail \n"
            "           call checkTHISmail \n"
            "        end \n"
            "        'wait 5' \n"
            "        call DropLink() \n"
            "     end \n"
            "     if news='AUTOMAIL' then  \n"
            "     do \n"
            "        do while DISmail = 1 | THISmail = 1 \n"
            "           call checkDISmail \n"
            "           call checkTHISmail \n"
            "        end \n"
            "        'wait 5' \n"
            "        call DropLink() \n"
            "     end \n"
            " \n"
            "  end \n"
            "  else  \n"
            "  do \n"
            "     if which='DOWN' then  \n"
            "     do \n"
            "        call DropLink()\n"
            "     end \n"
            "  end \n"
            "end \n"
            "exit \n"
            " \n"
            "/* ----------------- */\n"
            "DropLink:\n"
            "do\n"
            "   'AmiTCP:bin/mailkick quit' \n"
            "   'AmiTCP:bin/ifconfig ppp0 down' \n"
            "   'AmiTCP:bin/offline ppp0' \n"
            "   'AmiTCP:bin/route delete $ppp0IPRemote' \n"
            "   'AmiTCP:bin/route delete default' \n"
            "   if ~open(log,'uuspool:link.log','A') then  \n"
            "   do \n"
            "      if open(log,'uuspool:link.log','W') then \n"
            "      do \n"
            "         call WriteLog('Connection Closed') \n"
            "      end \n"
            "   end \n"
            "   else \n"
            "   do \n"
            "      call WriteLog('Connection Closed') \n"
            "   end \n"
            "end\n"
            "return\n"
            "\n"
            "/* ----------------- */\n"
            "checkDISmail: \n"
            "  say \"Checking for incoming mail...\" \n"
            "  DISmail = 0 \n"
            "  fingercmd mynode || mailhost \">t:linktmp\" \n"
            "  if (exists('t:linktmp')>0) then  \n"
            "  do \n"
            "     result = open('fingerout', 't:linktmp', read) \n"
            "     do while ~eof('fingerout') \n"
            "        ln = readln('fingerout') \n"
            "        ln = strip(ln) \n"
            "        if ln ~= '' then do \n"
            "           if index(ln,mynode)>0 then do \n"
            "              if find(ln,'no mail')=0 then do \n"
            "                 DISmail = 1 \n"
            "              end \n"
            "           end \n"
            "        end \n"
            "     end \n"
            "     result = close('fingerout') \n"
            "     result = delete('t:linktmp') \n"
            "  end \n"
            "  if DISmail = 1 then \n"
            "  do  \n"
            "     say \"Found incoming mail, waiting...\" \n"
            "     \"wait 5\" \n"
            "  end \n"
            "  else \n"
            "  do \n"
            "     say \"No incoming mail.\" \n"
            "  end \n"
            "return \n"
            " \n"
            "/* ----------------- */\n"
            "checkTHISmail: \n"
            "  say \"Checking for outgoing mail...\" \n"
            "  THISmail = 0 \n"
            "  \"list nohead uuspool: >t:spooltmp\" \n"
            "  if (exists('t:spooltmp')>0) then  \n"
            "  do \n"
            "     result = open('spoolout', 't:spooltmp', read) \n"
            "     do while ~eof('spoolout') \n"
            "        ln = readln('spoolout') \n"
            "        ln = strip(ln) \n"
            "        if index(ln,'C.')~=0 | index(ln,'D.')~=0 |index(ln,'X.')~=0 then  \n"
            "        do \n"
            "           THISmail = 1 \n"
            "        end \n"
            "     end \n"
            "     result = close('spoolout') \n"
            "     result = delete('t:spooltmp') \n"
            "  end \n"
            "  if THISmail = 1 then \n"
            "  do  \n"
            "     say \"Found outgoing mail, waiting...\" \n"
            "     \"wait 5\" \n"
            "  end \n"
            "  else \n"
            "  do \n"
            "     say \"No outgoing mail.\" \n"
            "  end \n"
            "return \n"
            " \n"
            "/* ----------------- */\n"
            "WriteLog: procedure EXPOSE mynode \n"
            "  logmsg = Arg(1) \n"
            "  logline = Date(E) || '-' || Time() || ' ' || mynode || ' ' || logmsg \n"
            "  call writeln(log,logline) \n"
            "  call close(log) \n"
            "return \n"
            "\n"
            "/* ----------------- */\n"
            "BREAK_C:\n"
            "\n"
            "exit\n"
            "\n"
            "/* EOF */\n"
         )
      )
   )                                                

   (working "Creating ADMail.config...")

   (set file (tackon (tackon usrdir myuser) "ADMail.config"))
   (delete file)
   (textfile
      (dest file)
      (append
         "# ADMail example config file \n"
         "# The settings below represent the available settings in ADMail. \n"
         "# Uncomment and fill in the appropriate ones, as detailed in \n"
         "# the ADMail documentation. \n"
         " \n"
         "#Sendmail \n"
         "#UUDecode \n"
         "Salute Hi $FIRSTNAME \n"
         "#ForwardIntro \n"
         "#IndentPrefix \n"
         "#SaveDir \n"
         "#SigDir \n"
         "#SigFile  \n"
         "#RandSigHook \n"
         "#Editor \n"
         "#MBoxDir \n"
         "# \n"
         "ToReceived never \n"
         "#LogOutgoing \n"
         "#LogEncoded \n"
         "#IncludeFrom \n"
         "#RandomSigs \n"
         "#SigDashes \n"
         "#ShowDeleted \n"
         "#SkipDeleted \n"
         "#ReloadOnResize \n"
         "#PubScreen \n"
         "ShowButtons yes \n"
         "# \n"
         "#MsgListLeft 4 \n"
         "#MsgListTop 2 \n"
         "#MsgListWidth 700 \n"
         "#MsgListHeight 128 \n"
         "# \n"
         "#MsgLeft 4 \n"
         "#MsgTop 130 \n"
         "#MsgWidth 700 \n"
         "#MsgHeight 128 \n"
         "# \n"
         "#SelectLeft \n"
         "#SelectTop \n"
         "#SelectWidth \n"
         "#SelectHeight \n"
         "# \n"
         "#TextWidth \n"
      )
   )

   (working "Creating UULIB:.Signature...")

   (set file (tackon suudir ".Signature"))
   (delete file)
   (textfile
      (dest file)
      (append
         (cat
            " " myname " - " myuser "@" mynode ".demon.co.uk (" myorg ")\n\n"
            " Connecting via Demon Internet Ltd\n"
         )
      )
   )
   (copyfiles (source suudir) (dest (tackon usrdir myuser)) (files) (pattern ".Signature"))

   (working "Creating UULIB:Config...")

   (set file (tackon suudir "Config"))
   (delete file)
   (textfile
      (dest file)
      (append
         (cat
            "#   Config file sample \n"
            "# \n"
            "#   Config may exist as 'UULIB:Config' or 'S:UUConfig', but not in \n"
            "#   any overide directory for UULIB: since that is listed in the config \n"
            "#   file and we have to find it first, eh? \n"
            "# \n"
            "UserName         " myuser "\n"
            "RealName         " myname "\n"
            "NodeName         " mynode "\n"
            "HostName         " mynode ".demon.co.uk\n"
            "Organization     " myorg "\n"
            "TimeZone         GMT\n"
            "DefaultNode      post.demon.co.uk\n"
            "NNTPServer       news.demon.co.uk\n"
            " \n"
            "#   These may be used to specify explicit paths to auto-run programs. \n"
            "#   Example paths are shown.  If not specified, the programs in question \n"
            "#   are assumed to exist in your command path. \n"
            "# \n"
            "MailEditor    " myeditor "\n"
            "NewsEditor    " myeditor "\n"
            "RMail         amitcp:bin/rmail \n"
            "SendMail      amitcp:bin/sendmail \n"
            "PostNews      amitcp:bin/postnews \n"
         )
      )
   )
)

(procedure copy-files
   (working "Copying Devices...")
   (copyfiles
      (prompt "Copying PPP device...")
      (help @copyfiles-help)
      (source "devs/networks") (dest "devs:networks") (all) (confirm)
   )
   (working "Copying Libraries...")
   (copylib 
      (prompt "Copying reqtools.library...")
      (help @copylib-help)
      (source "libs/reqtools.library") (dest "libs:") (confirm)
   )
   (copylib 
      (prompt "Copying rexxreqtools.library...")
      (help @copylib-help)
      (source "libs/rexxreqtools.library") (dest "libs:") (confirm)
   )
   (copylib 
      (prompt "Copying OwnDevUnit.library...")
      (help @copylib-help)
      (source "libs/OwnDevUnit.library") (dest "libs:") (confirm)
   )
   (copylib 
      (prompt "Copying socket.library...")
      (help @copylib-help)
      (source "libs/socket.library") (dest "libs:") (confirm)
   )
   (working "Copying Fonts...")
   (copyfiles (source "fonts") (dest "sys:fonts") (all))
   (working "Copying Environment...")
   (copyfiles (source "env") (dest "env:") (all))
   (copyfiles (source "env") (dest "envarc:") (all))
)

(procedure add-startup
   (message
      "We will now add the Startnet command to your user-startup. If you do not want to run AmiTCP at boot-up simply remove the command."
   )
   (startup "Demon Internet"
      (prompt "Adding \nexecute " startnet-name "\nto your s:user-startup.\n\nThis assign may need to be commented out due to AmiTCP 4.0 demo having a nag requester.")
      (help "Adding StartNet command to user-startup")
      (
         (command (cat "execute " startnet-name "\n"))
      )
   )
)

(procedure fix-bits
   (protect (tackon bindir "StartNet") "+s")
   (protect (tackon bindir "StopNet") "+s")
   (protect (tackon bindir "link") "+s")
   (protect (tackon bindir "tin") "+s")
   (protect (tackon bindir "NNTPTransfer") "+s")
   (protect (tackon bindir "NetStat") "+s")
   (protect (tackon bindir "Telnetn") "+s")
   (protect (tackon bindir "SynClock") "+s")
   (protect (tackon bindir "TalkRequest.rx") "+s")
   (protect (tackon bindir "Postnews") "+s")
   (protect (tackon bindir "NGMan") "+s")
   (protect (tackon bindir "ALMan") "+s")
   (protect (tackon servdir "rx.fingerd") "+s")
   (protect (tackon pkgdir "Connect") "+s")
   (protect (tackon pkgdir "Read_Mail") "+s")
   (protect (tackon pkgdir "Read_News") "+s")
   (protect (tackon pkgdir "WWW") "+s")
)

;; main routine
;;
(message
   "\n"
   "Welcome to the Demon Internet AmiTCP 4.0 installer\n"
   "\n"
   "You will now be asked a number of questions in order\n"
   "to complete the installation successfully.\n"
   "\n"
   "This installer will configure your AmiTCP 4.0 and\n"
   "support files *in place*. Only libraries and devices\n"
   "will be copied."
)

(message
   "\n"
   "Installer and Documentation originally\n"
   "© 1995 James Savage / Gothsoft Developments II\n"
   "\n"
   "Updated and amendments by\n"
   "Philip Stokes <phil@stokes.demon.co.uk>\n"
   "November 1996\n"
   "\n"
   "Copyrights held by their respective authors"
)

(makeassign "AmiTCP" source-dir)
(set checkok 5)
(while (<> checkok 0)
   (get-user-info)
)
(makedir (tackon usrdir myuser))
(set checkok 5)
(while (<> checkok 0)
   (get-comp-info)
)
(create-files)
(copy-files)
(set startnet-name (tackon (tackon (getassign pkgname) "bin") "StartNet"))
(add-startup)
(fix-bits)
(message
   "\n"
   "The installation of your Demon Internet suite has been completed successfully!\n"
   "\n"
   "Reboot, then simply click on Connect to take your first steps onto The Internet.\n"
   "\n"
   "Enjoy!\n"
   "\n"
   ":-)"
)
