;
; $VER: install 34.1 (10 Jun 1995)
;
; Installer script for exec-handler package.
;
; (C) Copyright 1995 Marius Gröger
;     All Rights Reserved.
;
; $HISTORY:
;
; 25 Jun 1995 : 034.001 :  initial
;

(set cpu (database "cpu"))
(set level @user-level)
(set #handler       "exec-handler")
(set #handler-mount "EXEC")
(set #helpfile      "Exec-Handler.guide")

; (The installer documentation says not to use this call inside
; distribtions, but I know no way to let the next decision
; popping up in novice mode. If you do, please mail to
; mag@sysgo.de. Thanks.)
(user 2)
(set mode
     (askchoice
         (prompt @app-name)
         (choices "Install" "Remove")
         (help (cat "  Select here wether to install or to remove the " #app-name " package."
                    "\n\n  The installation procedure will copy the handler file, a DOSDriver "
                    "and an AmigaGuide® on-line documentation, requesting your confirmation "
                    "for each file."
                    "\n\n  The removal procedure will try to delete any files from your system "
                    "which are related to the package. However, due to the high flexibility "
                    "of AmigaOS, it may not find them all if some are at unusual places. "
                    "If this is the case, though, you will be experienced enough to remove "
                    "them yourself."))
     )
)
(user level)

; get handler dir
(set handlerdir
        (askdir
                (prompt "Please locate the directory for handlers:")
                (help @askdir-help)
                (default "L:")
        )
)

; get permanent dosdriver dir
(set dosdir_perm
        (askdir
                (prompt "Please locate the directory for permanently mounted DOS-drivers:")
                (help (cat "  Select here the directory, where you keep those DOS-drivers "\
                           "that you want to have automatically mounted on system startup. "\
                           "This is DEVS:DOSDrivers directory unless you have modified the 'Mount' "\
                           "statement in your startup-sequence.\n\n"
                           @askdir-help
                      )
                )
                (default "DEVS:DOSDrivers")
        )
)

; get storage dosdriver dir
(set dosdir_stor
        (askdir
                (prompt "Please locate the directory for rarely used DOS-drivers:")
                (help (cat "  Select here the directory, where you keep those DOS-drivers "\
                           "that you want to use more rarely, mounting them explicitely "\
                           "from the AmigaShell or Workbench. This is the SYS:Storage/DOSDrivers "\
                           "directory for standard Amiga systems.\n\n"
                           @askdir-help
                      )
                )
                (default "SYS:Storage/DOSDrivers")
        )
)

(user 2)
(if (= mode 0)
   (
      (set perm
         (askchoice (prompt "Do you want to have the EXEC: device mounted always, or do you rather "\
                          "like to mount it explicitely from AmigaShell or Workbench ?")
                    (choices "Mount it always" "Only on demand")
                    (help (cat "  Select here wether to copy the EXEC DOS-driver into the "\
                               "system drawer that holds the permanent DOS-drivers or "
                               "the one keeping those drivers you can activate using "
                               "the 'Mount' command from AmigaShell or a double-click "\
                               "from Workbench.\n\n"\
                               "  Note that the EXEC icon has set the tooltype 'ACTIVATE' "\
                               "set to 0, which tells AmigaDOS to defer the actual loading "\
                               "of the handler-code until the first usage. Therefore "\
                               "you only loose some memory for the AmigaDOS-internal "\
                               "representation of the DOS-driver, if you don't use it.\n\n"
                               @askchoice-help
                          )
                    )
         )
      )
      (set perm (- 1 perm))   ; invert value to make usage more intuitive
   )
)
(user level)

; get dosdriver dir
(set helpdir
        (askdir
                (prompt "Please locate the directory for AmigaGuide®-Documents:")
                (help (cat "   Select here the directory where you keep your "\
                           "AmigaGuide® online documents.\n\n"
                            @askdir-help
                      )
                )
                (default "HELP:english")
        )
)

; now do install or remove
(if mode
        ; Remove
        (
                ; Show what we are doing
                (working "Removing " @app-name)

                ; Remove the non-standard pieces
                (set delfile (tackon handlerdir #handler))
                  (if (exists delfile) (delete delfile))

                (set delfile (tackon "L:" #handler))
                  (if (exists delfile) (delete delfile))

                (set delfile (tackon dosdir_perm #handler-mount))
                  (if (exists delfile) (delete delfile (cat delfile ".info")))

                (set delfile (tackon "DEVS:DOSDrivers" #handler-mount))
                  (if (exists delfile) (delete delfile (cat delfile ".info")))

                (set delfile (tackon "SYS:Storage/DOSDrivers" #handler-mount))
                  (if (exists delfile) (delete delfile (cat delfile ".info")))

                (set delfile (tackon helpdir #helpfile))
                  (if (exists delfile) (delete delfile (cat delfile ".info")))

                (set delfile (tackon "HELP:english" #helpfile))
                  (if (exists delfile) (delete delfile (cat delfile ".info")))

                ; Don't want to use the confusing "Installation Complete" message
                ; when what we really did was remove things...
                (message "The \"" @app-name "\" package has been removed")
                (exit (quiet))
        )

        ; Install
        (
                (working "Installing " @app-name)

                ; choose cpu type
                (set proc
                  (askchoice
                     (prompt (cat "There are diffent versions of \"" #handler "\", each one optimized "
                                  "for a specific CPU type. Please select one: "))
                     (choices "MC68000" "MC68020" "MC68040")
                     (help (cat "  Select here the CPU type that is installed in your system. "
                           "\n\n  Currently, this is a MC" cpu ".\n\n  If you select a certain CPU type "
                           "in the choice box, the \"" #handler "\" will run on any CPU which "
                           "type is higher or equal to the selection. However, it won't "
                           "run on a system equipped with a lower type.\n\n"
                           @askchoice-help)
                     )
                     (default 0)
                  )
                )

                (copylib
                        (prompt (cat "Copying the handler"))
                        (help @copylib-help)
                        (source (cat (tackon "l" #handler)
                                   (if (= 0 proc) ".000")
                                   (if (= 1 proc) ".020")
                                   (if (= 2 proc) ".040")
                        ))
                        (dest handlerdir)
                        (newname #handler)
                        (confirm)
                )

                (run (cat "delete >NIL: t:" #handler))

                ; Install the descriptors
                (copyfiles
                        (prompt "Copying the DOS-driver")
                        (help @copyfiles-help)
                        (source "devs/DOSDrivers")
                        (dest (if perm dosdir_perm dosdir_stor))
                        (pattern (cat #handler-mount "(%|.info)"))
                        (confirm)
                )

                ; install AmigaGuide file
                (copyfiles
                        (prompt "Copying AmigaGuide file")
                        (help @copyfiles-help)
                        (source "help")
                        (dest helpdir)
                        (pattern (cat #helpfile "(%|.info)"))
                        (confirm)
                )
                ; The standard "Installation Complete" message isn't very appropriate
                ; for the installation of a handler.
                (message "The \"" @app-name "\" package has been installed.\n\n"
                       "Depending on where you installed it, type \"mount EXEC:\", "
                       "or reboot the system, or double-click on the icon "
                       "in order to use the new exec-handler"
                )
                (exit (quiet))
        )
)

