Zarafa quick install script

From SME Server
Revision as of 06:55, 7 December 2013 by RequestedDeletion (talk | contribs) (added note)
Jump to navigation Jump to search

The below script will install the latest Zarafa 7.0, including dependencies and custom templates as per http://wiki.contribs.org/Zarafa_on_SME8. Please be aware that you read the how-to carefully to fully understand what the below script will install, remove or modify!!. The script will asume it runs on a fresh and updated SME8 setup connected to the internet. The main reason for this script is to reduce the installation time required of installing Zarafa 7.0 on SME8. {{Note box|

  • This script will only work with the Zarafa 7.0 series, it will fail on the 7.1 series due to changes in Zarafa 7.1 config files
  • The server must have internet access when te script is executed.
  • This is not a 'point and click' installation. A thorough understanding of Zarafa, SME Server and DB entries is required. Please study this page carefully.
  • This script is intended for 64-bit architecture. For SME-32-bit adapt the script at the end, where it needs to download the 32-bit zcp-package (zcp-7.0.14-42060-rhel-5-i386-free.tar.gz) and be executed in the 32-bit-directory (zcp-7.0.14-42060-rhel-5-i386). Just change the x86_64-references to i386-references at the end of the script.} (Adjusted script to auto detect architecture and SME Version)}

What we actually need is a member that has RPM skills to create and maintain a SME8-Zarafa7 rpm. Interested anyone?


1. Log in as root and create an installation directory and move to that directory

2. Copy the below script and paste it into the installation directory as install-zarafa7.sh

3. Make install-zarafa.sh executable (chmod 755 install-zarafa7.sh)

4. Execute the script (./install-zarafa7.sh)

The script will take care of all downloads, templates and custom templates (as per the how-to) and will leave you at the point where you have to select language (UTF) and zarafa mechanism db or unix.

From there on you need to follow the how-to from here.


install-zarafa7.sh

(credits forum user frifri)

#!/bin/sh
#
# Zarafa on SME8
#

