;                                                       __
; -----------------------------------------------      ///
; Mail Manager Installation Script by Marco Musso __  ///
; ----------------------------------------------- \\\///
;     Give credit where the credit is due          \///

(set prompt-mmdir "Where should I install Mail Manager (a drawer called MM will be created) ?")
(set help-mmdir "You must choose where to create your MM: dir...")

(set prompt-startup "Some instructions need to be added to the \"S:user-startup\" so that your system will be properly configured to use Mail Manager")
(set help-startup "These are the assignments for a correct use of Mail Manager")

(set fidonet-questions-intro "Now let's proceed with some questions for\na basic configuration of Mail Manager")
(set fidonet-questions-help "You must supply your name and other Fidonet parameters.")

(set prompt-sysopname "Please insert your name...")
(set help-sysopname "Here you must insert the name you want to use in the Message Areas.")

(set prompt-sysopaddr "Please enter your address in 5D (complete with the domain) ...\nExample: 2:335/602.2@fidonet")
(set help-sysopaddr "The Address must be in 5D format (<zone>:<net>/<node>.<point>@<domain> ). The domain string should not include the extension ( for example use 'fidonet' and not 'fidonet.org' ) and should not be longer than 8 chrs.")

(set prompt-bossaddr "Please enter the address of your boss...\nExample: 2:335/602.0@fidonet")
(set help-bossaddr "This is the address of the node which sends you the mail")

(set prompt-archiver "Which archiver do you want to use ?")
(set help-archiver "This is the archiver which will be used for crunching the Mail Packets")

(set prompt-archiver-add "Please, insert the Arc command")
(set help-archiver-add "This is the command to be executed to archive mail. Mail Manager will automatically append the name of the bundle and the name of the packet to compress, in this order.")

(set prompt-archiver-extr "Please, insert the UnArc command")
(set help-archiver-extr "This is the command to be executed to unarchive mail. Mail Manager will automatically append the name of the bundle to UnPack The bundle will be unarchived in the configured WorkDir.")

(set prompt-inbound-dir "Please, insert the path of your Inbound dir")
(set help-inbound-dir "This is the name of the directory where Mail Manager will look for incoming Bundles, Packets and Files. It should be the same directory as configured in your mailer as Inbound.")

(set prompt-outbound-dir "Please, insert the path of your Outbound dir")
(set help-outbound-dir "This is the name of the directory where Mail Manager will place outgoing Packets and Flow Files. It should be the same directory as configured in your mailer as Outbound.")

(set prompt-maildev-dir "Select the path where Mail Manager will create the Message Base")
(set help-maildev-dir "This is the directory or device where Mail Manager will create the Message Base. Mail Manager will also monitor it in order to show you the available diskspace.\nExample: Mail:")

(set prompt-bad-dir "Please, insert the path of your Bad dir")
(set help-bad-dir "This is the name of the directory where Mail Manager will move wrong or corrupted incoming Packets and Tick files.")

(set prompt-nodelist-dir "Please, insert the path where I should look for the Nodelist")
(set help-nodelist-dir "This is the name of the directory where Mail Manager will look for the compiled Nodelist.")

(set prompt-userlist-dir "Please, insert the path where I should look for the UserList")
(set help-userlist-dir "This is the name of the directory where Mail Manager will look for the Userlist.\nMail Manager uses the following userlist format:\n\"<Full Name>\"   <5D Address>  <nickname>")

(set prompt-genmmcfg "Generating default configuration file....")

(set prompt-copy-bin "Now copying binaries...")
(set help-copy-bin "These are the Mail Manager executables")

(set prompt-copy-doc "Now copying docs...")
(set help-copy-doc "Mail Manager offers you an AmigaGuide documentation and a Plain Text Manual translated in different languages.\nYou MUST at least copy the AmigaGuide documentation in order to get the OnLine Help function of Mail Manager.")

