#!/usr/bin/env bash

#export LC_ALL="en_US.UTF-8"
#export LANG="en_US.UTF-8"
#export LANGUAGE="en_US.UTF-8"
#export LC_CTYPE="en_US.UTF-8"
#export LC_NUMERIC="en_US.UTF-8"
#export LC_TIME="en_US.UTF-8"
#export LC_COLLATE="en_US.UTF-8"
#export LC_MONETARY="en_US.UTF-8"
#export LC_MESSAGES="en_US.UTF-8"
#export LC_PAPER="en_US.UTF-8"
#export LC_NAME="en_US.UTF-8"

localectl set-locale LANG=en_US.UTF-8

PANILUX_JUST_UPDATE=$1
PANILUX_EL7=$2
SHOW_SPINNER=$3
DEFAULT_YES=$4

if [[ ${PANILUX_JUST_UPDATE} == 1 ]]; then
  PANILUX_JUST_UPDATE=1
else
  PANILUX_JUST_UPDATE=0
fi

if [[ ${PANILUX_EL7} == 1 ]]; then
  PANILUX_EL7=1
else
  PANILUX_EL7=0
fi

if [[ ${SHOW_SPINNER} == 1 ]]; then
  SHOW_SPINNER=1
else
  SHOW_SPINNER=0
fi

if [[ ${DEFAULT_YES} == 1 ]]; then
  DEFAULT_YES=1
else
  DEFAULT_YES=0
fi

ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/')
ARCH_FULL=$(uname -m)

if [[ ${ARCH_FULL} == "i686" ]]; then
  ARCH_FULL="i386"
fi

if [[ ${ARCH_FULL} == "i386" ]]; then
  ARCH_REPO="x86"
else
  ARCH_REPO="x86_64"
fi

if
  [[ ${ARCH} != "32" ]] &&
    [[ ${ARCH} != "64" ]]
then
  echo "Could not determine architecture"
  exit
fi

