;
; Script to install AmigaSMail
;
;=================== procedures =========

;---------------------------------------------------------------------------
(procedure make-daemon
 (if (NOT (= daemon_already "yes"))
   (
	 (set daemon_already "yes")
    (copylib
	  (prompt "Where should the SMTP daemon be installed ? ")
	  (help @copylib-help)
	  (source "bin/smail_amitcp")
	  (dest "AmiTCP:serv/SMTPd")
	  (confirm)
    )
    (message "To complete the installation of the SMTP on your system "
             "you have to add the following line to your AmiTCP:db/Inet.Conf file: "
             "(Change amitcp:serv/smtpd to the path you installed SMTPd)\n"
             "\nsmtp stream tcp nowait root amitcp:serv/smtpd smtpd -S\n"
             "\nThen you have to restart AmiTCP\n"
   )
  )
 )
)

(procedure ask-sys-bsmtp
 (ask-sys-uucp)
 (set nr
  (askchoice
  (choices "compress" "gzip" "freeze" "none")
  (prompt "Which command should AmigaSMail use to compress the BSMTP mails ? ")
  (help "The command to compress and decompress your BSMTP mails. "
        "The command is:\nexecute cmd -c(d) <infile >outfile "
        "The packer must be able to work with pipes ")
  (default 1)
  )
 )
; compress
 (if (= nr 0)
  	(set rcmd "rcsmtp")
 )
; gzip
 (if (= nr 1)
  	(set rcmd "rgsmtp")
 )
; freeze
 (if (= nr 2)
  	(set rcmd "rfsmtp")
 )
; none
 (if (= nr 3)
  	(set rcmd "rsmtp")
 )

 (if (<> 3 nr)
  (set compress
   (askfile
    (prompt "Where is your compress command ? ")
    (help "I need the complete path of the command. ")
    (default (tackon UUBIN "compress"))
   )
  )
 )
 (set size
  (asknumber
     (prompt "Maximal size in bytes of the BSMTP batchfile for this host")
     (help
     "If the batchfile  will  grow  over this limit the batch will be "
     "delivered the same way as you start AmigaSMail with -D option. "
     "Use zero if you want to disable the automatic batching. "
     (default 204800)
    )
  )
 )
)

(procedure ask-sys-smtp
  (set batcher "none")
  (make-daemon)
)

(procedure ask-sys-uucp
  (set batcher
   (askfile
    (prompt "Where is your UUCP deliver command ? (\"uux -\" for wUUCP and \"send_uucp\" for all others) ")
    (help "Your uux command must be able to read the mailfile "
          "from stdin. wUUCP and AmigaUUCP 1.17 can and DillonUUCP can't do this. "
          "I need the complete path of the command. ")
    (default (tackon UUBIN "send_uucp"))
   )
  )
)

(procedure ask-sys-transport
 (set transport
  (askchoice
  (choices "UUCP" "BSMTP" "SMTP")
  (prompt (cat "Which transport should AmigaSMail use to deliver the mails to "system" ? "))
  (help "see smail.guide")
  (default 0)
  )
 )
)

(procedure make-sys
 (debug (run (cat "copy "c_sys" to "c_sys".old" )))

 (debug (run (cat "echo >"c_sys" \"#system protocol max_size local_cmd compress remote_cmd path options\"")))
 (while
     (set system
	  (askstring
	   (prompt "Give all system names (with domain if you call the systems in uulib:l.sys with domain) you call one at a time. Empty line to stop")
	   (default "")
	   (help "see smail.guide")))

    (ask-sys-transport)

    (set size "0")
    (if (= transport 0)
      (
   	(ask-sys-uucp)
      (set compress "none")
      (set rcmd "rmail")
      (set protocol "UUCP")
      )
    )

    (if (= transport 1)
      (
   	(ask-sys-bsmtp)
      (set protocol "BSMTP")
      )
    )
    (if (= transport 2)
      (
   	(ask-sys-smtp)
      (set compress "none")
      (set rcmd "none")
      (set protocol "SMTP")
      )
    )

	 (textfile
		(dest c_sys)
		(include c_sys)
		(prompt (cat "Generating new "c_sys" file"))
		(append (cat system"\t"protocol"\t"size"\t\""batcher"\"\t\""compress"\"\t\""rcmd"\"\t\""system"!%s\"\n")))
   )
)
;---------------------------------------------------------------------------
(procedure ask-paths-path
  (set p_path
   (askstring
    (prompt (cat "Give the bang (host1!..!hostN!%s) path for "p_system" ? "))
    (help (cat "The complete path to "p_system". "))
    (default (cat p_system"!%s"))
   )
  )
)

