;;;
;
;   MapleVr3 INSTALLATION SCRIPT - USE WITH INSTALLER TOOL
;
;;;
;
;   For debugging;
;
(set debugging 0)
;
;   Disable novice mode.  A Tool Type also blocks this.
;   Novice is TOO novice. Can not even use (askbool).
;
(if (= @user-level 0)
    (abort "\n\nDue to the large size of the Maple V Release 3 distribution, "
           "\"Novice\" mode is not supported: in novice mode the "
           "installation would copy more than 20 MBytes of files to an "
           "arbitrary location on your hard drive. There are several "
           "installation options that will need your input.")
)
;
;   Set variables for the locations of everything.  This should be roughly
;   the order of installation, too, if possible.
;
(set     help-loc "Maple.1:")
(set     bino-loc "Maple.2:")
(set     bin8-loc "Maple.2:")
(set     bini-loc "Maple.3:")
(set      afm-loc "Maple.3:")
(set examples-loc "Maple.3:")
(set    fonts-loc "Maple.4:")
(set      ind-loc "Maple.4:")
(set     misc-loc "Maple.4:")
(set tutorial-loc "Maple.4:")
(set   share1-loc "Maple.4:")
(set   share2-loc "Maple.5:")
(set   share3-loc "Maple.6:")
(set   share4-loc "Maple.7:")
(set     lib1-loc "Maple.7:")
(set     lib2-loc "Maple.8:")
(set     lib3-loc "Maple.9:")
;
;   Set variables for the locations of everything.
;
(set     help-name "help.rez")
(set      afm-name "afm.rez")
(set examples-name "examples.rez")
(set    fonts-name "fonts.rez")
(set      ind-name "ind.rez")
(set     misc-name "misc.rez")
(set tutorial-name "tutorial.rez")
(set     bin8-name "bin881.rez")
(set     bini-name "binieee.rez")
(set     bino-name "binother.rez")
(set   share1-name "share.rez.1")
(set   share2-name "share.rez.2")
(set   share3-name "share.rez.3")
(set   share4-name "share.rez.4")
(set     lib1-name "lib.rez.1")
(set     lib2-name "lib.rez.2")
(set     lib3-name "lib.rez.3")
;
(set       rezlog ">\"con:0/0/640/200/Unrez Output/INACTIVE\"")
;
;   Set variables for the sizes of the installation blocks
;
(set     help-size  3300)
(set      afm-size   300)
(set examples-size   300)
(set    fonts-size  2100)
(set      ind-size   500)
(set     misc-size   100)
(set tutorial-size   200)
(set      bin-size  3500)
(set    share-size  6400)
(set      lib-size 10100)
;
;   Copyright notices.
;
(message
    "\n"
    "All files in the distribution are:\n"
    "Copyright © 1995, Waterloo Maple Software\n"
    "All rights reserved\n\n"
    "With the exception of:\n\n"
    "Amigaguide.library, asl.library, Installer and Installer.info: "
    "Copyright © 1991-93, "
    "Commodore Business Machines, Inc., "
    "All Rights Reserved.\n"
    "Reproduced and distributed under license.\n\n"
    "Unrez: Copyright © 1995, Radical Eye Software\n"
    "All rights reserved. Used by permission."
)

