1

Topic: /opt/www/iredadmin/: No such file or directory

==== REQUIRED BASIC INFO OF YOUR IREDMAIL SERVER ====
- iRedMail version (check /etc/iredmail-release): 1.1
- Deployed with iRedMail Easy or the downloadable installer? download
- Linux/BSD distribution name and version: Ubuntu 18.04.5
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx):Apache2
- Manage mail accounts with iRedAdmin-Pro? iRedadmin
- [IMPORTANT] Related original log or error message is required if you're experiencing an issue.
====

When I try to upgrade from iRedAdmin 1.0 to 1.1, I get the 500 error. But I notice this:

/opt/www/iredadmin/: No such file or directory

What is missing? thank you

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: /opt/www/iredadmin/: No such file or directory

on Debian/Ubuntu, it's /opt/www/iredadmin/settings.py.
Note: on old iRedMail releases, it's /usr/share/apache2/iredadmin/settings.py.

I ran the upgrade to 1.1, but it did not move iredadmin to new location. How to install in new location?

thank you for your help

3

Re: /opt/www/iredadmin/: No such file or directory

- Is your server upgraded from an (very) old iRedMail release?
- check /opt/www/, /usr/share/apache2/.

4

Re: /opt/www/iredadmin/: No such file or directory

ZhangHuangbin wrote:

- Is your server upgraded from an (very) old iRedMail release?
- check /opt/www/, /usr/share/apache2/.

Yes. here is /opt/
lrwxrwxrwx  1 root    root      11 Jan 12 12:11 iredapd -> iRedAPD-4.7
dr-xr-xr-x  5 iredapd iredapd 4096 Jun 16  2013 iRedAPD-1.4.0
dr-xr-xr-x  6 iredapd iredapd 4096 Jan  4  2015 iRedAPD-1.4.4
dr-x------  7 root    root    4096 Dec 20  2016 iRedAPD-1.9.0
dr-x------  7 root    root    4096 Mar 30  2017 iRedAPD-1.9.1
dr-x------  8 root    root    4096 Nov 24  2017 iRedAPD-2.0
dr-x------  9 root    root    4096 Mar 12  2018 iRedAPD-2.1
dr-x------  9 root    root    4096 Jan  1  2019 iRedAPD-2.2
dr-x------  9 root    root    4096 Apr 24  2019 iRedAPD-2.3
dr-x------  9 root    root    4096 Sep  3  2019 iRedAPD-2.8
dr-x------  9 root    root    4096 Feb 25  2020 iRedAPD-3.1
dr-x------  9 root    root    4096 Jan 12 12:06 iRedAPD-3.4
dr-x------ 10 root    root    4096 Jan 12 12:11 iRedAPD-4.7
drwxr-xr-x 24 root    root    4096 Jan 11 02:30 letsencrypt
lrwxrwxrwx  1 root    root      21 Jan 12 12:14 mlmmjadmin -> /opt/mlmmjadmin-3.0.7
drwxrwxr-x 10 root    root    4096 Jan 12 12:12 mlmmjadmin-1.9
drwxr-xr-x 11 mlmmj   mlmmj   4096 Jan 12 12:39 mlmmjadmin-3.0.7

and /usr/share/apache2/
lrwxrwxrwx   1 root      root         13 Jan 12 12:39 iredadmin -> iRedAdmin-1.0
dr-xr-xr-x   8 iredadmin iredadmin  4096 Jun 16  2013 iRedAdmin-0.2.1
dr-xr-xr-x   8 iredadmin iredadmin  4096 Nov 21  2013 iRedAdmin-0.2.2
drwxr-xr-x   9 iredadmin iredadmin  4096 May 20  2014 iRedAdmin-0.3
dr-xr-xr-x   9 iredadmin iredadmin  4096 May 20  2014 iRedAdmin-0.3.3
dr-xr-xr-x   9 iredadmin iredadmin  4096 Jan  3  2015 iRedAdmin-0.4
dr-xr-xr-x   9 iredadmin iredadmin  4096 Jun  8  2015 iRedAdmin-0.4.2
dr-xr-xr-x   9 iredadmin iredadmin  4096 Jan 31  2016 iRedAdmin-0.5
dr-xr-xr-x   9 iredadmin iredadmin  4096 May  3  2016 iRedAdmin-0.6
dr-xr-xr-x   9 iredadmin iredadmin  4096 Jan  5  2017 iRedAdmin-0.6.3
dr-xr-xr-x  10 iredadmin iredadmin  4096 Apr  3  2017 iRedAdmin-0.7
dr-xr-xr-x  10 iredadmin iredadmin  4096 Nov 24  2017 iRedAdmin-0.8
dr-xr-xr-x  10 iredadmin iredadmin  4096 Mar 12  2018 iRedAdmin-0.9
dr-xr-xr-x  10 iredadmin iredadmin  4096 Jan  1  2019 iRedAdmin-0.9.1
dr-xr-xr-x  11 iredadmin iredadmin  4096 Jan  2  2019 iRedAdmin-0.9.2
dr-xr-xr-x  11 iredadmin iredadmin  4096 Apr 29  2019 iRedAdmin-0.9.7
dr-xr-xr-x  11 iredadmin iredadmin  4096 Sep 12  2019 iRedAdmin-0.9.8
dr-xr-xr-x  11 iredadmin iredadmin  4096 Jan 12 13:01 iRedAdmin-1.0
lrwxrwxrwx   1 root      root         38 Jun 16  2013 roundcubemail -> /usr/share/apache2/roundcubemail-0.8.6
drwxr-xr-x  12 root      root       4096 Jan 12 12:48 roundcubemail-0.8.6

5

Re: /opt/www/iredadmin/: No such file or directory

Any answer please?

6

Re: /opt/www/iredadmin/: No such file or directory

Could you please try again with commands below?

cd /path/to/iRedAdmin-1.1/tools/
bash -xv upgrade_iredadmin.sh

Then copy full console output as text and paste here for troubleshooting.

7 (edited by djfake 2021-01-18 00:20:05)

Re: /opt/www/iredadmin/: No such file or directory

# bash -xv upgrade_iredadmin.sh
#!/usr/bin/env bash

# Purpose: Upgrade iRedAdmin from old release.
#          Works with both iRedAdmin open source edition or iRedAdmin-Pro.

# USAGE:
#
#   # cd /path/to/iRedAdmin-xxx/tools/
#   # bash upgrade_iredadmin.sh
#
# Notes:
#
#   * it uses sql username 'root' by default to connect to sql database. If you
#     are using a remote SQL database which you don't have root privilege,
#     please specify the sql username on command line with 'SQL_IREDADMIN_USER'
#     parameter like this:
#
#       SQL_IREDADMIN_USER='iredadmin' bash upgrade_iredadmin.sh
#
#   * it reads sql password for given sql user from /root/.my.cnf by default.
#     if you use a different file, please specify the file on command line with
#     'MY_CNF' parameter like this:
#
#       MY_CNF='/root/.my.cnf-iredadmin' SQL_IREDADMIN_USER='iredadmin' bash upgrade_iredadmin.sh

export LC_ALL='C'
+ export LC_ALL=C
+ LC_ALL=C
export IRA_HTTPD_USER='iredadmin'
+ export IRA_HTTPD_USER=iredadmin
+ IRA_HTTPD_USER=iredadmin
export IRA_HTTPD_GROUP='iredadmin'
+ export IRA_HTTPD_GROUP=iredadmin
+ IRA_HTTPD_GROUP=iredadmin

export SYS_ROOT_USER='root'
+ export SYS_ROOT_USER=root
+ SYS_ROOT_USER=root

# If you don't have root privilege, use another sql user instead.
export SQL_IREDADMIN_USER="${SQL_IREDADMIN_USER:=root}"
+ export SQL_IREDADMIN_USER=root
+ SQL_IREDADMIN_USER=root
export MY_CNF="${MY_CNF:=/root/.my.cnf}"
+ export MY_CNF=/root/.my.cnf
+ MY_CNF=/root/.my.cnf
export CMD_MYSQL="mysql --defaults-file=${MY_CNF} -u ${SQL_IREDADMIN_USER}"
+ export 'CMD_MYSQL=mysql --defaults-file=/root/.my.cnf -u root'
+ CMD_MYSQL='mysql --defaults-file=/root/.my.cnf -u root'

# Check OS to detect some necessary info.
export KERNEL_NAME="$(uname -s | tr '[a-z]' '[A-Z]')"
++ uname -s
++ tr '[a-z]' '[A-Z]'
+ export KERNEL_NAME=LINUX
+ KERNEL_NAME=LINUX

export NGINX_PID_FILE='/var/run/nginx.pid'
+ export NGINX_PID_FILE=/var/run/nginx.pid
+ NGINX_PID_FILE=/var/run/nginx.pid
export NGINX_SNIPPET_CONF='/etc/nginx/templates/iredadmin.tmpl'
+ export NGINX_SNIPPET_CONF=/etc/nginx/templates/iredadmin.tmpl
+ NGINX_SNIPPET_CONF=/etc/nginx/templates/iredadmin.tmpl
export NGINX_SNIPPET_CONF2='/etc/nginx/templates/iredadmin-subdomain.tmpl'
+ export NGINX_SNIPPET_CONF2=/etc/nginx/templates/iredadmin-subdomain.tmpl
+ NGINX_SNIPPET_CONF2=/etc/nginx/templates/iredadmin-subdomain.tmpl
# iRedMail-0.9.7
export NGINX_SNIPPET_CONF3='/etc/nginx/conf.d/default.conf'
+ export NGINX_SNIPPET_CONF3=/etc/nginx/conf.d/default.conf
+ NGINX_SNIPPET_CONF3=/etc/nginx/conf.d/default.conf

export USE_SYSTEMD='NO'
+ export USE_SYSTEMD=NO
+ USE_SYSTEMD=NO
if which systemctl &>/dev/null; then
    export USE_SYSTEMD='YES'
    export SYSTEMD_SERVICE_DIR='/lib/systemd/system'
    export SYSTEMD_SERVICE_DIR2='/etc/systemd/system'
    export SYSTEMD_SERVICE_USER_DIR='/etc/systemd/system/multi-user.target.wants/'