(procedure ask-paths-cost
  (set p_cost
   (asknumber
    (prompt (cat "Give the cost for "p_system"?\n"))
    (help "see smail.guide")
    (default 0)
   )
  )
)

(procedure  make-paths
 (debug (run (cat "copy "c_path" to "c_path".old" )))
 (debug (run (cat "echo noline >"c_path)))
 (while
     (set p_system
	  (askstring
	   (prompt "Give all system names you want to insert in your path file (with and without domain). "
              "If you want to use domains (e.g: previously used uulib:domain) just prepend at dot to the name. "
              "E.g: \".hanse.de\" for the domain hanse.de. "
              "Empty line to stop")
	   (default "")
	   (help "see smail.guide")))

      (ask-paths-path)
      (ask-paths-cost)
	 (textfile
		(dest c_path)
		(include c_path)
		(prompt (cat "Generating new "c_path" file"))
		(append (cat p_cost"\t"p_system"\t"p_path"\n")))
   )
)

;---------------------------------------------------------------------------
(procedure make-config-pre
 (set c_path
  (askfile
   (prompt "Where is/should be your path file ?\n")
   (help "The installer script will generate this file for you")
   (default "uulib:mail/paths")
  )
 )
 (set c_sys
  (askfile
   (prompt "Where is/should be your sys file ?\n")
   (help "The installer script will generate this file for you")
   (default "uulib:mail/sys")
  )
 )
 (debug (run (cat "copy "c_path" to "c_path".old" )))
 (debug (run (cat "echo noline >"c_path)))
 (textfile
	(dest c_path)
	(include c_path)
	(prompt (cat "Generating new "c_path" file"))
	(append (cat "0\t"c_smarthost"\t"c_smarthost"!%s\n"))
  )
)

(procedure make-config-bsmtp
 (make-config-pre)
 (ask-sys-bsmtp)
 (debug (run (cat "copy "c_sys" to "c_sys".old" )))
 (debug (run (cat "echo >"c_sys" \"#system protocol max_size local_cmd compress remote_cmd path options\"")))
 (textfile
	(dest c_sys)
	(include c_sys)
	(prompt (cat "Generating new "c_sys" file"))
	(append (cat c_smarthost"\tBSMTP\t"size"\t"batcher"\t"compress"\t"rcmd"\n"))
 )
)

(procedure make-config-uucp
 (make-config-pre)
 (ask-sys-uucp)
 (debug (run (cat "copy "c_sys" to "c_sys".old" )))
 (debug (run (cat "echo >"c_sys" \"#system protocol max_size local_cmd compress remote_cmd path options\"")))
 (textfile
	(dest c_sys)
	(include c_sys)
	(prompt (cat "Generating new "c_sys" file"))
	(append (cat c_smarthost"\tUUCP\t0\t"batcher"\tnone\trmail\n"))
 )
)

(procedure make-config-smtp
 (make-config-pre)
 (ask-sys-smtp)
 (debug (run (cat "copy "c_sys" to "c_sys".old" )))
 (debug (run (cat "echo >"c_sys" \"#system protocol max_size local_cmd compress remote_cmd path options\"")))
 (textfile
	(dest c_sys)
	(include c_sys)
	(prompt (cat "Generating new "c_sys" file"))
	(append (cat c_smarthost"\tSMTP\t0\t"batcher"\tnone\tnone\n"))
 )
)

(procedure ask-system-type
  (set systemtype
   (askchoice
    (prompt "What kind of system do you have ?")
    (help "Here you can choose some prepared system settings. ")
    (choices "don't use the prepared settings"
             "system with a single host to call using UUCP"
             "system with a single host to call using BSMTP"
             "system ONLY using SMTP")
    (default "0")
   )
  )
)