zarafainstall ()
{
if [ `whoami` != "root" ]; then
	echo "This installation must be run as user root."
	echo "Become root, and run this script again."
	echo
	exit 1
fi

##########################################
# Creating some Zarafa-actions
##########################################

#
#--- zarafa-expand-templates ---
#
echo
echo "Creating zarafa-expand-templates-action ..."
echo
cat <<HERE1 > /etc/e-smith/events/actions/zarafa-expand-templates
#!/bin/sh
/sbin/e-smith/expand-template /etc/zarafa/gateway.cfg
/sbin/e-smith/expand-template /etc/zarafa/ical.cfg
/sbin/e-smith/expand-template /etc/zarafa/server.cfg
/sbin/e-smith/expand-template /etc/zarafa/unix.cfg
/sbin/e-smith/expand-template /etc/zarafa/monitor.cfg
/sbin/e-smith/expand-template /etc/zarafa/indexer.cfg
/sbin/e-smith/expand-template /etc/zarafa/spooler.cfg
/sbin/e-smith/expand-template /etc/zarafa/dagent.cfg
/sbin/e-smith/expand-template /etc/zarafa/licensed.cfg
/etc/e-smith/events/actions/qmail-update-user
HERE1


#
#--- zarafa-services ---
#
echo
echo "Creating zarafa-services-action ..."
echo
cat <<HERE2 > /etc/e-smith/events/actions/zarafa-services
#!/bin/sh
FILE=/etc/rc.d/init.d/zarafa-licensed
if [ "\$1" == start ]; then
 /etc/rc.d/init.d/zarafa-dagent start
 /etc/rc.d/init.d/zarafa-gateway start
 /etc/rc.d/init.d/zarafa-ical start
 if [ -a \$FILE ]; then \$FILE start; fi
 /etc/rc.d/init.d/zarafa-monitor start
 /etc/rc.d/init.d/zarafa-spooler start
 /etc/rc.d/init.d/zarafa-indexer start
 /etc/rc.d/init.d/zarafa-server start
 exit 0
fi
if [ "\$1" == stop ]; then
 /etc/rc.d/init.d/zarafa-dagent stop
 /etc/rc.d/init.d/zarafa-gateway stop
 /etc/rc.d/init.d/zarafa-ical stop
 if [ -a \$FILE ]; then \$FILE stop; fi
 /etc/rc.d/init.d/zarafa-indexer stop
 /etc/rc.d/init.d/zarafa-spooler stop
 /etc/rc.d/init.d/zarafa-server stop
 /etc/rc.d/init.d/zarafa-monitor stop  
 exit 0
fi
if [ "\$1" == restart ]; then
 /etc/rc.d/init.d/zarafa-dagent stop
 /etc/rc.d/init.d/zarafa-gateway stop
 /etc/rc.d/init.d/zarafa-ical stop
 if [ -a \$FILE ]; then \$FILE stop; fi
 /etc/rc.d/init.d/zarafa-monitor stop
 /etc/rc.d/init.d/zarafa-indexer stop
 /etc/rc.d/init.d/zarafa-spooler stop
 /etc/rc.d/init.d/zarafa-server stop
 /etc/rc.d/init.d/zarafa-dagent start
 /etc/rc.d/init.d/zarafa-gateway start
 /etc/rc.d/init.d/zarafa-ical start
 if [ -a \$FILE ]; then \$FILE start; fi
 /etc/rc.d/init.d/zarafa-monitor start
 /etc/rc.d/init.d/zarafa-server start
 /etc/rc.d/init.d/zarafa-spooler start
 /etc/rc.d/init.d/zarafa-indexer start
 exit 0
fi
if [ "\$1" == enabled ]; then
 config setprop zarafa-gateway status enabled
 config setprop zarafa-ical status enabled
 if [ -a \$FILE ]; then config setprop zarafa-licensed status enabled; fi
 config setprop zarafa-monitor status enabled
 config setprop zarafa-server status enabled
 config setprop zarafa-spooler status enabled
 config setprop zarafa-indexer status enabled
 config setprop zarafa-dagent status enabled
 exit 0
fi
if [ "\$1" == disabled ]; then
 config setprop zarafa-gateway status disabled
 config setprop zarafa-ical status disabled
 if [ -a \$FILE ]; then config setprop zarafa-licensed status disabled; fi
 config setprop zarafa-monitor status disabled
 config setprop zarafa-server status disabled
 config setprop zarafa-spooler status disabled
 config setprop zarafa-indexer status disabled
 config setprop zarafa-dagent status disabled
 exit 0
fi
echo "Usage: start|stop|restart|enabled|disabled"
exit 0
HERE2


#
#--- zarafa-create-user-action ---
#
echo
echo "Creating zarafa-create-user-action ..."
echo
cat <<HERE3 > /etc/e-smith/events/actions/zarafa-create-user
#!/bin/sh
clear
/bin/echo "Enter the username of the ZARAFA-user"
/bin/echo "If you have a multicompany-setup, format of the SME-username and the ZARAFA-username"
/bin/echo "has to be [username].[companyname] !!!"
read USERNAME
/bin/echo "Enter password:"
read PASSWORD
/bin/echo "Enter e-mail address:"
read EMAIL
/bin/echo "Enter full name:"
read FULLNAME
/bin/echo "Executing..."
/usr/bin/zarafa-admin -c "\$USERNAME" -p "\$PASSWORD" -e "\$EMAIL" -f "\$FULLNAME"
/usr/bin/zarafa-admin -l
/sbin/e-smith/db accounts setprop \$USERNAME zarafa enabled 
/etc/e-smith/events/actions/qmail-update-user
HERE3


#
#--- zarafa-create-company-action ---
#
echo
echo "Creating zarafa-create-company-action ..."
echo
cat <<HERE4 > /etc/e-smith/events/actions/zarafa-create-company
#!/bin/sh
clear
/bin/echo "Enter the companyname :"
read COMPANYNAME
/bin/echo "Executing..."
/usr/bin/zarafa-admin --create-company "\$COMPANYNAME"
HERE4


/bin/chmod 554 /etc/e-smith/events/actions/zarafa-expand-templates
/bin/chmod 554 /etc/e-smith/events/actions/zarafa-services
/bin/chmod 554 /etc/e-smith/events/actions/zarafa-create-user
/bin/chmod 554 /etc/e-smith/events/actions/zarafa-create-company

#
#--- zarafa-configuration-helper-action ---
#
echo
echo "Creating zarafa-configuration-helper-action ..."
echo
cat <<HERE5 > /etc/e-smith/events/actions/helpers.inc
# -*- Mode: sh -*-
replace() {
	file=\$1
	option=\$2
	value=\$3
	
	# escape &-signs, and % for sed
	value=\`echo \$value | sed -e 's/\&/\\\\\&/g' -e 's/\%/\\\\\%/g'\`
	sed -i -e "s%\([[:space:]]*\$option[[:space:]]*=[[:space:]]*\).*%\1\$value%" \$file

}
HERE5

. /etc/e-smith/events/actions/helpers.inc

##########################################
# Creating zarafa-db-creation-templates
##########################################

#
#--- /etc/e-smith/db/configuration/migrate/80zarafa ---
#
echo
echo "Creating /etc/e-smith/db/configuration/migrate/80zarafa ..."
echo
cat <<HERE6 > /etc/e-smith/db/configuration/migrate/80zarafa
{
    use MIME::Base64 qw(encode_base64);

    my \$rec = \$DB->get('zarafa-server') || \$DB->new_record('zarafa-server', {type => 'service'});

    my \$pw = \$rec->prop('DbPassword');
    return "" if \$pw;

    \$rec->set_prop('DbPassword', sprintf("%15.0f", int( (1000000000000000) * rand() )));
}
HERE6

#
#--- /etc/e-smith/templates/etc/e-smith/sql/init/80zarafa ---
#
echo
echo "Creating /etc/e-smith/templates/etc/e-smith/sql/init/80zarafa ..."
echo
cat <<HERE7 > /etc/e-smith/templates/etc/e-smith/sql/init/80zarafa
{
    my \$db = \${'zarafa-server'}{DbName} || 'zarafa';
    my \$user = \${'zarafa-server'}{DbUser} || 'zarafa';
    my \$pass = \${'zarafa-server'}{DbPassword} || 'changeme';
    \$OUT .= <<END
#! /bin/sh
    if [ -d /var/lib/mysql/\$db ]; then
      exit
    fi
    /usr/bin/mysql <<EOF
    CREATE DATABASE \$db DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
    use \$db;
 
    use mysql;
    GRANT ALL PRIVILEGES ON \$db.* TO \$user\@localhost
            IDENTIFIED BY '\$pass';
    flush privileges;
EOF
END
}
HERE7

#
#--- /etc/e-smith/templates.metadata/etc/e-smith/sql/init/80zarafa ---
#
echo
echo "Creating /etc/e-smith/templates.metadata/etc/e-smith/sql/init/80zarafa ..."
echo
cat <<HERE8 > /etc/e-smith/templates.metadata/etc/e-smith/sql/init/80zarafa
PERMS=0750
HERE8

##########################################
# Creating SME-HTTPD-templates
##########################################

#
#--- /etc/e-smith/templates/etc/httpd/conf/httpd.conf/VirtualHosts/29ZarafaAliases ---
#
echo
echo "Creating /etc/e-smith/templates/etc/httpd/conf/httpd.conf/VirtualHosts/29ZarafaAliases ..."
echo
cat <<HERE9 > /etc/e-smith/templates/etc/httpd/conf/httpd.conf/VirtualHosts/29ZarafaAliases
{
    # vim: ft=perl:

    \$haveSSL = (exists \${modSSL}{status} and \${modSSL}{status} eq "enabled") ?  'yes' : 'no';
    my \$zwebmailStatus = \$zarafa{'status'} || "disabled";
    my \$zwebmailAccessType = \$zarafa{'access'} || "SSL";

    my \$dirs;
    \$dirs{zarafa} = '/usr/share/zarafa-webaccess';
    \$dirs{webaccess} = '/usr/share/zarafa-webaccess';
    \$dirs{webmail} = '/usr/share/zarafa-webaccess';
    if (\$imp{'status'} eq 'enabled') {\$dirs{webmail} = ''};
    \$dirs{webapp} = '/usr/share/zarafa-webapp';
   
    return "    # Zarafa is disabled in this VirtualHost\n"
                unless \$zwebmailStatus eq 'enabled';

    foreach \$place ('zarafa','webmail','webaccess','webapp')
    {
        if ((\$port eq "80") && (\$haveSSL eq 'yes') && (\$zwebmailAccessType eq 'SSL'))
        {
            \$OUT .= "    RewriteRule ^/\$place(/.*|\\$)    https://%{HTTP_HOST}/\$place\\\$1 [L,R]\n";
        } else {
            if ((\$dirs{\$place}) ne '') {\$OUT .= "    Alias	 /\$place   \$dirs{\$place}\n"};
        }
    }																		
}
HERE9

#
#--- /etc/e-smith/templates/etc/httpd/conf/httpd.conf/86ZarafaAlias ---
#
echo
echo "Creating /etc/e-smith/templates/etc/httpd/conf/httpd.conf/86ZarafaAlias ..."
echo
cat <<HERE10 > /etc/e-smith/templates/etc/httpd/conf/httpd.conf/86ZarafaAlias
{
    my \$zstatus = \$zarafa{'status'};

    if (defined \$zstatus && \$zstatus eq 'enabled')
    {
        \$OUT .= qq(
#--------------------------------------------------------------------
# Zarafa specific configuration files.
#--------------------------------------------------------------------

Alias /zarafa /usr/share/zarafa-webaccess/
 <Directory /usr/share/zarafa-webaccess/>
  Options -Indexes
  AllowOverride All
  order allow,deny
  allow from all
  AddType application/x-httpd-php .php
  php_flag magic_quotes_gpc off
  php_flag track_vars on
 </Directory>

Alias /webapp /usr/share/zarafa-webapp/
 <Directory /usr/share/zarafa-webapp/>
  Options -Indexes
  AllowOverride All
  order allow,deny
  allow from all
  AddType application/x-httpd-php .php
  php_flag magic_quotes_gpc off
  php_flag track_vars on
 </Directory>
	    
);
    }    
    else
    {
       \$OUT .= "# Zarafa Webmail is not configured as it is disabled in the config db";
    }
}
HERE10

##########################################
# Creating SME-QMAIL-user-templates
##########################################

#
#--- /etc/e-smith/templates-user/.qmail/80Zarafa ---
#
echo
echo "Creating /etc/e-smith/templates-user/.qmail/80Zarafa ..."
echo
cat <<HERE11 > /etc/e-smith/templates-user/.qmail/80Zarafa
{
   my \$zarafa = \$user->prop('zarafa') || 'disabled';
   my \$zarafa2 = \${'zarafa-server'}{GlobalForward} || 'disabled';

   if (\$zarafa eq 'enabled' || \$zarafa2 eq 'enabled')
   { return "| /usr/bin/zarafa-dagent -q \$USERNAME ; if [ \\$\\? -ne 0 ] ; then exit -1; else exit 99; fi;"
   }
}
HERE11

#
#--- /etc/e-smith/templates-user/.qmail-junkmail/01Zarafa ---
#
echo
echo "Creating /etc/e-smith/templates-user/.qmail-junkmail/01Zarafa ..."
echo
cat <<HERE12 > /etc/e-smith/templates-user/.qmail-junkmail/01Zarafa
{
    # vim: ft=perl:
    die "USERNAME not set." unless defined (\$USERNAME);

    use esmith::AccountsDB;
    \$adb = esmith::AccountsDB->open_ro or die "Couldn't open AccountsDB";

    \$user = \$adb->get(\$USERNAME) or die "No user \$USERNAME in AccountsDB";

    my \$zarafa = \$user->prop('zarafa') || 'disabled';
    my \$zarafa2 = \${'zarafa-server'}{GlobalForward} || 'disabled';
    return "| /usr/bin/zarafa-dagent -qj \$USERNAME ; if [ \\$\\? -ne 0 ] ; then exit -1; else exit 99; fi;"
           if (\$zarafa eq 'enabled' || \$zarafa2 eq 'enabled');
}
HERE12


##########################################
# Creating Zarafa-configuration-templates
##########################################

#
#--- unix config ---
#
echo
echo "Creating zarafa-unix-configuration-template ..."
echo
mkdir -p /etc/e-smith/templates/etc/zarafa/unix.cfg
cat <<HERE13 > /etc/e-smith/templates/etc/zarafa/unix.cfg/unix.cfg
{
use esmith::AccountsDB
}
##############################################################
#  UNIX USER PLUGIN SETTINGS
#
# Any of these directives that are required, are only required if the
# userplugin parameter is set to unix.

# Charset used in /etc/passwd for the fullname of a user. Normally this
# is us-ascii, but this can differ according to your setup.
# The charset specified here must be supported by your iconv(1)
# setup. See iconv -l for all charsets.
fullname_charset = iso-8859-15

# Default email domain for constructing new users
# Required, no default
default_domain = { \${'zarafa-server'}{DomainName} || \$DomainName; }

# The lowest user id that is considered a regular user
# Optional, default = 1000
min_user_uid = 101

# The highest user id that is considered a regular user
# Optional, default = 10000
max_user_uid = 10000

# A list of user ids that are not considered to be regular users
# Optional, default = empty
# except_user_uids =
except_user_uids = {
\$accounts = esmith::AccountsDB->open_ro or die "Could not open AccountsDB";
{
while ((\$name, \$passwd, \$uid, \$gid, \$quota,
    \$comment, \$gcos, \$dir, \$shell) = getpwent())
{
\$user = \$accounts->get(\$name);
    
\$OUT .= "\$uid "
    unless \$uid <= 101 or (defined \$user and \$user->prop('type') eq "user");
}
}
}

# The lowest group id that is considered a regular group
# Optional, default = 1000
min_group_gid = 5000

# The highest group id that is considered a regular group
# Optional, default = 10000
max_group_gid = 10000

# A list of group ids that are not considered to be regular groups
# Optional, default = empty
# except_group_gids =
except_group_gids = {
setpwent();
while ((\$name, \$passwd, \$uid, \$gid, \$quota,
    \$comment, \$gcos, \$dir, \$shell) = getpwent())
{
\$group = \$accounts->get(\$name);
    
\$OUT .= "\$gid "
    unless \$gid < 5000 or (defined \$group and \$group->prop('type') eq "group");
}
endpwent();
}

# Create a user as non-active when it has this unix shell
non_login_shell = /bin/false
HERE13


#
#--- sysconfig config ---
#
echo
echo "Creating zarafa-sysconfig-configuration-template ..."
echo
mkdir -p /etc/e-smith/templates/etc/sysconfig/zarafa
cat /etc/sysconfig/zarafa | sed -e 's/\r$//g' >  /etc/e-smith/templates/etc/sysconfig/zarafa/zarafa
replace /etc/e-smith/templates/etc/sysconfig/zarafa/zarafa ZARAFA_LOCALE '"{ ${'\''zarafa'\''}{language} || '\''en_US.UTF-8'\'' ; }"'
replace /etc/e-smith/templates/etc/sysconfig/zarafa/zarafa ZARAFA_USERSCRIPT_LOCALE '"{ ${'\''zarafa'\''}{language} || '\''en_US.UTF-8'\'' ; }"'


#
#--- licensed config ---
#
echo
echo "Creating zarafa-licensed-configuration-template ..."
echo
mkdir -p /etc/e-smith/templates/etc/zarafa/licensed.cfg
cat /usr/share/doc/zarafa-licensed/example-config/licensed.cfg | sed -e 's/\r$//g' >  /etc/e-smith/templates/etc/zarafa/licensed.cfg/licensed.cfg
replace /etc/e-smith/templates/etc/zarafa/licensed.cfg/licensed.cfg log_method '{ ${'\''zarafa-licensed'\''}{log_method} || '\''file'\''; }'
replace /etc/e-smith/templates/etc/zarafa/licensed.cfg/licensed.cfg log_level '{ ${'\''zarafa-licensed'\''}{log_level} || '\''2'\''; }'
replace /etc/e-smith/templates/etc/zarafa/licensed.cfg/licensed.cfg log_timestamp '{ ${'\''zarafa-licensed'\''}{log_timestamp} || '\''1'\''; }'

#
#--- server config ---
#
echo
echo "Creating zarafa-server-configuration-template ..."
echo
mkdir -p /etc/e-smith/templates/etc/zarafa/server.cfg
cat /usr/share/doc/zarafa/example-config/server.cfg | sed -e 's/\r$//g' >  /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg server_tcp_enabled '{ ${'\''zarafa-server'\''}{server_tcp_enabled} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg server_tcp_port	'{ ${'\''zarafa-server'\''}{TCPPort} || '\''236'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg server_pipe_enabled '{ ${'\''zarafa-server'\''}{server_pipe_enabled} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg server_name '{ ${'\''zarafa-server'\''}{server_name} || '\''Zarafa'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg database_engine '{ ${'\''zarafa-server'\''}{database_engine} || '\''mysql'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg allow_local_users '{ ${'\''zarafa-server'\''}{allow_local_users} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg local_admin_users '{ ${'\''zarafa-server'\''}{local_admin_users} || '\''root'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg system_email_address '{ ${'\''zarafa-server'\''}{system_email_address} || '\''postmaster@localhost'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg session_timeout '{ ${'\''zarafa-server'\''}{session_timeout} || '\''300'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg license_timeout '{ ${'\''zarafa-server'\''}{license_timeout} || '\''10'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg log_method '{ ${'\''zarafa-server'\''}{log_method} || '\''file'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg log_level '{ ${'\''zarafa-server'\''}{log_level} || '\''2'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg log_timestamp '{ ${'\''zarafa-server'\''}{log_timestamp} || '\''1'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg audit_log_enabled '{ ${'\''zarafa-server'\''}{audit_log_enabled} || '\''no'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg audit_log_level	'{ ${'\''zarafa-server'\''}{audit_log_level} || '\''1'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg audit_log_timestamp '{ ${'\''zarafa-server'\''}{audit_log_timestamp} || '\''1'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg mysql_host '{ ${'\''zarafa-server'\''}{mysql_host} || '\''localhost'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg mysql_port '{ ${'\''zarafa-server'\''}{mysql_port} || '\''3306'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg mysql_user '{ ${'\''zarafa-server'\''}{DbUser} || '\''zarafa'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg mysql_password '{ ${'\''zarafa-server'\''}{DbPassword}; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg mysql_database '{ ${'\''zarafa-server'\''}{DbName} || '\''zarafa'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg attachment_storage '{ ${'\''zarafa-server'\''}{attachment_storage} || '\''files'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg attachment_path '/home/e-smith/files/zarafa'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg attachment_compression '{ ${'\''zarafa-server'\''}{attachment_compression} || '\''6'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg server_ssl_enabled '{ ${'\''zarafa-ssl'\''}{server_ssl_enabled} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg server_ssl_port	'{ ${'\''zarafa-ssl'\''}{TCPPort} || '\''237'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg server_ssl_key_file '/home/e-smith/ssl.pem/{$SystemName}.{$DomainName}.pem'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg server_ssl_key_pass '{ ${'\''zarafa-server'\''}{DbPassword}; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg server_ssl_ca_file '/home/e-smith/ssl.crt/{$SystemName}.{$DomainName}.crt'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg server_ssl_ca_path '/home/e-smith/ssl.crt'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg sslkeys_path '/home/e-smith/ssl.pem'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg threads	'{ ${'\''zarafa-server'\''}{threads} || '\''8'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg watchdog_frequency '{ ${'\''zarafa-server'\''}{watchdog_frequency} || '\''1'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg watchdog_max_age '{ ${'\''zarafa-server'\''}{watchdog_max_age} || '\''500'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg server_max_keep_alive_requests '{ ${'\''zarafa-server'\''}{server_max_keep_alive_requests} || '\''100'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg server_recv_timeout '{ ${'\''zarafa-server'\''}{server_recv_timeout} || '\''5'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg server_read_timeout '{ ${'\''zarafa-server'\''}{server_read_timeout} || '\''60'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg server_send_timeout '{ ${'\''zarafa-server'\''}{server_send_timeout} || '\''60'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg softdelete_lifetime '{ ${'\''zarafa-server'\''}{softdelete_lifetime} || '\''30'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg sync_lifetime '{ ${'\''zarafa-server'\''}{sync_lifetime} || '\''365'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg sync_log_all_changes '{ ${'\''zarafa-server'\''}{sync_log_all_changes} || '\''no'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg enable_sso '{ ${'\''zarafa-server'\''}{enable_sso} || '\''no'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg enable_gab '{ ${'\''zarafa-server'\''}{enable_gab} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg auth_method '{ ${'\''zarafa-server'\''}{auth_method} || '\''plugin'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg pam_service '{ ${'\''zarafa-server'\''}{pam_service} || '\''passwd'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg cache_cell_size '{ ${'\''zarafa-server'\''}{cache_cell_size} || '\''268435456'\''; }' 
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg cache_object_size '{ ${'\''zarafa-server'\''}{cache_object_size} || '\''5242880'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg cache_indexedobject_size '{ ${'\''zarafa-server'\''}{cache_indexedobject_size} || '\''16777216'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg cache_quota_size '{ ${'\''zarafa-server'\''}{cache_quota_size} || '\''1048576'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg cache_quota_lifetime '{ ${'\''zarafa-server'\''}{cache_quota_lifetime} || '\''1'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg cache_acl_size '{ ${'\''zarafa-server'\''}{cache_acl_size} || '\''1048576'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg cache_store_size '{ ${'\''zarafa-server'\''}{cache_store_size} || '\''1048576'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg cache_user_size	'{ ${'\''zarafa-server'\''}{cache_user_size} || '\''1048576'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg cache_userdetails_size '{ ${'\''zarafa-server'\''}{cache_userdetails_size} || '\''26214400'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg cache_userdetails_lifetime '{ ${'\''zarafa-server'\''}{cache_userdetails_lifetime} || '\''5'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg cache_server_size '{ ${'\''zarafa-server'\''}{cache_server_size} || '\''1048576'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg cache_server_lifetime '{ ${'\''zarafa-server'\''}{cache_server_lifetime} || '\''30'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg quota_warn '{ ${'\''zarafa-server'\''}{quota_warn} || '\''0'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg quota_soft '{ ${'\''zarafa-server'\''}{quota_soft} || '\''0'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg quota_hard '{ ${'\''zarafa-server'\''}{quota_hard} || '\''0'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg companyquota_warn '{ ${'\''zarafa-server'\''}{companyquota_warn} || '\''0'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg user_plugin '{ ${'\''zarafa-server'\''}{user_plugin} || '\''db'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg user_plugin_config '{ ${'\''zarafa-server'\''}{user_plugin_config}; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg user_safe_mode '{ ${'\''zarafa-server'\''}{user_safe_mode} || '\''no'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg thread_stacksize '{ ${'\''zarafa-server'\''}{thread_stacksize} || '\''512'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg enable_hosted_zarafa '{ ${'\''zarafa-server'\''}{enable_hosted_zarafa} || '\''false'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg enable_distributed_zarafa '{ ${'\''zarafa-server'\''}{enable_distributed_zarafa} || '\''false'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg storename_format '{ ${'\''zarafa-server'\''}{storename_format} || '\''%f'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg loginname_format '{ ${'\''zarafa-server'\''}{loginname_format} || '\''%u'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg client_update_enabled '{ ${'\''zarafa-server'\''}{client_update_enabled} || '\''false'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg client_update_path '{ ${'\''zarafa-server'\''}{client_update_path} || '\''/var/lib/zarafa/client'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg client_update_log_level '{ ${'\''zarafa-server'\''}{client_update_log_level} || '\''1'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg hide_everyone '{ ${'\''zarafa-server'\''}{hide_everyone} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg hide_system '{ ${'\''zarafa-server'\''}{hide_system} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg index_services_enabled '{ ${'\''zarafa-server'\''}{index_services_enabled} || '\''no'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg index_services_search_timeout '{ ${'\''zarafa-server'\''}{index_services_search_timeout} || '\''10'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg index_services_prefix_chars '{ ${'\''zarafa-server'\''}{index_services_prefix_chars} || '\''3'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg enable_enhanced_ics '{ ${'\''zarafa-server'\''}{enable_enhanced_ics} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg sync_gab_realtime '{ ${'\''zarafa-server'\''}{sync_gab_realtime} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg disabled_features '{ ${'\''zarafa-server'\''}{disabled_features}; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg max_deferred_records '{ ${'\''zarafa-server'\''}{max_deferred_records} || '\''0'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg max_deferred_records_folder '{ ${'\''zarafa-server'\''}{max_deferred_records_folder} || '\''20'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg coredump_enabled '{ ${'\''zarafa-server'\''}{coredump_enabled} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/server.cfg/server.cfg server_ssl_enable_v2 '{ ${'\''zarafa-server'\''}{server_ssl_enable_v2} || '\''no'\''; }'


#
#--- dagent config ---
#
echo
echo "Creating zarafa-dagent-configuration-template ..."
echo
mkdir -p /etc/e-smith/templates/etc/zarafa/dagent.cfg
cat /usr/share/doc/zarafa-dagent/example-config/dagent.cfg | sed -e 's/\r$//g' >  /etc/e-smith/templates/etc/zarafa/dagent.cfg/dagent.cfg
replace /etc/e-smith/templates/etc/zarafa/dagent.cfg/dagent.cfg log_method '{ ${'\''zarafa-dagent'\''}{log_method} || '\''file'\''; }'
replace /etc/e-smith/templates/etc/zarafa/dagent.cfg/dagent.cfg log_level '{ ${'\''zarafa-dagent'\''}{log_level} || '\''2'\''; }'
replace /etc/e-smith/templates/etc/zarafa/dagent.cfg/dagent.cfg log_timestamp '{ ${'\''zarafa-dagent'\''}{log_timestamp} || '\''1'\''; }'
replace /etc/e-smith/templates/etc/zarafa/dagent.cfg/dagent.cfg log_raw_message '{ ${'\''zarafa-dagent'\''}{log_raw_message} || '\''no'\''; }'
replace /etc/e-smith/templates/etc/zarafa/dagent.cfg/dagent.cfg lmtp_port '{ ${'\''zarafa-dagent'\''}{lmtp_port} || '\''2003'\''; }'
replace /etc/e-smith/templates/etc/zarafa/dagent.cfg/dagent.cfg lmtp_max_threads '{ ${'\''zarafa-dagent'\''}{lmtp_max_threads} || '\''20'\''; }'
replace /etc/e-smith/templates/etc/zarafa/dagent.cfg/dagent.cfg process_model '{ ${'\''zarafa-dagent'\''}{process_model} || '\''fork'\''; }'
replace /etc/e-smith/templates/etc/zarafa/dagent.cfg/dagent.cfg spam_header_name '{ ${'\''zarafa-dagent'\''}{spam_header_name} || '\''X-Spam-Status'\''; }'
replace /etc/e-smith/templates/etc/zarafa/dagent.cfg/dagent.cfg spam_header_value '{ ${'\''zarafa-dagent'\''}{spam_header_value} || '\''Yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/dagent.cfg/dagent.cfg archive_on_delivery '{ ${'\''zarafa-dagent'\''}{archive_on_delivery} || '\''no'\''; }'
replace /etc/e-smith/templates/etc/zarafa/dagent.cfg/dagent.cfg set_rule_headers '{ ${'\''zarafa-dagent'\''}{set_rule_headers} || '\''yes'\''; }'


#
#--- spooler config ---
#
echo
echo "Creating zarafa-spooler-configuration-template ..."
echo
mkdir -p /etc/e-smith/templates/etc/zarafa/spooler.cfg
cat /usr/share/doc/zarafa-spooler/example-config/spooler.cfg | sed -e 's/\r$//g' >  /etc/e-smith/templates/etc/zarafa/spooler.cfg/spooler.cfg
replace /etc/e-smith/templates/etc/zarafa/spooler.cfg/spooler.cfg smtp_port '{ ${'\''zarafa-spooler'\''}{smtp_port} || '\''25'\''; }'
replace /etc/e-smith/templates/etc/zarafa/spooler.cfg/spooler.cfg log_method '{ ${'\''zarafa-spooler'\''}{log_method} || '\''file'\''; }'
replace /etc/e-smith/templates/etc/zarafa/spooler.cfg/spooler.cfg log_level '{ ${'\''zarafa-spooler'\''}{log_level} || '\''3'\''; }'
replace /etc/e-smith/templates/etc/zarafa/spooler.cfg/spooler.cfg log_timestamp '{ ${'\''zarafa-spooler'\''}{log_timestamp} || '\''1'\''; }'
replace /etc/e-smith/templates/etc/zarafa/spooler.cfg/spooler.cfg max_threads '{ ${'\''zarafa-spooler'\''}{max_threads} || '\''5'\''; }'
replace /etc/e-smith/templates/etc/zarafa/spooler.cfg/spooler.cfg fax_domain '{ ${'\''zarafa-spooler'\''}{fax_domain} || '\''fax.local'\''; }'
replace /etc/e-smith/templates/etc/zarafa/spooler.cfg/spooler.cfg fax_international '{ ${'\''zarafa-spooler'\''}{fax_international} || '\''00'\''; }'
replace /etc/e-smith/templates/etc/zarafa/spooler.cfg/spooler.cfg always_send_delegates '{ ${'\''zarafa-spooler'\''}{always_send_delegates} || '\''no'\''; }'
replace /etc/e-smith/templates/etc/zarafa/spooler.cfg/spooler.cfg allow_redirect_spoofing '{ ${'\''zarafa-spooler'\''}{allow_redirect_spoofing} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/spooler.cfg/spooler.cfg copy_delegate_mails '{ ${'\''zarafa-spooler'\''}{copy_delegate_mails} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/spooler.cfg/spooler.cfg allow_delegate_meeting_request '{ ${'\''zarafa-spooler'\''}{allow_delegate_meeting_request} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/spooler.cfg/spooler.cfg allow_send_to_everyone '{ ${'\''zarafa-spooler'\''}{allow_send_to_everyone} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/spooler.cfg/spooler.cfg always_send_tnef '{ ${'\''zarafa-spooler'\''}{always_send_tnef} || '\''no'\''; }'
replace /etc/e-smith/templates/etc/zarafa/spooler.cfg/spooler.cfg always_send_utf8 '{ ${'\''zarafa-spooler'\''}{always_send_utf8} || '\''no'\''; }'
replace /etc/e-smith/templates/etc/zarafa/spooler.cfg/spooler.cfg charset_upgrade '{ ${'\''zarafa-spooler'\''}{charset_upgrade} || '\''windows-1252'\''; }'
replace /etc/e-smith/templates/etc/zarafa/spooler.cfg/spooler.cfg expand_groups '{ ${'\''zarafa-spooler'\''}{expand_groups} || '\''no'\''; }'
replace /etc/e-smith/templates/etc/zarafa/spooler.cfg/spooler.cfg archive_on_send '{ ${'\''zarafa-spooler'\''}{archive_on_send} || '\''no'\''; }'


#
#--- monitor config ---
#
echo
echo "Creating zarafa-monitor-configuration-template ..."
echo "The monitor program sends quota warning mails to users who are over quota."
echo
mkdir -p /etc/e-smith/templates/etc/zarafa/monitor.cfg
cat /usr/share/doc/zarafa-monitor/example-config/monitor.cfg | sed -e 's/\r$//g' >  /etc/e-smith/templates/etc/zarafa/monitor.cfg/monitor.cfg
replace /etc/e-smith/templates/etc/zarafa/monitor.cfg/monitor.cfg log_method '{ ${'\''zarafa-monitor'\''}{log_method} || '\''file'\''; }'
replace /etc/e-smith/templates/etc/zarafa/monitor.cfg/monitor.cfg log_level '{ ${'\''zarafa-monitor'\''}{log_level} || '\''2'\''; }'
replace /etc/e-smith/templates/etc/zarafa/monitor.cfg/monitor.cfg log_timestamp '{ ${'\''zarafa-monitor'\''}{log_timestamp} || '\''1'\''; }'
replace /etc/e-smith/templates/etc/zarafa/monitor.cfg/monitor.cfg quota_check_interval '{ ${'\''zarafa-monitor'\''}{quota_check_interval} || '\''15'\''; }'
replace /etc/e-smith/templates/etc/zarafa/monitor.cfg/monitor.cfg mailquota_resend_interval '{ ${'\''zarafa-monitor'\''}{mailquota_resend_interval} || '\''1'\''; }'


#
#--- gateway config ---
#
echo
echo "Creating zarafa-gateway-configuration-template ..."
echo
mkdir -p /etc/e-smith/templates/etc/zarafa/gateway.cfg
cat /usr/share/doc/zarafa-gateway/example-config/gateway.cfg | sed -e 's/\r$//g' >  /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg server_socket 'http://localhost:{${'\''zarafa-server'\''}{TCPPort}||'\''236'\'';}/zarafa'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg pop3_enable '{ if (${'\''zarafa-pop3'\''}{status} eq '\''enabled'\'') {'\''yes'\''} else {'\''no'\''}; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg pop3_port '{ ${'\''zarafa-pop3'\''}{TCPPort} || '\''8110'\''; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg pop3s_enable '{ if (${'\''zarafa-pop3s'\''}{status} eq '\''enabled'\'') {'\''yes'\''} else {'\''no'\''}; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg pop3s_port '{ ${'\''zarafa-pop3s'\''}{TCPPort} || '\''8995'\''; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg imap_enable '{ if (${'\''zarafa-imap'\''}{status} eq '\''enabled'\'') {'\''yes'\''} else {'\''no'\''}; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg imap_port '{ ${'\''zarafa-imap'\''}{TCPPort} || '\''8143'\''; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg imaps_enable '{ if (${'\''zarafa-imaps'\''}{status} eq '\''enabled'\'') {'\''yes'\''} else {'\''no'\''}; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg imaps_port '{ ${'\''zarafa-imaps'\''}{TCPPort} || '\''8993'\''; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg imap_only_mailfolders '{ ${'\''zarafa-imap'\''}{imap_only_mailfolders} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg imap_public_folders '{ ${'\''zarafa-imap'\''}{imap_public_folders} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg imap_capability_idle '{ ${'\''zarafa-imap'\''}{imap_capability_idle} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg imap_max_messagesize '{ ${'\''zarafa-imap'\''}{imap_max_messagesize} || '\''134217728'\''; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg imap_generate_utf8 '{ ${'\''zarafa-imap'\''}{imap_generate_utf8} || '\''no'\''; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg imap_expunge_on_delete '{ ${'\''zarafa-imap'\''}{imap_expunge_on_delete} || '\''no'\''; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg imap_store_rfc822 '{ ${'\''zarafa-imap'\''}{imap_store_rfc822} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg ssl_private_key_file '/home/e-smith/ssl.key/{$SystemName}.{$DomainName}.key'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg ssl_certificate_file '/home/e-smith/ssl.crt/{$SystemName}.{$DomainName}.crt'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg ssl_verify_client '{ ${'\''zarafa-gateway'\''}{ssl_verify_client} || '\''no'\''; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg process_model '{ ${'\''zarafa-gateway'\''}{process_model} || '\''fork'\''; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg log_method '{ ${'\''zarafa-gateway'\''}{log_method} || '\''file'\''; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg log_level '{ ${'\''zarafa-gateway'\''}{log_level} || '\''2'\''; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg log_timestamp '{ ${'\''zarafa-gateway'\''}{log_timestamp} || '\''1'\''; }'
replace /etc/e-smith/templates/etc/zarafa/gateway.cfg/gateway.cfg ssl_enable_v2 '{ ${'\''zarafa-gateway'\''}{ssl_enable_v2} || '\''no'\''; }'


#
#--- ical config ---
#
echo
echo "Creating zarafa-ical-configuration-template ..."
echo
mkdir -p /etc/e-smith/templates/etc/zarafa/ical.cfg
cat /usr/share/doc/zarafa-ical/example-config/ical.cfg | sed -e 's/\r$//g' >  /etc/e-smith/templates/etc/zarafa/ical.cfg/ical.cfg
replace /etc/e-smith/templates/etc/zarafa/ical.cfg/ical.cfg ical_enable '{ if (${'\''zarafa-ical'\''}{status} eq '\''enabled'\'') {'\''yes'\''} else {'\''no'\''}; }'
replace /etc/e-smith/templates/etc/zarafa/ical.cfg/ical.cfg ical_port '{ ${'\''zarafa-ical'\''}{TCPPort} || '\''8088'\''; }'
replace /etc/e-smith/templates/etc/zarafa/ical.cfg/ical.cfg icals_enable '{ if (${'\''zarafa-icals'\''}{status} eq '\''enabled'\'') {'\''yes'\''} else {'\''no'\''}; }'
replace /etc/e-smith/templates/etc/zarafa/ical.cfg/ical.cfg icals_port '{ ${'\''zarafa-icals'\''}{TCPPort} || '\''8089'\''; }'
replace /etc/e-smith/templates/etc/zarafa/ical.cfg/ical.cfg server_socket 'http://localhost:{${'\''zarafa-server'\''}{TCPPort}||'\''236'\'';}/zarafa'
replace /etc/e-smith/templates/etc/zarafa/ical.cfg/ical.cfg process_model '{ ${'\''zarafa-ical'\''}{process_model} || '\''fork'\''; }'
replace /etc/e-smith/templates/etc/zarafa/ical.cfg/ical.cfg log_method '{ ${'\''zarafa-ical'\''}{log_method} || '\''file'\''; }'
replace /etc/e-smith/templates/etc/zarafa/ical.cfg/ical.cfg log_level '{ ${'\''zarafa-ical'\''}{log_level} || '\''2'\''; }'
replace /etc/e-smith/templates/etc/zarafa/ical.cfg/ical.cfg log_timestamp '{ ${'\''zarafa-ical'\''}{log_timestamp} || '\''1'\''; }'
replace /etc/e-smith/templates/etc/zarafa/ical.cfg/ical.cfg ssl_private_key_file '/home/e-smith/ssl.key/{$SystemName}.{$DomainName}.key'
replace /etc/e-smith/templates/etc/zarafa/ical.cfg/ical.cfg ssl_certificate_file '/home/e-smith/ssl.crt/{$SystemName}.{$DomainName}.crt'
replace /etc/e-smith/templates/etc/zarafa/ical.cfg/ical.cfg ssl_verify_client '{ ${'\''zarafa-ical'\''}{ssl_verify_client} || '\''no'\''; }'
replace /etc/e-smith/templates/etc/zarafa/ical.cfg/ical.cfg server_timezone '{$TimeZone}'
replace /etc/e-smith/templates/etc/zarafa/ical.cfg/ical.cfg default_charset '{ ${'\''zarafa-ical'\''}{default_charset} || '\''utf-8'\''; }'
replace /etc/e-smith/templates/etc/zarafa/ical.cfg/ical.cfg enable_ical_get '{ ${'\''zarafa-ical'\''}{enable_ical_get} || '\''yes'\''; }'
replace /etc/e-smith/templates/etc/zarafa/ical.cfg/ical.cfg ssl_enable_v2 '{ ${'\''zarafa-ical'\''}{ssl_enable_v2} || '\''no'\''; }'


#
#--- indexer config ---
#
echo
echo "Creating zarafa-indexer-configuration-template ..."
echo
mkdir -p /etc/e-smith/templates/etc/zarafa/indexer.cfg
cat /usr/share/doc/zarafa-indexer/example-config/indexer.cfg | sed -e 's/\r$//g' >  /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg
replace /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg cleanup_lockfiles '{ ${'\''zarafa-indexer'\''}{cleanup_lockfiles} || '\''no'\''; }'
replace /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg limit_results	'{ ${'\''zarafa-indexer'\''}{limit_results} || '\''0'\''; }'
replace /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg log_method '{ ${'\''zarafa-indexer'\''}{log_method} || '\''file'\''; }'
replace /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg log_level '{ ${'\''zarafa-indexer'\''}{log_level} || '\''2'\''; }'
replace /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg log_timestamp '{ ${'\''zarafa-indexer'\''}{log_timestamp} || '\''1'\''; }'
replace /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg index_interval '{ ${'\''zarafa-indexer'\''}{index_interval} || '\''5'\''; }'
replace /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg index_threads '{ ${'\''zarafa-indexer'\''}{index_threads} || '\''1'\''; }'
replace /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg index_max_field_length '{ ${'\''zarafa-indexer'\''}{index_max_field_length} || '\''10000'\''; }'
replace /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg index_merge_factor '{ ${'\''zarafa-indexer'\''}{index_merge_factor} || '\''10'\''; }'
replace /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg index_max_buffered_docs '{ ${'\''zarafa-indexer'\''}{index_max_buffered_docs} || '\''10'\''; }'
replace /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg index_min_merge_docs '{ ${'\''zarafa-indexer'\''}{index_min_merge_docs} || '\''10'\''; }'
replace /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg index_max_merge_docs '{ ${'\''zarafa-indexer'\''}{index_max_merge_docs} || '\''2147483647'\''; }'
replace /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg index_term_interval '{ ${'\''zarafa-indexer'\''}{index_term_interval} || '\''128'\''; }'
replace /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg index_cache_timeout '{ ${'\''zarafa-indexer'\''}{index_cache_timeout} || '\''0'\''; }'
replace /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg index_attachments '{ ${'\''zarafa-indexer'\''}{index_attachments} || '\''no'\''; }'
replace /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg index_attachment_max_size '{ ${'\''zarafa-indexer'\''}{index_attachment_max_size} || '\''5120'\''; }'
replace /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg index_attachment_parser_max_memory '{ ${'\''zarafa-indexer'\''}{index_attachment_parser_max_memory} || '\''0'\''; }'
replace /etc/e-smith/templates/etc/zarafa/indexer.cfg/indexer.cfg index_attachment_parser_max_cputime '{ ${'\''zarafa-indexer'\''}{index_attachment_parser_max_cputime} || '\''0'\''; }'


######################################
# Configuring SME-events : Templates to expand
######################################

/bin/echo 
/bin/echo "Configuring SME-events : Templates2expand"
/bin/echo 
mkdir -p /etc/e-smith/events/email-update/templates2expand/etc/zarafa
touch /etc/e-smith/events/email-update/templates2expand/etc/zarafa/gateway.cfg
touch /etc/e-smith/events/email-update/templates2expand/etc/zarafa/ical.cfg
touch /etc/e-smith/events/email-update/templates2expand/etc/zarafa/server.cfg
touch /etc/e-smith/events/email-update/templates2expand/etc/zarafa/unix.cfg
touch /etc/e-smith/events/email-update/templates2expand/etc/zarafa/spooler.cfg
touch /etc/e-smith/events/email-update/templates2expand/etc/zarafa/licensed.cfg
touch /etc/e-smith/events/email-update/templates2expand/etc/zarafa/monitor.cfg
touch /etc/e-smith/events/email-update/templates2expand/etc/zarafa/dagent.cfg

mkdir -p /etc/e-smith/events/group-create/templates2expand/etc/zarafa
touch /etc/e-smith/events/group-create/templates2expand/etc/zarafa/unix.cfg

mkdir -p /etc/e-smith/events/group-delete/templates2expand/etc/zarafa
touch /etc/e-smith/events/group-delete/templates2expand/etc/zarafa/unix.cfg

mkdir -p /etc/e-smith/events/group-modify/templates2expand/etc/zarafa
touch /etc/e-smith/events/group-modify/templates2expand/etc/zarafa/unix.cfg

mkdir -p /etc/e-smith/events/user-create/templates2expand/etc/zarafa
touch /etc/e-smith/events/user-create/templates2expand/etc/zarafa/unix.cfg

mkdir -p /etc/e-smith/events/user-delete/templates2expand/etc/zarafa
touch /etc/e-smith/events/user-delete/templates2expand/etc/zarafa/unix.cfg

mkdir -p /etc/e-smith/events/user-modify/templates2expand/etc/zarafa
touch /etc/e-smith/events/user-modify/templates2expand/etc/zarafa/unix.cfg

mkdir -p /etc/e-smith/events/ibay-create/templates2expand/etc/zarafa
touch /etc/e-smith/events/ibay-create/templates2expand/etc/zarafa/unix.cfg

mkdir -p /etc/e-smith/events/machine-account-create/templates2expand/etc/zarafa
touch /etc/e-smith/events/machine-account-create/templates2expand/etc/zarafa/unix.cfg

mkdir -p /etc/e-smith/events/post-upgrade/templates2expand/etc/zarafa
touch /etc/e-smith/events/post-upgrade/templates2expand/etc/e-smith/sql/init/80zarafa
touch /etc/e-smith/events/post-upgrade/templates2expand/etc/zarafa/gateway.cfg
touch /etc/e-smith/events/post-upgrade/templates2expand/etc/zarafa/ical.cfg
touch /etc/e-smith/events/post-upgrade/templates2expand/etc/zarafa/server.cfg
touch /etc/e-smith/events/post-upgrade/templates2expand/etc/zarafa/unix.cfg
touch /etc/e-smith/events/post-upgrade/templates2expand/etc/zarafa/spooler.cfg
touch /etc/e-smith/events/post-upgrade/templates2expand/etc/zarafa/licensed.cfg
touch /etc/e-smith/events/post-upgrade/templates2expand/etc/zarafa/monitor.cfg
touch /etc/e-smith/events/post-upgrade/templates2expand/etc/zarafa/dagent.cfg


######################################
# Configuring SME-events : Services to adjust
######################################

/bin/echo 
/bin/echo "Configuring SME-events : Services2adjust"
/bin/echo
 
mkdir -p /etc/e-smith/events/machine-account-create/services2adjust
ln -s reload /etc/e-smith/events/group-create/services2adjust/zarafa-server
ln -s reload /etc/e-smith/events/group-delete/services2adjust/zarafa-server
ln -s reload /etc/e-smith/events/group-modify/services2adjust/zarafa-server
ln -s reload /etc/e-smith/events/user-create/services2adjust/zarafa-server
ln -s reload /etc/e-smith/events/user-delete/services2adjust/zarafa-server
ln -s reload /etc/e-smith/events/user-modify/services2adjust/zarafa-server
ln -s reload /etc/e-smith/events/ibay-create/services2adjust/zarafa-server
ln -s reload /etc/e-smith/events/machine-account-create/services2adjust/zarafa-server
ln -s reload /etc/e-smith/events/timezone-update/services2adjust/zarafa-server


######################################
# Setting up SME-db-entries
######################################

/bin/echo 
/bin/echo "Enter the language of your choice for your zarafa-mailboxes and public store(s)."
/bin/echo "Values: en_US.UTF-8, en_GB.UTF-8, nl_NL.UTF-8, fr_FR.UTF-8, de_DE.UTF-8, ..."
/bin/echo 
read ZARAFALANGUAGE
/sbin/e-smith/config set zarafa service status enabled language $ZARAFALANGUAGE
/sbin/e-smith/expand-template /etc/sysconfig/zarafa

/bin/echo 
/bin/echo "Initialize-default-databases"
/bin/echo 
/etc/e-smith/events/actions/initialize-default-databases

/bin/echo 
/bin/echo "Setting up db-entries for Zarafa"
/bin/echo 
/sbin/e-smith/db configuration setprop mysqld InnoDB enabled
/sbin/e-smith/db configuration setprop smtpd tnef2mime disabled
/sbin/e-smith/db configuration setprop zarafa-server access private status enabled TCPPort 236 index_services_enabled yes
/bin/echo 
/bin/echo "Enter your user plugin."
/bin/echo "Values: unix or db (ldap is not supported, multicompany-support only with db-plugin)."
/bin/echo 
read USERPLUGIN
/sbin/e-smith/db configuration setprop zarafa-server user_plugin $USERPLUGIN

if [ "$USERPLUGIN" == unix ]; then
/sbin/e-smith/db configuration setprop zarafa-server user_plugin_config /etc/zarafa/unix.cfg
fi

if [ "$USERPLUGIN" == db ]; then
/bin/echo
/bin/echo "Do you want to set up a multicompany-environment ?"
/bin/echo "Values: yes or no."
/bin/echo
read MULTICOMPANY
/sbin/e-smith/db configuration setprop zarafa-server Multicompany $MULTICOMPANY
/sbin/e-smith/db configuration delprop zarafa-server user_plugin_config
if [ "$MULTICOMPANY" == yes ]; then
/sbin/e-smith/db configuration setprop zarafa-server enable_hosted_zarafa true
/sbin/e-smith/db configuration setprop zarafa-server loginname_format %u.%c
else
/sbin/e-smith/db configuration setprop zarafa-server enable_hosted_zarafa false
/sbin/e-smith/db configuration setprop zarafa-server loginname_format %u
fi
fi

/sbin/e-smith/db configuration setprop zarafa access SSL
/sbin/e-smith/db configuration set zarafa-ical service access private status enabled TCPPort 8088
/sbin/e-smith/db configuration set zarafa-icals service access public status enabled TCPPort 8089
/sbin/e-smith/db configuration set zarafa-imap service access private status enabled TCPPort 8143
/sbin/e-smith/db configuration set zarafa-imaps service access public status enabled TCPPort 8993
/sbin/e-smith/db configuration set zarafa-pop3 service access private status enabled TCPPort 8110
/sbin/e-smith/db configuration set zarafa-pop3s service access public status enabled TCPPort 8995
/sbin/e-smith/db configuration set zarafa-ssl service access public status enabled TCPPort 237
/sbin/e-smith/db configuration set zarafa-gateway service status enabled
/sbin/e-smith/db configuration set zarafa-spooler service status enabled
/sbin/e-smith/db configuration set zarafa-monitor service status enabled
/sbin/e-smith/db configuration set zarafa-indexer service status enabled
/sbin/e-smith/db configuration set zarafa-licensed service status enabled
/sbin/e-smith/db configuration set zarafa-dagent service status enabled


######################################
# Setting up the Zarafa-db
######################################

/bin/echo
/bin/echo "Expanding the my.cnf-template"
/bin/echo
/sbin/e-smith/expand-template /etc/my.cnf

/bin/echo
/bin/echo "Restarting mysqld"
/bin/echo
/usr/bin/sv t /service/mysqld

/bin/echo
/bin/echo "Signal-event remoteaccess-update"
/bin/echo
/sbin/e-smith/signal-event remoteaccess-update

/bin/echo
/bin/echo "Creating the Zarafa-database"
/bin/echo
/sbin/e-smith/expand-template /etc/e-smith/sql/init/80zarafa
/etc/rc.d/init.d/mysql.init start


######################################
# Expanding the Zarafa-configuration-templates
######################################

/bin/echo
/bin/echo "Expanding the Zarafa-configuration-templates"
/bin/echo
/etc/e-smith/events/actions/zarafa-expand-templates


######################################
# Configuration of the Webaccess
######################################

/bin/echo
/bin/echo "Configuration of the Webaccess"
/bin/echo
/bin/chown -R www:www /var/lib/zarafa-webaccess/tmp
/bin/chown -R www:www /var/lib/zarafa-webapp/tmp
FILE=/etc/httpd/conf.d/zarafa-webaccess.conf; if [ -a $FILE ]; then /bin/rm -f $FILE; fi
FILE=/etc/httpd/conf.d/zarafa-webapp.conf; if [ -a $FILE ]; then /bin/rm -f $FILE; fi

/bin/echo
/bin/echo "Expanding http.conf-template"
/bin/echo
/sbin/e-smith/expand-template /etc/httpd/conf/httpd.conf

/bin/echo
/bin/echo "Restarting httpd"
/bin/echo
/usr/bin/sv restart /service/httpd-e-smith


######################################
# Setting up more symbolic links
######################################

/bin/echo
/bin/echo "Setting up more symbolic links"
/bin/echo
if [ `getconf LONG_BIT` = "64" ]; then
	ln -s /usr/lib64/zarafa /usr/lib/zarafa
	ln -s /lib64/libcrypto.so.0.9.8e /usr/lib/libcrypto.so.0.9.8
	ln -s /lib64/libssl.so.0.9.8e /usr/lib/libssl.so.0.9.8	
else
	ln -s /lib/libcrypto.so.0.9.8e /usr/lib/libcrypto.so.0.9.8
	ln -s /lib/libssl.so.0.9.8e /usr/lib/libssl.so.0.9.8
fi
ln -s /etc/rc.d/init.d/e-smith-service /etc/rc.d/rc7.d/S99zarafa-dagent
ln -s /etc/rc.d/init.d/e-smith-service /etc/rc.d/rc7.d/S99zarafa-gateway
ln -s /etc/rc.d/init.d/e-smith-service /etc/rc.d/rc7.d/S99zarafa-indexer
ln -s /etc/rc.d/init.d/e-smith-service /etc/rc.d/rc7.d/S99zarafa-licensed
ln -s /etc/rc.d/init.d/e-smith-service /etc/rc.d/rc7.d/S99zarafa-monitor
ln -s /etc/rc.d/init.d/e-smith-service /etc/rc.d/rc7.d/S99zarafa-spooler
ln -s /etc/rc.d/init.d/e-smith-service /etc/rc.d/rc7.d/S99zarafa-ical
ln -s /etc/rc.d/init.d/e-smith-service /etc/rc.d/rc7.d/S99zarafa-server


#######################################
# Installing a license-key
#######################################

/bin/echo 
/bin/echo "Installing a license-key"
/bin/echo 
if [ -x /usr/bin/zarafa-licensed ]; then
	if [ ! -f /etc/zarafa/license/base ]; then
		mkdir -p /etc/zarafa/license
		SERIAL="0"
		while [ ${#SERIAL} -ne 25 -a ${#SERIAL} -ne 0 ]; do
			if [ -n "$SERIAL" ]; then
				echo "Serial number must be 25 characters or empty"
			fi
			echo -ne "Server serial number (leave empty for none) []\t\t: "
			read SERIAL
		done
		SERIAL=`echo $SERIAL | tr [a-z] [A-Z]`
		echo $SERIAL > /etc/zarafa/license/base
		echo
		echo "The correctness of the serial will be checked when the Zarafa-server starts."
		echo
	fi
fi


#######################################
# Starting Zarafa
#######################################

/bin/echo 
/bin/echo "Starting Zarafa-services"
/bin/echo 
/etc/e-smith/events/actions/zarafa-services start

/bin/echo
/bin/echo "Setting permissions on files"
/bin/echo
FILE=/var/log/zarafa/dagent.log; if [ -a $FILE ]; then /bin/chmod 666 $FILE; fi
#/bin/chmod 554 /etc/e-smith/events/actions/zarafa-update


#######################################
# Creating public store(s)
#######################################

if [ "$USERPLUGIN" == unix ]; then
/bin/echo
/bin/echo "creating Public store"
/bin/echo
/usr/bin/zarafa-admin --utf8 -s
fi

if [ "$USERPLUGIN" == db ]; then
if [ "$MULTICOMPANY" == no ]; then
/bin/echo
/bin/echo "creating Public store"
/bin/echo
/usr/bin/zarafa-admin --utf8 -s
fi
fi

if [ "$USERPLUGIN" == db ]; then
if [ "$MULTICOMPANY" == yes ]; then
 /bin/echo
 /bin/echo "Make your first company. Enter your first companyname :"
 /bin/echo
 read COMPANYNAME
 /usr/bin/zarafa-admin --create-company "$COMPANYNAME"
 /bin/echo
 /bin/echo "!!! REMEMBER !!! : for a multicompany-environment the username-format of the SME-user and the ZARAFA-user,"
 /bin/echo "has to be : [username].[companyname] !!!"
 /bin/echo
 /bin/echo "You must perform a signal-event post-upgrade;signal-event reboot"

fi
fi
}

clear
# Start of the actual script
# Setting up epel and epel-testing repo's
/sbin/e-smith/db yum_repositories set epel repository \
Name 'Epel - EL5' \
BaseUrl 'http://download.fedoraproject.org/pub/epel/5/$basearch' \
MirrorList 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch' \
EnableGroups no \
GPGCheck yes \
GPGKey http://download.fedora.redhat.com/pub/epel/RPM-GPG-KEY-EPEL \
Visible no \
status disabled

/sbin/e-smith/db yum_repositories set epel-testing repository \
Name 'Epel-testing - EL5' \
BaseUrl 'http://download.fedoraproject.org/pub/epel/testing/5/$basearch' \
MirrorList 'http://mirrors.fedoraproject.org/mirrorlist?repo=testing-epel5&arch=$basearch' \
EnableGroups no \
GPGCheck yes \
GPGKey http://download.fedora.redhat.com/pub/epel/RPM-GPG-KEY-EPEL \
Visible no \
status disabled

signal-event yum-modify

VERSION=7.0.15-4279
if [ `$(cat /etc/redhat-release|grep -o 8)` = "8"); then
   RHV=5
else
   RHV=6
fi
if [ `getconf LONG_BIT` = "64" ]; then
   CPUARCH=x86_64
else
   CPUARCH=i386
fi
mkdir -p /root/install/zarafa
cd /root/install/zarafa
wget http://download.zarafa.com/community/final/7.0/$VERSION/zcp-$VERSION-rhel-$RHV-$CPUARCH-free.tar.gz
tar -zxvf zcp-*
cd zcp-$VERSION-rhel-$RHV-$CPUARCH
rm -f *-dev*.rpm
yum -y localinstall *.rpm
rpm -e php-mapi --nodeps
yum -y install php53-mapi --enablerepo=epel,epel-testing
zarafainstall
config setprop zarafa-server GlobalForward enabled
/etc/e-smith/events/actions/qmail-update-user
echo
echo "All done. You must perform a: signal-event post-upgrade; signal-event reboot"
exit 0