2020-01-16 23:55:54 +01:00
#!/bin/bash
2020-01-17 16:01:24 +01:00
#CyberPanel Upgrade script
2020-01-16 23:55:54 +01:00
2020-01-17 16:01:24 +01:00
export LC_CTYPE = en_US.UTF-8
SUDO_TEST = $( set )
2020-01-16 23:55:54 +01:00
SERVER_OS = 'Undefined'
OUTPUT = $( cat /etc/*release)
2020-01-29 12:32:55 +05:00
TEMP = $( curl --silent https://cyberpanel.net/version.txt)
2020-01-29 12:42:54 +05:00
BRANCH_NAME = v${ TEMP : 12 : 3 } .${ TEMP : 25 : 1 }
2020-03-07 21:22:53 +01:00
GIT_URL = "github.com/usmannasir/cyberpanel"
GIT_CONTENT_URL = "raw.githubusercontent.com/usmannasir/cyberpanel"
SERVER_COUNTRY = "unknow"
SERVER_COUNTRY = $( curl --silent --max-time 5 https://cyberpanel.sh/?country)
2020-04-11 11:31:13 +05:00
### Update and remove not needed repos
rm -f /etc/yum.repos.d/ius-archive.repo
rm -f /etc/yum.repos.d/copart-restic-epel-7.repo
rm -f /etc/yum.repos.d/dovecot.repo
rm -f /etc/yum.repos.d/epel.repo
rm -f /etc/yum.repos.d/epel-testing.repo
rm -f /etc/yum.repos.d/frank.repo
rm -f /etc/yum.repos.d/ius.repo
rm -f /etc/yum.repos.d/ius-testing.repo
rm -f /etc/yum.repos.d/MariaDB.repo
rm -f /etc/yum.repos.d/lux.repo
2020-04-11 12:44:40 +05:00
rm -f /etc/yum.repos.d/gf.repo
rm -f /etc/yum.repos.d/powerdns-auth-42.repo
2020-04-12 11:27:55 +05:00
rm -rf /etc/yum.repos.d/powerdns-auth-master.repo
rm -rf /etc/yum.repos.d/gf.repo.rpmnew
2020-04-13 15:53:55 +05:00
#sed -i 's|enabled=1|enabled=0|g' /etc/yum.repos.d/CentOS-AppStream.repo
2020-04-11 12:18:38 +05:00
yum clean all
yum update -y
yum autoremove epel-release -y
rm -f /etc/yum.repos.d/epel.repo
rm -f /etc/yum.repos.d/epel.repo.rpmsave
2020-04-11 11:31:13 +05:00
2020-04-11 15:06:02 +05:00
2020-04-11 11:31:13 +05:00
##
2020-03-07 21:22:53 +01:00
if [ [ ${# SERVER_COUNTRY } = = "2" ] ] || [ [ ${# SERVER_COUNTRY } = = "6" ] ] ; then
echo -e "\nChecking server..."
else
echo -e "\nChecking server..."
SERVER_COUNTRY = "unknow"
fi
2020-03-07 22:05:20 +01:00
#SERVER_COUNTRY="CN"
#for test
2020-03-07 22:03:45 +01:00
2020-03-07 21:22:53 +01:00
if [ [ $SERVER_COUNTRY = = "CN" ] ] ; then
GIT_URL = "gitee.com/qtwrk/cyberpanel"
GIT_CONTENT_URL = "gitee.com/qtwrk/cyberpanel/raw"
fi
2020-03-10 17:23:30 +01:00
regenerate_cert( ) {
cat << EOF > /usr/local/CyberCP/cert_conf
[ req]
prompt = no
distinguished_name = cyberpanel
[ cyberpanel]
commonName = www.example.com
countryName = CP
localityName = CyberPanel
organizationName = CyberPanel
organizationalUnitName = CyberPanel
stateOrProvinceName = CP
emailAddress = mail@example.com
name = CyberPanel
surname = CyberPanel
givenName = CyberPanel
initials = CP
dnQualifier = CyberPanel
[ server_exts]
extendedKeyUsage = 1.3.6.1.5.5.7.3.1
EOF
if [ [ $1 = = "8090" ] ] ; then
openssl req -x509 -config /usr/local/CyberCP/cert_conf -extensions 'server_exts' -nodes -days 820 -newkey rsa:2048 -keyout /usr/local/lscp/conf/key.pem -out /usr/local/lscp/conf/cert.pem
fi
if [ [ $1 = = "7080" ] ] ; then
if [ [ -f /usr/local/lsws/admin/conf/webadmin.key ] ] ; then
key_path = "/usr/local/lsws/admin/conf/webadmin.key"
cert_path = "/usr/local/lsws/admin/conf/webadmin.crt"
else
key_path = "/usr/local/lsws/admin/conf/cert/admin.key"
cert_path = "/usr/local/lsws/admin/conf/cert/admin.crt"
fi
openssl req -x509 -config /usr/local/CyberCP/cert_conf -extensions 'server_exts' -nodes -days 820 -newkey rsa:2048 -keyout $key_path -out $cert_path
fi
rm -f /usr/local/CyberCP/cert_conf
}
2020-01-16 23:55:54 +01:00
2020-02-09 13:28:01 +01:00
input_branch( ) {
echo -e "\nPress Enter key to continue with latest version or Enter specific version such as: \e[31m1.9.4\e[39m , \e[31m1.9.5\e[39m ...etc"
echo -e "\nIf nothing is input in 10 seconds , script will proceed with latest stable. "
echo -e "\nPlease press Enter key , or specify a version number ,or wait for 10 seconds timeout: "
printf "%s" ""
read -t 10 TMP_YN
if [ [ $TMP_YN = = "" ] ] ; then
BRANCH_NAME = " v ${ TEMP : 12 : 3 } . ${ TEMP : 25 : 1 } "
echo -e " \nBranch name set to $BRANCH_NAME "
else
base_number = "1.9.3"
if [ [ $TMP_YN = = *.*.* ] ] ; then
#check input if it's valid format as X.Y.Z
output = $( awk -v num1 = " $base_number " -v num2 = " $TMP_YN " '
BEGIN {
print "num1" , ( num1 < num2 ? "<" : ">=" ) , "num2"
}
' )
if [ [ $output = = *">=" * ] ] ; then
echo -e "\nYou must use version number higher than 1.9.4"
exit
else
BRANCH_NAME = " v $TMP_YN "
echo " set branch name to $BRANCH_NAME "
fi
else
echo -e "\nPlease input a valid format version number."
exit
fi
fi
}
2020-01-18 00:11:07 +01:00
install_utility( ) {
if [ [ ! -f /usr/bin/cyberpanel_utility ] ] ; then
wget -q -O /usr/bin/cyberpanel_utility https://cyberpanel.sh/misc/cyberpanel_utility.sh
chmod 700 /usr/bin/cyberpanel_utility
fi
}
2020-01-17 16:01:24 +01:00
check_root( ) {
echo -e "\nChecking root privileges...\n"
if echo $SUDO_TEST | grep SUDO > /dev/null ; then
echo -e "\nYou are using SUDO , please run as root user...\n"
2020-04-18 20:35:19 +02:00
echo -e "\nIf you don't have direct access to root user, please run \e[31msudo su -\e[39m command (do NOT miss the \e[31m-\e[39m at end or it will fail) and then run upgrade command again."
2020-01-17 16:01:24 +01:00
exit
fi
if [ [ $( id -u) != 0 ] ] > /dev/null; then
echo -e "\nYou must use root user to upgrade CyberPanel...\n"
exit
else
echo -e "\nYou are runing as root...\n"
fi
}
2020-01-16 23:55:54 +01:00
check_return( ) {
#check previous command result , 0 = ok , non-0 = something wrong.
if [ [ $? -eq "0" ] ] ; then
:
else
echo -e "\ncommand failed, exiting..."
exit
fi
}
2020-02-09 13:28:01 +01:00
input_branch
2020-01-17 16:01:24 +01:00
check_root
2020-01-16 23:55:54 +01:00
echo -e "\nChecking OS..."
OUTPUT = $( cat /etc/*release)
if echo $OUTPUT | grep -q "CentOS Linux 7" ; then
echo -e "\nDetecting CentOS 7.X...\n"
SERVER_OS = "CentOS7"
2020-04-13 11:01:15 +05:00
curl https://raw.githubusercontent.com/usmannasir/cyberpanel/v2.0.1/install/CyberPanel.repo > /etc/yum.repos.d/CyberPanel.repo
2020-01-16 23:55:54 +01:00
yum clean all
yum update -y
elif echo $OUTPUT | grep -q "CloudLinux 7" ; then
echo -e "\nDetecting CloudLinux 7.X...\n"
SERVER_OS = "CentOS7"
2020-04-13 11:01:15 +05:00
curl https://raw.githubusercontent.com/usmannasir/cyberpanel/v2.0.1/install/CyberPanel.repo > /etc/yum.repos.d/CyberPanel.repo
2020-01-16 23:55:54 +01:00
yum clean all
yum update -y
elif echo $OUTPUT | grep -q "CentOS Linux 8" ; then
2020-04-13 11:01:15 +05:00
curl https://raw.githubusercontent.com/usmannasir/cyberpanel/v2.0.1/install/CyberPanel8.repo > /etc/yum.repos.d/CyberPanel.repo
2020-01-16 23:55:54 +01:00
echo -e "\nDetecting CentOS 8.X...\n"
SERVER_OS = "CentOS8"
yum clean all
yum update -y
elif echo $OUTPUT | grep -q "Ubuntu 18.04" ; then
echo -e "\nDetecting Ubuntu 18.04...\n"
SERVER_OS = "Ubuntu"
else
cat /etc/*release
echo -e "\nUnable to detect your OS...\n"
echo -e "\nCyberPanel is supported on Ubuntu 18.04, CentOS 7.x, CentOS 8.x and CloudLinux 7.x...\n"
exit 1
fi
if [ $SERVER_OS = "CentOS7" ] ; then
yum -y install yum-utils
yum -y groupinstall development
2020-04-14 16:39:47 +05:00
yum --enablerepo= CyberPanel install -y wget strace htop net-tools telnet curl which bc telnet htop libevent-devel gcc libattr-devel xz-devel gpgme-devel curl-devel git socat openssl-devel MariaDB-shared mariadb-devel python36u python36u-pip python36u-devel
2020-01-16 23:55:54 +01:00
elif [ $SERVER_OS = "CentOS8" ] ; then
2020-04-13 11:01:15 +05:00
dnf install -y wget strace htop net-tools telnet curl which bc telnet htop libevent-devel gcc libattr-devel xz-devel mariadb-devel curl-devel git platform-python-devel tar socat
2020-01-16 23:55:54 +01:00
dnf --enablerepo= PowerTools install gpgme-devel -y
dnf install python3 -y
else
apt update -y
DEBIAN_FRONTEND = noninteractive apt upgrade -y
2020-04-16 17:24:18 +05:00
DEBIAN_FRONTEND = noninteracitve apt install -y htop telnet libcurl4-gnutls-dev libgnutls28-dev libgcrypt20-dev libattr1 libattr1-dev liblzma-dev libgpgme-dev libmariadbclient-dev libcurl4-gnutls-dev libssl-dev nghttp2 libnghttp2-dev idn2 libidn2-dev libidn2-0-dev librtmp-dev libpsl-dev nettle-dev libgnutls28-dev libldap2-dev libgssapi-krb5-2 libk5crypto3 libkrb5-dev libcomerr2 libldap2-dev virtualenv git
2020-01-16 23:55:54 +01:00
DEBIAN_FRONTEND = noninteractive apt install -y python3-pip
DEBIAN_FRONTEND = noninteractive apt install -y build-essential libssl-dev libffi-dev python3-dev
DEBIAN_FRONTEND = noninteractive apt install -y python3-venv
fi
if [ $SERVER_OS = "Ubuntu" ] ; then
pip3 install virtualenv
check_return
else
2020-02-13 09:44:15 +05:00
pip3.6 install virtualenv = = 16.7.9
2020-01-16 23:55:54 +01:00
check_return
fi
2020-04-11 15:51:19 +05:00
2020-04-11 20:55:39 +05:00
if [ [ -f /usr/local/CyberPanel/bin/python2 ] ] ; then
2020-04-11 21:06:34 +05:00
echo -e "\nPython 2 dectected, doing resetup...\n"
2020-04-11 20:55:39 +05:00
rm -rf /usr/local/CyberPanel/bin
virtualenv -p /usr/bin/python3 --system-site-packages /usr/local/CyberPanel
check_return
2020-04-12 11:21:31 +05:00
elif [ [ -d /usr/local/CyberPanel/bin/ ] ] ; then
2020-04-11 20:55:39 +05:00
echo -e "\nNo need to resetup virtualenv at /usr/local/CyberPanel...\n"
else
2020-04-11 21:06:34 +05:00
echo -e "\nNothing found, need fresh setup...\n"
virtualenv -p /usr/bin/python3 --system-site-packages /usr/local/CyberPanel
2020-04-11 20:55:39 +05:00
check_return
2020-04-11 15:51:19 +05:00
fi
2020-02-09 13:28:01 +01:00
rm -f requirments.txt
2020-04-11 12:11:46 +05:00
wget -O /usr/local/cyberpanel-pip.zip https://rep.cyberpanel.net/cyberpanel-pip.zip
check_return
2020-04-11 12:37:12 +05:00
rm -rf /usr/local/pip-packs/
2020-04-11 12:11:46 +05:00
unzip /usr/local/cyberpanel-pip.zip -d /usr/local
check_return
2020-01-16 23:55:54 +01:00
. /usr/local/CyberPanel/bin/activate
check_return
if [ $SERVER_OS = "Ubuntu" ] ; then
. /usr/local/CyberPanel/bin/activate
check_return
2020-04-23 12:48:54 +05:00
pip3 install --ignore-installed -r /usr/local/pip-packs/*
2020-01-16 23:55:54 +01:00
check_return
else
source /usr/local/CyberPanel/bin/activate
check_return
2020-04-11 12:18:38 +05:00
pip3.6 install --ignore-installed /usr/local/pip-packs/*
2020-01-16 23:55:54 +01:00
check_return
fi
2020-04-11 15:53:32 +05:00
## Doing again to prevent an error - dont confuse later
virtualenv -p /usr/bin/python3 --system-site-packages /usr/local/CyberPanel
check_return
##
2020-04-11 15:51:19 +05:00
2020-01-16 23:55:54 +01:00
rm -rf upgrade.py
2020-03-07 21:22:53 +01:00
wget https://$GIT_CONTENT_URL /${ BRANCH_NAME } /plogical/upgrade.py
if [ [ $SERVER_COUNTRY = = "CN" ] ] ; then
2020-03-07 23:38:38 +01:00
sed -i 's|wget https://raw.githubusercontent.com/usmannasir/cyberpanel/v1.9.4/lscpd-0.2.4 -P /usr/local/lscp/bin/|cp -f /usr/local/CyberCP/lscpd-0.2.4 /usr/local/lscp/bin/lscpd-0.2.4|g' upgrade.py
2020-03-07 22:03:45 +01:00
sed -i 's|wget https://raw.githubusercontent.com/usmannasir/cyberpanel/%s/lscpd-0.2.4 -P /usr/local/lscp/bin/|cp -f /usr/local/CyberCP/lscpd-0.2.4 /usr/local/lscp/bin/lscpd-0.2.4|g' upgrade.py
2020-04-11 21:06:34 +05:00
#sed -i $'s/0.2.4\' % (branch)/0.2.4\'/' upgrade.py
2020-03-07 21:22:53 +01:00
sed -i 's|raw.githubusercontent.com/usmannasir/cyberpanel|' ${ GIT_CONTENT_URL } '|g' upgrade.py
sed -i 's|git clone https://github.com/usmannasir/cyberpanel|git clone https://' ${ GIT_URL } '|g' upgrade.py
fi
2020-01-22 14:22:06 +05:00
/usr/local/CyberPanel/bin/python upgrade.py $BRANCH_NAME
2020-01-16 23:55:54 +01:00
check_return
2020-04-11 15:51:19 +05:00
2020-04-11 20:55:39 +05:00
if [ [ -f /usr/local/CyberCP/bin/python2 ] ] ; then
rm -rf /usr/local/CyberCP/bin
virtualenv -p /usr/bin/python3 /usr/local/CyberCP
2020-04-12 11:21:31 +05:00
elif [ [ -d /usr/local/CyberCP/bin/ ] ] ; then
2020-04-11 20:55:39 +05:00
echo -e "\nNo need to resetup virtualenv at /usr/local/CyberCP...\n"
else
virtualenv -p /usr/bin/python3 --system-site-packages /usr/local/CyberCP
check_return
2020-04-11 15:51:19 +05:00
fi
2020-01-16 23:55:54 +01:00
check_return
if [ $SERVER_OS = "Ubuntu" ] ; then
. /usr/local/CyberCP/bin/activate
check_return
2020-04-23 12:48:54 +05:00
pip3 install --ignore-installed -r /usr/local/pip-packs/*
2020-01-16 23:55:54 +01:00
check_return
else
source /usr/local/CyberCP/bin/activate
check_return
2020-04-11 12:11:46 +05:00
pip3.6 install --ignore-installed /usr/local/pip-packs/*
2020-01-16 23:55:54 +01:00
check_return
fi
##
2020-01-24 21:12:25 +05:00
rm -f wsgi-lsapi-1.5.tgz
2020-01-16 23:55:54 +01:00
rm -rf wsgi-lsapi-1.4
2020-01-24 21:12:25 +05:00
wget http://www.litespeedtech.com/packages/lsapi/wsgi-lsapi-1.5.tgz
tar xf wsgi-lsapi-1.5.tgz
cd wsgi-lsapi-1.5
2020-01-16 23:55:54 +01:00
/usr/local/CyberPanel/bin/python ./configure.py
make
cp lswsgi /usr/local/CyberCP/bin/
2020-01-31 11:41:58 +01:00
sed -i 's|python2|python|g' /usr/bin/adminPass
2020-01-16 23:55:54 +01:00
chmod 700 /usr/bin/adminPass
2020-02-01 15:48:29 +01:00
if [ [ ! -f /usr/sbin/ipset ] ] && [ [ $SERVER_OS = = "Ubuntu" ] ] ; then
ln -s /sbin/ipset /usr/sbin/ipset
fi
2020-01-23 22:32:39 +01:00
if [ [ -f /etc/cyberpanel/webadmin_passwd ] ] ; then
chmod 600 /etc/cyberpanel/webadmin_passwd
fi
2020-01-20 21:34:25 +01:00
if [ [ -f /etc/pure-ftpd/pure-ftpd.conf ] ] ; then
sed -i 's|NoAnonymous no|NoAnonymous yes|g' /etc/pure-ftpd/pure-ftpd.conf
fi
2020-01-23 22:32:39 +01:00
install_utility
2020-01-18 00:11:07 +01:00
2020-03-10 17:23:30 +01:00
output = $( timeout 3 openssl s_client -connect 127.0.0.1:8090 2>/dev/null)
echo $output | grep -q "mail@example.com"
if [ [ $? = = "0" ] ] ; then
# it is using default installer generated cert
regenerate_cert 8090
fi
output = $( timeout 3 openssl s_client -connect 127.0.0.1:7080 2>/dev/null)
echo $output | grep -q "mail@example.com"
if [ [ $? = = "0" ] ] ; then
regenerate_cert 7080
fi
2020-02-01 17:08:35 +01:00
if [ [ $SERVER_OS = = "CentOS7" ] ] ; then
2020-02-21 14:08:42 +01:00
sed -i 's|error_reporting = E_ALL \& ~E_DEPRECATED \& ~E_STRICT|error_reporting = E_ALL \& ~E_DEPRECATED \& ~E_STRICT|g' /usr/local/lsws/{ lsphp72,lsphp73} /etc/php.ini
#fix php.ini & issue
2020-02-01 17:08:35 +01:00
yum list installed lsphp74-devel
if [ [ $? != "0" ] ] ; then
yum install -y lsphp74-devel
fi
fi
if [ [ $SERVER_OS = = "Ubuntu" ] ] ; then
2020-03-10 17:23:30 +01:00
dpkg -l lsphp74-dev > /dev/null 2>& 1
2020-02-01 17:08:35 +01:00
if [ [ $? != "0" ] ] ; then
apt install -y lsphp74-dev
fi
fi
2020-01-28 18:31:54 +01:00
if [ [ ! -f /usr/local/lsws/lsphp74/lib64/php/modules/zip.so ] ] && [ [ $SERVER_OS = = "CentOS7" ] ] ; then
2020-03-10 17:23:30 +01:00
yum list installed libzip-devel > /dev/null 2>& 1
2020-01-30 19:16:32 +01:00
if [ [ $? = = "0" ] ] ; then
yum remove -y libzip-devel
fi
2020-02-01 17:08:35 +01:00
2020-02-17 16:06:45 +01:00
yum install -y https://cdn.cyberpanel.sh/misc/libzip-0.11.2-6.el7.psychotic.x86_64.rpm
yum install -y https://cdn.cyberpanel.sh/misc/libzip-devel-0.11.2-6.el7.psychotic.x86_64.rpm
2020-02-06 19:15:33 +01:00
yum install lsphp74-devel
if [ [ ! -d /usr/local/lsws/lsphp74/tmp ] ] ; then
mkdir /usr/local/lsws/lsphp74/tmp
fi
/usr/local/lsws/lsphp74/bin/pecl channel-update pecl.php.net
/usr/local/lsws/lsphp74/bin/pear config-set temp_dir /usr/local/lsws/lsphp74/tmp
2020-01-28 18:26:00 +01:00
/usr/local/lsws/lsphp74/bin/pecl install zip
2020-02-01 17:28:11 +01:00
if [ [ $? = = 0 ] ] ; then
2020-02-06 19:15:33 +01:00
echo "extension=zip.so" > /usr/local/lsws/lsphp74/etc/php.d/20-zip.ini
chmod 755 /usr/local/lsws/lsphp74/lib64/php/modules/zip.so
2020-02-01 17:28:11 +01:00
else
2020-02-06 19:15:33 +01:00
echo -e "\nlsphp74-zip compilation failed..."
2020-02-02 15:13:46 +01:00
fi
2020-01-28 18:26:00 +01:00
fi
#fix the lsphp74-zip missing issue.
2020-01-18 00:11:07 +01:00
2020-01-16 23:55:54 +01:00
##
systemctl restart lscpd
2020-02-09 13:28:01 +01:00
rm -f requirements.txt
rm -f requirments.txt
rm -f upgrade.py
rm -rf wsgi-lsapi-1.5
rm -f wsgi-lsapi-1.5.tgz
rm -f /usr/local/composer.sh
# clean up
2020-01-16 23:55:54 +01:00
echo "###################################################################"
echo " CyberPanel Upgraded "
echo "###################################################################"