fi
+ which systemctl
+ export USE_SYSTEMD=YES
+ USE_SYSTEMD=YES
+ export SYSTEMD_SERVICE_DIR=/lib/systemd/system
+ SYSTEMD_SERVICE_DIR=/lib/systemd/system
+ export SYSTEMD_SERVICE_DIR2=/etc/systemd/system
+ SYSTEMD_SERVICE_DIR2=/etc/systemd/system
+ export SYSTEMD_SERVICE_USER_DIR=/etc/systemd/system/multi-user.target.wants/
+ SYSTEMD_SERVICE_USER_DIR=/etc/systemd/system/multi-user.target.wants/

# Python.
export CMD_PYTHON3='/usr/bin/python3'
+ export CMD_PYTHON3=/usr/bin/python3
+ CMD_PYTHON3=/usr/bin/python3
export CMD_PIP3='/usr/bin/pip3'
+ export CMD_PIP3=/usr/bin/pip3
+ CMD_PIP3=/usr/bin/pip3

# uwsgi
export CMD_UWSGI='/usr/bin/uwsgi'
+ export CMD_UWSGI=/usr/bin/uwsgi
+ CMD_UWSGI=/usr/bin/uwsgi

if [ X"${KERNEL_NAME}" == X"LINUX" ]; then
    export DISTRO_VERSION=$(awk -F'"' '/^VERSION_ID=/ {print $2}' /etc/os-release)

    if [ -f /etc/redhat-release ]; then
        # RHEL/CentOS
        export DISTRO='RHEL'
        export CMD_UWSGI='/usr/sbin/uwsgi'

        if [ X"${DISTRO_VERSION}" == X'8' ]; then
            # CentOS 8 doesn't have uwsgi package, we will install it with pip3.
            export CMD_UWSGI='/usr/local/bin/uwsgi'
        fi

        export HTTPD_RC_SCRIPT_NAME='httpd'
        export CRON_SPOOL_DIR='/var/spool/cron'

        if [[ -L /opt/www/iredadmin ]]; then
            export HTTPD_SERVERROOT='/opt/www'
        else
            export HTTPD_SERVERROOT='/var/www'
        fi
    elif [ -f /etc/lsb-release ]; then
        # Ubuntu
        export DISTRO='UBUNTU'

        export HTTPD_RC_SCRIPT_NAME='apache2'
        export CRON_SPOOL_DIR='/var/spool/cron/crontabs'

        if [ -L /opt/www/iredadmin ]; then
            export HTTPD_SERVERROOT='/opt/www'
        else
            export HTTPD_SERVERROOT='/usr/share/apache2'
        fi
    elif [ -f /etc/debian_version ]; then
        # Debian
        export DISTRO='DEBIAN'

        export HTTPD_RC_SCRIPT_NAME='apache2'
        export CRON_SPOOL_DIR='/var/spool/cron/crontabs'

        if [ -L /opt/www/iredadmin ]; then
            export HTTPD_SERVERROOT='/opt/www'
        else
            export HTTPD_SERVERROOT='/usr/share/apache2'
        fi
    elif [ -f /etc/SuSE-release ]; then
        # openSUSE
        export DISTRO='SUSE'
        export HTTPD_SERVERROOT='/srv/www'
        export HTTPD_RC_SCRIPT_NAME='apache2'
        export CRON_SPOOL_DIR='/var/spool/cron'
    else
        echo "<<< ERROR >>> Cannot detect Linux distribution name. Exit."
        echo "Please contact support@iredmail.org to solve it."
        exit 255
    fi
elif [ X"${KERNEL_NAME}" == X'FREEBSD' ]; then
    export DISTRO='FREEBSD'
    export SYSRC='/usr/sbin/sysrc'

    export CMD_PYTHON3='/usr/local/bin/python3'
    export CMD_PIP3='/usr/local/bin/pip3'
    export CMD_UWSGI='/usr/local/bin/uwsgi'
    export CRON_SPOOL_DIR='/var/cron/tabs'
    export NGINX_SNIPPET_CONF='/usr/local/etc/nginx/templates/iredadmin.tmpl'
    export NGINX_SNIPPET_CONF2='/usr/local/etc/nginx/templates/iredadmin-subdomain.tmpl'
    export NGINX_SNIPPET_CONF3='/usr/local/etc/nginx/conf.d/default.conf'

    if [ -L /opt/www/iredadmin ]; then
        export HTTPD_SERVERROOT='/opt/www'
    else
        export HTTPD_SERVERROOT='/usr/local/www'
    fi

    if [ -f /usr/local/etc/rc.d/apache24 ]; then
        export HTTPD_RC_SCRIPT_NAME='apache24'
    else
        export HTTPD_RC_SCRIPT_NAME='apache22'
    fi
elif [ X"${KERNEL_NAME}" == X'OPENBSD' ]; then
    export CMD_PYTHON3='/usr/local/bin/python3'
    export CMD_PIP3='/usr/local/bin/pip3'
    export CMD_UWSGI='/usr/local/bin/uwsgi'
    export DISTRO='OPENBSD'
    export CRON_SPOOL_DIR='/var/cron/tabs'

    if [[ -h /opt/www/iredadmin ]]; then
        export HTTPD_SERVERROOT='/opt/www'
    else
        export HTTPD_SERVERROOT='/var/www'
    fi
else
    echo "Cannot detect Linux/BSD distribution. Exit."
    echo "Please contact author iRedMail team <support@iredmail.org> to solve it."
    exit 255
fi
+ '[' XLINUX == XLINUX ']'
++ awk '-F"' '/^VERSION_ID=/ {print $2}' /etc/os-release
+ export DISTRO_VERSION=18.04
+ DISTRO_VERSION=18.04
+ '[' -f /etc/redhat-release ']'
+ '[' -f /etc/lsb-release ']'
+ export DISTRO=UBUNTU
+ DISTRO=UBUNTU
+ export HTTPD_RC_SCRIPT_NAME=apache2
+ HTTPD_RC_SCRIPT_NAME=apache2
+ export CRON_SPOOL_DIR=/var/spool/cron/crontabs
+ CRON_SPOOL_DIR=/var/spool/cron/crontabs
+ '[' -L /opt/www/iredadmin ']'
+ export HTTPD_SERVERROOT=/usr/share/apache2
+ HTTPD_SERVERROOT=/usr/share/apache2

export CRON_FILE_ROOT="${CRON_SPOOL_DIR}/${SYS_ROOT_USER}"
+ export CRON_FILE_ROOT=/var/spool/cron/crontabs/root
+ CRON_FILE_ROOT=/var/spool/cron/crontabs/root