(procedure make-config
; don't use the prepared settings
 (if (= systemtype 0)
 (
  (ask-config-smarthost)
  (ask-config-dlogfile)
  (ask-config-bodylog)
  (ask-config-cnewslog)
  (ask-config-passwd)
  (ask-config-alias)
  (ask-config-path)
  (ask-config-sys)
  (ask-config-rerouting)
  (ask-config-rrt)
  (ask-config-restrictions)
  (ask-config-spoolspace)
  (ask-config-mailspace)
  (ask-config-tmpspace)
  (ask-config-tmpdir)
  (ask-config-bsmtpdir)
  (ask-config-frozen)
  (ask-config-headertype)
  (ask-config-returnfull)
  (ask-config-domainpath)
  )
 )
;system with a single host to call using UUCP
 (if (= systemtype 1)
  (
  (ask-config-smarthost)
  (ask-config-dlogfile)
  (ask-config-bodylog)
  (ask-config-cnewslog)
  (ask-config-passwd)
  (ask-config-alias)
  (make-config-uucp)
  (ask-config-rerouting)
  (ask-config-rrt)
  (ask-config-restrictions)
  (ask-config-spoolspace)
  (ask-config-mailspace)
  (ask-config-tmpspace)
  (ask-config-tmpdir)
  (ask-config-frozen)
  (ask-config-headertype)
  (ask-config-returnfull)
  (ask-config-domainpath)
  )
 )

;system with a single host to call using BSMTP
 (if (= systemtype 2)
  (
  (ask-config-smarthost)
  (ask-config-dlogfile)
  (ask-config-bodylog)
  (ask-config-cnewslog)
  (ask-config-passwd)
  (ask-config-alias)
  (make-config-bsmtp)
  (ask-config-rerouting)
  (ask-config-rrt)
  (ask-config-restrictions)
  (ask-config-spoolspace)
  (ask-config-mailspace)
  (ask-config-tmpspace)
  (ask-config-tmpdir)
  (ask-config-frozen)
  (ask-config-headertype)
  (ask-config-returnfull)
  (ask-config-domainpath)
  )
 )
;system ONLY using SMTP
 (if (= systemtype 3)
  (
  (ask-config-smarthost)
  (ask-config-dlogfile)
  (ask-config-bodylog)
  (ask-config-cnewslog)
  (ask-config-passwd)
  (ask-config-alias)
  (make-config-smtp)
  (ask-config-rerouting)
  (ask-config-rrt)
  (ask-config-restrictions)
  (ask-config-spoolspace)
  (ask-config-mailspace)
  (ask-config-tmpspace)
  (ask-config-tmpdir)
  (ask-config-frozen)
  (ask-config-headertype)
  (ask-config-returnfull)
  (ask-config-domainpath)
  )
 )

)

;---------------------------------------------------------------------------
(procedure make-binary
(set smail_type 0)
(set choice (askchoice
	    (prompt " There are different version for...")
	    (choices "support Getty passwd" "support AXSh passwd" "use MultiUserFilesystem V1.5 or higher" "use AmiTCP V3.0 or higher")
	    (default 0)
	    (help "Getty\n"
 "Insert all users of your system in getty:passwd. Insert in "
 "the comment part the realname of the user.This is only "
 "important for the Realname if you donnot use the local "
 "enviroment variable REALNAME. Besides AmigaSMail takes the home-directory "
 "for `Mail forwarding' from the getty's passwd.\n"
 "AXSh\n"
 "These programs use the AXSh passwd instead of Gettys passwd.\n"
 "MUFS\n"
 "These programs use the MUFS Version 1.5 or higher passwd instead of Gettys passwd.\n"
 "AmiTCP\n"
 "These programs use the AmiTCP Version 3.0 or higher passwd instead of Gettys passwd.")))
(if (= choice 0)
	(copyfiles
   		 (prompt "Install Getty programs...")
	   	 (help @copyfiles-help)
	       (source "bin")
		    (dest UUBIN)
   		 (choices "smail" "send_uucp")
	   	 (infos)
		    (confirm))
)

(if (= choice 1)
	(
	(copyfiles
	   	 (prompt "Install AXSh programs...")
		    (help @copyfiles-help)
      	 (source "bin")
		    (dest UUBIN)
   		 (choices "smail_axsh" "send_uucp")
   		 (infos)
		    (confirm))
			 (set smail2 (tackon UUBIN "smail_axsh"))
			 (set smail_type 1)
			 (debug (run (cat "rename from="smail2" to="smail)))
	)
)

(if (= choice 2)
	(
	(copyfiles
	   	 (prompt "Install MUFS programs...")
		    (help @copyfiles-help)
      	 (source "bin")
		    (dest UUBIN)
   		 (choices "smail_mufs" "send_uucp")
   		 (infos)
		    (confirm))
			 (set smail2 (tackon UUBIN "smail_mufs"))
			 (set smail_type 2)
			 (debug (run (cat "rename from="smail2" to="smail)))
	)
)

(if (= choice 3)
	(
	(copyfiles
	   	 (prompt "Install AmiTCP programs...")
		    (help @copyfiles-help)
      	 (source "bin")
		    (dest UUBIN)
   		 (choices "smail_amitcp" "send_uucp")
   		 (infos)
		    (confirm))
			 (set smail2 (tackon UUBIN "smail_amitcp"))
			 (set smail_type 3)
			 (debug (run (cat "rename from="smail2" to="smail)))
	)
)

; set the protection bits to exectuable and pure
(complete 40)
(debug (run (cat "protect "smail" +pe")))
(debug (run (cat "protect "mail" +pe")))
(debug (run (cat "protect "send_uucp" +pe")))
)

