; Copyright 1994 AugmenTek

(complete 0)

(transcript "On installing MultiVol, v1.01D")

(set @default-dest "Work:")

(set centered_title "                 MultiVol(TM) Demo")

(set assign_name "MVOLD"
     @@default-dest (cat assign_name ":"))


(if (NOT (exists @@default-dest (noreq)))
   (
     (set @@default-dest "Work:")
     (set default_exists 0)
   )
   (
    (set default_exists 1)
    ; Get the value so that later Assign works properly.  The Assign
    ; is done since the startup command will overwrite the old stuff.

    (set install_dest (expandpath @@default-dest))
   )
)

(welcome (cat centered_title "\n"))

(if (= default_exists 0)
  (
   (set install_dest 
      (askdir  
         (prompt 
            (cat "Select where you want to " 
                 "install the " assign_name " directory:\n"
                 "(Do not use MVD: as an assign name)"
            )
         )
         (default @@default-dest)
         (help "Choose a destination volume name or directory " 
               "in which to place the installation files. "
               (cat "A directory called '" assign_name "' ")
               "will be created in the location you choose and"
               "the installation files will be copied to it."
         )
      )
   )

   (set install_dest (tackon install_dest assign_name))
   (makedir install_dest (safe) (infos))
  )
)

(message "The destination for files is " install_dest)

(set parts
   (askoptions 
      (prompt "Choose the items you would like installed:")
      (choices
               "Programs"
               "Examples"
      )
      (help "You can install all or part of the MultiVol facility. "
            "If you do not install all parts, you will not be able to use "
            "certain features.  You can choose to install those parts later "
            "by rerunning this install program and selecting the new "
            "parts at this point.\n\n"
            "Here is a brief description of the parts:\n\n"

            "- Programs -\nall of the executable files required for MultiVol\n"
                      "\n"
            "- Examples -\nall of the examples listed in the ReadMe file\n"
                      "\n"

       )
    )
)
                     
(complete 5)

; Programs

(if (IN parts 0)
  (
    (set error 
       (trap 1 4
          (copyfiles
              (source "Programs") 
              (dest install_dest) (all)
          )
       )
    )
    
    (if (= error 1) (abort "Aborting..."))
    (if (= error 4) (message ("Copy error %ld" @ioerr)))

    (set error 
       (trap 1 4
          (copyfiles
              (source "ReadMe") (dest install_dest)
          )
       )
    )
    
    (if (= error 4) (message ("Copy error %ld" @ioerr)))
    (if (= error 1) (abort "Aborting..."))

  )
)

(complete 60)

; Examples

(if (IN parts 1)
  (
    (set error 
       (trap 1 4
          (copyfiles
              (source "Examples") 
              (dest install_dest) (all)
          )
       )
    )
    
    (if (= error 1) (abort "Aborting..."))
    (if (= error 4) (message ("Copy error %ld" @ioerr)))

  )
)

(complete 75)

; Assigns

(if (IN parts 0)
   (
;   Create the mount list

    (makedir (tackon install_dest "devs") (safe))

    (set devs_name (tackon install_dest "devs/mountlist.mv"))

    (delete devs_name)

    (textfile (dest devs_name)
         (append "MVD:        Stacksize  = 8000\n"
                 "            Priority   = 5\n"
                 "            GlobVec    = -1\n"
                 (cat
                 "            Handler = " 
                    (tackon install_dest "c/mv-handler"))
                 "\n#"
         )
    )

    (complete 80)

;   Create the strings used either now or at startup (usually).

    (set startup_assign_string ("Assign C: %s ADD" (tackon install_dest "c")))
    (run startup_assign_string)

    (set assign_string ("Assign %s: %s" assign_name install_dest))
    (run assign_string)

    (set startup_spec " >CON:0/20/640/50/MultiVol_Server/auto/close/wait")

    (set mount_string
         ("mount MVD: from %s" devs_name))
    (set run_string 
         (cat "run >NIL: "
              (tackon install_dest "c/mv_server")
         )
    )
     
    (set startup_name (tackon install_dest "c/mv_startup"))

    (textfile (dest startup_name)
         (append (cat 
                     ".KEY filespec\n" 
                     ".DEF filespec "NIL:"\n" 
                     ".BRA {\n" 
                     ".KET }\n" 
                     "Failat 50\n" 
                     "Assign MVD: dismount\n" 
                     "Failat 10\n" 
                     mount_string "\n" 
                     (cat run_string " >{filespec}")
                 )
         )
    )

    (protect startup_name "+s")

    (set execute_string (cat ("%s" startup_name) startup_spec))

;   Let the user decide when to make it operational.

    (set make_operational
          (askchoice
              (prompt "Do you want to make MultiVol operational now?"
              )
              (choices "Yes" "No")
              (default 0)
              (help "By making MultiVol operational now, you can immediately "
                    "start using it.  The alternative is either to put it "
                    "in your startup or to start it up manually, both at a later "
                    "time."
              )
          )
    )

;   If the decision was to make it operational, make it so

    (if (= make_operational 0)
       (
         (run execute_string)
       )
    )
 
    (set error 
       (trap 1 4
          (startup assign_name
             (prompt 
                ("%s\n%s\n\n%s\n%s\n%s"
                 "The following commands have been created."
                 "Do you want the following commands to be added to your startup?"
                 assign_string
                 startup_assign_string
                 execute_string
                )
             )
             (command 
                (cat assign_string "\n")
                (cat startup_assign_string "\n")
                (cat execute_string "\n")
             )
             (help "They are not required, but they just make it much easier"
                   "for you later on.  Upon your approval, the "
                   "installer will add the necessary commands to your s:user-startup "
                   "script, which is run when your machine boots.  If you decide not "
                   "to allow the installer to make these changes, you will need to "
                   "make them yourself."
             )
         )
       )
    )
   )
)

(complete 100)

(exit (cat "Installation of " @app-name " is complete."))