(complete 0)
;
;   Is there a math coprocessor?
;
(set SYSFPU (run "cpu check fpu" (safe)))
(if (= SYSFPU 0)
    (set SYSFPU 1)  ;=="cpu check fpu" RC=0 means FPU=True
    (set SYSFPU 0)  ;=="cpu check fpu" RC=5 means FPU=False
)
;
;   Store any existing maple: assigns
;
(set maple-save (getassign "maple"      "a"))
;
;   Copy unrez to ram:
;
(set copy-prompt "Copying dearchiver to RAM:")
;
;   Get unrez
;
(if (= debugging 1)
   (debug "Copying Maple.1:c/unrez to ram:")
; else
   (copyfiles
      (source "Maple.1:c/unrez")
      (dest "RAM:")
   )
)
;
;   Cleanup on error
;
(onerror
   (if (= debugging 1)
      (debug "Deleting ram:mapletemp and unrez")
   ; else
      (
         (if (exists "c:delete")
            (run "c:delete quiet ram:mapletemp all force")
         ; else
            (run "delete quiet ram:mapletemp all force")
         )
         (delete "RAM:unrez")
      )
   )
)
;
;   Create the default destination name
;
(if maple-save
   ((set maple-present 1) (set maple-dest maple-save))
; else
   ((set maple-present 0) (set maple-dest @default-dest))
)
;
;   Ask for the destination
;
(if (= maple-present 1)
   (
      (set choice
         (askbool
            (prompt "It looks like there is already a version of Maple "
                    "installed on your system. Would you like to install "
                    "Maple or Maple components in the same place?"
            )
            (help   "If the version in the Maple: directory is Maple V Release 3 "
                    "and you want to reinstall or add components, click on \"Yes\". "
                    "If you want to choose a different location, click on \"No\"."
            )
         )
      )
      (if (= choice 0) ((set maple-present 0) (set maple-dest @default-dest)) )
   )
)
;
;   Ask for directory if needed
;
(if (= maple-present 0)
   (
      (set maple-dest
         (askdir
            (prompt "Where should the Maple drawer be created?")
            (help @askdir-help)
            (default maple-dest)
         )
      )
   )
)
;
;   Check for null string.
;
(if (= maple-dest "")
   (set maple-dest @default-dest)
)
;
;   Find out available disk space.
;
(set disk-avail (getdiskspace maple-dest))
;
;   Now set the proper maple drawer destination
;   and check if there's a directory there already, and warn.
;
(if (= maple-present 0)
   (
      (set maple-dest (tackon maple-dest "Maple"))

      (if (exists maple-dest)
         (
            (set choice
               (askbool
                  (prompt "\nIt appears that you already have a version of Maple "
                            "installed in the selected directory. If it is an older "
                            "version of Maple, you should probably delete or move it, "
                            "before installing the new version, in order to avoid "
                            "mixing old and new files. You should continue this "
                            "installation ONLY if you are reinstalling or updating "
                            "Maple V Release 3 or parts of it.\n\nAre you sure you want to "
                            "continue?"
                  )
                  (help     "If the version in the selected directory is Maple V Release 3 "
                            "and you want to reinstall or add components, click on "
                            "\"Yes\". "
                            "Otherwise you should abort the current installation, "
                            "move or delete your old version of Maple, and run this "
                            "installation again when you are ready."
                  )
                  (default 0)
               )
            )

            (if (= choice 0) ( (delete "ram:unrez") (EXIT) ))
         )
      )
   )
)

(set @default-dest maple-dest)
;
;   Set default dest vars
;
(set     help-dest (tackon maple-dest "help"))
(set      afm-dest (tackon maple-dest "afm"))
(set      tex-dest (tackon maple-dest "tex"))
(set examples-dest (tackon maple-dest "examples"))
(set    fonts-dest (tackon maple-dest "fonts"))
(set      ind-dest (tackon maple-dest "lib"))
(set tutorial-dest (tackon maple-dest "tutorial"))
(set      bin-dest (tackon maple-dest "bin"))
(set    share-dest (tackon maple-dest "share"))
(set      lib-dest (tackon maple-dest "lib"))
;
;   A message about space
;
(message "\nA full Maple V Release 3 installation of all programs and "
           "support files will require approximately 27 MBytes of "
           "disk space. "
           "The next requester will let you choose which "
           "components of the distribution you want intstalled. "
           "You may skip certain parts at this time, and run the "
           "installer again later to install other parts. Parts that are "
           "required for a first-time installation are clearly labelled. "
           "Consult the help associated with the requester if you are "
           "uncertain about which parts to install."
)
;
;   Ask about the various components.
;
(set install-mask 1023)

