; $VER: ADMail Install Script 1.2 (17.12.95)
; by Simon Brown

; == Initialize ===========================================================

(set appname "ADMail")
(set doc-name "ADMail.guide")
; == Help Text ============================================================

(set #AskFile-help      (cat    "\n   Use the file requester to select the location\n"
                                "    on on your hard-disk, where the file resides.\n" ))

(set #AskDir-help       (cat    "\n   Use the requester to select the location (the\n"
                                "    directory, or partition) where the files(s)\n"
                                "    should be placed.\n\n"))

(set #Main-help         (cat    "\n   This section of the installation deals with\n"
                                "    copying the main ADMail executable.\n"
                                "    The file will be copied to the location\n"
                                "    previously specified.\n\n"
                                "   You are provided with information concerning\n"
                                "    the version of your current copy (if you have one),\n"
                                "    in order to ensure you don't accidently overwrite\n"
                                "    a newer version.\n" ))

(set #GuideViewer-help  (cat    "\n   Select from the list, the viewer you use to\n"
                                "      display AmigaGuide documents.\n\n"
                                "   If the one you use is not listed, select\n"
                                "    \"Other...\".  You will then be asked to select\n"
                                "    the one you use.\n" ))

(set #Config-help       (cat    "\n   Fill in the value you require for the option\n"
                                "    you are being prompted for. Check the guide\n"
                                "    for more information on each setting.\n\n"
                                "   If you don't want to specify a value, accept\n"
                                "    the displayed default.\n" ))

(set #Makedir-help      (cat    "\n   A user directory can be created for you under\n"
                                "    the base directory. This directory is where\n"
                                "    the user configuration file will be kept, and\n"
                                "    is also the default location for the .signature\n"
                                "    and header files.\n"
                                "   If you answer Yes, you'll be asked to confirm the\n"
                                "    directory name, the directory will be created\n"
                                "    (if it does not already exist) and an empty\n"
                                "    configuration file placed within.\n" ))

(set #Userid-help       (cat    "\n   The base directories for all settings have\n"
                                "    been configured. This last option allows you\n"
                                "    to specify the name of your home directory.\n"
                                "    The default should hopefully be correct,\n"
                                "    but if not you can enter a new name here.\n"))

; == Prompt Text ==========================================================

