#! /bin/bash

clear

function set_license_brainycp() {
	ip_get=$(wget -qO- http://core.brainycp.com/ipchecker.php)
	linux_date=$(date '+%m.%d.%y')
	time_record=$(date '+%Y-%m-%d %H:%I:%S')
	kernel_info=$(uname -a)
	
	if [ -f /etc/redhat-release ]; then
		get_osname=$(cat /etc/redhat-release | awk '{print tolower($1)}')
		os_relase=$(cat /etc/redhat-release | grep -Eo '[0-9]' | awk '{print $1}' | head -n1)
		virtall="$(virt-what)"
	else
		get_osname=$(cat /etc/os-release | grep -E '^NAME' | cut -d '=' -f2 | sed 's/\"//g' | xargs)
		os_relase=$(cat /etc/os-release | grep -E '^VERSION_ID' | cut -d '=' -f2 | sed 's/\"//g')
		virtall=''
	fi
	virttypez="$(dmidecode -s system-product-name 2>/dev/stdout| awk '{print $1}')"
	virttypexen="$(dmidecode | grep -i domU 2>/dev/stdout)"
	virttypemic="$(dmidecode | egrep -i 'manufacturer|product' 2>/dev/stdout)"

	if [[ $virtall = *"xen"* ]]; then
			virttype="xen"
		elif [[ $virtall = "lxc" ]];then
			virttype="xlc"
		elif [[ $virttypemic = "Product Name: HVM domU" ]];then
			virttype="microsoftvirtpc"
		elif [[ $virttypexen = "Product Name: HVM domU" ]];then
			virttype="xen"
		elif [[ $virttypez = "/dev/mem:" ]];then
			virttype="openvz"
		elif [[ $virttypez = "KVM" ]];then
			virttype="kvm"
		elif [[ $virttypez = "VMware" ]];then
			virttype="wmware"
		elif [[ $virttypez = "VirtualBox" ]];then
			virttype="virtualbox"
		elif [[ $virttypez = "Bochs" ]];then
			virttype="Bochs"
		else 
			virttype="baremetal"
	fi
	
	#for var in 'http://panelname.shn-host.com/check.php'
	for var in 'http://panelname.shn-host.ru/check.php' 'http://panelbr1.shn-host.ru/check.php' 'http://panelbr1u.s-host.net/check.php' 'http://panelbr2.shn-host.ru/check.php'
	do
		lic_mega_salt='kgj475yLH&I#@FJK!@J%Y#(*U&XDVJUS)(**U&)$*(U%()IJKDOVJOIU!@&*^$&*@HCG@YT&*DCSI@$$*()UODIVJMNKLJIkjhlkgjoi34uy5hiosdnjkljh8Y#*(HEU$^()*U@()&*($^Y(U*HDFjoh23i94ui5y9u8hgjkodfjh438yYGR&*9TYFBKL!&@Y'
		hash_license=$(echo "$ip_get$linux_date$lic_mega_salt$ip_get$linux_date" | openssl dgst -sha512 | awk '{print $2}')
		curl -X POST --connect-timeout 15 -d "ip_user=$ip_get&operation=install_softvare_license&date=$linux_date&paramin=$hash_license&time_record=$time_record&virttype=$virttype&get_osname=$get_osname&get_osver=$os_relase&kernel_info=$kernel_info" $var &>/dev/null
	done
}

if [[ -f /usr/share/zoneinfo/Europe/Kiev && ! -f /usr/share/zoneinfo/Europe/Kyiv ]]; then
    ln -s /usr/share/zoneinfo/Europe/Kiev /usr/share/zoneinfo/Europe/Kyiv
elif [[ -f /usr/share/zoneinfo/Europe/Kyiv && ! -f /usr/share/zoneinfo/Europe/Kiev ]]; then
    ln -s /usr/share/zoneinfo/Europe/Kyiv /usr/share/zoneinfo/Europe/Kiev
fi


#
# Terminates the program if it is not run with root privileges
# Return: null
assert_run_as_root() {
    if [[ $(id -u) -ne 0 ]]; then
        echo "This the script must be run as root"
        exit 2
    fi
}

# Reads a variable value from /etc/os-release
# Return: release name
get_os_release_version() {
    local -r var="${1}"
    local val
    if ! val="$(cat /etc/os-release 2>/dev/null | grep -i "^${var}" | cut -f 2 -d "=" | xargs)"; then
        echo "Error: ${var} is not found in /etc/os-release" >&2
        exit 1
    fi
    echo "${val}"
}

# Cheking OS version
# Return: null
check_os_version() {
    local -r os_type="${1}"
    if [[ "${os_type}" != "centos" ]] && [[ "${os_type}" != "ubuntu" ]] && [[ "${os_type}" != "almalinux" ]] && [[ "${os_type}" != "rocky" ]]
    then
        echo "Your system '${os_type}' is not supported."
        exit 1
    fi
}

###
#    main
###
d=$(dirname $0)
assert_run_as_root
os_type="$(get_os_release_version 'ID=')"
os_version="$(get_os_release_version 'VERSION_ID=')"

if ! [ -d /var/brainycp/ ]; then
        echo -e "Please Wait... "
        if [[ "${os_type}" == "ubuntu" ]] || [[ "${os_type}" == "debian" ]];then
	    apt-get update  &>/dev/null
	    apt-get -y install virt-what dmidecode &>/dev/null
	    apt-get install -y apt &>/dev/null
	else
	    yum -y install virt-what dmidecode &>/dev/null
	fi
#        if [ $? -eq 0 ]; then
#            echo -en "\033[1;32m [OK] \033[0m\n";tput sgr0
#        else
#            echo -e "\033[1;31m [ERROR] \033[0m\n";tput sgr0;exit 1
#        fi
	set_license_brainycp "${os_type}" "${os_version}"
fi

case "${os_type}" in
"ubuntu")
	apt-get update  &>/dev/null
        if [ "${os_version}" == "20.04" ];then
                echo 'System 20.04'
                echo -en "Loading of the shell... "
                apt-get install -y --force-yes wget &>/dev/null
                env DEBIAN_FRONTEND=noninteractive apt-get -y install openssh-server &>/dev/null
                if [ $? -eq 0 ]; then
                        echo -en "\033[1;32m [OK] \033[0m\n";tput sgr0
                else
                        echo -e "\033[1;31m [ERROR] \033[0m\n";tput sgr0
                        echo "There was an error in loading process of the installer."
                        exit 1
                fi
                apt-get install -y --force-yes wget &>/dev/null
                echo -en "Loading of the installer... "
                wget -t 2 http://core.brainycp.com/_installUbuntu.sh  &>/dev/null
                if [ $? -eq 0 ]; then
                        echo -en "\033[1;32m [OK] \033[0m\n";tput sgr0
                else
                        echo -e "\033[1;31m [ERROR] \033[0m\n";tput sgr0
                        exit 1
                fi
		. ${d}/_installUbuntu.sh
		chmod 0750 /usr/local/brainycp/ssh/*.php
		chmod 0750 /usr/local/brainycp/ssh/*.sh
		echo -e "Installation complete"
		exit 0
        elif [[ "${os_version}" == "22.04" ]] || [[ "${os_version}" == "22.10" ]];then
                echo 'System 22.04'
                echo -en "Loading of the shell... "
                apt-get install -y --force-yes wget &>/dev/null
                env DEBIAN_FRONTEND=noninteractive apt-get -y install openssh-server &>/dev/null
                if [ $? -eq 0 ]; then
                        echo -en "\033[1;32m [OK] \033[0m\n";tput sgr0
                else
                        echo -e "\033[1;31m [ERROR] \033[0m\n";tput sgr0
                        echo "There was an error in loading process of the installer."
                        exit 1
                fi
                echo -en "Loading of the installer... "
                wget -t 2 http://core.brainycp.com/_installUbuntu_22  &>/dev/null
                if [ $? -eq 0 ]; then
                        echo -en "\033[1;32m [OK] \033[0m\n";tput sgr0
                else
                        echo -e "\033[1;31m [ERROR] \033[0m\n";tput sgr0
                        echo "There was an error in loading process of the installer."
                        exit 1
                fi
		chmod 0700 ${d}/_installUbuntu_22
		${d}/_installUbuntu_22 "${1}"
		if [ $? -ne 0 ];then
		    /bin/rm -f ${d}/_installUbuntu_22 &>/dev/null
		    echo "There was an error at installation. Installation process was stopped."
		    exit 1
		fi
		/bin/rm -f ${d}/_installUbuntu_22 &>/dev/null
		touch ${d}/install_ubuntu_22.txt
		brainy-core -s auto &>brainy_core.log
		apt-get -y install zip &>/dev/null
		chmod 0750 /usr/local/brainycp/ssh/*.php
		chmod 0750 /usr/local/brainycp/ssh/*.sh
		echo -e "Installation complete"
		exit 0
        elif [[ "${os_version}" == "24.04" ]];then
                echo 'System 24.04'
                apt-get install -y --force-yes wget &>/dev/null
                echo -en "Loading of the shell... "
                apt-get install -y --force-yes wget &>/dev/null
                env DEBIAN_FRONTEND=noninteractive apt-get -y install openssh-server &>/dev/null
                if [ $? -eq 0 ]; then
                        echo -en "\033[1;32m [OK] \033[0m\n";tput sgr0
                else
                        echo -e "\033[1;31m [ERROR] \033[0m\n";tput sgr0
                        echo "There was an error in loading process of the installer."
                        exit 1
                fi
                echo -en "Loading of the installer... "
                wget -t 2 http://core.brainycp.com/_installUbuntu24.sh  &>/dev/null
                if [ $? -eq 0 ]; then
                        echo -en "\033[1;32m [OK] \033[0m\n";tput sgr0
                else
                        echo -e "\033[1;31m [ERROR] \033[0m\n";tput sgr0
                        echo "There was an error in loading process of the installer."
			echo -e "Installation complete"
                        exit 1
                fi
#		chmod 0700 ${d}/_installUbuntu_24
#		${d}/_installUbuntu_24 "${1}"
		. ${d}/_installUbuntu24.sh
		brainy-core -s auto &>brainy_core.log
		apt-get -y install zip &>/dev/null
		chmod 0750 /usr/local/brainycp/ssh/*.php
		chmod 0750 /usr/local/brainycp/ssh/*.sh
		echo -e "Installation complete"
		exit 0
        else
                echo "Error: your os version Ubuntu ${os_version} is not supported!"
                exit 1
        fi
        exit 1
        ;;
"debian")
        if [ "${os_version}" == "10" ];then
                echo 'System Debian 10'
                echo "Please wait... "
                apt-get --allow-releaseinfo-change update &>/dev/null
                apt-get update &>/dev/null
                apt-get install -y --force-yes wget &>/dev/null
                echo -en "Detected Download install script... "
                wget -t 2 http://core.brainycp.com/_installDebian10.sh  &>/dev/null
                if [ $? -eq 0 ]; then
                        echo -en "\033[1;32m [OK] \033[0m\n";tput sgr0
                else
                        echo -e "\033[1;31m [ERROR] \033[0m\n";tput sgr0
                        exit 1
                fi
                ##/usr/bin/bash ${d}/_installDebian10.sh "$1"
		. ${d}/_installDebian10.sh
        else
                echo "Error: your os version Debian ${os_version} is not supported!"
        fi

        exit 0
        ;;
"centos")
        if [[ "${os_version}" == "7" ]] || [[ "${os_version}" == "8" ]];then
                echo ''
                echo -e "Your version of the CentOS ${os_version} system is not supported!"
                echo -e "Please use AlmaLinux 8 or 9"
                exit 1
        fi

        echo "Error: Your version of the CentOS ${os_version} system is not supported!"
        exit 1
        ;;
"almalinux")
        if [[ "${os_version}" == "10.1" ]];then
                echo ""
                echo -en "Updating of scripts for AlmaLinux ${os_version}... "
                #rpm -e --nodeps centos-repos  &>/dev/null
                #rpm -e --nodeps centos-linux-repos  &>/dev/null
		rpm -Uv --replacepkgs http://core.brainycp.com/repo/repo-brainy-v3b-10.0-1.brainy.el10.noarch.rpm  &>/dev/null
                if [ $? -eq 0 ]; then
                        echo -en "\033[1;32m [OK] \033[0m\n";tput sgr0
                else
                        echo -e "\033[1;31m [ERROR] \033[0m\n";tput sgr0
                        exit 1
                fi
		yum clean all &>/dev/null

                echo -en "Updating of tools for the virtulny environment... "
		yum -y install virt-what dmidecode &>/dev/null
		yum -y install openssh-server &>/dev/null
                if [ $? -eq 0 ]; then
                        echo -en "\033[1;32m [OK] \033[0m\n";tput sgr0
                else
                        echo -e "\033[1;31m [ERROR] \033[0m\n";tput sgr0
                        exit 1
                fi
        elif [[ "${os_version}" == "10.0" ]];then
                echo ""
                echo -e "THE INSTALLER OF BRAINYCP ISSUED THE REPORT"
                echo -e "============================================="
                echo -e "Attention! Your version of AlmaLinux ${os_version} became outdated!"
                echo -e "Please, update to the last release by means of the commands shown below:"
                echo -e ""
                echo -e "   yum clean all && yum -y update"
                echo -e ""
                echo -e "After updating your system, run the installation script again.\n"
                exit 1
        elif [[ "${os_version}" == "9.7" ]];then
                echo ""
                echo -en "Updating of scripts for AlmaLinux ${os_version}... "
                #rpm -e --nodeps centos-repos  &>/dev/null
                #rpm -e --nodeps centos-linux-repos  &>/dev/null
		rpm -Uv --replacepkgs http://core.brainycp.com/repo/alma-brainy-repo-v3-9.0-2.el9.noarch.rpm  &>/dev/null
                if [ $? -eq 0 ]; then
                        echo -en "\033[1;32m [OK] \033[0m\n";tput sgr0
                else
                        echo -e "\033[1;31m [ERROR] \033[0m\n";tput sgr0
                        exit 1
                fi
		yum clean all &>/dev/null

                echo -en "Updating of tools for the virtulny environment... "
		yum -y install virt-what dmidecode &>/dev/null
		yum -y install openssh-server &>/dev/null
                if [ $? -eq 0 ]; then
                        echo -en "\033[1;32m [OK] \033[0m\n";tput sgr0
                else
                        echo -e "\033[1;31m [ERROR] \033[0m\n";tput sgr0
                        exit 1
                fi
        elif [[ "${os_version}" == "9.0" ]] || [[ "${os_version}" == "9.1" ]] || [[ "${os_version}" == "9.2" ]] || [[ "${os_version}" == "9.3" ]] || [[ "${os_version}" == "9.4" ]] || [[ "${os_version}" == "9.5" ]] || [[ "${os_version}" == "9.6" ]];then
                echo ""
                echo -e "THE INSTALLER OF BRAINYCP ISSUED THE REPORT"
                echo -e "============================================="
                echo -e "Attention! Your version of AlmaLinux ${os_version} became outdated!"
                echo -e "Please, update to the last release by means of the commands shown below:"
                echo -e ""
                echo -e "   yum clean all && yum -y update"
                echo -e ""
                echo -e "After updating your system, run the installation script again.\n"
                exit 1
        elif [[ "${os_version}" == "8.0" ]] || [[ "${os_version}" == "8.1" ]] || [[ "${os_version}" == "8.2" ]] || [[ "${os_version}" == "8.6" ]] || [[ "${os_version}" == "8.7" ]];then
    		yum clean all &>/dev/null
    		rpm --import https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux
                echo ''
                echo -e "THE INSTALLER OF BRAINYCP ISSUED THE REPORT"
                echo -e "============================================="
                echo -e "Attention! Your version of AlmaLinux ${os_version} became outdated!"
                echo -e "Please, update to the last release by means of the commands shown below:"
                echo -e ""
                echo -e "   yum clean all && yum -y update"
                echo -e ""
                echo -e "After updating your system, run the installation script again.\n"
                exit 1
        elif [[ "${os_version}" == "8.8" ]] || [[ "${os_version}" == "8.9" ]];then
		yum clean all &>/dev/null
    		rpm --import https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux
                echo ''
                echo -e "THE INSTALLER OF BRAINYCP ISSUED THE REPORT"
                echo -e "============================================="
                echo -e "Attention! Your version of AlmaLinux ${os_version} became outdated!"
                echo -e "Please, update to the last release by means of the commands shown below:"
                echo -e ""
                echo -e "   yum clean all && yum -y update"
                echo -e ""
                echo -e "After updating your system, run the installation script again.\n"
                exit 1
#        else
#                echo ''
#                echo -e "Your version ${os_version} is not supported!"
#                exit 1
        fi
        ;;
"rocky")
        if [[ "${os_version}" == "9.0" ]] || [[ "${os_version}" == "9.1" ]] || [[ "${os_version}" == "9.2" ]] || [[ "${os_version}" == "9.3" ]] || [[ "${os_version}" == "9.4" ]] || [[ "${os_version}" == "9.5" ]];then
                echo ''
                echo -en "Update repo scripts for Rocky Linux 9... "
		rpm -Uv --replacepkgs http://core.brainycp.com/repo/alma-brainy-repo-v3-9.0-2.el9.noarch.rpm  &>/dev/null
                if [ $? -eq 0 ]; then
                        echo -en "\033[1;32m [OK] \033[0m\n";tput sgr0
                else
                        echo -e "\033[1;31m [ERROR] \033[0m\n";tput sgr0
                        exit 1
                fi
		yum clean all &>/dev/null

                echo -en "Update virtual tools... "
		yum -y install virt-what dmidecode &>/dev/null
                if [ $? -eq 0 ]; then
                        echo -en "\033[1;32m [OK] \033[0m\n";tput sgr0
                else
                        echo -e "\033[1;31m [ERROR] \033[0m\n";tput sgr0
                        exit 1
                fi
        else
                echo ''
                echo -e "Your version Rocky Linux ${os_version} is not supported!"
                exit 1
        fi
        ;;
esac

## FIXME: test
k=`uname -r`
if [[ "${k}" == *".vz7."* ]]; then
    echo "Detected your kernel = 3.10.xx.vz7 Please, install panel for OPENVZ Ver.3 as shown below."
    echo -e "\n\033[1;37myum clean all && yum install -y wget && wget http://core.brainycp.com/openvz3.sh && bash ./openvz3.sh\033[0m\n";tput sgr0
    vopenvz="yes"
    exit
fi

get_osname_org=`cat /etc/redhat-release | awk '{print $1}'`
v8=`cat /etc/redhat-release | grep -oE '[0-9.]'| sed ':a;N;$!ba;s/\n//g' | cut -c 1`
v10=`cat /etc/redhat-release | grep -oE '[0-9.]'| sed ':a;N;$!ba;s/\n//g' | cut -f1 -d '.'`
srvname=`hostname`
srvip=`hostname -I`
default_lang="ru"

dip=`ip a s | grep inet | grep dynamic | xargs`
TOTALFILE="/proc/meminfo"
if [ -f $TOTALFILE ]; then
    memtotal=`cat /proc/meminfo | grep MemTotal: | xargs | cut -f2 -d' '`
    swaptotal=`cat /proc/meminfo | grep SwapTotal: | xargs | cut -f2 -d' '`
fi
if [[ "$v8" == "8" ]];then
  echo "";
  rpm -Uv --replacepkgs http://brainyrepo1.brainycp.com/centos/8_brainy_v3/x86_64/brainy-config-0.1b-1.brainy.el8.x86_64.rpm &>/dev/null
  export LANG=koi8-r
elif [[ "$v8" == "9" ]];then
  echo "";
  rpm -Uv --replacepkgs http://brainyrepo1.brainycp.com/centos/8_brainy_v3/x86_64/brainy-config-0.1b-1.brainy.el8.x86_64.rpm &>/dev/null
  export LANG=koi8-r
else
  echo "";
  rpm -Uv --replacepkgs http://brainyrepo1.brainycp.com/centos/7/x86_64/brainy-config-0.1b-1.brainy.el7.x86_64.rpm &>/dev/null
  export LANG=koi8-r
fi

#/usr/bin/brnconfig
#if [ $? -eq 0 ];then
#  echo "Abort installation."
#  exit 0
#fi

# Run process
#clear
#echo "Continued installation..."

osRhl="no"
osDebian="no"
osUbuntu="no"
vopenvz="no"

# Check that we are root ... so non-root users stop here
if [ "$EUID" -ne 0 ]
  then echo "Please run as root. Abort."
  exit
fi

#
# Check kernel version
#
k=`uname -r`
if [ "${k:0:2}" == "2." ]; then
    echo "Detected your kernel < 3.xx. Please, install panel for OPENVZ Ver.3 as shown below."
    echo -e "\033[1;37myum clean all && yum install -y wget && wget http://core.brainycp.com/openvz3.sh && bash ./openvz3.sh\033[0m\n";tput sgr0
    vopenvz="yes"
    exit
fi

if [ "${k:0:20}" == "3.10.0-862.11.6.vz7." ]; then
    echo "Detected your kernel = 3.10.xx.vz7 Please, install panel for OPENVZ Ver.3 as shown below."
    echo -e "\033[1;37myum clean all && yum install -y wget && wget http://core.brainycp.com/openvz3.sh && bash ./openvz3.sh\033[0m\n";tput sgr0
    vopenvz="yes"
    exit
fi

if [ "${k:0:21}" == "3.10.0-1062.12.1.vz7." ]; then
    echo "Detected your kernel = 3.10.xx.vz7 Please, install panel for OPENVZ Ver.3 as shown below."
    echo -e "\n\033[1;37myum clean all && yum install -y wget && wget http://core.brainycp.com/openvz3.sh && bash ./openvz3.sh\033[0m\n";tput sgr0
    vopenvz="yes"
    exit
fi

if [ "${k:0:12}" == "5.4.55-1-pve" ]; then
    echo "Detected your kernel = 5.4.xx.vz7 Please, install panel for LXC Ver.3 as shown below."
    echo -e "\033[1;37myum clean all && yum install -y wget && wget http://core.brainycp.com/openvz3.sh && bash ./openvz3.sh\033[0m\n";tput sgr0
    vopenvz="yes"
    exit
fi

##Checking vz
if [[ "${k}" == *".vz7."* ]]; then
    echo "Detected your kernel = 3.10.xx.vz7 Please, install panel for OPENVZ Ver.3 as shown below."
    echo -e "\n\033[1;37myum clean all && yum install -y wget && wget http://core.brainycp.com/openvz3.sh && bash ./openvz3.sh\033[0m\n";tput sgr0
    vopenvz="yes"
    exit
fi


#
# VIRT TYPE
#
yum -y install virt-what dmidecode &>/dev/null

function get_virt_lxc() {
    virtall="$(virt-what)"
    virttypez="$(dmidecode -s system-product-name 2>/dev/stdout| awk '{print $1}')"
    virttypexen="$(dmidecode | grep -i domU 2>/dev/stdout)"
    virttypemic="$(dmidecode | egrep -i 'manufacturer|product' 2>/dev/stdout)"

    if [[ $virtall = "lxc" ]];then
        virttype="lxc"
    elif [[ $virtall = "openvz" ]];then
        virttype="openvz"
    elif [[ $virttypez = "/dev/mem:" ]];then
        virttype="openvz"
    else
        virttype="PASS"
fi

echo $virttype
}
#
# END VIRT TYPE
#

PWD_L=`pwd`
#echo "PWD is '$PWD'"

vtype="$(get_virt_lxc)"
if [[ $vtype = "lxc" ]];then
    echo "LXC no support for v3. Run the installer for OpenVZ as shown below."
    vopenvz="yes"
#    exit
fi

vtype="$(get_virt_lxc)"
if [[ $vtype = "openvz" ]];then
    echo "OpenVZ no support for v3. Run the installer for OpenVZ as shown below."
    vopenvz="yes"
#    exit
fi

echo "Virtualization test: "$vtype
echo ""
echo "*******  THE INSTALLER BRAINYCP CORE v3.02  *******"
echo ""

d=$(dirname $0)

if [ -f "/usr/local/brainycp/license" ]; then
    echo "The panel is already installed."
    exit 1
fi

ARRD="http://core.brainycp.com"

##
## RedHat
##
if [ -f "/etc/redhat-release" ]; then
    yum install -y polkit &>/dev/null
    systemctl restart polkit &>/dev/null

    v8=`cat /etc/redhat-release | grep -oE '[0-9.]'| sed ':a;N;$!ba;s/\n//g' | cut -c 1`
    if [[ "$v8" == "8" ]];then

	    yum clean all &>/dev/null
	    yum -y install rpm dnf yum python3-rpm &>/dev/null

	    # Show server params
	    echo -e "Detected OS Version: \033[1;32m${get_osname_org} ${v8} \033[0m";tput sgr0
	    echo -e "Detected Server Name: \033[1;32m${srvname} \033[0m";tput sgr0
	    echo -e "Detected Server IP: \033[1;32m${srvip} \033[0m";tput sgr0
	    if [ -f $TOTALFILE ]; then
    		    echo -e "Detected Server RAM memory: \033[1;32m${memtotal} KB\033[0m";tput sgr0
    		    echo -e "Detected Server SWAP memory: \033[1;32m${swaptotal} KB\033[0m";tput sgr0
	    fi

	    sys_err_swap="no"
	    sys_err_dhcp="no"
	    if [ -f $TOTALFILE ]; then
    		    echo -n "Checking RAM size... "
    		    if [ "${memtotal}" -ge "900000" ]; then
    			echo -en "\033[1;32mPASS \033[0m\n";tput sgr0
    		    else
    			echo -en "\033[1;31mFAIL \033[0m\n";tput sgr0
    			echo "There is not enough RAM on your server. A minimum of 900MB is required. Aborted.";echo ""
    			exit -1
		    fi

		    echo -n "Checking SWAP size... "
    		    if [ "${swaptotal}" -ge "2000000" ]; then
    			echo -en "\033[1;32mPASS \033[0m\n";tput sgr0
    		    else
    			echo -en "\033[1;31mFAIL \033[0m\n";tput sgr0
    			sys_err_swap="yes"
    			#echo "There is not enough SWAP on your server. A minimum of 2G is required. Aborted.";echo ""
    			#exit -1
    		    fi
	    fi

	    #DHCP
	    echo -n "Checking type IP address... "
	    if [[ "${dip}" == *"dynamic"* ]];then
    		    echo -en "\033[1;31mFAIL \033[0m\n";tput sgr0
    		    sys_err_dhcp="yes"
    		    #echo "Your IP address is of a dynamic type (DHCP), but you need a static one. Aborted.";echo ""
    		    #exit 1
	    else
    		    echo -en "\033[1;32mPASS \033[0m\n";tput sgr0
	    fi

	    #err
	    if [[ "${sys_err_swap}" == "yes" || "${sys_err_dhcp}" == "yes" ]];then
    		    echo ""
    		    echo "The following issues were found:"
	    fi
	    if [[ "${sys_err_swap}" == "yes" ]];then
    		    echo " *) There is not enough SWAP on your server. A minimum of 2G is required."
    		    echo "    The absence or insufficient volume of this section can lead to unstable operation of the Panel or its services."
	    fi
	    if [[ "${sys_err_dhcp}" == "yes" ]];then
    		    echo " *) Your IP address is of a dynamic type (DHCP), but you need a static one."
    		    echo "    A dynamic address of a network interface can lead to incorrect operation of some services, "
    		    echo "    for example, issuing certificates. And also, disrupting the installation process itself."
	    fi

	    if [[ "${sys_err_swap}" == "yes" || "${sys_err_dhcp}" == "yes" ]];then
    		    echo ""
    		    echo "Please also note that technical support cannot help you until you fix these problems."
	    fi

	    if [[ "${sys_err_swap}" == "yes" || "${sys_err_dhcp}" == "yes" ]];then
    		    echo ""
    		    while true; do
        		read -p "Continue installation? {y/n}: " yn
        		case $yn in
            			[Yy]* ) echo "Continue and ignore these errors."; break;;
            			[Nn]* ) echo "Abort the installation process and exit."; exit;;
            			* ) echo "Please answer yes or no.";;
        		esac
    		    done
	    fi

	    echo -en "Download install script... "
	    yum install -y wget &>/dev/null

	    #remove old
	    /bin/rm -f ${d}/_installCentos_t01v8.sh &>/dev/null
	    wget -t 2  $ARRD/_installCentos_t01v8.sh &>/dev/null
	    if [ $? -eq 0 ]; then
		result=0
		echo -en "\033[1;32m [OK] \033[0m\n"
		tput sgr0
	    else
		result=1
		echo -e "\033[1;31m [ERROR] \033[0m\n"
		tput sgr0 
		echo -e "Please. Download new script for install. wget http://core.brainycp.com/install.sh"
		exit
	    fi

. ${d}/_installCentos_t01v8.sh
#. ${PWD_L}/_checkpkg.sh -u auto
	    brainy-core -s auto

	    #PWD_L=`pwd`
	    #echo "PWD is '$PWD_L'"
	    chmod 0750 /usr/local/brainycp/ssh/*.php
	    chmod 0750 /usr/local/brainycp/ssh/*.sh

	    echo -e "\n\n\033[1;34m BrainyCP was successfully installed! \033[0m\n\n";tput sgr0
	    echo -e "\nBy using this product you completely accept License Agreement - https://brainycp.com/license_agreement\n"
	    echo -e "To use it:\n"
	    echo -e "http://"$ip_serv":8002 or https://"$ip_serv":8000\n"
	    echo -e "username: root"
	    echo -e "password: YOUR ROOT PASSWORD"
	    echo ""
	    echo -e "\033[1;31m 1) WARNING!!! Kernel updated successfully. Please, reboot your system! \033[0m\n";tput sgr0

	    #
	    #sync ; echo 1 > /proc/sys/vm/drop_caches
	    exit 0

    fi
    # END 8

    # BEGIN 9
    if [[ "${v8}" == "9" ]]; then
	    echo ""
	    #echo -e "\033[1;31m Your system is not supported! \033[0m\n";tput sgr0
	    #exit 0

	    yum clean all &>/dev/null
	    yum -y install rpm dnf yum python3-rpm &>/dev/null

	    # Show server params
	    echo -e "Detected OS Version: \033[1;32m${get_osname_org} ${v8} \033[0m";tput sgr0
	    echo -e "Detected Server Name: \033[1;32m${srvname} \033[0m";tput sgr0
	    echo -e "Detected Server IP: \033[1;32m${srvip} \033[0m";tput sgr0
	    if [ -f $TOTALFILE ]; then
    		    echo -e "Detected Server RAM memory: \033[1;32m${memtotal} KB\033[0m";tput sgr0
    		    echo -e "Detected Server SWAP memory: \033[1;32m${swaptotal} KB\033[0m";tput sgr0
	    fi

	    sys_err_swap="no"
	    sys_err_dhcp="no"
	    if [ -f $TOTALFILE ]; then
    		    echo -n "Checking RAM size... "
    		    if [ "${memtotal}" -ge "900000" ]; then
    			echo -en "\033[1;32mPASS \033[0m\n";tput sgr0
    		    else
    			echo -en "\033[1;31mFAIL \033[0m\n";tput sgr0
    			echo "There is not enough RAM on your server. A minimum of 900MB is required. Aborted.";echo ""
    			exit 1
		    fi

		    echo -n "Checking SWAP size... "
    		    if [ "${swaptotal}" -ge "2000000" ]; then
    			echo -en "\033[1;32mPASS \033[0m\n";tput sgr0
    		    else
    			echo -en "\033[1;31mFAIL \033[0m\n";tput sgr0
    			sys_err_swap="yes"
    			#echo "There is not enough SWAP on your server. A minimum of 2G is required. Aborted.";echo ""
    			#exit 1
    		    fi
	    fi

	    #DHCP
	    echo -n "Checking type IP address... "
	    if [[ "${dip}" == *"dynamic"* ]];then
    		    echo -en "\033[1;31mFAIL \033[0m\n";tput sgr0
    		    sys_err_dhcp="yes"
    		    #echo "Your IP address is of a dynamic type (DHCP), but you need a static one. Aborted.";echo ""
    		    #exit 1
	    else
    		    echo -en "\033[1;32mPASS \033[0m\n";tput sgr0
	    fi

	    #err
	    if [[ "${sys_err_swap}" == "yes" || "${sys_err_dhcp}" == "yes" ]];then
    		    echo ""
    		    echo "The following issues were found:"
	    fi
	    if [[ "${sys_err_swap}" == "yes" ]];then
    		    echo " *) There is not enough SWAP on your server. A minimum of 2G is required."
    		    echo "    The absence or insufficient volume of this section can lead to unstable operation of the Panel or its services."
	    fi
	    if [[ "${sys_err_dhcp}" == "yes" ]];then
    		    echo " *) Your IP address is of a dynamic type (DHCP), but you need a static one."
    		    echo "    A dynamic address of a network interface can lead to incorrect operation of some services, "
    		    echo "    for example, issuing certificates. And also, disrupting the installation process itself."
	    fi

	    if [[ "${sys_err_swap}" == "yes" || "${sys_err_dhcp}" == "yes" ]];then
    		    echo ""
    		    echo "Please also note that technical support cannot help you until you fix these problems."
	    fi

	    if [[ "${sys_err_swap}" == "yes" || "${sys_err_dhcp}" == "yes" ]];then
    		    echo ""
    		    while true; do
        		read -p "Continue installation? {y/n}: " yn
        		case $yn in
            			[Yy]* ) echo "Continue and ignore these errors."; break;;
            			[Nn]* ) echo "Abort the installation process and exit."; exit;;
            			* ) echo "Please answer yes or no.";;
        		esac
    		    done
	    fi

	    echo -en "Download install script... "
	    yum install -y wget &>/dev/null
	    # remove old
	    if [ "${os_type}" == "rocky" ];then
		/bin/rm -f ${d}/_installRocky_9_3 &>/dev/null
		wget -t 2  $ARRD/_installRocky_9_3 &>/dev/null
	    else
		/bin/rm -f ${d}/_installAlma_9_3 &>/dev/null
		wget -t 2  $ARRD/_installAlma_9_3 &>/dev/null
	    fi
	    if [ $? -eq 0 ]; then
		result=0
		echo -en "\033[1;32m [OK] \033[0m\n";tput sgr0
	    else
		result=1
		echo -e "\033[1;31m [ERROR] \033[0m\n";tput sgr0
		echo -e "Please. Download new script for install. wget http://core.brainycp.com/install.sh"
		exit 1
	    fi

	    if [ "${os_type}" == "rocky" ];then
		chmod 0700 ${d}/_installRocky_9_3
		${d}/_installRocky_9_3 "${1}"
		/bin/rm -f ${d}/_installRocky_9_3 &>/dev/null
		touch ${d}/install_rocky_9.txt
	    else
		chmod 0700 ${d}/_installAlma_9_3
		${d}/_installAlma_9_3 "${1}"
		/bin/rm -f ${d}/_installAlma_9_3 &>/dev/null
		touch ${d}/install_alma_9.txt
	    fi
	    if [[ -f "/usr/local/brainycp/index.php" ]];then
		brainy-core -s auto &>brainy_core.log
		chmod 0750 /usr/local/brainycp/ssh/*.php
		chmod 0750 /usr/local/brainycp/ssh/*.sh
	    else
		echo -e "Fatal error. Abort"
	    fi
	    exit 0
    fi
    # END 9

    # BEGIN 10
    if [[ "${v10}" == "10" ]]; then
            echo ""
            #echo -e "\033[1;31m Your system is not supported! \033[0m\n";tput sgr0
            #exit 0

            echo -en "System update. Please wait... "
            yum clean all &>/dev/null
            #yum -y install rpm dnf yum python3-rpm openssl python3-dnf &>/dev/null
            yum -y update &>/dev/null
            if [ $? -eq 0 ]; then
        	#result=0
                echo -en "\033[1;32m [OK] \033[0m\n";tput sgr0
            else
                #result=1
                echo -e "\033[1;31m [ERROR] \033[0m\n";tput sgr0
        	exit
            fi

            #yum -y install rpm dnf yum python3-rpm openssl &>/dev/null

            # Show server params
            echo -e "Detected OS Version: \033[1;32m${get_osname_org} ${v10} \033[0m";tput sgr0
            echo -e "Detected Server Name: \033[1;32m${srvname} \033[0m";tput sgr0
            echo -e "Detected Server IP: \033[1;32m${srvip} \033[0m";tput sgr0
            if [ -f $TOTALFILE ]; then
                    echo -e "Detected Server RAM memory: \033[1;32m${memtotal} KB\033[0m";tput sgr0
                    echo -e "Detected Server SWAP memory: \033[1;32m${swaptotal} KB\033[0m";tput sgr0
            fi

            sys_err_swap="no"
            sys_err_dhcp="no"
            if [ -f $TOTALFILE ]; then
                    echo -n "Checking RAM size... "
                    if [ "${memtotal}" -ge "900000" ]; then
                        echo -en "\033[1;32mPASS \033[0m\n";tput sgr0
                    else
                        echo -en "\033[1;31mFAIL \033[0m\n";tput sgr0
                        echo "There is not enough RAM on your server. A minimum of 900MB is required. Aborted.";echo ""
                        exit 1
                    fi

                    echo -n "Checking SWAP size... "
                    if [ "${swaptotal}" -ge "2000000" ]; then
                        echo -en "\033[1;32mPASS \033[0m\n";tput sgr0
                    else
                        echo -en "\033[1;31mFAIL \033[0m\n";tput sgr0
                        sys_err_swap="yes"
                        #echo "There is not enough SWAP on your server. A minimum of 2G is required. Aborted.";echo ""
                        #exit 1
                    fi
            fi

            #DHCP
            echo -n "Checking type IP address... "
            if [[ "${dip}" == *"dynamic"* ]];then
                    echo -en "\033[1;31mFAIL \033[0m\n";tput sgr0
                    sys_err_dhcp="yes"
                    #echo "Your IP address is of a dynamic type (DHCP), but you need a static one. Aborted.";echo ""
                    #exit 1
            else
                    echo -en "\033[1;32mPASS \033[0m\n";tput sgr0
            fi

            #err
            if [[ "${sys_err_swap}" == "yes" || "${sys_err_dhcp}" == "yes" ]];then
                    echo ""
                    echo "The following issues were found:"
            fi
            if [[ "${sys_err_swap}" == "yes" ]];then
                    echo " *) There is not enough SWAP on your server. A minimum of 2G is required."
                    echo "    The absence or insufficient volume of this section can lead to unstable operation of the Panel or its services."
            fi
            if [[ "${sys_err_dhcp}" == "yes" ]];then
                    echo " *) Your IP address is of a dynamic type (DHCP), but you need a static one."
                    echo "    A dynamic address of a network interface can lead to incorrect operation of some services, "
                    echo "    for example, issuing certificates. And also, disrupting the installation process itself."
            fi

            if [[ "${sys_err_swap}" == "yes" || "${sys_err_dhcp}" == "yes" ]];then
                    echo ""
                    echo "Please also note that technical support cannot help you until you fix these problems."
            fi

            if [[ "${sys_err_swap}" == "yes" || "${sys_err_dhcp}" == "yes" ]];then
                    echo ""
                    while true; do
                        read -p "Continue installation? {y/n}: " yn
                        case $yn in
                                [Yy]* ) echo "Continue and ignore these errors."; break;;
                                [Nn]* ) echo "Abort the installation process and exit."; exit;;
                                * ) echo "Please answer yes or no.";;
                        esac
                    done
            fi

            #remove old
            /bin/rm -f ${d}/_installCentos_t01v10.sh &>/dev/null
            wget -t 2  $ARRD/_installCentos_t01v10.sh &>/dev/null
            if [ $? -eq 0 ]; then
                result=0
                echo -en "\033[1;32m [OK] \033[0m\n"
                tput sgr0
            else
                result=1
                echo -e "\033[1;31m [ERROR] \033[0m\n"
                tput sgr0
                echo -e "Please. Download new script for install. wget http://core.brainycp.com/install.sh"
                exit
            fi

. ${d}/_installCentos_t01v10.sh
#. ${PWD_L}/_checkpkg.sh -u auto
            brainy-core -s auto
            #remove 
            /bin/rm -f ${d}/_installCentos_t01v10.sh &>/dev/null
            /bin/rm -f ${d}/install.sh &>/dev/null


            chmod 0750 /usr/local/brainycp/ssh/*.php
            chmod 0750 /usr/local/brainycp/ssh/*.sh

            echo -e "\n\n\033[1;34m BrainyCP was successfully installed! \033[0m\n\n";tput sgr0
            echo -e "\nBy using this product you completely accept License Agreement - https://brainycp.com/license_agreement\n"
            echo -e "To use it:\n"
            echo -e "http://"$ip_serv":8002 or https://"$ip_serv":8000\n"
            echo -e "username: root"
            echo -e "password: YOUR ROOT PASSWORD"
            echo ""
            echo -e "\033[1;31m 1) WARNING!!! Kernel updated successfully. Please, reboot your system! \033[0m\n";tput sgr0


#           echo -en "Download install script... "
#           yum install -y wget &>/dev/null
#           # remove old
#           if [ "${os_type}" == "rocky" ];then
#               /bin/rm -f ${d}/_installRocky_9_3 &>/dev/null
#               wget -t 2  $ARRD/_installRocky_9_3 &>/dev/null
#           else
#               /bin/rm -f ${d}/_installAlma_9_3 &>/dev/null
#               wget -t 2  $ARRD/_installAlma_9_3 &>/dev/null
#           fi
#           if [ $? -eq 0 ]; then
#               result=0
#               echo -en "\033[1;32m [OK] \033[0m\n";tput sgr0
#           else
#               result=1
#               echo -e "\033[1;31m [ERROR] \033[0m\n";tput sgr0
#               echo -e "Please. Download new script for install. wget http://core.brainycp.com/install.sh"
#               exit 1
#           fi

#           if [ "${os_type}" == "rocky" ];then
#               chmod 0700 ${d}/_installRocky_9_3
#               ${d}/_installRocky_9_3 "${1}"
#               /bin/rm -f ${d}/_installRocky_9_3 &>/dev/null
#               touch ${d}/install_rocky_9.txt
#           else
#               chmod 0700 ${d}/_installAlma_9_3
#               ${d}/_installAlma_9_3 "${1}"
#               /bin/rm -f ${d}/_installAlma_9_3 &>/dev/null
#               touch ${d}/install_alma_9.txt
#           fi
#           brainy-core -s auto &>brainy_core.log
#           chmod 0750 /usr/local/brainycp/ssh/*.php
#           chmod 0750 /usr/local/brainycp/ssh/*.sh
            exit 0
    fi
    # END 10

if [[ $vopenvz = "no" ]];then
#KVM
#echo $openvz
#exit

    osRhl="yes"
    rm -rf /etc/yum.repos.d/epel.repo
    rm -rf /etc/yum.repos.d/epel-testing.repo
    rm -rf /etc/yum.repos.d/ceph.repo
    rm -rf /etc/yum.repos.d/cm.repo
    yum clean all &>/dev/null
    yum -y install rpm yum python3-rpm rpm-build-libs rpm-libs &>/dev/null

#    echo "Detected OS Version: CentOS"
    echo -e "Detected OS Version: \033[1;32mCentOS ${v8} \033[0m";tput sgr0
    echo -e "Detected Server Name: \033[1;32m${srvname} \033[0m";tput sgr0
    echo -e "Detected Server IP: \033[1;32m${srvip} \033[0m";tput sgr0
    if [ -f $TOTALFILE ]; then
        echo -e "Detected Server RAM memory: \033[1;32m${memtotal} KB\033[0m";tput sgr0
        echo -e "Detected Server SWAP memory: \033[1;32m${swaptotal} KB\033[0m";tput sgr0
    fi

    sys_err_swap="no"
    sys_err_dhcp="no"
    if [ -f $TOTALFILE ]; then
        echo -n "Checking RAM size... "
        if [ "${memtotal}" -ge "1000000" ]; then
        echo -en "\033[1;32mPASS \033[0m\n";tput sgr0
        else
        echo -en "\033[1;31mFAIL \033[0m\n";tput sgr0
        echo "There is not enough RAM on your server. A minimum of 1G is required. Aborted.";echo ""
        exit -1
    fi

    echo -n "Checking SWAP size... "
        if [ "${swaptotal}" -ge "2000000" ]; then
        echo -en "\033[1;32mPASS \033[0m\n";tput sgr0
        else
        echo -en "\033[1;31mFAIL \033[0m\n";tput sgr0
        sys_err_swap="yes"
        #echo "There is not enough SWAP on your server. A minimum of 2G is required. Aborted.";echo ""
        #exit -1
        fi
    fi

    #DHCP
    echo -n "Checking type IP address... "
    if [[ "${dip}" == *"dynamic"* ]];then
      echo -en "\033[1;31mFAIL \033[0m\n";tput sgr0
      sys_err_dhcp="yes"
      #echo "Your IP address is of a dynamic type (DHCP), but you need a static one. Aborted.";echo ""
      #exit 1
    else
      echo -en "\033[1;32mPASS \033[0m\n";tput sgr0
    fi

    #err
    if [[ "${sys_err_swap}" == "yes" || "${sys_err_dhcp}" == "yes" ]];then
        echo ""
        echo "The following issues were found:"
    fi
    if [[ "${sys_err_swap}" == "yes" ]];then
        echo " *) There is not enough SWAP on your server. A minimum of 2G is required."
        echo "    The absence or insufficient volume of this section can lead to unstable operation of the Pael or its services."
    fi
    if [[ "${sys_err_dhcp}" == "yes" ]];then
        echo " *) Your IP address is of a dynamic type (DHCP), but you need a static one."
        echo "    A dynamic address of a network interface can lead to incorrect operation of some services, "
        echo "    for example, issuing certificates. And also, disrupting the installation process itself."
    fi

    if [[ "${sys_err_swap}" == "yes" || "${sys_err_dhcp}" == "yes" ]];then
        echo ""
        echo "Please also note that technical support cannot help you until you fix these problems."
    fi

    if [[ "${sys_err_swap}" == "yes" || "${sys_err_dhcp}" == "yes" ]];then
        echo ""
        while true; do
            read -p "Continue installation? {y/n}: " yn
            case $yn in
                [Yy]* ) echo "Continue and ignore these errors."; break;;
                [Nn]* ) echo "Abort the installation process and exit."; exit;;
                * ) echo "Please answer yes or no.";;
            esac
        done
    fi

    echo -en "Download install script..."
    yum install -y wget &>/dev/null

    rm -f ${d}/_installCentos_t01.sh &>/dev/null
    wget -t 2  $ARRD/_installCentos_t01.sh &>/dev/null
	if [ $? -eq 0 ]; then
		result=0
		echo -en "\033[1;32m [OK] \033[0m\n"
		tput sgr0
	else
		result=1
		echo -e "\033[1;31m [ERROR] \033[0m\n"
		tput sgr0 
		echo -e "Please. Download new script for install. wget http://core.brainycp.com/install_t01.sh"
		exit
	fi

    wget -t 2  $ARRD/_checkpkg.sh &>/dev/null
    #chmod 755 ${d}/_checkpkg.sh

. ${d}/_installCentos_t01.sh
. ${PWD_L}/_checkpkg.sh -u auto

#PWD_L=`pwd`
#echo "PWD is '$PWD_L'"

echo -e "\n\n\033[1;34m BrainyCP was successfully installed! \033[0m\n\n";tput sgr0
echo -e "\nBy using this product you completely accept License Agreement - https://brainycp.com/license_agreement\n"
echo -e "To use it:\n"
echo -e "http://"$ip_serv":8002 or https://"$ip_serv":8000\n"
echo -e "username: root"
echo -e "password: YOUR ROOT PASSWORD"
echo ""
echo -e "\033[1;31m 1) WARNING!!! Kernel updated successfully. Please, reboot your system! \033[0m\n";tput sgr0
#sync ; echo 1 > /proc/sys/vm/drop_caches
exit 0

else
#OPENVZ
#echo $openvz
#exit

    yum -y install rpm python3-rpm rpm-build-libs rpm-libs &>/dev/null

    rm -f ${d}/_installCentos_01_openVZv3.sh &>/dev/null
    wget -t 2  $ARRD/_installCentos_01_openVZv3.sh &>/dev/null
        if [ $? -eq 0 ]; then
                result=0
                echo -en "\033[1;32m [OK] \033[0m\n"
                tput sgr0
        else
                result=1
                echo -e "\033[1;31m [ERROR] \033[0m\n"
                tput sgr0
                echo -e "Please. Download new script for install. wget http://core.brainycp.com/install.sh"
                exit
        fi
. ${d}/_installCentos_01_openVZv3.sh
exit 0
fi

fi


##
## Debian,Ubuntu
##
if [ -f "/etc/debian_version" ]; then
    ver=`cat /etc/issue.net | awk '{print $1$3}'`
    echo "Detected OS Version: "$ver

# Debian 8
if [[ $ver == "Debian8" ]];then
    osDebian="yes"
    apt-get install -y --force-yes wget &>/dev/null
    echo -en "Download install script... "
    wget -t 2 http://core.brainycp.com/_installDebian8.sh  &>/dev/null
	if [ $? -eq 0 ]; then
		result=0
		echo -en "\033[1;32m [OK] \033[0m\n"
		tput sgr0
	else
		result=1
		echo -e "\033[1;31m [ERROR] \033[0m\n"
		tput sgr0
		exit
	fi
. ${d}/_installDebian8.sh
exit 0
fi

# Debian 9
if [[ $ver == "Debian9__" ]];then
    osDebian="yes"
    apt-get install -y --force-yes wget &>/dev/null
    echo -en "Download install script... "
    wget -t 2 http://core.brainycp.com/_installDebian9.sh  &>/dev/null
	if [ $? -eq 0 ]; then
		result=0
		echo -en "\033[1;32m [OK] \033[0m\n"
		tput sgr0
	else
		result=1
		echo -e "\033[1;31m [ERROR] \033[0m\n"
		tput sgr0
		exit
	fi
. ${d}/_installDebian9.sh
exit 0
fi

# Ubuntu
if [[ $ver == "Ubuntu__" ]];then
    osUbuntu="yes"
    apt-get install -y --force-yes wget &>/dev/null
    echo -en "Detected Download install script... "
    wget -t 2 http://core.brainycp.com/_installUbuntu.sh  &>/dev/null
	if [ $? -eq 0 ]; then
		result=0
		echo -en "\033[1;32m [OK] \033[0m\n"
		tput sgr0
	else
		result=1
		echo -e "\033[1;31m [ERROR] \033[0m\n"
		tput sgr0
		exit
	fi
. ${d}/_installUbuntu.sh
exit 0
fi

fi

echo -e "\033[1;31mThe suitable system is not found or its parameters are not correct! \033[0m\n";tput sgr0
exit 0