;---------------------------------------------------------------------------
(procedure make-links
(debug (run (cat "delete force "rmail)))
(debug (run (cat "delete force "sendmail)))
(if (= 0 (askchoice
		    (prompt "sendmail, rmail,rsmtp, rcsmtp, rfsmtp and rgsmtp\nare the same programs as smail\n")
		    (choices "make hardlinks"
			     "make copies")
		    (default 0)
		    (help "If you use hardlinks there could(!) be problems with "
                "your filesystem, because hardlinks are not fully "
                "supported by the OS.")
          )
    )
	(
	(debug (run (cat "c:Makelink to="smail" from="rmail)))
	(debug (run (cat "c:Makelink to="smail" from="sendmail)))
	(debug (run (cat "c:Makelink to="smail" from="rsmtp)))
	(debug (run (cat "c:Makelink to="smail" from="rcsmtp)))
	(debug (run (cat "c:Makelink to="smail" from="rfsmtp)))
	(debug (run (cat "c:Makelink to="smail" from="rgsmtp)))
	)
	(
	(debug (run (cat "copy clone from="smail" to="rmail)))
	(debug (run (cat "copy clone from="smail" to="sendmail)))
	(debug (run (cat "copy clone from="smail" to="rsmtp)))
	(debug (run (cat "copy clone from="smail" to="rcsmtp)))
	(debug (run (cat "copy clone from="smail" to="rfsmtp)))
	(debug (run (cat "copy clone from="smail" to="rgsmtp)))
	)
)
)

;---------------------------------------------------------------------------
(procedure set-timezone
 (set TZNAME
  (askstring
   (prompt "Set Timezone Name Variable TZNAME: "
           "AmigaSMail needs this to know the name of you timezone."
           "Don't forget to copy the TZNAME and TZOFFS variables\n"
           "from ENV: to ENVARC:\n"
           "(For syntax see Help)")
   (help  "Please use the following syntax:\n\n"
          "TZNAME <name of you timezone>\n\n"
          "If you don't want to use the features and delete TZNAME\n"
          "and TZOFFS AmigaSmail try to use the offset from\n"
          "locale program of the workbench\n"
          "e.g: I use for Germany/Europe TZNAME CET and TZOFFS +0100")
    (default "GMT")
   )
 )
(debug (run (cat "setenv TZNAME "TZNAME)))

 (set TZOFFS
  (askstring
   (prompt "Set the Timezone Offset Variable TZOFFS: "
           "AmigaSMail needs this to calculate the offset to GMT time."
           "Don't forget to copy the TZNAME and TZOFFS variables\n"
           "from ENV: to ENVARC:\n"
           "(For syntax see Help)")
   (help  "Please use the following syntax:\n\n"
          "TZOFFS +/-HHMM\n\n"
          "If you don't want to use the features and delete TZNAME\n"
          "and TZOFFS AmigaSmail try to use the offset from\n"
          "locale program of the workbench\n"
          "e.g: I use for Germany/Europe TZNAME CET and TZOFFS +0100")
    (default "+0000")
   )
 )
(debug (run (cat "setenv TZOFFS "TZOFFS)))
)
;-------------------------------------------------
(procedure ask-config-smarthost
 (set c_smarthost
  (askstring
   (prompt "The name of your smarthost (with domain)?")
    (default "foo.bar")
    (help "The host, that receives all mails from you, "
          "which can't be found in the path file")
   )
 )
)

(procedure ask-config-dlogfile
 (message "AmigaSMail generate a AmigaUUCP styled logfile. "
          "Where this logfile go is controlled by the netsupport.library. "
          "See the docs for netsupport.library for more. ")
)

(procedure ask-config-bodylog
(set c_bodylog
  (askfile
   (prompt "Where should the logfile with the full mailbody should go (use a emtpy string for NIL:)?")
   (help "In this logfile AmigaSMail logs all mail delivery with the fully mail "
         "body. Normally you should only use this option for debugging")
   (default "t:smail.log")
  )
 )
)

