#!/usr/bin/make -f
# Request Tracker is Copyright 1997-9 Jesse Reed Vincent <jesse@fsck.com>
# RT is distribute under the terms of the GNU Public License

# Initialisation for Debian GNU/LinUX by <lss@debian.org> 

#
# Mysql related preferences
#
# This is where your mysql binaries are located
#

MYSQLDIR		=	/usr/bin
PERL			= 	/usr/bin/perl
RTUSER			=	rt
RTGROUP			=	rt

RT_VERSION_MAJOR	=	1
RT_VERSION_MINOR	=	0
RT_VERSION_PATCH	=	7

RT_VERSION =	$(RT_VERSION_MAJOR).$(RT_VERSION_MINOR).$(RT_VERSION_PATCH)

# Mysql version can be 3.20, 3.21 or 3.22.  This setting determines the order 
# $rtuser and $rtpass are passed to MysqlPerl.  

MYSQL_VERSION		= 	3.23

# define MYSQL_DBADMIN to the name of a MySQL user with permission to
# create new databases 
MYSQL_DBADMIN		=	root

#
# If you have defined a password for this Mysql user,
# you must either replace "somepassword" below with the mysql password
# of that user and uncomment the line.

# If you put the password here you should REMOVE IT
# AS SOON AS "webrtinit" FINISHES !!!
#
DBADMIN_MYSQL_PASS              =       <fill in MySQL admin pwd>

ifdef DBADMIN_MYSQL_PASS
DBADMIN_MYSQL_PASS_STRING = -p$(DBADMIN_MYSQL_PASS)
else 
DBADMIN_MYSQL_PASS_STRING = 
endif

#
# this password is what RT will use to authenticate itself to mysql
# change this password so nobody else can get into your rt databases
# (be sure not to use #, @ or $ characters)
#

RT_MYSQL_PASS           =       <fill in rt MySQL pwd set in /etc/rt/config.pm>

#
# Set this to the domain name of your Mysql server
# If the database is local, rather than on a remote host, using "localhost" 
# will greatly enhance performance.
#
RT_MYSQL_HOST		=	localhost

#
# Set this to the canonical name of the interface RT will be talking to the mysql database on.
# If you said that the RT_MYSQL_HOST above was "localhost," this should be too.
# This value will be used by mysql to grant  rt on your RT server access to the Mysql database.
#

RT_HOST			=	localhost

#
# set this to the name you want to give to the RT database in mysql
#

RT_MYSQL_DATABASE	=	rt

#
# if you want to give the rt user different default privs, modify this file
#

RT_MYSQL_ACL		= 	/etc/rt/mysql.acl


default:
	#set up MySQL database
	-$(MYSQLDIR)/mysqladmin -h $(RT_MYSQL_HOST) -u $(MYSQL_DBADMIN) $(DBADMIN_MYSQL_PASS_STRING) create $(RT_MYSQL_DATABASE)
	$(MYSQLDIR)/mysql -h $(RT_MYSQL_HOST) -u $(MYSQL_DBADMIN) $(DBADMIN_MYSQL_PASS_STRING) $(RT_MYSQL_DATABASE) < /var/lib/rt/schema      

	#set up MySQL ACLs

	-$(PERL) -p -i.orig -e "if ('$(RT_HOST)' eq '') { s'!!RT_HOST!!'localhost'g}\
			else { s'!!RT_HOST!!'$(RT_HOST)'g }\
		s'!!RT_MYSQL_PASS!!'$(RT_MYSQL_PASS)'g;\
		s'!!RTUSER!!'$(RTUSER)'g;\
		s'!!RT_MYSQL_DATABASE!!'$(RT_MYSQL_DATABASE)'g;\
		" $(RT_MYSQL_ACL)
	$(MYSQLDIR)/mysql -h $(RT_MYSQL_HOST) -u $(MYSQL_DBADMIN) $(DBADMIN_MYSQL_PASS_STRING) mysql < $(RT_MYSQL_ACL) 
	$(MYSQLDIR)/mysqladmin -h $(RT_MYSQL_HOST) -u $(MYSQL_DBADMIN) $(DBADMIN_MYSQL_PASS_STRING) reload 

	clear
	@echo
	@echo " -=> Remove the MySQL Adminstrator password from rtinit now !!! <=-"
	@echo
	@echo "Use http://localhost/cgi-bin/admin-webrt.cgi to setup users and queques:"
	@echo "Login: root, password: wordpass"
	@echo "CHANGE the root password to something sensible while you're at it !!!"
