;****************************************************************************;
;                                                                            ;
; $VER: SLIPCall_Installation 4.0b (5.11.95)                                 ;
;                                                                            ;
;  1995 Thomas Egrelius                                                     ;
;                                                                            ;
; egge@canit.se  /  thomas@fotoslide.bmc.uu.se                               ;
;                                                                            ;
;****************************************************************************;

(procedure :askdestination
    (set #destination
        (askdir
            (prompt "Where would you like to put SLIPCall 4.0?\n"
                    "A drawer will be created.")
            (help   @askdir-help)
            (default "SYS:")
        )
    )
)

(procedure :checksana
    (if (<> (exists "ENVARC:Sana2" (noreq)) 2)
        (makedir "ENVARC:Sana2")
    )
)

(procedure :askdefault
    (set #default
        (askchoice
            (prompt "Which provider do you use?")
            (help   "A predefined configuration will be saved "
                    "for your provider.\n\n"
                    "This file (PROGDIR:config/SLIPCall.config) will be used by SLIPCall "
                    "when no argument for configuration is submitted.")
            (choices "CanIt AB (SLIP/CSLIP)"
                     "Canit AB (PPP)"
                     "Algonet AB"
                     "ABC Klubben"
                     "Oden Telecom"
                     "University of Uppsala (SLIP/CSLIP)"
                     "University of Uppsala (PPP)"
                     "Kuai Connection (static)"
                     "Kuai Conection (dynamic)"
                     "Other")
            (default 9)
        )
    )
)



; -------------------------------------
; main()
; -------------------------------------

(complete 0)

(message "Welcome to the installation of SLIPCall 4.0!\n\n")

(:askdestination)

(makedir (tackon #destination "SLIPCall") (infos))

(copyfiles
    (source "")
    (dest (tackon #destination "SLIPCall"))
    (pattern "~(Install#?|#?.library)")
)

(copylib
    (source "bgui.library")
    (dest "LIBS:")
)

(complete 40)

(:askdefault)

(if (= #default 0) (set #defaultstr "CanIt.config"))
(if (= #default 1) (set #defaultstr "CanItPPP.config"))
(if (= #default 2) (set #defaultstr "Algonet.config"))
(if (= #default 3) (set #defaultstr "ABC.config"))
(if (= #default 4) (set #defaultstr "Oden.config"))
(if (= #default 5) (set #defaultstr "UU.config"))
(if (= #default 6) (set #defaultstr "UUPPP.config"))
(if (= #default 7) (set #defaultstr "KuaiStatic.config"))
(if (= #default 8) (set #defaultstr "KuaiDynamic.config"))
(if (= #default 9) (set #defaultstr "SLIPCall.config"))

(copyfiles
    (source "config/")
    (dest (tackon (tackon #destination "SLIPCall") "config"))
    (pattern "~(SLIPCall.config)")
    (nogauge)
)

(copyfiles
    (source (cat "config/" #defaultstr))
    (dest   (tackon (tackon #destination "SLIPCall") "config"))
    (newname "SLIPCall.config")
    (nogauge)
)

(complete 80)

(if (=
    (askbool
        (prompt "Do you use Phonebill?\n\nIf you do, you should upgrade "
                "your scanner.config. The format of SLIPCall's logfile "
                "has changed.")
        (help   "If you answer 'Yes', installer will check if you have a"
                " scanner for SLIPCall installed. If not, one will be installed.")
    )
    1)
    (
        (set #scanner
            (askfile
                (prompt "Choose the 'Scanner.config' used by Phonebill.")
                (help   @askfile-help)
                (default "SYS:")
            )
        )
        (if (run (cat "search " #scanner " SLIPCall"))
            ((textfile
                (dest "T:InstallerTemp")
                (include #scanner)
                (include "Extras/phonebill.scanner"))
            (copyfiles
                (source "T:InstallerTemp")
                (dest   (pathonly #scanner))
                (newname "Scanner.config"))
            (delete "T:InstallerTemp")))))

(set @default-dest #destination)
(complete 100)
(message "Installation of SLIPCall 4.0 is finnished!\n\n"
         "You can find it in " #destination)

(exit (quiet))