(procedure ask-config-cnewslog
 (set c_logtype
  (askchoice
   (choices "AmigaSMail V2.0 line-styled" "AmigaSMail V3.0/Unix-Smail styled")
   (prompt "Logfile Format ?\n")
   (help "see Smail.Guide ")
   (default 0)
  )
 )
 (set c_logfile
  (askfile
   (prompt "Where should the logfile should go (use a emtpy string for NIL:)? ")
   (help "see Smail.guide")
   (default "uulib:mail/logfile")
  )
 )
)

(procedure ask-config-passwd
 (if (= 0 smail_type)
	 (set c_passwd
	  (askfile
  		 (prompt "Where is the Getty passwd file ?\n")
  		 (help "GETTY:PASSWD is similar to the UNIX /etc/passwd file "
             "The format is:\n\n"
             "------ start of GETTY:PASSWD -----\n"
             "# Put any comment here\n"
             "#\n"
             "# User,Password,Uid,GroupId,Finger-Info,Home-Dir,Command-To-Run\n"
             "bbs,*,10,0,BBS,ram:,mybbs:c/mybbs\n")
  		(default "getty:passwd")
 	 )
 	)
 )
)

(procedure ask-config-alias
 (set c_alias
  (askfile
   (prompt "Where is your mail-alias file ?\n")
   (help "This file contains a list of aliases for local users or "
         "mailing lists.  The format of each alias is (like known by AUUCP)\n"
         "    alias_name recip_name1 recip_name2 ... \n\n"
         "Don't forget to insert white spaces as an indicator for a\n"
         "continuation line. AmigaUUCP uses a comma at the of a\n"
         "line as an indicator to continue in the next line.\n")
   (default "uulib:mail/aliases")
  )
 )
)

(procedure ask-config-path
 (set c_path
  (askfile
   (prompt "Where is/should be your path file ?\n")
   (help "Look at SMail.guide for more help")
   (default "uulib:mail/paths")
  )
 )
 (if (= 1 (askbool
	       (prompt " Do you want to make a path file ?")
          (choices "Proceed" "Skip this Part")
	       (default 0)
	       (help " If you select \"Skip this Part\" the installer script "
             " will not make a path file. If you select \"Proceed\""
             " the installer script will ask you system name, path and"
             " cost for each path entry.")
          )
     )
  (make-paths)
 )
)

(procedure ask-config-sys
 (set c_sys
  (askfile
   (prompt "Where is/should be your sys file ?\n")
   (help "Look at SMail.guide for more help")
   (default "uulib:mail/sys")
  )
 )
 (if (= 1 (askbool
	       (prompt " Do you want to make a sys file ?")
          (choices "Proceed" "Skip this Part")
	       (default 0)
	       (help " If you select \"Skip this Part\" the installer script "
             " will not make a sys file. If you select \"Proceed\""
             " the installer script will ask you system name, protocol, "
             " maxspool space, remote cmd, compress cmd and local cmd.")
          )
     )
 (make-sys)
 )
)

(procedure ask-config-rerouting
 (set c_rerouting
  (askchoice
   (choices "use rerouting" "don't use rerouting" "don't route anything")
   (prompt "Rerouting ability ?\n")
   (help " 'don't use rerouting' causes AmigaSMail to attempt to route the first "
         " component of a UUCP path, probably so it can impress people "
         " with how many UUCP hosts it knows.  If this fails, it passes "
         " the unrouted address to uux, in case the path database is "
         " not complete.  'use rerouting' causes AmigaSMail to take a UUCP "
         " path and route the rightmost component of the path (save the "
         " user name) possible.  This is mostly for hosts that have "
         " very up-to-date routing tables.")
   (default 0)
  )
 )
)

(procedure ask-config-rrt
 (set c_rrt
  (if
   (= 0
    (askchoice
     (choices "Return-Receipt-To Headers"  "ignore Return-Receipt-To Headers")
     (prompt "Return-Receipt-To Headers...\n")
     (help "AmigaSMail will send an mail with a copy of the header "
           "of the original mail to the address after the Return-Receipt-To: "
           "Header. You can turn this off via the SMReceipt keyword in the "
           "uulib:config file. See smail.guide for the recognition "
           "whether a user exists on your system.")
     (default 0)
    )
   )
   ("Yes")
   ("No")
  )
 )
)

(procedure ask-config-domainpath
 (set c_domainpath
  (if
   (= 0
    (askchoice
     (choices "No"  "Yes")
     (prompt "Domainpath...\n")
     (help "Places your fully domained host name in mail headers instead of "
           " USENET node name.  Use ONLY if your feed requires it. ")
     (default 0)
    )
   )
   ("No")
   ("Yes")
  )
 )
)

