Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 20 Next »

 

Disclaimer

Use the script at your own risk and only if you know what the script is doing .

This script is only intended for a "standard" setup, which means a server where all the ZCP components are installed on the same machine and the ldap- or db-plugin is used.

Requirements

The migration script needs the following dependencies

The following distributions are supported :

  • Debian 7 (amd64)
  • Debian 8 (amd64)
  • Ubuntu 14.04 (amd64)
  • RHEL/CentOS 6 (x86_64) 
  • RHEL/CentOS 7 (x86_64) 

Kopano

The latest final version of Kopano will always be installed from https://download.kopano.io/supported/core:/final/ 
Repositories will be added to your system in order to install Kopano Core and WebApp

Parameters

The following parameter are available. 

Options:
  -b, --backup          Location to backup.
  -c, --scl             Use software collections in RHEL
  -h, --help            Show this help message and exit
  -r, --run-script      Run the scipt

 

The script

The script will perform the following tasks;

  1. backup /etc/zarafa
  2. stop zarafa services
  3. remove Zarafa
  4. add Kopano Core and Webapp repositories
  5. install Kopano
  6. migrate configuration files
  7. chown /var/lib/zarafa to kopano
  8. start kopano services

 

zcp2kc.sh  Expand source
 master  KSC/migrate
#!/usr/bin/env bash
set -e
#default options
OS=$(cat /etc/*-release | grep PRETTY_NAME= | sed 's/^.*=//' | awk '{ print $1 }' |  sed 's/\"//g')
VERSION=$(cat /etc/*-release | grep VERSION_ID=  | sed 's/^.*=//'  |sed 's/\"//g')
locpath='leave'
backup=$(pwd)
dryrun=true
DEBUG=false
ldap=true

if [[ -z "$OS" ]] ; then

    OS=$(cat /etc/system-release | awk '{print $1}')
	VERSION=$(cat /etc/system-release | awk '{print $3}')
fi

function disclaimer {

echo "This software \"zcp2kc.sh\" is provided to assist you with the migration from Zarafa to Kopano. Non-standard configurations and configuration options are not supported and you should not try to convert these installations by means of THE PROGRAM. A migration manual with detailed migration steps is provided at  https://documentation.kopano.io/kopano_migration_manual/.

Before you begin the conversion, please ensure that you have created and validated a backup of:
 * Your mailbox database
 * Your attachment directory
 * Any configuration files

THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
"

}

function display_help {

echo "
Usage: ${0} [options]

Options:
  -b, --backup          Location to backup.
  -c, --scl             Use software collections in RHEL
  -h, --help            Show this help message and exit
  --ldap                keep the Kopano ldap.cfg.
  -r, --run-script      Run the scipt
"

}

getpack () {

            if [[ $getversionmeeting ]]; then
                downloadurl=$(curl --user ${username}:${password} https://download.zarafa.com/webmeetings/final/${getversionmeeting}/${OS,,}-${VERSION}/x86_64/)
                for pack in $(echo ${downloadurl} |sed -e 's/<[^>]*>/ /g') ; do
                    if [[ $(echo $pack |egrep "(deb$|rpm$)") ]]; then
                          echo "Downloading ${pack}"
                          curl -O --user  "${username}:${password}" https://download.zarafa.com/webmeetings/final/${getversionmeeting}/${OS,,}-${VERSION}/x86_64/$pack
                     fi
                done
            fi

            if [[ $getversionwebapp ]]; then
                downloadurl=$(curl https://download.zarafa.com/community/final/WebApp/${getversionwebapp}/${OS,,}-${VERSION}/)
                for pack in $(echo ${downloadurl} |sed -e 's/<[^>]*>/ /g') ; do
                    if [[ $(echo $pack |egrep "(deb$|rpm$)") ]]; then
                          echo "Downloading ${pack}"
                          curl -O  https://download.zarafa.com/community/final/WebApp/${getversionwebapp}/${OS,,}-${VERSION}/$pack
                     fi
                done
            fi

            if [[ $getversionfiles ]]; then
                if  [[ $getversionfiles == "1.0_" ]]; then
                    getversionfiles="beta1"
                else
                    getversionfiles="beta2"
                fi
                downloadurl=$(curl --user "${username}:${password}"  https://download.zarafa.com/supported/beta/Webapp/plugins/z-files/${getversionwebapp}/${OS,,}-${VERSION}/)
                for pack in $(echo ${downloadurl} |sed -e 's/<[^>]*>/ /g') ; do
                    if [[ $(echo $pack |egrep "(deb$|rpm$)") ]]; then
                          echo "Downloading ${pack}"
                          curl -O --user ${username}:${password}  https://download.zarafa.com/supported/beta/Webapp/plugins/z-files/${getversionwebapp}/${OS,,}-${VERSION}/$pack
                     fi
                done
            fi
}

rollback () {

    if  [[ ${DEBUG} == false ]]; then
        RED='\033[0;31m'
        ORANGE='\033[0;33m'
        NC='\033[0m'
        printf "${RED}Error detected, Please contact our support if you have a valid license${NC}\n\n

Email: support@kopano.com

Kopano Support Delft
Phone: +31 (0) 15 251 7715
Hours: 08:30 - 17:30 (Europe/Amsterdam)
Languages: English, Dutch

Kopano Support Germany
Phone: +49 (0) 7153 612090
Hours: 09:00 - 17:00 (Europe/Berlin)
Languages: German, English\n"
    fi
    exit
}

vercomp () {
    if [[ $1 == $2 ]]
    then
        return 0
    fi
    local IFS=.
    local i ver1=($1) ver2=($2)
    # fill empty fields in ver1 with zeros
    for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
    do
        ver1[i]=0
    done
    for ((i=0; i<${#ver1[@]}; i++))
    do
        if [[ -z ${ver2[i]} ]]
        then
            # fill empty fields in ver2 with zeros
            ver2[i]=0
        fi
        if ((10#${ver1[i]} > 10#${ver2[i]}))
        then
            return 1
        fi
        if ((10#${ver1[i]} < 10#${ver2[i]}))
        then
            return 2
        fi
    done
    return 0
}

testvercomp () {
    vercomp $1 $2
    case $? in
        0) op='=';;
        1) op='>';;
        2) op='<';;
    esac
    if [[ ${op} != $3 ]]
    then
        echo "FAIL"
    else
        echo "PASS"
    fi
}

function removezarafa {

    echo "Creating backup in ${backup}/zarafabackup/"
    #backup config files
    if [ ! -d ${backup}/zarafabackup ]; then
        mkdir -p ${backup}/zarafabackup/share/
    fi
    cp -rf /etc/zarafa/ ${backup}/zarafabackup/
    cp -rf /usr/share/zarafa/ /usr/share/zarafa-spooler/ /usr/share/zarafa-dagent/ ${backup}/zarafabackup/share/

    if [[ ${OS} == *"Debian"* ]]  ;then
            VERSION="${VERSION}.0"
    fi
    if [[ ${OS} == *"CentOS"* ]] || [[ ${OS} == *"RedHat"* ]] ; then
        OS='rhel'
            if [[ ${VERSION} =~ "6." ]]; then
                VERSION=6
                EXTRA='PHP_56'
        fi
    fi

#Trap info
#zarafa server part
    version=$(zarafa-admin -V | head -n 1 | awk '{print $ 3}' |sed s/,/./g)
    brand=$(echo ${version}| cut -c-3 )
    headversion=$(echo ${version} | cut -c-6)

    if [[ $(echo ${headversion:$i-1}) == '.' ]]; then
        headversion=$(echo ${version} | cut -c-5)
    fi
    versioning=$(echo ${version} | cut -d "." -f 4)

    if [[ $(testvercomp  $(echo ${version} | cut -c-5 )   7.2.2  '>') == "PASS" ]]; then
        middle="."
    else
        middle="-"
    fi

    rollbackurl="https://download.zarafa.com/supported/final/${brand}/${headversion}${middle}${versioning}/zcp-${headversion}${middle}${versioning}-${OS,,}-$(echo ${VERSION}|  sed  s'/_PHP_56/-php-56/')-x86_64-supported.tar.gz"
#webmeetings part

    if [[ ${OS} == *"Debian"* ]] || [[ ${OS} == *"Ubuntu"* ]] ; then
        getversionmeeting=$(dpkg -l | grep zarafa-webapp-plugins-meetings| awk '{print $3}' | cut -c-3)
        getversionwebapp=$(dpkg -l | grep 'zarafa-webapp ' | awk '{print $3}' | cut -c-5)
        getversionfiles=$(dpkg -l | grep 'zarafa-webapp-plugins-files ' | awk  '{print $3}' | cut  -c-5)
    fi
    if [[ ${OS} == *"CentOS"* ]] || [[ ${OS} == *"RedHat"* ]] || [[ ${OS} == *"rhel"* ]]; then
        getversionmeeting=$(rpm -qa | grep zarafa-webapp-plugins-meetings | cut -c31-33)
        getversionwebapp=$(rpm -qa  --qf  "%{NAME} %{VERSION}\n" |  grep 'zarafa-webapp ' | awk '{print $2}' | cut -c-5)
        getversionfiles=$(rpm -qa  --qf  "%{NAME} %{VERSION}\n" |grep 'zarafa-webapp-plugins-files ' | awk  '{print $2}' | cut  -c-5)
    fi


#End trap info

    services=()
    for server in server spooler dagent ical gateway monitor presence search; do
        read  -ra checkserver <<< $(pgrep zarafa-${server} )
        if [ ${checkserver} > "100" ]; then
              services+=(${server})
        fi
    done

    if [[ ${OS} == *"Debian"* ]] || [[ ${OS} == *"Ubuntu"* ]] ; then
        rollbackpackages=$(dpkg -l | grep -E  'zarafa|mapi|zcp' | awk '{print $2}' | grep -v -E 'libkcicalmapi0|libkcmapi')

        installpackages=$(dpkg -l | grep zarafa | awk '{print $2}' | grep -v lib)

        echo -e "purging following packages:\n$installpackages"

        if [[ ${dryrun} == false ]]; then
            for d in ${services[@]}; do /etc/init.d/zarafa-${d} stop ; done

            apt-get purge -y ${rollbackpackages}

        fi
    fi

   if [[ ${OS} == *"CentOS"* ]] || [[ ${OS} == *"RedHat"* ]] || [[ ${OS} == *"rhel"* ]]; then
        rollbackpackages=$(rpm -qa --qf  "%{NAME}\n" |  grep -E  'zarafa|mapi|zcp' | grep -v -E 'libkcicalmapi0|libkcmapi')
        installpackages=$(rpm -qa  --qf  "%{NAME}\n" |  grep -E  'zarafa|mapi|zcp' )

        echo -e "purging following packages:\n$installpackages"

        if [[ ${dryrun} == false ]]; then

           for d in ${services[@]}; do /etc/init.d/zarafa-${d} stop ; done

           yum remove  -y ${installpackages}
        fi
   fi

}

function installkopano {
    # rename Zarafa to Kopano

    whitelist='kopano-backup kopano-bash-completion kopano-dagent kopano-gateway kopano-ical kopano-monitor kopano-presence kopano-search kopano-server
    kopano-spooler kopano-webapp kopano-webmeetings kopano-webapp-plugin-contactfax kopano-webapp-plugin-delayeddelivery kopano-webapp-plugin-desktopnotifications
    kopano-webapp-plugin-filepreviewer kopano-webapp-plugin-files kopano-webapp-plugin-filesbackend-owncloud kopano-webapp-plugin-filesbackend-smb
    kopano-webapp-plugin-folderwidgets kopano-webapp-plugin-gmaps kopano-webapp-plugin-mdm kopano-webapp-plugin-meetings kopano-webapp-plugin-pimfolder
    kopano-webapp-plugin-quickitems kopano-webapp-plugin-smime kopano-webapp-plugin-smime kopano-webapp-plugin-spell kopano-webapp-plugin-spell-de-at
    kopano-webapp-plugin-spell-de-ch kopano-webapp-plugin-spell-de-de kopano-webapp-plugin-spell-en kopano-webapp-plugin-spell-en-gb  kopano-webapp-plugin-spell-es
    kopano-webapp-plugin-spell-fr kopano-webapp-plugin-spell-it kopano-webapp-plugin-spell-nl kopano-webapp-plugin-spell-pl-pl kopano-webapp-plugin-titlecounter'

    convertlist='kopano-webapp-contactfax kopano-webapp-desktopnotifications kopano-webapp-folderwidgets kopano-webapp-gmaps
    kopano-webapp-pimfolder kopano-webapp-quickitems kopano-webapp-titlecounter kopano-webapp-webappmanual'

    kopanoinstall=()
    for package in $(echo ${installpackages} |sed 's/zarafa/kopano/g' | sed 's/kopano-search-plus/kopano-search/g'|sed 's/plugins/plugin/g' | sed 's/kopano-backup-plus/kopano-backup/g'   ); do
        if [[ ! ${package}  == 'kopano' ]]; then
          if [[ ${convertlist} =~ $package ]]; then
            kopanoinstall+=($(echo ${package} | sed s/-/-plugin-/2))
          elif [[ ${whitelist} =~ $package ]]; then
            kopanoinstall+=(${package})
          fi

          if [[ ${package}  == 'kopano-backup' ]]; then
               kopanoinstall+=(${package})
          fi
            if [[ ${package}  == 'gsoap-kopano-dbg' ]]; then
               kopanoinstall+=(${package})
          fi
        fi
    done

    if [[ ${OS} == *"Debian"* ]] || [[ ${OS} == *"Ubuntu"* ]] ; then

            echo "Install apt-transport-https"
            if [[ ${dryrun} == false ]]; then
                trap rollback INT TERM EXIT
                DEBIAN_FRONTEND=noninteractive apt-get update
                apt-get -y install apt-transport-https
                trap - INT TERM EXIT
            fi

            echo "Add Repo in /etc/apt/sources.list.d/kopano.list"
            echo "Install following Kopano components ${kopanoinstall[@]} "
            if [[ ${dryrun} == false ]]; then
                echo '' >  /etc/apt/sources.list.d/kopano.list
                #add prefinal file
                if  [[ ${DEBUG} == false ]]; then
                    echo "deb https://"${username}":"${password}"@download.kopano.io/supported/files:/pre-final//${OS}_${VERSION}/ ./" >> /etc/apt/sources.list.d/kopano.list
                else
                    echo "deb https://download.kopano.io/supported/files:/pre-final//${OS}_${VERSION}/ ./" >> /etc/apt/sources.list.d/kopano.list
                fi

                for software in core mdm webapp webmeetings smime; do
                    if  [[ ${DEBUG} == false ]]; then
                        echo "deb https://${username}:${password}@download.kopano.io/supported/$software:/final/${OS}_${VERSION}/ ./" >> /etc/apt/sources.list.d/kopano.list
                    else
                        echo "deb https://download.kopano.io/supported/$software:/final/${OS}_${VERSION}/ ./" >> /etc/apt/sources.list.d/kopano.list
                    fi
                done
                trap rollback INT TERM EXIT
                lastdone="adding gpg key"
                if  [[ ${DEBUG} == false ]]; then
                    curl --user ${username}:${password} https://download.kopano.io/supported/core:/final/${OS}_${VERSION}/Release.key | apt-key add -
                else
                    curl https://download.kopano.io/supported/core:/final/${OS}_${VERSION}/Release.key | apt-key add -
                fi
                    lastdone="update"
                    apt-get update
                    lastdone="install kopano packages"
                    apt-get -y install ${kopanoinstall[@]}
                trap - INT TERM EXIT

            fi
    fi

    if [[ ${OS} == *"CentOS"* ]] || [[ ${OS} == *"RedHat"* ]] || [[ ${OS} == *"rhel"* ]] ; then
        echo "add kopano repo in /etc/yum.repos.d/kopano.repo \nInstalling kopano"
        if [[ ${dryrun} == false ]]; then
            if [[ ${EXTRA} == 'PHP_56' ]]; then
                VERSION=${VERSION}_${EXTRA}
                lastdone="Install SCL repo"
                yum install centos-release-scl-rh.noarch -y

            fi

            echo "" > /etc/yum.repos.d/kopano.repo
              echo "
[Kopano-files]
name=[Kopano-files
type=rpm-md
baseurl=https://${username}:${password}@download.kopano.io/supported/files:/pre-final//RHEL_${VERSION}/
gpgcheck=0
gpgkey=
enabled=1
" >> /etc/yum.repos.d/kopano.repo

            for software in core mdm webapp webmeetings smime; do
                echo "
[Kopano-${software}]
name=Kopano-${software}
type=rpm-md
baseurl=https://${username}:${password}@download.kopano.io/supported/$software:/final/RHEL_${VERSION}/
gpgcheck=0
gpgkey=
enabled=1
" >> /etc/yum.repos.d/kopano.repo
            done
            lastdone="Yum update"

            yum -y update
            trap rollback INT TERM EXIT
            lastdone="Install Kopano packages"
            yum -y install php ${kopanoinstall[@]}
            trap - INT TERM EXIT
            lastdone="Restart httpd"

        fi
    fi

}

function dochanges {
    echo "changing options in ${server}"
    if [[ ${dryrun} == false ]]; then
        ignorelist='mysql_password mysql_database plugin_manager_path'
        alwayschange='user_plugin_config plugin_path'
        loclist='attachment_path server_ssl_key_file server_ssl_ca_file sslkeys_path'
        for option in ${cfglist}; do
            lastdone="changing ${option} in ${server}"
            oldoption=$(cat ${backup}/zarafabackup/zarafa/${server}| grep ${option}| head -n 1)

            if [[ ! ${option} =~ 'zarafa' ]]; then
                option=$(echo ${option} | sed 's/zarafa/kopano/g')
            fi

            if [[ ! ${oldoption} =~ '#' ]]; then
                copyvalue=$(echo ${oldoption}| grep -o "=.*"| sed 's/=//g' | sed 's/\ //g')
                if [[ ${locpath} == 'switch' ]] || [[ ${locpath} == 'migrate' ]] || [[  ${alwayschange} =~ $option ]] ; then
                    if [[ ! ${ignorelist} =~ $option ]]; then
                        newcopyvalue=$(echo ${copyvalue}| sed 's/zarafa/kopano/g')
                        if  [[ ${locpath} == 'migrate' ]] && [[ ${loclist} =~ $option ]]; then

                                if [[ -f $copyvalue ]] || [[ -d $copyvalue ]]; then
                                    echo -e "cp  -rf ${copyvalue::-1} ${newcopyvalue}"
                                    if [[ "${str:$copyvalue:1}" == '/' ]]; then
                                        cp  -rf ${copyvalue::-1} ${newcopyvalue}
                                    else
                                        cp  -rf ${copyvalue} ${newcopyvalue}
                                    fi
                                fi
                        fi
                        copyvalue=${newcopyvalue}
                    fi
                fi

                copyvalue=$(echo ${copyvalue}  | sed 's/\//\\\//g')

                sed -i "/^$option/s/\(.[^=]*\)\([ \t]*=[ \t]*\)\(.[^=]*\)/\1\2$copyvalue/" /etc/kopano/${server}

            fi
        done

    fi
}


function changeconfig {


        cfglist='server_name server_hostname system_email_address mysql_host mysql_port mysql_user mysql_password mysql_socket mysql_database
        attachment_storage attachment_path attachment_compression server_ssl_enabled server_ssl_port server_ssl_key_file server_ssl_key_pass server_ssl_ca_file server_ssl_ca_path
        sslkeys_path threads softdelete_lifetime sync_lifetime sync_log_all_changes enable_sso enable_gab auth_method pam_service  cache_cell_size cache_object_size cache_indexedobject_size
        cache_quota_size cache_quota_lifetime cache_acl_size cache_store_size cache_user_size cache_userdetails_size cache_userdetails_lifetime cache_server_size  cache_server_lifetime
        quota_warn quota_soft quota_hard companyquota_warn user_plugin user_plugin_config plugin_path thread_stacksize enable_hosted_zarafa enable_distributed_zarafa storename_format
        loginname_format hide_everyone hide_system search_enabled sync_gab_realtime disabled_features restrict_admin_permissions'
        server=server.cfg
        if [[ -f ${backup}/zarafabackup/zarafa/${server} ]]; then
            trap rollback INT TERM EXIT
                dochanges
            trap - INT TERM EXIT
        fi

        cfglist='sslkey_file sslkey_pass log_method lmtp_port lmtp_max_threads run_as_user run_as_group run_as_group spam_header_name spam_header_value
        plugin_manager_path plugin_path default_charset set_rule_headers no_double_forward'
        server=dagent.cfg
        if [[ -f ${backup}/zarafabackup/zarafa/${server} ]]; then
            trap rollback INT TERM EXIT
                dochanges
            trap - INT TERM EXIT
        fi
        cfglist='server_bind server_hostname server_hostname_greeting running_path pop3_enable pop3_port pop3s_enable pop3s_port imap_enable imap_port imaps_enable imaps_port
        imap_only_mailfolders imap_public_folders imap_capability_idle imap_max_messagesize imap_generate_utf8 imap_expunge_on_delete imap_store_rfc822 imap_max_fail_commands
        disable_plaintext_auth ssl_private_key_file ssl_private_key_file ssl_verify_client process_model tmp_path'
        server=gateway.cfg
        if [[ -f ${backup}/zarafabackup/zarafa/${server} ]]; then
            dochanges
        fi

        cfglist='server_bind ical_enable ical_port icals_enable icals_port ssl_private_key_file ssl_certificate_file ssl_verify_client ssl_verify_file ssl_verify_path server_timezone
        default_charset enable_ical_get'
        server=ical.cfg
        if [[ -f ${backup}/zarafabackup/zarafa/${server} ]]; then
            dochanges
        fi

        cfglist='index_path limit_results sslkey_file sslkey_pass ssl_private_key_file ssl_certificate_file'
        server=search.cfg
        if [[ -f ${backup}/zarafabackup/zarafa/${server} ]]; then
            dochanges
        fi

        cfglist='smtp_server smtp_server tmp_path sslkey_file sslkey_pass max_threads fax_domain fax_international always_send_delegates allow_redirect_spoofing copy_delegate_mails
        allow_delegate_meeting_request allow_send_to_everyone always_send_tnef always_send_utf8 charset_upgrade enable_dsn enable_dsn archive_on_send plugin_enabled plugin_manager_path
        plugin_manager_path'
        server=spooler.cfg
        if [[ -f ${backup}/zarafabackup/zarafa/${server} ]]; then
            trap rollback INT TERM EXIT
                dochanges
            trap - INT TERM EXIT
        fi


        if [[ -f ${backup}/zarafabackup/zarafa/webmeetings.cfg ]]; then
            echo "Changing webmeetings file if exist"
            if [[ ${dryrun} == false ]]; then
                cp ${backup}/zarafabackup/zarafa/webmeetings.cfg /etc/kopano/
                sed -i "/^root/s/\(.[^=]*\)\([ \t]*=[ \t]*\)\(.[^=]*\)/\1\2\/usr\/share\/kopano-webmeetings\/www/" /etc/kopano/webmeetings.cfg
                if [[ ${OS} == *"Debian"* ]] || [[ ${OS} == *"Ubuntu"* ]] ; then
                    /etc/init.d/kopano-webmeetings restart
                fi
                if [[ ${OS} == *"CentOS"* ]] || [[ ${OS} == *"RedHat"* ]] || [[ ${OS} == *"rhel"* ]]; then
                    if [[ ${VERSION} == "6_PHP_56" ]]; then
                        service kopano-webmeetings restart
                    else
                        systemctl enable kopano-webmeetings
                        systemctl start kopano-webmeetings
                    fi
                fi
            fi
        fi


    if [[ ${locpath} == 'leave' ]]; then
        echo  "chown /var/lib/zarafa to kopano"
        if [[ ${dryrun} == false ]]; then
            chown -R kopano.  /var/lib/zarafa
        fi
    fi
    #check for user_plugin
    checkuser=$(cat ${backup}/zarafabackup/zarafa/server.cfg | grep user_plugin | head -n 1 |  grep -o "=.*" | sed 's/= //g')
    echo 'Checking if ldap is used and changing ldap config.'
    if [[ ${dryrun} == false ]]; then
        if  [[ ${checkuser} =~ 'ldap' ]]; then
                configfile=$(cat ${backup}/zarafabackup/zarafa/server.cfg | grep user_plugin_config |  grep -o "=.*" | sed 's/= //g' | sed 's/\/etc\/zarafa\///g')
                cp ${backup}/zarafabackup/zarafa/${configfile} /etc/kopano/
            if [[ ${ldap} == false ]]; then
                sed -i 's/\/etc\/zarafa\/ldap.propmap.cfg/\/usr\/share\/kopano\/ldap.propmap.cfg/' /etc/kopano/${configfile}
            else
               cp ${backup}/zarafabackup/zarafa/ldap.propmap.cfg /etc/kopano/
               sed -i 's/\/etc\/zarafa\/ldap.propmap.cfg/\/etc\/kopano\/ldap.propmap.cfg/' /etc/kopano/${configfile}
            fi
        fi
    fi

    echo "Starting  kopano services"
    if [[ ${dryrun} == false ]]; then
        chown -R kopano.  /etc/kopano/
        sleep 5
        for soft in ${services[@]}; do
            if [[ ${OS} == *"Debian"* ]] || [[ ${OS} == *"Ubuntu"* ]] ; then
                /etc/init.d/kopano-${soft} restart
            fi

            if [[ ${OS} == *"CentOS"* ]] || [[ ${OS} == *"RedHat"* ]] || [[ ${OS} == *"rhel"* ]]; then
                if [[ ${VERSION} == "6_PHP_56" ]]; then
                    service kopano-${soft} restart
                else
                    systemctl enable kopano-${soft}
                    systemctl start kopano-${soft}
                fi
            fi

        done
     fi

}


function changewebappconfig {
    echo "Check config file ${webappconfig}"
    if [[ ${dryrun} == false ]]; then
        for option in ${zarafaconfig[@]}; do
            export webappconfig=$configfile
            export WebAppoption=$option
            new_option=`parsewebappconfig`
            export webappconfig=/etc/kopano/webapp/$(basename $configfile)
            option=$(echo $option | sed 's/ZARAFA/KOPANO/g' )
            export WebAppoption=$option
            old_option=`parsewebappconfig`
            zerooptions='CLIENT_TIMEOUT FREEBUSY_LOAD_START_OFFSET FREEBUSY_LOAD_END_OFFSET MAX_EML_FILES_IN_ZIP max_execution_time BLOCK_SIZE'
            if ([[ ${old_option} == 'true' ]] || [[ ${old_option} == 'false' ]]) && ([[ ${new_option} != 'true' ]] && [[ ${new_option} != 'false' ]]) ; then
                continue
            fi
            if [[ ${new_option} != ${old_option} ]] && [[ ! ${new_option,,} == *"zarafa"* ]]; then
                    if [[  ${zerooptions} =~ $option ]] && [[ ${new_option} == 'false' ]];  then
                        new_option=0
                    fi
                    endchars=$(cat ${webappconfig} | grep  ${option} | awk '{print $2}')
                    if [[ ${endchars:0:1} == "'" ]]; then
                        sed -i "/${option}/s/, *'[^$']*'/, '${new_option}'/" $webappconfig
                    elif [[ ${endchars:0:1} == '"' ]]; then
                        sed -i  "/${option}/s/, *\"[^$\"]*\"/, \"${new_option}\"/" $webappconfig
                    else
                        sed -i "/${option}/s/,[^,]*/,\ ${new_option}\)\;/"  $webappconfig
                    fi
            fi
        done
    fi
}

