; script to install AXsh 1.32

(set newversion 1)
(set newrevision 32)

(transcript "Checking user level.")
(if	(< @user-level 1)
	(
		(transcript "Installation aborted due to too low user level.")
		(abort	"AXsh installation requires at least the \"average\" user "
			"level. Restart installation and select appropriate user level."
)	)	)

(onerror
	(makeassign "AXshPack" (safe))
)

(set #bad-kick
	(cat 	"You must be using Kickstart 2.04 to install using this script. "
		"Use installation by hand for Kickstart 1.2 or 1.3 machines."))

(complete 0)
	; check kick
(set vernum (getversion "graphics.library" (resident)))
(set ver (/ vernum 65536))
(set rev (- vernum (* ver 65536) ) )

(if (< ver 37)
	((abort #bad-kick)))

	; see if this is really an update
(set is_update 0)
(set in_place  0)
(set AXsh_dest (getassign "AXsh" "av"))
(if (not (exists "AXshPack:" (noreq)))
	(makeassign "AXshPack" "" (safe))	; make an educated quess..
)

	; if update, be sure they want program in same place
(if AXsh_dest
	(if	(askbool
			(prompt "Your current copy of AXsh appears to be located in the drawer named \""
				AXsh_dest "\". Do you want to update the installed version ?"
			)
			(help	"The installer has determined that you may already have a copy "
				"of AXsh installed on your system. If this is wrong or you want "
				"the update installed elsewhere, select NO as an answer. "
				"Otherwise, select YES.\n"
				"If you select YES, only binaries, manuals, information files and "
				"possibly language files are copied. Configuration files, home "
				"directories nor news/mail system files are NOT overwritten.\n"
			)
			(default 1)
		)
		(set is_update 1)		; if user wants in same place
	)
	; else if not an update, get a location for program
)

(if	(not	is_update)
	(if	(askbool
			(prompt "Do you want to do in-place installation, "
				"i.e. install AXsh to this directory ("
				(getassign "AXshPack" "av")
				") ?\n"
			)
			(help	"You can either install AXsh in any directory,"
				"in which case all material is copied there and "
				"you need to delete the originals.\n"
				"If you unpacked the installation packet into "
				"appropriate directory already, it is possible "
				"to install AXsh there and no files need "
				"to be deleted afterwards."
			)
			(	(default 1)
				(set AXsh_dest (getassign "AXshPack" "av"))
			)
		)
		(set in_place 1)
		(set AXsh_dest
			(askdir	(prompt "In which disk or drawer should AXsh be installed?\n"
					"Subdirectory will NOT be created!\n")
				(help 	"All AXsh subdirectoried will be created under this "
					"directory. If you are not dedicating a whole disk "
					"partition for AXsh, you should create a subdirectory "
					"for AXsh yourself.\n\n"
					@askdir-help)
				(default @default-dest)
				(disk)
)	)	)	)


(set oldver (getversion (tackon AXsh_dest "bin/AXsh")))
(set oldv (/ oldver 65536))
(set oldr (- oldver (* oldv 65536) ) )

(if	(and (= in_place 0) (or (and (= oldv newversion) (>= oldr newrevision))	(> oldv newversion)))
	(message "You already have AXsh version greater or equal than "
		 newversion "." newrevision " installed in \"" AXsh_dest
		 "\" (AXsh " oldv "." oldr ")\n" )
)

	; at this point we have a valid destination, so we tell installer where
	; the application will end up so the exit page will be correct -- also,
	; the installation log file (if any) will be copied to the destination
(set @default-dest AXsh_dest)

(if	(getassign "AXsh" "vd")
	(	(transcript "AXsh: is a partition!\n")
		(if	(not (= AXsh_dest "AXsh:"))
			(if	(askbool
					(prompt "Your current copy of AXsh is in a Volume.\n"
						"\"Assign AXsh: " AXsh_dest "\" will fail "
						"unless it's relabeled.\n"
						"Do you still want to continue ?"
					)
					(help	"The installer has determined that your old version of AXsh "
						"is installed in a partition named AXsh. Cancelling this by "
						"an assign is not possible and thus this installation will not "
						"be totally successfull until you relabel the old partition.\n"
						"You can also install AXsh on top of the old AXsh system, "
						"because old configuration files are preserved.\n"
					)
					(default 1)
				)
				(transcript "Continuing installation...\n")
				(exit (quiet))
)	)	)	)

(askdisk
	(prompt "Please insert \n the master program disk \n labeled \"AXshPack\".")
	(help	"The AXsh program and other options will be copied "
		"from \"AXshPack:\" into your system.")
	(dest  "AXshPack")
	(newname "AXsh")
	(assigns)	; Allow assigns so you don't need to use a floppy
)

(if	in_place
	(	(copyfiles
			(source "AXshPack:storage/AX-Sysghost.info")
			(dest "SYS:WBStartup")
		)
		(copyfiles
			(source "AXshPack:storage/AX-Server.info")
			(dest "SYS:WBStartup")
		)
		; If user-startup mounts handlers automatically (>=2.1)
		; just use that method. We need to copy the handlers to L:
		; because AXsh: is not mounted when they are mounted.
		; Also, mount files (icons) refer to handlers in L:
		(complete 50)
		(if	(exists "Devs:DOSDrivers" (noreq))
			(	(copyfiles
					(source "AXshPack:Storage/DosDrivers/NEWAUX")
					(dest "DEVS:DosDrivers")
					(infos)
				)
				(copylib
					(source "AXshPack:bin/NEWAUX-Handler")
					(dest "L:")
				)
				(copylib
					(source "AXshPack:bin/AXAUX-Handler")
					(dest "L:")
		)	)	)
		; In pre 2.1 system, add the mount command(s) to user-startup
		(complete 90)

		(if	(= "AXsh:" AXsh_dest)
			(	(transcript "AXsh assign/volume already exists, no assign needed\n")
				(if	(not	(exists "Devs:DOSDrivers" (noreq)))
					(startup "AXsh"
						(prompt	"I need to add \"mount NEWAUX: from AXsh:etc/Mountlist.AXsh\"\n"
							" to \"S:user-startup\" so that your system "
							"will be properly configured to use AXsh.")
						(help "Do this or AXsh won't work!!")
							(command "mount NEWAUX: from AXsh:etc/Mountlist.AXsh\n")
			)	)	)
			(if	(exists "Devs:DOSDrivers" (noreq))
				(startup "AXsh"
					(prompt	"I need to add \"assign AXsh: " AXsh_dest "\" to \"S:user-startup\" "
						"so that your system will be properly configured to use AXsh.")
					(help "Do this or AXsh won't work!!")
					(command "ASSIGN AXsh: \"" AXsh_dest "\"\n")
				)
				(startup "AXsh"
					(prompt	"I need to add \"assign AXsh: " AXsh_dest "\" and \n"
						" \"mount NEWAUX: from AXsh:etc/Mountlist.AXsh\"\n"
						" to \"S:user-startup\" "
						"so that your system will be properly configured to use AXsh.")
					(help "Do this or AXsh won't work!!")
						(command "ASSIGN AXsh: \"" AXsh_dest "\"\n"
						 "mount NEWAUX: from AXsh:etc/Mountlist.AXsh\n")
		)	)	)
		(complete 100)
		(if (not @pretend)
			(makeassign "AXsh" AXsh_dest)
		)
		(makeassign "AXshPack" (safe))
		(exit)
	)
	; else
)

(if (exists "locale:" (noreq))
	; KS2.1 or newer
	(set whichfiles
		(askoptions
			(prompt "Please select the files to be copied")
			(help	"This allows you to select only certain parts of the AXsh "
				"system to be installed on your hard drive. For normal installation "
				"select all the items")
			(choices "AXsh system"
				 "AXsh manuals"
				 "WB launchable system services"
				 "Languages")
	)	)
	; KS2.0
	(set whichfiles
		(askoptions
			(prompt "Please select the files to be copied")
			(help	"This allows you to select only certain parts of the AXsh "
				"system to be installed on your hard drive. For normal installation "
				"select all the items")
			(choices "AXsh system"
				 "AXsh manuals"
				 "WB launchable system services")
)	)	)

(if	(in whichfiles 0)
	(	(makedir (tackon AXsh_dest "bin")	(infos))
		(makedir (tackon AXsh_dest "info")	(infos))
		(makedir (tackon AXsh_dest "storage")	(infos))
		(if	(in whichfiles 3)
			(copyfiles
				(source "AXshPack:bin")
				(dest (tackon AXsh_dest "bin"))
				(all)
			)
			(copyfiles
				(source "AXshPack:bin")
				(dest (tackon AXsh_dest "bin"))
				(files) (pattern "#?")
		)	)
		; If we are updating, do not overwrite config files
		(if	(or	(not is_update)
				(not (exists (tackon AXsh_dest "etc") (noreq))))
			(
				(makedir (tackon AXsh_dest "etc") (infos))
				(copyfiles
					(source "AXshPack:etc")
					(dest (tackon AXsh_dest "etc"))
					(all)
		)	)	)
		(if	(or	(not is_update)
				(not (exists (tackon AXsh_dest "home") (noreq))))
			(	(makedir (tackon AXsh_dest "home") (infos))
				(copyfiles
					(source "AXshPack:home")
					(dest (tackon AXsh_dest "home"))
					(all)
		)	)	)
		(if	(or	(not is_update)
				(not (exists (tackon AXsh_dest "usr") (noreq))))
			(
				(makedir (tackon AXsh_dest "usr") (infos))
				(copyfiles
					(source "AXshPack:usr")
					(dest (tackon AXsh_dest "usr"))
					(all)
		)	)	)
		(complete 50)
		(copyfiles
			(source "AXshPack:info")
			(dest (tackon AXsh_dest "info"))
			(all)
		)
		(copyfiles
			(source "AXshPack:storage")
			(dest (tackon AXsh_dest "storage"))
			(all)
		)
		(copyfiles
			(source "AXshPack:AXsh.info")
			(dest AXsh_dest)
)	)	)

(complete 80)
(if	(in whichfiles 1)
	(	(copyfiles
			(source "AXshPack:man")
			(dest (tackon AXsh_dest "man"))
			(all)
		)
		(copyfiles
			(source "AXshPack:AXsh.guide")
			(dest AXsh_dest)
			(infos)
		)
		(copyfiles
			(source "AXshPack:Shell.guide")
			(dest AXsh_dest)
			(infos)
		)
		(copyfiles
			(source (cat "AXshPack:AXshUpdates" newversion "." newrevision))
			(dest AXsh_dest)
			(infos)
)	)	)

(if	(in whichfiles 2)
	(	(copyfiles
			(source "AXshPack:storage/AX-Sysghost.info")
			(dest "SYS:WBStartup")
		)
		(copyfiles
			(source "AXshPack:storage/AX-Server.info")
			(dest "SYS:WBStartup")
		)
		; If user-startup mounts handlers automatically (>=2.1)
		; just use that method. We need to copy the handlers to L:
		; because AXsh: is not mounted when they are mounted.
		; Also, mount files (icons) refer to handlers in L:
		(if	(exists "Devs:DOSDrivers" (noreq))
			(	(copyfiles
					(source "AXshPack:Storage/DosDrivers/NEWAUX")
					(dest "DEVS:DosDrivers")
					(infos)
				)
				(copylib
					(source "AXshPack:bin/NEWAUX-Handler")
					(dest "L:")
				)
				(copylib
					(source "AXshPack:bin/AXAUX-Handler")
					(dest "L:")
		)	)	)
		; In pre 2.1 system, add the mount command(s) to user-startup
)	)

(complete 95)
	; modify S:User-Startup

(if	(= "AXsh:" AXsh_dest)
	(transcript "AXsh assign/volume already exists, user-startup not touched\n")
	(if	(exists "Devs:DOSDrivers" (noreq))
		(startup "AXsh"
			(prompt	"I need to add \"assign AXsh: " AXsh_dest "\" to the \"S:user-startup\" "
				"so that your system will be properly configured to use AXsh.")
			(help "Do this or AXsh won't work!!")
			(command "ASSIGN AXsh: \"" AXsh_dest "\"\n")
		)
		(startup "AXsh"
			(prompt	"I need to add \"assign AXsh: " AXsh_dest "\" and \n"
				" \"mount NEWAUX: from AXsh:etc/Mountlist.AXsh\"\n"
				" to the \"S:user-startup\" "
				"so that your system will be properly configured to use AXsh.")
			(help "Do this or AXsh won't work!!")
			(command "ASSIGN AXsh: \"" AXsh_dest "\"\n"
				 "mount NEWAUX: from AXsh:etc/Mountlist.AXsh\n")
)	)	)

(complete 100)
(if	is_update
	(message "Because AXsh was installed on top of an old version, "
		 "configuration files were not updated. Read the file "
		 "AXshUpdates" newversion "." newrevision " to find out "
		 "about changes in the configuration files and change them "
		 "if needed.\n"
	)
)

	; reinitialize assigns
(if (not @pretend)
	(makeassign "AXsh" AXsh_dest)
)
	; cleanup
(makeassign "AXshPack" (safe))
	; this is not strictly necessary, but doesn't hurt
(exit)