(set #MainLoc-prompt            "Select location for main program file...\n" )
(set #IconLoc-prompt            "Select location for script & icon...\n")
(set #DocLoc-prompt             "Select location for documentation...\n" )

(set #GuideViewer-prompt        "Which AmigaGuide viewer?\n" )

(set #CopyMain-prompt               "Copying executable...\n" )
(set #CopyGuide-prompt              "Copying documentation...\n")

; == Config file prompts ==================================================

(set #basedir-prompt (cat       "\nGive the path to the directory you wish to use for\n"
                                "the base directory. This will be represented as\n"
                                "$BASEDIR in all other directory settings.\n"))

(set #maildir-prompt (cat       "\nGive the path to the directory where the mailboxes\n"
                                "are stored.\n"))

(set #editor-prompt (cat        "\nGive the name of your favourite text editor -\n"
                                "include any command line options you think you might need.\n"))

(set #sendmail-prompt (cat      "\nGive the name of the program you use to send mail -\n"
                                "include required command line options, and also\n"
                                "include \"$MSG\" to indicate the message filename.\n"))

(set #makedir-prompt (cat       "\nWould you like a user directory to be created?\n"))

(set #userid-prompt (cat        "\nGive the name of the user directory to create.\n"))

; == Config file defaults =================================================

(set #def-basedir               "USR:")
(set #def-maildir               "$BASEDIR/Mail")
(set #def-editor                "$Editor")
(set #def-sendmail              "sendmail <$MSG -f $USER")
; == Miscellaneous Text ===================================================

(set #Welcome-msg
                        (cat    "\nADMAIL INSTALLATION SCRIPT\n\n"
                                "Thank you for choosing\n"
                                "ADMail, Amazing Developments Mail.\n"
                                "\nThis installation script will copy all\n"
                                "necessary files to your hard-disk,\n"
                                "and enable you to set the basic\n"
                                "configuration for your system.\n\n"
                                "You are advised to have the docs handy,\n"
                                "if you wish to set any options.\n\n"
                                ))

(set #bad-kick
    (cat "ADMail requires Kickstart 2.04 or greater to run."))
; == Check KS version =====================================================

(if (< (/ (getversion) 65536) 37)
    (
        (abort #bad-kick)
    )
)

(set wbversion (/ (getversion "libs:version.library") 65536))

; == Give Welcome message =================================================

(message #Welcome-msg)
(welcome)

; == Install the Main Files ===============================================

; Where should I copy the new main files to?

(complete 0)

(set !MainLocation
    (askdir
        (prompt #MainLoc-prompt)
        (help #AskDir-help)
        (disk)
        (default "SYS:C")
    )
)

(set @default-dest !MainLocation)

(copylib
    (prompt #CopyMain-prompt)
    (help #Main-help)
    (source "ADMail")
    (dest !MainLocation)
    (confirm)
)

(complete 25)

; Where should I put the icon?

(set !IconLocation
    (askdir
        (prompt #IconLoc-prompt)
        (help #AskDir-help)
        (disk)
        (default !MainLocation)
    )
)

(delete "Read_Mail")

(textfile
    (dest "Read_Mail")
    (append (tackon !MainLocation appname))
    (append "\nendcli\n")
)

(copyfiles
    (prompt #Main-prompt)
    (source "Read_Mail")
    (dest !IconLocation)
    (infos)
)

(complete 50)

; == Install Documentation ================================================

; Where do they want the docs?

(set !DocLocation
    (askdir
        (prompt #DocLoc-prompt)
        (help #AskDir-help)
        (default !MainLocation)
        (disk)
    )
)

(set !GuideViewer
    (askchoice
        (prompt #GuideViewer-prompt)
        (help #GuideViewer-help)
        (choices
            "MultiView"
            "AmigaGuide"
            "Other..."
        )
        (default (if (>= wbversion 39) 0 1)
        )
    )
)

(if (= !GuideViewer 0) (set !GuideViewer "MultiView"))
(if (= !GuideViewer 1) (set !GuideViewer "AmigaGuide"))
(if (= !GuideViewer 2)
    (set !GuideViewer
        (askfile
            (prompt #GuideViewer-prompt)
            (help #AskFile-help)
            (default "SYS:")
        )
    )
)

(copyfiles
    (prompt #CopyGuide-prompt)
    (source doc-name)
    (dest !DocLocation)
    (infos)
)

(tooltype
    (dest (tackon !DocLocation doc-name))
    (setdefaulttool !GuideViewer)
)

(copyfiles
    (prompt #CopyGuide-prompt)
    (source "AFD-Copyright")
    (dest !DocLocation)
)
(complete 70)

(set !BaseConfig
    (askbool
        (prompt "\n\nDo you wish to set the base configuration?")
        (help "\n\nThis will set up the ENV:ADMail.config file,\n"
            "and copy it to ENVARC: for future use. The base\n"
            "configuration file holds defaults for all the users\n"
            "on your system, and also needs to be set up if you\n"
            "want a base directory other than USR:.\n")
        (default 1)
    )
)

(set #basedir
)

(if !BaseConfig
    (

    (set #basedir
        (askstring
            (prompt #basedir-prompt)
            (default #def-basedir)
            (help #Config-help)
        )
    )

    (complete 75)

    (set #maildir
        (askstring
            (prompt #maildir-prompt)
            (default #def-maildir)
            (help #Config-help)
        )
    )

    (complete 80)

    (set #editor
        (askstring
            (prompt #editor-prompt)
            (default #def-editor)
            (help #Config-help)
        )
    )

    (complete 85)

    (set #sendmail
        (askstring
            (prompt #sendmail-prompt)
            (default #def-sendmail)
            (help #Config-help)
        )
    )

    (complete 90)

    (textfile
        (dest (cat "ENV:" "ADMail.config"))
        (if (not (= #basedir #def-basedir))
            (append (cat "BaseDir   \"" #basedir "\"\n"))
        )
        (if (not (= #maildir #def-maildir))
            (append (cat "MBoxDir   \"" #maildir "\"\n"))
        )
        (if (not (= #editor #def-editor))
            (append (cat "Editor   \"" #editor "\"\n"))
        )
        (if (not (= #sendmail #def-sendmail))
            (append (cat "Sendmail   \"" #sendmail "\"\n"))
        )
    )

    (copyfiles
        (prompt #Main-prompt)
        (source (cat "ENV:" "ADMail.config"))
        (dest "ENVARC:")
    )
))

(complete 95)

(set !Makedir
    (askbool
        (prompt #makedir-prompt)
        (help #Makedir-help)
        (default 1)
    )
)

(set !user
    (getenv "USER")
)

(if (= !user "")
    (set !user "user")
)

(if !Makedir
    (
    (set !user
        (askstring
            (prompt #userid-prompt)
            (default !user)
            (help #Userid-help)
        )
    )

    (if (not (exists (tackon (tackon #basedir !user) "ADMail.config")))
        (
        (textfile
            (dest (cat "T:" "ADMail.config"))
            (append
                (cat "# " appname " configuration file.\n"
                     "# Check " appname ".guide and fill in the options you need.\n"
                ))
       )
       (copyfiles
            (prompt #Main-prompt)
            (source (cat "T:" "ADMail.config"))
            (dest (tackon #basedir !user))
       )

       (delete
            (dest (cat "T:" "ADMail.config"))
       )

   ))

   (message (cat "\nUser directory: " (tackon #basedir !user) "\n"))
))

(complete 100)

; == Exit =================================================================

(set #Exit-msg          (cat    "\nInstallation complete.\n\n\n"
                                "Location of program file:\n"
                                !MainLocation
                                "\n\nLocation of Document files:\n"
                                !DocLocation
                                "\n\n" ))

(message #Exit-msg)

(exit (quiet))