(set prompt-copy-stdrexx "Now copying the ARexx examples...")
(set help-copy-stdrexx "These are some small examples showing the use of some of the Mail Manager ARexx commads.")

(set prompt-askinst-contrib "Should I also copy the Contrib files ?")
(set help-askinst-contrib "These are some ARexx scripts written by the Testers of Mail Manager. Copy them, you'll find many useful functions !")
(set yes-inst-contrib "Yes")
(set no-inst-contrib "No")

(set prompt-copy-contrib "Now copying Contrib files...")
(set help-copy-contrib "...")

(set prompt-copy-locale "Copying the locale files ?")
(set help-copy-locale "...")

(set prompt-def-userlist "Now copying the Userlist")
(set help-def-userlist "This is an example of the Mail Manager Userlist")

(set prompt-copy-font "Shall I copy the MMBrowse Font ?")
(set help-copy-font "This is a special font designed by me (Pino Aliberti) to allow more characters to be displayed on the screen.\nThe MMBrowse/8 font is particularly useful if you normally use topaz 8 as your default font")

(set prompt-editor "Which Text Editor would you like to use ?\nWARNING: The Editor should be runned in a synchronous way (it should not return until you close it).\nFor example with CEd you should use  'CEd %s -sticky'.")
(set help-editor "This is the Editor command that will be executed by Mail Manager to edit a message.\nPut a `%s' in this command string to specify where Mail Manager should insert the name of the temporary file.")

; **** PROCEDURE declaration part ****
; ************************************

; *** procedure: choose-mmdir: ask the user for the MM: assign
(procedure choose-mmdir
    (set mmdir (askdir (prompt prompt-mmdir)
                 (help help-mmdir)
                 (disk)
                 (default "MAIL:")
               )
    )
)

; *** ask the user to write on user-startup
(procedure add-user-startup
    (startup "Mail Manager" (prompt prompt-startup)
                            (help help-startup)
                            (command
                                    "if exists \"" @default-dest "\"\n"
				    "   assign MM: \"" @default-dest "\"\n"
				    "endif\n"
                            )
    )
)

; *** Main Program ***
; ********************

(set inst-dir (pathonly @icon))

(complete 0)

; *** ask to the user and create the directory
(set mmdir (choose-mmdir))
(set @default-dest (tackon mmdir "MM"))

(makedir @default-dest)

(set mm-info (tackon inst-dir "//MM.info"))
(copyfiles (source mm-info) (dest mmdir))

(if (not @pretend) (makeassign "MM" @default-dest))

; *** Tell the user that we proceed with some question...
(message fidonet-questions-intro
    (help fidonet-questions-help)
)

; *** ask for the sysop's name
(set sysopname (askstring (prompt prompt-sysopname)
                          (help help-sysopname)
                          (default "your name")
               )
)

(complete 5)

; *** ask the user for his address
(set sysopaddr  (askstring (prompt prompt-sysopaddr)
                           (help help-sysopaddr)
                )
)

(complete 10)

; *** ask the user for the boss's address
(set bossaddr  (askstring (prompt prompt-bossaddr)
                          (help help-bossaddr)
               )
)

(complete 15)

; *** ask the user for the archiver
(set archiver (askchoice (prompt prompt-archiver)
                         (help help-archiver)
                         (choices "LhA" "Zip" "Zoo" "Arc" "Lzx")
                         (default 0)
              )
)

(complete 20)

; *** set the arc-id var
(select archiver
    (set arc-id "LHA     2       \"-lh\"")
    (set arc-id "ZIP     0       \"PK\"")
    (set arc-id "ZOO     0       \"ZOO\"")
    (set arc-id "ARC     0       \"\"")
    (set arc-id "LZX     0       \"LZX\"")
)

; *** ask the user for the command for packing files
(select archiver
    (set temp "C:LhA a")
    (set temp "C:Zip a")
    (set temp "C:Zoo a")
    (set temp "C:Arc a")
    (set temp "C:Lzx -x0 a")
)
(set archiver-add (askstring (prompt prompt-archiver-add)
                    (help help-archiver-add)
                    (default temp)
                  )
)