spinner() {
  local pid=$1

  if [[ ${SHOW_SPINNER} -eq 1 ]]; then
    local delay=0.6
    local spinstr="|/-\\"
    while [[ "$(ps a | awk '{print $1}' | grep ${pid})" ]]; do
      local temp=${spinstr#?}
      printf "[%c]" "${spinstr}"
      local spinstr=${temp}${spinstr%"${temp}"}
      sleep ${delay}
      printf "\b\b\b"
    done

    printf "   \b\b\b"
  else
    wait ${pid}
  fi
}

service_start() {
  SERVICE=$1

  RETURN_FILE="/tmp/return.service_start"

  echo -n "${TEXT_Starting} ${SERVICE}... "

  if [[ ${DIST_EL} -eq 6 ]]; then
    (
      service "${SERVICE}" start >/dev/null 2>&1
      echo $? >${RETURN_FILE}
    ) &
    spinner $!
  elif
    [[ ${DIST_EL} -eq 7 ]] ||
      [[ ${DIST_EL} -eq 8 ]] ||
      [[ ${DIST_EL} -eq 9 ]]
  then
    (
      systemctl start "${SERVICE}" >/dev/null 2>&1
      echo $? >${RETURN_FILE}
    ) &
    spinner $!
  fi

  if [[ $(cat ${RETURN_FILE}) == '0' ]]; then
    echo "${TEXT_OK}"
  else
    echo "${TEXT_FAIL}"
    do_cleanup
  fi

  rm -rf ${RETURN_FILE}
}

service_restart() {
  SERVICE=$1

  RETURN_FILE="/tmp/return.service_restart"

  echo -n "${TEXT_Restarting} ${SERVICE}... "

  if [[ ${DIST_EL} -eq 6 ]]; then
    (
      service "${SERVICE}" restart >/dev/null 2>&1
      echo $? >${RETURN_FILE}
    ) &
    spinner $!
  elif
    [[ ${DIST_EL} -eq 7 ]] ||
      [[ ${DIST_EL} -eq 8 ]] ||
      [[ ${DIST_EL} -eq 9 ]]
  then
    (
      systemctl restart "${SERVICE}" >/dev/null 2>&1
      echo $? >${RETURN_FILE}
    ) &
    spinner $!
  fi

  if [[ $(cat ${RETURN_FILE}) == '0' ]]; then
    echo "${TEXT_OK}"
  else
    echo "${TEXT_FAIL}"
    do_cleanup
  fi

  rm -rf ${RETURN_FILE}
}

service_stop() {
  SERVICE=$1

  RETURN_FILE="/tmp/return.service_stop"

  echo -n "${TEXT_Stopping} ${SERVICE}... "

  if [[ ${DIST_EL} -eq 6 ]]; then
    (
      service "${SERVICE}" stop >/dev/null 2>&1
      echo $? >${RETURN_FILE}
    ) &
    spinner $!
  elif
    [[ ${DIST_EL} -eq 7 ]] ||
      [[ ${DIST_EL} -eq 8 ]] ||
      [[ ${DIST_EL} -eq 9 ]]
  then
    (
      systemctl stop "${SERVICE}" >/dev/null 2>&1
      echo $? >${RETURN_FILE}
    ) &
    spinner $!
  fi

  if [[ $(cat ${RETURN_FILE}) == '0' ]]; then
    echo "${TEXT_OK}"
  else
    echo "${TEXT_FAIL}"
    do_cleanup
  fi

  rm -rf ${RETURN_FILE}
}

function package_install() {
  TITLE=$1
  PACKAGE=$2

  RETURN_FILE="/tmp/return.install_package"

  echo -n "${TITLE}... "

  # >/dev/null 2>&1
  # >/dev/null 2>&1

  if [[ ${SHOW_SPINNER} -eq 1 ]]; then
    (
      $INSTALL_COMMAND install -q -y $PACKAGE
      echo $? >${RETURN_FILE}
    ) &
    spinner $!
  else
    $INSTALL_COMMAND install -q -y $PACKAGE
    echo $? >${RETURN_FILE}
  fi

  if [[ $(cat ${RETURN_FILE}) == '0' ]]; then
    echo "${TEXT_INSTALLED}"
  elif [[ $(cat ${RETURN_FILE}) == '1' ]]; then
    echo "${TEXT_FOUND}"
  else
    echo "${TEXT_FAIL}"
    do_cleanup
  fi

  rm -rf ${RETURN_FILE}
}

function package_localinstall() {
  TITLE=$1
  PACKAGE=$2

  RETURN_FILE="/tmp/return.package_localinstall"

  echo -n "${TITLE}... "

  (
    $INSTALL_COMMAND localinstall -y --nogpgcheck "${PACKAGE}" >/dev/null 2>&1
    echo $? >${RETURN_FILE}
  ) &
  spinner $!

  if [[ $(cat ${RETURN_FILE}) == '0' ]]; then
    echo "${TEXT_INSTALLED}"
  elif [[ $(cat ${RETURN_FILE}) == '1' ]]; then
    echo "${TEXT_FOUND}"
  else
    echo "${TEXT_FAIL}"
    do_cleanup
  fi

  rm -rf ${RETURN_FILE}
}

function package_update() {
  echo -n "${TEXT_Updating_CentOS}"
  RETURN_FILE="/tmp/return.package_update"

  (
    $INSTALL_COMMAND update -y >/dev/null 2>&1
    echo $? >${RETURN_FILE}
  ) &
  spinner $!

  if [[ $(cat ${RETURN_FILE}) == '0' ]]; then
    echo "${TEXT_DONE}"
  elif [[ $(cat ${RETURN_FILE}) == '1' ]]; then
    echo "${TEXT_FOUND}"
  else
    echo "${TEXT_FAIL}"
    do_cleanup
  fi

  rm -rf ${RETURN_FILE}
}

function package_clean_all() {
  echo -n "${TEXT_YUM_cleaning}"

  RETURN_FILE="/tmp/return.package_clean_all"

  (
    $INSTALL_COMMAND clean all -y >/dev/null 2>&1
    echo $? >${RETURN_FILE}
  ) &
  spinner $!

  if
    [[ $(cat ${RETURN_FILE}) == '1' ]] ||
      [[ $(cat ${RETURN_FILE}) == '0' ]]
  then
    echo "${TEXT_DONE}"
  else
    echo "${TEXT_FAIL}"
    do_cleanup
  fi

  rm -rf ${RETURN_FILE}
}

function exit_status() {
  RETURN_CODE=$1
  EXITTEXT=$2

  if [[ ${RETURN_CODE} -ne 0 ]]; then
    error "${TEXT_Error}: ${EXITTEXT}"
    do_cleanup
  fi
}

function package_exit_status() {
  RETURN_CODE=$1
  EXITTEXT=$2

  if [[ ${RETURN_CODE} -ne 0 ]]; then
    error "${TEXT_Error}: ${EXITTEXT}"
    do_cleanup
  fi
}

function package_enable_remi() {
  crudini --set /etc/yum.repos.d/remi.repo remi enabled 1
}

function package_enable_gf() {
  crudini --set /etc/yum.repos.d/gf.repo gf sslverify 0
  crudini --set /etc/yum.repos.d/gf.repo gf-plus sslverify 0
  crudini --set /etc/yum.repos.d/gf.repo gf-plus enabled 1
  crudini --set /etc/yum.repos.d/gf.repo gf-plus exclude 'libevent*'
}

function rpm_exit_status() {
  RETURN_CODE=$1
  EXITTEXT=$2

  if
    [[ ${RETURN_CODE} -ne 1 ]]
    [[ ${RETURN_CODE} -ne 0 ]]
  then
    echo "${TEXT_Error}: ${EXITTEXT}"
    do_cleanup
  fi
}

function do_cleanup() {
  rm -rf /tmp/return.*

  yum-complete-transaction --cleanup-only >/dev/null 2>&1

  echo
  echo "${TEXT_Installation_aborted}"
  exit 1
}

function do_checkconfig_operations() {
  if [[ ${DIST_EL} -eq 6 ]]; then
    chkconfig pure-ftpd on
    chkconfig mysqld on
    chkconfig mongod on

    chkconfig nginx on
    chkconfig php-fpm on

    chkconfig postfix on
    chkconfig dovecot on
    chkconfig opendkim on
    chkconfig saslauthd on
    chkconfig spamassassin on
  elif
    [[ ${DIST_EL} -eq 7 ]] ||
      [[ ${DIST_EL} -eq 8 ]] ||
      [[ ${DIST_EL} -eq 9 ]]
  then
    systemctl enable pure-ftpd
    systemctl enable mysqld
    systemctl enable mongod

    systemctl enable nginx
    systemctl enable php-fpm

    systemctl enable postfix
    systemctl enable dovecot
    systemctl enable opendkim
    systemctl enable saslauthd
    systemctl enable spamassassin
  fi
}

trap 'do_cleanup' SIGINT SIGTERM

if [[ $? -ne 0 ]]; then
  do_cleanup
fi

function download_file() {
  FILE_URL=$1
  SAVE_TO=$2
  MD5SUM=$3

  if [[ ! -f "${SAVE_TO}.downloaded" ]]; then
    curl -f -# ${FILE_URL} -o ${SAVE_TO} || do_cleanup

    if [[ ${MD5SUM} ]]; then
      if [[ $(md5sum ${SAVE_TO} | cut -d\  -f1) != ${MD5SUM} ]]; then
        echo "md5sum mismatch for ${SAVE_TO}"
        do_cleanup
      fi
    fi

    touch "${SAVE_TO}.downloaded"
  else
    echo "${TEXT_Already_downloaded} ${FILE_URL}"
  fi
}

download_file_no_prog() {
  FILE_URL=$1
  SAVE_TO=$2

  if [[ ! -f "${SAVE_TO}.downloaded" ]]; then
    curl -f -s ${FILE_URL} -o ${SAVE_TO} || do_cleanup
  fi
}

error() {
  printf '\E[31m'
  echo "$@"
  printf '\E[0m'
}

if [[ -f /etc/system-release ]]; then
  if [[ ! -f /etc/redhat-release ]]; then
    echo "Fix for missing redhat-release"
    ln -sf /etc/system-release /etc/redhat-release
  fi
fi

if [[ ! -f /etc/redhat-release ]]; then
  echo
  error "${TEXT_Error}: /etc/redhat-release ${TEXT_was_not_detected}"
  echo
  exit 1
fi

DIST_EL=0
DIST_NAME=""

RELEASE=$(cat /etc/redhat-release | awk -F\( '{print $1}')

# EL3, EL4, and Fedora
if grep -qE "^Fedora|release 3|release 4" /etc/redhat-release; then
  cat /etc/redhat-release
  error "${TEXT_This_platform_is_no_longer_supported}"
  echo "${TEXT_Exiting}..."
  exit 1
# EL5
elif grep -qEi "^CentOS Linux release 5|release 2011" /etc/redhat-release; then
  DIST_EL=5
  DIST_NAME="centos"
# EL6
elif grep -qEi "^CentOS Linux release 6|release 2012" /etc/redhat-release; then
  DIST_EL=6
  DIST_NAME="centos"
# EL7
elif grep -qEi "^CentOS Linux release 7" /etc/redhat-release; then
  DIST_EL=7
  DIST_NAME="centos"
# EL8
elif grep -qEi "^Red Hat Enterprise Linux release 8" /etc/redhat-release; then
  DIST_EL=8
  DIST_NAME="rhel"
# EL9
elif grep -qEi "^Red Hat Enterprise Linux release 9" /etc/redhat-release; then
  DIST_EL=9
  DIST_NAME="rhel"
elif grep -qEi "^Rocky Linux release 8" /etc/redhat-release; then
  DIST_EL=8
  DIST_NAME="rhel"
elif grep -qEi "^Rocky Linux release 9" /etc/redhat-release; then
  DIST_EL=9
  DIST_NAME="rhel"
elif grep -qEi "^AlmaLinux release 8" /etc/redhat-release; then
  DIST_EL=8
  DIST_NAME="rhel"
elif grep -qEi "^AlmaLinux release 9" /etc/redhat-release; then
  DIST_EL=9
  DIST_NAME="rhel"
else
  error "${TEXT_Error}: ${TEXT_Unable_to_determine_distribution_type}"
  exit 1
fi

YUM_PATH=$(which yum)
DNF_PATH=$(which dnf)

INSTALL_COMMAND=$YUM_PATH

if [[ ${DIST_EL} -eq 8 ]] || [[ ${DIST_EL} -eq 9 ]]; then
  INSTALL_COMMAND=$DNF_PATH
fi

if [[ ! $INSTALL_COMMAND ]]; then
  echo
  error "${TEXT_Error}: ${TEXT_Yum_was_not_detected}"
  echo
  exit 1
fi

# check whoami?
if
  [[ $(id -u) -ne 0 ]]
then
  error "Please run as root"
  exit
fi

if [[ ${PANILUX_JUST_UPDATE} -ne 1 ]]; then
  #	if [[ ${PANILUX_EL7} -ne 1 ]]; then
  #		if [[ ${DIST_EL} -eq 6 ]]; then
  #			exit_status 1 "${TEXT_Panilux_is_supported_Centos_6}."
  #		fi
  #	fi

  if
    [[ ${ARCH} != "64" ]]
  then
    exit_status 1 "${TEXT_Panilux_is_supported_Only_64bit_servers}."
  fi

  clear
  if [[ ${INSTALL_BETA} == true ]]; then
    echo '!!!!!!! INSTALLING PANILUX WITH BETA FEATURES !!!!!!!!'
  fi

  echo
  echo "              ${TEXT_Welcome_to_Panilux_installer}"
  echo
  echo "${TEXT_Release_is}: ${RELEASE} ${ARCH}bit"

  function catch_install_en_yn() {
    case $1 in
    [Yy]) true ;;
    [Nn]) false ;;
    *) echo "${TEXT_Please_answer_Yes_or_No}" ;;
    esac
  }

  function catch_install_tr_yn() {
    case $1 in
    [Ee]) true ;;
    [Hh]) false ;;
    *) echo "${TEXT_Please_answer_Yes_or_No}" ;;
    esac
  }

  if [[ ${DEFAULT_YES} == 0 ]]; then
    while true; do
      read -r -p "${TEXT_Do_you_wish_to_install_Panilux_Y_or_N}: " yn

      if [[ ${INSTALLER_LANG} == "en" ]]; then
        catch_install_en_yn "${yn}" && break || exit
      else
        catch_install_tr_yn "${yn}" && break || exit
      fi
    done
  else
    echo "${TEXT_Do_you_wish_to_install_Panilux_Y_or_N}: Y"
  fi

  if [[ -d "/panilux" ]]; then
    if [[ ${DEFAULT_YES} == 0 ]]; then
      while true; do
        read -r -p "${TEXT_Panilux_is_already_installed}: " yn

        if [[ ${INSTALLER_LANG} == "en" ]]; then
          catch_install_en_yn "${yn}" && break || exit
        else
          catch_install_tr_yn "${yn}" && break || exit
        fi
      done
    else
      echo "${TEXT_Panilux_is_already_installed}: Y"
    fi
  fi
