$ ! NEWS_SYSTARTUP.COM
$ !
$ !	Based on SETUP_LOG_EXAMPLE.COM from News 5.7 distribution.
$ !
$ !	Normally invoked by UUCP_SYSTARTUP.COM .  
$ !
$ ! Author:
$ !     G Huston
$ !       Computer Services Centre
$ !       Australian National University
$ !
$ ! Version:
$ !     V1.0    17-Jul-1986
$ !     V2.0    16-Jul-1987
$ !     V4.3    12-Jan-1987     GIH
$ !     V5.2    26-Apr-1988     GIH
$ !     V5.6     3-Nov-1988     GIH
$ !	V5.7A 	08-Feb-1989	Mark Pizzolato (for DECUS UUCP)
$ !	V5.7B	01-Apr-1989	Jamie Hanrahan (for DECUS UUCP)
$ !	V6.0-3  26-Mar-1991	Mark Pizzolato (mark@infocomm.com)
$ !**********************************************************************
$
$	defsys = "DEFINE/SYSTEM/EXEC/NAME=NO_ALIAS"
$	defsysconc = "DEFINE/SYSTEM/EXEC/TRANSLATION=CONCEALED/NAME=NO_ALIAS"
$	SAY = "WRITE SYS$OUTPUT"
$	ON ERROR THEN GOTO BAD_OPTION
$	IF ("''p1'" .NES. "") THEN GOTO 'f$extr(0,4,p1)'
$	GOTO COMMON_START
$
$BAD_OPTION:
$	SAY "Valid options:  "
$	SAY "LOGICALS, INSTALLS, BATCH_JOBS, DEINSTALL, SHUTDOWN or empty"
$	EXIT
$
$ COMMON_START:
$
$ LOGI:
$
$!	********************************************************************
$!	****								****
$!	****	Local customizations begin here				****
$!	****								****
$!	********************************************************************
$
$ ! This logical defines the device on which all of the news items will 
$ ! live.  Normal news activity on this device will create and delete LARGE
$ ! numbers of small files, which will quickly result in a very fragmented
$ ! disk.  This is normally not a big problem if this disk is used exclusively
$ ! for lots of relatively small files.
$ ! P2 specifies the disk; if blank, we assume UUCP_DISK.  Either way, this 
$ ! code tries to find NEWS.DIR in either of its likely abodes on the disk 
$ ! -- as a UFD or as a subdirectory of [UUCP].  
$
$	news_disk = "''p2'"
$	if (news_disk .eqs. "") then news_disk = "UUCP_DISK:"
$
$	news_disk = (news_disk - ":") + ":" ! ensure there's a trailing colon
$	news_disk = f$parse(news_disk,,,"DEVICE")
$	root = ""
$	if f$search("''news_disk'[000000]NEWS.DIR") .nes. "" 
$	then
$		root = news_disk + "["
$	else
$		if f$search("''news_disk'[UUCP]NEWS.DIR") .nes. "" then -
			root = news_disk + "[UUCP."
$	endif
$	if root .eqs. "" then -
	 say "NEWS_SYSTARTUP WARNING:  NEWS.DIR not found, NEWS_ROOT and NEWS_DEVICE not defined"