function parsewebappconfig {

   oldoption=`/usr/bin/php  << 'EOF'
<?php
    include(getenv("webappconfig"));
    $option=  constant(getenv("WebAppoption"));
    if (is_bool($option) === true) {
        echo $option ? 'true' : 'false';
    }
    else if (empty($option)){
        echo $option ? 'true' : 'false';
    }
    else{
        echo $option;
    }

?>
EOF`

    echo $oldoption

}

function webappconfig {
    for configfile in ${backup}/zarafabackup/zarafa/webapp/* ; do
        #check if config exist for kopano

        if [  -f /etc/kopano/webapp/$(basename $configfile) ]; then
            export webappconfig=$configfile
            configarray=`/usr/bin/php  << 'EOF'
<?php
include(getenv("webappconfig"));
$constants = get_defined_constants(true);
//foreach ($constants['user'] as $page) {



foreach($constants['user'] as $key => $value)
{
  echo $key,' ';

}


?>
EOF`

            zarafaconfig=($configarray)
            changewebappconfig
         fi
    done
}




#check arguments.
while [[ $# > 0 ]] ; do
  case "$1" in
  	  -b | --backup)
	  backup=$2
	    ;;
	  -c | --scl)
	  EXTRA='PHP_56'
	    ;;
  	  -d | --debug)
	  DEBUG=true
	    ;;
       -h | --help)
	  display_help
	    exit 0
	    ;;
	  -l | --Leave)
	  locpath='leave'
	    ;;
	  --ldap)
	  ldap=true
	    ;;
      -r | --run-script)
	  dryrun=false
	    ;;


  esac
  shift
done

#check for ldapms plugin
checkldapms=$(cat /etc/zarafa/server.cfg | grep user_plugin | head -n 1 |  grep -o "=.*" | sed 's/= //g')
  if  [[ ${checkldapms} =~ 'ldapms' ]]; then
    echo "Multiserver enviroment detected please use the migration documentation https://documentation.kopano.io/kopano_migration_manual/"
    exit 1
  fi


if [[ ${OS} == *"SUSE"* ]]; then

    echo "Script is not compatible with your distribution system"
    exit 1
fi


# print disclaimer
disclaimer

if  [[ ${DEBUG} == false ]]; then

    while true; do
        read -p "Please confirm that you understand  what the script will do by typing OK: `echo $'\n> '`" yn
        case ${yn} in
            OK ) break;;
            [EXIT]* ) exit;;
            * ) echo "Please answer OK or EXIT to quit.";;
        esac
    done

fi

check_ssl=$( cat /etc/zarafa/server.cfg | grep server_ssl_enabled | grep -o "=.*" | sed 's/= //g')
if [[ ${check_ssl,,} == 'yes' ]]; then
     ssl_cert=$(cat /etc/zarafa/server.cfg | grep server_ssl_key_file | grep -o "=.*" | sed 's/= //g')

     common_name=$(openssl x509 -in ${ssl_cert} -noout -subject | sed -e 's/^subject.*CN=\([a-zA-Z0-9\.\-]*\).*$/\1/')

     echo -e "

WARNING: From Kopano Core 8.2.0 the Common Name in the ssl certificate should match the FQDN of the server
if the FQDN and the CN do not match, client's(Webapp, Dagent, Spooler, e.g.) can not connect to the server
The Common Name in the SSL certificate is '${common_name}'"
 while true; do
        read -p "Please confirm that your FQDN match the common name in your SSl certificate by typing OK: `echo $'\n> '`" yn
        case ${yn} in
            OK ) break;;
            [EXIT]* ) exit;;
            * ) echo "Please answer OK or EXIT to quit.";;
        esac
    done

fi


if  [[ ${DEBUG} == false ]]; then
    RED='\033[0;31m'
    NC='\033[0m'
    printf "${RED}We use the credentials for authentication for the Kopano repository. The credentials will be stored on you server ${NC}\n"
    echo "Please enter your credentials from portal.kopano.com:"

    while true; do
        echo -n Username:
        read username
        echo -n Password:
        read -s password

        if [[ ${username} ]] && [[ ${password} ]]; then
               check=$(curl --user ${username}:${password} -s --head  https://download.kopano.io/supported/ | head -n 1)
               if [[ ${check} =~ '200' ]]; then
                    break
               else
                    echo -e "\nSorry, unrecognized username or password"
               fi
        else
            echo "Please enter your credentials from portal.kopano.com:"
        fi

    done

fi

if [[ ${dryrun} == true ]]; then
    echo -e '\nScript will only print the steps that will be performed. To execute the migration please use the parameter -r'
    sleep 2
else
    echo -e '\nRunning script in live mode'
fi

echo 'Backup Zarafa config files'
removezarafa

echo 'Installing Kopano'
installkopano

echo 'Comparing configs'
changeconfig

echo 'Comparing webapp configs'
webappconfig

echo -e "Kopano is installed \nPlease reload apache for Kopano WebApp."

or use git 

git clone https://stash.kopano.io/scm/ksc/migrate.git

 

ZCP version 

The script is able to migrate from the latest ZCP 7.1.x and ZCP 7.2.x final version.
If you are running a beta version the rollback function will not work. 

Starting the script

By default the script will start in dryrun mode, which means that it will not change anything on the system and only print the things it would do.
Running the script with parameter  -r will start the migration. 

Rollback

If for some reason the script fails, an automatic rollback will be triggered that will reinstall ZCP. 
The rollback function is only available if there was a final version of ZCP installed, rollbacks to beta versions are not supported.

For RHEL/CentOS users, the rollback function will not work if epel is installed. This is because a zcp version is available in the EPEL repository 

 

  • No labels