; $VER: Install_Miami 3.0 (22.02.98)
(procedure P-check-system-version
 (if (< (/ @installer-version 65536) 43)
  (abort "The Miami installation script needs Installer\n"
   "version 43 or higher. It is available from Aminet\n"
   "and from www.nordicglobal.com")
 )
 (set #exec-version (/ (getversion) 65536))
 (if (< #exec-version 37)
  (abort "Miami needs Kickstart 2.04 or higher.\n")
 )
 (if (< #exec-version 39)
  (set #ag-browser "AmigaGuide")
  (set #ag-browser "MultiView")
 )
)

(procedure P-select-destination-directory
 (if (exists "Miami:" (noreq))
  (
   (set #old-miami-assign 1)
   (set #old-miami-assign-location (expandpath "Miami:"))
   (set @default-dest
    (askdir
     (prompt "Select the directory where you want to "
      "install Miami 3.0. You already have a 'Miami:' "
      "assign on your system, so it is assumed that this "
      "is the location of an older version of Miami that "
      "you want to upgrade.")
     (help "Select the directory where you want to "
      "install Miami 3.0. Since you already have a 'Miami:' "
      "assign on your system you should probably accept "
      "the default.")
     (default "Miami:")
    )
   )
  ) (
   (set #old-miami-assign 0)
   (if (exists "Work:" (noreq))
    (set @default-dest "Work:")
    (set @default-dest "SYS:")
   )
   (set @default-dest
    (askdir
     (prompt "Select the directory where you want to "
      "install Miami 3.1. An additional directory "
      "will *NOT* be created at the location you specify.")
     (help "Select the directory where you want to "
      "install Miami 3.0. All necessary files will be copied "
      "to that directory during installation. A new directory "
      "will *NOT* be created at the location you specify. "
      "This means if you want Miami to be installed in its "
      "own directory then you need to create that directory "
      "yourself first.")
     (default @default-dest)
    )
   )
  )
 )
 (makeassign "Miami" @default-dest)
)

(procedure P-select-binary
 (set #cpu-choice (if (patmatch "68000|68010" (database "cpu")) 0 1))
 (set #cpu-choice
  (askchoice
   (prompt "Please select which version of\nMiami you want to use:")
   (help "Miami exists in a 68000 version,\n and a 68020 version.\n"
    "One of these versions will be installed.")
   (choices "68000/010 version" "68020/030/040/060 version")
   (default #cpu-choice)
  )
 )
)

(procedure P-check-binary
 (set #bin-choice
  (select #cpu-choice
   "000/Miami.000"
   "020/Miami.020"
  )
 )
 (if (not (exists (tackon #source-dir #bin-choice)))
  (abort "Before you can install Miami you first need to\n"
   "download and unpack the archive that contains the Miami\n"
   "binary you want to install.")
 )
)

(procedure P-select-guis
 (set #gui-options
  (askoptions
   (prompt "Please select which GUI modules you want to use with Miami. The "
    "MUI and MUIMWB modules need MUI 3.8 or higher, which has to be installed "
    "BEFORE installing Miami.")
   (help "Miami supports several different user interface engines: "
    "MUI, MUIMWB (a version of the MUI module with additional images, "
    "for screens with 8 or more colors), and GTLayout "
    "(using gtlayout.library, creating GadTools gadgets). Please select "
    "which ones you want to install.")
   (choices "MUI" "MUIMWB (MUI with MagicWB-style images)" "GTLayout")
  )
 )
 (if (= #gui-options 0)
  (abort "You need to install at least one GUI module.")
 )
 (if (not (= 0 (BITAND #gui-options 3))) (
  (if (not (exists "MUI:Libs/muimaster.library" (noreq)))
   (abort "You need to install MUI 3.8 before you can install GUI "
    "modules for Miami.")
  )
  (if (< (/ (getversion "MUI:Libs/muimaster.library") 65536) 18)
   (abort "Your installed MUI version is too old for Miami 3.0. "
    "Please upgrade to MUI 3.8 or higher before installing Miami."
   )
  )
 ))
)

(procedure P-check-gui
 (if (not (exists (tackon #source-dir #current-gui)))
  (abort "Before you can install Miami you first need to\n"
   "download and unpack the archives that contain the Miami\n"
   "GUI modules you want to install.")
 )
)

(procedure P-check-guis
 (if (= 1 (BITAND #gui-options 1)) (
  (set #current-gui "MUI")
  (P-check-gui)
 ))
 (if (= 2 (BITAND #gui-options 2)) (
  (set #current-gui "MUI")
  (P-check-gui)
 ))
 (if (= 4 (BITAND #gui-options 4)) (
  (set #current-gui "GTLayout")
  (P-check-gui)
 ))
)


(procedure P-select-gui
 (if (= 4 (BITAND #gui-options 4))
  ((set #gui-choice-gtlayout "GTLayout") (set #gui-choice 2))
  (set #gui-choice-gtlayout "")
 )
 (if (= 1 (BITAND #gui-options 1))
  ((set #gui-choice-mui "MUI") (set #gui-choice 0))
  (set #gui-choice-mui "")
 )
 (if (= 2 (BITAND #gui-options 2))
  ((set #gui-choice-muimwb "MUIMWB") (set #gui-choice 1))
  (set #gui-choice-muimwb "")
 )
 (set #gui-choice
  (askchoice
   (prompt "Please select which GUI module you want to use as the default "
    "module for Miami")
   (help "Miami supports several different user interface engines: "
    "MUI, MUIMWB (a version of the MUI module with additional images, "
    "for screens with 8 or more colors), and GTLayout "
    "(using gtlayout.library, creating GadTools gadgets). Please select "
    "which one you want to use as the default. Only modules that you "
    "selected for installation earlier can be used. Note: If you have already "
    "saved the settings with a Miami version 2.9 or higher then the GUI module "
    "you seleted in Miami overrides the choice you make here.")
   (choices #gui-choice-mui #gui-choice-muimwb #gui-choice-gtlayout)
   (default #gui-choice)
  )
 )
 (set #gui-choice-name (select #gui-choice "MUI" "MUIMWB" "GTLayout"))
)

(procedure P-select-icon
 (set #icon-choice
  (askchoice
   (prompt "Please select which icons you\nwant to use for Miami and\n"
    "the utility programs:")
   (help "Miami comes with three different\nicon styles. Please select\n"
    "the one you prefer.")
   (choices "do not install new icons" "standard" "Magic Workbench" "NewIcons")
  )
 )
)

(procedure P-copy-file
 (copyfiles
  (source (tackon #source-dir #to-copy))
  (dest @default-dest)
  (optional force)
 )
)

(procedure P-set-tooltypes
 (if (not (= #icon-choice 0)) (
  (tooltype
   (dest (tackon @default-dest "Miami"))
   (noposition)
  )
  (tooltype
   (dest (tackon @default-dest "MiamiInit"))
   (noposition)
  )
  (tooltype
   (dest (tackon @default-dest "MiamiRegister"))
   (noposition)
  )
  (tooltype
   (dest (tackon @default-dest "Miami.guide"))
   (noposition)
   (setdefaulttool #ag-browser)
  )
 ))
)

(procedure P-add-to-startup
 (if #old-miami-assign
  (if (= (#old-miami-assign-location (expandpath @default-dest)))
   (set #change-startup 0)
   (set #change-startup 1)
  )
  (set #change-startup 1)
 )
 (if #change-startup
  (
   (set #startup-addition (cat
    "assign Miami: \"" (expandpath @default-dest) "\"\n"
    )
   )
   (if
    (askbool
     (prompt "It is NECESSARY that an assign "
      "'Miami:' is created for the Miami installation "
      "directory. Would you like Installer "
      "to make the required change to your user-startup "
      "file ? If you answer 'No' then you need to make the "
      "addition yourself, manually, before you can use Miami.")
     (help "It is NECESSARY that an assign "
      "'Miami:' is created for the Miami installation "
      "directory. Would you like Installer "
      "to make the required change to your user-startup "
      "file ? If you answer 'No' then you need to make the "
      "addition yourself, manually, before you can use Miami. "
      "You should only answer with 'No' if you prefer to edit "
      "the user-startup file yourself. If you answer 'No' then "
      "a file 'addition-to-user-startup' will be created in the "
      "Miami installation directory instead. You need to add the "
      "contents of that file to your user-startup file.")
     (choices "Yes" "No")
    )
    (startup "Miami"
     (command #startup-addition)
     (prompt "Installer will modify your s:user-startup "
      "script. The following lines will be added:\n\n"
      #startup-addition)
     (help "Installer will modify your s:user-startup "
      "script. The following lines will be added:\n\n"
      #startup-addition)
    )
    (textfile
     (dest (tackon @default-dest "addition-to-user-startup"))
     (append #startup-addition)
    )
   )
  )
 )
)

(procedure P-set-envvars

 (set #env-equal-envarc (= (expandpath "ENV:") (expandpath "ENVARC:")))
 (if (not (exists "ENV:MIAMI"))
  (makedir "ENV:MIAMI")
 )
 (if (not #env-equal-envarc)
  (if (not (exists "ENVARC:MIAMI"))
   (makedir "ENVARC:MIAMI")
  )
 )
 (textfile
  (dest "ENV:MIAMI/GUI")
  (append #gui-choice-name)
 )
 (if (not env-equal-envarc)
  (copyfiles
   (source "ENV:MIAMI/GUI")
   (dest "ENVARC:MIAMI")
  )
 )
)


(welcome "Welcome to the Miami 3.0 installation.\n")

(set app-name "Miami 3.0")

(P-check-system-version)

(complete 0)

(set #source-dir (if (= 1 (exists @icon)) (pathonly (expandpath @icon))
 (expandpath @icon))
)

(P-select-destination-directory)

(complete 5)

(P-select-binary)

(P-check-binary)

(complete 10)

(P-select-icon)

(complete 15)

(P-select-guis)

(P-select-gui)

(P-check-guis)

(complete 20)

; start actual installation

; delete obsolete files from older Miami versions
(delete (tackon @default-dest "MiamiRemind.doc") (optional force))
(delete (tackon @default-dest "MiamiInitSANA2") (optional force) (infos))
(delete (tackon @default-dest "Miami.000") (optional force) (infos))
(delete (tackon @default-dest "Miami.020") (optional force) (infos))
(delete (tackon @default-dest "Miami.eval") (optional force) (infos))

(complete 25)

; copy Miami binary selected by user
(set #to-copy (select #cpu-choice "000/Miami.000" "020/Miami.020"))
(copyfiles
 (source (tackon #source-dir #to-copy))
 (dest @default-dest)
 (newname "Miami")
 (optional force)
)

(complete 30)

; copy individual files
(set #to-copy "main/CHANGES") (P-copy-file)
(set #to-copy "main/Miami.guide") (P-copy-file)
(set #to-copy "main/MiamiArp") (P-copy-file)
(set #to-copy "main/MiamiFinger") (P-copy-file)
(set #to-copy "main/MiamiIfConfig") (P-copy-file)
(set #to-copy "main/MiamiInit") (P-copy-file)
(complete 40)
(set #to-copy "main/MiamiMapMBone") (P-copy-file)
(set #to-copy "main/MiamiMRInfo") (P-copy-file)
(set #to-copy "main/MiamiMRouteD") (P-copy-file)
(set #to-copy "main/MiamiMTrace") (P-copy-file)
(set #to-copy "main/MiamiNetStat") (P-copy-file)
(set #to-copy "main/MiamiPing") (P-copy-file)
(set #to-copy "main/MiamiRegister") (P-copy-file)
(complete 50)
(set #to-copy "main/MiamiRemind") (P-copy-file)
(set #to-copy "main/MiamiResolve") (P-copy-file)
(set #to-copy "main/MiamiRoute") (P-copy-file)
(set #to-copy "main/MiamiSysCtl") (P-copy-file)
(set #to-copy "main/MiamiTCPDump") (P-copy-file)
(set #to-copy "main/MiamiTraceRoute") (P-copy-file)

(complete 60)

; copy libraries
(if (not (exists (tackon @default-dest "Libs")))
 (makedir (tackon @default-dest "Libs"))
)
(copyfiles
 (source (tackon #source-dir "main/Libs"))
 (dest (tackon @default-dest "Libs"))
 (optional force)
 (all)
)

(complete 70)

; copy GUI modules
(if (= 1 (BITAND #gui-options 1)) (
 (copyfiles
  (source (tackon #source-dir "MUI/MUI.MiamiGui"))
  (dest (tackon @default-dest "Libs"))
  (optional force)
 )
 (copyfiles
  (source (tackon #source-dir "MUI/MUI.MiamiToolsGui"))
  (dest (tackon @default-dest "Libs"))
  (optional force)
 )
))

(if (= 2 (BITAND #gui-options 2)) (
 (run (cat "\"" (tackon #source-dir "MUI/spatch") "\" -oRAM:MUIMWB.MiamiGui \"-p"
  (tackon #source-dir "MUI/MUIMWB.pch") "\" \"" (tackon #source-dir "MUI/MUI.MiamiGui") "\""))
 (copyfiles
  (source "RAM:MUIMWB.MiamiGui")
  (dest (tackon @default-dest "Libs"))
  (optional force)
  (all)
 )
 (delete "RAM:MUIMWB.MiamiGui")
 (copyfiles
  (source (tackon #source-dir "MUI/MUI.MiamiToolsGui"))
  (dest (tackon @default-dest "Libs"))
  (optional force)
 )
))
  
(if (= 4 (BITAND #gui-options 4)) (
 (copyfiles
  (source (tackon #source-dir "GTLayout/GTLayout.MiamiGui"))
  (dest (tackon @default-dest "Libs"))
  (optional force)
 )
 (copyfiles
  (source (tackon #source-dir "GTLayout/GTLayout.MiamiToolsGui"))
  (dest (tackon @default-dest "Libs"))
  (optional force)
 )
 (copylib
  (source (tackon #source-dir "GTLayout/gtlayout.library"))
  (dest "LIBS:")
  (prompt "The Installer is about to install gtlayout.library "
  "in your LIBS: directory.")
  (help "The GTLayout GUI module needs gtlayout.library for layout generation. "
  "If you skip this step during the installation, you have to "
  "install gtlayout.library manually somewhere within your LIBS: "
  "assign.")
  (confirm)
 )
))

(complete 80)

; set icons

(if (not (= #icon-choice 0)) (
 (set #to-copy
  (select #icon-choice
   ""
   "main/Icons/Standard/Miami.info"
   "main/Icons/MagicWB/Miami.info"
   "main/Icons/NewIcons/Miami.info"
  )
 )
 (copyfiles
  (source (tackon #source-dir #to-copy))
  (dest @default-dest)
 )
 (copyfiles
  (source (tackon #source-dir #to-copy))
  (dest @default-dest)
  (newname "MiamiInit.info")
 )
 (copyfiles
  (source (tackon #source-dir #to-copy))
  (dest @default-dest)
  (newname "MiamiRegister.info")
 )
 (copyfiles
  (source (tackon #source-dir #to-copy))
  (dest "ENV:Sys")
  (newname "def_MiamiApp.info")
 )
 (copyfiles
  (source (tackon #source-dir #to-copy))
  (dest "ENV:Sys")
  (newname "def_MiamiAppOnline.info")
 )
 (copyfiles
  (source (tackon #source-dir #to-copy))
  (dest "ENVARC:Sys")
  (newname "def_MiamiApp.info")
 )
 (copyfiles
  (source (tackon #source-dir #to-copy))
  (dest "ENVARC:Sys")
  (newname "def_MiamiAppOnline.info")
 )
 (set #to-copy "main/CHANGES.info") (P-copy-file)
 (set #to-copy "main/Miami.guide.info") (P-copy-file)
 (if (= #icon-choice 3) (
  (if (exists "ENV:Sys/def_amigaguide.info")
   (copyfiles
    (source "ENV:Sys/def_amigaguide.info")
    (dest @default-dest)
    (newname "Miami.guide.info")
   )
  )
  (if (exists "ENV:Sys/def_ascii.info")
   (copyfiles
    (source "ENV:Sys/def_ascii.info")
    (dest @default-dest)
    (newname "CHANGES.info")
   )
  )
 ))
))

(complete 85)

(P-set-tooltypes)

(complete 90)

(P-set-envvars)

(complete 95)

(P-add-to-startup)

(complete 100)

(exit "The installation of Miami is finished. If you are "
 "upgrading from an earlier version of Miami then you need "
 "to execute the Shell command `avail flush' or reboot your "
 "computer before starting Miami 3.0.")