$
$	defsys		NEWS_ROOT	'root'NEWS]
$	defsysconc	NEWS_DEVICE	'root'NEWS.]
$
$ ! The "work directory" for news - normally sys$login of the news manager 
$ ! account.  Assumptions elsewhere in NEWS_RNEWS and NEWSSKIM presume that
$ ! these directories are on the same device as the NEWS_DEVICE.
$
$	defsys		NEWS_MANAGER	'root'NEWS_MGR]
$	defsysconc	NEWS_MANAGER_DEV 'root'NEWS_MGR.]
$ 
$
$ ! finally... if P3 is specified, it may be used to override NEWS_ROOT .  
$ ! NEWS_ROOT is where the large indexed files NEWS.ITEMS, NEWS.GROUPS, 
$ ! and NEWS.HISTORY are kept.  This allows these files to live on a 
$ ! separate disk from the news item text files.  
$
$ if "''p3'" .nes. "" then defsys NEWS_ROOT 'p3'
$
$ ! This logical equates to the username (NEWSMGR is recommended in the 
$ ! News documentation; in uucp we use NETNEWS) under which the News batch
$ ! jobs will run.  This is used in a subsequent SUBMIT command.  The 
$ ! corresponding INIT/QUEUE command assumes that an identifier of this 
$ ! name also exists.  
$
$	defsys		NEWS_MGR_UN	NETNEWS
$
$ ! the following two logical names are the mail destinations used by
$ ! other sites when forwarding news as mail.  These logicals point all
$ ! such mail at the "news manager" account described above.  This purpose
$ ! could also be served by giving the following commands to Mail:
$ !
$ !	MAIL> SET FORWARD/USER=RNEWS NEWS_MGR_UN
$ !	MAIL> SET FORWARD/USER=NEWSMAIL NEWS_MGR_UN
$
$	defsys		RNEWS		'f$trnlnm("NEWS_MGR_UN")'
$	defsys		NEWSMAIL	'f$trnlnm("NEWS_MGR_UN")'
$
$ ! People who do news management functions (creating newsgroups, etc.) must
$ ! own the identifier named by this logical, as must the username under which
$ ! the NEWSSKIM batch job will run (named by the logical NEWS_MGR_UN).  This
$ ! identifier must be *different* from that username so that it can be granted
$ ! to other usernames.  
$
$	defsys 		NEWS_MGR_ID	NEWSMANAGER
$
$ ! the logical name USENET defines the name of the account which should
$ ! receive mail regarding administrative details of the news system's
$ ! operation.  This should NOT be the NEWS_MGR_UN defined above - It should
$ ! be an account where a person logs and has been granted the NEWS_MGR_ID
$ ! identifier.  The default value for this is the same as the UUCP_POSTMASTER.
$ ! This also could be resolved with a mail forward as RNEWS and NEWSMAIL above.
$
$	defsys		USENET		'f$trnlnm("UUCP_POSTMASTER")'
$
$ ! NEWS_ADDRESS is the internet address of the node.  This is used to build
$ ! Reply-To headers in locally-written news items.  We assume that this will
$ ! be the same as logical UUCP_DOMAIN_NAME; if that doesn't exist we'll make 
$ ! do with uucp_host_name.UUCP .  If neither name exists, complain.
$
$	if f$trnlnm("UUCP_HOST_NAME") .nes. "" then -
		defsys	NEWS_ADDRESS	"''f$trnlnm(""UUCP_HOST_NAME"")'.UUCP"
$	if f$trnlnm("UUCP_DOMAIN_NAME") .nes. "" then -
	 	defsys	NEWS_ADDRESS	"''f$trnlnm(""UUCP_DOMAIN_NAME"")'"
$	if f$trnlnm("NEWS_ADDRESS") .eqs. "" then -
	 say "NEWS_SYSTARTUP WARNING:  No uucp host or domain name, NEWS_ADDRESS not defined"
$
$ ! The following two names, NEWS_NODE and NEWS_PATHNAME, are NOT (normally)
$ ! DECnet node names, but rather the name by which this NEWS site will be known
$ ! to the rest of the News world.  For uucp sites, this will generally be the 
$ ! same as the uucp host name; in a non-uucp site, it will be the site's 
$ ! fully-qualified domain name.  This should be the same as the name of the 
$ ! system as defined in the NEWS.SYS entry that defines the local node's 
$ ! filter set.  
$ ! 
$ ! NEWS_NODE is the string that NEWS looks for in the Path: line of incoming 
$ ! articles, to determine whether an incoming article has already passed 
$ ! through this node.  
$ ! NEWS_PATHNAME is the string that NEWS places in the Path: line of outgoing
$ ! articles (whether written locally or route-through).
$ ! Normally these should be identical.  
$ !
$ ! We define both of these to be either the UUCP_DOMAIN_NAME 
$ ! or the UUCP_HOST_NAME, with preference for the latter if both exist.  
$ 
$	if f$trnlnm("UUCP_DOMAIN_NAME") .nes. "" then -
	 	defsys	NEWS_NODE	"''f$trnlnm(""UUCP_DOMAIN_NAME"")'"
