;Installer script to install [-cR!SP-]^BK's Sysdude Send door written by MaLC0MN^BK
;$VER: v3.0 of the installer script for Sysdude Send v1.53 --- Script by MaLC0MN^BK (17/08/96)
;.------------------------------------------------------------------------------------.
;|                                  * H·I·S·T·O·R·Y *                                 |
;+------------------------------------------------------------------------------------+
;| v1.0: Original code from install script (by me) for `SystemInfo' by Franky^BK      |
;| v2.0: First full working version for `Sysdude Send', never released:               |
;|       -added `Config.info' support;                                                |
;|       -changed version check into size check;                                      |
;|       -and a whole lot of tiny improvements.                                       |
;| v3.0: Final version, finished on 17-08-1996 at 00h23m25s:                          |
;|       -shortened the overall code by some 30 lines;                                |
;|       -optimised the tooltype adding stuff a great deal;                           |
;|       -removed a severe bug in the `tooltype-asking' structure;                    |
;|       -and, again, a whole lot of tiny improvements.                               |
;+------------------------------------------------------------------------------------+
;|                              * O·T·H·E·R  S·T·U·F·F *                              |
;+------------------------------------------------------------------------------------+
;| Comment strings beginning with `-----' indicate the different stadia of the script |
;| Comment strings beginning with `*****' indicate additional comment to some calls   |
;`------------------------------------------------------------------------------------'

;----- First we'll set up some standard string variables... -----

(set #hello_dudez
    (cat "\nB · A · D     K · A · R · M · A \n"
         "P r e s e n t s\n\n"
         "* Sysdude Send  v1.53 *\n"
         "Coded by [-cR!SP-]^BK\n\n"
         "Sysopsend Door for S!X & /X · Small update\n"
         "Features multiple-dir-sending, online help\n"
         "selectable archive names, LHA/LZX/ZIP pack\n"
         "and an `are you sure you wish to send' request.\n"
    )
)
(set #install_info
    (cat "\nThis script will NOT prompt you to\n"
         "create dirs or select a destination.\n"
         "It will install this door in \"Doors:BK/SysdudeSend/\".\n"
         "The necessary directories will be created;\n"
         "if you have an older version, that one will be updated;\n"
         "if you have a newer version, nothing will happen.\n"
         "It will also check your version of the \"AEDoor.library\"\n"
         "and the \"reqtools.library\"and, if necessary, update it.\n\n"
         "The only thing this script will ask you are some\n"
         "parameters needed to set up the configuration.\n\n"
         "DON'T COME WHINING TO US THAT WE DIDN'T WARN YOU!\n"
    )
)
(set #ttconfig
    (cat "A list of all tooltypes and their explanation:\n\n"
         "PSW\n"
         "              Here you can specify what password has to be used to start\n"
         "              the door.\n\n"
         "REQUESTER\n"
         "              This is the alternative to the password routines.\n"
         "              If this tooltype is set, the password routine will be skipped,\n"
         "              and a visual protection will be run. A requester will open;\n"
         "              This requester has to get closed within 4-5 seconds, or else\n"
         "              the door will quit. (This will prevent users from starting\n"
         "              the door and having the board hang the whole day!)\n"
         "              I prefer this method, because it is faster, and safer!\n"
         "              (Passwords are easily hacked, this will force the sysop to\n"
         "              be present!)\n\n"
         "DISPLAYFILES\n"
         "               If this tooltype is set, Sysdudesend will first display\n"
         "               a list of the files that are about to get transmitted.\n"
         "               This will slowdown a bit, but will prevent you from\n"
         "               sending wrong files (cardlists etc 8)..\n\n"
         "PACKERPATH\n"
         "               Here you can specify whether you want to use a default\n"
         "               packerpath or not. If you do not tick this box, the installer\n"
         "               will automatically set the path to \"RAM:\".\n"
         "               If you want the files to be packed somewhere else, this is the\n"
         "               way to specify it. You can enter pathnames here like \"RAM:\"\n"
         "               or \"DH1:Pack/\" or whatever. When using subdirs, don't forget\n"
         "               the ending `/' !\n\n"
         "EXTRACONFIRM\n"
         "               This tooltype has been added for the doubtfull people out there.\n"
         "               It gives you the chance to ABORT before sending.\n"
         "               Note: This tooltype is only valid when DISPLAYFILES is selected.\n"
         "                         You can't abort the sending of packed archives.\n"
    )
)
(set #newer
    (cat "\nIt seems that you have a newer version of \"Sysdude Send\"\n"
         "installed than the version in this archive(!?).\n"
         "Nothing has been changed.\n\n"
    )
)
(set #ready
    (cat "\nIt seems that you have allready installed this version of \n"
         "\"Sysdude Send\". I don't see why you'd like to install it again.\n"
         "Nothing has been changed.\n\n"
    )
)
(set #update_msg
    (cat "\nIt seems that an older version of \"Sysdude Send\"\n"
         "is present on your BBS. The main executeable and the\n"
         "AmigaGuide docs will be updated; your configuration\n"
         "will NOT be touched.\n"
    )
)
(set #update_exit
    (cat "\nWell... Seems everything went O.K.\n"
         "Your version of \"Sysdude Send\" was succesfully\n"
         "updated to \"Sysdude Send v1.53\".\n\n"
    )
)
(set #boardz
    (cat "Don't forget to call our boards:\n\n"
         "CYBER GARDEN.......[BHQ].......[2 NODES]......+32-11-xxxxxx\n"
         "DOXOLOGY...........[LHQ].......[2 NODES]......+32-16-xxxxxx\n"
         "METAL IMPACT.......[ HQ].......[3 NODES]......+32-15-xxxxxx\n"
         "NUCLEAR WASTE......[SHQ].......[2 NODES]......+46-510-xxxxx\n"
         "SKY TOWER..........[EHQ].......[6 NODES]......+45-748-xxxxx\n"
         "WHO CARES..........[WHQ].......[4 NODES].......416-xxx-xxxx\n"
    )
)