(set install-mask
   (askoptions
      (prompt "Maple V Release 3 Components. Items marked with a * are "
              "required for a first-time installation:")
      (help   
              "\nThe Maple executables (MapleView, Maple itself, "
              "and various graphics drivers including MaplePlot) "
              "are required for a first-time installation. They "
              "take up about " ("%ld" bin-size) " kBytes."
              "\n"
              "\nThe Fonts and AFM files are required for normal "
              "Maple operation when using the graphical user "
              "interface. They are also needed for MaplePlot and "
              "for printing. They take up about " ("%ld" (+ fonts-size afm-size))
              " kBytes."
              "\n"
              "\nThe Maple Index file is required for Maple operation. "
              "It contains the locations of all functions in the Maple "
              "Library. It uses about " ("%ld" ind-size) " kBytes of space."
              "\n"
              "\nThe Maple Library file is required for Maple operation. "
              "It contains most of the Maple functions. "
              "It uses about " ("%ld" lib-size) " kBytes of space."
              "\n"
              "\nThe Online-Help files are not required for Maple"
              "operation, but they do contain the full documentation"
              "for the Maple release. Installation is strongly recommended."
              "It takes up about " ("%ld" help-size) " kBytes of space."
              "\n"
              "\nThe Examples are not required for Maple operation. "
              "There are various different examples that "
              "may help you learn about worksheets. They also present "
              "some nice examples of the types of things Maple can do. "
              "It uses about " ("%ld" examples-size) " kBytes of space."
              "\n"
              "\nThe Tutorial is not required for Maple operation. "
              "However, it gives you a guided tour of the basic way "
              "Maple works, and may be helpful if you are a first-time "
              "Maple user. "
              "It uses about " ("%ld" tutorial-size) " kBytes of space."
              "\n"
              "\nThe Share library is a large collection of "
              "user-written functions and examples. It is not required "
              "for Maple operation. It contains, however, a "
              "number of packages that complement the ones "
              "already present in the main Maple library. "
              "It uses about " ("%ld" share-size) " kBytes of space."
              "\n"
              "\nThe miscellaneous files are necessary for proper "
              "maple operation. They use about " ("%ld" misc-size)
              " kBytes of space."
      )
      (choices
              "*Maple Executables"
              "*Fonts"
              "*Font AFM files"
              "*Maple Index file"
              "*Maple Library"
              " Online Help files"
              " Examples"
              " Tutorial"
              " Share library"
              "*Miscellaneous files"
      )
      (default install-mask)
   )
)
;
;   Compute total size to be installed
;
(set tot-size 0)
(if (IN install-mask 0)   (set tot-size (+ tot-size bin-size)))
(if (IN install-mask 1)   (set tot-size (+ tot-size fonts-size)))
(if (IN install-mask 2)   (set tot-size (+ tot-size afm-size)))
(if (IN install-mask 3)   (set tot-size (+ tot-size ind-size)))
(if (IN install-mask 4)   (set tot-size (+ tot-size lib-size)))
(if (IN install-mask 5)   (set tot-size (+ tot-size help-size)))
(if (IN install-mask 6)   (set tot-size (+ tot-size examples-size)))
(if (IN install-mask 7)   (set tot-size (+ tot-size tutorial-size)))
(if (IN install-mask 8)   (set tot-size (+ tot-size share-size)))
(if (IN install-mask 9)   (set tot-size (+ tot-size misc-size)))
;
;   Is there enough disk space?
;
(set space-ok 0)
(if (< (* tot-size 1000) disk-avail)
   (set space-ok 1)
)
;
;   If there's not enough space, abort.
;
(if (= space-ok 0)
   (abort "\n\nYou have selected "
          ("%ld" tot-size)
          " kBytes for installation; the destination disk has "
          ("%ld" (/ disk-avail 1000))
          " kBytes available; there is therefore insufficient space. "
          "Please check your hard disk(s), "
          "create some space if necessary, and run "
          "the installation procedure again. "
   )
)
;
;   If we haven't selected anything, abort.
;
(if (= tot-size 0)
   (abort "\n\nYou have selected nothing to install!")
)
;
;   Install stuff.
;
(message "\nDuring the installation of the various files, you "
         "will be prompted for Maple disks as they become "
         "necessary."
)

(set done-size 0)
(set do-readme 0)
;
;   Create the directory and all subdirectories, if they don't exist yet.
;
(if (not (exists    maple-dest)) (makedir    maple-dest (infos)))
(tooltype (dest     maple-dest) (noposition))

(if (not (exists     help-dest)) (makedir     help-dest (infos)))
(tooltype (dest      help-dest) (noposition))

(if (not (exists      afm-dest)) (makedir      afm-dest ))

(if (not (exists examples-dest)) (makedir examples-dest (infos)))
(tooltype (dest  examples-dest) (noposition))

(if (not (exists      tex-dest)) (makedir      tex-dest ))

(if (not (exists    fonts-dest)) (makedir    fonts-dest ))

