; FTPMount install script
; Date : 30-May-02
; Version 0.3

(transcript "Installing FTPMount ...")

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


; ask for installation mode:
(set #permanentinstall
  (askbool
    (prompt "\nDo you want to install FTPMount permanently?")
    (help   "There are two possibilities to install FTPMount: "
            "a permanent installation which will make an assign FTPMountDir "
            "and copy all needed files to a suitable place in your system; "
            "and a small installation which will only copy the files to a "
            "place on your harddisk where FTPMount must be started each time "
            "by the Quick-Install and removed by Quick-Remove (thanks to "
            "Alessandro Marinuzzi [alecos@ltsnet.it])."
    )
  )
)

; get destination:
(set #parent
        (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.  In permanent installation, 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)
        )
)
; create directories:
(set @default-dest (tackon #parent "FTPMountDir"))
(if(not(exists @default-dest))
  (
    (makedir @default-dest (infos))
  )
)
(if(not(exists (tackon @default-dest "L")))
  (
    (makedir (tackon @default-dest "L") (infos))
  )
)
(makeassign "FTPMountDir" @default-dest)

; modify user-startup:
(if #permanentinstall
  (
    (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: " @default-dest "\n"))
    )
  )
)

; copy files:
(copyfiles (source "FTPMountdir")(dest "FTPMountdir:")(all) )

(if #permanentinstall
  (
    ; copy mount entry:
    (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 select 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 "FTPMountdir:FTP")
        (dest name)
        (infos)
    )
    (if (= dact "1") (tooltype (dest (tackon name "FTP")) (settooltype "ACTIVATE" "1")))
  )
)

; set environment variables:
(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)
                )
        )
)

; copy catalogs:
;(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 "locale:catalogs")
;        (confirm "average")
;)


; rename correct handler:
(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 #permanentinstall
  (
    (set #exitmsg "Depending on the way you want to start FTPMount, a reboot is recommended before you use FTP:")
  )
  (
    (run "assign FTPMountDir: remove")
    (set #exitmsg (cat "\n\n\nTo use FTPMount, simply start Quick-Install in " @default-dest "."))
  )
)

(exit #exitmsg (quiet))
