;
;
;   Installation Script For RexxNet
;
;
;

;
;   Initialize the variables
;   ------------------------
(set @user-level 1)
(set @default-dest "ram:")
(set aos (getversion))
(set aos (/ aos 65536))

(set ineta "")
(set amia  "")
(set tcpname "")
(set dpath  "Work:")
(set dcpath "Work:")
(set dspath "Work:")
(set sbpath "Binaries/AS225/")
(set cpusuf ".000")
(set rnstr "")
(set rndstr "")
(set rnstrinfo "")
(set rndstrinfo "")
(set msg1 "")
(set msg2 "")
(set servpath "")
(set suopt 0)

;
;   Determine the current CPU
;   -------------------------
(set tcptype 0)
(set cpu (database "cpu"))
(if (> (exists ("sys:libs/68060.library")) 0) (set cpu "68060"))
(if (= cpu "68000")
    (
    (set cpuid 0)
    )
    (
    (set cpuid 1)
    )
)

;
;   Determine the document viewer
;   -----------------------------
(if (< aos 39)
    (set docv "AmigaGuide")
    (set docv "MultiView")

)

;
;   Determine the current TCP/IP package
;   ------------------------------------
(set amia (getassign "AmiTCP" "a"))
(if amia
    (
    (set tcptype 1)
    )
)

(set ineta (getassign "inet" "a"))
(if ineta
    (
    (set tcptype 0)
    )

)

;
;   Set the TCP/IP package to use with RexxNet
;   ------------------------------------------
(set tcptype
    (askchoice
        (prompt "Which type of TCP/IP Package are you using?\n(Your current one has been auto-selected)")
        (help "AS225 and AmiTCP are incompatible.\n\n"
              "Choose AS225 if the package uses the\n"
              "socket.library.\n\n"
              "Choose AmiTCP if the package uses the\n"
              "bsdsocket.library.")
        (choices "AS225 (CPR,I-NET)" "AmiTCP")
        (default tcptype)
    )
)

(if (= tcptype 0)
    (
        (if ineta
            (
            (set dpath  "inet:")
            (set dcpath "inet:c")
            (set dspath "inet:serv")
            )
        )
        (set sbpath "Binaries/AS225/")
        (set tcpname "_as225")
    )
)

(if (= tcptype 1)
    (
        (if amia
            (
            (set dpath  "AmiTCP:")
            (set dcpath "AmiTCP:bin")
            (set dspath "AmiTCP:serv")
            )
        )
        (set sbpath "Binaries/AmiTCP/")
        (set tcpname "_amitcp")
    )
)


;
;   Set the CPU type of RexxNet
;   ---------------------------
(set cpuid
    (askchoice
        (prompt "Which CPU are using in this Amiga?\n(Your current CPU has been auto-selected)")
        (help "Select 68000 for a stock 500, 600, 2000 or any\n"
              "other Amiga that uses the 68000 CPU chip.\n\n"
              "Select 68020+ for an Amiga that uses a\n"
              "68020, 68030, 68040 or a 68060 CPU chip.")
        (choices "68000" "68020+")
        (default cpuid)
    )
)

(if (= cpuid 0)
    (
    (set cpusuf ".000")
    )
    (
    (set cpusuf ".020")
    )
)

;
;   Create the source path to the binaries
;   --------------------------------------
(set rnstr
    (cat sbpath "rexxnet"  tcpname cpusuf)
)
(set rnstrinfo
    (cat sbpath "rexxnet.info")
)
(set rndstr
    (cat sbpath "rexxnetd" tcpname cpusuf)
)
(set rndstrinfo
    (cat sbpath "rexxnetd.info")
)

;
;   Copy the Client: rexxnet
;   ------------------------
(set rn (askdir
        (prompt "Where do you want the rexxnet copied to?\n(This is the 'Client' software)")
        (help "Where do you want to execute the 'Client' from?")
        (default dcpath)
        )
)
(if rn
    (
        (copyfiles
            (source rnstr)
            (newname "rexxnet")
            (dest rn)
        )
        (copyfiles
            (source rnstrinfo)
            (dest rn)
        )
    )
)

