;Install script for WebPlug version 1.4 Š 1998 Esteve Boix
;This install script is Š Bo Liljegren (bosse@algonet.se)
;Updated 04/98 Esteve Boix (again :)
;

(complete 0)

;Pure sequrity. If the Installer, by some strange reason,
; can't find the default language, it will use english
; Actually, I've removed the other languages :P

(set default_lang 2)

;=============================================================================
; English strings

;(if (= @language "english")
;(
(set default_lang 2)

(set #low-user-level
(cat "\nWebPlug installation requires at least the \"Average\" user level.\n\n"
     "Restart installation and select appropriate user level."
))

(set #ask-upgrade
(cat "\nIs this a new installation or\n"
     "an upgrade?\n\n"
     "A reinstallation is equal an upgrade"
))

(set #upgr-choice-upgr
(cat "An upgrade"
))

(set #upgr-choice-new
(cat "New installation"
))

(set #which-oldfile
(cat "Where is the program webPlug?\n(The program, NOT the directory webPlug)\n"
))

(set #mess-oldinstaller1
(cat "\nYou are using an old version\nof the Installer program. (%ld.%ld)\n\n"
))

(set #mess-oldinstaller2
(cat "Please use the Installer v43.3"
))

(set #mess-obsoletekick
(cat "webPlug requires AmigaDOS version 3.0 or higher\nPrevious versions are no longer supported..."
))

(set #mess-nomui
(cat "\nwebPlug requires MUI.\nNo muimaster.library is found.\n\n"
     "Sorry, can not continue the installation"
))

(set #mess-oldmui
(cat "\nwebPlug requires MUI version 3.8 or higher.\n\n"
     "That means muimaster.library ver 19.35\n"
     "You have version %ld.%ld\n\n"
     "Sorry, can not continue the installation"
))

(set #which-directory
(cat "Where do you want to install webPlug ?\n(A drawer named \"webPlug\" WILL be created)"
))

(set #confirm-adddocs
(cat "\n\nWould you like to install the (HTML) documentation?"
))

(set #confirm-custom-dirs
(cat "\n\nWould you like to install the CustomTags and CustomStrings directories?"
))

(set #which-language
(cat "\nWhich languages should be installed?\n(english is built-in)"
))

(set #prompt-makemaindir
(cat "Going to create webPlug's dir"
))

(set #prompt-copybrowserlinks
(cat "Going to copy the BrowserLinks dir"
))

(set #prompt-copyplugins
(cat "Going to copy the plugins dir"
))

(set #prompt-adddocs
(cat "Going to copy the (HTML) documentation"
))

(set #prompt-texteditor
(cat "About to install the Texteditor.mcc"
))

(set #prompt-betterstring
(cat "About to install the BetterString.mcc"
))

(set #prompt-popcolor
(cat "About to install the PopColor.mcc"
))

(set #prompt-customtags
(cat "About to install the CustomTags directory"
))

(set #prompt-customstrings
(cat "About to install the CustomStrings directory"
))

(set #prompt-copytoolicons
(cat "About to copy the toolbar image files"
))

(set #prompt-executable
(cat "Going to copy webPlug's executable"
))

(set #mess-congra
(cat "\nCongratulations, webPlug is now installed.\n\n"
))

(set #mess-docsfound
(cat "The documentation is in html format and\n"
     "can be found in the directory \"%s\"\n"
     "Please used your favorite browser to read it.\n"
     "Start with the document \"webPlug.html\"\n\n"
))

(set #mess-shareware
(cat "webPlug is released as Shareware.\n"
     "The fee is only $10, so please consider\n"
     "registering it if you use it.\n\n"
     "Enjoy!"
))

;))

;=============================================================================
; procedure to copy the language catalogs

