;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   Login script for AmiTCP/SLIP connection to the University of
;   Tuebingen, Germany using IPDial
;
;   Version 1.1,    06.12.1994
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   The line below *must* be present and *must* be the first command
;   line in the script. It specifies the device and the protocol to
;   use. (Possible protocols are 7WIRE (= RTSCTS), XONXOFF or NONE.)
;   You may omit the protocol, in which case the defaults of the
;   serial.device are used.
;
;   Be sure, that the parameters you are using in this script are the
;   same as used for initializing AmiTCP/IP!

    DEVICE serial.device 7WIRE UNIT 0


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   Certain settings (Note, that these override the respective settings
;   of the serial.prefs.)
;
;   Possible settings are:
;       BAUD            Baudrate, integer
;       DATABITS        number of data bits, integer
;       STOPBITS        number of stop bits, integer
;       BUFSIZE         Read buffer size, integer
;       PARITY          one of NONE, ODD or EVEN
;
;   These are scanned with ReadArgs(), thus you can either use the syntax
;       set BAUD=38400
;   or, if you prefer, this version
;       set BAUD 38400
;   In the first case, however, it is important, that you omit blanks.
;

    set BAUD=38400 DATABITS=8 STOPBITS=1 BUFSIZE=4096

;   Possible settings in the following line are:
;       NONE EVEN ODD

    set PARITY=NONE


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   Show the new settings

;   SHOWPARMS


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   Send initialization command

    SEND "ATZ\r"


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   Wait for the modems ok; break, if timeout
    WAIT TIMEOUT=10 "NO CARRIER" "OK"
    ON STATUS GOTO TIMEOUT NoCarrier


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   Initialize the modem not to hang up, when IPDial terminates (this
;   will make DTR becoming low)

    SEND "AT&D0\r"


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   Wait for the modems ok; break, if timeout

    WAIT TIMEOUT=10 "OK"
    ON STATUS GOTO TIMEOUT


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   Dialing ...

Dial:
    SEND "ATDP07071927920\r"

    WAIT TIMEOUT=60 "Username: " "BUSY" "DELAYED"
    ON STATUS GOTO TIMEOUT Login


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   The usual case: Our Remote is busy. :-(
;   We do a delay of 30 secs (thanks, telecom :-) and dial again.

    Echo "Remote busy, delaying ...\n"
    DELAY 30
    Echo "Trying again.\n"
    GOTO Dial


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   Okay, we are connected. Login into the host. It is a local
;   convention that we have to enter the password twice.

Login:
    SEND "zrawi01\r"
    WAIT TIMEOUT=60 "Password: "
    ON STATUS GOTO TIMEOUT
    SEND "<mypassword>\r"
    WAIT TIMEOUT=60 "TS2>"
    ON STATUS GOTO TIMEOUT
    SEND "slip zrawi01\r"
    WAIT TIMEOUT=60 "Password:"
    ON STATUS GOTO TIMEOUT
    SEND "<mypassword>\n"
    WAIT TIMEOUT=60 "bytes"

;   If we came so far, everything is fine. AmiTCP (and thus Slip) may be
;   started.
;
;   Remote host will answer with a string like
;
;       Your IP address is 134.2.1.23, MTU 1524 bytes.
;
;   Scan this and store the values into the environment variables
;   IPADDRESS and MTU, so that they can be used by the startnet script.

    SCAN "%{Your IP address is%} %[IPADDRESS%]%(,%) %{MTU%} %[MTU%]" GLOBAL

    ECHO "Slip connection ready, starting AmiTCP/IP.\n"
    EXIT 0


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   Error message: Timeout

TIMEOUT:
    ECHO "\nTimeout\n"
    EXIT 10

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   Error message: NO CARRIER

NoCarrier:
    ECHO "\nNO CARRIER\n"
    EXIT 10