fi

if [[ ${DIST_EL} -eq 6 ]] || [[ ${DIST_EL} -eq 7 ]]; then
  package_install "YUM Utils" "yum-utils"
  yum-complete-transaction --cleanup-only
# >/dev/null 2>&1
elif [[ ${DIST_EL} -eq 8 ]] || [[ ${DIST_EL} -eq 9 ]]; then
  package_install "DNF Utils" "dnf-utils"
  package_install "Lang Packs" "glibc-all-langpacks"
# >/dev/null 2>&1
fi

if [[ ${DIST_EL} -eq 6 ]]; then
  if
    [[ ${ARCH} == "32" ]]
  then
    package_install "${TEXT_Adding_Repository} EPEL (32bit)" "http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm"
  fi
  if
    [[ ${ARCH} == "64" ]]
  then
    package_install "${TEXT_Adding_Repository} EPEL (64bit)" "http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm"
  fi
elif [[ ${DIST_EL} -eq 7 ]]; then
  package_install "${TEXT_Adding_Repository} EPEL" "https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm"
elif [[ ${DIST_EL} -eq 8 ]]; then
  package_install "${TEXT_Adding_Repository} EPEL" "https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm"
  dnf config-manager --enable PowerTools
elif [[ ${DIST_EL} -eq 9 ]]; then
  package_install "${TEXT_Adding_Repository} EPEL" "https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm"
  dnf config-manager --enable crb
fi

package_install "${TEXT_Installing} Crudini Tool" 'crudini'
package_install "${TEXT_Installing} Rsync" 'rsync'

