; $VER: Install_MiamiSSL 2.21 (15.04.2000)
(procedure check-system-version
 (set #exec-version (/ (getversion) 65536))
 (if (< #exec-version 37)
  (abort "MiamiSSL needs Kickstart 2.04 or higher.\n")
 )
 (if (< #exec-version 39)
  (set #ag-browser "AmigaGuide")
  (set #ag-browser "MultiView")
 )
)

(procedure select-destination-directory
 (set @default-dest "Miami:")
)

(procedure select-lib
 (set lib-choice
  (askchoice
   (prompt "Please select which version of\nthe encryption library you want to use:")
   (help "There are two MiamiSSL encryption,one\nfor users within the USA/Canada and one\n"
    "for all other users.")
   (choices "US/Canadian version" "International version")
  )
 )
)

(procedure check-registered
 (set is-registered (exists (tackon @default-dest "Miami.key2")))
 (if (not is-registered)
  (abort "MiamiSSL needs the registered version of Miami 2.1 or higher")
 )
)

(procedure check-library
 (set bin-choice
  (select lib-choice
   "miamisslusa.library"
   "miamisslintl.library"
  )
 )
 (if (not (exists (tackon @default-dest (cat "Libs/orig" bin-choice))))
  (abort "Before you can install MiamiSSL you first need to\n"
   "get one of the encryption library. Please see the\n"
   "included README_ssl.txt file for more information.")
 )
)

(procedure copy-files
  (if (not (exists (tackon @default-dest "Libs")))
   (makedir (tackon @default-dest "Libs"))
  )
  (if (exists (tackon @default-dest (cat "Libs/" bin-choice)))
   (delete (tackon @default-dest (cat "Libs/" bin-choice)) force)
  )
  (select lib-choice
   (
    (run (cat "\"" (tackon source-dir "xpatch") "\" Miami:libs/origmiamisslusa.library \""
     (tackon source-dir "miamisslusa.xpch") "\" Miami:libs/miamisslusa.library"))
   )
   (
    (run (cat "\"" (tackon source-dir "xpatch") "\" Miami:libs/origmiamisslintl.library \""
     (tackon source-dir "miamisslintl.xpch") "\" Miami:libs/miamisslintl.library"))
   )
  )
  (if (not (exists (tackon @default-dest "SSL")))
   (makedir (tackon @default-dest "SSL"))
  )
  (if (not (exists (tackon @default-dest "SSL/v2certs")))
   (makedir (tackon @default-dest "SSL/v2certs"))
  )
  (if (not (exists (tackon @default-dest "SSL/lib")))
   (makedir (tackon @default-dest "SSL/lib"))
  )
  (if (not (exists (tackon @default-dest "SSL/private")))
   (makedir (tackon @default-dest "SSL/private"))
  )
  (copyfiles
   (source (tackon source-dir "certs"))
   (dest (tackon @default-dest "SSL/v2certs"))
   (all)
  )
  (copyfiles
   (source (tackon source-dir "ssl.config"))
   (dest (tackon @default-dest "SSL/lib"))
  )
  (copyfiles
   (source (tackon source-dir "MiamiSSLCiphers"))
   (dest @default-dest)
  )
  (copyfiles
   (source (tackon source-dir "MiamiSSLClient"))
   (dest @default-dest)
  )
  (copyfiles
   (source (tackon source-dir "MiamiSSLVersion"))
   (dest @default-dest)
  )
  (copyfiles
   (source (tackon source-dir "MiamiSSLIDEA"))
   (dest @default-dest)
  )
  (copyfiles
   (source (tackon source-dir "MiamiSSLUSAArcFour"))
   (dest @default-dest)
  )
  (copyfiles
   (source (tackon source-dir "MiamiSSL.guide"))
   (dest @default-dest)
  )
  (copyfiles
   (source (tackon source-dir "MiamiSSL.guide.info"))
   (dest @default-dest)
  )
  (tooltype
   (dest (tackon @default-dest "MiamiSSL.guide"))
   (noposition)
   (setdefaulttool #ag-browser)
  )
  (if (not (exists "ENV:MIAMI"))
   (makedir "ENV:MIAMI")
  )
  (if (not (exists "ENVARC:MIAMI"))
   (makedir "ENVARC:MIAMI")
  )
  (textfile
   (dest "ENV:MIAMI/SSLLIB")
   (append (tackon @default-dest (tackon "Libs/" bin-choice)))
  )
  (copyfiles
   (source "ENV:MIAMI/SSLLIB")
   (dest "ENVARC:MIAMI")
  )
)

;;;; Start

(welcome "Welcome to the MiamiSSL installation.\n")

(set app-name "MiamiSSL")

(check-system-version)

(complete 0)

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

(select-destination-directory)

(check-registered)

(select-lib)

(check-library)

(complete 75)

(copy-files)

(complete 100)