;***** These `set()'-calls are made because this way we only need to type in the board list once. *****

(set #newer (cat #newer #boardz))
(set #ready (cat #ready #boardz))
(set #asshole (cat #asshole #boardz))
(set #update_exit (cat #update_exit #boardz))

;----- Then we'll check if there is an older version... -----

(complete 0)

(message #hello_dudez)
(message #install_info)
(if (exists "Doors:BK/SysdudeSend/SS.xim") ((set #size1 (getsize "Doors:BK/SysdudeSend/SS.xim"))
                                            (set #size2 (getsize "BBS/Doors/BK/SysdudeSend/SS.xim"))
                                            (if (> #size1 #size2) (exit #newer (quiet)))
                                            (if (= #size1 #size2) (exit #ready (quiet)))
                                           )
)

;----- And if so we'll update it... -----

(if (< #size1 #size2) ((message #update_msg)
                       (working "Updating SS.xim...")
                       (copyfiles (source "BBS/Doors/BK/SysdudeSend/SS.xim")
                                  (dest "Doors:BK/SysdudeSend/")
                                  (nogauge)
                       )

                       (complete 25)

                       (working "Updating AmigaGuide docs...")
                       (copyfiles (source "Docs/SS.guide")
                                  (dest "Doors:BK/SysdudeSend/")
                                  (nogauge)
                       )

                       (complete 50)

                       (set #BK (exists "LIBS:AEDoor.library"))
                       (if (= #BK 1) ((set #ver1 (getversion "LIBS:AEDoor.library"))
                                      (set #ver2 (getversion "Libs/AEDoor.library"))
                                      (if (< #ver1 #ver2) ((working "Copying AEDoor.library...")
                                                           (copyfiles (source "Libs/AEDoor.library")
                                                                      (dest "LIBS:")
                                                                      (nogauge)
                                                           )
                                                          )
                                      )
                                     )
                                     ((working "Copying AEDoor.library...")
                                      (copyfiles (source "Libs/AEDoor.library")
                                                 (dest "LIBS:")
                                                 (nogauge)
                                      )
                                     )
                       )

                       (complete 75)

                       (set #BK (exists "LIBS:ReqTools.library"))
                       (if (= #BK 1) ((set #ver1 (getversion "LIBS:ReqTools.library"))
                                      (set #ver2 (getversion "Libs/ReqTools.library"))
                                      (if (< #ver1 #ver2) ((working "Copying ReqTools.library...")
                                                           (copyfiles (source "Libs/ReqTools.library")
                                                                      (dest "LIBS:")
                                                                      (nogauge)
                                                           )
                                                          )
                                      )
                                     )
                                     ((working "Copying ReqTools.library...")
                                      (copyfiles (source "Libs/ReqTools.library")
                                                 (dest "LIBS:")
                                                 (nogauge)
                                      )
                                     )
                       )

                       (working "Showing AmigaGuide docs...")
                       (run "C/AmigaGuide Doors:BK/SysdudeSend/SS.guide")

                       (complete 100)

                       (exit #update_exit (quiet))
                      )
)

;----- And if not we'll do the full install, after bugging the user with these necessary questions... -----

(set #BBS
    (askchoice (prompt "\nPlease indicate which BBS-software you run:\n")
               (help "It's necessary to know which BBS software you are running, since\n"
                     "these programs use a different method to add doors to the BBS-system.\n\n"
                     "  * If you select \"S!X\" then the door will be added in the\n"
                     "    file \"BBS:Commands/BBS.CMD\".\n"
                     "  * If you select \"/X\" then the door will be added via an\n"
                     "    icon in the dir \"BBS:Commands/BBSCmd/\".")
               (choices "S!X" "/X")
               (default 0)
    )
)

(complete 10)

(if (= #BBS 0) ((set #node (askstring (prompt "\nPlease enter the node number of which the door can be started (*=all nodes):")
                                      (help "If you enter 1 \"Sysdude Send\" can only be started from node 1.")
                                      (default "*")
                           )
                )
                (set #cmd (askstring (prompt "\nPlease enter the command name by which the door can be started:")
                                     (help "If you enter SS \"Sysdude Send\" can only be started by typing SS.")
                                     (default "SS")
                                     )
                          )
                (set #user (askstring (prompt "\nPlease enter the minimum user level required to start the door:")
                                      (help "If you enter 100 \"Sysdude Send\" can only be started by users with at least user level 100.")
                                      (default "100")
                           )
                )
                (working "Adding \"Sysdude Send v1.53\" to \"BBS.CMD\"...")
                (copyfiles (source "BBS:Commands/BBS.CMD")
                           (dest "RAM:T/")
                           (nogauge)
                           (safe)
                )
                (working "Adding \"Sysdude Send v1.53\" to \"BBS.CMD\"...")
                (textfile (dest "BBS:Commands/BBS.CMD")
                          (include "RAM:T/BBS.CMD")
                          (append #node #cmd "       XM" #user "DOORS:BK/SysdudeSend/SS.xim\n")
                )
                (delete "RAM:T/BBS.CMD" (safe) (optional "force"))
               )
               ((set #cmd (askstring (prompt "\nPlease enter the command name by which the door can be started, followed by:")
                                     (help "If you enter SS \"Sysdude Send\" can only be started by typing SS.")
                                     (default "SS")
                          )
                )
                (set #nname (cat #cmd ".info"))
                (set #user (askstring (prompt "\nPlease enter the minimum user level required to start the door:")
                                      (help "If you enter 100 \"Sysdude Send\" can only be started by users with at least user level 100.")
                                      (default "100")
                           )
                )
                (working "Adding \"Sysdude Send v1.53\" via icon...")
                (copyfiles (source "BBS/SS.info")
                           (dest "BBS:Commands/BBSCMD/")
                           (newname #nname)
                           (nogauge)
                )
                (set #icon (tackon "BBS:Commands/BBSCMD" #cmd))
                (working ("Setting %s tooltypes..." #nname))
                         (tooltype (dest #icon)
                                   (settooltype "ACCES" #user)
                                   (settooltype "TYPE" "XIM")
                                   (settooltype "LOCATION" "DOORS:BK/SysdudeSend/SS.xim")
                         )
               )
)

(complete 20)

(set #ttopts
    (askoptions (prompt "\nSelect the tooltypes you wish to be installed.\nDo NOT select `PSW' and `REQUESTER' simultaneously!\nPLEASE DO READ THE HELP HERE!\n")
                (help #ttconfig)
                (choices "[2p" "PSW" "REQUESTER" "DISPLAYFILES" "PACKERPATH" "EXTRACONFIRM")
                (default 0)
    )
)
(until (NOT (= #ttopts 0)) ((set #ttopts (askoptions (prompt "\nYou did not select anything!\nRead the help and choose one of these:\n")
                                                     (help #ttconfig)
                                                     (choices "[2p" "PSW" "REQUESTER" "DISPLAYFILES" "PACKERPATH" "EXTRACONFIRM")
                                                     (default 0)
                                         )
                            )
                           )
)
(until (OR (BITAND #ttopts 2) (BITAND #ttopts 4)) ((set #ttopts (askoptions (prompt "\nYou did not select `PSW' nor `REQUESTER'.\nReselect your choice and make sure you select `PSW' OR `REQUESTER' (read the help for info):\n")
                                                                            (help #ttconfig)
                                                                            (choices "[2p" "PSW" "REQUESTER" "DISPLAYFILES" "PACKERPATH" "EXTRACONFIRM")
                                                                            (default 0)
                                                                )
                                                   )
                                                  )
)
(until (NOT (AND (BITAND #ttopts 2) (BITAND #ttopts 4))) ((set #ttopts (askoptions (prompt "\nYou neglected the warning:\n\"DO NOT SELECT `PSW' AND `REQUESTER' SIMULTANEOUSLY!\"\nRead the help and choose again:\n")
                                                                                   (help #ttconfig)
                                                                                   (choices "[2p" "PSW" "REQUESTER" "DISPLAYFILES" "PACKERPATH" "EXTRACONFIRM")
                                                                                   (default 0)
                                                                       )
                                                          )
                                                         )
)
(if (BITAND #ttopts 2) (set #psw (askstring (prompt "\nPlease enter a password that will be needed for the sysop to confirm starting the door:")
                                            (help "If you enter YES \"Sysdude Send\" will only start when you enter YES at the `Password:' prompt.")
                                            (default "666")
                                 )
                       )
                       (set #psw "666")
)
(if (BITAND #ttopts 4) (set #req "1") (set #req "0"))
(if (BITAND #ttopts 8) (set #dpf "1") (set #dpf "0"))
(if (BITAND #ttopts 16) (set #ppt (askstring (prompt "\nPlease enter the path where \"Sysdude Send\" will store the archive after packing the selected files (this should end with a `/' when using subdirs!):")
                                             (help "If you enter `DH9:Stuff/Dope/Crack/' \"Sysdude Send\" will pack the archive you defined the name of, to that directory.")
                                             (default "RAM:")
                                  )
                        )
                        (set #ppt "RAM:")
)
(if (BITAND #ttopts 32) (set #ecf "1") (set #ecf "0"))

(complete 30)

;***** This may seem strange, but these `set()'-calls have to be put here since  *****
;***** the variable `#cmd' has just been set to the right string. If these would *****
;***** have been put earlier then the `%s' string would have been be replaced by *****
;***** an empty value, resulting in "...type `' and... ".                        *****

(set #normal_exit ("\nWell... Seems everything went O.K.\n \"Sysdude Send v1.53\" was succesfully installed so,\n start up your board, type `%s\' and have a look!\n\n" #cmd))
(set #normal_exit (cat #normal_exit #boardz))

;----- The nasty questions are done so, finally we'll start copying the actual program... -----

(if (exists "LIBS:AEDoor.library") ((set #ver1 (getversion "LIBS:AEDoor.library"))
                                    (set #ver2 (getversion "Libs/AEDoor.library"))
                                    (if (< #ver1 #ver2) ((working "Copying AEDoor.library...")
                                                         (copyfiles (source "Libs/AEDoor.library")
                                                                    (dest "LIBS:")
                                                                    (nogauge)
                                                         )
                                                        )
                                    )
                                   )
                                   ((working "Copying AEDoor.library...")
                                    (copyfiles (source "Libs/AEDoor.library")
                                               (dest "LIBS:")
                                               (nogauge)
                                    )
                                   )
)

(complete 40)

(if (exists "LIBS:ReqTools.library") ((set #ver1 (getversion "LIBS:ReqTools.library"))
                                      (set #ver2 (getversion "Libs/ReqTools.library"))
                                      (if (< #ver1 #ver2) ((working "Copying ReqTools.library...")
                                                           (copyfiles (source "Libs/ReqTools.library")
                                                                      (dest "LIBS:")
                                                                      (nogauge)
                                                           )
                                                          )
                                      )
                                     )
                                     ((working "Copying ReqTools.library...")
                                      (copyfiles (source "Libs/ReqTools.library")
                                                 (dest "LIBS:")
                                                 (nogauge)
                                      )
                                     )
)

(complete 50)

(set #BK )
(if (NOT (exists "Doors:BK")) (makedir "Doors:BK"))
(makedir "Doors:BK/SysdudeSend")

(complete 70)

(working "Copying \"SS.xim\"...")
(copyfiles (source "BBS/Doors/BK/SysdudeSend/SS.xim")
           (dest "Doors:BK/SysdudeSend/")
           (nogauge)
)
(working "Copying \"Config.info\"...")
(copyfiles (source "BBS/SS.info")
           (dest "Doors:BK/SysdudeSend/")
           (newname "Config.info")
           (nogauge)
)

(working "Setting tooltypes...")
(if (= #ecf 0) (set #tt_ecf "(EXTRACONFIRM)") (set #tt_ecf "EXTRACONFIRM"))
(if (AND (= #req 0) (= #dpf 0)) (set #tt_req "(REQUESTER)" #tt_dpf "(DISPLAYFILES)" #tt_psw "PSW"))
(if (AND (= #req 0) (= #dpf 1)) (set #tt_req "(REQUESTER)" #tt_dpf "DISPLAYFILES"  #tt_psw "PSW"))
(if (AND (= #req 1) (= #dpf 0)) (set #tt_req "REQUESTER" #tt_dpf "(DISPLAYFILES)" #tt_psw "(PSW" #psw "666)"))
(if (AND (= #req 1) (= #dpf 1)) (set #tt_req "REQUESTER" #tt_dpf "DISPLAYFILES" #tt_psw "(PSW" #psw "666)"))
(tooltype (dest "Doors:BK/SysdudeSend/Config")
          (settooltype #tt_ecf "")
          (settooltype "PACKERPATH" #ppt)
          (settooltype #tt_dpf "")
          (settooltype #tt_req "")
          (settooltype #tt_psw #psw)
)

(complete 80)

(working "Copying AmigaGuide docs...")
(copyfiles (source "Docs/SS.guide")
           (dest "Doors:BK/SysdudeSend/")
           (nogauge)
)

(complete 90)

(working "Showing AmigaGuide docs...")
(run "C/AmigaGuide Doors:BK/SysdudeSend/SS.guide")

(complete 100)

(exit #normal_exit (quiet))
