;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; *** MuPAD installer script ***
;;
;; $VER: install_mupad_eng 2.0 (31.1.1996)
;; Copyright © 1996 Daniel Balster
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; TODO:
;;
;;	- system check (cpu,fpu,ram,harddisk-space)
;;
;;	- ixemul disk
;;

;;(set @default-dest "RAM:")

(set #disk1 "MuPAD Disk 1")
(set #disk2 "MuPAD Disk 2")
(set #disk3 "MuPAD Disk 3")

;;;;;;;; locale strings ;;;;;;;;;

(set #hello-message
	(cat	"\n\n\nMuPAD\n\n"
		"Multi Processing Algebra Data Tool\n\n\n"
		"Copyright ©1992-96 by Benno Fuchsteiner,\n"
		"Automath, University of Paderborn, Germany.\n"
	)
)

(set #askdisk-text
	(cat "\n\n\n\nPlease insert the disk\n\n%s\n\nin any drive")
)
(set #choose-libs-text
	(cat "Choose the library packages you want to install")
)
(set #copy-libs-text
	(cat "\n\n\nInstalling the library package\n\n%s\n\nto \"%s\"")
)
(set #copy-hilf-text
	(cat "\n\n\n\nInstalling the help files\n\nto \"%s\"")
)
(set #inst-bin-text
	(cat "\n\n\n\nInstalling the program files\n\nto \"%s\"")
)
(set #makedir-text
	(cat "\n\n\n\nCreating drawer\n\n"
		"\"%s\""
	)
)
(set #startup-text
	(cat "\nThe following lines will be added\n"
		"to your S:user-startup file:\n\n\n"
		";BEGIN MuPAD             \n"
		"ASSIGN MuPAD: <your path>\n"
		"PATH MuPAD:BIN ADD       \n"
		"SETENV PAGER MORE        \n"
		";END MuPAD               \n"
	)
)
(set #dest-dir-text
	(cat "Where should MuPAD and its files be installed?\n"
		"(a drawer called \"MuPAD\" will be created there)"
	)
)
(set #choice-bin	"MuPAD program binaries (~826 KB)")
(set #choice-lib	"MuPAD library packages (~2.2 MB)")
(set #choice-help	"MuPAD help files       (~462 KB)")
(set #choice-ixemu	"ixemul.library V42.0   (~110 KB)")
(set #install-mupad-text
	(cat "Which parts of MuPAD do you want to install?"
	)
)
(set #missing-ixemul-text
	(cat "Sorry, but the \"MuPAD Disk 3\" is still not ready "
		"due to copyright reasons. It should contain the\n"
		"ixemul.library Version V42.0\n"
		"and utilities, which are highly required to get "
		"MuPAD to work. But you can obtain these stuff FREELY from "
		"any Aminet(R) site; just search for \"ixemul\" there!\n\n"
		"Suggested sites:\n"
		"ftp.wustl.edu, ftp.uni-paderborn.de\n\n"
		"We hope to fix this as fast as possible!\n"
	)
)
(set #warning-text
	(cat "\n\n** This is a DEVELOPERS VERSION of MuPAD **\n\n"
		"- you are not allowed to spread or copy it   \n"
		"- bugs, crashes and gurus WILL happen        \n"
		"- we won't take any responsibility for any   \n"
		"  damages or data losses caused by the usage \n"
		"  of this version of MuPAD.                  \n"
		"- only the ``tty'' version is available yet  \n\n"
		"Abort NOW if you don't accept this aggreements!"
	)
)
(set #finish-text
	(cat "Things you should do now:\n\n"
		"- Go and buy a MuPAD book!            \n"
		"- Read the supplied \"Readme\" file!  \n"
		"\nMuPAD was ported to the Amiga by\n"
		"Daniel Balster, <dbalster@uni-paderborn.de"
	)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(procedure askdisk1
	(askdisk
		(prompt (#askdisk-text #disk1))
		(dest #disk1)
		(help @askdir-help)
	)
)

(procedure askdisk2
	(askdisk
		(prompt (#askdisk-text #disk2))
		(dest #disk2)
		(help @askdir-help)
	)
)

(procedure askdisk3
	(askdisk
		(prompt (#askdisk-text #disk3))
		(dest #disk3)
		(help @askdir-help)
	)
)

(set progress 0)

;; system check here !! still todo

;; returns a bitmask in lib-files
;;
(procedure choose-libs
	(if (= @user-level 2) ;; only the expert wants to see this list
		(set lib-files
			(askoptions
				(prompt #choose-libs-text)
				(help @askoptions-help)
				(choices
					"ASSUME"		"BASEFILES"	"C0MBINAT"	"D0MAINS"
					"FACLIB"		"FP"			"GCDLIB"		"GENERATE"
					"GR0EBNER"	"INTLIB"		"ISA"		"LIBFILES"
					"LINALG"		"L0GIC"		"MISC"		"M0DULE"
					"MSYMM"		"NETW0RK"		"NFINT"		"NUMERIC"
					"NUMLIB"		"0DE"		"0RTHP0LY"	"PL0TLIB"
					"SERIES"		"SHARE"		"SPECFUNC"	"STATS"
					"STDLIB"		"STUDENT"		"TEST"		"TYPE"
				)
				(default $ffffffff)
			)
		)
	)
	(set lib-files $ffffffff)
	(set lib-count 32)
)

(procedure inst-bin
	(set @execute-dir
		dest-dir
	)
	(set name
		"bin"
	)
	(set themessage
		(#inst-bin-text dest-dir)
	)
	(set thecommand
		(cat "RAM:LHEX -f x \"" #disk1 ":files/" name ".lha\"")
	)
	(working themessage)
	(run thecommand)
	(complete (set progress (+ progress 20)))
)

(procedure copy-hilf
	(set @execute-dir
		dest-dir
	)
	(set name
		"help"
	)
	(set themessage
		(#copy-hilf-text dest-dir)
	)
	(set thecommand
		(cat "RAM:LHEX -f x \"" #disk1 ":files/" name ".lha\"")
	)
	(working themessage)
	(run thecommand)
	(complete (set progress (+ progress 10)))
)

(procedure copy-libs
	(makedir (tackon dest-dir "lib"))
	(set @execute-dir
		(tackon dest-dir "lib")
	)
	(set n 0)
	(while (< n lib-count)
		(if (bitand lib-files (shiftleft 1 n))
			(;;begin
				(set name
					(select n
						"ASSUME"		"BASEFILES"	"C0MBINAT"	"D0MAINS"
						"FACLIB"		"FP"			"GCDLIB"		"GENERATE"
						"GR0EBNER"	"INTLIB"		"ISA"		"LIBFILES"
						"LINALG"		"L0GIC"		"MISC"		"M0DULE"
						"MSYMM"		"NETW0RK"		"NFINT"		"NUMERIC"
						"NUMLIB"		"0DE"		"0RTHP0LY"	"PL0TLIB"
						"SERIES"		"SHARE"		"SPECFUNC"	"STATS"
						"STDLIB"		"STUDENT"		"TEST"		"TYPE"
					)
				)
				(set percent	;; estimated percent of whole package
					(select n
						1	1	1	8
						4	1	1	1
						1	4	1	3
						4	1	1	1
						1	1	1	1
						1	1	1	1
						1	2	2	1
						10	1	1	1
					)
				)
				(set themessage
					(#copy-libs-text name dest-dir)
				)
				(set thecommand
					(cat "RAM:LHEX -f x \"" #disk2 ":files/" name ".lha\"")
				)
				(working themessage)
				(run thecommand)
				(complete (set progress (+ progress percent)))
			);;end
		)
		(set n (+ n 1))
	)
)

(procedure install-mupad
	(set install-what
		(askoptions
			(prompt #install-mupad-text)
			(help @askoptions-help)
			(choices
				#choice-bin
				#choice-help
				#choice-lib
				#choice-ixemu
			)
		)
	)
	
	(if (BITAND install-what 1)
		(inst-bin)
	)
	(if (BITAND install-what 2)
		(copy-hilf)
	)
	(if (BITAND install-what 4)
		(
			(choose-libs)
			(askdisk2)
			(copy-libs)
		)
	)
	(if (BITAND install-what 8)
	;;	(askdisk3)
		(message
			#missing-ixemul-text
		)
	)
)

(message #hello-message)
(message #warning-text)

;; Make sure we are working with the correct disk
;;
(askdisk1)

(complete 0)

;; Cache the extractor "LHEX"
;;
(copyfiles
	(source (cat #disk1 ":C/LHEX"))
	(dest "RAM:")
	(files)
	(optional fail force askuser)
	(safe)
)

;; Let the user choose the destination
;;
(set dest-dir
	(tackon
		(askdir
			(prompt #dest-dir-text)
			(help @askdir-help)
			(default @default-dest)
		)
		"MuPAD"
	)
)

(makedir dest-dir
	(prompt (#makedir-text dest-dir))
	(help @makedir-help)
	(confirm)
	(infos)
	(safe)
)

(install-mupad)

(complete 99)
(startup "MuPAD"
	(prompt #startup-text)
	(command
		"Assign MuPAD: \""dest-dir"\"\n"
		"path MuPAD:bin add\n"
		"setenv PAGER more"
		)
	(help @startup-help)
)

;; Delete the extractor from RAM:
;;
(delete "RAM:LHEX"
	(optional force askuser)
	(safe)
)

(complete 100)

(exit #finish-text)
