#!/usr/bin/perl -wT

#----------------------------------------------------------------------
# copyright (C) 2002 Mitel Networks Corporation
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 		
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 		
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
# 
# Technical support for this program is available from Mitel Networks 
# Please visit our web site www.mitel.com/sme/ for details.
#----------------------------------------------------------------------
use strict;
use esmith::ConfigDB;

my $conf = esmith::ConfigDB->open() or die "Unable to open config db";

# Obsolete migrate-imp-to-turba config db entry if found
my $migrateturba = $conf->get('migrate-imp-to-turba');
$migrateturba->delete if defined $migrateturba;

# Set things up for the turba address book to be created. This script
# is not safe to run multiple times, so we need to guard the creation
# of the symlink, and add a "use horde" statement.
unless(-f "/var/lib/mysql/horde/turba_objects.frm")
{
    open OUT, ">/etc/e-smith/sql/init/40mysql.create.turba.sql";
    print OUT "use horde;\n";
    open IN, "/home/httpd/html/horde/turba/scripts/drivers/turba.sql";
    print OUT while(<IN>);
    close IN;
    close OUT;
}

# set things up so that mysql.init migrates an old IMP address
# book (if one exists)
unlink "/etc/e-smith/sql/init/60migrate-imp-to-turba";
symlink "/etc/e-smith/events/actions/migrate-imp-to-turba",
        "/etc/e-smith/sql/init/60migrate-imp-to-turba";

# set things up to migrate turba 1.1 to 1.2 if necessary
unlink "/etc/e-smith/sql/init/50turba_upgrade_1.1_to_1.2";
symlink "/etc/e-smith/events/actions/turba_upgrade_1.1_to_1.2", 
        "/etc/e-smith/sql/init/50turba_upgrade_1.1_to_1.2";

exit 0;
