; Install-Script for DLG Pro
; Begin header segment

(user 2)
(welcome)

(set #dlg-version "2.1")
(set #FidoOK 0)

; Check installer version

(set ver @installer-version)
(set ver (/ ver 65536))

(if
   (< ver 43)
   (
      (abort
         (cat  "This installer script requires V43 of the Amiga Installer. You will need a copy of the V43 "
               "Installer in your command path (C: or Sys:) or change the icon of this installer to point to "
               "wherever you have your installer at. You may download Installer V43 from AmiNet, from the DLG "
               "web site ( http://www.ald.net/dlg ) or contact Digerati Dreams for a copy of the V43 installer."
         )
      )
   )
)


; check for workbench 2.x

(set ver (getversion))
(set ver (/ ver 65536))

(if (< ver 37)
   (Abort
      (cat  "DLG "
            #dlg-version
            " needs KickStart 2.04 (v37) or later. It seems not to be installed on your system."
      )
   )
)

; End Header segment

;;; Begin Check-for-DLG components

(set #AbortMe 0)
(set #OptionalsOK 1)

;;; Check for DLG:
(if
   (exists "DLG:" (noreq))
   (
      (set @default-dest (expandpath "DLG:/"))
      (set #dlg-dir (expandpath "DLG:") )
   )
   (  (message "Cannot find the assign \"DLG:\"")
      (set #AbortMe 1)
   )
)
;;-
;;; Check for DLGConfig:
(if
   (exists "DLGConfig:" (noreq))
   (
      (set #config-dir (expandpath "DLGConfig:") )
   )
   (  (message "Cannot find the assign \"DLGConfig:\"")
      (set #AbortMe 1)
   )
)
;;-
;;; Check for Handler
(if
   (NOT(exists "l:tpt-handler" (noreq)))
   (  (message "Cannot find TPT-Handler")
      (set #AbortMe 1)
   )
)
;;-
;;; Check for Fido:
(if
   (exists "Fido:" (noreq))
   (
      (set #fido-dir (expandpath "Fido:") )
      (set #FidoOK 1)
   )
   (  (message "Non-fatal error: cannot find the assign \"Fido:\". Fido utils will not be installed." )
      (set #FidoOK 0)
      (set #OptionalsOK 0)
   )
)
;;-

;;; What to do if something vital is missing
(if
   (= #AbortMe 1)
   (Abort
      (cat  "This installer is intended as an upgrade to currently installed DLG systems. At least one "
            "DLG component is missing on your system.  If you believe that you have DLG installed properly "
            "you will need to contact DLG technical support for assistance. You may contact DLG technical "
            "support in a number of ways:\n\n"
            "Email to dlg@cts.com\n"
            "Web page at http://www.ald.net/dlg\n"
            "FidoNet netmail to Jeff Grimmett at 1:202/720 or 40:405/101\n"
            "Fidonet echo DLG_SUPPORT\n"
      )
   )
)
;;-
;;; What to do if something optional is missing
(if
   (= #OptionalsOK 0)
   (if
      (NOT
         (askbool
            (prompt
               (cat  "One or more optional components were not found on your system. If this is as you "
                     "intended, then you may proceed and the optional components will not be updated. If "
                     "you use those optional components and wish to update them, then you will need to "
                     "correct the problem before installing."
               )
            )
            (help @askchoice-help)
            (choices "I meant to do that." "Abort! I need those things!")
            (default 1)
         )
      )
      (exit
         (cat  "You need to correct the problem with your system and then re-run the installer. If you believe "
               "that you have the missing components installed properly you will need to contact DLG "
               "technical support for assistance. You may contact DLG technical support in a number of ways:\n\n"
               "Email to dlg@cts.com\n"
               "Web page at http://www.ald.net/dlg\n"
               "FidoNet netmail to Jeff Grimmett at 1:202/720 or 40:405/101\n"
               "Fidonet echo DLG_SUPPORT\n"
         )
         (quiet)
      )
   )
)
;;-

;;- End Check-for-DLG

;;; Begin "Backup first!" warning

(if
   (NOT
      (askbool
         (prompt
            (cat  "You should make backups of your software before you proceed. While we have taken every "
                  "precaution, there is still a slight chance that you might need to revert back to an "
                  "older version if something doesn't work. Be prepared!"
            )
         )
         (help @askchoice-help)
         (choices "I am prepared." "Abort! I need to backup!")
         (default 1)
      )
   )
   (exit
      (cat  "Aborting installation process. To make good backups, you need to back up the following: \n\n"
            "Contents of DLG: directory\n"
            "Libs:DLG.library\n"
            "L:TPT-Handler\n"
            "Contents of DLGConfig:\n"
            "Contents of Fido:\n\n"
            "When you have completed backing up your software, run this installer again and tell it you are "
            "prepared when it asks."
      )
      (quiet)
   )
)

;;- End "Backup First!" warning

; Begin handler update

(if
   (exists "L:Tpt-Handler" (noreq))
   (
      (working "Creating keyfile.")
      (
         (set @execute-dir "c")
         (set #result (run "CreateKeyFile"))
      )

      (if
         (<> #result 0)
         (abort
            (cat  "An error occurred when trying to create your new keyfile. "
                  "Contact Digerati Dreams for instructions."
            )
         )
      )
   )
)

; End handler update

; Begin Handler segment

(copyfiles
   (prompt "Copying TPT-Handler to L:")
   (help @copyfiles-help)
   (source "L/TPT-Handler")
   (dest "L:")
)

; End Handler segment
; Begin library segment

(set cpu (database "cpu"))

(if
   (NOT (OR (= cpu "68000") (= cpu "68010")))
      (
         (set sourcelib "libs/dlg.library_68030")
         (set sourcerlib "libs/dlgrexx.library_68030")
      )
      (
         (set sourcelib "libs/dlg.library_any")
         (set sourcerlib "libs/dlgrexx.library_any")
      )
)

(copyfiles
   (prompt "Copying " cpu " version of DLG.library to LIBS:")
   (help @copyfiles-help)
   (source sourcelib)
   (dest "Libs:")
   (newname "dlg.library")
)

(copyfiles
   (prompt "Copying " cpu " version of DLGRexx.library to LIBS:")
   (help @copyfiles-help)
   (source sourcerlib)
   (dest "Libs:")
   (newname "dlgrexx.library")
)

; End library segment
;;; Begin Executable Modules

(copyfiles
   (prompt "Copying DLG Modules to " #dlg-dir)
   (help @copyfiles-help)
   (source "DLG")
   (all)
   (dest #dlg-dir)
)

;;- End executables

;;; Begin Fido modules

(if
   (= #FidoOK 1)
   (copyfiles
      (prompt "Copying Fido Modules to " #fido-dir)
      (help @copyfiles-help)
      (source "FIDO")
      (all)
      (dest #fido-dir)
   )
)

;;- End Fido Modules

;;; Begin Configs

(copyfiles
   (prompt "Copying new configs to " #config-dir)
   (help @copyfiles-help)
   (source "DLGConfig")
   (all)
   (Confirm)            ; Uncomment this for more than one dir
   (dest #config-dir)
)

;;- End Configs

;;; Begin Message components

(  (message
      (cat
         "Please read Changes.txt that was included in this archive. It contains much information "
         "that is vital for using new modules and settings released with this version of DLG. "
         "Also read the release notes for more information that will come in handy from time to time."
      )
   )
)

;;- End Message

;;; Begin Doc Install

(set #doc-dir
   (AskDir
      (prompt
         (cat  "Please indicate where you would like the DLG documentation installed. A new directory called "
               "\"DLG-Docs\" will be created there."
         )
      )
      (Help @askdir-help)
      (Default @default-dest)
      (newpath)
      (disk)
   )
)

(set #doc-dir (tackon #doc-dir "DLG-Docs"))

(copyfiles
   (prompt "Copying DLG Docs to " #doc-dir)
   (help @copyfiles-help)
   (source "Docs")
   (all)
   (dest #doc-dir)
)

;;- End doc install

; Begin RepairLevels

(  (message
      (cat
         "The installer will now run a program called RepairLevels that will inspect all your system's "
         "user accounts and repair any that have access levels outside of the normal limits of 1 to "
         "255. This will take a moment."
      )
   )
)


(working "Repairing user files.")
(
   (set @execute-dir "c")
   (set #result (run "RepairLevels"))
)

; End RepairLevels

;;; Begin exit

(exit
   (Cat
      "Installation is complete! Now is a good time to read the DLG Update documentation.\n\n"
      "A FULL REBOOT IS REQUIRED to get everything working."
   )
   (quiet)
)

;;;- End Exit