(procedure ask-config-returnfull
 (set c_returnfull
  (if
   (= 0
    (askchoice
     (choices "Full mail"  "Only the header")
     (prompt "Returning Mail...\n")
     (help "Return the full mail if the delivery fails. "
           "Else only the header is returned. ")
     (default 0)
    )
   )
   ("Yes")
   ("No")
  )
 )
)

(procedure ask-config-headertype
 (set c_headertype
    (askchoice
     (choices "Empty"  "Small received lines" "bigger received lines")
     (prompt "Received lines...\n")
     (help "see smail.guide")
     (default 1)
    )
 )
)


(procedure ask-config-frozen
 (set c_frozen
  (askfile
   (prompt "Where should go your frozen uulib:config file?\n")
   (help "Set to the filename of the freeze file and AmigaSMail "
         "will save the actual config entries into this file a "
         "read them at the next startup. This save half of the "
         "startup time. Don't forget to delete the frozen file "
         "if you change something in uulib:config ")
   (default "uulib:config.f")
  )
 )
)

(procedure ask-config-restrictions
 (set c_restrictions
  (if
   (= 0
    (askchoice
     (choices "no restrictions"  "restrictions")
     (prompt "AmigaSMail offers you the opportunity to allow only "
             "to some local users to write mail via UUCP/BSMTP/SMTP")
     (help   "See smail.guide")
     (default 0)
    )
   )
   ("No")
   ("Yes")
  )
 )
)

(procedure ask-config-spoolspace
 (set c_spoolspace
  (asknumber
     (prompt "The minimum space left on UUSPOOL: else the mail is sent back the sender")
     (help
     "AmigaSMail checks the space left on UUSPOOL: before delivering the "
     "mail. If the space is too small AmigaSMail stops delivering to make "
     "sure your system have a minimum of space left.")
     (default 204800)
    )
 )
)

(procedure ask-config-mailspace
 (set c_mailspace
  (asknumber
     (prompt "The minimum space left on UUMAIL: else the mail is sent back the sender")
     (help
     "AmigaSMail checks the space left on UUMAIL: before delivering the "
     "mail. If the space is too small AmigaSMail stops delivering to make "
     "sure your system have a minimum of space left.")
     (default 204800)
    )
 )
)

(procedure ask-config-tmpspace
 (set c_tmpspace
  (asknumber
     (prompt " AmigaSmail will temporary store several copys of the mail. This could consume lot of memory !"
             " With this option you can tell AmigaSmail how much space on T: is needed as minimum. If not "
             " enough space left on T: AmigaSmail switch to the directory defined in SMTempDir later.")
     (help @askdir-help)
	  (default 102400)
    )
 )
)

(procedure ask-config-tmpdir
 (set c_tmpdir
  (askdir
     (prompt " AmigaSmail uses this directory to store temporary files "
             " if the space on T: is smaller than SMTempSpace")
     (help @askdir-help)
	  (default "Tmp:")
    )
 )
)

(procedure ask-config-bsmtpdir
 (set c_bsmtpdir
  (askdir
     (prompt " AmigaSmail uses this directory to store BSMTP batch and SMTP queue files ")
     (help @askdir-help)
	  (default "uuspool:batch/")
    )
 )
)
;=================== init ===============
(complete 0)
(set default-dest "uucp:c")
(set @app-name "AmigaSMail")
(set @default-dest "UUCP:C")
(set need-version 37)

(welcome "    Welcome to " @app-name " installation.\n")

(set exec-version (/ (getversion) 65536))
(if (< exec-version need-version)	; check operating system version
     ((message @app-name " needs at least Exec version " need-version
	       " to run.\nYou have only version " exec-version ".\n"
	       "You can proceed with the installation, but consider "
	       "installing the " @app-name " with proper version of "
	       "the operating system."
	       (help
		"    The " @app-name " uses some system functions "
		"that are not present or functional in earlier system "
		"versions. Consider updating your system.\n"
		"    If you have a later version of operating system "
		"and are only now using older version: be sure to use "
		"only release 2.04 or newer with " @app-name ". "
		"No damage happens if you run " @app-name " with an "
		"earlier operating system, however. It just "
		"refuses to start.\n"))))

;=================== search assings ==========
(if (= @user-level 2)
    (set UULIB
	(askdir
	    (prompt "Where do you keep your uucp configs ?")
	    (help @askdir-help)
	    (default "UULIB:")
	)
    )
    (set UULIB "UULIB:")
)