# Optional argument to set the directory which stores iRedAdmin.
if [ $# -gt 0 ]; then
    if [ -d ${1} ]; then
        export HTTPD_SERVERROOT="${1}"
    fi

    if echo ${HTTPD_SERVERROOT} | grep '/iredadmin/*$' > /dev/null; then
        export HTTPD_SERVERROOT="$(dirname ${HTTPD_SERVERROOT})"
    fi
fi
+ '[' 0 -gt 0 ']'

# iRedAdmin directory and config file.
export IRA_ROOT_DIR="${HTTPD_SERVERROOT}/iredadmin"
+ export IRA_ROOT_DIR=/usr/share/apache2/iredadmin
+ IRA_ROOT_DIR=/usr/share/apache2/iredadmin
export IRA_CONF_PY="${IRA_ROOT_DIR}/settings.py"
+ export IRA_CONF_PY=/usr/share/apache2/iredadmin/settings.py
+ IRA_CONF_PY=/usr/share/apache2/iredadmin/settings.py
export IRA_CUSTOM_CONF_PY="${IRA_ROOT_DIR}/custom_settings.py"
+ export IRA_CUSTOM_CONF_PY=/usr/share/apache2/iredadmin/custom_settings.py
+ IRA_CUSTOM_CONF_PY=/usr/share/apache2/iredadmin/custom_settings.py

enable_service() {
    srv="$1"

    echo "* Enable service: ${srv}"
    if [ X"${DISTRO}" == X'RHEL' ]; then
        if [ X"${USE_SYSTEMD}" == X'YES' ]; then
            systemctl enable $srv
        else
            chkconfig --level 345 $srv on
        fi
    elif [ X"${DISTRO}" == X'DEBIAN' -o X"${DISTRO}" == X'UBUNTU' ]; then
        if [ X"${USE_SYSTEMD}" == X'YES' ]; then
            systemctl enable $srv
        else
            update-rc.d $srv defaults
        fi
    elif [ X"${DISTRO}" == X'FREEBSD' ]; then
        ${SYSRC} -f /etc/rc.conf.local ${srv}_enable=YES
    elif [ X"${DISTRO}" == X'OPENBSD' ]; then
        rcctl enable $srv
    fi
}

restart_service() {
    srv="$1"

    if [ X"${KERNEL_NAME}" == X'LINUX' ]; then
        if [ X"${USE_SYSTEMD}" == X'YES' ]; then
            systemctl restart ${srv}
        else
            service ${srv} restart
        fi
    elif [ X"${KERNEL_NAME}" == X'FREEBSD' ]; then
        service ${srv} restart
    elif [ X"${KERNEL_NAME}" == X'OPENBSD' ]; then
        rcctl restart ${srv}
    fi

    if [ X"$?" != X'0' ]; then
        echo "Failed, please restart service manually and check its log file."
    fi
}

restart_web_service()
{
    export web_service="${HTTPD_RC_SCRIPT_NAME}"
    if [ -f ${NGINX_PID_FILE} ]; then
        if [ -n "$(cat ${NGINX_PID_FILE})" ]; then
            export web_service="iredadmin"
        fi
    fi

    echo "* Restarting ${web_service} service."
    if [ X"${KERNEL_NAME}" == X'LINUX' ]; then
        # The uwsgi script on CentOS 6 has problem with 'restart' action,
        # 'stop' with few seconds sleep fixes it.
        if [ X"${DISTRO}" == X'RHEL' -a X"${web_service}" == X'uwsgi' ]; then
            service ${web_service} stop
            sleep 5
            service ${web_service} start
        else
            service ${web_service} restart
        fi
    elif [ X"${KERNEL_NAME}" == X'FREEBSD' ]; then
        service ${web_service} restart
    elif [ X"${KERNEL_NAME}" == X'OPENBSD' ]; then
        rcctl restart ${web_service}
    fi

    if [ X"$?" != X'0' ]; then
        echo "Failed, please restart Apache web server or 'iredadmin' (if you're running Nginx as web server) manually."
    fi
}

check_mlmmjadmin_installation()
{
    if [ ! -e /opt/mlmmjadmin ]; then
        echo "<<< ERROR >>> No mlmmjadmin installation found (/opt/mlmmjadmin)."
        echo "<<< ERROR >>> Please follow iRedMail upgrade tutorials to the latest"
        echo "<<< ERROR >>> stable release first, then come back to upgrade iRedAdmin-Pro."
        echo "<<< ERROR >>> mlmmj and mlmmjadmin was first introduced in iRedMail-0.9.8."
        echo "<<< ERROR >>> https://docs.iredmail.org/iredmail.releases.html"
        exit 255
    fi
}

install_pkg()
{
    echo "Install package(s): $@"

    if [ X"${DISTRO}" == X'RHEL' ]; then
        yum -y install $@
    elif [ X"${DISTRO}" == X'DEBIAN' -o X"${DISTRO}" == X'UBUNTU' ]; then
        apt-get install -y $@
    elif [ X"${DISTRO}" == X'FREEBSD' ]; then
        cd /usr/ports/$@ && make install clean
    elif [ X"${DISTRO}" == X'OPENBSD' ]; then
        pkg_add -r $@
    else
        echo "<< ERROR >> Please install package(s) manually: $@"
    fi
}

has_python_module()
{
    mod="$1"
    ${CMD_PYTHON3} -c "import $mod" &>/dev/null
    if [ X"$?" == X'0' ]; then
        echo 'YES'
    else
        echo 'NO'
    fi
}

add_missing_parameter()
{
    # Usage: add_missing_parameter VARIABLE DEFAULT_VALUE [COMMENT]
    var="${1}"
    value="${2}"
    shift 2
    comment="$@"

    if ! grep "^${var}" ${IRA_CONF_PY} &>/dev/null; then
        if [ ! -z "${comment}" ]; then
            echo "# ${comment}" >> ${IRA_CONF_PY}
        fi

        if [ X"${value}" == X'True' -o X"${value}" == X'False' ]; then
            echo "${var} = ${value}" >> ${IRA_CONF_PY}
        else
            # Value must be quoted as string.
            echo "${var} = '${value}'" >> ${IRA_CONF_PY}
        fi
    fi
}

# Remove all single quote and double quotes in string.
strip_quotes()
{
    # Read input from stdin
    str="$(cat <&0)"
    value="$(echo ${str} | tr -d '"' | tr -d "'")"
    echo "${value}"
}

get_iredadmin_setting()
{
    var="${1}"
    value="$(grep "^${var}" ${IRA_CONF_PY} | awk '{print $NF}' | strip_quotes)"
    echo "${value}"
}

check_dot_my_cnf()
{
    if egrep '^backend.*(mysql|ldap)' ${IRA_CONF_PY} &>/dev/null; then
        if [ ! -f ${MY_CNF} ]; then
            echo "<<< ERROR >>> File ${MY_CNF} not found."
            echo "<<< ERROR >>> Please add mysql root user and password in it like below, then run this script again."
            cat <<EOF

[client]
host=127.0.0.1
port=3306
user=${SQL_IREDADMIN_USER}
password="plain_password"

EOF

            exit 255
        fi

        # Check MySQL connection
        ${CMD_MYSQL} -e "SHOW DATABASES" &>/dev/null
        if [ X"$?" != X'0' ]; then
            echo "<<< ERROR >>> MySQL user name '${SQL_IREDADMIN_USER}' or password is incorrect in ${MY_CNF}, please double check."
            exit 255
        fi
    fi
}

check_mlmmjadmin_installation
+ check_mlmmjadmin_installation
+ '[' '!' -e /opt/mlmmjadmin ']'
check_dot_my_cnf
+ check_dot_my_cnf
+ egrep '^backend.*(mysql|ldap)' /usr/share/apache2/iredadmin/settings.py
+ '[' '!' -f /root/.my.cnf ']'
+ mysql --defaults-file=/root/.my.cnf -u root -e 'SHOW DATABASES'
+ '[' X0 '!=' X0 ']'

echo "* Detected Linux/BSD distribution: ${DISTRO}"
+ echo '* Detected Linux/BSD distribution: UBUNTU'
* Detected Linux/BSD distribution: UBUNTU
echo "* HTTP server root: ${HTTPD_SERVERROOT}"
+ echo '* HTTP server root: /usr/share/apache2'
* HTTP server root: /usr/share/apache2

if [ -L ${IRA_ROOT_DIR} ]; then
    export IRA_ROOT_REAL_DIR="$(readlink ${IRA_ROOT_DIR})"
    echo "* Found iRedAdmin directory: ${IRA_ROOT_DIR}, symbol link of ${IRA_ROOT_REAL_DIR}"
else
    echo "<<< ERROR >>> Directory (${IRA_ROOT_DIR}) is not a symbol link created by iRedMail. Exit."
    exit 255
fi
+ '[' -L /usr/share/apache2/iredadmin ']'
++ readlink /usr/share/apache2/iredadmin
+ export IRA_ROOT_REAL_DIR=iRedAdmin-1.0
+ IRA_ROOT_REAL_DIR=iRedAdmin-1.0
+ echo '* Found iRedAdmin directory: /usr/share/apache2/iredadmin, symbol link of iRedAdmin-1.0'
* Found iRedAdmin directory: /usr/share/apache2/iredadmin, symbol link of iRedAdmin-1.0

# Copy config file
if [ -f ${IRA_CONF_PY} ]; then
    echo "* Found iRedAdmin config file: ${IRA_CONF_PY}"
else
    echo "<<< ERROR >>> Cannot find a valid config file (settings.py)."
    exit 255
fi
+ '[' -f /usr/share/apache2/iredadmin/settings.py ']'
+ echo '* Found iRedAdmin config file: /usr/share/apache2/iredadmin/settings.py'
* Found iRedAdmin config file: /usr/share/apache2/iredadmin/settings.py

# Check whether current directory is iRedAdmin
PWD="$(pwd)"
++ pwd
+ PWD=/root/iRedAdmin-1.1/tools
if ! echo ${PWD} | grep 'iRedAdmin-.*/tools' >/dev/null; then
    echo "<<< ERROR >>> Cannot find new version of iRedAdmin in current directory. Exit."
    exit 255
fi
+ grep 'iRedAdmin-.*/tools'
+ echo /root/iRedAdmin-1.1/tools

# Copy current directory to Apache server root
dir_new_version="$(dirname ${PWD})"
++ dirname /root/iRedAdmin-1.1/tools
+ dir_new_version=/root/iRedAdmin-1.1
name_new_version="$(basename ${dir_new_version})"
++ basename /root/iRedAdmin-1.1
+ name_new_version=iRedAdmin-1.1
NEW_IRA_ROOT_DIR="${HTTPD_SERVERROOT}/${name_new_version}"
+ NEW_IRA_ROOT_DIR=/usr/share/apache2/iRedAdmin-1.1
if [ -d ${NEW_IRA_ROOT_DIR} ]; then
    COPY_FILES="${dir_new_version}/*"
    COPY_DEST_DIR="${NEW_IRA_ROOT_DIR}"
    #echo "<<< ERROR >>> Directory exist: ${NEW_IRA_ROOT_DIR}. Exit."
    #exit 255
else
    COPY_FILES="${dir_new_version}"
    COPY_DEST_DIR="${HTTPD_SERVERROOT}"
fi
+ '[' -d /usr/share/apache2/iRedAdmin-1.1 ']'
+ COPY_FILES=/root/iRedAdmin-1.1
+ COPY_DEST_DIR=/usr/share/apache2

echo "* Copying new version to ${NEW_IRA_ROOT_DIR}"
+ echo '* Copying new version to /usr/share/apache2/iRedAdmin-1.1'
* Copying new version to /usr/share/apache2/iRedAdmin-1.1
cp -rf ${COPY_FILES} ${COPY_DEST_DIR}
+ cp -rf /root/iRedAdmin-1.1 /usr/share/apache2

# Copy old config files
echo "* Copy ${IRA_CONF_PY}."
+ echo '* Copy /usr/share/apache2/iredadmin/settings.py.'
* Copy /usr/share/apache2/iredadmin/settings.py.
cp -p ${IRA_CONF_PY} ${NEW_IRA_ROOT_DIR}/
+ cp -p /usr/share/apache2/iredadmin/settings.py /usr/share/apache2/iRedAdmin-1.1/

if [ -f ${IRA_CUSTOM_CONF_PY} ]; then
    echo "* Copy ${IRA_CUSTOM_CONF_PY}."
    cp -p ${IRA_CUSTOM_CONF_PY} ${NEW_IRA_ROOT_DIR}
fi
+ '[' -f /usr/share/apache2/iredadmin/custom_settings.py ']'

# Copy hooks.py. It's ok if missing.
if [ -f ${IRA_ROOT_DIR}/hooks.py ]; then
    echo "* Copy ${IRA_ROOT_DIR}/hooks.py."
    cp -p ${IRA_ROOT_DIR}/hooks.py ${NEW_IRA_ROOT_DIR}/ &>/dev/null
fi
+ '[' -f /usr/share/apache2/iredadmin/hooks.py ']'

# Copy custom files under 'tools/'. It's ok if missing.
cp -p ${IRA_ROOT_DIR}/tools/*.custom ${NEW_IRA_ROOT_DIR}/tools/ &>/dev/null
+ cp -p '/usr/share/apache2/iredadmin/tools/*.custom' /usr/share/apache2/iRedAdmin-1.1/tools/
cp -p ${IRA_ROOT_DIR}/tools/*.last-time ${NEW_IRA_ROOT_DIR}/tools/ &>/dev/null
+ cp -p '/usr/share/apache2/iredadmin/tools/*.last-time' /usr/share/apache2/iRedAdmin-1.1/tools/

# Template file renamed
if [ -f "${IRA_ROOT_DIR}/tools/notify_quarantined_recipients.custom.html" ]; then
    echo "* Copy ${IRA_ROOT_DIR}/tools/notify_quarantined_recipients.custom.html"
    cp -f ${IRA_ROOT_DIR}/tools/notify_quarantined_recipients.custom.html \
        ${NEW_IRA_ROOT_DIR}/tools/notify_quarantined_recipients.html.custom
fi
+ '[' -f /usr/share/apache2/iredadmin/tools/notify_quarantined_recipients.custom.html ']'

# Copy favicon.ico and brand logo image.
for var in 'BRAND_FAVICON' 'BRAND_LOGO'; do
    if grep "^${var}\>" ${IRA_CONF_PY} &>/dev/null; then
        _file=$(grep "^${var}\>" ${IRA_CONF_PY} | awk '{print $NF}' | tr -d '"' | tr -d "'")
        echo "* Copy file ${IRA_ROOT_DIR}/static/${_file}"
        cp -f ${IRA_ROOT_DIR}/static/${_file} ${NEW_IRA_ROOT_DIR}/static/
    fi
done
+ for var in 'BRAND_FAVICON' 'BRAND_LOGO'
+ grep '^BRAND_FAVICON\>' /usr/share/apache2/iredadmin/settings.py
+ for var in 'BRAND_FAVICON' 'BRAND_LOGO'
+ grep '^BRAND_LOGO\>' /usr/share/apache2/iredadmin/settings.py

# iredadmin is now ran as a standalone uwsgi instance, we don't need uwsgi
# daemon service anymore.
_uwsgi_confs='
    /etc/uwsgi.d/iredadmin.ini
    /etc/uwsgi-available/iredadmin.ini
    /etc/uwsgi/apps-enabled/iredadmin.ini &>/dev/null
    /etc/uwsgi/apps-available/iredadmin.ini &>/dev/null
    /usr/local/etc/uwsgi/iredadmin.ini
    /etc/uwsgi-enabled/iredadmin.ini &>/dev/null
    /etc/uwsgi-available/iredadmin.ini &>/dev/null
'
+ _uwsgi_confs='
    /etc/uwsgi.d/iredadmin.ini
    /etc/uwsgi-available/iredadmin.ini
    /etc/uwsgi/apps-enabled/iredadmin.ini &>/dev/null
    /etc/uwsgi/apps-available/iredadmin.ini &>/dev/null
    /usr/local/etc/uwsgi/iredadmin.ini
    /etc/uwsgi-enabled/iredadmin.ini &>/dev/null
    /etc/uwsgi-available/iredadmin.ini &>/dev/null
'

for f in ${_uwsgi_confs}; do
    rm -f ${f} &>/dev/null
done
+ for f in ${_uwsgi_confs}
+ rm -f /etc/uwsgi.d/iredadmin.ini
+ for f in ${_uwsgi_confs}
+ rm -f /etc/uwsgi-available/iredadmin.ini
+ for f in ${_uwsgi_confs}
+ rm -f /etc/uwsgi/apps-enabled/iredadmin.ini
+ for f in ${_uwsgi_confs}
+ rm -f '&>/dev/null'
+ for f in ${_uwsgi_confs}
+ rm -f /etc/uwsgi/apps-available/iredadmin.ini
+ for f in ${_uwsgi_confs}
+ rm -f '&>/dev/null'
+ for f in ${_uwsgi_confs}
+ rm -f /usr/local/etc/uwsgi/iredadmin.ini
+ for f in ${_uwsgi_confs}
+ rm -f /etc/uwsgi-enabled/iredadmin.ini
+ for f in ${_uwsgi_confs}
+ rm -f '&>/dev/null'
+ for f in ${_uwsgi_confs}
+ rm -f /etc/uwsgi-available/iredadmin.ini
+ for f in ${_uwsgi_confs}
+ rm -f '&>/dev/null'

# Remove 'uwsgi_XXX' from /etc/rc.conf on FreeBSD.
if [[ X"${DISTRO}" == X'FREEBSD' ]]; then
    ${SYSRC} -x uwsgi_enable &>/dev/null
    ${SYSRC} -x uwsgi_profiles &>/dev/null
    ${SYSRC} -x uwsgi_iredadmin_flags &>/dev/null
fi
+ [[ XUBUNTU == X\F\R\E\E\B\S\D ]]

# Update Nginx template file
export _restart_nginx='NO'
+ export _restart_nginx=NO
+ _restart_nginx=NO
for f in ${NGINX_SNIPPET_CONF} ${NGINX_SNIPPET_CONF2} ${NGINX_SNIPPET_CONF3}; do
    if [[ -f ${f} ]]; then
        if grep 'unix:.*iredadmin.socket' ${f} &>/dev/null; then
            export _restart_nginx='YES'
            perl -pi -e 's#uwsgi_pass unix:.*iredadmin.socket;#uwsgi_pass 127.0.0.1:7791;#g' ${f}
        fi
    fi
done
+ for f in ${NGINX_SNIPPET_CONF} ${NGINX_SNIPPET_CONF2} ${NGINX_SNIPPET_CONF3}
+ [[ -f /etc/nginx/templates/iredadmin.tmpl ]]
+ for f in ${NGINX_SNIPPET_CONF} ${NGINX_SNIPPET_CONF2} ${NGINX_SNIPPET_CONF3}
+ [[ -f /etc/nginx/templates/iredadmin-subdomain.tmpl ]]
+ for f in ${NGINX_SNIPPET_CONF} ${NGINX_SNIPPET_CONF2} ${NGINX_SNIPPET_CONF3}
+ [[ -f /etc/nginx/conf.d/default.conf ]]

if [[ X"${_restart_nginx}" == X'YES' ]]; then
    restart_service nginx
fi
+ [[ XNO == X\Y\E\S ]]

# Update uwsgi ini config file
if [ -d ${NEW_IRA_ROOT_DIR}/rc_scripts/uwsgi ]; then
    perl -pi -e 's#^chdir = (.*)#chdir = $ENV{HTTPD_SERVERROOT}/iredadmin#g' ${NEW_IRA_ROOT_DIR}/rc_scripts/uwsgi/*.ini
fi
+ '[' -d /usr/share/apache2/iRedAdmin-1.1/rc_scripts/uwsgi ']'
+ perl -pi -e 's#^chdir = (.*)#chdir = $ENV{HTTPD_SERVERROOT}/iredadmin#g' /usr/share/apache2/iRedAdmin-1.1/rc_scripts/uwsgi/debian.ini /usr/share/apache2/iRedAdmin-1.1/rc_scripts/uwsgi/freebsd.ini /usr/share/apache2/iRedAdmin-1.1/rc_scripts/uwsgi/openbsd.ini /usr/share/apache2/iRedAdmin-1.1/rc_scripts/uwsgi/rhel7.ini /usr/share/apache2/iRedAdmin-1.1/rc_scripts/uwsgi/rhel8.ini

# Copy rc script or systemd service file
if [ X"${USE_SYSTEMD}" == X'YES' ]; then
    echo "* Remove existing systemd service files."
    rm -f ${SYSTEMD_SERVICE_DIR}/iredadmin.service &>/dev/null
    rm -f ${SYSTEMD_SERVICE_DIR2}/iredadmin.service &>/dev/null
    rm -f ${SYSTEMD_SERVICE_USER_DIR}/iredadmin.service &>/dev/null

    echo "* Copy systemd service file: ${SYSTEMD_SERVICE_DIR}/iredadmin.service."
    if [ X"${DISTRO}" == X'RHEL' ]; then
        cp -f ${NEW_IRA_ROOT_DIR}/rc_scripts/systemd/rhel${DISTRO_VERSION}.service ${SYSTEMD_SERVICE_DIR}/iredadmin.service
        perl -pi -e 's#/opt/www#$ENV{HTTPD_SERVERROOT}#g' ${SYSTEMD_SERVICE_DIR}/iredadmin.service
    elif [ X"${DISTRO}" == X'DEBIAN' -o X"${DISTRO}" == X'UBUNTU' ]; then
        cp -f ${NEW_IRA_ROOT_DIR}/rc_scripts/systemd/debian.service ${SYSTEMD_SERVICE_DIR}/iredadmin.service
        perl -pi -e 's#/opt/www#$ENV{HTTPD_SERVERROOT}#g' ${SYSTEMD_SERVICE_DIR}/iredadmin.service
    fi

    chmod -R 0644 ${SYSTEMD_SERVICE_DIR}/iredadmin.service
    systemctl daemon-reload &>/dev/null
else
    if [ X"${DISTRO}" == X"FREEBSD" ]; then
        cp ${NEW_IRA_ROOT_DIR}/rc_scripts/iredadmin.freebsd /usr/local/etc/rc.d/iredadmin
        perl -pi -e 's#/opt/www#$ENV{HTTPD_SERVERROOT}#g' /usr/local/etc/rc.d/iredadmin

        # Remove 'uwsgi_iredadmin_flags=' in /etc/rc.conf.local
        if [ -f /etc/rc.conf.local ]; then
            perl -pi -e 's#^uwsgi_iredadminflags=.*##g' /etc/rc.conf.local
        fi
    elif [ X"${DISTRO}" == X'OPENBSD' ]; then
        cp ${NEW_IRA_ROOT_DIR}/rc_scripts/iredadmin.openbsd ${DIR_RC_SCRIPTS}/iredadmin
        perl -pi -e 's#/opt/www#$ENV{HTTPD_SERVERROOT}#g' /etc/rc.d/iredadmin

        cp -f ${NEW_IRA_ROOT_DIR}/rc_scripts/iredadmin.openbsd /etc/rc.d/iredadmin
        chmod 0755 /etc/rc.d/iredadmin

        # Remove 'uwsgi_flags=' in /etc/rc.conf.local
        if [ -f /etc/rc.conf.local ]; then
            perl -pi -e 's#^uwsgi_flags=.*iredadmin.*##g' /etc/rc.conf.local
        fi
    fi
fi
+ '[' XYES == XYES ']'
+ echo '* Remove existing systemd service files.'
* Remove existing systemd service files.
+ rm -f /lib/systemd/system/iredadmin.service
+ rm -f /etc/systemd/system/iredadmin.service
+ rm -f /etc/systemd/system/multi-user.target.wants//iredadmin.service
+ echo '* Copy systemd service file: /lib/systemd/system/iredadmin.service.'
* Copy systemd service file: /lib/systemd/system/iredadmin.service.
+ '[' XUBUNTU == XRHEL ']'
+ '[' XUBUNTU == XDEBIAN -o XUBUNTU == XUBUNTU ']'
+ cp -f /usr/share/apache2/iRedAdmin-1.1/rc_scripts/systemd/debian.service /lib/systemd/system/iredadmin.service
+ perl -pi -e 's#/opt/www#$ENV{HTTPD_SERVERROOT}#g' /lib/systemd/system/iredadmin.service
+ chmod -R 0644 /lib/systemd/system/iredadmin.service
+ systemctl daemon-reload

# Set owner and permission.
chown -R ${IRA_HTTPD_USER}:${IRA_HTTPD_GROUP} ${NEW_IRA_ROOT_DIR}
+ chown -R iredadmin:iredadmin /usr/share/apache2/iRedAdmin-1.1
chmod -R 0555 ${NEW_IRA_ROOT_DIR}
+ chmod -R 0555 /usr/share/apache2/iRedAdmin-1.1
chmod 0400 ${NEW_IRA_ROOT_DIR}/settings.py
+ chmod 0400 /usr/share/apache2/iRedAdmin-1.1/settings.py

echo "* Removing old symbol link ${IRA_ROOT_DIR}"
+ echo '* Removing old symbol link /usr/share/apache2/iredadmin'
* Removing old symbol link /usr/share/apache2/iredadmin
rm -f ${IRA_ROOT_DIR}
+ rm -f /usr/share/apache2/iredadmin

echo "* Creating symbol link ${IRA_ROOT_DIR} to ${NEW_IRA_ROOT_DIR}"
+ echo '* Creating symbol link /usr/share/apache2/iredadmin to /usr/share/apache2/iRedAdmin-1.1'
* Creating symbol link /usr/share/apache2/iredadmin to /usr/share/apache2/iRedAdmin-1.1
cd ${HTTPD_SERVERROOT}
+ cd /usr/share/apache2
ln -s ${name_new_version} iredadmin
+ ln -s iRedAdmin-1.1 iredadmin

# Add missing setting parameters.
if grep 'amavisd_enable_logging.*True.*' ${IRA_CONF_PY} &>/dev/null; then
    add_missing_parameter 'amavisd_enable_policy_lookup' True 'Enable per-recipient spam policy, white/blacklist.'
else
    add_missing_parameter 'amavisd_enable_policy_lookup' False 'Enable per-recipient spam policy, white/blacklist.'
fi
+ grep 'amavisd_enable_logging.*True.*' /usr/share/apache2/iredadmin/settings.py
+ add_missing_parameter amavisd_enable_policy_lookup True 'Enable per-recipient spam policy, white/blacklist.'
+ var=amavisd_enable_policy_lookup
+ value=True
+ shift 2
+ comment='Enable per-recipient spam policy, white/blacklist.'
+ grep '^amavisd_enable_policy_lookup' /usr/share/apache2/iredadmin/settings.py

if ! grep '^iredapd_' ${IRA_CONF_PY} &>/dev/null; then
    add_missing_parameter 'iredapd_enabled' True 'Enable iRedAPD integration.'

    # Get iredapd db password from /opt/iredapd/settings.py.
    if [ -f /opt/iredapd/settings.py ]; then
        grep '^iredapd_db_' /opt/iredapd/settings.py >> ${IRA_CONF_PY}
        perl -pi -e 's#iredapd_db_server#iredapd_db_host#g' ${IRA_CONF_PY}
    else
        # Check backend.
        if egrep '^backend.*pgsql' ${IRA_CONF_PY} &>/dev/null; then
            export IREDAPD_DB_PORT='5432'
        else
            export IREDAPD_DB_PORT='3306'
        fi

        add_missing_parameter 'iredapd_db_host' '127.0.0.1'
        add_missing_parameter 'iredapd_db_port' ${IREDAPD_DB_PORT}
        add_missing_parameter 'iredapd_db_name' 'iredapd'
        add_missing_parameter 'iredapd_db_user' 'iredapd'
        add_missing_parameter 'iredapd_db_password' 'password'
    fi
fi
+ grep '^iredapd_' /usr/share/apache2/iredadmin/settings.py
perl -pi -e 's#iredapd_db_server#iredapd_db_host#g' ${IRA_CONF_PY}
+ perl -pi -e s#iredapd_db_server#iredapd_db_host#g /usr/share/apache2/iredadmin/settings.py

if ! grep '^fail2ban_' ${IRA_CONF_PY} &>/dev/null; then
    # Try to get password of SQL user `fail2ban`.
    if egrep '^backend.*(mysql|ldap)' ${IRA_CONF_PY} &>/dev/null; then
        _my_cnf='/root/.my.cnf-fail2ban'
        if [ -f ${_my_cnf} ]; then
            _host="$(grep '^host=' ${_my_cnf} | awk -F'host=' '{print $2}' | strip_quotes)"
            _port="$(grep '^port=' ${_my_cnf} | awk -F'port=' '{print $2}' | strip_quotes)"
            _user="$(grep '^user=' ${_my_cnf} | awk -F'user=' '{print $2}' | strip_quotes)"
            _password="$(grep '^password=' ${_my_cnf} | awk -F'password=' '{print $2}' | strip_quotes)"

            [ X"${_host}" == X'' ] && _host='127.0.0.1'
            [ X"${_port}" == X'' ] && _port='3306'
        fi
    elif egrep '^backend.*pgsql' ${IRA_CONF_PY} &>/dev/null; then
        # Absolute path to ~/.pgpass
        #   - RHEL:             /var/lib/pgsql/.pgpass
        #   - Debian/Ubuntu:    /var/lib/postgresql/.pgpass
        #   - FreeBSD:          /var/db/postgres/.pgpass
        #   - OpenBSD:          /var/postgresql/.pgpass
        for dir in \
            /var/lib/pgsql \
            /var/lib/postgresql \
            /var/db/postgres \
            /var/postgresql; do
            _pgpass="${dir}/.pgpass"
            if [ -f ${_pgpass} ]; then
                if grep ':fail2ban:' ${_pgpass} &>/dev/null; then
                    _host="127.0.0.1"
                    _port="5432"
                    _user="fail2ban"
                    _password="$(grep ':fail2ban:' ${_pgpass} | awk -F':' '{print $NF}')"
                    break
                fi
            fi
        done
    fi

    if [ X"${_host}" != X'' ] && \
        [ X"${_port}" != X'' ] && \
        [ X"${_user}" != X'' ] && \
        [ X"${_password}" != X'' ]; then
        echo "* Enable Fail2ban SQL integration."
        add_missing_parameter 'fail2ban_enabled' 'True'
        add_missing_parameter 'fail2ban_db_host' "${_host}"
        add_missing_parameter 'fail2ban_db_port' "${_port}"
        add_missing_parameter 'fail2ban_db_name' "fail2ban"
        add_missing_parameter 'fail2ban_db_user' "${_user}"
        add_missing_parameter 'fail2ban_db_password' "${_password}"
    fi
fi
+ grep '^fail2ban_' /usr/share/apache2/iredadmin/settings.py
+ egrep '^backend.*(mysql|ldap)' /usr/share/apache2/iredadmin/settings.py
+ _my_cnf=/root/.my.cnf-fail2ban
+ '[' -f /root/.my.cnf-fail2ban ']'
+ '[' X '!=' X ']'

# FreeBSD uses /var/run/log for syslog.
if [ X"${DISTRO}" == X'FREEBSD' ]; then
    add_missing_parameter 'SYSLOG_SERVER' '/var/run/log'
fi
+ '[' XUBUNTU == XFREEBSD ']'

#
# Enable mlmmj integration
#
if [ -e /opt/mlmmjadmin ]; then
    echo "* Enable mlmmj integration."
    # Force to use backend `bk_none`.
    perl -pi -e 's#^(backend_api).*#${1} = "bk_none"#g' /opt/mlmmjadmin/settings.py

    if egrep '^backend.*(ldap)' ${IRA_CONF_PY} &>/dev/null; then
        perl -pi -e 's#^(backend_cli).*#${1} = "bk_iredmail_ldap"#g' /opt/mlmmjadmin/settings.py
    else
        perl -pi -e 's#^(backend_cli).*#${1} = "bk_iredmail_sql"#g' /opt/mlmmjadmin/settings.py
    fi

    # Add parameter `mlmmjadmin_api_auth_token` if missing
    if ! grep '^mlmmjadmin_api_auth_token' ${IRA_CONF_PY} >/dev/null; then
        # Get first api auth token
        token=$(grep '^api_auth_tokens' /opt/mlmmjadmin/settings.py | awk -F"[=\']" '{print $3}' | tr -d '\n')
        echo -e "\nmlmmjadmin_api_auth_token = '${token}'" >> ${IRA_CONF_PY}
    fi

    echo "* Restarting service: mlmmjadmin."
    restart_service mlmmjadmin
fi
+ '[' -e /opt/mlmmjadmin ']'
+ echo '* Enable mlmmj integration.'
* Enable mlmmj integration.
+ perl -pi -e 's#^(backend_api).*#${1} = "bk_none"#g' /opt/mlmmjadmin/settings.py
+ egrep '^backend.*(ldap)' /usr/share/apache2/iredadmin/settings.py
+ perl -pi -e 's#^(backend_cli).*#${1} = "bk_iredmail_sql"#g' /opt/mlmmjadmin/settings.py
+ grep '^mlmmjadmin_api_auth_token' /usr/share/apache2/iredadmin/settings.py
+ echo '* Restarting service: mlmmjadmin.'
* Restarting service: mlmmjadmin.
+ restart_service mlmmjadmin
+ srv=mlmmjadmin
+ '[' XLINUX == XLINUX ']'
+ '[' XYES == XYES ']'
+ systemctl restart mlmmjadmin
+ '[' X0 '!=' X0 ']'

# Change old parameter names to the new ones:
#
#   - ADDITION_USER_SERVICES -> ADDITIONAL_ENABLED_USER_SERVICES
#   - LDAP_SERVER_NAME -> LDAP_SERVER_PRODUCT_NAME
perl -pi -e 's#ADDITION_USER_SERVICES#ADDITIONAL_ENABLED_USER_SERVICES#g' ${IRA_CONF_PY}
+ perl -pi -e s#ADDITION_USER_SERVICES#ADDITIONAL_ENABLED_USER_SERVICES#g /usr/share/apache2/iredadmin/settings.py
perl -pi -e 's#LDAP_SERVER_NAME#LDAP_SERVER_PRODUCT_NAME#g' ${IRA_CONF_PY}
+ perl -pi -e s#LDAP_SERVER_NAME#LDAP_SERVER_PRODUCT_NAME#g /usr/share/apache2/iredadmin/settings.py

# Remove deprecated setting: ENABLE_SELF_SERVICE, it's now a per-domain setting.
perl -pi -e 's#^(ENABLE_SELF_SERVICE.*)##g' ${IRA_CONF_PY}
+ perl -pi -e 's#^(ENABLE_SELF_SERVICE.*)##g' /usr/share/apache2/iredadmin/settings.py


# Dependent packages.
export REQUIRED_PKGS=""
+ export REQUIRED_PKGS=
+ REQUIRED_PKGS=
export PIP3_MODS=""
+ export PIP3_MODS=
+ PIP3_MODS=
# Python modules.
export PKG_PY_PIP='python3-pip'
+ export PKG_PY_PIP=python3-pip
+ PKG_PY_PIP=python3-pip
export PKG_PY_LDAP='python3-ldap'
+ export PKG_PY_LDAP=python3-ldap
+ PKG_PY_LDAP=python3-ldap
export PKG_PY_MYSQL='python3-pymysql'
+ export PKG_PY_MYSQL=python3-pymysql
+ PKG_PY_MYSQL=python3-pymysql
export PKG_PY_PGSQL='python3-psycopg2'
+ export PKG_PY_PGSQL=python3-psycopg2
+ PKG_PY_PGSQL=python3-psycopg2
export PKG_PY_JSON='python3-simplejson'
+ export PKG_PY_JSON=python3-simplejson
+ PKG_PY_JSON=python3-simplejson
export PKG_PY_DNS='python3-dnspython'
+ export PKG_PY_DNS=python3-dnspython
+ PKG_PY_DNS=python3-dnspython
export PKG_PY_REQUESTS='python3-requests'
+ export PKG_PY_REQUESTS=python3-requests
+ PKG_PY_REQUESTS=python3-requests
export PKG_PY_JINJA='python3-jinja2'
+ export PKG_PY_JINJA=python3-jinja2
+ PKG_PY_JINJA=python3-jinja2
# Python modules installed with pip3: uwsgi.

if [ X"${DISTRO}" == X'RHEL' ]; then
    if [ X"${DISTRO_VERSION}" == X'7' ]; then
        export PKG_PY_MYSQL='python36-PyMySQL'
        export PKG_PY_JSON='python36-simplejson'
        export PKG_PY_JINJA='python36-jinja2'
        export REQUIRED_PKGS="${REQUIRED_PKGS} uwsgi uwsgi-plugin-python36 uwsgi-plugin-syslog"
    else
        if [ ! -x ${CMD_UWSGI} ]; then
            export REQUIRED_PKGS="${REQUIRED_PKGS} python3-devel python3-pip"
            export PIP3_MODS="${PIP3_MODS} uwsgi"
        fi
    fi

    export PKG_PY_DNS='python3-dns'
elif [ X"${DISTRO}" == X'DEBIAN' -o X"${DISTRO}" == X'UBUNTU' ]; then
    export REQUIRED_PKGS="${REQUIRED_PKGS} uwsgi-core uwsgi-plugin-python3"

    if [ X"${DISTRO_VERSION}" == X'9' ]; then
        export PKG_PY_LDAP='python3-pyldap'
    else
        export PKG_PY_LDAP='python3-ldap'
    fi
elif [ X"${DISTRO}" == X'OPENBSD' ]; then
    export PKG_PY_PIP='py3-pip'
    export PKG_PY_JSON='py3-simplejson'
    export PKG_PY_DNS='py3-dnspython'
    export PKG_PY_REQUESTS='py3-requests'
    export PKG_PY_JINJA='py3-jinja2'

    if [ ! -x ${CMD_UWSGI} ]; then
        export PIP3_MODS="${PIP3_MODS} uwsgi"
    fi
elif [ X"${DISTRO}" == X'FREEBSD' ]; then
    export PKG_PY_PIP='devel/py-pip'
    export PKG_UWSGI="www/uwsgi"
    export PKG_PY_JSON='devel/py-simplejson'
    export PKG_PY_DNS='dns/py-dnspython'
    export PKG_PY_REQUESTS='www/py-requests'
    export PKG_PY_JINJA='devel/py-Jinja2'

    if [ ! -x ${CMD_UWSGI} ]; then
        export REQUIRED_PKGS="${REQUIRED_PKGS} ${PKG_UWSGI}"
    fi
fi
+ '[' XUBUNTU == XRHEL ']'
+ '[' XUBUNTU == XDEBIAN -o XUBUNTU == XUBUNTU ']'
+ export 'REQUIRED_PKGS= uwsgi-core uwsgi-plugin-python3'
+ REQUIRED_PKGS=' uwsgi-core uwsgi-plugin-python3'
+ '[' X18.04 == X9 ']'
+ export PKG_PY_LDAP=python3-ldap
+ PKG_PY_LDAP=python3-ldap

echo "* Check and install required packages."
+ echo '* Check and install required packages.'
* Check and install required packages.
if egrep '^backend.*ldap' ${IRA_CONF_PY} &>/dev/null; then
    [ X"$(has_python_module ldap)" == X'NO' ] && REQUIRED_PKGS="${REQUIRED_PKGS} ${PKG_PY_LDAP}"
    [ X"$(has_python_module pymysql)" == X'NO' ] && REQUIRED_PKGS="${REQUIRED_PKGS} ${PKG_PY_MYSQL}"
elif egrep '^backend.*mysql' ${IRA_CONF_PY} &>/dev/null; then
    [ X"$(has_python_module pymysql)" == X'NO' ] && REQUIRED_PKGS="${REQUIRED_PKGS} ${PKG_PY_MYSQL}"
elif egrep '^backend.*pgsql' ${IRA_CONF_PY} &>/dev/null; then
    [ X"$(has_python_module psycopg2)" == X'NO' ] && REQUIRED_PKGS="${REQUIRED_PKGS} ${PKG_PY_PGSQL}"
fi
+ egrep '^backend.*ldap' /usr/share/apache2/iredadmin/settings.py
+ egrep '^backend.*mysql' /usr/share/apache2/iredadmin/settings.py
++ has_python_module pymysql
++ mod=pymysql
++ /usr/bin/python3 -c 'import pymysql'
++ '[' X0 == X0 ']'
++ echo YES
+ '[' XYES == XNO ']'
[ X"$(has_python_module pip)" == X'NO' ] && REQUIRED_PKGS="${REQUIRED_PKGS} ${PKG_PY_PIP}"
++ has_python_module pip
++ mod=pip
++ /usr/bin/python3 -c 'import pip'
++ '[' X0 == X0 ']'
++ echo YES
+ '[' XYES == XNO ']'
[ X"$(has_python_module simplejson)" == X'NO' ] && REQUIRED_PKGS="${REQUIRED_PKGS} ${PKG_PY_JSON}"
++ has_python_module simplejson
++ mod=simplejson
++ /usr/bin/python3 -c 'import simplejson'
++ '[' X0 == X0 ']'
++ echo YES
+ '[' XYES == XNO ']'
[ X"$(has_python_module dns)" == X'NO' ] && REQUIRED_PKGS="${REQUIRED_PKGS} ${PKG_PY_DNS}"
++ has_python_module dns
++ mod=dns
++ /usr/bin/python3 -c 'import dns'
++ '[' X0 == X0 ']'
++ echo YES
+ '[' XYES == XNO ']'
[ X"$(has_python_module requests)" == X'NO' ] && REQUIRED_PKGS="${REQUIRED_PKGS} ${PKG_PY_REQUESTS}"
++ has_python_module requests
++ mod=requests
++ /usr/bin/python3 -c 'import requests'
++ '[' X0 == X0 ']'
++ echo YES
+ '[' XYES == XNO ']'
if [ X"$(has_python_module web)" == X'NO' ]; then
    PIP3_MODS="${PIP3_MODS} web.py>=0.61"
else # Verify module version.
    _webpy_ver=$(${CMD_PYTHON3} -c "import web; print(web.__version__)")
    if echo ${_webpy_ver} | grep '^0\.[45]' &>/dev/null; then
        PIP3_MODS="${PIP3_MODS} web.py>=0.61"
    fi
fi
++ has_python_module web
++ mod=web
++ /usr/bin/python3 -c 'import web'
++ '[' X0 == X0 ']'
++ echo YES
+ '[' XYES == XNO ']'
++ /usr/bin/python3 -c 'import web; print(web.__version__)'
+ _webpy_ver=0.51
+ grep '^0\.[45]'
+ echo 0.51
+ PIP3_MODS=' web.py>=0.61'
[ X"$(has_python_module jinja2)" == X'NO' ] && REQUIRED_PKGS="${REQUIRED_PKGS} ${PKG_PY_JINJA}"
++ has_python_module jinja2
++ mod=jinja2
++ /usr/bin/python3 -c 'import jinja2'
++ '[' X0 == X0 ']'
++ echo YES
+ '[' XYES == XNO ']'

if [ X"${REQUIRED_PKGS}" != X'' ]; then
    install_pkg ${REQUIRED_PKGS}
    if [ X"$?" != X'0' ]; then
        echo "Package installation failed, please check console output and fix it manually."
        exist 255
    fi
fi
+ '[' 'X uwsgi-core uwsgi-plugin-python3' '!=' X ']'
+ install_pkg uwsgi-core uwsgi-plugin-python3
+ echo 'Install package(s): uwsgi-core' uwsgi-plugin-python3
Install package(s): uwsgi-core uwsgi-plugin-python3
+ '[' XUBUNTU == XRHEL ']'
+ '[' XUBUNTU == XDEBIAN -o XUBUNTU == XUBUNTU ']'
+ apt-get install -y uwsgi-core uwsgi-plugin-python3
Reading package lists... Done
Building dependency tree       
Reading state information... Done
uwsgi-core is already the newest version (2.0.15-10.2ubuntu2.1).
uwsgi-plugin-python3 is already the newest version (2.0.15-10.2ubuntu2.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
+ '[' X0 '!=' X0 ']'

if [ X"${PIP3_MODS}" != X'' ]; then
    ${CMD_PIP3} install -U ${PIP3_MODS}
    if [ X"$?" != X'0' ]; then
        echo "Package installation failed, please check console output and fix it manually."
        exist 255
    fi
fi
+ '[' 'X web.py>=0.61' '!=' X ']'
+ /usr/bin/pip3 install -U 'web.py>=0.61'
The directory '/home/USERNAME/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/USERNAME/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting web.py>=0.61
Requirement already up-to-date: cheroot in /usr/local/lib/python3.6/dist-packages (from web.py>=0.61)
Requirement already up-to-date: more-itertools>=2.6 in /usr/local/lib/python3.6/dist-packages (from cheroot->web.py>=0.61)
Requirement already up-to-date: jaraco.functools in /usr/local/lib/python3.6/dist-packages (from cheroot->web.py>=0.61)
Requirement already up-to-date: six>=1.11.0 in /usr/local/lib/python3.6/dist-packages (from cheroot->web.py>=0.61)
Installing collected packages: web.py
  Found existing installation: web.py 0.51
    Uninstalling web.py-0.51:
      Successfully uninstalled web.py-0.51
Successfully installed web.py-0.62
+ '[' X0 '!=' X0 ']'

#------------------------------------------
# Add new SQL tables, drop deprecated ones.
#
export ira_db_host="$(get_iredadmin_setting 'iredadmin_db_host')"
++ get_iredadmin_setting iredadmin_db_host
++ var=iredadmin_db_host
+++ strip_quotes
+++ awk '{print $NF}'
+++ grep '^iredadmin_db_host' /usr/share/apache2/iredadmin/settings.py
++++ cat
+++ str='"127.0.0.1"'
++++ tr -d \'
++++ tr -d '"'
++++ echo '"127.0.0.1"'
+++ value=127.0.0.1
+++ echo 127.0.0.1
++ value=127.0.0.1
++ echo 127.0.0.1
+ export ira_db_host=127.0.0.1
+ ira_db_host=127.0.0.1
export ira_db_port="$(get_iredadmin_setting 'iredadmin_db_port')"
++ get_iredadmin_setting iredadmin_db_port
++ var=iredadmin_db_port
+++ strip_quotes
+++ awk '{print $NF}'
+++ grep '^iredadmin_db_port' /usr/share/apache2/iredadmin/settings.py
++++ cat
+++ str=3306
++++ tr -d \'
++++ tr -d '"'
++++ echo 3306
+++ value=3306
+++ echo 3306
++ value=3306
++ echo 3306
+ export ira_db_port=3306
+ ira_db_port=3306
export ira_db_name="$(get_iredadmin_setting 'iredadmin_db_name')"
++ get_iredadmin_setting iredadmin_db_name
++ var=iredadmin_db_name
+++ strip_quotes
+++ awk '{print $NF}'
+++ grep '^iredadmin_db_name' /usr/share/apache2/iredadmin/settings.py
++++ cat
+++ str='"iredadmin"'
++++ tr -d \'
++++ tr -d '"'
++++ echo '"iredadmin"'
+++ value=iredadmin
+++ echo iredadmin
++ value=iredadmin
++ echo iredadmin
+ export ira_db_name=iredadmin
+ ira_db_name=iredadmin
export ira_db_user="$(get_iredadmin_setting 'iredadmin_db_user')"
++ get_iredadmin_setting iredadmin_db_user
++ var=iredadmin_db_user
+++ strip_quotes
+++ awk '{print $NF}'
+++ grep '^iredadmin_db_user' /usr/share/apache2/iredadmin/settings.py
++++ cat
+++ str='"iredadmin"'
++++ tr -d \'
++++ tr -d '"'
++++ echo '"iredadmin"'
+++ value=iredadmin
+++ echo iredadmin
++ value=iredadmin
++ echo iredadmin
+ export ira_db_user=iredadmin
+ ira_db_user=iredadmin
export ira_db_password="$(get_iredadmin_setting 'iredadmin_db_password')"
---------lines removed for security

#
# Update sql tables
#
psql_conn="psql -h ${ira_db_host} \
                -p ${ira_db_port} \
                -U ${ira_db_user} \
                -d ${ira_db_name}"
+ psql_conn='psql -h 127.0.0.1                 -p 3306                 -U iredadmin                 -d iredadmin'

if egrep '^backend.*(mysql|ldap)' ${IRA_CONF_PY} &>/dev/null; then
    echo "* Check SQL tables, and add missed ones - if there's any"
    ${CMD_MYSQL} ${ira_db_name} -e "SOURCE ${IRA_ROOT_DIR}/SQL/iredadmin.mysql"
    ${CMD_MYSQL} ${ira_db_name} -e "ALTER TABLE log MODIFY COLUMN msg TEXT;"

    # Add column `tracking.id`.
    ${CMD_MYSQL} ${ira_db_name} -e "DESC tracking \G" | grep 'Field: id' &>/dev/null
    if [ X"$?" != X'0' ]; then
        ${CMD_MYSQL} ${ira_db_name} -e "ALTER TABLE tracking ADD COLUMN id BIGINT(20) UNSIGNED AUTO_INCREMENT PRIMARY KEY;"
    fi

    # Set column `id` to `PRIMARY KEY`
    _tables='deleted_mailboxes updatelog log tracking'
    for _table in ${_tables}; do
        ${CMD_MYSQL} ${ira_db_name} -e "DESC ${_table}" | grep '^id.*PRI.*auto_increment' &>/dev/null

        if [ X"$?" != X'0' ]; then
            ${CMD_MYSQL} ${ira_db_name} -e "ALTER TABLE ${_table} ADD PRIMARY KEY (id)"
        fi
    done

elif egrep '^backend.*pgsql' ${IRA_CONF_PY} &>/dev/null; then
    export PGPASSWORD="${ira_db_password}"

    # Allow log.msg to store long text.
    ${psql_conn} <<EOF
ALTER TABLE log ALTER COLUMN msg TYPE TEXT;
EOF

    # SQL table: tracking.
    ${psql_conn} -c '\d' | grep '\<tracking\>' &>/dev/null
    if [ X"$?" != X'0' ]; then
        echo "* [SQL] Add new table: iredadmin.tracking."

        ${psql_conn} <<EOF
CREATE TABLE tracking (
    id SERIAL PRIMARY KEY,
    k VARCHAR(50) NOT NULL,
    v TEXT,
    time TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE UNIQUE INDEX idx_tracking_k ON tracking (k);
EOF
    fi

    # Set column `tracking.id` to `PRIMARY KEY`

    # SQL table: domain_ownership.
    ${psql_conn} -c '\d' | grep '\<domain_ownership\>' &>/dev/null
    if [ X"$?" != X'0' ]; then
        echo "* [SQL] Add new table: iredadmin.domain_ownership."

        ${psql_conn} <<EOF
CREATE TABLE domain_ownership (
    id SERIAL PRIMARY KEY,
    admin VARCHAR(255) NOT NULL DEFAULT '',
    domain VARCHAR(255) NOT NULL DEFAULT '',
    alias_domain VARCHAR(255) NOT NULL DEFAULT '',
    verify_code VARCHAR(100) NOT NULL DEFAULT '',
    verified INT2 NOT NULL DEFAULT 0,
    message TEXT,
    last_verify TIMESTAMP NULL DEFAULT NULL,
    expire INT DEFAULT 0
);
CREATE UNIQUE INDEX idx_ownership_1 ON domain_ownership (admin, domain, alias_domain);
CREATE INDEX idx_ownership_2 ON domain_ownership (verified);
EOF
    fi

    # SQL table: newsletter_subunsub_confirms.
    ${psql_conn} -c '\d' | grep '\<newsletter_subunsub_confirms\>' &>/dev/null
    if [ X"$?" != X'0' ]; then
        echo "* [SQL] Add new table: iredadmin.newsletter_subunsub_confirms."

        _sql="$(cat ${IRA_ROOT_DIR}/SQL/snippets/newsletter_subunsub_confirms.pgsql)"
        ${psql_conn} <<EOF
${_sql}
EOF
        unset _sql
    fi

    # SQL table: settings.
    ${psql_conn} -c '\d' | grep '\<settings\>' &>/dev/null
    if [ X"$?" != X'0' ]; then
        echo "* [SQL] Add new table: iredadmin.settings."

        _sql="$(cat ${IRA_ROOT_DIR}/SQL/snippets/settings.pgsql)"
        ${psql_conn} <<EOF
${_sql}
EOF
        unset _sql
    fi
fi
+ egrep '^backend.*(mysql|ldap)' /usr/share/apache2/iredadmin/settings.py
+ echo '* Check SQL tables, and add missed ones - if there'\''s any'
* Check SQL tables, and add missed ones - if there's any
+ mysql --defaults-file=/root/.my.cnf -u root iredadmin -e 'SOURCE /usr/share/apache2/iredadmin/SQL/iredadmin.mysql'
+ mysql --defaults-file=/root/.my.cnf -u root iredadmin -e 'ALTER TABLE log MODIFY COLUMN msg TEXT;'
+ grep 'Field: id'
+ mysql --defaults-file=/root/.my.cnf -u root iredadmin -e 'DESC tracking \G'
+ '[' X0 '!=' X0 ']'
+ _tables='deleted_mailboxes updatelog log tracking'
+ for _table in ${_tables}
+ grep '^id.*PRI.*auto_increment'
+ mysql --defaults-file=/root/.my.cnf -u root iredadmin -e 'DESC deleted_mailboxes'
+ '[' X0 '!=' X0 ']'
+ for _table in ${_tables}
+ grep '^id.*PRI.*auto_increment'
+ mysql --defaults-file=/root/.my.cnf -u root iredadmin -e 'DESC updatelog'
+ '[' X0 '!=' X0 ']'
+ for _table in ${_tables}
+ grep '^id.*PRI.*auto_increment'
+ mysql --defaults-file=/root/.my.cnf -u root iredadmin -e 'DESC log'
+ '[' X0 '!=' X0 ']'
+ for _table in ${_tables}
+ grep '^id.*PRI.*auto_increment'
+ mysql --defaults-file=/root/.my.cnf -u root iredadmin -e 'DESC tracking'
+ '[' X0 '!=' X0 ']'

#------------------------------
# Cron job.
#
[[ -d ${CRON_SPOOL_DIR} ]] || mkdir -p ${CRON_SPOOL_DIR} &>/dev/null
+ [[ -d /var/spool/cron/crontabs ]]
if [[ ! -f ${CRON_FILE_ROOT} ]]; then
    touch ${CRON_FILE_ROOT} &>/dev/null
    chmod 0600 ${CRON_FILE_ROOT} &>/dev/null
fi
+ [[ ! -f /var/spool/cron/crontabs/root ]]

# cron job: clean up database.
if ! grep 'iredadmin/tools/cleanup_db.py' ${CRON_FILE_ROOT} &>/dev/null; then
    cat >> ${CRON_FILE_ROOT} <<EOF
# iRedAdmin: Clean up sql database.
1   *   *   *   *   ${CMD_PYTHON3} ${IRA_ROOT_DIR}/tools/cleanup_db.py &>/dev/null
EOF
fi
+ grep iredadmin/tools/cleanup_db.py /var/spool/cron/crontabs/root

# cron job: clean up database.
if ! grep 'iredadmin/tools/delete_mailboxes.py' ${CRON_FILE_ROOT} &>/dev/null; then
    cat >> ${CRON_FILE_ROOT} <<EOF
# iRedAdmin: Remove mailboxes which are scheduled to be removed.
1   3   *   *   *   ${CMD_PYTHON3} ${IRA_ROOT_DIR}/tools/delete_mailboxes.py
EOF
fi
+ grep iredadmin/tools/delete_mailboxes.py /var/spool/cron/crontabs/root

echo "* Replace py2 by py3 in cron jobs."
+ echo '* Replace py2 by py3 in cron jobs.'
* Replace py2 by py3 in cron jobs.
perl -pi -e 's#(.*) python (.*/iredadmin/tools/.*)#${1} $ENV{CMD_PYTHON3} ${2}#' ${CRON_FILE_ROOT}
+ perl -pi -e 's#(.*) python (.*/iredadmin/tools/.*)#${1} $ENV{CMD_PYTHON3} ${2}#' /var/spool/cron/crontabs/root
perl -pi -e 's#(.*) python2 (.*/iredadmin/tools/.*)#${1} $ENV{CMD_PYTHON3} ${2}#' ${CRON_FILE_ROOT}
+ perl -pi -e 's#(.*) python2 (.*/iredadmin/tools/.*)#${1} $ENV{CMD_PYTHON3} ${2}#' /var/spool/cron/crontabs/root
perl -pi -e 's#(.*)/usr/bin/python (.*/iredadmin/tools/.*)#${1}$ENV{CMD_PYTHON3} ${2}#' ${CRON_FILE_ROOT}
+ perl -pi -e 's#(.*)/usr/bin/python (.*/iredadmin/tools/.*)#${1}$ENV{CMD_PYTHON3} ${2}#' /var/spool/cron/crontabs/root
perl -pi -e 's#(.*)/usr/bin/python2 (.*/iredadmin/tools/.*)#${1}$ENV{CMD_PYTHON3} ${2}#' ${CRON_FILE_ROOT}
+ perl -pi -e 's#(.*)/usr/bin/python2 (.*/iredadmin/tools/.*)#${1}$ENV{CMD_PYTHON3} ${2}#' /var/spool/cron/crontabs/root
perl -pi -e 's#(.*)/usr/local/bin/python (.*/iredadmin/tools/.*)#${1}$ENV{CMD_PYTHON3} ${2}#' ${CRON_FILE_ROOT}
+ perl -pi -e 's#(.*)/usr/local/bin/python (.*/iredadmin/tools/.*)#${1}$ENV{CMD_PYTHON3} ${2}#' /var/spool/cron/crontabs/root
perl -pi -e 's#(.*)/usr/local/bin/python2 (.*/iredadmin/tools/.*)#${1}$ENV{CMD_PYTHON3} ${2}#' ${CRON_FILE_ROOT}
+ perl -pi -e 's#(.*)/usr/local/bin/python2 (.*/iredadmin/tools/.*)#${1}$ENV{CMD_PYTHON3} ${2}#' /var/spool/cron/crontabs/root

