#!/bin/sh

# Filename:  initiate database
# Description:  This script attempts to create an initial message database 
#   for the rocat BBS system.
# Author:	Greg Shaw
# Created:	1/17/96

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

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


# create messages database
$BBSDIR/msql/bin/msqladmin create rocat

# failed?
if [ $# -ne 0 ]; then
	echo I am unable to create the database.  Please check that the 
	echo database has been started.
	exit 1
fi


# check for msql
if [ ! -x $BBSDIR/msql/bin/msql ]; then
	echo I am unable to find the msql command.  Exiting!
	exit 1
fi

# create the lock table

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

create table lock (
		table_name 	char(50),
		record_id	int not null,
		date 		int,
		username	char(11)
)
\g

create table tagline (
		tag_id		int not null,
		tagline		char(320)
)
\g
		

create table private (
		message_number 	int not null primary key,
		from_ 		char(50),
		to 		char(50),
		subject 	char(70),
		date 		int,
		text 		char(12000),
		link_message	int,
		link_table	char(50),
		thread_number	int,
		local_origin 	int
)
\g

create table info (
		table_name char(50) not null primary key,
		high_message 	int,
		high_thread 	int,
		num_messages 	int,
		section_type	int,
		acl		int,
		flags		int,
		modifier	int,
		read_only	int,
		anonymous	int,
		group		int,
		days		int,
		maxlines	int,
		tagline		int,
		date		int,
		last_import	int,
		high_import	int,
		external_name	char(150),
		moderator	char(100),
		long_name	char(150)
)
\g

insert into info values ('private',1,1,0,0,0,257,0,0,0,0,7,150,0,0,0,0,'','','Private Email')\g

	