;
;   Copy the Server: rexxnetd
;   -------------------------
(set rnd (askdir
        (prompt "Where do you want rexxnetd copied to?\n(This is the 'Server' software)")
        (help "Where do you want to execute the 'Server' from?")
        (default dspath)
        )
)
(if rnd
    (
        (copyfiles
            (source rndstr)
            (newname "rexxnetd")
            (dest rnd)
        )
        (copyfiles
            (source rndstrinfo)
            (dest rnd)
        )
    )
)

;
;   Modify the Services file?
;   -------------------------
(set servpath
    (cat dpath "db/services")
)
(set msg1
    (cat "Modify your " servpath " file?\n\nThis is required in order to run RexxNet.\n\nDon't modify this file more than once.\nIf you are re-installing RexxNet or taking\nan upgrade, just 'Skip This Part'. ")
)
(set msg2
    (cat "This will modify your " servpath "\n")
)

(textfile
    (prompt msg1)
    (dest servpath)
    (include servpath)
    (append "rexxnetd   2001/tcp\n")
    (confirm)
    (help msg2
          "file to contain an entry for rexxnetd.\n"
          "\n"
          "This line will be added to the end of the table:\n"
          "\n"
          "'rexxnetd   2001/tcp'\n\n"
          "If RexxNet has been previously installed, don't do this again."
          " It will add the entry again at the bottom of your file and you will"
          "have to manually remove it."
    )
)


;
;   See if the user wants to automatically start rexxnetd
;   -----------------------------------------------------
(set suopt
    (askchoice
        (prompt "Would you like to aways startup the Server\n'rexxnetd' during bootup?")
        (help "This allows you to have the Server running whenever\n"
              "you boot up.\n\n"
              "If you choose an option, make sure it occurs after\n"
              "your TCP/IP startup has occured.")
        (choices "Don't auto startup 'rexxnetd'" "Auto startup through user-startup" "Auto startup through WBStartup")
        (default 0)
    )
)

(if (= suopt 1)
    (
        (set servpath
            (cat "run <>nil: " rnd "/rexxnetd\n")
        )
        (startup "RexxNet"
            (prompt "Adding lines to user-startup to automatically start rexxnetd")
            (help "This will modify your s:user-startup file")
            (command servpath)
        )
    )
)

(if (= suopt 2)
    (
    (set servpath
        (cat rnd "/rexxnetd")
    )
    (copyfiles
            (source "Binaries/AS225/rexxnetd.project.info")
            (newname "rexxnetd.info")
            (dest "Sys:WBStartup")
        )
    (tooltype
        (dest "Sys:WBStartup/rexxnetd")
        (prompt "Modifying the path to the default tool")
        (setdefaulttool servpath)
        (help "This sets the path to rexxnetd")
        (noposition)
    )
    )
)


;
;   Copy the AmigaGuide Documentation?
;   ----------------------------------
(set doit
    (
    askbool
        (prompt "Do you want the RexxNet.guide file copied to your system?")
        (help "This AmigaGuide document describes all about RexxNet.")
        (choices "Yes" "No")

    )
)
(if doit
    (
        (set nr (askdir
                (prompt "Where do you want RexxNet.guide copied to?")
                (help "Choose a directory to copy the file to...")
                (default "help:")
                )
        )
        (if nr
            (copyfiles
                (source "Documentation/RexxNet.guide")
                (dest nr)
                (infos)
            )
        )
        (tooltype
            (dest (tackon nr "RexxNet.guide"))
            (prompt "Modifying the default viewer")
            (setdefaulttool docv)
            (help "This sets the default viewer for the AmigaGuide documentation")
            (noposition)
        )
    )
)

;
;   Force Viewing the AmigaGuide Documentation
;   ------------------------------------------
(copyfiles
    (source "Documentation/RexxNet.guide")
    (dest "ram:")
    (nogauge)
)
(set cmd (cat "Sys:Utilities/" docv))
(cat cmd " ram:RexxNet.guide")

(run "system:utilities/AmigaGuide ram:RexxNet.guide"
    (help "RexxNet FAQ")
    (prompt "This displays the AmigaGuide Documenation?")
)

(delete "ram:RexxNet.guide")