echo "* Clean up."
+ echo '* Clean up.'
* Clean up.
cd ${NEW_IRA_ROOT_DIR}/
+ cd /usr/share/apache2/iRedAdmin-1.1/
rm -f settings.pyc settings.pyo tools/settings.py
+ rm -f settings.pyc settings.pyo tools/settings.py
if [[ -f ${NEW_IRA_ROOT_DIR}/libs/form_utils.py ]]; then
    # Not a trial license.
    cd ${NEW_IRA_ROOT_DIR}
    find . -name '*.so' | xargs rm -f {}
    cd - &>/dev/null
fi
+ [[ -f /usr/share/apache2/iRedAdmin-1.1/libs/form_utils.py ]]
+ cd /usr/share/apache2/iRedAdmin-1.1
+ xargs rm -f '{}'
+ find . -name '*.so'
+ cd -

# Delete all sessions to force admins to re-login.
cd ${NEW_IRA_ROOT_DIR}/tools/
+ cd /usr/share/apache2/iRedAdmin-1.1/tools/
${CMD_PYTHON3} delete_sessions.py
+ /usr/bin/python3 delete_sessions.py
* Delete all existing sessions to force all admins to re-login.

echo "* iRedAdmin has been successfully upgraded."
+ echo '* iRedAdmin has been successfully upgraded.'
* iRedAdmin has been successfully upgraded.
restart_web_service
+ restart_web_service
+ export web_service=apache2
+ web_service=apache2
+ '[' -f /var/run/nginx.pid ']'
+ echo '* Restarting apache2 service.'
* Restarting apache2 service.
+ '[' XLINUX == XLINUX ']'
+ '[' XUBUNTU == XRHEL -a Xapache2 == Xuwsgi ']'
+ service apache2 restart
+ '[' X0 '!=' X0 ']'

