;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   Example IPDial 2.1 login script for AmiTCP with SLIP/CSLIP
;   $VER: Login-SLIP.IPDial 2.1 (16.04.96)
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   The line below *must* be present and *must* be the first command
;   line in the script if you don't use the command line option SANADEV.
;   It specifies the device, unit, baudrate and the protocol to use (7WIRE,
;   XONXOFF or NONE). You may omit the unit, baudrate and protocol, in which
;   case the defaults are used (see manual).
;
;   Be sure, that the parameters you are using in this script are the
;   same as used for initializing AmiTCP/IP (or use SANADEV)!

    DEVICE serial.device UNIT=0 BAUD=38400 7WIRE


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

    SEND "\r\n"
    DELAY 1
    SEND "ATZ\r"


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   Wait for the modems ok; break, if timeout (default: 5 seconds)

    WAIT "OK"
    ON STATUS GOTO TIMEOUT


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

    SEND "AT&D0\r"
    WAIT "OK"
    ON STATUS GOTO TIMEOUT


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

Dial:
    ECHO "Dialing...\n"
    SEND "ATDP XXXXXXXXXX\r"
    WAIT TIMEOUT=60 "CONNECT" "NO CARRIER" "BUSY" "DELAYED"
    ON STATUS GOTO TIMEOUT Login NoCarrier


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

    ECHO "Remote busy, delaying 30 seconds...\n"
    DELAY 30
    GOTO Dial


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

Login:
    ECHO "Connection established!\n"

    WAIT TIMEOUT=10 "login:"
    SEND "MyAccount\r"

    WAIT "password:"
    ON STATUS GOTO TIMEOUT
    SEND "MyPassword\r"

    WAIT TIMEOUT=10 "shell>"
    ON STATUS GOTO TIMEOUT
    SEND "slip\r"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   If we came so far, everything is fine. AmiTCP and 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.
;
;   Attention: the SCAN command works on the buffer that was received by
;   the last WAIT command, so
;
;   WAIT TIMEOUT=10 "Your IP address"
;
;   won't work!

    WAIT TIMEOUT=10 "bytes"
    SCAN "%{Your IP address is%} %[IPADDRESS%]%(,%) %{MTU%} %[MTU%]" GLOBAL
    ON STATUS GOTO NeverHappens ScanError ScanError

    ECHO "SLIP connection ready, starting AmiTCP.\n"
    EXIT 0


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

TIMEOUT:
    ECHO "\nTimeout. Entering terminal mode!\n"
    TERMINAL NOECHO RAW
    EXIT 10


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

NoCarrier:
    ECHO "\nNError: NO CARRIER.\n"
    EXIT 10


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;   Error message: SCAN error

ScanError:
    ECHO "\nNError: Could not set environment variables.\n"
    EXIT 10

