;******************************************************************************
;         __  __                                     
;        / / / /                                    
;       / / / /______ __  __ ______  ______ ______ _____
;      / / / // __  / \ \/ // __  / / __  // ____// .__/
;     /  \/ // /_/ /   \  // __  / / /_/ // __/_ / /
;     \____//_____/    / //_/ /_/ _\__  //_____//_/
;                     /_/        /_____/   
;
; $VER: 1.0e_Voyager_Installer (May-03-1996) 
; Changes, suggestions or problems: rcr@netcom.com
; May not be hacked into any "internet pack"!
; If you wish to use any part of this installer you must ask.
;
; Installer by Robert C. Reiswig ©1995, 1996 
; Voyager by Oliver Wagner ©1995, 1996 
;******************************************************************************
;*** System Stuff ***
(set cpu (database "cpu"))  (set vblank (database "vblank"))
(set graphmem (database "graphics-mem")) (set totmem (database "total-mem"))
(set osver (/ (getversion "LIBS:version.library") 65536))
(if (= vblank "60") ((set blank "NTSC")) ((set blank "PAL")))
(set fastmem (- totmem graphmem))

(if (= osver 37) (set workbench "2.0")) (if (= osver 38) (set workbench "2.1"))
(if (= osver 39) (set workbench "3.0")) (if (= osver 40) (set workbench "3.1"))
(if (= osver 41) (set workbench "3.2"))