if [[ ${DIST_EL} -eq 6 ]]; then

  echo -n "${TEXT_Adding_Repository} Panilux CentOS 6... "
  crudini --set /etc/yum.repos.d/panilux.repo "panilux" name "Panilux CentOS Repo"
  crudini --set /etc/yum.repos.d/panilux.repo "panilux" baseurl "https://repos.panilux.com/el6"
  crudini --set /etc/yum.repos.d/panilux.repo "panilux" enabled 1
  crudini --set /etc/yum.repos.d/panilux.repo "panilux" gpgcheck 0
  echo "${TEXT_DONE}"

  if [[ ${INSTALL_BETA} == true ]]; then
    echo -n "${TEXT_Adding_Repository} Panilux CentOS 6 Beta... "
    crudini --set /etc/yum.repos.d/panilux.repo "panilux-beta" name "Panilux CentOS Beta Repo"
    crudini --set /etc/yum.repos.d/panilux.repo "panilux-beta" baseurl "https://repos.panilux.com/beta/el6"
    crudini --set /etc/yum.repos.d/panilux.repo "panilux-beta" enabled 1
    crudini --set /etc/yum.repos.d/panilux.repo "panilux-beta" gpgcheck 0
    echo "${TEXT_DONE}"
  fi

  echo -n "${TEXT_Adding_Repository} Dovecot... "
  crudini --set /etc/yum.repos.d/dovecot.repo "dovecot-2.3-latest" name "Dovecot 2.3 ${DIST_NAME} \$releasever - \$basearch"
  crudini --set /etc/yum.repos.d/dovecot.repo "dovecot-2.3-latest" baseurl "https://repo.dovecot.org/ce-2.3-latest/${DIST_NAME}/\$releasever/RPMS/\$basearch"
  crudini --set /etc/yum.repos.d/dovecot.repo "dovecot-2.3-latest" gpgkey "https://repo.dovecot.org/DOVECOT-REPO-GPG"
  crudini --set /etc/yum.repos.d/dovecot.repo "dovecot-2.3-latest" gpgcheck 1
  crudini --set /etc/yum.repos.d/dovecot.repo "dovecot-2.3-latest" enabled 1
  echo "${TEXT_DONE}"

  package_install "${TEXT_Adding_Repository} REMI" "https://rpms.famillecollet.com/enterprise/remi-release-6.rpm"
  RET=$?
  if [[ ${RET} -eq 0 ]]; then
    package_enable_remi
  fi

  package_install "${TEXT_Adding_Repository} MySQL Community" "https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm"

  echo -n "${TEXT_YUM_configuring}"
  # >/dev/null 2>&1
  $INSTALL_COMMAND remove -y centos-release-SCL
  $INSTALL_COMMAND remove -y --disablerepo=scl centos-release-SCL
  $INSTALL_COMMAND install -y yum-priorities
  echo "${TEXT_DONE}"

  package_install "${TEXT_Adding_Repository} CentOS Linux Software Collections" "centos-release-scl"

  package_install "${TEXT_Adding_Repository} GhettoForge" "https://mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el6.noarch.rpm"

  if
    [[ ${ARCH} == "32" ]]
  then
    package_localinstall "${TEXT_Adding_Repository} Rpmfusion free (32bit)" "https://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm"
    package_localinstall "${TEXT_Adding_Repository} Rpmfusion nonfree (32bit)" "https://download1.rpmfusion.org/nonfree/el/updates/6/i386/rpmfusion-nonfree-release-6-1.noarch.rpm"
  fi
  if
    [[ ${ARCH} == "64" ]]
  then
    package_localinstall "${TEXT_Adding_Repository} Rpmfusion free (64bit)" "https://download1.rpmfusion.org/free/el/updates/6/x86_64/rpmfusion-free-release-6-1.noarch.rpm"
    package_localinstall "${TEXT_Adding_Repository} Rpmfusion nonfree (64bit)" "https://download1.rpmfusion.org/nonfree/el/updates/6/x86_64/rpmfusion-nonfree-release-6-1.noarch.rpm"
  fi

elif
  [[ ${DIST_EL} -eq 7 ]] ||
    [[ ${DIST_EL} -eq 8 ]] ||
    [[ ${DIST_EL} -eq 9 ]]
