; FTPMount install script
; Date : 11-Apr-01
; Version 0.2

(transcript "Installing FTPMount ...")

(welcome "Greetings!\nYou are about to install FTPMount on your system.  "
                        "This is a wise choice.\n")

(set name 
        (askdir
                (prompt "Where should FTPMount be installed?")
                (help
                        "All of FTPMount's files will be installed in one directory, "
                        "called FTPMountDir, which will be placed in the directory you specify "
                        "here.  This directory will have the logical assign of FTPMountDir: "
                        "associated with it.  You will probably need to be able to access this "
                        "directory fairly often, so don't bury it too deep.\n\n"
                        @askdir-help
                )
                (default @default-dest)
        )
)

(makeassign "FTPMountDir" name)

(set @default-dest name)

(makedir "FTPMountDir:FTPMountDir" (infos))

(if @pretend
        (makeassign "FTPMountDir" "T:" (safe))
        (makeassign "FTPMountDir" "FTPMountDir:FTPMountDir")
)

(set @default-dest (getassign "FTPMountDir" "a"))

(startup "FTPMount" 
        (prompt "Adding assign of FTPMountDir: to User-Startup")
        (help 
                "FTPMount uses the FTPMountDir: assign to work out where its files are.\n\n"
                @startup-help
        )
        (command (cat "assign FTPMountDir: " (getassign "FTPMountDir" "a") "\n"))
)

(makedir "FTPMountDir:Hosts" (infos))

(makedir "FTPMountDir:L")

(set ddest
        (askchoice
                (prompt
                        "Where do you want to install the DOSDriver mount entry?\n\n"
                        "NB:  If the entry is put in DEVS:DOSDrivers it is inadvisable "
                        "for it to be activated upon mounting."
                )
                (help
                        "This file tells the system where to find FTPMount-Handler and what "
                        "to do with it.  The standard places to find DOSDriver mount entries are "
                        "DEVS:DOSDrivers and SYS:Storage/DOSDrivers.  "
                        "SYS:WBStartup is a little unorthodox, however it seems to be the only "
                        "place that is guaranteed to work and mount FTP: safely upon system "
                        "startup time.  If you elect to put the FTP: entry in DEVS:DOSDrivers "
                        "or SYS:WBStartup it will be mounted at boot time.  If you "
                        "put it anywhere else, then you will have to explicitly mount it before "
                        "you can reference FTP: ... either by double clicking on the icon, or, if "
                        "you have placed the entry in Storage, by typing 'mount FTP:' from a CLI.\n\n"
                        "NB:  Mounting from DEVS:DOSDrivers is done at boot time before the assign "
                        "of FTPMountDir: is done.  Because of this it is inadvisable for an entry to "
                        "be put in DEVS:DOSDrivers if you want it to be activated at boot time.  Put "
                        "it in SYS:WBStartup (or equivalent) instead in this case."
                )
                (choices "SYS:WBStartup" "DEVS:DOSDrivers" "SYS:Storage/DOSDrivers" "Elsewhere")
        )
)

(if (= ddest 3)
        (set name
                (askdir
                        (prompt "Where do you want to put the FTP: DOSDriver mount entry?")
                        (help @askdir-help)
                        (default "SYS:WBStartup")
                )
        )
)

(set dact
        (askbool
                (prompt
                        "Do you want the DOSDriver to be activated upon mounting?"
                        (if (= ddest 1) 
                                (cat
                                        "\n\nNB: It is inadvisable to say \"Yes\" here since FTPMountDir: will "
                                        "not have been assigned when DEVS:DOSDrivers/FTP is mounted."
                                )
;                                ""
                        )
                )
                (help
                        (if (<= ddest 1) ("FTP: will be mounted at boot time, however, " "When FTP: is mounted "))
                        "you have the option of making it active at this time, or leaving it inactive "
                        "until you first reference a file or directory on FTP:.  "
                        "The main difference is that when FTP: is not active there is no icon associated "
                        "with the device, and so it will not appear on Workbench.  Leaving it inactive "
                        "means that no memory is used by the device until it is actually referenced.\n\n"
                        "NB:  Mounting from DEVS:DOSDrivers is done at boot time before the assign "
                        "of FTPMountDir: is done.  Because of this it is inadvisable for an entry in "
                        "DEVS:DOSDrivers to be auto-activated."
                )
                (default 1)
        )
)


