#!/bin/sh  

# Filename:  create_table
# Description:  This script attempts to create an additional message base
#	table for the rocat BBS system.
# Author:	Greg Shaw
# Created:	2/13/96

# BBSDIR set?
if [ "$BBSDIR" = "" ]; then
	echo Please run this script as user bbs.
	exit 1
fi

# right number of arguments?

if [ $# -ne 3 ]; then
	echo "USAGE: $0 <new_table_name> <number_of_lines_per_message> \"Long name of section\" "
	exit 1
fi

tablename=$1
textsize=`echo $2*80 | bc`

if [ $textsize -eq 0 ]; then
	echo number_of_lines_per_message must be larger than 1
	exit 1
fi


# check for msql
if [ ! -x $BBSDIR/msql/bin/msql ]; then
	echo Please compile and install the mSQL package prior to executing
	echo this utility.
	exit 1
fi

# the following items are assumed not to change on a regular basis.  
# however, to create a message area with different parameters, simply edit
# the following:
# (I wouldn't change the first 3)

# start at message 1 for the new section
HIGH_MESSAGE=0
# start at thread 1 for the new section
HIGH_THREAD=1
# 0 messages in section
NUM_MESSAGES=0
# section type:   
# 0 - private message base
# 1 - rocat message base
# 2 - fido message base (unused)
# 3 - usenet news message base (unused)
SECTION_TYPE=1
# access level to access
ACL=200
# flags to access 
FLAGS=0
# I wouldn't change the below unless you're really sure you need them
# flags/access modifier: (bit mapped -- acl and flags or'd together)
# 0x00 - no modifiers
# 0x01 - user acl must be greater than acl
# 0x02 - user acl must be equal to acl
# 0x04 - user acl must be less than acl
# 0x0100 - flags must match
# 0x0200 - flags must not match
# convert the value to decimal for the value
# (e.g. 0x0100 = 256)
# by default, use 0x0101 = 257 (greater and flags must match)
FAMOD=257
# is the section read_only?  (e.g. no postings by users)
READ_ONLY=0
# are anonymous postings allowed?
ANONYMOUS=0
# read group number (see manual for description)
GROUP=1
# days to keep messages before deletion
DAYS=7
# tagline ID:
# 0 - don't use taglines
# non-zero - use a tagline of the numbered group
TAGLINE=1
# date of last update (don't change)
DATE=0
# external name of the group (name of the fido or usenet group)
EXTERNAL_NAME=
# email address of the moderator of this section (if any)
MODERATOR=



$BBSDIR/msql/bin/msql rocat <<EOF

create table $1 (
		message_number 	int not null primary key,
		from_ 		char(50),
		to 		char(50),
		subject 	char(70),
		date 		int,
		text 		char($textsize),
		link_number     int,
		link_table      char(50),
		thread_number	int,
		local_origin 	int
)
\g

create table $1_thread (
		subject		char(70) not null primary key,
		section		char(50),
		thread_number	int,
		messages	int
)
\g


insert into info values ('$1',
		$HIGH_MESSAGE,
		$HIGH_THREAD,
		$NUM_MESSAGES,
		$SECTION_TYPE,
		$ACL,
		$FLAGS,
		$FAMOD,
		$READ_ONLY,
		$ANONYMOUS,
		$GROUP,
		$DAYS,
		$2,
		$TAGLINE,
		$DATE,
		0,
		0,
		'$EXTERNAL_NAME',
		'$MODERATOR',
		'$3'
)\g

