; Copyright 1994 AugmenTek

(complete 0)

(transcript "On installing RexxVar Demo, v1.01D")

(set @default-dest "Work:")

(set centered_title "                      RexxVar Demo")

(set assign_name "RXVD"
     @@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 REXXVAR: 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"
      )
      (help "You can install all or part of the RexxVar 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\n"
                      "using the REXXVAR or REXXVAR_RC function hosts\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 75)

; Assigns

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

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

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

    (delete devs_name)

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

    (complete 80)

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

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

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

    (set mount_string
         ("mount AREXXVAR: from %s" devs_name))
    (set run_string 
         (cat "run >NIL: "
              (tackon install_dest "c/rexxvar_server")
              " >CON:460/20/200/22/RexxVar_Server/auto/simple"))
    (set env_string
         (cat "setenv REXXVAR_PATH " (tackon install_dest "c")))
     
    (set startup_name (tackon install_dest "s/rexxvar_startup"))

    (textfile (dest startup_name)
         (append (cat 
                     "Failat 50\n" 
                     "Assign AREXXVAR: dismount\n" 
                     "Failat 10\n" 
                     env_string "\n" 
                     mount_string "\n" 
                     run_string
                 )
         )
    )

    (protect startup_name "+s")

    (set execute_string ("EXECUTE %s" startup_name))

;   Let the user decide when to make it operational.

    (set make_operational
          (askchoice
              (prompt "Do you want to make RexxVar operational now?"
              )
              (choices "Yes" "No")
              (default 0)
              (help "By making RexxVar 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."))