(procedure P_InstLocale
(
    (set n 0)
    (while (set #language (select n "catalā"
                "english"
                "espaņol"
;                "italiano"
;                "portuguęs"
                "svenska"
;                "norsk"
;                "deutsch"
                ""
   ))
    (
   (if (IN #locales n)
   (
   ;; The english language is built in. No need to install it
      (if (<> 1 n)
      (
          (copyfiles
         (source (tackon "/bin/locale/catalogs/" #language))
         (dest (tackon "LOCALE:Catalogs" #language))
         (all)
   )))))
   (set n (+ n 1))
))))

;========================================================
; check user-level

(if (< @user-level 1)
    (abort (#low-user-level @app-name))
)

;========================================================
; variable setup

(set #installver (/ @installer-version 65536))
(set #installrev (- @installer-version (* #installver 65536)))
(set #tempversion (getversion))
(set #osversion (/ #tempversion 65536))
(set #osrevision (- #tempversion (* #osversion 65536)))
(set #adddocs 0)
(set #frominstdir (pathonly @icon))
(set #frominstdir (substr #frominstdir 0 (- (strlen #frominstdir) (strlen "/install"))))

;========================================================
; check installer version

(if (< #installver 43)
    (
     (abort (#mess-oldinstaller1 #installver #installrev)
             #mess-oldinstaller2)
))

;========================================================
; check kickstart version

(if (< #osversion 37)
    (
     (abort #mess-obsoletekick)
))

;========================================================
; Display picture

(if (> (exists ("c:multiview")) 0) (set #mv "c:") )
(if (> (exists ("sys:utilities/multiview")) 0) (set #mv "sys:Utilities") )
(if (> (exists ("sys:tools/multiview")) 0) (set #mv "sys:Tools") )

(if (<> #mv 0)
    ((run (cat "run " (tackon #mv "multiview ") "/docs/pics/webPlugS.gif"))))


;========================================================
; check mui (MUI 3.8 = muimaster.library V19.35)

(if (= (exists "LIBS:muimaster.library" (noreq)) 1)
    (
     (set #tempver (getversion "LIBS:muimaster.library"))
     (set #muiver (/ #tempver 65536))
     (set #muirev (- #tempver (* #muiver 65536)))
     (if (< #muiver 19)
    (
     (abort (#mess-oldmui #muiver #muirev))
     )))
  ((abort #mess-nomui))
)

;=============================================================================
; ask new install or upgrade

(set #b-upgrade
   (askbool
      (prompt #ask-upgrade)
      (help @askbool-help)
      (choices #upgr-choice-upgr #upgr-choice-new)
   )
)

;=============================================================================
; where should webPlug be installed

(if (= (exists "Work:" (noreq)) 2)
    (set #def-dest "Work:")
    (set #def-dest "SYS:")
    )

;-----------------------------------------------
; if upgrade, where is the old program?

(if (= 1 #b-upgrade)
(
    (set #oldprogfile
   (askfile
       (prompt #which-oldfile)
       (help @askdir-help)
       (default #def-dest)
   )
    )
    (set #directory (pathonly (#oldprogfile)))

    ;; If Docs directory exists, new documentation will be installed!
    (if (= (exists (tackon #directory "Docs") (noreq)) 2)
   (set #adddocs 1)
    )
)

;-----------------------------------------------
; else new install

((set #directory
   (askdir
       (prompt #which-directory)
       (help @askdir-help)
       (default #def-dest)
))))
(complete 10)

;=============================================================================
; should documentation be installed?

(if (OR (= #adddocs 0) (= @user-level 2))
(
    (set #adddocs
   (askbool
       (prompt #confirm-adddocs)
       (help @askbool-help)
       (default 1)
    ))
))
(complete 20)

;=============================================================================
; should CustomTags and CustomStrins directories be installed?

(
   (set #addcustom
   (askbool
       (prompt #confirm-custom-dirs)
       (help @askbool-help)
       (default 1)
    ))
)
(complete 20)

;=============================================================================
; which languages should be installed?

(set #locales
   (askoptions
      (prompt #which-language)
      (help @askoptions-help)
      (choices
                      "Catalā"
                      "English"
                      "Espaņol"
;                      "Italiano (not complete)"
;                      "Portuguęs (not complete)"
                     "Svenska"
;                      "Norsk (not complete)"
;                      "Deutsch (not complete)"
                 )
      (default default_lang)
   )
)
(complete 30)

;=============================================================================
; if new installation create the main directory

(if (= 0 #b-upgrade)
(
   (set @default-dest (tackon #directory "webPlug"))
   (makedir
    (@default-dest)
    (prompt #prompt-makemaindir)
    (help @makedir-help)
    (infos)
   )
   (complete 40)

;-----------------------------------------------
; and copying icon file for main program/directory

   (copyfiles
    (source (cat #frominstdir ".info"))
    (dest (tackon @default-dest '/'))
    (newname 'webPlug.info' )
    (infos)
    (help @copyfiles-help)
   )
)
;-----------------------------------------------
; else just set @default-dest

    (set @default-dest #directory)
)
(complete 50)

;=============================================================================
; copy the BrowserLinks directory

(copyfiles
   (source "/bin/BrowserLinks")
   (dest (tackon @default-dest "BrowserLinks"))
   (prompt #prompt-copybrowserlinks)
   (all)
   (help @copyfiles-help)
)
(complete 60)

;=============================================================================
; copy the "toolicons" directory

(copyfiles
   (source "/bin/toolicons")
   (dest (tackon @default-dest "toolicons"))
   (prompt #prompt-copytoolicons)
   (all)
   (help @copyfiles-help)
)
(complete 65)

;=============================================================================
; copy the (HTML) documentation
(set #docs-dest (tackon @default-dest "Docs"))

(if (= 1 #adddocs)
   (copyfiles
      (source "/docs")
      (dest #docs-dest)
      (prompt #prompt-adddocs)
      (help @copyfiles-help)
      (all) 
   )
)
(complete 70)
;=============================================================================
; copy the CustomTags and CustomStrins directories
(set #docs-dest (tackon @default-dest "Docs"))

(if (= 1 #adddocs)
  (
   (copyfiles
      (source "/bin/CustomStrings")
      (dest (tackon @default-dest "CustomStrings"))
      (prompt #prompt-customstrings)
      (all)
      (infos)
      (help @copyfiles-help)
   )
   (copyfiles
      (source "/bin/CustomTags")
      (dest (tackon @default-dest "CustomTags"))
      (prompt #prompt-customstags)
      (all)
      (infos)
      (help @copyfiles-help)
   )
  )
)
(complete 75)
;=============================================================================
; install the PopColor.mcc progdir:mui/

(copylib
    (source "/bin/mui/popcolor.mcc")
    (dest (tackon @default-dest "mui"))
    (prompt #prompt-popcolor)
)

;=============================================================================
; install the Texteditor.mcc MUI:Libs/mui/

(copylib
    (source "/bin/mui/texteditor.mcc")
    (dest "mui:libs/mui")
    (prompt #prompt-texteditor)
)

;=============================================================================
; install the BetterString.mcc MUI:Libs/mui/

(copylib
    (source "/bin/mui/betterstring.mcc")
    (dest "mui:libs/mui")
    (prompt #prompt-betterstring)
)

(complete 85)

;=============================================================================
; install executable files for webPlug

(copyfiles
   (source "/bin/webPlug")
   (dest @default-dest)
   (prompt #prompt-executable)
   (help @copyfiles-help)
   (infos)
)
(complete 90)

;=============================================================================
; install sample plugins for webPlug

(copyfiles
   (source "/bin/webplugins")
   (dest (tackon @default-dest "webplugins"))
   (prompt #prompt-plugins)
   (help @copyfiles-help)
   (infos)
   (all)
)
(complete 95)

;=============================================================================
; procedure to copy the language catalogs

(P_InstLocale)

;=============================================================================
;Close the mlutiview window

(rexx "quit_multiview.rexx")

(complete 100)

;=============================================================================
; That's it!

(if (= 1 #adddocs)
   (set #exit-text (cat #mess-congra (#mess-docsfound #docs-dest) #mess-shareware))
   (set #exit-text (cat #mess-congra #mess-shareware) )
)

(exit (#exit-text) )