; *** ask the user for the command for unpacking files
(select archiver
    (set temp "C:LhA x")
    (set temp "C:Zip x")
    (set temp "C:Zoo x")
    (set temp "C:Arc x")
    (set temp "C:Lzx -x0 x")
)
(set archiver-extr (askstring (prompt prompt-archiver-extr)
                    (help help-archiver-extr)
                    (default temp)
                   )
)

(complete 30)

(set editor (askstring (prompt prompt-editor)
                (help help-editor)
                (default "C:Ed %s")
            )
)

(complete 32)

; *** ask the user for various directories
(set maildev-dir (askdir (prompt prompt-maildev-dir)
                         (help help-maildev-dir )
                         (disk)
                         (default "MAIL:")
                 )
)

(complete 35)

(set inbound-dir (askdir (prompt prompt-inbound-dir)
                         (help help-inbound-dir )
                         (disk)
                         (default "IN:")
                 )
)

(complete 40)

(set outbound-dir (askdir (prompt prompt-outbound-dir)
                          (help help-outbound-dir)
                          (disk)
                          (default "OUT:")
                  )
)

(complete 45)

(set bad-dir (askdir (prompt prompt-bad-dir)
                     (help help-bad-dir)
                     (disk)
                     (default "BAD:")
             )
)

(complete 50)

(set nodelist-dir (askdir (prompt prompt-nodelist-dir)
                          (help help-nodelist-dir)
                          (disk)
                          (default "NODELIST:")
                  )
)

(complete 55)

(set userlist-dir (askdir (prompt prompt-userlist-dir)
                      (help help-userlist-dir)
                      (disk)
                      (default "NODELIST:")
                  )
)

(complete 60)

; *** now we proceed with the real installation
(makedir "MM:Config")

; *** copy bin files
(makedir "MM:Bin")
(set mmbin-info (tackon inst-dir "/Bin.info"))
(copyfiles (source mmbin-info) (dest "MM:"))

(set bin-dir (tackon inst-dir "/bin"))
(copyfiles (prompt prompt-copy-bin)
           (help help-copy-bin)
           (source bin-dir)
           (dest "MM:Bin")
           (all)
           (infos)
)

(complete 62)

; *** copy guide file (no interaction with user)
(makedir "MM:Docs")
(set mmdocs-info (tackon inst-dir "/Docs.info"))
(copyfiles (source mmdocs-info) (dest "MM:"))

(set doc-dir (tackon inst-dir "/docs"))
(copyfiles (source (tackon doc-dir "MailManager.guide"))
           (dest "MM:Docs")
           (infos)
           (nogauge)
           (optional nofail)
)

(complete 65)

; *** copy doc files
(set doc-dir (tackon inst-dir "/docs"))
(copyfiles (prompt prompt-copy-doc)
           (help help-copy-doc)
           (source doc-dir)
           (pattern "~(MailManager.guide#?)")
           (dest "MM:Docs")
           (infos)
           (if (= @user-level 2) (confirm))
           (optional nofail)
)

(complete 70)

; *** copy registration
(makedir "MM:Registration")
(set mmreg-info (tackon inst-dir "/Registration.info"))
(copyfiles (source mmreg-info) (dest "MM:"))

(set registration-dir (tackon inst-dir "/registration"))
(copyfiles (source registration-dir)
           (dest "MM:Registration")
           (all)
           (infos)
)

(complete 72)

; *** copy standard rexx files
(set stdrexx-dir (tackon inst-dir "/rexx"))
(copyfiles (prompt prompt-copy-stdrexx)
           (help help-copy-stdrexx)
           (source stdrexx-dir)
           (dest "MM:Rexx")
           (all)
           (optional nofail)
)

(complete 75)

; *** copy previews
(makedir "MM:Previews")
(set mmprev-info (tackon inst-dir "/Previews.info"))
(copyfiles (source mmprev-info) (dest "MM:"))