(if (not (exists      ind-dest)) (makedir      ind-dest ))

(if (not (exists tutorial-dest)) (makedir tutorial-dest (infos)))
(tooltype (dest  tutorial-dest) (noposition))

(if (not (exists      bin-dest)) (makedir      bin-dest (infos)))
(tooltype (dest       bin-dest) (noposition))

(if (not (exists    share-dest)) (makedir    share-dest (infos)))
(tooltype (dest     share-dest) (noposition))

(if (not (exists      lib-dest)) (makedir      lib-dest ))

(if (IN install-mask 5)
   (
      (set runstr ("RAM:unrez %s/ %s %s" maple-dest (tackon help-loc help-name)
                                                   rezlog))

      (working "\nUncompressing and installing help files...")

      (if (= debugging 1)
         (debug runstr)
      ; else
         (run runstr
             (confirm) 
             (prompt ("\n\n\nCopy help files to %s?" help-dest))
             (help "")
         )
      )
      (if (= debugging 1)
         (
            (debug "Copying README")
            (set do-readme 1)
         )
      ; else
         (
            (copyfiles
               (source (tackon help-loc "README"))
               (dest maple-dest)
               (optional)
               (infos)
            )
            (set do-readme 1)
         )
      )

      (set done-size (+ done-size help-size))

      (complete (/ (* done-size 100) tot-size))
   )
)

(set ask-asl 0)

(if (IN install-mask 0)
   (
      (working "\nUncompressing and installing executables...")

      (set runstr ("RAM:unrez %s/ %s %s" maple-dest
                      (tackon bino-loc bino-name) rezlog))

      (if (= debugging 1)
         (debug runstr)
      ; else
         (run runstr
            (confirm) 
            (prompt ("\n\n\nCopy various executables to %s?" bin-dest))
            (help "")
         )
      )

      (set ask-asl 1)
;
;   Ask for which maple CPU version
;
      (if (= @user-level 2)
         (
            (set fpu881 0)
            (set fpuieee 0)

            (if (= SYSFPU 1)
               ((set fpustr "a" ) (set fpu881  1))
            ;else
               ((set fpustr "no") (set fpuieee 1))
            )
   
            (set choice
               (askbool
                  (prompt "The main Maple excutables come in two versions, one version "
                          "for systems with at least a 68020 CPU and a math coprocessor, "
                          "and the other version for systems with a 68000 CPU or no "
                          "math coprocessor. It looks like your system has " fpustr
                          " math coprocessor. Would you like to install both versions "
                          "anyway?"
                  )
                  (help   "If you answer \"no\", the version appropriate for your system "
                          "will be installed. If you answer \"yes\", both versions "
                          "will be installed."
                  )
               )
            )
         )
      ;else
         (
            (set choice 1)
         )
      )

      (if (= choice 1) ((set fpu881 1) (set fpuieee 1)) )

      (working "\nUncompressing and installing more executables...")

      (if (= fpu881 1)
         (
            (set runstr ("RAM:unrez %s/ %s %s" maple-dest
                            (tackon bin8-loc bin8-name) rezlog))

            (if (= debugging 1)
               (debug runstr)
            ; else
               (run runstr
                  (confirm) 
                  (prompt ("\n\n\nCopy binaries for math coprocessor systems to %s?" bin-dest))
                  (help "")
               )
            )
         )
      )

      (if (= fpuieee 1)
         (
            (set runstr ("RAM:unrez %s/ %s %s" maple-dest
                            (tackon bini-loc bini-name) rezlog))

            (if (= debugging 1)
               (debug runstr)
            ; else
               (run runstr
                  (confirm) 
                  (prompt ("\n\n\nCopy binaries for systems without math coprocessor to %s?" bin-dest))
                  (help "")
               )
            )
         )
      )

      (set done-size (+ done-size bin-size))

      (complete (/ (* done-size 100) tot-size))
   )
)


(if (IN install-mask 2)
   (
      (set runstr ("RAM:unrez %s/ %s %s" maple-dest (tackon afm-loc afm-name)
                                    rezlog))

      (working "\nUncompressing and installing font AFM files...")

      (if (= debugging 1)
         (debug runstr)
      ; else
         (run runstr
            (confirm) 
            (prompt ("\n\n\nCopy font AFM files to %s?" afm-dest))
            (help "")
         )
      )

      (set done-size (+ done-size afm-size))

      (complete (/ (* done-size 100) tot-size))
   )
)