# Enable and restart service
enable_service iredadmin
+ enable_service iredadmin
+ srv=iredadmin
+ echo '* Enable service: iredadmin'
* Enable service: iredadmin
+ '[' XUBUNTU == XRHEL ']'
+ '[' XUBUNTU == XDEBIAN -o XUBUNTU == XUBUNTU ']'
+ '[' XYES == XYES ']'
+ systemctl enable iredadmin
Created symlink /etc/systemd/system/multi-user.target.wants/iredadmin.service -> /lib/systemd/system/iredadmin.service.
restart_service iredadmin
+ restart_service iredadmin
+ srv=iredadmin
+ '[' XLINUX == XLINUX ']'
+ '[' XYES == XYES ']'
+ systemctl restart iredadmin
+ '[' X0 '!=' X0 ']'

echo "* Upgrading completed."
+ echo '* Upgrading completed.'
* Upgrading completed.

cat <<EOF
<<< NOTE >>> If iRedAdmin doesn't work as expected, please post your issue in
<<< NOTE >>> our online support forum: http://www.iredmail.org/forum/
EOF
+ cat
<<< NOTE >>> If iRedAdmin doesn't work as expected, please post your issue in
<<< NOTE >>> our online support forum: http://www.iredmail.org/forum/
/root/iRedAdmin-1.1/tools#