(set previews-dir (tackon inst-dir "/previews"))
(copyfiles (source previews-dir)
           (dest "MM:Previews")
           (all)
           (infos)
)

(complete 80)

; *** ask the user if he wants the contrib rexx files
(set contrib-dir (tackon inst-dir "/contrib"))
(if (askbool (prompt prompt-askinst-contrib)
             (help help-askinst-contrib)
             (default 1)
             (choices yes-inst-contrib no-inst-contrib))
        ; *** if yes, copy contrib rexx files
        (copyfiles (prompt prompt-copy-contrib)
                   (help help-copy-contrib)
                   (source contrib-dir)
                   (dest "MM:Contrib")
                   (all)
                   (optional nofail)
        )
)

(complete 85)

; *** copy the default userlist
(set other-dir (tackon inst-dir "/other"))
(copyfiles (prompt prompt-def-userlist)
           (help help-def-userlist)
           ; *** only one / needed !!!
           (source other-dir)
           (dest userlist-dir)
           (all)
           (if (= @user-level 2) (confirm))
           (optional nofail)
)

(complete 87)

; *** copy font files
(set fonts-dir (tackon inst-dir "/fonts"))
(if (askbool (prompt prompt-copy-font)
             (help help-copy-font)
             (default 1)
             (choices yes-inst-contrib no-inst-contrib))
        (copyfiles  (prompt prompt-copy-font)
                    (help help-copy-font)
                    (source fonts-dir)
                    (dest "FONTS:")
                    (all)
                    (optional nofail)
        )
)

(complete 90)

; *** copy Example.CFG
(set example-cfg (tackon inst-dir "/Config/Example.CFG"))
(copyfiles (source example-cfg) (dest "MM:Config"))
>

; *** generating MailManager.cfg
(textfile (prompt prompt-genmmcfg)
          (dest "MM:Config/MailManager.cfg")
          (append "#DEFSYSOPNAME \"" sysopname "\"\n"
                  "#ADDRESS " sysopaddr " 0\n"
                  "#GROUP default" "\n"
                  "#ARCHIVER " arc-id " \"" archiver-add "\" " "\"" archiver-extr "\"" "\n"
                  "#NODE " bossaddr " ADDR2D PACK4D NORMAL NORMAL " (substr arc-id 0 3) "\n"
                  "Group default 10\n"
                  "CanCreateAreas " maildev-dir " " sysopaddr " Compressed default 10\n"
                  "#ROUTING *:*/*.*@* ALL SEND " bossaddr " NORMAL" "\n"
                  "#INBOUND " inbound-dir "\n"
                  "#OUTBOUND " outbound-dir "\n"
                  "#BADDIR " bad-dir "\n"
                  "#MAILDEV " maildev-dir "\n"
                  "#USERLIST \"" (tackon userlist-dir "MM.userlist") "\"\n"
                  "#NODELISTDIR " nodelist-dir "\n"
                  "#EDITOR \"" editor "\"\n"
                  "#PREPARSEKLUDGE \"\\8\"\n"
                  "#PREPARSEQUOTED \"\\3\"\n"
                  "#CHECKDOMAIN\n"
                  "#ORIGIN5D\n"
                  "#TEXTSTYLES\n"
                  "#SHOWKLUDGES\n"
                  "#QUOTEKUDGES\n"
                  "#REFLOW\n"
                  "#MAILAREA \"\\bMatrix\" MATRIX " (tackon maildev-dir "MATRIX/ ") sysopaddr " default 10\n"
                  "#BADAREA  \"\\bBAD\" BAD_MSGS " (tackon maildev-dir "BAD/ ") sysopaddr " default 10\nReadOnly\n"
          )
)

(complete 95)

; *** warn the user that we must write to the user-startup
(add-user-startup)

(complete 100)

; **** End Mail Manager Installation Script ****
; **********************************************

