;
; SysLog Installation script
;
; Copyright  1995 Petri Nordlund. All rights reserved.
;
; $Id: Install 1.4 1995/11/04 16:07:55 petrin Exp petrin $
;
; Languages available:
;   English (default)
;

; =======================================================================
;   Set up some variables
; =======================================================================

(set OSVersion		(/ (getversion) 65536))
(set WBVersion		(/ (getversion "libs:version.library") 65536))
(set AGVersion		(/ (getversion "libs:amigaguide.library") 65536))
(set TRUE		1)
(set FALSE		0)
(set startup_added	FALSE)
(set prefs_written	FALSE)

; =======================================================================
;   Set up localized strings
; =======================================================================

;
; ===== English
;
(set #kickstart37 "Sorry, but SysLog requires AmigaDos 2.04.")
(set #begin_install "\nYou're about to install SysLog. If you need any help, just press the HELP-button.\n\nYou can always abort the installation and the installed parts will be safely deleted.\n\nIf you decide to uninstall SysLog, there's a program available for this purpose.")
(set #uninstall "\n\n\n\nIf you want to uninstall SysLog, use the supplied uninstall program.\n\n\n\n")
(set #dir_prompt "Where should SysLog be installed? A drawer named `SysLog' will be created there. If you're updating from a previous version, select the directory containing the SysLog drawer.")
(set #dir_help "A good place to install SysLog is your WORK: partition or if it isn't available, the SYS: partition.\n\nIf you're updating from a previous version, you must select the directory where the SysLog drawer is, not the SysLog drawer. For example WORK: but not WORK:SysLog/.\n\n")
(set #extract_progs "Copying executables")
(set #installing_docs "Installing documentation")
(set #doc_format "Please select documentation format:")
(set #df_1 "AmigaGuide")
(set #df_2 "ASCII text")
(set #doc_askansi "\nDo you want to use ANSI format codes in the ASCII documentation?")
(set #ansi_yes "Yes, use ANSI")
(set #ansi_no "No, don't use ANSI")
(set #conv_doc "Converting documentation")
(set #addcmds "The following instructions will be added to your \"S:User-Startup\" file so that your system will be properly configured to use SysLog.\n\nPath %s Add\nRun <NIL: >NIL: %s/SysLogDaemon")
(set #addhelp "This will add some commands to your S:User-Startup file to allow the correct operation of SysLog. SysLog will be started when you boot your Amiga.\n\n")
(set #abort_remove "Installation aborted. Do you want to delete the files that were installed?\n\nIf you are updating an existing version of SysLog, it may have already been overwritten, so you must reinstall it.\n\n")
(set #abort_rem_yes "Yes, remove")
(set #abort_rem_no "No")
(set #remcmds "\nCommands added to your \"S:User-Startup\" file will now be removed.")
(set #remhelp "The installation program has added commands to your \"S:User-Startup\" file. These will now be removed, nothing else will be deleted or changed.\n\n")
(set #userstartup "; SysLog installation was aborted.")
(set #thanks "\nThank you for installing SysLog.\n\nNow you must reboot the machine to start the SysLogDaemon.")


; =======================================================================
;   Initialization
; =======================================================================

; ===== Make sure that we are running under 2.04 or better
(if (< OSVersion 37)
	(abort #kickstart37)
)

; ===== Set up an error cleanup routine
(onerror
	(delete "RAM:tool")
	(if (exists "SLDest:" (noreq))
	(
		(if (askbool
			(prompt #abort_remove)
			(help "")
			(default 0)
			(choices #abort_rem_yes #abort_rem_no))
			(
				(run "delete SLDest:SysLog ALL FORCE QUIET")
				(delete "SLDest:SysLog.info")

				(run "Delete DEVS:Mountlist.LOG FORCE QUIET")
				(run "Delete DEVS:DOSDrivers/LOG FORCE QUIET")
				(run "Delete DEVS:DOSDrivers/LOG.info FORCE QUIET")

				(run "Delete L:LOG-Handler FORCE QUIET")
				(run "Delete LIBS:syslog.library FORCE QUIET")

				(if (= startup_added TRUE)
					(startup "SysLog"
						(prompt (#remcmds))
						(help #remhelp @startup-help)
						(command #userstartup)
					)
				) ;  end of if statement

			)
		) ; end of if statement

		(makeassign "SLSrc" (safe))
		(makeassign "SLDest" (safe))
	)) ; end of if statement
) ; end of onerror statement

(welcome #welcome)

; =======================================================================
;   Begin installation
; =======================================================================

(complete 0)

(message #begin_install)

; ===== cancel the assign in case of installation restart
(makeassign "SLSrc" (safe))
(makeassign "SLDest" (safe))

(transcript #uninstall)

(set SLDest
    (tackon
        (askdir
            (prompt #dir_prompt)
            (help #dir_help @askdir-help)
            (default @default-dest)
        )
        "SysLog"
    )
)

(complete 5)

(makeassign "SLDest"
	(pathonly SLDest)
	(safe)
)

(if (not (exists "SLDest:SysLog"))
	(makedir "SLDest:SysLog")
)

; ===== Tell installer where SysLog will be installed
(set @default-dest SLDest)

; ===== Copy c/tool to RAM:
(run "copy c/tool RAM:")

(complete 10)

; ===== Copy executables
(working #copy_progs)
(copyfiles
	(source "bin")
	(dest "SLDest:SysLog")
	(infos)
	(all)
)

(complete 15)

; ===== Install documentation
(
	(working #installing_docs)

	(if (= AGVersion 0)
		; ASCII
		(set gdefault 2)
		; AmigaGuide
		(set gdefault 1)
	)

	(set asciitype 0)

	(if (= @user-level 2)
		(
			(set gtype
				(askoptions
					(prompt #doc_format)
					(help @askchoice-help)
					(choices
						#df_1
						#df_2
					)
					(default gdefault)
				)
			)
			(if (IN gtype 1)
				(if (askbool
					(prompt #doc_askansi)
					(default 0)
					(help "")
					(choices #ansi_yes #ansi_no))
					(
						; ANSI
						(set asciitype 1)
					)
				) ; end of if statement
			) ; end of if statement
		)
		(
			; user is not expert, don't ask anything
			(set gtype gdefault)
		)
	) ; end of if statement

	(working #conv_doc)

	(if (IN gtype 0)
	(
		(if (>= AGVersion 39)
			(run "copy doc/SysLog.guide SLDest:SysLog/")
			(run "RAM:tool FROM=doc/SysLog.guide TO=SLDest:SysLog/SysLog.guide STRIPGUIDE")
		)
		(run "copy doc/SysLog.guide.info SLDest:SysLog/")
	))
	(if (IN gtype 1)
	(
		(if (= asciitype 0)
			(run "RAM:tool FROM=doc/SysLog.guide TO=SLDest:SysLog/SysLog.doc GUIDETOTEXT")
			(run "RAM:tool FROM=doc/SysLog.guide TO=SLDest:SysLog/SysLog.doc GUIDETOTEXT ANSI")
		)
		(run "copy doc/SysLog.doc.info SLDest:SysLog/")
	))

	; gtype is used later in this file also, see icon installation
)

(complete 30)

(if (>= WBVersion 39)
(
	; 3.0+
	(run "RAM:tool ICON=SLDest:SysLog/SysLog.guide.info CHANGETOOL DEFTOOL=Multiview")
	(run "RAM:tool ICON=SLDest:SysLog/SysLog.doc.info CHANGETOOL DEFTOOL=Multiview")
)
(
	; 2.x
	(run "RAM:tool ICON=SLDest:SysLog/SysLog.guide.info CHANGETOOL DEFTOOL=AmigaGuide")
	(run "RAM:tool ICON=SLDest:SysLog/SysLog.doc.info CHANGETOOL DEFTOOL=more")
)) ; end of if statement

(if (NOT (IN gtype 0))
	(delete "SLDest:SysLog/SysLog.guide.info")
) ; end of if statement

(if (NOT (IN gtype 1))
	(delete "SLDest:SysLog/SysLog.doc.info")
) ; end of if statement

(complete 40)

; ===== Copy syslog.library
(copylib
	(source "libs/syslog.library")
	(dest "LIBS:")
)

(complete 50)

; ===== Copy LOG-Handler
(copylib
	(source "l/LOG-Handler")
	(dest "L:")
)

; ===== Copy Mountlists
(copyfiles
	(source "devs/Mountlist")
	(dest "DEVS:")
	(newname "Mountlist.LOG")
)
(copyfiles
	(source "devs/DOSDrivers")
	(dest "DEVS:DOSDrivers/")
	(all)
)

; ===== Copy .conf-files
(copyfiles
	(source "s")
	(dest "SLDest:SysLog")
	(all)
)

; ===== UnInstall
(copyfiles
	(source "UnInstall")
	(dest "SLDest:SysLog/")
	(all)
)
(run "RAM:tool ICON=SLDest:SysLog/UnInstall.info ADDTT TOOLTYPE=\"DEFUSER=Expert\"")

(complete 60)

; ===== Copy developer files
(copyfiles
	(source "Developer")
	(dest "SLDest:SysLog/Developer")
	(all)
)

(complete 80)

; ===== Copy directory icon
(copyfiles
	(source "dir_icon")
	(dest "SLDest:")
	(newname "SysLog.info")
)

(complete 90)

; ===== Add commands to s:user-startup
(startup "SysLog"
	(prompt (#addcmds SLDest SLDest))
	(help #addhelp @startup-help)
	(command ("PATH %s Add\n" SLDest))
	(command ("Run <NIL: >NIL: %s/SysLogDaemon\n" SLDest))
)
(set startup_added TRUE)

; =======================================================================
;   Cleanup
; =======================================================================

(complete 100)

(delete "RAM:tool")

(makeassign "SLSrc" (safe))
(makeassign "SLDest" (safe))

(exit #thanks)
