;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; *** MuPAD installer script ***
;;
;; $VER: install_mupad_deu 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\nBitte legen Sie die Diskette\n\n%s\n\n"
		"in ein beliebiges Laufwerk!")
)
(set #choose-libs-text
	(cat "Welche Bibliotheken wollen Sie installiert haben?")
)
(set #copy-libs-text
	(cat "\n\n\nInstalliere die Bibliothek\n\n%s\n\nto \"%s\"")
)
(set #copy-hilf-text
	(cat "\n\n\n\nInstalliere die Hilfedateien\n\nto \"%s\"")
)
(set #inst-bin-text
	(cat "\n\n\n\nInstalliere die Programmdateien\n\nto \"%s\"")
)
(set #makedir-text
	(cat "\n\n\n\nErzeuge das Verzeichnis\n\n"
		"\"%s\""
	)
)
(set #startup-text
	(cat "\nDie folgenden Zeilen werden in\n"
		"Ihre S:user-startup eingefügt:\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 "Wo sollen MuPAD und Zusätze installiert werden?\n"
		"(ein Verzeichnis \"MuPAD\" wird dort erstellt)"
	)
)
(set #choice-bin	"MuPAD Programmdateien (~826 KB)")
(set #choice-lib	"MuPAD Bibliotheken    (~2.2 MB)")
(set #choice-help	"MuPAD Hilfedateien    (~462 KB)")
(set #choice-ixemu	"ixemul.library V42.0  (~110 KB)")
(set #install-mupad-text
	(cat "Welche Teile von MuPAD wollen Sie installieren?"
	)
)
(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** Dies ist eine ENTWICKLER VERSION von MuPAD **\n\n"
		"- Es ist nicht erlaubt diese zu Verbreiten   \n"
		"- Fehler und Abstürze sind vorprogrammiert   \n"
		"- Wir werden keine Verantwortung für evt.    \n"
		"  Beschädigungen und Datenverluste übernehmen\n"
		"  die durch den Gebrauch dieser Software ent-\n"
		"  standen sind.                              \n"
		"- nur die ``tty'' Version ist verfügbar.     \n\n"
		"Beenden Sie JETZT wenn Sie die diese Vereinbarungen "
		"nicht akzeptieren wollen."
	)
) 
(set #finish-text
	(cat "Was Sie jetzt noch erledigen müssen:\n\n"
		"- Kaufen Sie sich ein MuPAD Buch!     \n"
		"- Lesen Sie die \"Liesmich\" Datei!   \n"
		"\nMuPAD wurde portiert auf den Amiga von\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)