(if (= @user-level 2)
    (set UUBIN
	(askdir
	    (prompt "Where do you keep your uucp binarys ?")
	    (help @askdir-help)
	    (default "UUCP:C")
	)
    )
    (set UUBIN "UUCP:C")
)

(if (= @user-level 2)
    (set UUSPOOL
	(askdir
	    (prompt "Where do you keep your uucp spool files ?")
	    (help @askdir-help)
	    (default "UUSPOOL:")
	)
    )
    (set UUSPOOL "UUSPOOL:")
)
(set @default-dest UUBIN)

(set sendmail (tackon UUBIN "sendmail"))
(set rmail (tackon UUBIN "rmail"))
(set smail (tackon UUBIN "smail"))
(set rsmtp (tackon UUBIN "rsmtp"))
(set rcsmtp (tackon UUBIN "rcsmtp"))
(set rfsmtp (tackon UUBIN "rfsmtp"))
(set rgsmtp (tackon UUBIN "rgsmtp"))
(set send_uucp (tackon UUBIN "send_uucp"))

;================= backup existings files ==========
(complete 5)

(set backup (askbool
	    (prompt " Do you want to backup your existing "sendmail","rmail","rcsmtp
               "," rfsmtp"," rgsmtp" and "rsmtp" to a backup device (default T:) ?")
       (choices "Proceed" "Skip this Part")
	    (default 0)
	    (help "none available :-(")
))

(if (= backup 1)
(

(if (exists rsmtp)
	(copyfiles
    (prompt "Backup original programs from " UUBIN)
    (help @copyfiles-help)
    (source rsmtp)
    (dest "t:")
    (infos)
    (confirm)
	)
)

(if (exists rcsmtp)
	(copyfiles
    (prompt "Backup original programs from " UUBIN)
    (help @copyfiles-help)
    (source rcsmtp)
    (dest "t:")
    (infos)
    (confirm)
	)
)

(if (exists rfsmtp)
	(copyfiles
    (prompt "Backup original programs from " UUBIN)
    (help @copyfiles-help)
    (source rfsmtp)
    (dest "t:")
    (infos)
    (confirm)
	)
)

(if (exists rgsmtp)
	(copyfiles
    (prompt "Backup original programs from " UUBIN)
    (help @copyfiles-help)
    (source rgsmtp)
    (dest "t:")
    (infos)
    (confirm)
	)
)

(if (exists rmail)
	(copyfiles
    (prompt "Backup original programs from " UUBIN)
    (help @copyfiles-help)
    (source rmail)
    (dest "t:")
    (infos)
    (confirm)
	)
)

(if (exists sendmail)
	(copyfiles
    (prompt "Backup original programs from " UUBIN)
    (help @copyfiles-help)
    (source sendmail)
    (dest "t:")
    (infos)
    (confirm)
	)
)

(if (exists send_uucp)
	(copyfiles
    (prompt "Backup original programs from " UUBIN)
    (help @copyfiles-help)
    (source send_uucp)
    (dest "t:")
    (infos)
    (confirm)
	)
)
))

;================ delete old files ================
(complete 10)

(debug (run (cat "delete force "smail)))
(debug (run (cat "delete force "rsmtp)))
(debug (run (cat "delete force "rcsmtp)))
(debug (run (cat "delete force "rfsmtp)))
(debug (run (cat "delete force "rgsmtp)))
(debug (run (cat "delete force "sendmail)))

;================ install netsupport.library ======
(complete 15)
(copylib
	(prompt "copy netsupport.library")
	(help @copylib-help)
	(source "libs/netsupport.library")
	(dest	"libs:")
	(confirm)
)
(if (= (exists "S:NSPConfig" (noreq)) 0)
 (textfile
  (dest "S:NSPConfig")
  (prompt "Generating Netsupport.library Configfile")
  (append "#\n# NetSupport.Library config file\n#\n# $VER: NSPConfig 1.23 (22.2.94)\n#\nMasterConfig    UULib:Config\nDefaultLog     UUSpool:Logfile\nDEBUG 0\n")
 )
)

;================ copy files to uubin =============
(complete 20)
(make-binary)

;================== generate rmail and sendmail =================
(complete 45)
(make-links)

;===================  setup Timezone ==========
(complete 50)
(set-timezone)

;=================== generate the uulib:config entries ==========
(complete 60)
(set uuconfig (askbool
	    (prompt " Do you want to install or modify the uulib:config"
               " entries for AmigaSMail ?\n"
               " If you don't use this option please refer to Smail.guide "
               " chapter \"Misc/Config options\" and modify the options "
               " according to your wishes.")
       (choices "Proceed" "Skip this Part")
	    (default 0)
	    (help " If you select \"Skip this Part\" the installer script "
             " will not modify your uulib:config. If you select \"Proceed\""
             " the installer script will ask you some questions and will "
             " include the AmigaSMail options to your uulib:config file." )
))

