! 30 Mar 89
!
! Terry Lambert
!
! 30 Mar 89	Fixed for SysV.3 execute access so message base happy,
!		moved bbstart to .profile to avoid SysV rsh problems on
!		startup.  Possible to make it work anyway, but it would
!		require .profile to take a lot of steroids.
!
! Grapevine 2.0 installation, customized for, and runnable on, UNIX only
! run me by typing: term -z bbsinst
!

! Name:		install
! Purpose:	install bbs system core files and directories
! Parameters:	optional: owning user for unix chmod command [UNIX]
! Comments:	1) should only be run by root, else may not work
!		2) must have first created the username bbs.  May
!		   be changed to something else later, or may use
!		   the desired owner-username as a parameter
!		3) files bbstart, bbs.cmd, bbsio.cmd, and bbsmail.cmd must be in
!		   the current directory

! DOS Comments:	1) files bbs.bat, bbs.cmd, bbsio.cmd, and bbsmail.cmd must be in
!		   the current directory

if opsys()>1 and opsys()<4				! UNIX type system
	? "Are you logged in and running as root? ";
	if toupper(chrin())!="Y"
		? "NO"
		? "You must be logged in and running as root to install"
		? "the BBS files and set appropriate permissions."
		quit
	endif
	? "YES"
	? "Is there a user named 'bbs' in the password file? ";
	if toupper(chrin())!="Y"
		? "NO"
		? "This installation routine assumes a user named bbs"
		? "exists and changes ownership and permissions in a"
		? "way that requires it.  Add the user bbs and run again."
		? "Read the file bbs.txt or add the following line to"
		? "your /etc/passwd file:"
		? "bbs::64:64:Bulletin board:/usr/term/bbs:/usr/term/bbs/bbstart"
		quit
	endif
	? "YES"
	if !exists("bbstart")
		? "'bbstart' is not in the current directory - cannot proceed"
		quit
	endif
!elseif opsys()=1					! MS-DOS
!	if !exists("bbs.bat")
!		? "'bbs.bat' is not in the current directory - cannot proceed"
!		quit
!	endif
else
	? "Grapevine 2.0 only provides support for UNIX-like operating"
	? "systems.  You will have to 'get into it' to use it on some systems"
	? "such as VMS, as it will require some modification in areas such"
	? "as system calls and directory syntax."
	quit
endif

!
! non-system specific stuff: next time we check, we don't care unless we're
! running under MS-DOS, because we threw out all the other non-UNIX ones
! in the code above
!

!
! check for the common files
!

if !exists("bbs.cmd")
	? "'bbs.cmd' is not in the current directory - cannot proceed"
	quit
endif
if !exists("bbsmail.cmd")
	? "'bbsmail.cmd' is not in the current directory - cannot proceed"
	quit
endif
if !exists("bbsio.cmd")
	? "'bbsio.cmd' is not in the current directory - cannot proceed"
	quit
endif
if !exists("bbsadmin.cmd")
	? "'bbsadmin.cmd' is not in the current directory - cannot proceed"
	quit
endif

!
! make the directory
!

iferror mkdir bbs
	? "Cannot create directory bbs under current one"
	quit
else
	if opsys()>1 and opsys()<4	! unix/xenix only
		run chown bbs bbs
		run chmod 755 bbs
	endif
endif

!
! copy the files
!

iferror copy bbs.cmd bbs/bbs.cmd
	? "Cannot copy bbs.cmd to bbs directory"
	quit
endif
iferror copy bbsmail.cmd bbs/bbsmail.cmd
	? "Cannot copy bbsmail.cmd to bbs directory"
	quit
endif
iferror copy bbsio.cmd bbs/bbsio.cmd
	? "Cannot copy bbsio.cmd to bbs directory"
	quit
endif
iferror copy bbsadmin.cmd bbs/bbsadmin.cmd
	? "Cannot copy bbsadmin.cmd to bbs directory"
	quit
endif