$	if f$trnlnm("UUCP_HOST_NAME") .nes. "" then -
		defsys	NEWS_NODE	"''f$trnlnm(""UUCP_HOST_NAME"")'"
$	if f$trnlnm("NEWS_NODE") .nes. "" then -
		defsys	NEWS_PATHNAME	"''f$trnlnm(""NEWS_NODE"")'"
$	if f$trnlnm("NEWS_NODE") .eqs. "" then -
	 say "NEWS_SYSTARTUP WARNING:  No uucp host or domain name, NEWS_NODE not defined"
$
$ ! The news log directory.  This is new for DECUS UUCP.  
$
$	defsys		NEWS_LOG	'f$trnlnm("UUCP_DISK")'[UUCP.NEWS_LOG]
$
$ ! Organisation name (placed in headers of locally-created messages)
$
$	defsys NEWS_ORGANISATION -
		"INFO COMM - Computer Consulting, Redwood City, Ca"
$
$ ! Batch Queue to run NEWSSKIM.COM , which does Expired-Skimming, Delivery, 
$ ! and Remote Posting.
$ !
$ ! (see the BATCH_JOBS entry below)
$
$	defsys		NEWS_BATCH_QUEUE	NEWS_BATCH
$
$ ! If you are running this on a VAX Cluster, you must specify
$ ! which node will be the execution node for the queue defined by
$ ! the above logical NEWS_BATCH_QUEUE.  If you are not on a cluster
$ ! leave this defined as "-" .  (If you convert to a cluster 
$ ! environment later, don't forget to change this.)
$
$	defsys		NEWS_BATCH_NODE		"VS3100"
$
$ ! when adding news batches from other systems, should `control' messages
$ ! (other than cancels) be executed automatically (Y) or just mailed to 
$ ! the local username, USENET (N)?  
$
$	defsys		NEWS_EXECUTE_CONTROL	"N"
$
$ ! when adding news batches from other systems, if items arrive for groups
$ ! which do not exist on the local machine, should the groups be created
$ ! automatically (Y) or not (N)?
$
$	defsys		NEWS_AUTO_CREGRP	"N"
$
$ ! the timezone (put in news headers) should always be the same as the 
$ ! UUCP value
$	defsys		NEWS_TIMEZONE		"''f$trnlnm("UUCP_TIME_ZONE")'"
$
$ ! define the difference between Coordinated Universal Time (UTC, GMT, 
$ ! whatever you want to call it) and local time.  
$ ! here we derive the NEWS_GMT_OFFSET from the timezone given RFC822 rules.
$
$	news_gmt_offset = ""
$	news_tz = f$trnlnm("NEWS_TIMEZONE")
$	if news_tz.eqs."PST" then news_gmt_offset = "-08:00"
$	if news_tz.eqs."PDT" then news_gmt_offset = "-07:00"
$	if news_tz.eqs."MST" then news_gmt_offset = "-07:00"
$	if news_tz.eqs."MDT" then news_gmt_offset = "-06:00"
$	if news_tz.eqs."CST" then news_gmt_offset = "-06:00"
$	if news_tz.eqs."CDT" then news_gmt_offset = "-05:00"
$	if news_tz.eqs."EST" then news_gmt_offset = "-05:00"
$	if news_tz.eqs."EDT" then news_gmt_offset = "-04:00"
$	if news_tz.eqs."GMT" then news_gmt_offset =  "00:00"
$	if news_tz.eqs."UT"  then news_gmt_offset =  "00:00"
$	if news_tz.eqs."1A"  then news_gmt_offset = "-01:00"
$	if news_tz.eqs."1B"  then news_gmt_offset = "-02:00"
$	if news_tz.eqs."1C"  then news_gmt_offset = "-03:00"
$	if news_tz.eqs."1D"  then news_gmt_offset = "-04:00"
$	if news_tz.eqs."1E"  then news_gmt_offset = "-05:00"
$	if news_tz.eqs."1F"  then news_gmt_offset = "-06:00"
$	if news_tz.eqs."1G"  then news_gmt_offset = "-07:00"
$	if news_tz.eqs."1H"  then news_gmt_offset = "-08:00"
$	if news_tz.eqs."1I"  then news_gmt_offset = "-09:00"
$	if news_tz.eqs."1K"  then news_gmt_offset = "-10:00"
$	if news_tz.eqs."1L"  then news_gmt_offset = "-11:00"
$	if news_tz.eqs."1M"  then news_gmt_offset = "-12:00"
$	if news_tz.eqs."1N"  then news_gmt_offset = "+01:00"
$	if news_tz.eqs."1O"  then news_gmt_offset = "+02:00"
$	if news_tz.eqs."1P"  then news_gmt_offset = "+03:00"
$	if news_tz.eqs."1Q"  then news_gmt_offset = "+04:00"
$	if news_tz.eqs."1R"  then news_gmt_offset = "+05:00"
$	if news_tz.eqs."1S"  then news_gmt_offset = "+06:00"
$	if news_tz.eqs."1T"  then news_gmt_offset = "+07:00"
$	if news_tz.eqs."1U"  then news_gmt_offset = "+08:00"
$	if news_tz.eqs."1V"  then news_gmt_offset = "+09:00"
$	if news_tz.eqs."1W"  then news_gmt_offset = "+10:00"
$	if news_tz.eqs."1X"  then news_gmt_offset = "+11:00"
$	if news_tz.eqs."1Y"  then news_gmt_offset = "+12:00"
$	if news_tz.eqs."1Z"  then news_gmt_offset =  "00:00"
$	if (f$extract(0,1,news_tz).eqs."-").or.			-
	   (f$extract(0,1,news_tz).eqs."+") then 		-
		news_gmt_offset = f$extract(0,3,news_tz) + ":"	-
					+ f$extract(3,2,news_tz)
$	if news_gmt_offset.nes."" 
$	  then 
$	    defsys	NEWS_GMT_OFFSET	"''news_gmt_offset'"
$	  else
$	    SAY "%NEWS-W-UNKTZONE, Unknown Timezone (non RFC822): ''news_tz'"
$	    SAY "-NEWS-W-GMTONOTSET, NEWS_GMT_OFFSET not set"
$	endif
$
$ IF ("''p1'" .NES. "") THEN EXIT
$
$ INST:
$
$ @'f$environment("PROCEDURE")' DEINSTALL
$
$ ! Install the News user interface program with sysprv (so that created news
$ ! items are owned by NEWSMGR, not by the writer) and syslck (so that record
$ ! locking on the news database works cluster-wide).   
$
$	install = "$install/command_mode"
$	install
add NEWS_ROOT:NEWS/OPEN/HEAD/SHARE/PRIV=(SYSPRV,SYSLCK)
exit
$
$ IF ("''p1'" .NES. "") THEN EXIT
$
$ BATC:
$
$ ! make sure the queue exists, and start it in any case.  
$ ! The working set values shown here were not picked arbitrarily.  
$ ! The large WSEXTENT is needed for MAKEPATHS (which is invoked by
$ ! NEWSSKIM on the first run of the day, if new maps have arrived through
$ ! the news).  It also helps significantly on the news database rebuilds 
$ ! that happen weekly.  Note NEWSSKIM attempts to only run these resource
$ ! intensive tasks in the middle of the night.
$ !
$ ! THIS QUEUE MUST HAVE A /JOB_LIMIT OF ONE, NO MORE.  
$ !
$ ! THIS QUEUE SHOULD NOT BE STARTED FROM SYSTARTUP.COM UNLESS THIS
$ ! IS DONE AFTER UUCP_SYSTARTUP HAS COMPLETED.  Otherwise, NEWSSKIM
$ ! might try to send things out via uucp before the UUCP_ logicals
$ ! exist.   Note that UUCP_SYSTARTUP has a provision to start this
$ ! command proc at the appropriate time, if invoked with the correct
$ ! P2 parameter.  
$
$	START = "/START"
$	IF .NOT.F$GETSYI("CLUSTER_MEMBER") THEN GOTO INIT_Q
$	BATCH_NODE = f$trnlnm("NEWS_BATCH_NODE")
$	START = START + "/ON=" + BATCH_NODE + "::"
$	IF BATCH_NODE.NES.F$GETSYI("NODENAME") THEN START = START - "/START"
$INIT_Q:
$!
$!
$	INITIALIZE/QUEUE 'START' /BATCH 		-
		/DESCRIPTION="Network NEWS Processing"	-
		/OWNER=['f$trnlnm("NEWS_MGR_UN")']	-
		/PROT=(OWNER:RWD,GROUP:RWD,WORLD)	-
		/JOB_LIMIT=1 /BASE_PRIO=2		-
		/WSQUOTA=1024 /WSEXTENT=10240		-
		/NOENABLE_GENERIC			-
		'f$trnlnm("NEWS_BATCH_QUEUE")'
$
$ ! Start the SKIM and Delivery Batch Job.
$ ! we don't want to do this if the job is already in the queue.
$
$	STATUS_SKIM = 0
$	JUNK = F$GETQUI("CANCEL_OPERATION")
$	QUEUE = F$TRNLNM("NEWS_BATCH_QUEUE")
$	QNAME = F$GETQUI("DISPLAY_QUEUE","QUEUE_NAME",QUEUE,"BATCH,WILDCARD")
$	IF QNAME .EQS. "" THEN GOTO QLOOP_END
$
$QLOOP:	JNAME = F$GETQUI("DISPLAY_JOB", "JOB_NAME",,"ALL_JOBS")
$	IF JNAME .EQS. "" THEN GOTO QLOOP_END
$	IF JNAME .EQS. "NEWSSKIM" THEN STATUS_SKIM = 1
$	GOTO QLOOP
$
$QLOOP_END:
$	JUNK = F$GETQUI("CANCEL_OPERATION")
$	IF (STATUS_SKIM .EQ. 0)
$	THEN 
$
$	! We let the first invocation of this run now, and the automatic
$	! resubmit will work with the desired intervals.
$
$		SUBMIT/LOG=NEWS_LOG:/NOPRINT/RESTART		-
			/USER='f$trnlnm("NEWS_MGR_UN")'		-
			/QUEUE=NEWS_BATCH_QUEUE 		-
			UUCP_BIN:NEWSSKIM.COM
$	ENDIF
$
$	EXIT
$
$ !
$ ! Deinstall and/or Shutdown NEWS
$ !
$ SHUT:
$	IF F$GETSYI("CLUSTER_MEMBER")
$	THEN
$		IF f$trnlnm("NEWS_BATCH_NODE").EQS.f$getsyi("NODENAME")
$		THEN
$			STOP/QUEUE/RESET 'f$trnlnm("NEWS_BATCH_QUEUE")'
$		ENDIF
$	ELSE
$		STOP/QUEUE/RESET 'f$trnlnm("NEWS_BATCH_QUEUE")'
$	ENDIF
$ DEIN:
$	install = "$install"
$	if f$file_attributes("NEWS_ROOT:NEWS.EXE","KNOWN") THEN 	-
		install NEWS_ROOT:NEWS.EXE/delete
$ EXIT