8

Re: /opt/www/iredadmin/: No such file or directory

Hi any further answer?

9

Re: /opt/www/iredadmin/: No such file or directory

There's no error in pasted console output. iRedAdmin-Pro upgrade should be finished successfully.

10

Re: /opt/www/iredadmin/: No such file or directory

But it doesn't install to /opt/www/iredadmin and doesn't open. I get error.
/opt/www/iredadmin/: No such file or directory

Have to re-rerun 1.0 version.

Maybe an issue with python?

Also, this is not the pro version.

11

Re: /opt/www/iredadmin/: No such file or directory

Are you running Apache or Nginx now?
If it's Apache, please check its config file to make sure it uses correct directory for iRedAdmin-Pro.

12

Re: /opt/www/iredadmin/: No such file or directory

Per reply #1, using Iredadmin  and Apache2

Per reply #4, see dir listings. iRedapd and mlmmjadmin both in /opt/

Do you mean checking /etc/apache2/conf.d file?

13

Re: /opt/www/iredadmin/: No such file or directory

djfake wrote:

Do you mean checking /etc/apache2/conf.d file?

Check files under /etc/apache2/.

14

Re: /opt/www/iredadmin/: No such file or directory

ZhangHuangbin wrote:

Check files under /etc/apache2/.

If I change default-ssl.conf to use /opt/www/iredadmin/ instead of /usr/share/apache2/ I get 500 error

