; $Id: Install 1.6 1997/02/07 19:31:38 angela Exp $
; $VER: Install-MakeCD 2.0 (7.2.97)



(procedure P_GET_LANG_FROM_ENV
	(
		(if (exists "ENV:Language")
			(if (patmatch (getenv "language") txt_lang_0)
				0
				(if (patmatch (getenv "language") txt_lang_1)
					1
					1
				)
			)
			(if (patmatch @language txt_lang_0)
				0
				(if (patmatch @language txt_lang_1)
					1
					1
				)
			)
		)
	)
)



(procedure P_SELECT_LANGUAGE
	(
		(set txt_lang_0 "Deutsch")    (set txt_langdir_0 "deutsch")
		(set txt_lang_1 "English")    (set txt_langdir_1 "english")
		(set txt_lang_2 "Français")   (set txt_langdir_2 "français")
		(set txt_lang_3 "Italiano")   (set txt_langdir_3 "italiano")
		(set txt_lang_4 "Nederlands") (set txt_langdir_4 "nederlands")
		(set txt_lang_5 "Norsk")      (set txt_langdir_5 "norsk")
		(set txt_lang_6 "Suomi")      (set txt_langdir_6 "suomi")
		(set txt_lang_7 "Svenska")    (set txt_langdir_7 "svenska")
		(set txt_lang_8 "")           (set txt_langdir_8 "")
		(set txt_lang_9 "")           (set txt_langdir_9 "")

		(set numlangs 2)

		(if (AND (= 0 origuserlevel) (exists "ENV:Language"))
			(
				(set langnum P_GET_LANG_FROM_ENV)
			)
			(
				(user 2)
				(set langnum
					(askchoice
						(prompt "Choose the language to be used in this installer script.")
						(help "Please select your favourite language.\n\n" "Bitte wählen Sie ihre bevorzugte Sprache.")
						(choices
							txt_lang_0
							txt_lang_1
						)
						(default
							P_GET_LANG_FROM_ENV
						)
					)
				)
				(user origuserlevel)
			)
		)

		(if (= langnum 0) (set langstring txt_lang_0))
		(if (= langnum 1) (set langstring txt_lang_1))
		(if (= langnum 2) (set langstring txt_lang_2))
		(if (= langnum 3) (set langstring txt_lang_3))
		(if (= langnum 4) (set langstring txt_lang_4))
		(if (= langnum 5) (set langstring txt_lang_5))
		(if (= langnum 6) (set langstring txt_lang_6))
		(if (= langnum 7) (set langstring txt_lang_7))
		(if (= langnum 8) (set langstring txt_lang_8))
		(if (= langnum 9) (set langstring txt_lang_9))

		(if (not (exists "ENV:Language"))
			(
				(run ("%s%s" "setenv Language " langstring))
			)
		)


		; Set default strings

		(set #yes_answer
			("%s"
				"Yes"
			)
		)
		(set #no_answer
			("%s"
				"No"
			)
		)
		(set #choose_yes_or_no
			("%s"
				"Please chose \"Yes\" or \"No\"."
			)
		)
		(set #extracting_archive
			("%s"
				"Extracting archive \"%s\" to directory \"%s\"."
			)
		)
		(set #install_requires_lha
			("%s"
				"Installation of %s requires LhA. Skipping this part."
			)
		)
		(set #warning_old_os
			(
				"%s%s"
				"Please update the operating system. "
				"MakeCD requires OS 2.04."
			)
		)
		(set #intro_msg
			("%s%s%s"
				"Welcome at the MakeCD installation!\n\n"
				"Although MakeCD is able to run without further installation, you might want to "
				"copy it to your hard disk. This script will help you doing this."
			)
		)
		(set #select_dest_dir
			("%s%s"
				"Please select the destination directory for MakeCD. "
				"The \"MakeCD\" directory will be created automatically."
			)
		)
		(set #which_languages_to_install
			("%s"
				"Which languages do you want to install?"
			)
		)
		(set #install_developer
			("%s%s%s%s%s"
				"Do you want to install developer material? This material "
				"describes all you have to know about SUSP (System Use "
				"Sharing Protocol), RRIP (Rock Ridge Interchange Protocol) "
				"and about the support of Amiga protection bits and file "
				"comments on CD-ROM."
			)
		)
		(set #install_goodies
			("%s%s%s"
				"Do you want to install some goodies? This material does not "
				"really belong to MakeCD and is not included in the MakeCD "
				"registration fee, but might be useful."
			)
		)
		(set #remove_oldversion
			("%s%s%s%s%s"
				"The destination directory \"%s\" that you chose already exists. Before installing the "
				"new version, this directory has to be cleaned up. Files and directories which have been "
				"created by you, are not affected - except when their names collide with the names of "
				"MakeCD related files.\n\n"
				"May the installer script delete the affected files and directories?"
			)
		)
		(set #remove_oldversion_help
			("%s"
				"The following commands will be performed:"
			)
		)
		(set #abort_on_cleanup
			("%s"
				"Could not cleanup directory.\n\nAborting.\n\nInstallation not done."
			)
		)
		(set #deleting_old_files
			("%s"
				"Deleting old files and directories."
			)
		)
		(set #cannot_find_lang_docs
			("%s%s"
				"Sorry, cannot find any docs for language \"%s\".\n\n"
				"Installation of the docs of this language skipped."
			)
		)
		(set #cannot_find_lang_catalogs
			("%s%s"
				"Sorry, cannot find any catalogs for language \"%s\".\n\n"
				"Installation of the catalogs of this language skipped."
			)
		)
		(set #cannot_find_div_docs
			("%s%s"
				"Sorry, cannot find some of the doc files.\n\n"
				"Installation of these docs skipped."
			)
		)
		(set #copying_files
			("%s"
				"Please stand by while copying ..."
			)
		)
		(set #cannot_find_development_docs
			("%s%s"
				"Sorry, cannot find the development docs.\n\n"
				"Installation of these docs skipped."
			)
		)
		(set #select_drivers
			("%s"
				"Please select the drivers to install."
			)
		)
		(set #copy_libs
			("%s"
				"MakeCD requires triton.library V6."
			)
		)


		; Hier folgen die Strings, die für die deutsche Übersetzung benötigt
		; werden. Bei Übersetzungen in andere Sprachen einfach den folgenden
		; Block komplett kopieren und die Texte ändern. Die Steuerzeichen
		; sollten unverändert bleiben. Wer irgendwo eine Zeile hinzufügen oder
		; löschen möchte, muß dir Anzahl der "%s" entsprechend anpassen - für
		; jede Zeile steht ein "%s".

		(if (patmatch langstring "Deutsch")
			(
				(set #yes_answer
					"Ja"
				)
				(set #no_answer
					"Nein"
				)
				(set #choose_yes_or_no
					("%s"
						"Wählen Sie bitte \"Ja\" oder \"Nein\"."
					)
				)
				(set #extracting_archive
					("%s"
						"Entpacke Archiv \"%s\" ins Verzeichnis \"%s\"."
					)
				)
				(set #install_requires_lha
					("%s"
						"Sie benötigen das Programm LhA, um %s zu installieren. Überspringe diesen Teil."
					)
				)
				(set #warning_old_os
					(
						"%s%s"
						"Bitte bringen Sie Ihr Betriebssystem auf den neuesten Stand. "
						"MakeCD funktioniert erst ab OS 2.04."
					)
				)
				(set #intro_msg
					("%s%s%s"
						"Willkommen zur MakeCD Installation!\n\n"
						"MakeCD ist zwar auch ohne weitere Installation lauffähig, aber Sie werden es sicherlich "
						"auch auf Festplatte installieren wollen. Dabei hilft Ihnen dieses Skript."
					)
				)
				(set #select_dest_dir
					("%s%s"
						"Bitte wählen Sie das Verzeichnis, in dem Sie MakeCD installieren möchten. "
						"Ein Verzeichnis \"MakeCD\" wird automatisch angelegt."
					)
				)
				(set #which_languages_to_install
					("%s"
						"Welche Sprachen möchten Sie installieren?"
					)
				)
				(set #install_goodies
					("%s%s%s"
						"Sollen einige Goodies installiert werden? Die Goodies gehören "
						"nicht wirklich zu MakeCD und sind nicht in der Registrier-Gebühr "
						"von MakeCD enthalten, könnten sich jedoch als nützlich erweisen. "
					)
				)
				(set #install_developer
					("%s%s%s%s%s"
						"Möchten Sie die Dateien für Entwickeler installieren? Diese "
						"Dateien beschreiben alles, was Sie über SUSP (System Use "
						"Sharing Protocol), RRIP (Rock Ridge Interchange Protocol) "
						"und über die Unterstützung von Amiga Protection Bits and Datei-Kommentaren "
						"auf CD-ROMs wissen müssen."
					)
				)
				(set #remove_oldversion
					("%s%s%s%s%s"
						"Das von Ihnen gewählte Zielverzeichnis \"%s\" existiert bereits. Bevor die neue Version "
						"installiert wird, muß in diesem Verzeichnis aufgeräumt werden. Dateien und Verzeichnisse, "
						"die von Ihnen in diesem Verzeichnis angelegt wurden, sind davon nicht betroffen - außer "
						"wenn Sie Namen vergeben haben, die mit den von MakeCD vergebenen Namen kollidieren.\n\n"
						"Darf das Installer-Skript die betroffenen Dateien und Verzeichnisse löschen?"
					)
				)
				(set #remove_oldversion_help
					("%s"
						"Die folgenden Befehle werden ausgeführt:"
					)
				)
				(set #abort_on_cleanup
					("%s"
						"Konnte Verzeichnis nicht aufräumen.\n\nBreche Installation ab.\n\nEs wurde nichts installiert."
					)
				)
				(set #deleting_old_files
					("%s"
						"Lösche alte Dateien und Verzeichnisse."
					)
				)
				(set #cannot_find_lang_docs
					("%s%s"
						"Die Anleitung für die Sprache \"%s\" kann leider nicht gefunden werden.\n\n"
						"Die Installation der Anleitung dieser Sprache wurde übersprungen."
					)
				)
				(set #cannot_find_lang_catalogs
					("%s%s"
						"Der Katalog für die Sprache \"%s\" kann leider nicht gefunden werden.\n\n"
						"Die Installation des Katalogs dieser Sprache wurde übersprungen."
					)
				)
				(set #cannot_find_div_docs
					("%s%s"
						"Einige der Dokumentations-Dateien können leider nicht gefunden werden.\n\n"
						"Die Installation dieser Dateien wurde übersprungen."
					)
				)
				(set #copying_files
					"Kopiere ... Bitte etwas Geduld."
				)
				(set #cannot_find_development_docs
					("%s%s"
						"Die Entwickler-Dokumentation kann leider nicht gefunden werden.\n\n"
						"Die Installation dieser Dokumentation wurde übersprungen."
					)
				)
				(set #select_drivers
					"Welche Treiber möchten Sie installieren?"
				)
				(set #copy_libs
					"MakeCD benötigt triton.library V6."
				)
			)
		)
	)
)