then

  echo -n "${TEXT_Adding_Repository} Panilux EL${DIST_EL}... "
  crudini --set /etc/yum.repos.d/panilux.repo "panilux" name "Panilux EL${DIST_EL} Repo"
  crudini --set /etc/yum.repos.d/panilux.repo "panilux" baseurl "https://repos.panilux.com/el${DIST_EL}"
  crudini --set /etc/yum.repos.d/panilux.repo "panilux" enabled 1
  crudini --set /etc/yum.repos.d/panilux.repo "panilux" gpgcheck 0
  echo "${TEXT_DONE}"

  if [[ ${INSTALL_BETA} == true ]]; then
    echo -n "${TEXT_Adding_Repository} Panilux EL${DIST_EL} Beta... "
    crudini --set /etc/yum.repos.d/panilux.repo "panilux-beta" name "Panilux EL${DIST_EL} Beta Repo"
    crudini --set /etc/yum.repos.d/panilux.repo "panilux-beta" baseurl "https://repos.panilux.com/beta/el${DIST_EL}"
    crudini --set /etc/yum.repos.d/panilux.repo "panilux-beta" enabled 1
    crudini --set /etc/yum.repos.d/panilux.repo "panilux-beta" gpgcheck 0
    echo "${TEXT_DONE}"
  fi

  if [[ ${DIST_EL} -eq 7 ]] || [[ ${DIST_EL} -eq 8 ]]; then
    DOVECOT_VERSION="latest"
    #    if [[ ${DIST_EL} -eq 7 ]]; then
    #      DOVECOT_VERSION="21"
    #    fi
    echo -n "${TEXT_Adding_Repository} Dovecot... "
    crudini --set /etc/yum.repos.d/dovecot.repo "dovecot-2.3-${DOVECOT_VERSION}" name "Dovecot 2.3 ${DIST_NAME} \$releasever - \$basearch"
    crudini --set /etc/yum.repos.d/dovecot.repo "dovecot-2.3-${DOVECOT_VERSION}" baseurl "https://repo.dovecot.org/ce-2.3-${DOVECOT_VERSION}/${DIST_NAME}/\$releasever/RPMS/\$basearch"
    crudini --set /etc/yum.repos.d/dovecot.repo "dovecot-2.3-${DOVECOT_VERSION}" gpgkey "https://repo.dovecot.org/DOVECOT-REPO-GPG"
    crudini --set /etc/yum.repos.d/dovecot.repo "dovecot-2.3-${DOVECOT_VERSION}" gpgcheck 1
    crudini --set /etc/yum.repos.d/dovecot.repo "dovecot-2.3-${DOVECOT_VERSION}" enabled 1
    echo "${TEXT_DONE}"
  fi

  if [[ ${DIST_EL} -eq 7 ]]; then
    package_install "${TEXT_Adding_Repository} MySQL Community" "https://dev.mysql.com/get/mysql84-community-release-el7-1.noarch.rpm"

    package_install "${TEXT_Adding_Repository} REMI" "https://rpms.remirepo.net/enterprise/remi-release-7.rpm"
    RET=$?

    if [[ ${RET} -eq 0 ]]; then
      package_enable_remi
    fi

    package_install "${TEXT_Adding_Repository} GhettoForge" "https://mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el7.noarch.rpm"
  elif [[ ${DIST_EL} -eq 8 ]]; then
    package_install "${TEXT_Adding_Repository} MySQL Community" "https://dev.mysql.com/get/mysql84-community-release-el8-1.noarch.rpm"
    $INSTALL_COMMAND module -y disable mysql

    package_install "${TEXT_Adding_Repository} REMI" "https://rpms.remirepo.net/enterprise/remi-release-8.rpm"
    RET=$?

    if [[ ${RET} -eq 0 ]]; then
      package_enable_remi
    fi

    package_install "${TEXT_Adding_Repository} GhettoForge" "https://mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el8.noarch.rpm"
  elif [[ ${DIST_EL} -eq 9 ]]; then
    package_install "${TEXT_Adding_Repository} MySQL Community" "https://dev.mysql.com/get/mysql84-community-release-el9-1.noarch.rpm"

    package_install "${TEXT_Adding_Repository} REMI" "https://rpms.remirepo.net/enterprise/remi-release-9.rpm"
    RET=$?

    if [[ ${RET} -eq 0 ]]; then
      package_enable_remi
    fi

    package_install "${TEXT_Adding_Repository} GhettoForge" "https://mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el9.noarch.rpm"
  fi

  # >/dev/null 2>&1

  $INSTALL_COMMAND update -y

  package_install "${TEXT_Installing} net-tools" "net-tools"

  package_install "${TEXT_Installing} GeoLite databases" "geolite2-city geolite2-country"

fi

if [[ ${DIST_EL} -eq 8 ]] || [[ ${DIST_EL} -eq 9 ]]; then
  $INSTALL_COMMAND module -y reset php
  $INSTALL_COMMAND module -y install php:remi-8.3
fi

echo -n "${TEXT_Adding_Repository} PowerDNS... "
curl -o /etc/yum.repos.d/powerdns-auth-49.repo https://repo.powerdns.com/repo-files/el-auth-49.repo
curl -o /etc/yum.repos.d/powerdns-dnsdist-19.repo https://repo.powerdns.com/repo-files/el-dnsdist-19.repo
echo 'DONE'

package_enable_gf

crudini --set /etc/yum.repos.d/mongodb-org-8.0.repo 'mongodb-org-8.0' name "MongoDB Repository"
crudini --set /etc/yum.repos.d/mongodb-org-8.0.repo 'mongodb-org-8.0' baseurl "https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/8.0/x86_64/"
crudini --set /etc/yum.repos.d/mongodb-org-8.0.repo 'mongodb-org-8.0' enabled 1
crudini --set /etc/yum.repos.d/mongodb-org-8.0.repo 'mongodb-org-8.0' gpgcheck 1
crudini --set /etc/yum.repos.d/mongodb-org-8.0.repo 'mongodb-org-8.0' gpgkey "https://www.mongodb.org/static/pgp/server-8.0.asc"

#rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 >/dev/null 2>&1
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2023 >/dev/null 2>&1
crudini --set /etc/yum.repos.d/mysql-community.repo 'mysql80-community' enabled 1

package_install "${TEXT_Installing} CA-Certificates" "ca-certificates"
update-ca-trust enable >/dev/null 2>&1

rpm -e --nodeps postfix >/dev/null 2>&1

$INSTALL_COMMAND remove -y dovecot dovecot-pigeonhole dovecot-mysql >/dev/null 2>&1
$INSTALL_COMMAND install -y cronie cronie-anacron crontabs sysstat >/dev/null 2>&1

package_clean_all
package_update

if [[ ${DIST_EL} -eq 6 ]] || [[ ${DIST_EL} -eq 7 ]]; then
  package_install "${TEXT_Installing} deltarpm" "deltarpm"
  package_install "${TEXT_Installing} ntpdate" "ntpdate"
elif [[ ${DIST_EL} -eq 8 ]] || [[ ${DIST_EL} -eq 9 ]]; then
  package_install "${TEXT_Installing} Time utils" "chrony ntpsec"
  service_start "chronyd"
fi

echo -n "${TEXT_Updating_time} "
(ntpdate pool.ntp.org >/dev/null 2>&1) &
spinner $!
echo "${TEXT_DONE}"

package_install "${TEXT_Installing_libraries}" "bind-utils zip unzip zlib hdparm cpuid virt-what sudo wget nano crypto-utils libmcrypt t1lib libpng12 freetype openssl098e openssl apr apr-util libaio libicu geoip pv nice at cronie gd mail perl-Net-CIDR bash-completion jwhois libmaxminddb shellinabox libxslt perl-DBD-mysql wp-cli"

package_install "${TEXT_Installing} MySQL" "mysql-community-server mysql-community-libs-compat mysql-community-client mysql-community-common mysql-community-libs"

package_install "${TEXT_Installing} MongoDB" "mongodb-org"

