; Installer script for Professional File System 2
; (c) 1998 GREat Effects Development
;

(transcript "Professional File System 2 Installation")

(procedure afs_message
  (message "Please insert your original Ami-FileSafe disk in drive df0:"
	(all)
  )
  (while (not (exists "df0:" (noreq)))
	(message "Please insert your original Ami-FileSafe disk in drive df0:"
	  (all)
    )
  )
)

(procedure install_fs #installfile #sourcefile #help
  (copyfiles
    (prompt "Copying " #installfile)
    (help #help)
    (source (tackon (tackon #mainpath "fs") #sourcefile))
    (dest "l:")
	(newname #installfile)
	(optional "force" "askuser")
  )

  (set #ok 0)
  (while (= #ok 0)
    (set #rc
	  (run "c/getserial" #cdkey (tackon "l:" #installfile) #username)
    )

	(if (= #rc 4)
	  (afs_message)
	)

	(if (= #rc 3)
	  (abort "Installation failed")
	)

	(if (= #rc 2)
	  (set #ok 1)
	)
  )
)

(procedure dopatch #patchfile #target
  (if (askbool
	    (prompt "Patching " #target)
	    (help "Choose proceed to patch " #target ". The patch makes "
		  "it possible to use PFS2 with multiuser. For the patch to "
		  "succeed the original, not previously patched, version "
		  "of " #target " is needed")
	    (default 1)
	    (choices "Proceed" "Cancel"))

	(if (exists #target)
	  (if (= 0 (run "c/spatch" "-ot:temp" (cat "-p" #patchfile) #target
		    (prompt "Patching " #target)))
		(copyfiles
		  (source "t:temp")
		  (dest (pathonly #target))
		  (newname (fileonly #target))
		  (optional "force")
   	 	)
		(abort #target " could not be patched. Please copy the original,"
		  " not patched, multiuser.library to libs: and try again"
		)
  	  )
	  (abort (fileonly #target) " not found")
	)
  )
)

;-----------------------
; Welcome
;
(welcome "Welcome to the Professional File System 2 Installation"
)


;-----------------------
; Ask for serial number
;
(set #tmp @user-level)
(set #licence 0)
(if (= @user-level 0)
  (user 1)
)
(while (= #licence 0)
  (set #username
	(askstring
		(prompt "Please enter your full name")
		(help "To register PFS2 your name is needed")
	)
  )

  (set #cdkey
	(asknumber
		(prompt "Please enter your CD-key")
		(help "The CD-Key is the number on the sticker at the back of the CD case.")
		(default 0)
	)
  )

  (set #licence 
	(run "c/getserial" #cdkey)
  )

  (if (= #licence 0)
	(message "Invalid CD-Key")
  )
)

(set #language "eng")
(if (<> 0 (BITAND #licence 8))
  (afs_message)
)

(if (<> 0 (BITAND #licence 1))
  ( 
	(set #language "ger")
    (message "Key accepted. Installing German version"
	  (all)
    )
  )
)

(if (<> 0 (BITAND #licence 2))
  ( 
	(set #language "fra")
    (message "Key accepted. Installing French version"
	  (all)
    )
  )
)

(user #tmp)

;--------------------------
; Some defaults
;
(set #root "")
(set #mainpath (tackon #root (tackon "data/" #language)))

;--------------------------
; Ask where to install
;
(set #destdir
  (askdir
    (prompt "Select a directory where you would like to install PFS2 "
    		"documentation and tools. A directory 'PFS2' will be created "
			"here")
    (help	@askdir-help)
	(default "Workbench:tools")
  )
)

(set #destdir (tackon #destdir "pfs2"))
(if (not (exists #destdir))
  (makedir #destdir 
	(infos)
  )
)
(set @default-dest #destdir)
	    		
(set #docdir (tackon #destdir "doc"))
(set #tooldir (tackon #destdir "tools"))
(set #driverdir ("sys:Storage/DosDrivers"))

;--------------------------
; Get CPU
;
(set cpu_any	0)
(set cpu_68020	1)
(set cpu_68040	2)
(set cpu_68060	3)
(set #cpu 0)
(set #cputext (database "cpu"))
(if (patmatch "68000|68010" #cputext) (set #cpu cpu_any))
(if (patmatch "68020|68030" #cputext) (set #cpu cpu_68020))
(if (patmatch "68040" #cputext) (set #cpu cpu_68040))
(if (patmatch "68060" #cputext) (set #cpu cpu_68060))

; Ask expert user for CPU
(if (> @user-level 1)
  (set #cpu
	(askchoice 
	  (prompt
		(cat "Select for which processor you would like to install: " #cputext))
	  (help @askchoice-help) 
	  (choices
		"For 68000 Or 68010"
   		"For 68020 Or 68030"
		"For 68040"
		"For 68060"
      )
	  (default #cpu)
	)
  )
)

(set #cpuext "");
(if (= #cpu cpu_68020) (set #cpuext "020"))
(if (= #cpu cpu_68040) (set #cpuext "040"))
(if (= #cpu cpu_68060) (set #cpuext "060"))

;-------------------------
; Get filesystem options
;
(set mask_normal	1)
(set mask_ds		2)
(set mask_multiuser 4)
(set mask_dsmultiuser 8)
(set mask_floppy	16)
(set #fs_options -1)
(if (not (exists "libs:multiuser.library"))
  (set #fs_options 
	(BITAND #fs_options (BITNOT (BITOR mask_multiuser mask_dsmultiuser)))
  )
)
(if (> @user-level 1)
  (set #fs_options
 	(askoptions
	  (prompt "Select which versions you would like to install:")
	  (help @askoptions-help)
	  (choices
		"Normal version"
		"DirectScsi version"
		"Multiuser version"
		"DirectScsi Multiuser version"
		"Floppy version"
	  )
	)
  )
)



;-------------------------
; Get documentation
;
(set mask_guide 1)
(set #manual -1)
(if (> @user-level 1)
  (set #manual
	(askoptions
	  (prompt "Select the documentation to install:")
	  (help @askoptions-help)
	  (choices
	    "Amigaguide documentation"
	  )
	)
  )
)
	
;-------------------------
; Install PFS2
;
(if (<> 0 (BITAND #fs_options mask_normal))
  ( (install_fs
	  "pfs2"
	  (cat "PFS-II" #cpuext)
	  "Installation of default version"
	)
  )
)

;-------------------------
; Install PFS2ds
;
(if (<> 0 (BITAND #fs_options mask_ds))
  ( (install_fs
	  "pfs2ds"
	  (cat "PFS-II" #cpuext "ds")
	  "Installation of direct scsi version"
	)
  )
)

;-------------------------
; Install multiuser patch
;
(if (<> 0 (BITAND #fs_options (BITOR mask_multiuser mask_dsmultiuser)))
  (dopatch
	(cat "patch/multiuser" #cpuext ".pch")
	  "libs:multiuser.library"
  )
)

;-------------------------
; Install muPFS2
;
(if (<> 0 (BITAND #fs_options mask_multiuser))
  ( (install_fs
	  "mupfs2"
	  (cat "muPFS-II" #cpuext)
	  "Installation of multiuser version"
	)
  )
)

;-------------------------
; Install muPFS2ds
;
(if (<> 0 (BITAND #fs_options mask_dsmultiuser))
  ( (install_fs
	  "mupfs2ds"
	  (cat "muPFS-II" #cpuext "ds")
	  "Installation of direct scsi multiuser version"
	)
  )
)

;-------------------------
; Install floppyPFS
;
(if (<> 0 (BITAND #fs_options mask_floppy))
  ( 
	(install_fs
	  "floppyPFS"
	  "floppyPFS"
	  "Installation of floppy version"
	)

    (copyfiles
	  (prompt "Installing dosdrivers")
	  (help @copyfiles-help)
	  (source (tackon #root "devs"))
	  (dest #driverdir)
	  (all)
	  (infos)
	  (confirm)
    )
  )
)

;-------------------------
; Install Tools
;
(copyfiles
  (prompt "Installing tools")
  (help @copyfiles-help)
  (source (tackon #root "tools"))
  (dest #tooldir)
  (all)
  (infos)
  (confirm)
)

;-------------------------
; Install docs
;
(if (<> 0 (BITAND #manual mask_guide))
  (copyfiles
    (prompt "Installing documentation in guide form")
    (help "The AmigaGuide files installed are the usermanual, "
    	  "the tools manuals and the programming information"
    )
    (source (tackon #mainpath "doc"))
    (dest #docdir)
    (all)
	(infos)
    (confirm)
  )
)

(exit
)