(if (= ddest 0) (set name "SYS:WBStartup"))
(if (= ddest 1) (set name "DEVS:DOSDRIVERS"))
(if (= ddest 2) (set name "SYS:Storage/DOSDrivers"))
; else name is already set correct

(copyfiles
        (source "DOSDrivers/FTP")
        (dest name)
        (infos)
)
(if (= dact "1") (tooltype (dest (tackon name "FTP")) (settooltype "ACTIVATE" "1")))

(set #user (getenv "user"))
(if (= #user "")
        (
                (set name
                        (askstring
                                (prompt
                                        "The USER environment variable needs to be set to your standard user name:"
                                )
                                (help
                                        "For anonymous logins, your email address is required.  FTPMount looks at "
                                        "the USER and HOST environment variables to construct your email address "
                                        "as USER@HOST.  Please enter a valid user name here.  This name will be "
                                        "saved to ENVARC:USER.\n\n"
                                        @askstring-help
                                )
                                (default "")
                        )
                )
                (textfile
                        (dest "ENVARC:USER")
                        (append name)
                )
                (textfile
                        (dest "ENV:USER")
                        (append name)
                )
        )
)

(set #host (getenv "host"))
(if (= #host "")
        (
                (set name
                        (askstring
                                (prompt
                                        "The HOST environment variable needs to be set to your email host:"
                                )
                                (help
                                        "For anonymous logins, your email address is required.  FTPMount looks at "
                                        "the USER and HOST environment variables to construct your email address "
                                        "as USER@HOST.  Please enter a valid email host here.  This name will be "
                                        "saved to ENVARC:HOST.\n\n"
                                        @askstring-help
                                )
                                (default "")
                        )
                )
                (textfile
                        (dest "ENVARC:HOST")
                        (append name)
                )
                (textfile
                        (dest "ENV:HOST")
                        (append name)
                )
        )
)

(copyfiles
        (prompt "Which catalogs do you want to install?")
        (help 
                "If you want FTPMount to use a language other than English "
                "(or you wish to modify the English used by FTPMount) "
                "then you will need to install the relevant catalogs.  "
                "You don't need to install any catalogs, in which case "
                "FTPMount will use its default English informative information.\n\n"
                @askoptions-help
        )
        (all)
        (source "Catalogs")
        (dest "sys:locale/catalogs")
        (confirm "average")
)

(set #hand (askchoice
        (prompt "Which Handler do you want to install?")
        (help "Use the first option if you still use a 68000.\n"
              "Else use the 60020 version.\n"
              "The debug  version is only for experts who want to find errors etc.")
        (choices "Plain 68000 version" "68020 version" "Debug version"))
)
(if (= #hand "0") (set #hanfile "l/ftpmount-handler"))
(if (= #hand "1") (set #hanfile "l/ftpmount-handler.68020"))
(if (= #hand "2") (set #hanfile "l/ftpmount-handler.debug"))

(copyfiles
        (source #hanfile)
        (dest "FTPMountDir:L")
        (newname "FTPMount-Handler")
)

(if (askbool    (prompt "Do you want the example Hosts installed?")
                (help   "Some example sub-directories of Hosts are available "
                        "to give some idea of how the various tooltype options "
                        "can be used." )
                (default 1)
     )
     (
        (copyfiles (source "Hosts") (dest "FTPMountDir:Hosts") (all))
     )
)

(if
        (askbool
                (prompt
                        "Do you want the documentation file installed?"
                )
                (help
                        "Do you want the documentation file copied over to FTPMountDir: "
                        "for future reference?"
                )
                (default 1)
        )

        (copyfiles
                (source "FTPMount.guide")
                (dest "FTPMountDir:")
                (infos)
        )
)

(exit "Depending on the way you want to start FTPMount, a reboot is recommended before you use FTP:" (quiet))