(procedure P_SET_GLOBALS
	(
		(set osversion (/ (getversion) 65536))
		(set volname (expandpath (":")))
		(set origuserlevel @user-level)
		(run "which >ENV:MAKECDLHAPATH LhA")
		(set lhapath (getenv "MAKECDLHAPATH"))
		(if (patmatch "\n" (substr lhapath (- (strlen lhapath) 1)))
			( ; then
				(set lhapath
					(substr lhapath 0 (- (strlen lhapath) 1))
				)
			)
		)
		(run "delete QUIET ENV:MAKECDLHAPATH")
		(set lhexexists (exists "lhex"))
		(if (patmatch "#?LhA" lhapath)
			( ; then
				(set lhaexists (exists lhapath))
			)
			( ; else
				(set lhaexists 0)
			)
		)
	)
)



(procedure P_EXTRACT_FILE archive path objectname
	(
		(if (= 1 lhexexists)
			( ; then
				(working (#extracting_archive archive path))
				(run ("lhex -afFqw=%s e %s" path archive))
			)
			( ; else
				(if (= 1 lhaexists)
					( ; then
						(working (#extracting_archive archive path))
						(run ("%s -a -m -M x %s %s/" lhapath archive path))
					)
					( ; else
						(message (#install_requires_lha objectname))
					)
				)
			)
		)
	)
)



(procedure P_WARN_OLD_OS
	(
		(if (< osversion 37)
			(
				(user 2)
				(message
					#warning_old_os
				)
				(user origuserlevel)
			)
		)
	)
)



(procedure P_SELECT_DEST
	(
		(set destdir
			(tackon
				(askdir
					(prompt #select_dest_dir)
					(help @askdir-help)
					(default @default-dest)
				)
				"MakeCD"
			)
		)
	)
)



(procedure P_SELECT_INSTALL_LANG
	(
		(set i 0)
		(set langbits 0)
		(while (< i numlangs)
			(
				(set thislangdir (select i txt_langdir_0 txt_langdir_1 txt_langdir_2 txt_langdir_3 txt_langdir_4 txt_langdir_5 txt_langdir_6 txt_langdir_7 txt_langdir_8 txt_langdir_9))
				(set langbits
					(if
						(OR
							(OR
								(= 1 (exists ("doc_%s.lha" thislangdir)))
								(= 2 (exists (tackon "Catalogs" thislangdir)))
							)
							(= 2 (exists (tackon "doc" thislangdir)))
						)
						( ; then
							(+ langbits (shiftleft 1 i))
						)
						( ; else
							(+ langbits 0)
						)
					)
				)
				(set i (+ i 1))
			)
		)


		(set langbits
			(askoptions
				(prompt #which_languages_to_install)
				(help @askoptions-help)
				(choices txt_lang_0 txt_lang_1)
				(default langbits)
			)
		)
	)
)



(procedure P_ASK_INSTALL_GOODIES
	(
		(if
			(OR
				(= 2 (exists "Extras"))
				(= 2 (exists "Goodies"))
			)
			(
				(set installgoodies
					(askbool
						(prompt #install_goodies)
						(choices #yes_answer #no_answer)
						(help #choose_yes_or_no)
						(default 1)
					)
				)
			)
			( ;else
				(set install_goodies 0)
			)
		)
	)
)



(procedure P_ASK_INSTALL_DEVELOPER
	(
		(if
			(OR
				(= 1 (exists "doc_development.lha"))
				(= 2 (exists "doc/Development"))
			)
			(
				(set installdev
					(askbool
						(prompt #install_developer)
						(choices #yes_answer #no_answer)
						(help #choose_yes_or_no)
						(default 0)
					)
				)
			)
			( ;else
				(set installdev 0)
			)
		)
	)
)



(procedure P_COPY_DOCS
	(

		(set i 0)
		(while (< i numlangs)
			(
				(set thislang (select i txt_lang_0 txt_lang_1 txt_lang_2 txt_lang_3 txt_lang_4 txt_lang_5 txt_lang_6 txt_lang_7 txt_lang_8 txt_lang_9))
				(set thislangdir (select i txt_langdir_0 txt_langdir_1 txt_langdir_2 txt_langdir_3 txt_langdir_4 txt_langdir_5 txt_langdir_6 txt_langdir_7 txt_langdir_8 txt_langdir_9))
				(if (IN langbits i)
					(
						(if (= 2 (exists (tackon "doc" thislangdir)))
							(
								(copyfiles
									(source "doc")
									(dest (tackon destdir "doc"))
									(pattern ("%s#?" thislangdir))
									(optional force)
								)
							)
							(
								(if (= 1 (exists ("doc_%s.lha" thislangdir)))
									(
										(P_EXTRACT_FILE ("doc_%s.lha" thislangdir) (tackon destdir "doc") ("doc/%s" thislangdir))
									)
									(
										(message (#cannot_find_lang_docs thislang))
									)
								)
							)
						)
						(if (= 2 (exists (tackon "Catalogs" thislangdir)))
							(
								(copyfiles
									(source "Catalogs")
									(dest (tackon destdir "Catalogs"))
									(pattern thislangdir)
									(optional force)
								)
								(copyfiles
									(source "Catalogs")
									(dest (tackon destdir "Catalogs"))
									(pattern ("%s.info" thislangdir))
									(optional force)
								)
							)
							( ; else
								(if (NOT (patmatch "english" thislangdir))	; nicht English
									(
										(message (#cannot_find_lang_catalogs thislang))
									)
								)
							)
						)
					)
				)
				(set i (+ i 1))
			)
		)

		(
			(if (AND
					(= 1 (exists "doc/History"))
					(AND
						(= 1 (exists "doc/History.info"))
						(AND
							(= 1 (exists "doc/Compatibility"))
							(AND
								(= 1 (exists "doc/Compatibility.info"))
								(AND
									(= 1 (exists "doc/Triton.readme"))
									(= 1 (exists "doc/Triton.readme.info"))
								)
							)
						)
					)
				)
				( ;then
					(copyfiles
						(source "doc")
						(dest (tackon destdir "doc"))
						(choices "History" "History.info" "Compatibility" "Compatibility.info" "Triton.readme" "Triton.readme.info")
						(optional force)
					)
				)
				( ;else
					(if (= 1 (exists ("doc_div.lha")))
						(
							(P_EXTRACT_FILE "doc_div.lha" (tackon destdir "doc") "doc/#?")
						)
						(
							(message #cannot_find_div_docs)
						)
					)
				)
			)
		)

	)
)



(procedure P_CLEANUP_OLD
	(
		(set executestring1 ("delete %s QUIET FORCE" (tackon destdir "(ReadMe|History|MakeCD|Install(%|er)|registerscript|Triton.readme|triton.library)(%|.info)")))
		(set executestring2 ("delete %s QUIET FORCE" (tackon destdir "(Extras|Goodies|doc|deutsch|english|Modules|Development|Catalogs).info")))
		(set executestring3 ("delete %s QUIET FORCE ALL" (tackon destdir "(Extras|Goodies|doc|deutsch|english|Modules|Development|Catalogs)")))

		(if
			(askbool
				(prompt (#remove_oldversion destdir))
				(choices #yes_answer #no_answer)
				(help #remove_oldversion_help "\n\n" executestring1 "\n\n" executestring2 "\n\n" executestring3)
				(default 0)
			)
			( ; then
				(working #deleting_old_files)
				(run executestring1)
				(run executestring2)
				(run executestring3)
			)
			( ; else
				(abort #abort_on_cleanup)
			)
		)
	)
)



(procedure P_CREATE_DIRS
	(
		(if (NOT (exists destdir))
			( ; then
				(makedir
					destdir
					(infos)
				)
			)
			( ; else
				(P_CLEANUP_OLD)
			)
		)

		(if (NOT (exists (tackon destdir "Modules")))
			(
				(makedir
					(tackon
						destdir
						"Modules"
					)
				)
			)
		)

		(if (NOT (exists (tackon destdir "Modules/SCSIDrivers")))
			(
				(makedir
					(tackon
						destdir
						"Modules/SCSIDrivers"
					)
				)
			)
		)

		(if (NOT (exists (tackon destdir "Catalogs")))
			(
				(makedir
					(tackon
						destdir
						"Catalogs"
					)
				)
			)
		)

		(if (NOT (exists (tackon destdir "doc")))
			(
				(makedir
					(tackon
						destdir
						"doc"
					)
				)
			)
		)

		(if (NOT (exists (tackon destdir "Tracks")))
			(
				(makedir
					(tackon
						destdir
						"Tracks"
					)
				)
			)
		)
	)
)



(procedure P_COPY_FILES
	(
		(copyfiles
			(prompt #copying_files)
			(choices "MakeCD" "MakeCD.info" "ReadMe" "ReadMe.info" "doc.info" "Modules.info" "Catalogs.info" "registerscript")
			(help @copyfiles-help)
			(source "")
			(dest destdir)
			(optional force)
		)

		(copyfiles
			(prompt #copying_files)
			(help @copyfiles-help)
			(source "Tracks.noinfo")
			(dest destdir)
			(newname "Tracks.info")
			(optional force)
		)

		(copyfiles
			(prompt #copying_files)
			(help @copyfiles-help)
			(source "MakeCD.noinfo")
			(dest (pathonly ("%s.info" destdir)))
			(newname (fileonly ("%s.info" destdir)))
			(optional force)
		)

		(copyfiles
			(prompt #copying_files)
			(help @copyfiles-help)
			(choices "makecdromfs.module" "SCSISupport.module" "ReadWrite.module" "SCSIDrivers.info")
			(source "Modules")
			(dest (tackon destdir "Modules"))
			(optional force)
		)

		(if (= 1 installdev)
			(
				(if (= 2 (exists "doc/Development"))
					(
						(copyfiles
							(prompt #copying_files)
							(help @copyfiles-help)
							(source "doc")
							(dest (tackon destdir "doc"))
							(pattern "Development#?")
							(optional force)
						)
					)
					(
						(if (= 1 (exists "doc_development.lha"))
							(
								(P_EXTRACT_FILE "doc_development.lha" (tackon destdir "doc") "doc/Development")
							)
							(
								(message (#cannot_find_development_docs))
							)
						)
					)
				)
			)
		)

		(if (= 1 installgoodies)
			(
				(if (= 2 (exists "Goodies"))
					( ; then
						(copyfiles
							(prompt #copying_files)
							(help @copyfiles-help)
							(source "Goodies")
							(dest (tackon destdir "Goodies"))
							(pattern "Goodies#?")
							(optional force)
						)
					)
					( ; else
						(copyfiles
							(prompt #copying_files)
							(help @copyfiles-help)
							(source "Extras.info")
							(dest destdir)
							(newname "Goodies.info")
							(optional force)
						)
						(makedir
							(tackon destdir "Goodies")
						)
						(copyfiles
							(prompt #copying_files)
							(help @copyfiles-help)
							(source "Extras/ReadMe.unpacked")
							(dest (tackon destdir "Goodies"))
							(newname "ReadMe")
							(optional force)
						)
						(copyfiles
							(prompt #copying_files)
							(help @copyfiles-help)
							(source "Extras/ReadMe.info")
							(dest (tackon destdir "Goodies"))
							(optional force)
						)
						(tooltype
							(dest (tackon destdir ("Goodies/ReadMe")))
							(noposition)
						)
						(foreach "Extras" "#?.lha"
							(
								(P_EXTRACT_FILE ("Extras/%s" @each-name) (tackon destdir "Goodies") ("Goodies/%s" @each-name))
								(tooltype
									(dest (tackon destdir ("Goodies/%s" (substr @each-name 0 (- (strlen @each-name) 4)))))
									(noposition)
								)
							)
						)
					)
				)
			)
		)
	)
)



(procedure P_COPY_DRIVERS
	(
		(copyfiles
			(prompt #select_drivers)
			(help @copyfiles-help)
			(pattern "#?")
			(source "Modules/SCSIDrivers")
			(dest (tackon destdir "Modules/SCSIDrivers"))
			(confirm)
			(optional force)
		)
	)
)



(procedure P_COPY_LIBS
	(
		(copylib 
			(prompt #copy_libs)
			(help #copy_libs)
			(confirm)
			(source "triton.library")
			(dest "LIBS:")
		)
	)
)


(complete 5)
(P_SET_GLOBALS)
(complete 10)
(P_SELECT_LANGUAGE)
(complete 15)
(P_WARN_OLD_OS)
(complete 20)
(message #intro_msg)
(complete 25)
(P_SELECT_DEST)
(complete 30)
(P_SELECT_INSTALL_LANG)
(complete 35)
(P_ASK_INSTALL_DEVELOPER)
(complete 40)
(P_ASK_INSTALL_GOODIES)
(complete 45)
(P_CREATE_DIRS)
(complete 50)
(P_COPY_DOCS)
(complete 60)
(P_COPY_FILES)
(complete 80)
(P_COPY_DRIVERS)
(complete 90)
(P_COPY_LIBS)
(complete 99)

(set @default-dest destdir)

(complete 100)
