; Installer Script for EZCron.
; 11/30/97  Jim Hines

; set up an error cleanup routine
(onerror
    (makeassign "EZsrc" (safe))
    (makeassign "EZdest" (safe))
)


(getassign "EZCron" "a")

;started
(complete 0)

;cancel the assign in case of installation restart
(makeassign "EZsrc" (safe))
(makeassign "EZdest" (safe))

; get the dest dir for EZCron (create it if it does not exist)
(set ez_dest
	(tackon
    	(askdir
			(prompt "If you have not read the README.FIRST file\n, please do so before continuing.\n Where should EZCron be installed? A drawer named `EZCron' will be created.")
			(help @askdir-help)
			(default "Work:")
        )
        "EZCron"
    )
)
(makeassign "EZdest"
    (pathonly ez_dest)
    (safe)
)

(if (exists "EZdest:EZCron")
    (+ 1 1)
    (makedir
        "EZdest:EZCron"
        (infos)
        (safe)
    )
)

(if (exists "EZdest:EZCron/Prefs")
    (+ 1 1)
    (makedir
        "EZdest:EZCron/Prefs"
        (safe)
    )
)

(if (exists "EZdest:EZCron/Doc")
    (+ 1 1)
    (makedir
        "EZdest:EZCron/Doc"
        (safe)
		(infos)
    )
)

(if (exists "EZdest:EZCron/rexx")
    (+ 1 1)
    (makedir
		"EZdest:EZCron/rexx"
		(safe)
	)
)

(if (exists "EZdest:EZCron/ConfigFiles")
    (+ 1 1)
    (makedir
		"EZdest:EZCron/ConfigFiles"
		(safe)
	)
)

;We now have a valid destination, so tell Installer where EZCron will end up
;so the exit page will be correct.
(set @default-dest ez_dest)

;copy program files from source to dest
;(copyfiles
;	(source "EZCrond")
;	(dest "EZdest:EZCron")
;	(infos)
;)

; ASK WHETHER TO INSTALL IN WBSTARTUP OR USER-STARTUP
(set name
	(askchoice
		(prompt "Where you you like EZCronD (Daemon) to be started from?")
		(help @askoptions-help)
		(choices "User-Startup" "WBStartup")
		(default 0)
	)
)
; Copy EZCronD to EZDest: regardless of choice.
(copyfiles
	(source "EZCronD")
	(dest "EZdest:EZCron")
	(infos)
)

(if (= name 1)
	(set wbstart_dest
    	(askdir
			(prompt "Select your WBStartup drawer.")
			(help "Pick the WBstartup drawer you wish to install the EZCronD (Daemon) into.")
			(default "sys:WBStartup")
	    )
	)
)
(if wbstart_dest
	(copyfiles
		(source "EZCronD")
		(dest wbstart_dest)
		(infos)
	)
) ;if
; END OF ASK WHETHER TO INSTALL IN WBSTARTUP OR USER-STARTUP


(copyfiles
	(source "EZCron")
	(dest "EZdest:EZCron")
	(infos)
)


(copyfiles
	(source "ezc.gui")
	(dest "EZdest:EZCron")
)


;copy program files from source to dest
(copyfiles
	(source "readme")
	(dest "EZdest:EZCron")
	(infos)
)

;copy program files from source to dest
(copyfiles
	(source "README.FIRST")
	(dest "EZdest:EZCron")
	(infos)
)

;copy program files from source to dest
(copyfiles
	(source "Doc")
	(dest "EZdest:EZCron/Doc")
	(all)
)


(working "Copying the rexx scripts.")
;copy rexx files from source to dest
(copyfiles
	(source "rexx")
	(dest "EZdest:EZCron/rexx")
	(all)
)

(working "Copying the example Configuration files.")
;copy Config files from source to dest
(copyfiles
	(source "ConfigFiles")
	(dest "EZdest:EZCron/ConfigFiles")
	(all)
)


(copyfiles
	(prompt "Select which .prefs files you wish copied.\n See HELP.")
	(help "If you are upgrading from EZCron v2.++, you will probably not want to overwrite your existing preferences files. If this is a first time install, you will need these files.")
	(source "prefs")
	(dest "EZdest:EZCron/prefs")
	(pattern "#?.prefs")
	(files)
	(confirm)
)


; Ask the user if he wants the config.file copied to s:

(if (askbool (prompt "Do you wish to copy the included example cron.config file to your s: directory?\n See HELP")
	(help "Release 2 cron.config files are no longer compatable with the current format.")
		(default 0))
	    (
    	; Ok. Install it anyway!
	      (set InstallConfig TRUE)
    	)
)            

(if InstallConfig
        (copyfiles
            (source "s/cron.config")
            (dest "s:")
        )
)


;copy library files from source to dest with version checking
(copylib
	(prompt "Copying library\n arexxport.library")
	(help "Copy Librarys")
	(source "Libs/arexxport.library")
	(dest "libs:")
	(confirm)
)


;copy library files from source to dest with version checking
(copylib
	(prompt "Copying library\n rexxreqtools.library")
	(help "Copy Librarys")
	(source "Libs/rexxreqtools.library")
	(dest "libs:")
	(confirm)
)

;copy Varexx files from source to dest with version checking
(copylib
	(prompt "Copying Varexx to sys:rexxc")
	(help "Copy VArexx")
	(source "rexxc/VArexx")
	(dest "sys:rexxc")
	(confirm)
)


;copy Varexx files from source to dest with version checking
(copyfiles
	(source "rexxc/VXC")
	(dest "sys:rexxc")
)

;add the assign for EZCron: to user-startup
(set ezassign ("Assign EZCron: \"%s\"\n" ez_dest))

;add program startup to s:user-startup sequence
(set ezrexxstart ("run <>NIL: rx EZCron:EZCrond start \n"))
(startup "EZCron"
	(prompt "EZCron requires that an AmigaDOS assign be created. It WILL NOT work properly without it! The following will be added to your s:user-startup file:\n\n"
    	ezassign
		"\nIs it okay to add this now?"
		"\n\nIMPORTANT: Reboot your computer or manually assign EZCron: before using for the first time."
	)
		(help "This is required if installing EZCron for the first time.")
		(command ezassign)
)

(if (= name 0)
	(startup "EZCron"
		(prompt "Since you opted to NOT install EZCronD in WBStartup, this command must also be added to your user-startup sequence:\n\n"
			ezrexxstart
			"\nIs it okay to add this now?"
			"\n\nIMPORTANT: REBOOT YOUR COMPUTER BEFORE EZCRON FOR THE FIRST TIME."
		)
			(help "This is required if installing EZCron for the first time.")
			(command ezrexxstart)
	)
)

(complete 95)

;un-snapshot the EZCron drawer icon
(tooltype
	(dest ez_dest)
	(noposition)
)


;finished with install
(complete 100)

;cleanup
(makeassign "EZsrc" (safe))
(makeassign "EZdest" (safe))

;display the guide file
(run "run sys:utilities/multiview doc/ezcron.guide" (safe))

;leave
(exit)