(if (= uuconfig 1)
 (
;================ ask system type =============
 (ask-system-type)


;================ make directories =============
 (complete 65)
 (set tmp (tackon UULIB "mail"))
 (if (NOT (= (exists tmp (noreq)) 2))
 	(debug (run (cat "makedir " tmp)))
 )

 (complete 66)
 (set tmp (tackon UUSPOOL "batch"))
 (if (NOT (= (exists tmp (noreq)) 2))
 	(debug (run (cat "makedir " tmp)))
 )

;=================== generate the config entries ==========
 (make-config)

;=================== write the config entries ==========
 (complete 86)
 (textfile
  (dest "t:add_to_config")
  (prompt "Generating new "UULIB"config file")
  (include (tackon UULIB "config"))
  (append "\n# Options for AmigaSMail\n")
  (append "SMDebug 0\n")
  (append "SMSmarthost ")
  (append c_smarthost)
  (append "\n")
  (append "SMSentlog ")
  (if (= "" c_bodylog)
	 (append "NIL:")
	 (append c_bodylog)
  )
  (append "\n")
  (append "SMLogType ")
  (append c_logtype)
  (append "\n")
  (append "SMLogfile ")
  (if (= "" c_logfile)
	 (append "NIL:")
	 (append c_logfile)
  )
  (append "\n")
  (append "SMAlias ")
  (append c_alias)
  (append "\n")
  (if (= 0 smail_type)
 	 (
	 (append "SMPasswd ")
	 (append c_passwd)
	 (append "\n")
	 )
  )
  (append "SMPath ")
  (append c_path)
  (append "\n")
  (append "SMSysFile ")
  (append c_sys)
  (append "\n")
  (append "SMRerouting ")
  (append c_rerouting)
  (append "\n")
  (append "SMReceipt ")
  (append c_rrt)
  (append "\n")
  (append "SMCheckuser ")
  (append c_restrictions)
  (append "\n")
  (append "SMFreeSpoolSpace ")
  (append c_spoolspace)
  (append "\n")
  (append "SMFreeMailSpace ")
  (append c_mailspace)
  (append "\n")
  (append "SMTempDir ")
  (append c_tmpdir)
  (append "\n")
  (append "SMTempSpace ")
  (append c_tmpspace)
  (append "\n")
  (append "SMBatchDir ")
  (append c_bsmtpdir)
  (append "\n")
  (append "SMDomainPath ")
  (append c_domainpath)
  (append "\n")
  (append "SMReturnFullMail ")
  (append c_returnfull)
  (append "\n")
  (append "SMHeaderType ")
  (append c_headertype)
  (append "\n")
  (if (NOT (=  c_frozen ""))
	 (
	  (append "SMFreeze ")
	  (append c_frozen)
	  (append "\n")
   )
  )
 )

 (run "copy uulib:config uulib:config.o")
 (run "copy t:add_to_config uulib:config")
 (run "delete t:add_to_config")
 )
)
(complete 90)
;=================== showing AmigaGuide ==================
(run "run AmigaGuide Doc/smail.guide"
    (prompt "Running AmigaGuide smail.guide.")
    (safe)
)

;=================== sending the accounting mail =========
(debug (run ("echo >t:smail_version \"\"")))
(debug (run ("echo >>t:smail_version \"Version strings of the commands\"")))
(debug (run (cat "Version >>t:smail_version full "smail)))
(debug (run (cat "Version >>t:smail_version full "send_uucp)))

(debug (run ("echo >t:smail_run stack 80000")))
(debug (run (cat "echo >>t:smail_run path "UUBIN)))
(debug (run (cat "echo >>t:smail_run \""sendmail" -M <t:smail_version -s SMail_account_msg smail@mavhh.hanse.de\"")))

(run ("execute t:smail_run sendmail"))

(run "delete t:smail_version")
(run "delete t:smail_run")

(complete 100)
(exit "AmigaSMail is now (hopefully correct) installed. "
      "You should edit/setup the paths file. Please read the "
      "\"Installation/Setup a path file\" section in smail.guide. "
      "Copys of your previous sendmail/rmail etc. programs can be found in t:.\n"
      "Attention !!! This Installer script sends a mail with the version strings "
      "of the installed programs to a special account (smail@mavhh.hanse.de) "
      "at the system of the AmigaSMail programmer. "
)
