.KEY PROVIDER,USER,PASSWORD/S,INETD/S,SAFER/S,EXIT/S,POPONLY/S,STACKONLY/S,DEBUG/S
.DEF PROVIDER xs4all
.DEF USER joe

; $VER: startnet 1.0 (4.10.97)

; *** Command line arguments ***
;
;     PROVIDER ... postfix for ENV: files
;         USER ... Amiga login name
;   PASSWORD/S ... enter new password for old user
;      SAFER/S ... delete password after use
;       EXIT/S ... abort shell after use
;      INETD/S ... start the 'super server'
;    POPONLY/S ... restart AmiPOP
;  STACKONLY/S ... Start TCP stack, nothing else
;      DEBUG/S ... Type the DIALSTRING, nothing else

; ******************************************************

;--- Login on Amiga
login -f <USER>
umask 022

If <STACKONLY>
 Skip StartTCP
EndIf

;--- check provider exist
If "$<PROVIDER>DIAL" EQ "*$<PROVIDER>DIAL"
 Echo "*"<PROVIDER>*" not found"
 Skip Cleanup
EndIf

;--- Ask for password
If <PASSWORD>
 UnsetEnv <PROVIDER> ; delete old password
EndIf
If "$<PROVIDER>" EQ "*$<PROVIDER>"
 Echo "*N<PROVIDER> password: *E[40;30m" NOLINE
 SetEnv >NIL: <PROVIDER> ?
 Echo "*E[40;31m"
EndIf

If <POPONLY>
 Skip StartPOP
EndIf
 
;--- make dialscript
Echo TO PIPE:DIALSCRIPT "$<PROVIDER>DIAL $<PROVIDER>"
If "$<PROVIDER>DIAL2" NOT EQ "*$<PROVIDER>DIAL2"
 Echo TO PIPE:DIALSCRIPT "$<PROVIDER>DIAL2"
EndIf

If <DEBUG>
 Type PIPE:DIALSCRIPT NUMBER
 Skip Cleanup
EndIf

;--- Start TCP/IP stack
Lab StartTCP
Assign >NIL: TCP: EXISTS
If WARN
 AmiTCP:AmiTCP
 Mount TCP: FROM AmiTCP:Devs/Inet-Mountlist
 WaitForPort AMITCP
EndIf
If <STACKONLY>
 Skip Cleanup
EndIf

;--- Start ppp0
online ppp0

;--- Configure loop-back device
ifconfig lo0 localhost

;--- Configure ppp0
ifconfig ppp0 $ppp0iplocal $ppp0ipremote

;--- Add route to this host
route >NIL: add $ppp0iplocal localhost

;--- Add route to the default gateway
route >NIL: add default $ppp0ipremote

SetEnv HOSTNAME `hostname`

;--- Start the internet `super server'
If <INETD>
 Run >NIL: inetd
EndIf

;--- Start AmiPOP
Lab StartPOP
If "$<PROVIDER>POPARGS" NOT EQ "*$<PROVIDER>POPARGS"
 Run >NIL: AmiPOP Password=$<PROVIDER> $<PROVIDER>POPARGS NoWindow Port=110 CX_Popkey="ctrl lalt '" WinX=50 WinY=50
EndIf

Lab Cleanup
If <SAFER>
 UnsetEnv <PROVIDER>
EndIf

If <EXIT>
 EndCLI >NIL:
EndIf

