(set pine-install "assign pine: ")
(if
(and
  ( = (exists "libs:ixemul.library") 1)
  ( < ( / (getversion "libs:ixemul.library") 65536) 40 ) )
    (abort "You must have ixemul.library version >40.0 to run pine.")
)

(set @pine-dest
  (askdir
    (prompt "Enter directory for installing pine")
    (help @askdir-help)
    (default "work3:pine3.91")
  )
)

(copyfiles
    (prompt "Copying necessary files")
    (source "")
    (dest @pine-dest)
    (help @copyfiles-help)
    (all)
    (infos)
)

(set pine-install (cat pine-install @pine-dest) )
(set pine-install (cat pine-install "\npath pine: add\n") )

(if ( = (exists "bin:" (noreq) )  2 )
    (
	(copyfiles
	    (prompt "Copying bin to bin:")
	    (source "bin")
	    (dest "bin:")
	    (confirm)
	    (help @copyfiles-help)
	    (all)
	)

	(if ( = (exists "bin:csh" (noreq) )  1 )

	    (debug "bin:csh exists")

	    (copyfiles
		(prompt "Copying bin/sh to bin:csh")
		(source "bin/sh")
		(dest "bin:csh")
		(help @copyfiles-help)
	    )
	)

	(delete (tackon @pine-dest "bin") )
    )
    (
	(set pine-install (cat pine-install "assign bin: pine:bin\n") )
	(copyfiles
	    (prompt "Copying bin/sh to bin/csh")
	    (source "bin/sh")
	    (dest (tackon @pine-dest "bin/csh") )
	    (help @copyfiles-help)
	)
    )
)

(if ( = (exists "lib:" (noreq) )  2 )
    (
	(copyfiles
	    (prompt "Copying lib to lib:")
	    (source "lib")
	    (dest "lib:")
	    (confirm)
	    (help @copyfiles-help)
	    (all)
	)

	(delete (tackon @pine-dest "lib") )
    )
    (set pine-install (cat pine-install "assign lib: pine:lib\n") )
)

(if ( = (exists "etc:" (noreq) )  2)
    (
	(copyfiles
	    (prompt "Copying etc to etc:")
	    (source "etc")
	    (dest "etc:")
	    (help @copyfiles-help)
	    (confirm)
	    (all)
	)

	(delete (tackon @pine-dest "etc") )
    )
    (set pine-install (cat pine-install "assign etc: pine:etc") )
)

(debug "pine-install is" pine-install)

(startup "pine" pine-install
    (prompt ("%s%s"
	    "Add the following lines to s:user-startup\n"
	    pine-install
	    )
    )
    (help @startup-help)
    (command pine-install)
)


(if ( = (exists "env:TERM" (noreq) ) 0)
    (
	(message "Setting environment variable TERM to amiga")
	(textfile
	    (dest "env:TERM")
	    (append "amiga")
	)

	(message "Setting envarc:TERM to amiga")
	(textfile
	    (dest "envarc:TERM")
	    (append "amiga")
	)
    )
    (debug "env:term exists")
)

(message "Installation complete. Please read the file pine.guide for information"
     " on configuring and running Pine. Happy emailing"
)
(exit (quiet))

