;===========================================================================;
;
;                    Installer script for ACDPlay V1.5
;                            by Martin Kresse
;                            and Marc Altmann
;
;                   $VER: Install_ACDPlay 1.5 (31.03.97)
;
;===========================================================================;


(set #welcome
    (cat "Welcome to the installation of\nACDPlay V1.1\n"
         "a CDDA player for SCSI CD-ROM drives.")
)

(set #acdpdir-prompt
    (cat "In which directory do you want to install ACDPlay?\n"
         "(a drawer named \"ACDPlay\" will be created)")
)
(set #acdpdir-help
    (cat "You may now choose a directory in which an own drawer "
         "drawer named \"ACDPlay\" will be created. ACDPlay will be "
         "copied to the resulting path with all files belonging to it.\n\n"
         @askdir-help)
)

(set #backup-prompt
    (cat "ACDPlay is already present.\nDo you wish a backup of "
         "the old version to be made?")
)
(set #backup-help
    (cat "You may now decide if the old version is to be moved "
         "into a subdirectory, before the new one is installed.")
)
(set #backup-dir "old")

(set #components-prompt
    (cat "Which of ACDPlay's components do you want to install?")
)
(set #components-help
    (cat "You may now select the individual components of the ACDPlay "
         "package you want to install. All items should be selected for "
         "a normal installation.\n\n"
         @askoptions-help)
)
(set #components-main "main program")
(set #components-docs "documentation")
(set #components-cats "catalogs")
(set #components-rexx "ARexx examples")
(set #components-cdid "title files")

(set #abort "No component chosen: installation aborted")

(set #magicwb-prompt "Do you prefer MagicWB icons?")
(set #magicwb-help
    (cat "If you have Martin Huttenloher's MagicWB package installed "
         "on your machine, you should use ACDPlay's MagicWB icons too. "
         "If it's the first time you hear the term MagicWB, it's a good "
         "idea to install the standard icons to ensure a 'clear sight'.")
)

(set #catalogs-prompt
    (cat "For what language do you want to install catalogs and documentation?")
)
(set #catalogs-help
    (cat "You may now choose the language in which ACDPlay and the documentation "
         "should appear. If your own language isn't supported, please contact one "
         "of the programmers\n\n"
         "Attention: In order to use the different languages ACDPlay needs "
         "locale.library installed which is part of the operating system since "
         "Workbench 2.1. Under older versions of the OS ACDPlay will always"
         "appear in English.\n\n"
         @askchoice-help)
)
(set #catalogs-german    "German")
(set #catalogs-english   "English")
(set #catalogs-norwegian "Norwegian")
(set #catalogs-default 0)

(set #getdev-prompt "Examining your SCSI device...")

(set #devicename-prompt "Enter the name of your SCSI device:")
(set #devicename-help
    (cat "In order to send commands to your CD-ROM drive ACDPlay must know "
         "the name of your SCSI device driver. Because this can be different "
         "on each system because of many different configurations it's hard "
         "to determine the right one with 100% safity. "
         "Please make sure with the help of your SCSI host adapters' manual "
         "whether this 'guessed' name is the right one.\n\n"
         @askstring-help)
)

(set #getunit-prompt "Looking for CD-ROM drive...")

(set #deviceunit-prompt
    (cat "Enter the unit of your CD-ROM drive:")
)
(set #deviceunit-help
    (cat "Since a SCSI adapter is able to control up to 7 devices, "
         "each one must be indentified by a number (0-7). "
         "If ACDPlay doesn't work with the proposed number, you may "
         "just try every number until it does.\n\n"
         @asknumber-help)
)

(set #copycdlib-prompt "Copying 'cdplay.library' to LIBS:")
(set #copycdlib-help
    (cat "Patrick Hess' 'cdplay.library' is badly needed by ACDPlay "
         "In order to be found and used it must be situated "
         "within the logical device LIBS:.\n\n"
         @copylib-help)
)




(welcome #welcome)

(complete 0)

;---------------------------------------------------------- ask user options

(set installmode
    (askchoice
        (prompt  #installmode-prompt)
        (help    #installmode-help)
        (choices "Install" "Update")
        (default 0)
    )
)

(set rootdestdir
    (askdir
        (prompt  #acdpdir-prompt)
        (help    #acdpdir-help)
        (default "Sys:Utilities")
    )
)

(set destdir (tackon rootdestdir "ACDPlay"))

(if (= (exists destdir (noreq)) 2)
    (set backup
        (askbool
            (prompt #backup-prompt)
            (help   #backup-help)
            (default 1)
        )
    )
)

(set @default-dest destdir)

(set components
    (askoptions
        (prompt #components-prompt)
        (help   #components-help)
        (choices #components-main
                 #components-docs
                 #components-cats
                 #components-rexx
                 #components-cdid)
        (default 31)
    )
)

(if (= components 0)
    (exit #abort (quiet))
)

(complete 10)

(set magicwb
    (askbool
        (prompt #magicwb-prompt)
        (help   #magicwb-help)
        (default 0)
    )
)

(set catalogs
    (askchoice
        (prompt #catalogs-prompt)
        (help   #catalogs-help)
        (choices #catalogs-german
                 #catalogs-english
                 #catalogs-norwegian)
        (default #catalogs-default)
    )
)

(set language (select catalogs "deutsch" "english" "norsk"))

(complete 20)

(run "c/FindDevice >ENV:scsi_device" (prompt #getdev-prompt))

(set devicename
    (askstring
        (prompt #devicename-prompt)
        (help   #devicename-help)
        (default (getenv "scsi_device"))
    )
)

(run ("c/FindCDROM >ENV:scsi_unit %s" devicename) (prompt #getunit-prompt))

(set deviceunit
    (asknumber
        (prompt #deviceunit-prompt)
        (help   #deviceunit-help)
        (range 0 7)
        (default (getenv "scsi_unit"))
    )
)

(complete 30)


;----------------------------------------- now we can start the installation


(makedir destdir)
(if (= magicwb 1)
    (copyfiles
        (source "ACDPlay.info")
        (dest   rootdestdir)
        (noposition)
    )
    (copyfiles
        (source  "icons/ACDPlay-Dir.info")
        (dest    rootdestdir)
        (newname "ACDPlay.info")
        (noposition)
    )
)

; backup directory
;
(if (= backup 1)
  (
    (makedir (tackon destdir #backup-dir)
             (infos)
    )
    (copyfiles
        (source  destdir)
        (dest    (tackon destdir #backup-dir))
        (pattern ("~(%s|%s.info)" #backup-dir #backup-dir))
    )
  )
)

(complete 40)

; copy cdplay.library
;
(copylib
    (prompt #copycdlib-prompt)
    (help   #copycdlib-help)
    (source "libs/cdplay.library")
    (dest   "LIBS:")
    (confirm)
    (optional oknodelete askuser)
)

(complete 50)

; copy and configure main program
;
(if (IN components 0)
  (
    (copyfiles
        (source "ACDPlay/ACDPlay")
        (dest   destdir)
        (files)
        (infos)
    )
    (if (= magicwb 0)                        ; 4 colour icons?
      (copyfiles
          (source "Icons/ACDPlay.info")
          (dest   destdir)
      )
    )
    (tooltype
        (dest (tackon destdir "ACDPlay"))
        (settooltype "(DEVICE")
        (settooltype "DEVICE" devicename)
        (settooltype "(UNIT")
        (settooltype "UNIT" ("%ld" deviceunit ))
        (noposition)
    )
  )
)

; copy documentation
;
(if (IN components 1)
  (
    (copyfiles
        (source (tackon "docs" (tackon language "ACDPlay.guide")))
        (dest   destdir)
        (infos)
        (noposition)
    )
    (if (= magicwb 0)                        ; 4 colour icons?
      (copyfiles
          (source "Icons/ACDPlay.guide.info")
          (dest   destdir)
      )
    )
  )
)

(complete 60)

; copy catalogs
;
(if (IN components 2)
  (if (<> language "english")
    (
      (makedir (tackon destdir "catalogs"))
      (copyfiles
          (source (tackon "Catalogs" (tackon language "ACDPlay.catalog")))
          (dest   (tackon destdir (tackon "catalogs" language)))
      )
    )
  )
)

(complete 70)

; copy arexx examples
;
(if (IN components 3)
    (copyfiles
        (source "Arexx")
        (dest   (tackon destdir "ARexx"))
        (all)
    )
)

(complete 80)

; copy diskfiles
;
(if (IN components 4)
    (copyfiles
        (source "Disks")
        (dest   (tackon destdir "Disks"))
        (all)
    )
)

;------------------------------------------------------------------ clean up

; kill these global variables
;
(delete "ENV:scsi_device" (safe))
(delete "ENV:scsi_unit" (safe))

(complete 100)