(set cpu (database "cpu"))
(if (= cpu 68000) (set #cpu 0)) (if (= cpu 68010) (set #cpu 1))
(if (= cpu 68020) (set #cpu 2)) (if (= cpu 68030) (set #cpu 3))
(if (= cpu 68040) (set #cpu 4)) 
(if (> (exists ("sys:libs/68060.library")) 0) (set #cpu 5) )

(set vernum1 (getversion "V")) (set ver1 (/ vernum1 65536)) 
(set rev1 (- vernum1 (* ver1 65536) ) ) (set Voyagerver (cat ver1 "." rev1))

(if (> (exists ("env:Language")) 0) (set lanfound (getenv "Language")) )
(set lan 0)

(if (= "english"    lanfound) (set lan 0))  (if (= "deutsch"    lanfound) (set lan 1))
(set #English    "English")  (set #Deutsch    "Deutsch")

(set mfound 0) (set newicon1 1) 
(set keeper 1) (set firsttime 0)

(set TELNET_APP-A "amitcp:bin/telnet <>con://640/256/Telnet/SCREEN* %h %p")
(set TELNET_APP-I "inet:bin/telnet %h %p")
(set MAILTO_APP "<path:program><needed-option> %h")
(set WWWPROXY "<proxy server>")
(set WWWPROXYPORT "<proxy port>")
;********************************************************************
; English Strings
;********************************************************************
(set #about (cat "\n\n\n\nWelcome to Voyager " Voyagerver "\n\n\nCopyright © 1995,1996 by\n\nOliver Wagner\n") )
(set #installup " Install or Update Voyager")
(set #clearcache " Clear Cache Directory")
(set #task "\nWhat would you like to do?\n")
(set #whereVoyager "Where do you wish to install Voyager. The directory 'Voyager' will be created if it is not there. If a copy of Voyager is found it will be backed up.")
(set muiver "No Version Installed")
(set #newermui "\nVoyager needs version 3.3 or higher of MUI installed to work correctly.\n\nNow would be a good time to Upgrade!\n\nYou can find mui33usr.lha on Aminet in dev/gui\n\nIt looks like you have: \n\n")
(set #need-os "\n\nVoyager needs version 3.0 or higher of the Amiga OS installed to work correctly.\n\n It looks like you have: \n\n")
(set #000used "\n\nThe 68000 version will be installed.") 
(set #nompc "\nThe .MPC files for Voyager can not be installed to 'mui:libs/mui'")
(set #filethere1 "\n\nThe installer has found Voyager version ")
(set #filethere2 " at ")
(set #filethere3 "\n\nThe file will be renamed to ")
(set #filethere4 " and it will then be moved to ")
(set #backuptoXXX "Back-UP to file named 'Voyager.")
(set #copyover "Copy Over Old Version")
(set #oktodelete1 "\nIs it ok to delete the older Voyager binary so that the Voyager Directory can be made?\n")
(set #oktodelete2 "\nIs it ok to delete the older _renamed_ Voyager binary so that the Voyager Directory can be made?\n")
(set #Voyagerfound "\nThe Installer has found a copy of Voyager already installed. What do you want to do?\n")
(set #no020found "\n\nThe 68020 Version of Voyager, V020, was not found in this archive the 68000 version was installed.")
(set #newicon "\nDo you wish to copy over The Voyager Icon from the archive? If you have any ToolTypes already set you should select no.\n")
(set #nonewicon  "No  - ToolTypes already set.")
(set #yesnewicon "Yes - Copy over Icon.")
(set #yesnewicon "Yes - Copy over Icon.")
(set #whatcat "\nSelect the ALabTV Language catalog you wish to install.\n")
(set #wherecat "\nWhere do you wish to install the Voyager Language Catalog? Default is ")
(set #catnofind "Can not find this catalog in this Voyager archive. You may need to get a newer archive.")
(set #whatdocs "\nWhat Voyager documentation would you like to install?\n")
(set #wheredocs "Where would you like the Voyager documentation you selected to be installed?")
(set #byebye (cat "\nVoyager Install Complete!\n\n" ))

(set #whatenv "\nWhat Environment Variables do you wish to set?\n")
(set #telnet " TELNET_APP - Set telnet:")
(set #mailto " MAILTO_APP - Set mailto:")
(set #wwwproxy " WWWPROXY & WWWPROXYPORT - Proxy")
(set #telnetset "Enter the Program and command line option(s) you wish Voyager to call when you select a telnet: address. If you have 'env:Voyager/TELNET_APP' set it will be displayed below, if not a default/example will be filled in. (%h=host, %p=port)")
(set #mailopt "\nPlease select the Program that you use to post email with.\n") 
(set #mailset "Enter the Program and command line option(s) you wish Voyager to call when you select a mailto: address. If you have 'env:Voyager/MAILTO_APP' set it will be displayed below, if not an example will be shown. (%h=email-address)")
(set #wwwpset "\nPlease enter the Proxy Server you wish to use.\n")
(set #wwwppset "\nPlease enter the Proxy Port you wish to use.\n")

(set #updateinstaller "\nJust to let you know ESCOM AG has released a new version of the installer, Version 43.1\n\n\nIt can be found on Aminet in:\n\n/util/misc/Installer-43_1.lha\n\n\nYou might want to upgrade soon.")

;********************************************************************
; German Strings
;********************************************************************
(if (= lan 1)
 (set OlliDontShareThePizza TRUE)
)

;********************************************************************
; Hello
;********************************************************************
(message #about)
(welcome) 

;********************************************************************
; Checks for MUI & OS versions
;********************************************************************
(set ver 0)
(if (<> (getassign "mui") "")
(
  (if (exists "mui:mui") 
   (
    (set vernum (getversion "mui:mui") )
    (set ver (/ vernum 65536)) (set rev (- vernum (* ver 65536) ) )

    (if (= ver 7) (set muiver "2.0") )   (if (= ver 8) (set muiver "2.1") )
    (if (= ver 9) (set muiver "2.2") )   (if (= ver 10) (set muiver "2.3") )
    (if (= ver 11) (set muiver "3.0") )  (if (= ver 12) (set muiver "3.1") )
    (if (= ver 13) (set muiver "3.2") )  (if (= ver 14) (set muiver "3.3") )
    (if (= ver 15) (set muiver "3.4") )  (if (= ver 16) (set muiver "3.5") )
   )
  )
)
)

(if (< ver 14)   ( (message (cat #newermui muiver))   (set cpuPick 0) ))
(if (< osver 39) ( (message (cat #need-os workbench)) (set cpuPick 0) ))

;********************************************************************
; Ask where to put Voyager & Make dir if needed
;********************************************************************
(set Package (getassign "AmiTCP"))
(if (= Package "") (set Package (getassign "Inet")) )

(set Voyagerdir  (askdir (prompt #whereVoyager)
		        (help   #whereVoyager)
     		        (default Package)
               )  
)

(set where Voyagerdir)

;********************************************************************
; Check to see if Voyager is already there, if so ask to backup
;********************************************************************
(if (= 1 (exists (tackon where "V") ) ) 
  (
    (set vernum1 (getversion (tackon where "V") ))
    (set ver1 (/ vernum1 65536)) (set rev1 (- vernum1 (* ver1 65536) ) )
    (set Voyager_old (cat ver1 "." rev1))

    (message (cat #filethere1 ver1 "." rev1 #filethere2 where #filethere3 
                  (cat "V" Voyager_old) #filethere4 (tackon Voyagerdir "V") )
    )
    

    (copyfiles (source (tackon where "V"))
               (dest where) 
               (infos)
               (newname (cat "V." Voyager_old))
    )
    
    (delete (tackon Voyagerdir "V") (prompt #oktodelete1) (help #oktodelete1) (confirm) (infos)) 

    (if (< (exists (tackon Voyagerdir "V")) 2) (makedir (tackon Voyagerdir "V") (infos)) )    

    (copyfiles (source (tackon where (cat "V." Voyager_old) ))
                       (dest (tackon Voyagerdir "V")) 
                       (infos)
               
    )

    (delete (tackon where (cat "V" Voyager_old)) (prompt #oktodelete2) (help #oktodelete2) (confirm) (infos) ) 

    ;(set firsttime 1)

  )
)

(if (< (exists (tackon Voyagerdir "Voyager")) 2) (makedir (tackon Voyagerdir "Voyager") (infos)) )
(set where (tackon Voyagerdir "Voyager"))
(set @default-dest where)

;********************************************************************
; Check for old & backup
;********************************************************************
(if (exists (tackon where "V")) 
  (
      (set vernum1 (getversion (tackon where "V") ))
      (set ver1 (/ vernum1 65536)) (set rev1 (- vernum1 (* ver1 65536) ) )
      (set Voyager_old (cat ver1 "." rev1))

      (set keeper  (askchoice (choices  (cat #backuptoXXX Voyager_old "'")  #copyover)
                     (prompt #Voyagerfound)
	             (help   #Voyagerfound)
                     (default 0)
	           )
      )    


      (if (= keeper 0)
         (copyfiles (source (tackon where "V"))
                     (dest where) 
                     (infos)
                     (newname (cat "V" Voyager_old))
         )
      )          

      (set firsttime 1)
    
  )
)

;********************************************************************
; Copy over correct Voyager and Icon if wanted
;********************************************************************
(if (AND (> #cpu 1) (exists ("V020")) )
 (copyfiles (source "V020") (dest where) (newname "V") (optional "nofail") )
 (copyfiles (source "V") (dest where) (optional "nofail") )
)

(if (AND (> #cpu 1) (= (exists ("V020")) 0) )
 (message #no020found)
)


(if (= firsttime 0)  (copyfiles (source "V.info") (dest where) (optional "nofail") ) )

(if (OR (= keeper 0) (= (exists (tackon where "V.info")) 0))
  (
  
   (set newicon (askchoice (choices #yesnewicon #nonewicon)
                           (prompt #newicon)
	                   (help   #newicon)
                           (default 0)
	        )
   )
  
   (if (= newicon 0) 
     (copyfiles (source "V.info") (dest where)  (optional "nofail") )
   )

  )

)

;********************************************************************
; Copy over Other stuff & config stuff *IF* not there!
;********************************************************************
(copyfiles (source "CacheBrowser") (dest where) (infos) (optional "nofail") ) 

(if (= (exists (tackon where "Bookmarks.ASC")) 0)
 (if (> (exists "Bookmarks.ASC") 0)
  (copyfiles (source "Bookmarks.ASC") (dest where) (infos) (optional "nofail") ) 
 )
)

(if (= (exists (tackon where "Voyager.prefs")) 0)
 (if (> (exists "Voyager.prefs") 0)
  (copyfiles (source "Voyager.prefs") (dest where) (infos) (optional "nofail") ) 
 )
)

(makedir (tackon where "Cache") (infos))

;********************************************************************
; Copy over DOCS (home.html and Vpics dir) & Other Docs
;********************************************************************
(set docs (askoptions (choices " Docs In HTML format" " V.readme") ;" V.history"
		      (prompt #whatdocs) 
                      (help #whatdocs)
	              (default 3)
	  )
)

(if (<> docs 0)
 (
   (set docsdir (askdir (prompt (cat #wheredocs " (V.readme)" )) ; & V.history
		        (help   (cat #wheredocs " (V.readme)" )) ; & V.history
     		        (default where)
                )  
   )

   (if (IN docs 0)
    (
      (if (< (exists (tackon where "Voyager_home")) 2) (makedir (tackon where "Voyager_home") (infos)) )    
      (if (< (exists (tackon where "Voyager_home/VPics")) 2) (makedir (tackon where "Voyager_home/VPics") (infos)) )    

      (foreach "Voyager_home/VPics" "#?"
         (copyfiles (source (tackon "Voyager_home/VPics" @each-name)) (dest (tackon where "Voyager_home/VPics")) (optional "nofail") ) 
      )

      (copyfiles (source "Voyager_home/home.html") (dest (tackon where "Voyager_home")) (infos) (optional "nofail") )
    )
   )


   (if (IN docs 1) (copyfiles (source "V.readme") (dest docsdir) (infos) (optional "nofail") ) )
   (if (IN docs 2) (copyfiles (source "V.history") (dest docsdir) (infos) (optional "nofail") ) )
   
 )
)

;********************************************************************
; Copy over TOOLS if wanted
;********************************************************************
(if (> (exists "Tools") 0)
 (
  (set #whattools "\nWhat Tools would you like to install? They will be placed in: ")

  (set tools (askoptions (choices " ClearCacheDir" " Uninstall")
	  	         (prompt (cat #whattools (tackon where "Tools\n"))) 
                         (help   (cat #whattools (tackon where "Tools\n")))
	                 (default 1)
             )
  )

  (if (<> tools 0)
   (
     (if (< (exists (tackon where "Tools")) 2) (makedir (tackon where "Tools") (infos)) )    
     (set toolsdir (tackon where "Tools"))   

     (if (IN tools 0) (copyfiles (source "Tools/ClearCacheDir") (dest toolsdir) (infos) (optional "nofail") ) )
     (if (IN tools 1) (copyfiles (source "Tools/Uninstall") (dest toolsdir) (infos) (optional "nofail") ) )
   
   )
  )
 
 )
)
;******************************************************************************** 
; Copy over rexx stuff
;********************************************************************************
(if (< (exists (tackon where "rexx")) 2) (makedir (tackon where "rexx") (infos)) )    

(if (> (exists "rexx") 0)
  (foreach "rexx" "#?"
     (copyfiles (source (tackon "rexx" @each-name)) (dest (tackon where "rexx")) (optional "nofail") ) 
  )
)

;********************************************************************
; Copy over #?.mpc|#?.mcc (Need to be in mui:libs/mui)
;********************************************************************
(if (<> (getassign "mui") "")
(
  (if (> (exists "mui:libs/mui") 0)
   (
      (foreach "mui" "#?.mpc"
         (copyfiles (source (tackon "mui" @each-name)) (dest "mui:libs/mui") (optional "nofail") ) 
      )
    
      (foreach "mui" "#?.mcc"
         (copyfiles (source (tackon "mui" @each-name)) (dest "mui:libs/mui") (optional "nofail") ) 
      )
 
   )

   (message (cat #newermui muiver #nompc)) 
 
  )

)
)

;********************************************************************
; setting-changing env settings 
;********************************************************************
(set envset (askoptions (choices #telnet #mailto #wwwproxy)
		        (prompt #whatenv)
                        (help #whatenv)
	                (default 3)
            )
)


(if (<> envset 0)
 (
   (if (= (exists "ENV:Voyager") 0) (makedir "ENV:Voyager") )    
   (if (= (exists "ENVARC:Voyager") 0) (makedir "ENVARC:Voyager") )    

   (if (IN envset 0) 
     (

       (set Package (getassign "AmiTCP"))
       (if (= Package "")
          (set TELNET_APP  TELNET_APP-I)
          (set TELNET_APP  TELNET_APP-A)
       )
 
       (if (> (exists ("env:Voyager/TELNET_APP")) 0) (set TELNET_APP (getenv "Voyager/TELNET_APP")) )
       (set TELNET_APP (askstring (prompt #telnetset)
                                  (help   #telnetset)
                                  (default TELNET_APP)
	               )
       )
       
       (delete "ENV:Voyager/TELNET_APP")
       (textfile (dest "ENV:Voyager/TELNET_APP") (append TELNET_APP) )
       (delete "ENVARC:Voyager/TELNET_APP")
       (textfile (dest "ENVARC:Voyager/TELNET_APP") (append TELNET_APP) )
     
     )
   )


   (if (IN envset 1) 
     (

       (set mailop (askchoice (choices "Thor" "Yam" "smtppost" "Other"
                               (prompt #mailopt)
	                       (help #mailopt)
          		       (default 0)
 	                      )
                   )
       )


       (if (= mailop 0)
         (
           (delete "ENV:Voyager/MAILTO_APP")
           (textfile (dest "ENV:Voyager/MAILTO_APP") (append (cat "rx \"" (tackon (tackon where "rexx") "MailTo-THOR.VRX") "\" %h")) )
           (delete "ENVARC:Voyager/MAILTO_APP")
           (textfile (dest "ENVARC:Voyager/MAILTO_APP") (append (cat "rx \"" (tackon (tackon where "rexx") "MailTo-THOR.VRX") "\" %h")) )
         )
       )

       (if (= mailop 1)
         (
           (delete "ENV:Voyager/MAILTO_APP")
           (textfile (dest "ENV:Voyager/MAILTO_APP") (append (cat "rx \"" (tackon (tackon where "rexx") "MailTo-YAM.VRX") "\" %h")) )
           (delete "ENVARC:Voyager/MAILTO_APP")
           (textfile (dest "ENVARC:Voyager/MAILTO_APP") (append (cat "rx \"" (tackon (tackon where "rexx") "MailTo-YAM.VRX") "\" %h")) )
         )
       )

       (if (= mailop 2)
         (
           (delete "ENV:Voyager/MAILTO_APP")
           (textfile (dest "ENV:Voyager/MAILTO_APP") (append (cat "rx \"" (tackon (tackon where "rexx") "mailsmtppost") "\" %h")) )
           (delete "ENVARC:Voyager/MAILTO_APP")
           (textfile (dest "ENVARC:Voyager/MAILTO_APP") (append (cat "rx \"" (tackon (tackon where "rexx") "mailsmtppost") "\" %h")) )
         )
       )


       (if (= mailop 3)
         (
           (if (> (exists ("env:Voyager/MAILTO_APP")) 0) (set MAILTO_APP (getenv "Voyager/MAILTO_APP")) )
           (set MAILTO_APP (askstring (prompt #mailset)
                                      (help   #mailset)
                                      (default MAILTO_APP)
	                   )
           )
       
           (delete "ENV:Voyager/MAILTO_APP")
           (textfile (dest "ENV:Voyager/MAILTO_APP") (append MAILTO_APP) )
           (delete "ENVARC:Voyager/MAILTO_APP")
           (textfile (dest "ENVARC:Voyager/MAILTO_APP") (append MAILTO_APP) )
         )
       )


     )
   )


   (if (IN envset 2) 
     (
       (if (> (exists ("env:Voyager/WWWPROXY")) 0) (set WWWPROXY (getenv "Voyager/WWWPROXY")) )  
       (set WWWPROXY  (askstring (prompt #wwwpset)
                                 (help   #wwwpset)
                                 (default WWWPROXY)
	              )
       )

       (delete "ENV:Voyager/WWWPROXY")
       (textfile (dest "ENV:Voyager/WWWPROXY") (append WWWPROXY) )
       (delete "ENVARC:Voyager/WWWPROXY")
       (textfile (dest "ENVARC:Voyager/WWWPROXY") (append WWWPROXY) )


       (if (> (exists ("env:Voyager/WWWPROXYPORT")) 0) (set WWWPROXYPORT (getenv "Voyager/WWWPROXYPORT")) )  
       (set WWWPROXYPORT (askstring (prompt #wwwppset)
                                    (help   #wwwppset)
                                    (default WWWPROXYPORT)
                         )
       )

       (delete "ENV:Voyager/WWWPROXYPORT")
       (textfile (dest "ENV:Voyager/WWWPROXYPORT") (append WWWPROXYPORT) )
       (delete "ENVARC:Voyager/WWWPROXYPORT")
       (textfile (dest "ENVARC:Voyager/WWWPROXYPORT") (append WWWPROXYPORT) )  

     )
   )


 )
)

;********************************************************************
; Check on New installer 
;********************************************************************
(set vernum1 @installer-version) (set ver1 (/ vernum1 65536)) 
(set rev1 (- vernum1 (* ver1 65536) ) ) (set InstallerVer (cat ver1 "." rev1))

;(if (< InstallerVer 43.1)
; (message #updateinstaller)
;)

;********************************************************************
; End Bye 
;********************************************************************
(if (> (exists ("c:multiview")) 0) (set #mpath "c:") )
(if (> (exists ("sys:Utilities/multiview")) 0) (set #mpath "sys:Utilities") )
(run (cat "run " #mpath "/multiview V.readme") )

(exit #byebye (quiet))
