#!/bin/sh
# ISPsystem install.pkg
#set -e
LOG_PIPE=/tmp/log.pipe.$$
mkfifo ${LOG_PIPE}
LOG_FILE=/tmp/log.file.$$
tee < ${LOG_PIPE} ${LOG_FILE} &
exec > ${LOG_PIPE}
exec 2> ${LOG_PIPE}
LogClean() {
rm -f ${LOG_PIPE}
rm -f ${LOG_FILE}
}
Usage()
{
cat << EOU >&2
Usage:
$0 --help Print this help
$0 [options] [mgrname]
--osfamily <FAMILY> REDHAT, DEBIAN . Force if can not be detected.
--osversion <VERSION> Version for OS. Example: wheezy for debain, 6 for centos. Force if can not be detected.
--release <type> Installs managers non-interactively with desired release <type>.
--noinstall Not install packages. Just add repository. Also disable mirror detecting.
--ignore-hostname Ignore incorrect hostname.
--silent Do not ask hostname and activation key. Exit on these errors immediatly.
--no-letsencrypt Disable automatic certificate generation
EOU
}
GetMgrUrl() {
# ${1} - mgr
if [ -z ${1} ]; then echo "Empty arg 1" ; return 1; fi
if [ "#${1}" = "#billmgr" ]; then
ihttpd_port=443
IPADDR=$(/usr/local/mgr5/sbin/ihttpd | awk -F: '$3 == "443" {print $2}')
IPADDR=$(echo ${IPADDR})
fi
if [ -n "${IPADDR}" ]; then
echo "https://${IPADDR}/${1}"
else
ihttpd_port=1500
IPADDR=$(echo $SSH_CONNECTION | awk '{print $3}')
if [ -z ${IPADDR} ]; then
if [ "${ISPOSTYPE}" = "FREEBSD" ]; then
IPADDR=$(ifconfig | awk '$1 ~ /inet/ && $2 !~ /127.0.0|::1|fe80:/ {print $2}' |cut -d/ -f1 | head -1)
else
IPADDR=$(ip addr show | awk '$1 ~ /inet/ && $2 !~ /127.0.0|::1|fe80:/ {print $2}' |cut -d/ -f1 | head -1)
fi
fi
if echo ${IPADDR} | grep -q ':' ; then
SHOWIPADDR="[${IPADDR}]"
else
SHOWIPADDR=${IPADDR}
fi
echo "https://${SHOWIPADDR}:1500/${1}"
fi
}
PkgInstalled() {
case ${ISPOSTYPE} in
REDHAT)
rpm -q ${1} >/dev/null 2>&1 ; return $?
;;
DEBIAN)
dpkg -s ${1} >/dev/null 2>&1 ; return $?
;;
*)
:
;;
esac
}
PkgAvailable() {
case ${ISPOSTYPE} in
REDHAT)
yum -q -C info ${1} >/dev/null 2>/dev/null
;;
DEBIAN)
apt-cache -q show ${1} | grep -q "${1}" >/dev/null 2>/dev/null
;;
*)
;;
esac
}
MgrInstalled() {
if [ -z ${1} ]; then echo "Empty arg 1" ; return 1; fi
if [ -z ${2} ]; then echo "Empty arg 2" ; return 1; fi
Info "================================================="
Info "$2 is installed"
local MGRDOMAIN=$(/usr/local/mgr5/sbin/licctl info ${mgr} | awk -F"[: \t]+" '$1 == "JustInstalled" {print $2}')
if [ -n "${MGRDOMAIN}" ] && ! echo "${MGRDOMAIN}" | grep -qE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' ; then
# TEST FUNCTION
Info "Go to the \"https://${MGRDOMAIN}:1500/${mgr}\" to login"
Info "Login: root"
Info "Password: <root password>"
Info ""
echo "If this doesn't work You can use IP instead of domain"
echo "Like: \"$(GetMgrUrl ${mgr})\""
else
Info "Go to the \"$(GetMgrUrl ${mgr})\" to login"
Info "Login: root"
Info "Password: <root password>"
fi
Info "================================================="
}
OpenFirewall() {
local port
port=${1}
if which firewall-cmd >/dev/null && service firewalld status >/dev/null ; then
firewall-cmd --zone=public --add-port ${port}/tcp
elif [ -f /sbin/iptables ]; then
iptables -I INPUT -p tcp --dport ${port} -j ACCEPT
fi
}
CloseFirewall() {
local port
port=${1}
if which firewall-cmd >/dev/null && service firewalld status >/dev/null ; then
firewall-cmd --zone=public --remove-port ${port}/tcp || :
elif [ -f /sbin/iptables ]; then
iptables -D INPUT -p tcp --dport ${port} -j ACCEPT || :
fi
}
LetsEncrypt() {
test -n "${no_letsencrypt}" && return
local MGRDOMAIN=$(/usr/local/mgr5/sbin/licctl info ${mgr} | awk -F"[: \t]+" '$1 == "JustInstalled" {print $2}')
if [ -n "${MGRDOMAIN}" ] && ! echo "${MGRDOMAIN}" | grep -qE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' ; then
if [ -x /usr/local/mgr5/sbin/letsencrypt.sh ]; then
Info "Trying to get and install Let\`s Encrypt certificate"
OpenFirewall 80 || :
/usr/local/mgr5/sbin/letsencrypt.sh ${MGRDOMAIN} || :
CloseFirewall 80 || :
fi
fi
}
# Disable dialog
DIALOG_BIN=
centos_OSVERSIONS="6 7"
debian_OSVERSIONS="wheezy jessie"
ubuntu_OSVERSIONS="trusty xenial"
freebsd_OSVERSIONS="10.0 10.1 10.2 10.3"
export DEBIAN_FRONTEND=noninteractive
export NOTIFY_SERVER=https://n...content-available-to-author-only...m.com/v1
CheckRoot() {
if [ $(id -u) -ne 0 ]; then
Error "You must be root user to continue"
exit 1
fi
local RID=$(id -u root 2>/dev/null)
if [ $? -ne 0 ]; then
Error "User root no found. You should create it to continue"
exit 1
fi
if [ $RID -ne 0 ]; then
Error "User root UID not equals 0. User root must have UID 0"
exit 1
fi
}
Infon() {
printf "\033[1;32m$@\033[0m"
}
Info()
{
Infon "$@\n"
}
Warningn() {
printf "\033[1;35m$@\033[0m"
}
Warning()
{
Warningn "$@\n"
}
Warnn()
{
Warningn "$@"
}
Warn()
{
Warnn "$@\n"
}
Error()
{
printf "\033[1;31m$@\033[0m\n"
}
DetectManager() {
if [ "${MIGRATION}" != "mgr5" ] && [ "${noinstall}" != "true" ] && [ -d /usr/local/ispmgr ]; then
local MGRLIST=$(ls /usr/local/ispmgr/bin/ 2>/dev/null | tr '\n' ' ')
Error "Old managers is installed: ${MGRLIST}"
exit 1
fi
}
CheckSELinux() {
local kern=`uname -s`
if [ "$kern" = "Linux" ]; then
if selinuxenabled > /dev/null 2>&1 ; then
# silent install
if [ -n "$release" ] || [ -n "$silent" ]; then
Error "SELinux is enabled, aborting installation."
exit 1
fi
Error "SELinux is enabled on your server. It is strongly recommended to disable SELinux before you proceed."
local uid=`id -u`
# do we have a root privileges ?
if [ "$uid" = "0" ]; then
echo -n "Would you like to disable SELinux right now (yes/no)?"
local ask1
ask1="true"
while [ "$ask1" = "true" ]
do
ask1="false"
read answer
if [ -z "$answer" ] || [ "$answer" = "yes" ]; then
# do disable SELinux
setenforce 0 >/dev/null 2>&1
cp -n /etc/selinux/config /etc/selinux/config.orig >/dev/null 2>&1
echo SELINUX=disabled > /etc/selinux/config
Error "Reboot is requred to complete the configuration of SELinux."
echo -n "Reboot now (yes/no)?"
local ask2
ask2="true"
while [ "$ask2" = "true" ]
do
ask2="false"
read answer
if [ "$answer" = "yes" ]; then
Info "Rebooting now. Please start installation script again once the server reboots."
shutdown -r now
exit 0
elif [ "$answer" = "no" ]; then
Error "It is strongly recommended to reboot server before you proceed the installation"
else
ask2="true"
echo -n "Please type 'yes' or 'no':"
fi
done
elif [ "$answer" != "no" ]; then
ask1="true";
echo -n "Please type 'yes' or 'no':"
fi
done
fi
fi
fi
}
DetectFetch()
{
if [ -x /usr/bin/fetch ]; then
fetch="/usr/bin/fetch -o "
elif [ -x /usr/bin/wget ]; then
if [ "$unattended" = "true" ]; then
fetch="/usr/bin/wget -q -O "
else
fetch="/usr/bin/wget -q -O "
fi
elif [ -x /usr/bin/curl ]; then
fetch="/usr/bin/curl -o "
else
Error "ERROR: no fetch program found."
exit 1
fi
}
OSDetect() {
test -n "${ISPOSTYPE}" && return 0
ISPOSTYPE=unknown
kern=$(uname -s)
case "${kern}" in
Linux)
if [ -f /etc/redhat-release ] || [ -f /etc/centos-release ]; then
# RH family
export ISPOSTYPE=REDHAT
elif [ -f /etc/debian_version ]; then
# DEB family
export ISPOSTYPE=DEBIAN
fi
;;
FreeBSD)
# FreeBSD
export ISPOSTYPE=FREEBSD
;;
esac
if [ "#${ISPOSTYPE}" = "#unknown" ]; then
Error "Unknown os type. Try to use \"--osfamily\" option"
exit 1
fi
}
BadHostname() {
test -z "${1}" && return 1
local HOSTNAME=${1}
LENGTH=$(echo ${HOSTNAME} | wc -m)
if [ ${LENGTH} -lt 2 -o ${LENGTH} -gt 50 ]; then
return 1
fi
if ! echo ${HOSTNAME} | grep -q '\.'; then
return 1
fi
if echo ${HOSTNAME} | grep -q '_'; then
return 1
fi
local TOPLEVEL=$(echo ${HOSTNAME} | awk -F. '{print $NF}')
if [ -z "${TOPLEVEL}" ]; then
return 1
fi
if [ -n "$(echo ${TOPLEVEL} | sed -r 's/[a-zA-Z0-9\-]//g')" ]; then
return 1
fi
}
GetFirstIp() {
if [ -n "$(which ip 2>/dev/null)" ]; then
ip route get 1 | awk '{print $NF;exit}'
fi
}
SetHostname() {
# 1 - new hostname
# 2 - old hostname
test -z "${1}" && return 1
# test -z "${2}" && return 1
local HOSTNAME=$(echo ${1} | sed 's|\.+$||')
case "${ISPOSTYPE}" in
REDHAT)
hostname ${HOSTNAME} || return 1
sed -i -r "s|^HOSTNAME=|HOSTNAME=${HOSTNAME}|" /etc/sysconfig/network || return 1
if [ -n "${2}" ]; then
sed -i -r "s|${2}|${HOSTNAME}|g" /etc/hosts || return 1
fi
;;
DEBIAN)
local CUTHOSTNAME=$(echo ${HOSTNAME%\.*})
hostname ${CUTHOSTNAME} || return 1
echo ${CUTHOSTNAME} > /etc/hostname || return 1
if [ -n "${2}" ]; then
sed -i -r "s|${2}|${HOSTNAME}|g" /etc/hosts || return 1
fi
if ! hostname -f >/dev/null 2>&1 ; then
sed -i -r "s|^([0-9\.]+\s+)${HOSTNAME}\s*$|\1${HOSTNAME} ${CUTHOSTNAME}|g" /etc/hosts
fi
if ! hostname -f >/dev/null 2>&1 ; then
echo "$(GetFirstIp) ${HOSTNAME} ${CUTHOSTNAME}" >> /etc/hosts
fi
if ! hostname -f >/dev/null 2>&1 ; then
Error "Can not set hostname"
return 1
fi
;;
FREEBSD)
hostname ${HOSTNAME} || return 1
cat /etc/rc.conf | sed -r '/^hostname=/d' > /etc/rc.conf.repo
echo "hostname=\"${HOSTNAME}\"" >> /etc/rc.conf.repo
mv /etc/rc.conf.repo /etc/rc.conf
;;
esac
}
CheckHostname() {
if [ "${ISPOSTYPE}" = "DEBIAN" ]; then
local CURHOSTNAME=$(hostname -f ||:)
else
local CURHOSTNAME=$(hostname || :)
fi
local HOSTNAME=${CURHOSTNAME}
if [ "#${silent}" != "#true" ]; then
while ! BadHostname ${HOSTNAME};
do
Error "You have incorrect hostname: ${HOSTNAME}"
read -p "Enter new hostname(or Ctrl+C to exit): " HOSTNAME
echo
done
Info "You have hostname: ${HOSTNAME}"
if [ ! "${CURHOSTNAME}" = "${HOSTNAME}" ]; then
local err_hn=0
SetHostname ${HOSTNAME} ${CURHOSTNAME} || err_hn=1
if [ ${err_hn} -ne 0 ]; then
echo
Error "Can not change hostname. Please change it manually"
exit 1
fi
fi
else
if ! BadHostname ${HOSTNAME}; then
Error "You have incorrect hostname: ${HOSTNAME}"
Error "Please change it manually"
exit 1
fi
fi
}
OSVersion() {
test -n "${OSVER}" && return 0
OSVER=unknown
case ${ISPOSTYPE} in
REDHAT)
if ! which which >/dev/null 2>/dev/null ; then
yum -y install which
fi
if [ -z "$(which hexdump 2>/dev/null)" ]; then
yum -y install util-linux-ng
fi
OSVER=$(rpm -q --qf "%{version}" -f /etc/redhat-release)
if echo "${OSVER}" | grep -q Server ; then
OSVER=$(echo "${OSVER}" | sed 's/Server//')
fi
OSVER=${OSVER%%\.*}
if ! echo ${centos_OSVERSIONS} | grep -q -w ${OSVER} ; then
unsupported_osver="true"
fi
;;
DEBIAN)
/usr/bin/apt-get -qy update
if ! which which >/dev/null 2>/dev/null ; then
/usr/bin/apt-get -qy --allow-unauthenticated install which
fi
if [ -z "$(which lsb_release 2>/dev/null)" ]; then
/usr/bin/apt-get -qy --allow-unauthenticated install lsb-release
fi
if [ -z "$(which hexdump 2>/dev/null)" ]; then
/usr/bin/apt-get -qy --allow-unauthenticated install bsdmainutils
fi
if [ -z "$(which logger 2>/dev/null)" ]; then
/usr/bin/apt-get -qy --allow-unauthenticated install bsdutils
fi
if [ -z "$(which free 2>/dev/null)" ]; then
/usr/bin/apt-get -qy --allow-unauthenticated install procps
fi
if [ -x /usr/bin/lsb_release ]; then
OSVER=$(lsb_release -s -c)
fi
if ! echo "${debian_OSVERSIONS} ${ubuntu_OSVERSIONS}" | grep -q -w ${OSVER} ; then
unsupported_osver="true"
fi
if [ "$(lsb_release -s -i)" = "Ubuntu" ]; then
export reponame=ubuntu
else
export reponame=debian
fi
;;
esac
if [ "#${OSVER}" = "#unknown" ]; then
Error "Unknown os version. Try to use \"--osversion\" option"
exit 1
fi
if [ "#${unsupported_osver}" = "#true" ]; then
Error "Unsupported os version (${OSVER})"
exit 1
fi
}
PingTest() {
local ITER=5
ping -q -c ${ITER} -n ${1} 2>&1 | tail -1 | awk -F '/' '{print $5}' | awk -F. '{print $1}'
}
GetFastestMirror() {
# Detect fastest mirror. If redhat not needed. If mirror detected not needed
# Mirror already set
if [ -n "${MIRROR}" ]; then
return 0
fi
# Thist is developer installation
if ! echo "${release}" | grep -qE "^(stable|beta|beta5|stable5|intbeta|intstable|alpha|5\.[0-9]+)$"; then
export MIRROR=intrepo.download.ispsystem.com
return 0
fi
# For RH based OS using fastestmirror plugin. And if we do not planning install packages via install.sh
if [ "#${ISPOSTYPE}" = "#REDHAT" ] || [ "${noinstall}" = "true" ] ; then
MIRROR=download.ispsystem.com
return 0
fi
Infon "Detecting fastest mirror..."
local PRU
PRU=$(PingTest download.ispsystem.com)
if [ -z "${PRU}" ]; then
PRU=10000
fi
if [ ${PRU} -lt 10 ]; then
export MIRROR=download.ispsystem.com
else
local PCDN
PCDN=$(PingTest cdn.ispsystem.com)
if [ -z "${PCDN}" ]; then
PCDN=10001
fi
if [ ${PRU} -lt ${PCDN} ]; then
export MIRROR=download.ispsystem.com
else
export MIRROR=cdn.ispsystem.com
fi
fi
Info " Using ${MIRROR}"
}
OsName() {
case ${ISPOSTYPE} in
REDHAT)
echo "$(rpm -qf /etc/redhat-release)"
;;
DEBIAN)
echo "$(lsb_release -s -i -c -r | xargs echo |sed 's; ;-;g')-$(dpkg --print-architecture)"
;;
FREEBSD)
echo FreeBSD
;;
esac
}
GetMachineID() {
if [ ! -f /etc/machine-id ]; then
hexdump -n 16 -e '/2 "%x"' /dev/urandom > /etc/machine-id
fi
echo $(cat /etc/machine-id| awk '{print $1}')
}
StartInstall() {
HOSTID=$(GetMachineID)
URL="${NOTIFY_SERVER}/startinstall"
wget --tries=3 --connect-timeout=10 --no-check-certificate --post-data="os=$(OsName)&mirror=${MIRROR}&repo=${release}&mgr=${pkgname}&hostid=${HOSTID}" -O - "${URL}" 2>/dev/null || :
}
LicInstall() {
HOSTID=$(GetMachineID)
URL="${NOTIFY_SERVER}/licinstall"
licid=$(/usr/local/mgr5/sbin/licctl info /usr/local/mgr5/etc/${mgr}.lic 2>/dev/null| awk '$1 == "ID:" {print $2}' || :)
licexpire=$(/usr/local/mgr5/sbin/licctl info /usr/local/mgr5/etc/${mgr}.lic 2>/dev/null| awk '$1 == "Expire:" {print $2}' || :)
LICPART="&licid=${licid}&licexpire=${licexpire}"
corever=$(/usr/local/mgr5/bin/core core -v 2>/dev/null)
POST_DATA="hostid=${HOSTID}&mgr=${pkgname}&corever=${corever}"
if [ "#${licid}" != "#0" ]; then
POST_DATA="${POST_DATA}${LICPART}"
fi
wget --tries=3 --connect-timeout=10 --no-check-certificate --post-data="${POST_DATA}" -O - "${URL}" 2>/dev/null || :
}
CancelInstall() {
HOSTID=$(GetMachineID)
if [ -n "${1}" ]; then
REASON="&reason=${1}"
fi
URL="${NOTIFY_SERVER}/cancelinstall"
wget --tries=3 --connect-timeout=10 --no-check-certificate --post-data="hostid=${HOSTID}&mgr=${pkgname}${REASON}" -O - "${URL}" 2>/dev/null || :
rm -f ${COOKIES_FILE}
LogClean
}
FinishInstall() {
HOSTID=$(GetMachineID)
URL="${NOTIFY_SERVER}/finishinstall"
mgrver=$(/usr/local/mgr5/bin/core ${mgr} -v 2>/dev/null)
wget --tries=3 --connect-timeout=10 --no-check-certificate --post-data="hostid=${HOSTID}&mgr=${pkgname}&mgrver=${mgrver}&url=$(GetMgrUrl ${mgr})" -O - "${URL}" 2>/dev/null || :
rm -f ${COOKIES_FILE}
LogClean
}
ErrorInstall() {
HOSTID=$(GetMachineID)
URL="${NOTIFY_SERVER}/errorinstall"
if [ -n "${1}" ]; then
err_text="${1}"
else
#Pkglist
err_text="$(cat ${LOG_FILE} | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | hexdump -v -e '/1 "%02x"' | sed 's/\(..\)/%\1/g')"
fi
wget --tries=3 --connect-timeout=10 --no-check-certificate --post-data="hostid=${HOSTID}&mgr=${pkgname}&text=${err_text}" -O - "${URL}" 2>/dev/null || :
LogClean
exit 1
}
DetectInstalled() {
# Check if coremanager is installed
if PkgInstalled coremanager || test -f /usr/local/mgr5/etc/core.conf ; then
export core_installed=yes
fi
}
GetCurrentRepo() {
case ${ISPOSTYPE} in
REDHAT)
if [ -f /etc/yum.repos.d/ispsystem.repo ]; then
release=$(grep -E '^name=ispsystem-' /etc/yum.repos.d/ispsystem.repo | tail -1|sed -r 's/name=ispsystem-//g')
fi
if [ -z "${release}" ]; then
rm -f /etc/yum.repos.d/ispsystem.repo
else
added_repo=yes
export MIRROR="$(awk -F= '$1 == "baseurl" {print $2}' /etc/yum.repos.d/ispsystem.repo | awk -F/ '{print $3}')"
fi
;;
DEBIAN)
if [ -f /etc/apt/sources.list.d/ispsystem.list ]; then
release=$(cat /etc/apt/sources.list.d/ispsystem.list | awk '$1 == "deb" && $2 ~ /http|ftp/ {print $3}' | awk -F- '{print $1}')
fi
if [ -z "${release}" ]; then
rm -f /etc/apt/sources.list.d/ispsystem.list
else
added_repo=yes
export MIRROR="$(awk -F/ '{print $3}' /etc/apt/sources.list.d/ispsystem.list)"
fi
;;
*)
;;
esac
}
CheckRepo() {
# Check unsupported centos repo
# skip if silent install
test -n "${silent}" && return 0
# skip if debian
[ "${ISPOSTYPE}" = "DEBIAN" ] && return 0
Info "List of enabled repositories:"
yum --noplugins repolist enabled 2>/dev/null | grep -v repolist
echo ""
local arepos=$(yum --noplugins repolist enabled 2>/dev/null | grep -v repolist | sed '1d' | awk '{print $1}' | awk -F/ '{print $1}' | sed 's/^!//')
if [ -n "${arepos}" ] && ! echo "${arepos}" | grep -q '^base$' ;then
Error "Can not be installed without CentOS base repository"
CancelInstall baserepo
exit 1
fi
local repos=$(yum --noplugins repolist enabled 2>/dev/null | grep -v repolist | sed '1d' | awk '{print $1}' | awk -F/ '{print $1}' | grep -vE '^\!*(ispsystem-.*|epel.*|vz-.*|base|extras|updates|cloudlinux-.*)$')
if echo "${repos}" | grep -v remi-safe | grep -qE "(\s|^)remi(-\w+)*(\s|\n|$)" ; then
Error "Can not be installed with remi repo"
CancelInstall remirepo
exit 1
elif [ -n "${repos}" ]; then
Warningn "You have next unsupported repositories: "
echo ${repos}
Warning "This may cause installtion problems."
Warning "Please disable this repositories for correct installation."
Warningn "Are You really want to continue? (y/N) "
read answer
if [ "#${answer}" != "#y" ]; then
CancelInstall unsupportedrepos
exit 1
fi
fi
}
CheckDF() {
# Check free disk space for centos
# $1 - partition
# $2 - min size
# skip if silent install
test -n "${silent}" && return 0
if [ "${ISPOSTYPE}" = "REDHAT" ]; then
local cursize=$(df -P -m ${1} 2>/dev/null | tail -1 | awk '{print $4}')
test -z "${cursize}" && return 0
if [ ${cursize} -lt ${2} ]; then
Error "You have insufficiently disk space to install in directory ${1}: ${cursize} MB"
Error "You need to have at least ${2} MB"
CancelInstall diskspace
exit 1
fi
fi
}
CheckMEM() {
# Chech memory size
# skip if silent install
test -n "${silent}" && return 0
local lowmemlimit=256
local lowmem=$(free -m | awk -v lml=${lowmemlimit} 'NR==2 && $2 <= lml {print $2}')
if [ -n "${lowmem}" ]; then
Error "You have to low memory: ${lowmem}"
Error "You need to have at least 300 Mb"
CancelInstall lowmem
exit 1
fi
}
Pkglist() {
echo "" >> ${LOG_FILE}
echo "List of installed packages" >> ${LOG_FILE}
case ${ISPOSTYPE} in
REDHAT)
rpm -qa | sort >> ${LOG_FILE} 2>&1
;;
DEBIAN)
dpkg -l >> ${LOG_FILE} 2>&1
;;
esac
}
CheckConflicts() {
# Check installed packages with same name
# $1 - package
local name=${1}
local short_name=${name%%-*}
test -z "${short_name}" && return 0
if [ "${ISPOSTYPE}" = "REDHAT" ]; then
local vpkglist=$(rpm -qa "${short_name}*")
elif [ "${ISPOSTYPE}" = "DEBIAN" ]; then
vpkglist=$(dpkg -l "${short_name}*" 2>/dev/null | awk '$1 !~ /un/ {print $2 "-" $3}' | grep "^${short_name}"| xargs)
fi
local pkglist=""
for pkg in ${vpkglist}; do
if echo "${pkg}" | grep -q "${short_name}-pkg"; then
continue
else
pkglist="${pkglist} ${pkg}"
fi
done
pkglist="$(echo ${pkglist} | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'| xargs)"
if [ -n "${pkglist}" ]; then
Error "You have already installed next ${short_name} packages: "
echo "${pkglist}"
Error "If You want to install ${name} You should remove them first"
CancelInstall conflicts
exit 1
fi
}
trap ErrorInstall TERM
set -e
# Parsing arguments
while true
do
case "${1}" in
-h | --help)
Usage
exit 0
;;
--mirror)
MIRROR="${2:-.}"
shift 2
if [ ! -n "${MIRROR}" ]; then
Error "Empty mirror"
exit 1
fi
;;
--release)
release="${2:-.}"
shift 2
;;
--osfamily)
ISPOSTYPE="${2:-.}"
if ! echo "${ISPOSTYPE}" | grep -qE "^(REDHAT|DEBIAN)$"; then
Error "Incorrect OS"
exit 1
fi
shift 2
;;
--osversion)
OSVER="${2:-.}"
shift 2
;;
--noinstall)
noinstall="true"
shift 1
;;
--silent)
silent="true"
shift 1
;;
--ignore-hostname)
ignore_hostname="true"
shift 1
;;
--disable-fail2ban)
disable_fail2ban="true"
shift 1
;;
--no-letsencrypt)
no_letsencrypt="true"
shift 1
;;
*)
inpkgname=${1}
break
;;
esac
done
if [ -f /.dockerinit ]; then
export ignore_hostname="true"
fi
if [ -n "${release}" ]; then
if [ "#${release}" = "#beta" ]; then
release=beta5
fi
if [ "#${release}" = "#stable" ]; then
release=stable5
fi
fi
if [ "#${MIGRATION}" = "#mgr5" ]; then
Info "This is migration from 4th version"
fi
OSDetect
OSVersion
Infon "Installing on ${ISPOSTYPE} ${OSVER}"
echo ""
Info "System memory:"
free -m
echo ""
Info "Disk space:"
df -h -P -l -x tmpfs -x devtmpfs
echo ""
DetectManager
CheckRoot
CheckSELinux
CheckRepo
CheckDF /var/cache/yum/ 300
CheckDF /usr/local 1024
CheckMEM
if [ "#${ignore_hostname}" != "#true" ]; then
CheckHostname
else
export IGNORE_HOSTNAME=yes
fi
DetectFetch
DetectInstalled
if [ -z "${release}" ]; then
GetCurrentRepo
fi
if [ -n "${release}" ] && [ -n "${added_repo}" ]; then
Info "Detected added repository: ${release}"
Info "updating cache"
case ${ISPOSTYPE} in
REDHAT)
yum clean all || :
;;
DEBIAN)
apt-get -y update
;;
esac
fi
while [ -z "${release}" ]
do
echo "Which version would You like to install ?"
echo "b) beta version - has the latest functionality"
echo "s) stable version - time-proved version"
echo
read -p "Choose repository type to work with: " n
echo
case ${n} in
r|s|2|stable)
release="stable5"
;;
b|1|beta)
release="beta5"
;;
a|alpha)
release="alpha"
;;
m|master)
release="master"
;;
si)
release="stable-int"
;;
bi)
release="beta-int"
;;
ib)
release="intbeta"
;;
is)
release="intstable"
;;
i)
read -p "Enter full repository name: " rn
release="${rn}"
;;
*)
:
;;
esac
done
MirrorlistInstall() {
# $1 - file with repo
# $2 - repo name (epel, beta e.t.c.)
sed -i -r "s|(mirrorlist=http://d...content-available-to-author-only...m.com/repo/centos/${2})/mirrorlist.txt|\1/mirrorlist-install.txt|" /etc/yum.repos.d/${1}.repo
}
MirrorlistDefault() {
# $1 - file with repo
# $2 - repo name (epel, beta e.t.c.)
sed -i -r "s|(mirrorlist=http://d...content-available-to-author-only...m.com/repo/centos/${2})/mirrorlist-install.txt|\1/mirrorlist.txt|" /etc/yum.repos.d/${1}.repo
}
RemoveCdnRepo() {
case ${ISPOSTYPE} in
REDHAT)
MirrorlistDefault epel epel
MirrorlistDefault ispsystem-base base
MirrorlistDefault ispsystem ${release}
yum -y makecache || yum -y makecache
;;
DEBIAN)
if echo "${MIRROR}" | grep -q cdn ; then
sed -i -r "s|(http://)cdn.ispsystem.com|\1download.ispsystem.com|g" /etc/apt/sources.list.d/ispsystem.list
sed -i -r "s|(http://)cdn.ispsystem.com|\1download.ispsystem.com|g" /etc/apt/sources.list.d/ispsystem-base.list
apt-get -y update
fi
;;
esac
}
InstallGpgKey() {
# Install gpg key
case ${ISPOSTYPE} in
REDHAT)
if [ ! -s /etc/pki/rpm-gpg/RPM-GPG-KEY-ISPsystem ]; then
Info "Adding ISPsystem gpg key..."
${fetch} /etc/pki/rpm-gpg/RPM-GPG-KEY-ISPsystem "http://d...content-available-to-author-only...m.com/repo/ispsystem.gpg.key" || return 1
if [ ! -s /etc/pki/rpm-gpg/RPM-GPG-KEY-ISPsystem ]; then
${fetch} /etc/pki/rpm-gpg/RPM-GPG-KEY-ISPsystem "http://c...content-available-to-author-only...m.com/repo/ispsystem.gpg.key" || return 1
fi
if [ -s /etc/pki/rpm-gpg/RPM-GPG-KEY-ISPsystem ]; then
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-ISPsystem || return 1
else
return 1
fi
fi
;;
DEBIAN)
if ! apt-key list | grep -q 810F8996 ; then
Info "Adding ISPsystem gpg key..."
${fetch} - http://${MIRROR}/repo/${reponame}/ispsystem.gpg.key | apt-key add - >/dev/null 2>&1
fi
;;
esac
}
CheckRepo() {
# Check if repository added
# $1 - repo name
case ${ISPOSTYPE} in
REDHAT)
yum repolist enabled 2>/dev/null | awk '{print $1}' | grep -q ${1}
;;
DEBIAN)
apt-cache policy | awk -vrname=${1}/main '$NF == "Packages" && $(NF-2) == rname' | grep -q ${1}
;;
esac
}
InstallEpelRepo() {
# Install epel repo
# ${1} = true - Use cdn or mirrorlist
test "${ISPOSTYPE}" = "REDHAT" || return 0
test -z "${MIRROR}" && GetFastestMirror
Infon "Checking epel... "
if [ ! -f /etc/yum.repos.d/epel.repo ] || ! CheckRepo epel ; then
if rpm -q epel-release >/dev/null ; then
Warn "Epel repo file broken. Removing epel-release package"
rpm -e --nodeps epel-release
else
Info "Epel repo not exists"
fi
rm -f /etc/yum.repos.d/epel.repo
fi
if grep -iq cloud /etc/redhat-release ; then
Info "Importing EPEL key.."
rpm --import http://m...content-available-to-author-only...x.ru/epel/RPM-GPG-KEY-EPEL-${OSVER} || return 1
if ! rpm -q epel-release >/dev/null ; then
Info "Adding repository EPEL.."
if [ "${OSVER}" = "6" ]; then
rpm -iU http://d...content-available-to-author-only...m.com/repo/centos/epel/6/x86_64/epel-release-6-8.noarch.rpm || return 1
elif [ "${OSVER}" = "7" ]; then
rpm -iU http://d...content-available-to-author-only...m.com/repo/centos/epel/7/x86_64/e/epel-release-7-5.noarch.rpm || return 1
fi
fi
yum -y update mysql-libs || return 1
else
if ! rpm -q epel-release >/dev/null ; then
# epel-release already in extras repository which enabled by default
Info "Installing epel-release package.."
yum -y install epel-release || return 1
else
Info "Epel package already installed"
fi
fi
if ! grep -qE "mirrorlist=http://d...content-available-to-author-only...m.com/" /etc/yum.repos.d/epel.repo ; then
sed -i -r '/\[epel\]/,/\[epel/s|^(mirrorlist=).*|\1http://d...content-available-to-author-only...m.com/repo/centos/epel/mirrorlist.txt|' /etc/yum.repos.d/epel.repo
yum clean all || :
fi
# If install with packages use mirrorlist with cdn
if [ "${1}" = "true" ]; then
MirrorlistInstall epel epel
fi
}
InstallDebRepo() {
# Check debian/ubuntu base repo
return 0 # Function disabled
test "${ISPOSTYPE}" = "DEBIAN" || return 0
if ! CheckRepo ${OSVER} ; then
Warn "Standard ${reponame}-${OSVER} repository does not enabled. Add it to sources.list"
if [ "${reponame}" = "debian" ]; then
echo "deb http://f...content-available-to-author-only...n.org/debian ${OSVER} main contrib non-free" >> /etc/apt/sources.list
echo "deb http://f...content-available-to-author-only...n.org/debian ${OSVER}-updates main contrib non-free" >> /etc/apt/sources.list
echo "deb http://s...content-available-to-author-only...n.org ${OSVER}/updates main contrib non-free" >> /etc/apt/sources.list
else
echo "deb http://a...content-available-to-author-only...u.com/ubuntu ${OSVER} main restricted universe" >> /etc/apt/sources.list
echo "deb http://a...content-available-to-author-only...u.com/ubuntu ${OSVER}-updates main restricted universe" >> /etc/apt/sources.list
echo "deb http://s...content-available-to-author-only...u.com/ubuntu ${OSVER}-security main restricted universe multiverse" >> /etc/apt/sources.list
fi
apt-get -y update || return 1
fi
}
InstallBaseRepo() {
# Check and install ispsystem-base repo
test -z "${MIRROR}" && GetFastestMirror
InstallGpgKey || return 1
case ${ISPOSTYPE} in
REDHAT)
Infon "Checking ispsystem-base repo... "
if [ ! -f /etc/yum.repos.d/ispsystem-base.repo ] || ! CheckRepo ispsystem-base ; then
Warn "Not found"
Info "Adding repository ISPsystem-base.."
rm -f /etc/yum.repos.d/ispsystem-base.repo
${fetch} /etc/yum.repos.d/ispsystem-base.repo "http://d...content-available-to-author-only...m.com/repo/centos/ispsystem-base.repo" >/dev/null 2>&1 || return 1
else
Info "Found"
fi
:
;;
DEBIAN)
Infon "Checking ispsystem-base repo... "
if ! CheckRepo base-${OSVER} ; then
Warn "Not found"
Info "Adding repository ISPsystem-base.."
rm -f /etc/apt/sources.list.d/ispsystem-base.list
if echo "${MIRROR}" | grep -q intrepo ; then
base_mirror=download.ispsystem.com
else
base_mirror=${MIRROR}
fi
echo "deb http://${base_mirror}/repo/${reponame} base-${OSVER} main" > /etc/apt/sources.list.d/ispsystem-base.list
else
Info "Found"
fi
;;
esac
}
InstallRepo() {
# Install ispsystem main repo
# ${1} = true - Use cdn or mirrorlist
test -z "${MIRROR}" && GetFastestMirror
InstallEpelRepo ${1} || return 1
InstallBaseRepo ${1} || return 1
InstallGpgKey || return 1
case ${ISPOSTYPE} in
REDHAT)
Info "Adding repository ISPsystem.."
rm -f /etc/yum.repos.d/ispsystem.repo
if echo "${release}" | grep -qE "^(stable|beta|beta5|stable5|intbeta|intstable|alpha|5\.[0-9]+)$"; then
${fetch} /etc/yum.repos.d/ispsystem.repo.tmp "http://${MIRROR}/repo/centos/ispsystem5.repo" >/dev/null 2>&1 || return 1
sed -i -r "s/__VERSION__/${release}/g" /etc/yum.repos.d/ispsystem.repo.tmp && mv /etc/yum.repos.d/ispsystem.repo.tmp /etc/yum.repos.d/ispsystem.repo || exit
else
${fetch} /tmp/ispsystem.repo "http://${MIRROR}/repo/centos/ispsystem-template.repo" >/dev/null 2>&1 || return 1
sed -i -r "s|TYPE|${release}|g" /tmp/ispsystem.repo
mv /tmp/ispsystem.repo /etc/yum.repos.d/ispsystem.repo
fi
# If install with pacages use mirrorlist with cdn
if [ "${1}" = "true" ]; then
if ! echo "${MIRROR}" | grep -q intrepo; then
MirrorlistInstall ispsystem-base base
MirrorlistInstall ispsystem ${release}
fi
fi
# Check if release support gpg
local gpgenable
case ${release} in
beta|beta5)
gpgenable=yes
;;
5.*)
if [ ${release#5.} -gt 59 ]; then
gpgenable=yes
fi
;;
*)
;;
esac
if echo "${MIRROR}" | grep -q intrepo ; then
gpgenable=yes
fi
# Enable gpgkey verification
if [ -n "${gpgenable}" ]; then
for f in ispsystem ispsystem-base ; do
fname=/etc/yum.repos.d/${f}.repo
if grep -q 'gpgkey=$' ${fname} ; then
sed -i -r "s/(gpgkey=)$/\1file:\/\/\/etc\/pki\/rpm-gpg\/RPM-GPG-KEY-ISPsystem/g" ${fname}
sed -i -r "s/gpgcheck=0/gpgcheck=1/g" ${fname}
fi
done
fi
yum -y makecache || yum -y makecache || return 1
;;
DEBIAN)
Info "Adding repository ISPsystem.."
rm -f /etc/apt/sources.list.d/ispsystem.list
if echo "${release}" | grep -qE "^(stable|beta|intbeta|intstable|alpha|5\.[0-9]+)$"; then
if echo "${release}" | grep -qE "5\.[0-9]+"; then
echo "deb http://${MIRROR}/repo/${reponame} ${release}-${OSVER} main" > /etc/apt/sources.list.d/ispsystem.list
else
${fetch} /etc/apt/sources.list.d/ispsystem.list "http://${MIRROR}/repo/${reponame}/${OSVER}-ispsystem-${release}.list"
fi
if echo ${MIRROR} | grep -q cdn ; then
sed -i -r "s|(http://)download.ispsystem.com|\1cdn.ispsystem.com|g" /etc/apt/sources.list.d/ispsystem.list
fi
else
echo "deb http://${MIRROR}/repo/${reponame} ${release}-${OSVER} main" > /etc/apt/sources.list.d/ispsystem.list
fi
apt-get -y update >/dev/null
;;
FREEBSD)
mkdir -p /usr/local/etc/pkg/repos
${fetch} /usr/local/etc/pkg/repos/ispsystem.conf "http://${MIRROR}/repo/freebsd/${release}.conf"
if echo ${MIRROR} | grep -q cdn ; then
sed -i"" -r "s|\(http://\)download.ispsystem.com|\1cdn.ispsystem.com|g" /usr/local/etc/pkg/repos/ispsystem.conf
fi
pkg update
;;
*)
Error "Unsupported os family: ${ISPOSTYPE}"
;;
esac
mkdir -p /usr/local/mgr5/etc
chmod 750 /usr/local/mgr5/etc
if echo "${release}" | grep -qE '^5\.[0-9]+'; then
echo "${release}" > /usr/local/mgr5/etc/repo.version
elif [ "#${release}" = "#beta5" ]; then
echo "beta" > /usr/local/mgr5/etc/repo.version
elif [ "#${release}" = "#stable5" ]; then
echo "stable" > /usr/local/mgr5/etc/repo.version
else
echo "${release}" > /usr/local/mgr5/etc/repo.version
fi
}
PkgInstall() {
# Install package if error change mirror if possible
local pi_fail
pi_fail=1
while [ "#${pi_fail}" = "#1" ]; do
pi_fail=0
case ${ISPOSTYPE} in
REDHAT)
yum -y install ${@} || pi_fail=1
;;
DEBIAN)
apt-get -y update
apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y -q install ${@} || pi_fail=1
;;
FREEBSD)
pkg install -r ispsystem-${release} -y ${@} || pi_fail=1
;;
*)
;;
esac
if [ "#${pi_fail}" = "#0" ]; then
return 0
break
elif echo ${MIRROR} | grep -q cdn ; then
export MIRROR=download.ispsystem.com
InstallRepo
else
return 1
break
fi
done
}
PkgRemove() {
# Remove package
case ${ISPOSTYPE} in
REDHAT)
yum -y remove ${@}
;;
DEBIAN)
apt-get -y -q remove ${@}
;;
*)
return 1
;;
esac
}
CoreInstall() {
PkgInstall coremanager
}
Fail2Ban() {
if PkgAvailable coremanager-pkg-fail2ban ; then
# Package coremanager-pkg-fail2ban exist in repo (bug #26482)
PkgInstall coremanager-pkg-fail2ban || :
elif [ -x /usr/local/mgr5/sbin/fail2ban.sh ]; then
Info "Instaling fail2ban"
local failpkgs=fail2ban
if [ "${ISPOSTYPE}-${OSVER}" = "REDHAT-7" ]; then
failpkgs="fail2ban-server"
fi
PkgInstall ${failpkgs} || :
/usr/local/mgr5/sbin/fail2ban.sh && Info "fail2ban configured" || :
fi
}
if [ "#${noinstall}" != "#true" ]; then
# Installing coremanager
if [ -n "${inpkgname}" ]; then
inpkgname=$(echo ${inpkgname} | awk '{print tolower($0)}')
while [ -z "${mgr}" ] && [ -n "${inpkgname}" ]
do
case ${inpkgname} in
billmanager-standard)
mgr=billmgr
pkgname=billmanager-standard
;;
billmanager-advanced)
mgr=billmgr
pkgname=billmanager-advanced
;;
billmanager-corporate)
mgr=billmgr
pkgname=billmanager-corporate
;;
coremanager)
mgr=core
pkgname=coremanager
;;
ispmanager-lite-common|ispmanager-lite|ispmanager-pro|ispmanager-business)
mgr=ispmgr
# Rename Pro
if [ "${inpkgname}" = "ispmanager-pro" ]; then
pkgname=ispmanager-business
else
pkgname=${inpkgname}
fi
;;
vemanager|vmmanager-ovz)
mgr=vemgr
pkgname=vmmanager-ovz
;;
vmmanager-basic|vmmanager-kvm)
mgr=vmmgr
pkgname=vmmanager-kvm
;;
vmmanager-cloud)
mgr=vmmgr
pkgname=${inpkgname}
;;
dcimanager-essential|dcimanager-progressive|dcimanager-enterprise)
mgr=dcimgr
pkgname=${inpkgname}
;;
ipmanager|ipmanager-bind|ipmanager-pdns)
mgr=ipmgr
pkgname=${inpkgname}
;;
dnsmanager|dnsmanager-bind|dnsmanager-pdns)
mgr=dnsmgr
pkgname=${inpkgname}
;;
ispmanager)
mgr=ispmgr
;;
billmanager)
mgr=billmgr
;;
vmmanager)
mgr=vmmgr
;;
dcimanager)
mgr=dcimgr
;;
*)
if echo ${inpkgname} | grep -q \-; then
inpkgname=$(echo ${inpkgname} | cut -d- -f1)
else
Error "Incorrect package name"
exit 1
fi
;;
esac
done
fi
while [ -z ${mgr} ]
do
if [ ${ISPOSTYPE} != "FREEBSD" ]; then
Info "Which manager would You like to install ?"
echo "1) ISPmanager"
echo "2) VMmanager"
echo "3) DCImanager"
echo "4) DNSmanager"
echo "5) IPmanager"
echo "6) BILLmanager"
echo
read -p "Choose manager: " n
echo
echo "Chosen: ${n}"
echo
case "$n" in
1) mgr=ispmgr ;;
2) mgr=vmmgr ;;
3) mgr=dcimgr ;;
4) mgr=dnsmgr ;;
5) mgr=ipmgr ;;
6) mgr=billmgr ;;
*) ;;
esac
else
Info "Which manager would You like to install ?"
echo "1) ISPmanager"
echo "2) DNSmanager"
echo "3) IPmanager"
echo
read -p "Choose manager: " n
echo
case "$n" in
1) mgr=ispmgr ;;
2) mgr=dnsmgr ;;
3) mgr=ipmgr ;;
*) ;;
esac
fi
done
licname="${mgr}"
case "${mgr}" in
ipmgr)
while [ -z ${pkgname} ]
do
echo "What version do You want to install"
echo "1) IPmanager with bind (recommended)"
echo "2) IPmanager with pdns"
echo
read -p "Choose version: " n
echo
echo "Chosen: ${n}"
echo
case "$n" in
1) pkgname=ipmanager ;;
2) pkgname=ipmanager-pdns ;;
*) ;;
esac
done
;;
dnsmgr)
while [ -z ${pkgname} ]
do
echo "What version do You want to install"
echo "1) DNSmanager with bind (recommended)"
echo "2) DNSmanager with pdns"
echo
read -p "Choose version: " n
echo
echo "Chosen: ${n}"
echo
case "$n" in
1) pkgname=dnsmanager ;;
2) pkgname=dnsmanager-pdns ;;
*) ;;
esac
done
;;
dcimgr)
while [ -z ${pkgname} ]
do
echo "What version do You want to install"
echo "1) DCImanager"
echo "2) DCImanager-Enterprise"
echo
read -p "Choose version: " n
echo
echo "Chosen: ${n}"
echo
case "$n" in
1) pkgname=dcimanager-progressive ;;
2) pkgname=dcimanager-enterprise ;;
*) ;;
esac
done
;;
vemgr)
pkgname=vmmanager-ovz
;;
vmmgr)
while [ -z ${pkgname} ]
do
echo "What version do You want to install"
echo "1) VMmanager-KVM"
echo "2) VMmanager-OVZ"
echo "3) VMmanager-Cloud"
echo
read -p "Choose version: " n
echo
echo "Chosen: ${n}"
echo
case "$n" in
1) pkgname=vmmanager-kvm ;;
2)
pkgname=vmmanager-ovz
mgr=vemgr
;;
3) pkgname=vmmanager-cloud ;;
*) ;;
esac
done
;;
ispmgr)
while [ -z ${pkgname} ]
do
echo "What version do You want to install"
echo "1) ISPmanager-Lite with recommended software"
echo "2) ISPmanager-Lite minimal version"
echo "3) ISPmanager-Business"
echo
read -p "Choose version: " n
echo
echo "Chosen: ${n}"
echo
case "$n" in
1) pkgname=ispmanager-lite ;;
2) pkgname=ispmanager-lite-common ;;
3) pkgname=ispmanager-business ;;
*) ;;
esac
done
;;
core)
pkgname=coremanager
;;
billmgr)
while [ -z ${pkgname} ]
do
echo "What version do You want to install"
echo "1) BILLmanager"
echo "2) BILLmanager-Corporate"
echo
read -p "Choose version: " n
echo
echo "Chosen: ${n}"
echo
case "$n" in
1) pkgname=billmanager-advanced ;;
2) pkgname=billmanager-corporate ;;
*) ;;
esac
done
;;
esac
case ${pkgname} in
ispmanager-lite|ispmanager-lite-common)
if PkgInstalled ispmanager-business ; then
Error "ISPmanager-Business already installed"
exit 1
fi
;;
ispmanager-business)
if PkgInstalled ispmanager-lite-common; then
Error "ISPmanager-Lite already installed"
exit 1
fi
;;
billmanager-standard)
if PkgInstalled billmanager-advanced; then
Error "BILLmanager-Advanced already installed"
exit 1
fi
if PkgInstalled billmanager-corporate; then
Error "BILLmanager-Corporate already installed"
exit 1
fi
;;
billmanager-advanced)
if PkgInstalled billmanager-standard; then
Error "BILLmanager-Standard already installed. Run \"/usr/local/mgr5/sbin/billmgr-upgrade.sh advanced\" to upgrade"
exit 1
fi
if PkgInstalled billmanager-corporate; then
Error "BILLmanager-Corporate already installed"
exit 1
fi
;;
billmanager-corporate)
if PkgInstalled billmanager-advanced; then
Error "BILLmanager-Advanced already installed. Run \"/usr/local/mgr5/sbin/billmgr-upgrade.sh corporate\" to upgrade"
exit 1
fi
if PkgInstalled billmanager-standard; then
Error "BILLmanager-Standard already installed. Run \"/usr/local/mgr5/sbin/billmgr-upgrade.sh corporate\" to upgrade"
exit 1
fi
;;
*) ;;
esac
# CheckConflicts ${pkgname}
StartInstall
trap CancelInstall INT
if [ "#${added_repo}" != "#yes" ]; then
InstallDebRepo || ErrorInstall
IR_FAIL=0
InstallRepo true || IR_FAIL=1
if [ ${IR_FAIL} -ne 0 ]; then
Error "Some errors with repository"
if echo "${MIRROR}" | grep -q "cdn"; then
Info "Falling back to mirror download.ispsystem.com"
export MIRROR=download.ispsystem.com
IR_FAIL=0
InstallRepo || IR_FAIL=1
fi
fi
if [ ${IR_FAIL} -ne 0 ]; then
Error "Problems with repository. Please try again in an hour"
ErrorInstall
fi
else
InstallDebRepo || ErrorInstall
InstallEpelRepo || ErrorInstall
InstallBaseRepo || ErrorInstall
fi
default_OS_LIST="centos-6 debian-wheezy centos-7 debian-jessie"
default_ARCH_LIST="i686 x86_64"
vmmanager_kvm_ARCH_LIST="x86_64"
vmmanager_cloud_OS_LIST="centos-6 centos-7"
vmmanager_cloud_ARCH_LIST="x86_64"
vmmanager_ovz_OS_LIST="centos-6 centos-7 debian-wheezy"
vmmanager_ovz_ARCH_LIST="x86_64"
ipmanager_OS_LIST="centos-6 centos-7 debian-wheezy debian-jessie"
dnsmanager_OS_LIST="centos-6 centos-7 debian-wheezy debian-jessie"
billmanager_standard_OS_LIST="centos-7 debian-jessie"
billmanager_standard_ARCH_LIST="x86_64"
billmanager_standard_OS_LIST_beta="centos-7 debian-jessie"
billmanager_standard_ARCH_LIST_beta="x86_64"
billmanager_advanced_OS_LIST="centos-7 debian-jessie"
billmanager_advanced_ARCH_LIST="x86_64"
billmanager_corporate_OS_LIST="centos-7 debian-jessie"
billmanager_corporate_ARCH_LIST_alpha="x86_64"
dcimanager_essential_OS_LIST="centos-6 debian-wheezy"
dcimanager_progressive_OS_LIST="centos-6 debian-wheezy"
dcimanager_enterprise_OS_LIST="centos-6 debian-wheezy"
ispmanager_lite_common_OS_LIST="centos-6 centos-7 debian-wheezy debian-jessie ubuntu-trusty ubuntu-xenial"
ispmanager_lite_OS_LIST="${ispmanager_lite_common_OS_LIST}"
ispmanager_lite_common_OS_LIST_stable="centos-6 centos-7 debian-wheezy debian-jessie ubuntu-trusty ubuntu-xenial"
ispmanager_lite_OS_LIST_stable="centos-r centos-7 debian-wheezy debian-jessie ubuntu-trusty ubuntu-xenial"
ispmanager_business_OS_LIST="centos-6 centos-7 debian-wheezy debian-jessie"
ispmanager_business_common_OS_LIST="${ispmanager_business_OS_LIST}"
# # If pkg exist in list use them else use default
# if [ -n "$(eval echo \${$(echo ${pkgname} | sed 's/-/_/g')_OS_LIST_${release}})" ]; then
# os_list=$(eval echo \${$(echo ${pkgname} | sed 's/-/_/g')_OS_LIST_${release}})
# elif [ -n "$(eval echo \${$(echo ${pkgname} | sed 's/-/_/g')_OS_LIST})" ]; then
# os_list=$(eval echo \${$(echo ${pkgname} | sed 's/-/_/g')_OS_LIST})
# else
# os_list="${default_OS_LIST}"
# fi
# if [ -n "$(eval echo \${$(echo ${pkgname} | sed 's/-/_/g')_ARCH_LIST_${release}})" ]; then
# arch_list=$(eval echo \${$(echo ${pkgname} | sed 's/-/_/g')_ARCH_LIST_${release}})
# elif [ -n "$(eval echo \${$(echo ${pkgname} | sed 's/-/_/g')_ARCH_LIST})" ]; then
# arch_list=$(eval echo \${$(echo ${pkgname} | sed 's/-/_/g')_ARCH_LIST})
# else
# arch_list="${default_ARCH_LIST}"
# fi
os_list=$(eval echo \${$(echo ${pkgname} | sed 's/-/_/g')_OS_LIST})
arch_list="${default_ARCH_LIST}"
MgrExist() {
Info "package ${pkgname} exists for follow Linux distribution and architectures:"
Info "Operation systems: ${os_list}"
if [ -n "$(eval echo \${$(echo ${pkgname} | sed 's/-/_/g')_OS_LIST_beta})" ]; then
Info "Operation systems(beta repository): $(eval echo \${$(echo ${pkgname} | sed 's/-/_/g')_OS_LIST_beta})"
fi
Info "Architectures: ${arch_list}"
if [ -n "$(eval echo \${$(echo ${pkgname} | sed 's/-/_/g')_ARCH_LIST_beta})" ]; then
Info "Architectures(beta repository): $(eval echo \${$(echo ${pkgname} | sed 's/-/_/g')_ARCH_LIST_beta})"
fi
}
MgrNotExist() {
cur_arch=$(uname -m)
if [ "${ISPOSTYPE}" = "REDHAT" ]; then
cur_os_name="centos"
else
cur_os_name=$(lsb_release -s -i | awk '{print tolower($0)}')
fi
cur_os_ver=${OSVER}
cur_os="${cur_os_name}-${cur_os_ver}"
mgrnotexist() {
Error "Package ${pkgname} does not support ${cur_os} ( ${cur_arch} )"
CancelInstall norepo
MgrExist
}
if ! echo "${arch_list}" | grep -q ${cur_arch}; then
mgrnotexist
elif ! echo "${os_list}" | grep -q ${cur_os}; then
mgrnotexist
fi
trap - INT TERM EXIT
exit 1
}
PkgAvailable ${pkgname} || MgrNotExist
if [ "${mgr}" != "core" ]; then
CoreInstall || ErrorInstall
# Xmlgen...
/usr/local/mgr5/sbin/mgrctl exit >/dev/null
# License
licfetch_count=0
export HTTP_PROXY=""
export http_proxy=""
while true
do
licerror=0
licfetch_count=$(expr ${licfetch_count} + 1)
/usr/local/mgr5/sbin/licctl fetch ${mgr} ${ACTIVATION_KEY} >/dev/null 2>&1 || licerror=$?
if [ ${licerror} -eq 0 ]; then
# if not error code get info and exit
LicInstall
break
elif [ ${licfetch_count} -lt 3 ]; then
# if less than 3 attempt
sleep 2
elif [ -z "${ACTIVATION_KEY}" ]; then
if [ "#${mgr}" = "#ispmgr" ]; then
Warning "Trial license for this IP has expired"
else
Warning "Can not fetch free license for this IP. You can try again later"
fi
Warning "You have no commercial license for ${pkgname} or it can't be activated automatically"
if [ "#${silent}" != "#true" ]; then
printf "Please enter activation key or press Enter to exit: "
read ACTIVATION_KEY
export ACTIVATION_KEY
fi
if [ -z "${ACTIVATION_KEY}" ]; then
exit_flag=1
fi
else
Error "Invalid activation key"
exit_flag=1
fi
if [ -n "${exit_flag}" ]; then
if locale 2>/dev/null | grep LANG | grep -q "ru_RU.UTF-8" ; then
Info "Ð”Ð¾ÐºÑƒÐ¼ÐµÐ½Ñ‚Ð°Ñ†Ð¸Ñ Ð½Ð°Ñ…Ð¾Ð´Ð¸Ñ‚ÑÑ Ð¿Ð¾ адреÑу: http://d...content-available-to-author-only...m.ru/index.php/Схема_лицензированиÑ"
else
Info "Documentation can be found at http://d...content-available-to-author-only...m.com/index.php/Software_licensing_policy"
fi
CancelInstall nolic
trap - INT TERM EXIT
exit 1
fi
done
# Fetching license for repo change
/usr/local/mgr5/sbin/licctl fetch ${mgr} >/dev/null 2>&1 || :
if [ -z "${core_installed}" ]; then
Info "Checking COREmanager downgrade"
crelease=${release}
GetCurrentRepo
if [ "${crelease}" != "${release}" ]; then
Info "Downgrading COREmanager"
PkgRemove coremanager
PkgInstall coremanager
else
Info "Not need to downgrade COREmanager"
fi
else
Info "COREmanager installed before this run. Downgrade checking skipped"
fi
LetsEncrypt || :
fi
PkgInstall ${pkgname} || ErrorInstall
if [ -z "${disable_fail2ban}" ]; then
Fail2Ban
fi
FinishInstall &
RemoveCdnRepo # Remove cdn repo or mirrorrlist-install
MgrInstalled ${mgr} ${pkgname}
trap - INT TERM EXIT
else
InstallRepo
LogClean
fi