; $VER: Install_MiamiDx 1.0 (09.04.2000)
(procedure P-check-system-version
 (if (< (/ @installer-version 65536) 43)
  (abort "The MiamiDx 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 "MiamiDx needs Kickstart 2.04 or higher.\n")
 )
 (if (< #exec-version 39)
  (set #ag-browser "AmigaGuide")
  (set #ag-browser "MultiView")
 )
 (set #wb-version (/ (getversion "LIBS:workbench.library") 65536))
)

(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 MiamiDx. You already have a 'Miami:' "
      "assign on your system, so it is assumed that this "
      "is the location of an older version of Miami or MiamiDx that "
      "you want to upgrade.")
     (help "Select the directory where you want to "
      "install MiamiDx. 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 MiamiDx. An additional directory "
      "will *NOT* be created at the location you specify.")
     (help "Select the directory where you want to "
      "install MiamiDx. 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 MiamiDx 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))
 (if (= #cpu-choice 0)
  (abort "The current version of MiamiDx requires a 68020\n"
   "or higher CPU. A version for 68000/010 may be\n"
   "available at a later time.")
 )
)

(procedure P-select-guis
 (set #gui-options
  (askoptions
   (prompt "Please select which GUI modules you want to use with MiamiDx. The "
    "MUI module requires MUI 3.8 or higher, which has to be installed "
    "BEFORE installing MiamiDx.")
   (help "MiamiDx supports several different user interface engines, "
    "but at the moment only the MUI version is available")
   (choices "MUI")
  )
 )
 (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 MiamiDx.")
  )
  (if (< (/ (getversion "MUI:Libs/muimaster.library") 65536) 18)
   (abort "Your installed MUI version is too old for MiamiDx. "
    "Please upgrade to MUI 3.8 or higher before installing MiamiDx."
   )
  )
 ))
)

(procedure P-select-sana
 (set #sana-choice
  (askbool
   (prompt "Do you want to install sanamni.device in\n"
    "DEVS:Networks ? That device allows you to use\n"
    "some third-party software like Envoy with MNI\n"
    "drivers.")
   (help "MiamiDx supports 'MNI', a new driver standard\n"
    "for Ethernet. sanamni.device allows you to use\n"
    "these new drivers with some older third-party\n"
    "software such as Envoy that usually requires\n"
    "SANA-II drivers")
  )
 )
)

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

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


(procedure P-select-gui
 (if (= 1 (BITAND #gui-options 1))
  ((set #gui-choice-mui "MUI") (set #gui-choice 0))
  (set #gui-choice-mui "")
 )
 (set #gui-choice
  (askchoice
   (prompt "Please select which GUI module you want to use as the default "
    "module for MiamiDx")
   (help "MiamiDx supports several different user interface engines, "
    "but at the moment only the MUI module is available.")
   (choices #gui-choice-mui)
   (default #gui-choice)
  )
 )
 (set #gui-choice-name (select #gui-choice "MUI"))
)

(procedure P-select-icon
 (if (>= #wb-version 44)
  (set #icon-choice-os35 "OS 3.5")
  (set #icon-choice-os35 "")
 )
 (set #icon-choice
  (askchoice
   (prompt "Please select which icons you\nwant to use for MiamiDx and\n"
    "the utility programs:")
   (help "MiamiDx comes with four different\nicon styles. Please select\n"
    "the one you prefer.")
   (choices "do not install new icons" "standard" "Magic Workbench" "NewIcons"
    #icon-choice-os35)
  )
 )
)

(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 "MiamiDx"))
   (noposition)
  )
  (tooltype
   (dest (tackon @default-dest "MiamiInit"))
   (noposition)
  )
  (tooltype
   (dest (tackon @default-dest "MiamiRegister"))
   (noposition)
  )
  (tooltype
   (dest (tackon @default-dest "MiamiDx.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 MiamiDx 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 MiamiDx.")
     (help "It is NECESSARY that an assign "
      "'Miami:' is created for the MiamiDx 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 MiamiDx. "
      "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 "
      "MiamiDx 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 MiamiDx 1.0 installation.\n")

(set app-name "MiamiDx 1.0")

(P-check-system-version)

(if @pretend
  (abort "Pretend mode cannot be used with this\n"
   "installation script.")
)

(complete 0)

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

(P-select-destination-directory)

(complete 5)

(P-select-binary)

(complete 10)

(P-select-icon)

(complete 15)

(P-select-guis)

(P-select-gui)

(P-check-guis)

(P-select-sana)

(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 MiamiDx binary selected by user
(copyfiles
 (source (tackon #source-dir "main/MiamiDx"))
 (dest @default-dest)
 (optional force)
)

(complete 30)

; copy individual files
(set #to-copy "main/MiamiDx.guide") (P-copy-file)
(set #to-copy "main/MiamiAddr") (P-copy-file)
(set #to-copy "main/MiamiArp") (P-copy-file)
(set #to-copy "main/MiamiDiG") (P-copy-file)
(set #to-copy "main/MiamiDNSQuery") (P-copy-file)
(set #to-copy "main/MiamiDod") (P-copy-file)
(set #to-copy "main/MiamiFinger") (P-copy-file)
(set #to-copy "main/MiamiFtp") (P-copy-file)
(set #to-copy "main/MiamiHost") (P-copy-file)
(set #to-copy "main/MiamiIfConfig") (P-copy-file)
(set #to-copy "main/MiamiInit") (P-copy-file)
(set #to-copy "main/MiamiIPFW") (P-copy-file)
(set #to-copy "main/MiamiIPNatD") (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/MiamiNSLookup") (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/MiamiSecureShellKeygen") (P-copy-file)
(set #to-copy "main/MiamiSecureShellKill") (P-copy-file)
(set #to-copy "main/MiamiSysCtl") (P-copy-file)
(set #to-copy "main/MiamiTCPDump") (P-copy-file)
(set #to-copy "main/MiamiTelnet") (P-copy-file)
(set #to-copy "main/MiamiTelnetD") (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 62)

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

(complete 64)

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

(complete 66)

; copy sanamni.device
(if #sana-choice (
 (if (not (exists "DEVS:Networks"))
  (makedir "DEVS:Networks")
 )
 (copyfiles
  (source (tackon #source-dir "main/SANA2"))
  (dest "DEVS:Networks")
  (optional force)
  (all)
 )
))

(complete 68)

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

(complete 70)

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

(complete 80)

; set icons

(if (not (= #icon-choice 0)) (
 (set #to-copy
  (select #icon-choice
   ""
   "main/Icons/Standard/MiamiDx.info"
   "main/Icons/MagicWB/MiamiDx.info"
   "main/Icons/NewIcons/MiamiDx.info"
   "main/Icons/OS3.5/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/MiamiDx.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 "MiamiDx.guide.info")
   )
  )
 ))
))

(complete 85)

(P-set-tooltypes)

(complete 90)

(P-set-envvars)

(complete 95)

(P-add-to-startup)

(complete 100)

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