package_install "${TEXT_Installing} Quota" "quota"
package_install "${TEXT_Installing} PowerDNS" "pdns pdns-backend-mysql pdns-backend-pipe pdns-backend-geoip pdns-tools"
package_install "${TEXT_Installing} Nginx for Panilux Panel" "nginx"
package_install "${TEXT_Installing} Pure-FTPd" "pure-ftpd"
package_install "${TEXT_Installing} Postfix" "postfix3 postfix3-mysql postfix3-pcre postfix3-ldap postfix3-lmdb postfix3-pgsql postfix3-sqlite postfix3-perl-scripts"
package_install "${TEXT_Installing} dovecot" "dovecot dovecot-mysql dovecot-pigeonhole spamassassin opendkim cyrus-sasl"
package_install "${TEXT_Installing} Monitoring service (monit)" "monit"

package_install "${TEXT_Installing} cluebringer" "https://download.policyd.org/v2.0.14/cluebringer-2.0.14-1.noarch.rpm"

package_install "${TEXT_Installing} PHP & FPM" "php php-fpm"
package_install "${TEXT_Installing} PHP extensions" "php-pdo php-imap php-pecl-mcrypt php-mysqlnd php-gd php-mbstring php-pecl-memcache php-pecl-memcached php-ldap php-intl php-opcache php-dom php-xml"
package_install "${TEXT_Installing} Imagick & PHP extension" "ImageMagick php-pecl-imagick-im7"
package_install "${TEXT_Installing} memcached" "memcached"

#crudini --set /etc/yum.repos.d/unit.repo 'unit' name 'unit repo'
#crudini --set /etc/yum.repos.d/unit.repo 'unit' baseurl 'https://packages.nginx.org/unit/centos/\$releasever/\$basearch/'
#crudini --set /etc/yum.repos.d/unit.repo 'unit' enabled 1
#crudini --set /etc/yum.repos.d/unit.repo 'unit' gpgcheck 0
#crudini --set /etc/yum.repos.d/unit.repo 'unit' priority 1

#package_install "${TEXT_Installing} Unit" "unit unit-go unit-perl unit-python27 unit-python36 unit-jsc8 unit-jsc11 php54-unit-php php55-unit-php php56-unit-php php70-unit-php php71-unit-php php72-unit-php php73-unit-php php74-unit-php"