Alias /iredadmin/static "/usr/share/apache2/iredadmin/static/"
WSGIScriptAlias /iredadmin "/usr/share/apache2/iredadmin/iredadmin.py/"

15

Re: /opt/www/iredadmin/: No such file or directory

Changed default-ssl.conf to reflect new location,
Alias /iredadmin/static "/opt/www/iredadmin/static/"
WSGIScriptAlias /iredadmin "/opt/www/iredadmin/iredadmin.py/"

Installed following,
sudo apt-get install libapache2-mod-wsgi-py3

Okay, fixed now!

16 (edited by djfake 2021-02-02 23:25:33)

Re: /opt/www/iredadmin/: No such file or directory

Okay, now I try to upgrade to 1.2, but I see the issue.

root@:/root/iRedAdmin-1.2/tools# bash upgrade_iredadmin.sh
* Detected Linux/BSD distribution: UBUNTU
* HTTP server root: /usr/share/apache2
* Found iRedAdmin directory: /usr/share/apache2/iredadmin, symbol link of iRedAdmin-1.0

I manually change upgrade_iredadmin.sh and now I have the iredadmin1.2 in new location, but

I see crontabs are all with old directory. How to change?

17

Re: /opt/www/iredadmin/: No such file or directory

djfake wrote:

I see crontabs are all with old directory. How to change?

Run "crontab -e" as root user, then fix the paths.

18

Re: /opt/www/iredadmin/: No such file or directory

ZhangHuangbin wrote:
djfake wrote:

I see crontabs are all with old directory. How to change?

Run "crontab -e" as root user, then fix the paths.

I still have the issue with the path. Today I try to upgrade to iRedAdmin 1.3 and it goes to old location "/usr/share/apache2/iredadmin/"

If I change the upgrade_iredadmin.sh it installs to new location.

Where does this script find the directory?

19

Re: /opt/www/iredadmin/: No such file or directory

upgrade_iredadmin.sh checks Apache directory first for backward compatible concern. If you don't use /usr/share/apache2/iredadmin/ anymore, then please remove it.