(if (IN install-mask 6)
   (
      (set runstr ("RAM:unrez %s/ %s %s" maple-dest
                        (tackon examples-loc examples-name) rezlog))

      (working "\nUncompressing and installing examples...")

      (if (= debugging 1)
         (debug runstr)
      ; else
         (run runstr
            (confirm) 
            (prompt ("\n\n\nCopy examples to %s?" examples-dest))
            (help "")
         )
      )

      (set done-size (+ done-size examples-size))

      (complete (/ (* done-size 100) tot-size))
   )
)

(if (IN install-mask 1)
   (
      (working "\nUncompressing and installing fonts...")

      (if (= debugging 1)
         (debug "Deleting old fonts")
      ; else
         (
            (if (exists "c:delete")
               (set runstr "c:delete fonts:maple#? all quiet force")
            ; else
               (set runstr "delete fonts:maple#? all quiet force")
            )
            (run runstr
               (confirm)
               (prompt "\n\n\nDelete obsolete maple fonts in fonts:?")
               (help "Old maple fonts can cause problems.")
            )
            (if (exists "c:delete")
               (set runstr ("c:delete %s all quiet force" (tackon fonts-dest "Maple#?")))
            ; else
               (set runstr ("delete %s all quiet force" (tackon fonts-dest "Maple#?")))
            )
            (run runstr
               (confirm)
               (prompt "\n\n\nDelete obsolete maple fonts in " fonts-dest "?")
               (help "Old maple fonts can cause problems.")
            )
         )
      )

      (set runstr ("RAM:unrez %s/ %s %s" maple-dest
             (tackon fonts-loc fonts-name) rezlog))

      (if (= debugging 1)
         (debug runstr)
      ; else
         (run runstr
            (confirm) 
            (prompt ("\n\n\nCopy fonts to %s?" fonts-dest))
            (help "")
         )
      )

      (set done-size (+ done-size fonts-size))

      (complete (/ (* done-size 100) tot-size))
   )
)

(if (IN install-mask 3)
   (
      (set runstr ("RAM:unrez %s/ %s %s" maple-dest (tackon ind-loc ind-name)
                              rezlog))

      (working "\nUncompressing and installing index...")

      (if (= debugging 1)
         (debug runstr)
      ; else
         (run runstr
            (confirm) 
            (prompt ("\n\n\nCopy index file to %s?" ind-dest))
            (help "")
         )
      )

      (set done-size (+ done-size ind-size))

      (complete (/ (* done-size 100) tot-size))
   )
)

(if (IN install-mask 9)
   (
      (set runstr ("RAM:unrez ram:mapletemp/ %s %s" (tackon misc-loc misc-name)
                                      rezlog))

      (working "\nUncompressing and installing miscellaneous files...")

      (if (not (exists "ram:mapletemp")) (makedir "ram:mapletemp"))

      (if (= debugging 1)
         (debug runstr)
      ; else
         (run runstr)
      )

      (if (= debugging 1)
         (debug "copying MapleVR3.info")
      ; else
         (copyfiles
            (source "ram:mapletemp/MapleVR3.info")
            (dest maple-dest)
            (prompt ("\n\n\nCopy MapleVR3.info to %s?" maple-dest))
	    (help "Copies the MapleVR3 icon")
            (confirm)
            (optional)
         )
      )

      (if (= debugging 1)
         (debug "copying MapleView.info to Maple:bin")
      ; else
         (copyfiles
            (source "ram:mapletemp/MapleView.info")
            (dest bin-dest)
            (prompt ("\n\n\nCopy MapleView.info to %s?" bin-dest))
	    (help "Copies the MapleView icon")
            (confirm)
            (optional)
         )
      )

      (if (= debugging 1)
         (debug "copying texfiles to Maple:tex")
      ; else
         (copyfiles
            (source "ram:mapletemp/tex")
            (dest tex-dest)
            (prompt "Copy TeX files to Maple:tex?")
	    (help "Copies the TeX files")
            (confirm)
            (optional)
	    (all)
         )
      )

      (set done-size (+ done-size misc-size))

      (complete (/ (* done-size 100) tot-size))
   )
)