if [[ ${PANILUX_JUST_UPDATE} -eq 1 ]]; then
  do_checkconfig_operations

  rpm -q panilux-www3th >/dev/null 2>&1
  www3th_is_installed=$?

  if [[ ${www3th_is_installed} == 1 ]]; then
    package_install "${TEXT_Installing} Panilux www3th" "panilux-www3th"
  fi

  if [[ ${www3th_is_installed} == 0 ]]; then
    pushd /panilux/www3th/webmails/rainloop >/dev/null 2>&1
    push_success=$?

    if [[ ${push_success} == 0 ]]; then
      echo -n 'Checking and Updating webmails... '
      rm -rf /panilux/www3th/webmails/rainloop/* >/dev/null 2>&1
      curl -sL https://repository.rainloop.net/installer.php | php >/dev/null 2>&1
      php index.php >/dev/null 2>&1

      chmod 777 -R /panilux/www3th/webmails/rainloop/data/
      popd >/dev/null 2>&1
      /panilux/bin/api 'domain-webmail_install_check?webmailsoftware=rainloop' >/dev/null 2>&1
      echo 'OK'
    fi
  fi

  echo -n 'Configuring Web Services... '
  /panilux/bin/api web-reconfigure >/dev/null 2>&1
  RET_CODE=$?
  #	echo RET_CODE
  echo 'OK'

  echo -n 'Configuring Mail Services... '
  /panilux/bin/api mail-reconfigure >/dev/null 2>&1
  RET_CODE=$?
  #	echo RET_CODE
  echo 'OK'

  echo -n 'Configuring Ftp Services... '
  /panilux/bin/api ftp-reconfigure >/dev/null 2>&1
  RET_CODE=$?
  #	echo RET_CODE
  echo 'OK'

  echo -n 'Configuring DNS Services... '
  /panilux/bin/api dns-reconfigure >/dev/null 2>&1
  RET_CODE=$?
  #	echo RET_CODE
  echo 'OK'

  echo -n 'Configuring MySQL Services... '
  /panilux/bin/api database-reconfigure >/dev/null 2>&1
  RET_CODE=$?
  #	echo RET_CODE
  echo 'OK'

  postfix set-permissions >/dev/null 2>&1

  echo 'Your system is updated'
  exit
fi

echo -n "${TEXT_Creating_Panilux_environment} "
if [[ ! $(getent group panilux) ]]; then
  groupadd panilux >/dev/null 2>&1
  RET=$?
  if
    [[ ${RET} -ne 9 ]] &&
      [[ ${RET} -ne 0 ]]
  then
    echo "${TEXT_FAIL}"
    do_cleanup
  fi
fi

id -u panilux 2>&- >/dev/null
if [[ $? -eq 1 ]]; then
  useradd panilux -s /sbin/nologin -g panilux -c "" >/dev/null 2>&1
  RET=$?
  if
    [[ ${RET} -ne 9 ]] &&
      [[ ${RET} -ne 0 ]]
  then
    echo "${TEXT_FAIL}"
    do_cleanup
  fi
fi

mkdir -p /sites/ /sites/nginx-confs /sites/phpfpm /sites/phpfpm/domains /sites/phpfpm/sockets /sites/domains/default/www /sites/domains/default/vhosts/domain_suspend/ >/dev/null 2>&1

useradd -r -u 101 -g mail -d /sites/postfix/vmail -s /sbin/nologin -c "Virtual mailbox" vmail >/dev/null 2>&1

mkdir -p /sites/ssls/postfix /sites/ssls/dovecot /sites/postfix/opendkim /sites/postfix/vmail /sites/logs >/dev/null 2>&1
touch /sites/postfix/opendkim/signingtable >/dev/null 2>&1
touch /sites/postfix/opendkim/keytable >/dev/null 2>&1
chmod -R 770 /sites/postfix/vmail >/dev/null 2>&1
chown vmail:mail /sites/postfix/vmail >/dev/null 2>&1

mkdir -p /sites/postfix/sieve >/dev/null 2>&1
chown -R vmail.mail /sites/postfix/sieve >/dev/null 2>&1
chmod -R ug+rwx /sites/postfix/sieve >/dev/null 2>&1

chgrp mail /usr/libexec/dovecot/dovecot-lda >/dev/null 2>&1
chmod 04750 /usr/libexec/dovecot/dovecot-lda >/dev/null 2>&1
chmod 777 /sites/logs >/dev/null 2>&1

cat >/etc/postfix/main.cf <<EOL
html_directory = no
readme_directory = no
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
queue_directory = /var/spool/postfix
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
EOL

postfix set-permissions >/dev/null 2>&1

if
  [[ ${RET} -ne 9 ]] &&
    [[ ${RET} -ne 0 ]]
then
  echo "${TEXT_FAIL}"
  do_cleanup
fi

echo "${TEXT_DONE}"

package_install "${TEXT_Installing} Panilux php" "panilux-php"
package_install "${TEXT_Installing} Panilux agent" "panilux-agent"
package_install "${TEXT_Installing} Panilux bin" "panilux-bin"
package_install "${TEXT_Installing} Panilux nginx" "panilux-nginx"
package_install "${TEXT_Installing} Panilux Panel" "panilux-panel"
package_install "${TEXT_Installing} Panilux www3th" "panilux-www3th"

pushd /panilux/www3th/webmails/rainloop >/dev/null 2>&1
push_success=$?

if [[ push_success == 0 ]]; then
  rm -rf /panilux/www3th/webmails/rainloop/* >/dev/null 2>&1
  curl -sL https://repository.rainloop.net/installer.php | php >/dev/null 2>&1
  php index.php >/dev/null 2>&1

  chmod 777 -R /panilux/www3th/webmails/rainloop/data/
  popd >/dev/null 2>&1
  /panilux/bin/api 'domain-webmail_install_check?webmailsoftware=rainloop' >/dev/null 2>&1
fi

CHECK_ENFORCE=$(getenforce)
if [[ ${CHECK_ENFORCE} != '0' ]]; then
  echo -n "${TEXT_Disabling_SELINUX} "
  setenforce 0 >/dev/null 2>&1
  sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config >/dev/null 2>&1
  echo "${TEXT_DONE}"
fi

if [[ ! $(grep -i '#Changing lda users vmail to active email user' /etc/sudoers) ]]; then
  echo "" >>/etc/sudoers
  echo "#Changing lda users vmail to active email user" >>/etc/sudoers
  echo "Defaults:vmail !syslog" >>/etc/sudoers
  echo "vmail ALL=NOPASSWD:/usr/libexec/dovecot/dovecot-lda" >>/etc/sudoers
fi

if
  [[ ${DIST_EL} -eq 7 ]] ||
    [[ ${DIST_EL} -eq 8 ]] ||
    [[ ${DIST_EL} -eq 9 ]]
then
  package_install "${TEXT_Installing} iptables" 'iptables-services'
fi

echo -n "${TEXT_Stopping_iptables} "
iptables -F >/dev/null 2>&1
iptables -S >/dev/null 2>&1
if [[ ${DIST_EL} -eq 6 ]]; then
  service iptables stop >/dev/null 2>&1
  chkconfig iptables off
elif
  [[ ${DIST_EL} -eq 7 ]] ||
    [[ ${DIST_EL} -eq 8 ]] ||
    [[ ${DIST_EL} -eq 9 ]]
then
  systemctl stop firewalld >/dev/null 2>&1
  systemctl disable firewalld
fi
echo "${TEXT_DONE}"

if
  [[ ${DIST_EL} -eq 7 ]] ||
    [[ ${DIST_EL} -eq 8 ]] ||
    [[ ${DIST_EL} -eq 9 ]]
then
  systemctl stop iptables >/dev/null 2>&1
  systemctl disable iptables
fi

crudini --set /etc/sysconfig/iptables-config '' IPTABLES_MODULES '"nf_conntrack_ftp nf_conntrack"'

do_checkconfig_operations

echo -n "${TEXT_Creating_Panilux_services} "

cp -Rf /panilux/www/cconfigs/default-www-index.html /sites/domains/default/www/index.html >/dev/null 2>&1
cp -Rf /panilux/www/favicon.png /sites/domains/default/www/ >/dev/null 2>&1
cp -Rf /panilux/www/favicon.ico /sites/domains/default/www/ >/dev/null 2>&1

mkdir -p /panilux/tmp /panilux/logs /panilux/cache /panilux/cache/sqls /panilux/cache/ngx_pagespeed >/dev/null 2>&1
chmod 777 -R /panilux/tmp /panilux/logs /panilux/cache >/dev/null 2>&1

touch /tmp/panilux_debug.log >/dev/null 2>&1
chmod 777 /tmp/panilux_debug.log >/dev/null 2>&1
echo "${TEXT_DONE}"

echo -n "${TEXT_Creating_certificates}"
/panilux/bin/create-cert.sh default >/dev/null 2>&1
RET1=$?
echo -n "."
/panilux/bin/create-cert.sh postfix >/dev/null 2>&1
RET2=$?
echo -n "."
/panilux/bin/create-cert.sh dovecot >/dev/null 2>&1
RET3=$?
echo -n "."

if
  [[ ${RET1} -ne 0 ]]
  [[ ${RET2} -ne 0 ]]
  [[ ${RET3} -ne 0 ]]
then
  echo "${TEXT_FAIL}"
  do_cleanup
else
  mv /sites/ssls/postfix.* /sites/ssls/postfix/
  mv /sites/ssls/dovecot.* /sites/ssls/dovecot/
fi

(openssl dhparam -out /etc/nginx/dhparam.pem 2048 >/dev/null 2>&1) &
spinner $!
echo "${TEXT_DONE}"

echo -n "${TEXT_Installing_WordPress_CLI}"
wget -P /panilux/bin/ https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar >/dev/null 2>&1
RET=$?
mv /panilux/bin/wp-cli.phar /panilux/bin/wp
chmod 777 /panilux/bin/wp
echo "${TEXT_DONE}"

postmap /etc/postfix/transport >/dev/null 2>&1

touch /etc/postfix/virtual_regexp >/dev/null 2>&1

echo -n "${TEXT_Checking_Panilux} "
/panilux/bin/panilux stop >/dev/null 2>&1
RET=$?
if [[ ${RET} -ne 0 ]]; then
  echo "${TEXT_FAIL}"
  do_cleanup
else
  echo "${TEXT_DONE}"
fi

echo -n "${TEXT_Starting_Panilux} "
/panilux/bin/panilux start >/dev/null 2>&1
RET=$?
if [[ ${RET} -ne 0 ]]; then
  echo "${TEXT_FAIL}"
  do_cleanup
else
  echo "${TEXT_DONE}"
fi

service_stop "mongod"
service_start "mongod"

echo -n "${TEXT_Configuring_Mongo_user} "
/panilux/bin/mongo_grant_service_users.php >/dev/null 2>&1
RET=$?
if [[ ${RET} -ne 0 ]]; then
  echo "${TEXT_FAIL}"
  do_cleanup
else
  echo "${TEXT_DONE}"
fi

echo "service_restart mongod"
service_restart "mongod"

echo "/panilux/www/bin/import_mongo.php"
/panilux/www/bin/import_mongo.php >/dev/null 2>&1

echo -n "${TEXT_Configuring_Mongo_service} "
/panilux/bin/api mongod-reconfigure >/dev/null 2>&1
RET=$?
if [[ ${RET} -ne 0 ]]; then
  echo "${TEXT_FAIL}"
  do_cleanup
else
  echo "${TEXT_DONE}"
fi

echo "${TEXT_Configuring_MySQL_service} "

service mysqld restart >/dev/null 2>&1

/panilux/bin/mysql_grant_service_users.php >/dev/null 2>&1
RET_CODE=$?
#	echo RET_CODE
echo 'OK'

echo -n "${TEXT_Configuring_Quota} "
(/panilux/bin/api quota-install >/dev/null 2>&1) &
spinner $!
/panilux/bin/api quota-check >/dev/null 2>&1
/panilux/bin/api quota-fix >/dev/null 2>&1
echo "${TEXT_DONE}"

service_stop "nginx"
service_stop "crond"

service postfix restart >/dev/null 2>&1
service_start "postfix"

service dovecot restart >/dev/null 2>&1
service_start "dovecot"

service spamassassin restart >/dev/null 2>&1
service_start "spamassassin"

[[ ! -e /var/run/saslauthd ]] && mkdir /var/run/saslauthd >/dev/null 2>&1

service saslauthd restart >/dev/null 2>&1
service_start "saslauthd"

#service postgrey restart >/dev/null 2>&1
#service_start "postgrey"

#service opendkim restart >/dev/null 2>&1
#service_start "opendkim"

service pure-ftpd restart >/dev/null 2>&1
service_start "pure-ftpd"

service memcached restart >/dev/null 2>&1
service_start "memcached"

service_start "mysqld"

echo -n "${TEXT_Configuring_PHP_ini} "
crudini --set /etc/php.ini PHP expose_php Off
crudini --set /etc/php.ini PHP short_open_tag On
crudini --set /etc/php.ini PHP post_max_size 500M
crudini --set /etc/php.ini PHP upload_max_filesize 500M
crudini --set /etc/php.ini PHP memory_limit 512M
crudini --set /etc/php.ini Session session.save_path '"/tmp/php_sessions"'

crudini --set /etc/sysconfig/memcached '' 'MAXCONN' '"2000"'
crudini --set /etc/sysconfig/memcached '' 'CACHESIZE' '"4096"'
crudini --set /etc/sysconfig/memcached '' 'OPTIONS' '"-l 127.0.0.1"'

if
  [[ ${DIST_EL} -eq 7 ]] ||
    [[ ${DIST_EL} -eq 8 ]] ||
    [[ ${DIST_EL} -eq 9 ]]
then
  mkdir /etc/systemd/system/php-fpm.service.d >/dev/null 2>&1
  echo -e "[Service]\nPrivateTmp=no" >/etc/systemd/system/php-fpm.service.d/privatetmp.conf
  mkdir /etc/systemd/system/nginx.service.d >/dev/null 2>&1
  echo -e "[Service]\nPrivateTmp=no" >/etc/systemd/system/nginx.service.d/privatetmp.conf
  mkdir /etc/systemd/system/dovecot.service.d >/dev/null 2>&1
  echo -e "[Service]\nPrivateTmp=no" >/etc/systemd/system/dovecot.service.d/privatetmp.conf
  mkdir /etc/systemd/system/postfix.service.d >/dev/null 2>&1
  echo -e "[Service]\nPrivateTmp=no" >/etc/systemd/system/postfix.service.d/privatetmp.conf
  systemctl daemon-reload >/dev/null 2>&1
  systemctl restart php-fpm >/dev/null 2>&1
  systemctl restart nginx >/dev/null 2>&1
  systemctl restart postfix >/dev/null 2>&1
  systemctl restart dovecot >/dev/null 2>&1
fi

mkdir -p /tmp/php_sessions >/dev/null 2>&1
chmod 777 -R /tmp/php_sessions >/dev/null 2>&1

echo "${TEXT_DONE}"

/panilux/bin/api server-init_panilux >/dev/null 2>&1
/panilux/bin/api web-reconfigure >/dev/null 2>&1
/panilux/bin/api dns-reconfigure >/dev/null 2>&1
/panilux/bin/api iptables-reconfigure >/dev/null 2>&1

touch /sites/logs/mysqld.log >/dev/null 2>&1
chown mysql.mysql /sites/logs/mysqld.log >/dev/null 2>&1

if
  [[ ${DIST_EL} -eq 7 ]] ||
    [[ ${DIST_EL} -eq 8 ]] ||
    [[ ${DIST_EL} -eq 9 ]]
then
  echo -n "${TEXT_Configuring_Network}"
  systemctl start NetworkManager >/dev/null 2>&1
  systemctl enable NetworkManager >/dev/null 2>&1

  /panilux/bin/network_reconfigure "${ARCH}" >/dev/null 2>&1
  echo "${TEXT_DONE}"
fi

IP_ADDRESS=$(hostname -I | cut -d\  -f1)

if [[ -f /panilux/www/conf.ini ]]; then
  PANEL_PORT=$(crudini --get /panilux/www/conf.ini 'panilux' 'panel_port')
else
  PANEL_PORT=1453
fi

if [[ ${DIST_EL} -eq 7 ]]; then
  echo
  echo "${TEXT_Important_Warning}: ${TEXT_Cant_activate_quota_on_xfs_disk_Please_reboot_server_before_proceeding_to_setup}"
  echo
fi

echo
echo "${TEXT_Panilux_is_installed_successfuly}"
echo "${TEXT_Please_visit_Panilux_Panel_to_finalize_your_installation}"
echo "https://${IP_ADDRESS}:${PANEL_PORT}"
echo