if opsys()>1 and opsys()<4				! UNIX type system
	iferror copy bbstart bbs/.profile
		? "Cannot copy bbstart shell file to bbs directory .profile"
		quit
	endif
	? "DO NOT type 'bbstart' under the bbs directory to execute; Install"
	? "so that a user may type 'bbs' at login time, make the account"
	? "with the username 'bbs' have bbs/.profile as it's shell profile."
!elseif opsys()=1						! MS-DOS
!	iferror copy bbs.bat bbs/bbs.bat
!		? "Cannot copy bbs.bat to bbs directory"
!		quit
!	endif
endif

cd bbs

! The startup file
? "Creating the 'startup' file: contains the system startup message"
if exists("startup")
	erase startup
endif
fcreate 1,"startup"
fwriteln 1,"This text is in the file called startup under the bbs directory"
fwriteln 1,"and will be displayed upon bbs initializtion upon each 'run'..."
fwriteln 1,"That is, it will be shown to each caller, as a system bulletin"
fwriteln 1,"at call connect time.  Registration and other general information"
fwriteln 1,"can therefore be put here for public viewing."
fclose 1

! The user file
? "Creating the 'userlist' file: contains system user information"
if exists("userlist")
	erase userlist
endif
fcreate 1,"userlist"
fwriteln 1,"############################## ###### #################### ## #### xx"
fwriteln 1,"ADMIN ADMIN                    ADMIN  THE ADMINISTRATOR    20 511  xx"
fclose 1

! The "stats" file
? "Creating the 'stats' file: contains system statistics"
if exists("stats")
	erase stats
endif
fcreate 1,"stats"
fwriteln 1,"You are currently talking to:"
fwriteln 1,""
fwriteln 1,"  - Grapevine 2.0 machine-independent BBS, written in"
fwriteln 1,"  - Century Software's TERM 'The latest and greatest!'"
fwriteln 1,""
fwriteln 1,"For more information regarding this BBS program, or the"
fwriteln 1,"TERM programmable communication software, contact"
fwriteln 1,""
fwriteln 1,"      Century Software"
fwriteln 1,"      5284 South 320 West"
fwriteln 1,"      Suite C134"
fwriteln 1,"      Salt Lake City, UT  84107"
fwriteln 1,"      (801) 268-3088"
fwriteln 1,""
fwriteln 1,"Runs identically under DOS, UNIX, XENIX, and VMS"
fwriteln 1,"ONE PROGRAM does 10 protocols, 14 emulations, 140+ machines"
fclose 1

if !exists("message")
	? "Creating upload directory"
	mkdir upload
	? "Creating download directory"
	mkdir dnload
	? "Creating message directory"
	mkdir message
	cd message
	? "Creating the message base 'general'... up to 19 more may be"
	? "added using 'mkdir basename' under the directory message."
	mkdir general
else
	? "Warning! File or directory 'message' exists!  NOT creating the"
	? "message or file base... I am assuming it already exists!\007"
endif

if opsys()>1 and opsys()<4
? "Setting permissions for UNIX files... please wait"
set echo on
	run chmod 755 general
	run chown bbs general
	cd ..
	run chmod 755 .profile
	run chown bbs .profile

	run chmod 666 bbsio.cmd bbs.cmd bbsmail.cmd bbsadmin.cmd
	run chown bbs bbsio.cmd bbs.cmd bbsmail.cmd bbsadmin.cmd

	run chmod 755 message upload dnload startup userlist stats
	run chown bbs message upload dnload startup userlist stats
	set echo off
endif
? "DONE.  Sysop currently logs in with first name ADMIN, last name ADMIN,"
? "       and password ADMIN.  User maintenance is done with menus which will"
? "       only show to sysops.  Uploaded files will be put in the directory"
? "       upload, downloadable files in the directory download.  TERM and the"
? "       Kermit protocols allow *.* files to be sent.  Time limits can be set"
? "       with a minor code modification by the operator.   File formats are"
? "       shown in all routines using files in 'bbsio.cmd' and 'bbsmail.cmd'."
quit