(if (IN install-mask 7)
   (
      (set runstr ("RAM:unrez %s/ %s %s" maple-dest
            (tackon tutorial-loc tutorial-name) rezlog))

      (working "\nUncompressing and installing tutorial...")

      (if (= debugging 1)
         (debug runstr)
      ; else
         (run runstr
            (confirm) 
            (prompt ("\n\n\nCopy tutorial to %s?" tutorial-dest))
            (help "")
         )
      )

      (set done-size (+ done-size tutorial-size))

      (complete (/ (* done-size 100) tot-size))
   )
)

(if (IN install-mask 8)
   (
      (set runstr ("RAM:unrez %s/ %s %s %s %s %s" maple-dest
            (tackon share1-loc share1-name)
            (tackon share2-loc share2-name) (tackon share3-loc share3-name)
            (tackon share4-loc share4-name) rezlog))

      (working "\nUncompressing and installing Share library...")

      (if (= debugging 1)
         (debug runstr)
      ; else
         (run runstr
            (confirm) 
            (prompt ("\n\n\nCopy Share library to %s?" share-dest))
            (help "")
         )
      )

      (set done-size (+ done-size share-size))

      (complete (/ (* done-size 100) tot-size))
   )
)

(if (IN install-mask 4)
   (
      (set runstr ("RAM:unrez %s/ %s %s %s %s" maple-dest (tackon lib1-loc lib1-name)
                              (tackon lib2-loc lib2-name)
                              (tackon lib3-loc lib3-name) rezlog))

      (working "\nUncompressing and installing library...")

      (if (= debugging 1)
         (debug runstr)
      ; else
         (run runstr
            (confirm) 
            (prompt ("\n\n\nCopy Maple library file to %s?" lib-dest))
            (help "")
         )
      )

      (set done-size (+ done-size lib-size))

      (complete (/ (* done-size 100) tot-size))
   )
)

(complete 99)
;
;   Patch User-Startup
;
(set MapleAssigns
   ("Assign Maple: %s\nAssign fonts: Maple:fonts add\nPath Maple: add\nPath Maple:bin add\n" maple-dest)
)

(startup
   "Waterloo Maple Software"
   (prompt  "\nThe following commands are recommended for your "
            "User-Startup file:\n\n"
            MapleAssigns
            "\n\nWould you like them appended now?"
   )
   (help
            "Without these commands in your startup, Maple V Release 3 "
            "may not work properly!\n\n"
            @startup-help
   )
   (command MapleAssigns)
)
;
;   Install newer version of ASL.library.
;
(if (= ask-asl 1)
   (if (= debugging 1)
      (
         (debug "Checking asl.library and copying if newer.")
      )
   ; else
      (copylib
         (prompt "In order to be able to select screen modes, "
                 "Maple needs the asl.library that comes with version 2.1 "
                 "(or newer) of AmigaDOS. Should the 2.1 version be copied?"
         )
         (help   "")
         (source (tackon maple-dest "libs/asl.library"))
         (dest   "libs:")
         (confirm)
         (optional nofail force)
      )
   )
)
;
;   See if the user wants to set up the assignments now
;
(if (= @user-level 2)
   (set AssignNow
      (askbool
         (prompt "\nWould you like the required assignments made now?\n")
         (help @askbool-help)
      )
   )
;else
   (set AssignNow 1)
)


(if (= AssignNow 1)
   (
      (if (<> @pretend 1) (makeassign "Maple" maple-dest))
      (if (exists "c:assign")
         (run "c:assign fonts: Maple:fonts add")
      ; else
         (run "assign fonts: Maple:fonts add")
      )
   )
)

(if (= do-readme 1)
   (if (= debugging 1)
      (debug "Running more maple:readme")
   ;else
      (if (exists "c:run")
         (run "c:run >nil: <nil: sys:utilities/more maple:readme")
      ; else
         (run "run >nil: <nil: sys:utilities/more maple:readme")
      )
   )
)

(if (= debugging 1)
   (debug "Deleting ram:mapletemp")
; else
   (
      (if (exists "c:delete") 
         (run "c:delete quiet ram:mapletemp all force")
      ; else
         (run "delete quiet ram:mapletemp all force")
      )
      (delete "RAM:unrez")
   )
)

(complete 100)
(EXIT)

