diff --git a/cyberpanel.sh b/cyberpanel.sh index c502f7e98..b91ceac03 100644 --- a/cyberpanel.sh +++ b/cyberpanel.sh @@ -1,444 +1,821 @@ #!/bin/bash +#set -e -o pipefail +#set -x +#set -u + + #CyberPanel installer script for CentOS 7.X, CentOS 8.X, CloudLinux 7.X, Ubuntu 18.04 and Ubuntu 20.04 +#For whoever may edit this script, please follow : +#Please use Pre_Install_xxx() and Post_Install_xxx() if you want to something respectively before or after the panel installation +#and update below accordingly +#Please use variable/functions name as MySomething or My_Something, and please try not to use too-short abbreviation :) +#Please use On/Off, True/False, Yes/No. -SUDO_TEST=$(set) +#workflow: +#Set_Default_Variables() ---> set some default variable for later use +#Check_Root() ---> check for root +#Check_Server_IP() ---> check for server IP and geolocation at country level +#Check_OS() ---> check system , support on centos7/8 ubutnu18/20 and cloudlinux 7 , 8 is untested. +#Check_Virualization() ---> check for virtualizaon , LXC not suppoed , some edit needed on OVZ +#Check_Panel() ---> check to make sure no other panel is installed +#Check_Porcess() ---> check no other process like apache is running +#Check_Provider() ---> check the provider, certain provider like Alibaba or tencent yun may need some special change +#Check_Argument() ---> parse argument and go to Argument_Mode() or Interactive_Mode() respectively +#Pre_Install_Setup_Repository() ---> setup/install repositories for centos system. +#go to Pre_Install_Setup_CN_Repository() if server is within China. +#Pre_Install_Setup_Git_URL() ---> form up github URL , use Gitee for servers within China. +#Pre_Install_Required_Components() ---> install required softwares and git clone it +#Pre_Install_System_Tweak() ---> set up SWAP and apply some system tweak depends on providers +#Main_Installation() ---> change some code within python files for CN servers and start to install +#Post_Install_Addon_Memcached() ---> Install Memcached extension and process +#Post_Install_Addon_Redis() ---> Install Redis extension and process +#Post_Install_Required_Components() ---> install some required softwares. +#Post_Install_PHP_Session_Setup() ---> set up PHP session +#Post_Install_PHP_TimezoneDB() ---> set up PHP timezoneDB +#Post_Install_Regenerate_Cert() ---> regenerate cert for :7080 and :8090 to avoid Chrome on MacOS blocking. +#Post_Install_Regenerate_Webadmin_Console_Passwd() ---> regenerate the webadmin console password +#Post_Install_Setup_Watchdog() ---> set up watchdog script for webserver and MariaDB. +#Post_Install_Setup_Utility() ---> set up utility script for some handy features +#Post_Install_Tweak() ---> some patches/fixes on certain systems +#Post_Install_Display_Final_Info() ---> display installation successful information. -DEV="OFF" -POSTFIX_VARIABLE="ON" -POWERDNS_VARIABLE="ON" -PUREFTPD_VARIABLE="ON" -### Remote MySQL Variables +Sudo_Test=$(set) +#for SUDO check -REMOTE_MYSQL='OFF' -MYSQL_HOST='' -MYSQL_DB='' -MYSQL_USER='' -MYSQL_PASSWORD='' -MYSQL_PORT='' +Set_Default_Variables() { -PROVIDER="undefined" -SERIAL_NO="" -DIR=$(pwd) -TEMP=$(curl --silent https://cyberpanel.net/version.txt) -CP_VER1=${TEMP:12:3} -CP_VER2=${TEMP:25:1} -SERVER_OS="CentOS" -VERSION="OLS" -LICENSE_KEY="" -KEY_SIZE="" -ADMIN_PASS="1234567" -CUSTOM_PASS="False" -MEMCACHED="ON" -REDIS="ON" -TOTAL_RAM=$(free -m | awk '/Mem:/ { print $2 }') -CENTOS_8="False" -UBUNTU_20="False" -WATCHDOG="OFF" -VIRT_TYPE="" -MASTER_GIT_URL="github.com/usmannasir/cyberpanel" +echo -e "Fetching latest data from CyberPanel server...\n" +echo -e "This may take few seconds..." -set_git_repos_and_branch() { - echo 'Setting up Branches,1' >/var/log/installLogs.txt - local GIT_DIR - local GIT_USER - local GIT_REPO +Silent="Off" +Server_Edition="OLS" +Admin_Pass="1234567" - if [ -z ${GIT_URL+x} ]; then - GIT_URL=$MASTER_GIT_URL - else - printf "Found custom provided GIT URL...\n" - fi +Memcached="On" +Redis="On" - if [ -z ${BRANCH_NAME+x} ]; then - BRANCH_NAME="v${TEMP:12:3}.${TEMP:25:1}" - else - printf "Found custom provided branch...\n" - fi +Postfix_Switch="On" +PowerDNS_Switch="On" +PureFTPd_Switch="On" - ### To be removed when branch is merged +Server_IP="" +Server_Country="Unknow" +Server_OS="" +Server_OS_Version="" +Server_Provider='Undefined' - BRANCH_NAME="v2.0.4-dev" +Watchdog="On" +Redis_Hosting="No" +Temp_Value=$(curl --silent --max-time 30 -4 https://cyberpanel.net/version.txt) +Panel_Version=${Temp_Value:12:3} +Panel_Build=${Temp_Value:25:1} - ### +Branch_Name="v${Panel_Version}.${Panel_Build}" +Base_Number="1.9.3" - GIT_DIR=$(dirname "$GIT_URL") - GIT_USER=$(basename "$GIT_DIR") - GIT_REPO=$(basename "$GIT_URL") - GIT_CONTENT_URL="raw.githubusercontent.com/$GIT_USER/$GIT_REPO" +Total_RAM=$(free -m | awk '/Mem:/ { print $2 }') - printf "\n~~~~~~~~~~\n" - printf "Github URL: %s\n" "$GIT_URL" - printf "Github Content URL: %s\n" "$GIT_CONTENT_URL" - printf "Github Branch: %s\n" "$BRANCH_NAME" - printf "~~~~~~~~~~\n" - echo 'Setting up Branches,1' >/var/log/installLogs.txt -} +Remote_MySQL="Off" -disable_repos() { +Final_Flags=() - if [[ $SERVER_OS == "CentOS" ]]; then - sed -i 's|enabled=1|enabled=0|g' /etc/yum.repos.d/CentOS-Base.repo - sed -i 's|enabled=1|enabled=0|g' /etc/yum.repos.d/CentOS-Debuginfo.repo - sed -i 's|enabled=1|enabled=0|g' /etc/yum.repos.d/CentOS-Media.repo - sed -i 's|enabled=1|enabled=0|g' /etc/yum.repos.d/CentOS-Vault.repo - sed -i 's|enabled=1|enabled=0|g' /etc/yum.repos.d/CentOS-CR.repo - sed -i 's|enabled=1|enabled=0|g' /etc/yum.repos.d/CentOS-fasttrack.repo - sed -i 's|enabled=1|enabled=0|g' /etc/yum.repos.d/CentOS-Sources.repo - fi +Git_User="" +Git_Content_URL="" +Git_Clone_URL="" + +LSWS_Latest_URL="https://cyberpanel.sh/update.litespeedtech.com/ws/latest.php" +curl --silent --max-time 30 -4 -o /tmp/lsws_latest "$LSWS_Latest_URL" 2>/dev/null +LSWS_Stable_Line=$(grep "LSWS_STABLE" /tmp/lsws_latest) +LSWS_Stable_Version=$(expr "$LSWS_Stable_Line" : '.*LSWS_STABLE=\(.*\) BUILD .*') +#grab the LSWS latest stable version. + +Enterprise_Flag="" +License_Key="" +Debug_Log2 "Starting installation...1" } -check_return() { +Debug_Log() { +echo -e "\n${1}=${2}\n" >> /tmp/cyberpanel_debug.log +} + +Debug_Log2() { +echo -e "\n${1}" >> /var/log/installLogs.txt +} + +Branch_Check() { +if [[ "$1" = *.*.* ]]; then + #check input if it's valid format as X.Y.Z + Output=$(awk -v num1="$Base_Number" -v num2="${1//[[:space:]]/}" ' + 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${1//[[:space:]]/}" + echo -e "\nSet branch name to $Branch_Name..." + fi +else + echo -e "\nPlease input a valid format version number." + exit +fi +} + +License_Check() { +License_Key="$1" +echo -e "\nChecking LiteSpeed Enterprise license key..." +if echo "$License_Key" | grep -q "^....-....-....-....$" && [[ ${#License_Key} = "19" ]]; then + echo -e "\nLicense key set...\n" +elif [[ ${License_Key,,} = "trial" ]] ; then + echo -e "\nTrial license set..." + License_Key="Trial" +else + echo -e "\nLicense key seems incorrect, please verify" + echo -e "\nIf you are copying/pasting, please make sure you didn't paste blank space...\n" + exit +fi +} + +Check_Return() { #check previous command result , 0 = ok , non-0 = something wrong. - if [[ $? -eq "0" ]]; then - : +# shellcheck disable=SC2181 +if [[ $? != "0" ]]; then + if [[ -n "$1" ]] ; then + echo -e "\n\n\n$1" + fi + echo -e "above command failed..." + Debug_Log2 "command failed, exiting. For more information read /var/log/installLogs.txt [404]" + if [[ "$2" = "no_exit" ]] ; then + echo -e"\nRetrying..." else - echo -e "\ncommand failed, exiting..." - echo 'command failed, exiting. For more information read /var/log/installLogs.txt [404]' >>/var/log/installLogs.txt exit fi +fi +} +# check command success or not + +Retry_Command() { +# shellcheck disable=SC2034 +for i in {1..50}; +do + $1 && break || echo -e "\n$1 has failed for $i times\nWait for 3 seconds and try again...\n"; sleep 3; +done } -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 +Check_Root() { +echo -e "\nChecking root privileges..." + if echo "$Sudo_Test" | grep SUDO >/dev/null; then + echo -e "\nYou are using SUDO , please run as root user...\n" + 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 installation command again." + exit fi -} -watchdog_setup() { - if [[ $WATCHDOG == "ON" ]]; then - wget -O /etc/cyberpanel/watchdog.sh https://$GIT_CONTENT_URL/stable/CPScripts/watchdog.sh - chmod 700 /etc/cyberpanel/watchdog.sh - ln -s /etc/cyberpanel/watchdog.sh /usr/local/bin/watchdog - pid=$(ps aux | grep "watchdog lsws" | grep -v grep | awk '{print $2}') - if [[ $pid == "" ]]; then - nohup watchdog lsws >/dev/null 2>&1 & - fi - echo -e "Checking MariaDB ..." - pid=$(ps aux | grep "watchdog mariadb" | grep -v grep | awk '{print $2}') - if [[ $pid == "" ]]; then - nohup watchdog mariadb >/dev/null 2>&1 & - fi - - if [[ $SERVER_OS == "CentOS" ]]; then - echo "nohup watchdog lsws > /dev/null 2>&1 & - nohup watchdog mariadb > /dev/null 2>&1 &" >>/etc/rc.d/rc.local - else - echo "nohup watchdog lsws > /dev/null 2>&1 & - nohup watchdog mariadb > /dev/null 2>&1 &" >>/etc/rc.local - fi - echo -e "\n Setting up WatchDog..." - fi -} - -webadmin_passwd() { - if [[ $VERSION == "OLS" ]]; then - php_command="admin_php" + if [[ $(id -u) != 0 ]] >/dev/null; then + echo -e "\nYou must run on root user to install CyberPanel...\n" + echo -e "or run following command: (do NOT miss the quotes)" + echo -e "\e[31msudo su -c \"sh <(curl https://cyberpanel.sh || wget -O - https://cyberpanel.sh)\"\e[39m" + exit 1 else - php_command="admin_php5" + echo -e "\nYou are runing as root...\n" + fi +} + +Check_Server_IP() { +Server_IP=$(curl --silent --max-time 30 -4 https://cyberpanel.sh/?ip) + if [[ $Server_IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo -e "Valid IP detected..." + else + echo -e "Can not detect IP, exit..." + Debug_Log2 "Can not detect IP" + exit fi - WEBADMIN_PASS=$( +echo -e "\nChecking server location...\n" + +Server_Country=$(curl --silent --max-time 10 -4 https://cyberpanel.sh/?country) +if [[ ${#Server_Country} != "2" ]] ; then + Server_Country="Unknow" +fi + +if [[ "$Debug" = "On" ]] ; then + Debug_Log "Server_IP" "$Server_IP" + Debug_Log "Server_Country" "$Server_Country" +fi + +if [[ "$*" = *"--mirror"* ]] ; then + Server_Country="CN" + echo -e "Force to use mirror server due to --mirror argument...\n" +fi + +if [[ "$Server_Country" = *"CN"* ]] ; then + Server_Country="CN" + echo -e "Setting up to use mirror server...\n" +fi +} + +Check_OS() { +if [[ ! -f /etc/os-release ]] ; then + echo -e "Unable to detect the operating system...\n" + exit +fi + +if ! uname -m | grep -q 64 ; then + echo -e "x64 system is required...\n" + exit +fi + +if grep -q -E "CentOS Linux 7|CentOS Linux 8" /etc/os-release ; then + Server_OS="CentOS" +elif grep -q -E "CloudLinux 7|CloudLinux 8" /etc/os-release ; then + Server_OS="CloudLinux" +elif grep -q -E "Ubuntu 18.04|Ubuntu 20.04" /etc/os-release ; then + Server_OS="Ubuntu" +else + echo -e "Unable to detect your system..." + echo -e "\nCyberPanel is supported on Ubuntu 18.04 x86_64, Ubuntu 20.04 x86_64, CentOS 7.x, CentOS 8.x and CloudLinux 7.x...\n" + Debug_Log2 "CyberPanel is supported on Ubuntu 18.04 x86_64, Ubuntu 20.04 x86_64, CentOS 7.x, CentOS 8.x and CloudLinux 7.x... [404]" + exit +fi + +Server_OS_Version=$(grep VERSION_ID /etc/os-release | awk -F[=,] '{print $2}' | tr -d \" | head -c2) +#to make 20.04 display as 20 + +echo -e "System: $Server_OS $Server_OS_Version detected...\n" + +if [[ $Server_OS = "CloudLinux" ]] ; then + Server_OS_Version=$(grep VERSION_ID /etc/os-release | awk -F[=,] '{print $2}' | tr -d \" | cut -c1-1) + Server_OS="CentOS" + #CloudLinux gives version id like 7.8 , 7.9 , so cut it to show first number only + #then treat it as CentOS system. +fi + +if [[ "$Debug" = "On" ]] ; then + Debug_Log "Server_OS" "$Server_OS $Server_OS_Version" +fi + +} + +Check_Virualization() { +echo -e "Checking virtualization type..." +if hostnamectl | grep -q "Virtualization: lxc"; then + echo -e "\nLXC detected..." + echo -e "CyberPanel does not support LXC" + echo -e "Exiting..." + Debug_Log2 "CyberPanel does not support LXC.. [404]" + exit +fi + +if hostnamectl | grep -q "Virtualization: openvz"; then + echo -e "OpenVZ detected...\n" + + if [[ ! -d /etc/systemd/system/pure-ftpd.service.d ]]; then + mkdir /etc/systemd/system/pure-ftpd.service.d + echo "[Service] +PIDFile=/run/pure-ftpd.pid" >/etc/systemd/system/pure-ftpd.service.d/override.conf + echo -e "PureFTPd service file modified for OpenVZ..." + fi + + if [[ ! -d /etc/systemd/system/lshttpd.service.d ]]; then + mkdir /etc/systemd/system/lshttpd.service.d + echo "[Service] +PIDFile=/tmp/lshttpd/lshttpd.pid" >/etc/systemd/system/lshttpd.service.d/override.conf + echo -e "LiteSPeed service file modified for OpenVZ..." + fi + + if [[ ! -d /etc/systemd/system/spamassassin.service.d ]]; then + mkdir /etc/systemd/system/spamassassin.service.d + echo "[Service] +PIDFile=/run/spamassassin.pid" >/etc/systemd/system/spamassassin.service.d/override.conf + echo -e "SpamAssassin service file modified for OpenVZ..." + fi +fi + +if [[ "$Debug" = "On" ]] ; then + Debug_Log "Server_Virtualization" "$(hostnamectl | grep "Virtualization")" +fi +} + +Check_Panel() { +if [[ -d /usr/local/cpanel ]]; then + echo -e "\ncPanel detected...\n" + Debug_Log2 "cPanel detected...exit... [404]" + exit +elif [[ -d /usr/local/directadmin ]]; then + echo -e "\nDirectAdmin detected...\n" + Debug_Log2 "DirectAdmin detected...exit... [404]" + exit +elif [[ -d /etc/httpd/conf/plesk.conf.d/ ]] || [[ -d /etc/apache2/plesk.conf.d/ ]]; then + echo -e "\nPlesk detected...\n" + Debug_Log2 "Plesk detected...exit... [404]" + exit +fi +} + +Check_Porcess() { +if systemctl is-active --quiet httpd; then + systemctl disable httpd + systemctl stop httpd + systemctl mask httpd + echo -e "\nhttpd process detected, disabling...\n" +fi +if systemctl is-active --quiet apache2; then + systemctl disable apache2 + systemctl stop apache2 + systemctl mask apache2 + echo -e "\napache2 process detected, disabling...\n" +fi +if systemctl is-active --quiet named; then + systemctl stop named + systemctl disable named + systemctl mask named + echo -e "\nnamed process detected, disabling...\n" +fi +if systemctl is-active --quiet exim; then + systemctl stop exim + systemctl disable exim + systemctl mask exim + echo -e "\nexim process detected, disabling...\n" +fi +} + +Check_Provider() { +if hash dmidecode >/dev/null 2>&1; then + if [[ "$(dmidecode -s bios-vendor)" = "Google" ]]; then + Server_Provider="Google Cloud Platform" + elif [[ "$(dmidecode -s bios-vendor)" = "DigitalOcean" ]]; then + Server_Provider="Digital Ocean" + elif [[ "$(dmidecode -s system-product-name | cut -c 1-7)" = "Alibaba" ]]; then + Server_Provider="Alibaba Cloud" + elif [[ "$(dmidecode -s system-manufacturer)" = "Microsoft Corporation" ]]; then + Server_Provider="Microsoft Azure" + elif [[ -d /usr/local/qcloud ]]; then + Server_Provider="Tencent Cloud" + else + Server_Provider="Undefined" + fi +else + Server_Provider='Undefined' +fi + +if [[ -f /sys/devices/virtual/dmi/id/product_uuid ]]; then + if [[ "$(cut -c 1-3 /sys/devices/virtual/dmi/id/product_uuid)" = 'EC2' ]] && [[ -d /home/ubuntu ]]; then + Server_Provider='Amazon Web Service' + fi +fi + +if [[ "$Debug" = "On" ]] ; then + Debug_Log "Server_Provider" "$Server_Provider" +fi +} + +Show_Help() { +echo -e "\nCyberPanel Installer Script Help\n" +echo -e "\nUsage: sh <(curl cyberpanel.sh) --argument" +echo -e "\n -v or --version: choose to install CyberPanel OpenLiteSpeed or CyberPanel Enterprise, available options are \e[31mols\e[39m and \e[31mSERIAL_NUMBER\e[39m, default ols" +echo -e "\n Please be aware, this serial number must be obtained from LiteSpeed Store." +echo -e "\n And if this serial number has been used before, it must be released/migrated in Store first, otherwise it will fail to start." +echo -e "\n -a or --addons: install addons: memcached, redis, PHP extension for memcached and redis" +echo -e "\n -p or --password: set password of new installation, empty for default 1234567, [r] or [random] for randomly generated 16 digital password, any other value besides [d] and [r(andom)] will be accept as password, default use 1234567." +echo -e "\n -m: set to minimal mode which will not install PowerDNS, Pure-FTPd and Postfix" +echo -e "\n Example:" +echo -e "\n sh <(curl cyberpanel.sh) -v ols -p r or ./cyberpanel.sh --version ols --password random" +echo -e "\n This will install CyberPanel OpenLiteSpeed and randomly generate the password." +echo -e "\n sh <(curl cyberpanel.sh) -v LICENSE_KEY -a -p my_pass_word" +echo -e "\n This will install LiteSpeed Enterise , replace LICENSE_KEY to actual license key and set password to my_pass_word\n" +} + +Check_Argument() { +if [[ "$#" = "0" ]] || [[ "$#" = "1" && "$1" = "--debug" ]] || [[ "$#" = "1" && "$1" = "--mirror" ]]; then + echo -e "\nInitializing...\n" +else + if [[ $1 = "help" ]]; then + Show_Help + exit + elif [[ $1 = "default" ]]; then + echo -e "\nThis will start default installation...\n" + Silent="On" + Postfix_Switch="On" + PowerDNS_Switch="On" + PureFTPd_Switch="On" + Server_Edition="OLS" + Admin_Pass="1234567" + Memcached="On" + Redis="On" + else + while [[ -n "${1}" ]]; do + case $1 in + -v | --version) + shift + if [[ "${1}" = "" ]]; then + Show_Help + exit + elif [[ "${1^^}" = "OLS" ]] ; then + Server_Edition="OLS" + Silent="On" + echo -e "\nSet to use OpenLiteSpeed..." + else + Server_Edition="Enterprise" + License_Key="${1}" + Silent="On" + echo -e "\nSet to use LiteSpeed Enterprise..." + echo -e "\nSet to use license key ${1}..." + fi + ;; + -p | --password) + shift + if [[ ${1} = "" ]]; then + Admin_Pass="1234567" + elif [[ ${1} = "r" ]] || [[ $1 = "random" ]]; then + Admin_Pass=$( + head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 + echo '' + ) + elif [[ ${1} = "d" ]]; then + Admin_Pass="1234567" + else + if [[ ${#1} -lt 8 ]]; then + echo -e "\nPassword lenth less than 8 digital, please choose a more complicated password.\n" + exit + fi + Admin_Pass="${1}" + fi + echo -e "\nSet to use password ${1}..." + ;; + -b | --branch) + shift + Branch_Check "${1}" + ;; + -m | --minimal) + if ! echo "$@" | grep -q -i "postfix\|pureftpd\|powerdns" ; then + Postfix_Switch="Off" + PowerDNS_Switch="Off" + PureFTPd_Switch="Off" + echo -e "\nSet to use minimal installation..." + else + if [[ "${*^^}" = *"POSTFIX"* ]] ; then + Postfix_Switch="On" + echo -e "\nEnable Postfix..." + fi + if [[ "${*^^}" = *"PUREFTPD"* ]] ; then + PureFTPd_Switch="On" + echo -e "\nEnable PureFTPd..." + fi + if [[ "${*^^}" = *"POWERDNS"* ]] ; then + PowerDNS_Switch="On" + echo -e "\nEnable PowerDNS..." + fi + fi + ;; + -a | --addons) + Memcached="On" + Redis="On" + echo -e "\nEnable Addons..." + ;; + -h | --help) + Show_Help + exit + ;; + --debug) + echo -e "\nEnable Debug log...\n" + ;; + --mirror) + echo -e "\nForce to use mirror server...\n" + ;; + *) + if [[ "${1^^}" = *"POSTFIX"* ]] || [[ "${1^^}" = *"PUREFTPD"* ]] || [[ "${1^^}" = *"POWERDNS"* ]] ; then + : + #this is ugly workaround , leave it for now , to-do for further improvement. + else + echo -e "\nUnknown argument...\n" + Show_Help + exit + fi + ;; + esac + shift + done + fi +fi + +if [[ "$Debug" = "On" ]] ; then + Debug_Log "Arguments" "${@}" +fi + +Debug_Log2 "Initialization completed..,2" +} + +Argument_Mode() { +if [[ "${Server_Edition^^}" = "OLS" ]] ; then + Server_Edition="OLS" + echo -e "\nSet to OpenLiteSpeed..." +else + License_Check "$License_Key" +fi + +if [[ $Admin_Pass = "d" ]]; then + Admin_Pass="1234567" + echo -e "\nSet to default password..." + echo -e "\nAdmin password will be set to \e[31m$Admin_Pass\e[39m\n" +elif [[ $Admin_Pass = "r" ]]; then + Admin_Pass=$( + head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 + echo '' + ) + echo -e "\nSet to random-generated password..." + echo -e "\nAdmin password will be set to \e[31m$Admin_Pass\e[39m" +else + echo -e "\nAdmin password will be set to \e[31m$Admin_Pass\e[39m" +fi +} + +Interactive_Mode() { +echo -e " CyberPanel Installer v$Panel_Version.$Panel_Build + +1. Install CyberPanel. + +2. Addons and Miscellaneous + +3. Exit. + +" +read -r -p " Please enter the number[1-3]: " Input_Number +echo "" +case "$Input_Number" in + 1) + Interactive_Mode_Set_Parameter + ;; + 2) + Interactive_Mode_Addon + ;; + 3) + exit + ;; + *) + echo -e " Please enter the right number [1-3]\n" + exit + ;; +esac +} + + +Interactive_Mode_Set_Parameter() { +echo -e " CyberPanel Installer v$Panel_Version.$Panel_Build + +RAM check : $(free -m | awk 'NR==2{printf "%s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }') + +Disk check : $(df -h | awk '$NF=="/"{printf "%d/%dGB (%s)\n", $3,$2,$5}') (Minimal \e[31m10GB\e[39m free space) + +1. Install CyberPanel with \e[31mOpenLiteSpeed\e[39m. + +2. Install Cyberpanel with \e[31mLiteSpeed Enterprise\e[39m. + +3. Exit. + +" +read -r -p " Please enter the number[1-3]: " Input_Number +echo "" +case "$Input_Number" in + 1) + Server_Edition="OLS" + ;; + 2) + Interactive_Mode_License_Input + ;; + 3) + exit + ;; + *) + echo -e " Please enter the right number [1-3]\n" + exit + ;; +esac + +echo -e "\nInstall Full service for CyberPanel? This will include PowerDNS, Postfix and Pure-FTPd." +echo -e "" +printf "%s" "Full installation [Y/n]: " +read -r Tmp_Input +if [[ $(expr "x$Tmp_Input" : 'x[Yy]') -gt 1 ]] || [[ $Tmp_Input = "" ]]; then + echo -e "\nFull installation selected..." + Postfix_Switch="On" + PowerDNS_Switch="On" + PureFTPd_Switch="On" +else + echo -e "" + printf "%s" "Install Postfix? [Y/n]: " + read -r Tmp_Input + if [[ $Tmp_Input =~ ^(no|n|N) ]]; then + Postfix_Switch="Off" + else + Postfix_Switch="On" + fi + echo -e "" + printf "%s" "Install PowerDNS? [Y/n]: " + read -r Tmp_Input + if [[ $Tmp_Input =~ ^(no|n|N) ]]; then + PowerDNS_Switch="Off" + else + PowerDNS_Switch="On" + fi + echo -e "" + printf "%s" "Install PureFTPd? [Y/n]: " + read -r Tmp_Input + if [[ $Tmp_Input =~ ^(no|n|N) ]]; then + PureFTPd_Switch="Off" + else + PureFTPd_Switch="On" + fi +fi + + ### Ask if you want to set up this CyberPanel with remote MySQL + +echo -e "\nDo you want to setup Remote MySQL? (This will skip installation of local MySQL)" +echo -e "" +printf "%s" "(Default = No) Remote MySQL [y/N]: " +read -r Tmp_Input +if [[ $(expr "x$Tmp_Input" : 'x[Yy]') -gt 1 ]]; then + echo -e "\nRemote MySQL selected..." + Remote_MySQL="On" + + echo -e "" + printf "%s" "Remote MySQL Hostname: " + read -r MySQL_Host + + echo -e "" + printf "%s" "Remote MySQL Database that contains meta information regarding MYSQL. (usually mysql): " + read -r MySQL_DB + + echo -e "" + printf "%s" "Remote MySQL Username: " + read -r MySQL_User + + echo -e "" + printf "%s" "Remote MySQL Password: " + read -r -s -p "Password: " MySQL_Password + + echo -e "" + printf "%s" "Remote MySQL Port: " + read -r MySQL_Port +else + echo -e "\nLocal MySQL selected..." +fi + +echo -e "\nPress \e[31mEnter\e[39m key to continue with latest version or Enter specific version such as: \e[31m1.9.4\e[39m , \e[31m2.0.1\e[39m , \e[31m2.0.2\e[39m ...etc" +printf "%s" "" +read -r Tmp_Input + +if [[ $Tmp_Input = "" ]]; then + echo -e "Branch name set to $Branch_Name" +else + Branch_Check "$Tmp_Input" +fi + +echo -e "\nPlease choose to use default admin password \e[31m1234567\e[39m, randomly generate one \e[31m(recommended)\e[39m or specify the admin password?" +printf "%s" "Choose [d]fault, [r]andom or [s]et password: [d/r/s] " +read -r Tmp_Input + +if [[ $Tmp_Input =~ ^(d|D| ) ]] || [[ -z $Tmp_Input ]]; then + Admin_Pass="1234567" + echo -e "\nAdmin password will be set to $Admin_Pass\n" +elif [[ $Tmp_Input =~ ^(r|R) ]]; then + Admin_Pass=$( head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 echo '' - ) - TEMP=$(/usr/local/lsws/admin/fcgi-bin/${php_command} /usr/local/lsws/admin/misc/htpasswd.php ${WEBADMIN_PASS}) - echo "" >/usr/local/lsws/admin/conf/htpasswd - echo "admin:$TEMP" >/usr/local/lsws/admin/conf/htpasswd - echo ${WEBADMIN_PASS} >/etc/cyberpanel/webadmin_passwd - chmod 600 /etc/cyberpanel/webadmin_passwd -} - -openvz_change() { - if [[ $VIRT_TYPE == "OpenVZ" ]]; then - if [[ ! -d /etc/systemd/system/pure-ftpd.service.d ]]; then - mkdir /etc/systemd/system/pure-ftpd.service.d - echo "[Service] -PIDFile=/run/pure-ftpd.pid" >/etc/systemd/system/pure-ftpd.service.d/override.conf - echo -e "PureFTPd service file modified for OpenVZ..." - fi - - if [[ ! -d /etc/systemd/system/lshttpd.service.d ]]; then - mkdir /etc/systemd/system/lshttpd.service.d - echo "[Service] -PIDFile=/tmp/lshttpd/lshttpd.pid" >/etc/systemd/system/lshttpd.service.d/override.conf - echo -e "LiteSPeed service file modified for OpenVZ..." - fi - - if [[ ! -d /etc/systemd/system/spamassassin.service.d ]]; then - mkdir /etc/systemd/system/spamassassin.service.d - echo "[Service] -PIDFile=/run/spamassassin.pid" >/etc/systemd/system/spamassassin.service.d/override.conf - echo -e "SpamAssassin service file modified for OpenVZ..." - fi - fi -} - -check_virtualization() { - echo -e "Checking virtualization type..." - if hostnamectl | grep -q "Virtualization: lxc"; then - echo -e "\nLXC detected..." - echo -e "CyberPanel does not support LXC" - echo -e "Exiting..." - echo 'CyberPanel does not support LXC.. [404]' >>/var/log/installLogs.txt + ) + echo -e "\nAdmin password will be provided once installation is completed...\n" +elif [[ $Tmp_Input =~ ^(s|S) ]]; then + Custom_Pass="True" + echo -e "\nPlease enter your password:" + printf "%s" "" + read -r -s -p "Password: " Tmp_Input + if [[ -z "$Tmp_Input" ]]; then + echo -e "\nPlease do not use empty string...\n" exit fi - - if hostnamectl | grep -q "Virtualization: openvz"; then - echo -e "\nOpenVZ detected..." - VIRT_TYPE="OpenVZ" - openvz_change + if [[ ${#Tmp_Input} -lt 8 ]]; then + echo -e "\nPassword lenth less than 8 digital, please choose a more complicated password.\n" + exit fi + Tmp_Input1=$Tmp_Input + read -r -s -p "Confirm Password:" Tmp_Input + if [[ -z "$Tmp_Input" ]]; then + echo -e "\nPlease do not use empty string...\n" + exit + fi + if [[ "$Tmp_Input" = "$Tmp_Input1" ]]; then + Admin_Pass=$Tmp_Input + else + echo -e "\nRepeated password didn't match , please check...\n" + exit + fi +else + Admin_Pass="1234567" + echo -e "\nAdmin password will be set to $Admin_Pass\n" +fi + +echo -e "\nDo you wish to install Memcached process and its PHP extension?" +printf "%s" "Please select [Y/n]: " +read -r Tmp_Input +if [[ $Tmp_Input =~ ^(no|n|N) ]]; then + Memcached="Off" +else + Memcached="On" + echo -e "\nInstall Memcached process and its PHP extension set to Yes...\n" +fi + +echo -e "\nDo you wish to install Redis process and its PHP extension?" +printf "%s" "Please select [Y/n]: " +read -r Tmp_Input +if [[ $Tmp_Input =~ ^(no|n|N) ]]; then + Redis="Off" +else + Redis="On" + echo -e "\nInstall Redis process and its PHP extension set to Yes...\n" +fi + +echo -e "\nWould you like to set up a WatchDog \e[31m(beta)\e[39m for Web service and Database service ?" +echo -e "The watchdog script will be automatically started up after installation and server reboot" +echo -e "If you want to kill the watchdog , run \e[31mwatchdog kill\e[39m" +echo -e "Please type Yes or no (with capital \e[31mY\e[39m, default Yes): " +read -r Tmp_Input +if [[ $Tmp_Input = "Yes" ]] || [[ $Tmp_Input = "" ]]; then + Watchdog="On" + echo -e "\nInstall Watchdog set to Yes...\n" +else + Watchdog="Off" +fi } -license_validation() { - CURRENT_DIR=$(pwd) +Interactive_Mode_License_Input() { +Server_Edition="Enterprise" +echo -e "\nPlease note that your server has \e[31m$Total_RAM MB\e[39m RAM" +echo -e "If you are using \e[31mFree Start\e[39m license, It will not start due to \e[31m2GB RAM limit\e[39m.\n" +echo -e "If you do not have any license, you can also use trial license (if server has not used trial license before), type \e[31mTRIAL\e[39m\n" - if [ -f /root/cyberpanel-tmp ]; then - rm -rf /root/cyberpanel-tmp - fi +printf "%s" "Please input your serial number for LiteSpeed WebServer Enterprise: " +read -r License_Key +if [[ -z "$License_Key" ]]; then + echo -e "\nPlease provide license key\n" + exit +fi - mkdir /root/cyberpanel-tmp - cd /root/cyberpanel-tmp - wget -q https://$DOWNLOAD_SERVER/litespeed/lsws-$LSWS_STABLE_VER-ent-x86_64-linux.tar.gz - tar xzvf lsws-$LSWS_STABLE_VER-ent-x86_64-linux.tar.gz >/dev/null - cd /root/cyberpanel-tmp/lsws-$LSWS_STABLE_VER/conf - if [[ $LICENSE_KEY == "TRIAL" ]]; then - wget -q http://license.litespeedtech.com/reseller/trial.key - sed -i "s|writeSerial = open('lsws-5.4.2/serial.no', 'w')|command = 'wget -q --output-document=./lsws-$LSWS_STABLE_VER/trial.key http://license.litespeedtech.com/reseller/trial.key'|g" $CURRENT_DIR/installCyberPanel.py - sed -i 's|writeSerial.writelines(self.serial)|subprocess.call(command, shell=True)|g' $CURRENT_DIR/installCyberPanel.py - sed -i 's|writeSerial.close()||g' $CURRENT_DIR/installCyberPanel.py - else - echo $LICENSE_KEY >serial.no - fi +echo -e "The serial number you input is: \e[31m$License_Key\e[39m\n" +printf "%s" "Please verify it is correct. [y/N]: " +read -r Tmp_Input +if [[ -z "$Tmp_Input" ]]; then + echo -e "\nPlease type \e[31my\e[39m\n" + exit +fi - cd /root/cyberpanel-tmp/lsws-$LSWS_STABLE_VER/bin +License_Check "$License_Key" - if [[ $LICENSE_KEY == "TRIAL" ]]; then - if ./lshttpd -V |& grep "ERROR"; then - echo -e "\n\nIt apeears to have some issue with license , please check above result..." - echo 'It appears to have some issue with LiteSpeed License, make sure you are using correct serial key. [404]' >>/var/log/installLogs.txt - exit - fi - LICENSE_KEY="1111-2222-3333-4444" - else - if ./lshttpd -r |& grep "ERROR"; then - ./lshttpd -r - echo -e "\n\nIt apeears to have some issue with license , please check above result..." - echo 'It appears to have some issue with LiteSpeed License, make sure you are using correct serial key. [404]' >>/var/log/installLogs.txt - exit - fi - fi - echo -e "License seems valid..." - cd /root/cyberpanel-tmp - rm -rf lsws-$LSWS_STABLE_VER* - cd $CURRENT_DIR - rm -rf /root/cyberpanel-tmp +#echo -e "\nWould you like use Redis Mass Hosting?" +#echo -e "Please type Yes or No (with capital \e[31mY\e[39m, default No):" +#read -r Redis_Hosting + +#if [[ "$Redis_Hosting" = "Yes" ]]; then +# echo -e "\nRedis Mass Hosting is set to Yes...\n" +#fi +# hide it for now } -special_change() { - sed -i 's|cyberpanel.sh|'$DOWNLOAD_SERVER'|g' install.py - sed -i 's|mirror.cyberpanel.net|'$DOWNLOAD_SERVER'|g' install.py - sed -i 's|git clone https://github.com/usmannasir/cyberpanel|echo downloaded|g' install.py +Pre_Install_Setup_Repository() { +if [[ $Server_OS = "CentOS" ]] ; then + rpm --import https://cyberpanel.sh/rpms.litespeedtech.com/centos/RPM-GPG-KEY-litespeed + #import the LiteSpeed GPG key - #change to CDN first, regardless country - #sed -i 's|http://|https://|g' install.py + yum clean all + yum autoremove -y epel-release + rm -f /etc/yum.repos.d/epel.repo + rm -f /etc/yum.repos.d/epel.repo.rpmsave + yum install -y epel-release + Check_Return "yum repo" "no_exit" - if [[ $PROVIDER == "Alibaba Cloud" ]]; then - if ! grep -q "100.100.2.136" /etc/resolv.conf; then - echo -e "\nnameserver 100.100.2.136" >>/etc/resolv.conf - fi - if ! grep -q "100.100.2.138" /etc/resolv.conf; then - echo -e "\nnameserver 100.100.2.138" >>/etc/resolv.conf - fi - else - if ! grep -q "1.1.1.1" /etc/resolv.conf; then - echo -e "\nnameserver 1.1.1.1" >>/etc/resolv.conf - fi - if ! grep -q "8.8.8.8" /etc/resolv.conf; then - echo -e "\nnameserver 8.8.8.8" >>/etc/resolv.conf - fi - fi - cp /etc/resolv.conf /etc/resolv.conf-tmp - - line1="$(grep -n "f.write('nameserver 8.8.8.8')" installCyberPanel.py | head -n 1 | cut -d: -f1)" - sed -i "${line1}i\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ subprocess.call(command, shell=True)" installCyberPanel.py - sed -i "${line1}i\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ command = 'cat /etc/resolv.conf-tmp > /etc/resolv.conf'" installCyberPanel.py - - LATEST_URL="https://update.litespeedtech.com/ws/latest.php" - #LATEST_URL="https://cyberpanel.sh/latest.php" - curl --silent -o /tmp/lsws_latest $LATEST_URL 2>/dev/null - LSWS_STABLE_LINE=$(cat /tmp/lsws_latest | grep LSWS_STABLE) - LSWS_STABLE_VER=$(expr "$LSWS_STABLE_LINE" : '.*LSWS_STABLE=\(.*\) BUILD .*') - - if [[ $PROVIDER == "Alibaba Cloud" ]] && [[ $SERVER_OS == "Ubuntu" ]]; then - mkdir /root/.config - mkdir /root/.config/pip - cat </root/.config/pip/pip.conf -[global] -index-url = https://pypi.python.org/simple/ -[install] -trusted-host=pypi.python.org + if [[ "$Server_OS_Version" = "8" ]]; then + cat </etc/yum.repos.d/CentOS-PowerTools-CyberPanel.repo +[powertools-for-cyberpanel] +name=CentOS Linux \$releasever - PowerTools +mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=PowerTools&infra=\$infra +baseurl=http://mirror.centos.org/\$contentdir/\$releasever/PowerTools/\$basearch/os/ +gpgcheck=1 +enabled=1 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial EOF - echo -e "\nSet pip repo..." - fi - #seems Alibaba cloud , other than CN , also requires change on ubuntu. - - if [[ $SERVER_COUNTRY == "CN" ]]; then - #line1="$(grep -n "github.com/usmannasir/cyberpanel" install.py | head -n 1 | cut -d: -f1)" - #line2=$((line1 - 1)) - #sed -i "${line2}i\ \ \ \ \ \ \ \ subprocess.call(command, shell=True)" install.py - #sed -i "${line2}i\ \ \ \ \ \ \ \ command = 'tar xzvf cyberpanel-git.tar.gz'" install.py - #sed -i "${line2}i\ \ \ \ \ \ \ \ subprocess.call(command, shell=True)" install.py - #sed -i "${line2}i\ \ \ \ \ \ \ \ command = 'wget cyberpanel.sh/cyberpanel-git.tar.gz'" install.py - sed -i 's|wget http://rpms.litespeedtech.com/debian/|wget --no-check-certificate https://rpms.litespeedtech.com/debian/|g' install.py - sed -i 's|https://repo.powerdns.com/repo-files/centos-auth-42.repo|https://'$DOWNLOAD_SERVER'/powerdns/powerdns.repo|g' installCyberPanel.py - sed -i 's|https://www.rainloop.net/repository/webmail/rainloop-community-latest.zip|https://'$DOWNLOAD_SERVER'/misc/rainloop-community-latest.zip|g' install.py - sed -i 's|rpm -ivh http://rpms.litespeedtech.com/centos/litespeed-repo-1.2-1.el7.noarch.rpm|curl -o /etc/yum.repos.d/litespeed.repo https://'$DOWNLOAD_SERVER'/litespeed/litespeed.repo|g' install.py - sed -i 's|https://copr.fedorainfracloud.org/coprs/copart/restic/repo/epel-7/copart-restic-epel-7.repo|https://'$DOWNLOAD_SERVER'/restic/restic.repo|g' install.py - sed -i 's|yum -y install http://cyberpanel.sh/gf-release-latest.gf.el7.noarch.rpm|wget -O /etc/yum.repos.d/gf.repo https://'$DOWNLOAD_SERVER'/gf-plus/gf.repo|g' install.py - sed -i 's|dovecot-2.3-latest|dovecot-2.3-latest-mirror|g' install.py - sed -i 's|git clone https://github.com/usmannasir/cyberpanel|wget https://cyberpanel.sh/cyberpanel-git.tar.gz \&\& tar xzvf cyberpanel-git.tar.gz|g' install.py - sed -i 's|http://repo.dovecot.org/ce-2.3-latest/centos/$releasever/RPMS/$basearch|https://'$DOWNLOAD_SERVER'/dovecot/|g' install.py - sed -i 's|'$DOWNLOAD_SERVER'|cyberpanel.sh|g' install.py - sed -i 's|https://www.litespeedtech.com/packages/5.0/lsws-5.4.2-ent-x86_64-linux.tar.gz|https://'$DOWNLOAD_SERVER'/litespeed/lsws-'$LSWS_STABLE_VER'-ent-x86_64-linux.tar.gz|g' installCyberPanel.py - sed -i 's|wget -O - https://get.acme.sh \| sh|git clone https://gitee.com/qtwrk/acme.sh.git ; cd acme.sh ; ./acme.sh --install ; cd - ; rm -rf acme.sh|g' install.py - sed -i 's|composer.sh|composer_cn.sh|g' install.py - sed -i 's|yum -y install http://repo.iotti.biz/CentOS/7/noarch/lux-release-7-1.noarch.rpm|wget -O /etc/yum.repos.d/lux.repo https://'$DOWNLOAD_SERVER'/lux/lux.repo|g' install.py - - # global change for CN , regardless provider and system - - if [[ $SERVER_OS == "CentOS" ]]; then - sed -i 's|https://www.litespeedtech.com/packages/5.0/lsws-5.3.5-ent-x86_64-linux.tar.gz|https://cyberpanel.sh/packages/5.0/lsws-5.3.5-ent-x86_64-linux.tar.gz|g' installCyberPanel.py - fi - - if [[ $SERVER_OS == "Ubuntu" ]]; then - echo $'\n89.208.248.38 rpms.litespeedtech.com\n' >>/etc/hosts - echo -e "Mirror server set..." - if [[ $PROVIDER == "Tencent Cloud" ]]; then - #tencent cloud and ubuntu system - echo -e "\n Tencent Cloud detected ... bypass default repository" - cp /etc/apt/sources.list /etc/apt/sources.list-backup - #backup original sources list - cat <<'EOF' >/etc/apt/sources.list -deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse -deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse -deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse -deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse -deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse -deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse -deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse -deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse -deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse -deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse -EOF - DEBIAN_FRONTEND=noninteractive apt update -y - fi - fi - fi -} - -system_tweak() { - number=$(grep -n "127.0.0.1" /etc/hosts | cut -d: -f 1) - my_hostname=$(hostname) - - if [[ -n $number ]]; then - for number2 in $number; do - string=$(sed "${number2}q;d" /etc/hosts) - if [[ $string == *"$my_hostname"* ]]; then - : - else - new_string="$string $my_hostname" - sed -i "${number2}s/.*/${new_string}/" /etc/hosts - fi - done - else - echo "127.0.0.1 $my_hostname " >>/etc/hosts fi - #this should address on "sudo: unable to resolve host ..." on Ubuntu , it's not issue but annoying. + if [[ "$Server_OS_Version" = "7" ]]; then - if [[ $SERVER_OS == "CentOS" ]]; then - setenforce 0 - sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config - fi - if ! grep -q "pid_max" /etc/rc.local; then - if [[ $SERVER_OS == "CentOS" ]]; then - echo "echo 1000000 > /proc/sys/kernel/pid_max -echo 1 > /sys/kernel/mm/ksm/run" >>/etc/rc.d/rc.local - chmod +x /etc/rc.d/rc.local - else - echo "echo 1000000 > /proc/sys/kernel/pid_max -echo 1 > /sys/kernel/mm/ksm/run" >>/etc/rc.local - chmod +x /etc/rc.local - fi - echo "fs.file-max = 65535" >>/etc/sysctl.conf - sysctl -p >/dev/null - echo "* soft nofile 65535 -* hard nofile 65535 -root soft nofile 65535 -root hard nofile 65535 -* soft nproc 65535 -* hard nproc 65535 -root soft nproc 65535 -root hard nproc 65535" >>/etc/security/limits.conf - fi + yum install -y yum-plugin-priorities + Check_Return "yum repo" "no_exit" + curl -o /etc/yum.repos.d/powerdns-auth-43.repo https://cyberpanel.sh/repo.powerdns.com/repo-files/centos-auth-43.repo + Check_Return "yum repo" "no_exit" - #sed -i 's|#DefaultLimitNOFILE=|DefaultLimitNOFILE=65535|g' /etc/systemd/system.conf - - TOTAL_SWAP=$(free -m | awk '/^Swap:/ { print $2 }') - SET_SWAP=$((TOTAL_RAM - TOTAL_SWAP)) - SWAP_FILE=/cyberpanel.swap - - if [ ! -f $SWAP_FILE ]; then - if [[ $TOTAL_SWAP -gt $TOTAL_RAM ]] || [[ $TOTAL_SWAP -eq $TOTAL_RAM ]]; then - echo "SWAP check..." - else - if [[ $SET_SWAP -gt "2049" ]]; then - SET_SWAP="2048" - else - echo "Checking SWAP..." - fi - fallocate --length ${SET_SWAP}MiB $SWAP_FILE - chmod 600 $SWAP_FILE - mkswap $SWAP_FILE - swapon $SWAP_FILE - echo "${SWAP_FILE} swap swap sw 0 0" | sudo tee -a /etc/fstab - sysctl vm.swappiness=10 - echo "vm.swappiness = 10" >>/etc/sysctl.conf - echo "SWAP set..." - fi - fi -} - -install_required() { - echo 'Installing necessary components..,3' >/var/log/installLogs.txt - if [[ -d /etc/yum.repos.d ]]; then - - 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 - yum install epel-release -y - - if [[ $CENTOS_8 == "True" ]]; then - dnf install zip -y - elif [[ $CENTOS_8 == "False" ]]; then - ###### Setup Required Repos - - ## Start with PDNS - - yum install yum-plugin-priorities -y - curl -o /etc/yum.repos.d/powerdns-auth-43.repo https://repo.powerdns.com/repo-files/centos-auth-43.repo - - ## MariaDB - - cat </etc/yum.repos.d/MariaDB.repo + cat </etc/yum.repos.d/MariaDB.repo # MariaDB 10.5 CentOS repository list - created 2020-09-08 14:54 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] @@ -448,794 +825,765 @@ gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 EOF - ## Ghetoo Repo for Postfix/Dovecot + yum install --nogpg -y https://cyberpanel.sh/mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el7.noarch.rpm + Check_Return "yum repo" "no_exit" - yum --nogpg install https://mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el7.noarch.rpm -y + yum install -y yum-plugin-copr + Check_Return "yum repo" "no_exit" + yum copr enable -y copart/restic + Check_Return "yum repo" "no_exit" - ## Copr for restic - - yum install yum-plugin-copr -y - yum copr enable copart/restic -y - - ## Lux for git 2.17 or more - - yum install http://repo.iotti.biz/CentOS/7/noarch/lux-release-7-1.noarch.rpm -y - - ## IUS Repo for python 3 - - yum install https://repo.ius.io/ius-release-el7.rpm -y - - fi + rpm -ivh https://cyberpanel.sh/repo.iotti.biz/CentOS/7/noarch/lux-release-7-1.noarch.rpm + Check_Return "yum repo" "no_exit" + rpm -ivh https://cyberpanel.sh/repo.ius.io/ius-release-el7.rpm + Check_Return "yum repo" "no_exit" fi +fi +Debug_Log2 "Setting up repositories..." - echo -e "\nInstalling necessary components..." - if [[ $SERVER_OS == "CentOS" ]]; then +if [[ "$Server_Country" = "CN" ]] ; then + Pre_Install_Setup_CN_Repository + Debug_Log2 "Setting up repositories for CN server..." +fi - yum clean all - yum update -y - - if [[ $CENTOS_8 == "False" ]]; then - yum install -y wget strace net-tools curl which bc telnet htop libevent-devel gcc libattr-devel xz-devel gpgme-devel curl-devel git socat openssl-devel MariaDB-shared mariadb-devel yum-utils python36u python36u-pip python36u-devel - check_return - yum -y groupinstall development - check_return - fi - if [[ $CENTOS_8 == "True" ]]; then - dnf install -y wget strace net-tools curl which bc telnet htop libevent-devel gcc libattr-devel xz-devel mariadb-devel curl-devel git platform-python-devel tar socat python3 - check_return - dnf --enablerepo=PowerTools install gpgme-devel -y - dnf --enablerepo=powertools install gpgme-devel -y - #check_return - fi - ln -s /usr/bin/pip3 /usr/bin/pip - pip install virtualenv==16.7.9 - #pip install virtualenv - check_return - - fi - - if [[ $SERVER_OS == "Ubuntu" ]]; then - - apt update -y - #DEBIAN_FRONTEND=noninteractive apt upgrade -y - 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 socat vim unzip zip - check_return - - DEBIAN_FRONTEND=noninteractive apt install -y python3-pip - check_return - ln -s /usr/bin/pip3 /usr/bin/pip3.6 - ln -s /usr/bin/pip3.6 /usr/bin/pip - DEBIAN_FRONTEND=noninteractive apt install -y build-essential libssl-dev libffi-dev python3-dev - check_return - DEBIAN_FRONTEND=noninteractive apt install -y python3-venv - check_return - - pip install virtualenv==16.7.9 - #pip install virtualenv - check_return - - fi - echo 'Necessary components installed..,5' >/var/log/installLogs.txt -} - -memcached_installation() { - if [[ $SERVER_OS == "CentOS" ]]; then - yum install -y lsphp74-memcached lsphp73-memcached lsphp72-memcached lsphp71-memcached lsphp70-memcached lsphp56-pecl-memcached lsphp55-pecl-memcached lsphp54-pecl-memcached - if [[ $TOTAL_RAM -eq "2048" ]] || [[ $TOTAL_RAM -gt "2048" ]]; then - yum groupinstall "Development Tools" -y - yum install autoconf automake zlib-devel openssl-devel expat-devel pcre-devel libmemcached-devel cyrus-sasl* -y - wget https://$DOWNLOAD_SERVER/litespeed/lsmcd.tar.gz - tar xzvf lsmcd.tar.gz - DIR=$(pwd) - cd $DIR/lsmcd - ./fixtimestamp.sh - ./configure CFLAGS=" -O3" CXXFLAGS=" -O3" - make - make install - systemctl enable lsmcd - systemctl start lsmcd - cd $DIR - else - yum install -y memcached - sed -i 's|OPTIONS=""|OPTIONS="-l 127.0.0.1 -U 0"|g' /etc/sysconfig/memcached - systemctl enable memcached - systemctl start memcached - fi - fi - if [[ $SERVER_OS == "Ubuntu" ]]; then - DEBIAN_FRONTEND=noninteractive apt install -y lsphp74-memcached - DEBIAN_FRONTEND=noninteractive apt install -y lsphp73-memcached - DEBIAN_FRONTEND=noninteractive apt install -y lsphp72-memcached - DEBIAN_FRONTEND=noninteractive apt install -y lsphp71-memcached - DEBIAN_FRONTEND=noninteractive apt install -y lsphp70-memcached - - if [[ $TOTAL_RAM -eq "2048" ]] || [[ $TOTAL_RAM -gt "2048" ]]; then - DEBIAN_FRONTEND=noninteractive apt install build-essential zlib1g-dev libexpat1-dev openssl libssl-dev libsasl2-dev libpcre3-dev git -y - wget https://$DOWNLOAD/litespeed/lsmcd.tar.gz - tar xzvf lsmcd.tar.gz - DIR=$(pwd) - cd $DIR/lsmcd - ./fixtimestamp.sh - ./configure CFLAGS=" -O3" CXXFLAGS=" -O3" - make - make install - cd $DIR - systemctl enable lsmcd - systemctl start lsmcd - else - DEBIAN_FRONTEND=noninteractive apt install -y memcached - systemctl enable memcached - systemctl start memcached - fi - fi - - if ps -aux | grep "lsmcd" | grep -v grep; then - echo -e "\n\nLiteSpeed Memcached installed and running..." - fi - - if ps -aux | grep "memcached" | grep -v grep; then - echo -e "\n\nMemcached installed and running..." - fi +if [[ "$Server_Country" = "CN" ]] || [[ "$Server_Provider" = "Alibaba Cloud" ]] || [[ "$Server_Provider" = "Tencent Cloud" ]]; then + Setup_Pip +fi } -redis_installation() { - if [[ $SERVER_OS == "CentOS" ]]; then - if [[ CENTOS_8 == "True" ]]; then - yum install -y lsphp74-redis lsphp73-redis lsphp72-redis lsphp71-redis lsphp70-redis lsphp56-redis lsphp55-redis lsphp54-redis redis - else - yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm - yum-config-manager --disable remi - yum-config-manager --disable remi-safe - yum -y --enablerepo=remi install redis - fi - fi - if [[ $SERVER_OS == "Ubuntu" ]]; then - DEBIAN_FRONTEND=noninteractive apt install -y lsphp74-redis - DEBIAN_FRONTEND=noninteractive apt install -y lsphp73-redis - DEBIAN_FRONTEND=noninteractive apt install -y lsphp72-redis - DEBIAN_FRONTEND=noninteractive apt install -y lsphp71-redis - DEBIAN_FRONTEND=noninteractive apt install -y lsphp70-redis - DEBIAN_FRONTEND=noninteractive apt install -y redis - fi +Setup_Pip() { - if ifconfig -a | grep inet6; then - echo -e "\n IPv6 detected..." +rm -rf /root/.pip +mkdir -p /root/.pip +cat </root/.pip/pip.conf +[global] +index-url=https://cyberpanel.sh/pip-repo/pypi/simple/ +EOF +#default to self-host pip for CN + +if [[ "$Server_Provider" = "Alibaba Cloud" ]] ; then +sed -i 's|https://cyberpanel.sh/pip-repo/pypi/simple/|http://mirrors.cloud.aliyuncs.com/pypi/simple/|g' /root/.pip/pip.conf +echo "trusted-host = mirrors.cloud.aliyuncs.com" >> /root/.pip/pip.conf +fi + +if [[ "$Server_Provider" = "Tencent Cloud" ]] ; then +sed -i 's|https://cyberpanel.sh/pip-repo/pypi/simple/|https://mirrors.cloud.tencent.com/pypi/simple/|g' /root/.pip/pip.conf +fi +#set Alibaba and Tencent to their private mirror + + +Debug_Log2 "Setting up PIP repo..." +#set up pip for Alibaba, Tencent worldwide and Chinese server + +if [[ "$Debug" = "On" ]] ; then + Debug_Log "Pip Source" "$(grep "index-url" /root/.pip/pip.conf)" +fi +} + +Pre_Install_Setup_CN_Repository() { +if [[ "$Server_OS" = "CentOS" ]] && [[ "$Server_OS_Version" = "7" ]]; then + + sed -i 's|http://yum.mariadb.org|https://cyberpanel.sh/yum.mariadb.org|g' /etc/yum.repos.d/MariaDB.repo + sed -i 's|https://yum.mariadb.org/RPM-GPG-KEY-MariaDB|https://cyberpanel.sh/yum.mariadb.org/RPM-GPG-KEY-MariaDB|g' /etc/yum.repos.d/MariaDB.repo + # use MariaDB Mirror + + sed -i 's|https://download.copr.fedorainfracloud.org|https://cyberpanel.sh/download.copr.fedorainfracloud.org|g' /etc/yum.repos.d/_copr_copart-restic.repo + + sed -i 's|http://repo.iotti.biz|https://cyberpanel.sh/repo.iotti.biz|g' /etc/yum.repos.d/frank.repo + + sed -i "s|mirrorlist=http://mirrorlist.ghettoforge.org/el/7/gf/\$basearch/mirrorlist|baseurl=https://cyberpanel.sh/mirror.ghettoforge.org/distributions/gf/el/7/gf/x86_64/|g" /etc/yum.repos.d/gf.repo + sed -i "s|mirrorlist=http://mirrorlist.ghettoforge.org/el/7/plus/\$basearch/mirrorlist|baseurl=https://cyberpanel.sh/mirror.ghettoforge.org/distributions/gf/el/7/plus/x86_64/|g" /etc/yum.repos.d/gf.repo + + sed -i 's|https://repo.ius.io|https://cyberpanel.sh/repo.ius.io|g' /etc/yum.repos.d/ius.repo + + sed -i 's|http://repo.iotti.biz|https://cyberpanel.sh/repo.iotti.biz|g' /etc/yum.repos.d/lux.repo + + sed -i 's|http://repo.powerdns.com|https://cyberpanel.sh/repo.powerdns.com|g' /etc/yum.repos.d/powerdns-auth-43.repo + sed -i 's|https://repo.powerdns.com|https://cyberpanel.sh/repo.powerdns.com|g' /etc/yum.repos.d/powerdns-auth-43.repo +fi +# sed -i 's|http://mirrors.tencentyun.com/ubuntu/|https://cyberpanel.sh/us.archive.ubuntu.com/ubuntu/|g' /etc/apt/sources.list + +Debug_Log2 "Setting up repositories for CN server..." +} + +Download_Requirement() { +for i in {1..50} ; + do + wget -O /usr/local/requirments.txt "${Git_Content_URL}/${Branch_Name}/requirments.txt" + if grep -q "Django==" /usr/local/requirments.txt ; then + break else - sed -i 's|bind 127.0.0.1 ::1|bind 127.0.0.1|g' /etc/redis/redis.conf - echo -e "\n no IPv6 detected..." - fi - - if [[ $SERVER_OS == "CentOS" ]]; then - systemctl enable redis - systemctl start redis - fi - - if [[ $SERVER_OS == "Ubuntu" ]]; then - systemctl stop redis-server - rm -f /var/run/redis/redis-server.pid - systemctl enable redis-server - systemctl start redis-server - fi - - if ps -aux | grep "redis" | grep -v grep; then - echo -e "\n\nRedis installed and running..." + echo -e "\n Requirement list has failed to download for $i times..." + echo -e "Wait for 30 seconds and try again...\n" + sleep 30 fi +done +#special made function for Gitee.com , for whatever reason , sometimes it fails to download this file } -check_provider() { +Pre_Install_Required_Components() { - if hash dmidecode >/dev/null 2>&1; then - if [ "$(dmidecode -s bios-vendor)" = 'Google' ]; then - PROVIDER='Google Cloud Platform' - elif [ "$(dmidecode -s bios-vendor)" = 'DigitalOcean' ]; then - PROVIDER='Digital Ocean' - elif [ "$(dmidecode -s system-product-name | cut -c 1-7)" = 'Alibaba' ]; then - PROVIDER='Alibaba Cloud' - elif [ "$(dmidecode -s system-manufacturer)" = 'Microsoft Corporation' ]; then - PROVIDER='Microsoft Azure' - elif [ -d /usr/local/qcloud ]; then - PROVIDER='Tencent Cloud' +Debug_Log2 "Installing necessary components..,3" + +if [[ "$Server_OS" = "CentOS" ]] ; then + yum update -y + if [[ "$Server_OS_Version" = "7" ]] ; then + yum install -y wget strace net-tools curl which bc telnet htop libevent-devel gcc libattr-devel xz-devel gpgme-devel curl-devel git socat openssl-devel MariaDB-shared mariadb-devel yum-utils python36u python36u-pip python36u-devel zip unzip bind-utils + Check_Return + yum -y groupinstall development + Check_Return + elif [[ "$Server_OS_Version" = "8" ]] ; then + dnf install -y zip wget strace net-tools curl which bc telnet htop libevent-devel gcc libattr-devel xz-devel mariadb-devel curl-devel git platform-python-devel tar socat python3 zip unzip bind-utils + Check_Return + dnf install -y gpgme-devel + Check_Return + fi + ln -s /usr/bin/pip3 /usr/bin/pip +else + apt update -y + DEBIAN_FRONTEND=noninteractive apt upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" + DEBIAN_FRONTEND=noninteracitve apt install -y dnsutils 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 socat vim unzip zip + Check_Return + + DEBIAN_FRONTEND=noninteractive apt install -y python3-pip + Check_Return + + ln -s /usr/bin/pip3 /usr/bin/pip3.6 + ln -s /usr/bin/pip3.6 /usr/bin/pip + + DEBIAN_FRONTEND=noninteractive apt install -y build-essential libssl-dev libffi-dev python3-dev + Check_Return + DEBIAN_FRONTEND=noninteractive apt install -y python3-venv + Check_Return + + DEBIAN_FRONTEND=noninteractive apt install -y locales + locale-gen "en_US.UTF-8" + update-locale LC_ALL="en_US.UTF-8" +fi + + +export LC_CTYPE=en_US.UTF-8 +export LC_ALL=en_US.UTF-8 +#need to set lang to address some pip module installation issue. + +Retry_Command "pip install --default-timeout=3600 virtualenv==16.7.9" + +Download_Requirement + +virtualenv -p /usr/bin/python3 /usr/local/CyberPanel + Check_Return + +if [[ "$Server_OS" = "Ubuntu" ]] && [[ "$Server_OS_Version" != "20" ]] ; then + # shellcheck disable=SC1091 + source /usr/local/CyberPanel/bin/activate +else + # shellcheck disable=SC1091 + . /usr/local/CyberPanel/bin/activate +fi + +Retry_Command "pip install --default-timeout=3600 -r /usr/local/requirments.txt" + Check_Return "requirments" "no_exit" + +rm -rf cyberpanel +echo -e "\nFetching files from ${Git_Clone_URL}...\n" + +Retry_Command "git clone ${Git_Clone_URL}" + Check_Return "git clone ${Git_Clone_URL}" + +echo -e "\nCyberPanel source code downloaded...\n" + +cd cyberpanel || exit +git checkout "$Branch_Name" + Check_Return "git checkout" +cd - || exit +cp -r cyberpanel /usr/local/cyberpanel +cd cyberpanel/install || exit + +Debug_Log2 "Necessary components installed..,5" +} + +Pre_Install_System_Tweak() { +Debug_Log2 "Setting up sytem tweak..." +Line_Number=$(grep -n "127.0.0.1" /etc/hosts | cut -d: -f 1) +My_Hostname=$(hostname) + +if [[ -n $Line_Number ]]; then + for Line_Number2 in $Line_Number ; do + String=$(sed "${Line_Number2}q;d" /etc/hosts) + if [[ $String != *"$My_Hostname"* ]]; then + New_String="$String $My_Hostname" + sed -i "${Line_Number2}s/.*/${New_String}/" /etc/hosts + fi + done +else + echo "127.0.0.1 $My_Hostname " >>/etc/hosts +fi + #this should address on "sudo: unable to resolve host ..." on Ubuntu , it's not issue but annoying. + +if [[ "$Server_OS" = "CentOS" ]] ; then + setenforce 0 || true + sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config + #disable SELinux + + if [[ "$Server_OS_Version" = "7" ]] ; then + : + fi + #CentOS 7 specific change + if [[ "$Server_OS_Version" = "8" ]] ; then + : + fi + #CentOS 8 specific change + +elif [[ "$Server_OS" = "Ubuntu" ]] ; then + if [[ "$Server_OS_Version" = "20" ]] ; then + sed -i 's|ce-2.3-latest/ubuntu/bionic bionic main|ce-2.3-latest/ubuntu/focal focal main|g' install.py + fi + #Ubuntu 20 specific change. + + if [[ "$Server_OS_Version" = "18" ]] ; then + : + fi + #Ubuntu 18 specific change. +fi + +if ! grep -q "pid_max" /etc/rc.local 2>/dev/null ; then + if [[ $Server_OS = "CentOS" ]] ; then + echo "echo 1000000 > /proc/sys/kernel/pid_max + echo 1 > /sys/kernel/mm/ksm/run" >>/etc/rc.d/rc.local + chmod +x /etc/rc.d/rc.local + else + echo "echo 1000000 > /proc/sys/kernel/pid_max + echo 1 > /sys/kernel/mm/ksm/run" >>/etc/rc.local + chmod +x /etc/rc.local + fi + echo "fs.file-max = 65535" >>/etc/sysctl.conf + sysctl -p >/dev/null + echo "* soft nofile 65535 + * hard nofile 65535 + root soft nofile 65535 + root hard nofile 65535 + * soft nproc 65535 + * hard nproc 65535 + root soft nproc 65535 + root hard nproc 65535" >>/etc/security/limits.conf + fi + #sed -i 's|#DefaultLimitNOFILE=|DefaultLimitNOFILE=65535|g' /etc/systemd/system.conf + #raise the file limit for systemd process + + Total_SWAP=$(free -m | awk '/^Swap:/ { print $2 }') + Set_SWAP=$((Total_RAM - Total_SWAP)) + SWAP_File=/cyberpanel.swap + + if [ ! -f $SWAP_File ]; then + if [[ $Total_SWAP -gt $Total_RAM ]] || [[ $Total_SWAP -eq $Total_RAM ]]; then + echo -e "Check SWAP...\n" else - PROVIDER='undefined' - fi - else - PROVIDER='undefined' - fi - - if [[ -f /sys/devices/virtual/dmi/id/product_uuid ]]; then - if [ "$(cat /sys/devices/virtual/dmi/id/product_uuid | cut -c 1-3)" = 'EC2' ] && [ -d /home/ubuntu ]; then - PROVIDER='Amazon Web Service' - fi - fi - -} - -check_OS() { - 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="CentOS" - elif echo $OUTPUT | grep -q "CloudLinux 7"; then - echo -e "\nDetecting CloudLinux 7.X...\n" - SERVER_OS="CentOS" - elif echo $OUTPUT | grep -q "CentOS Linux 8"; then - echo -e "\nDetecting CentOS 8.X...\n" - SERVER_OS="CentOS" - CENTOS_8="True" - elif echo $OUTPUT | grep -q "Ubuntu 18.04"; then - if uname -m | grep -q 64; then - echo -e "\nDetecting Ubuntu 18.04...\n" - SERVER_OS="Ubuntu" - else - echo -e "\nUbuntu 18.04 x32 detected...ths only works on x64 system." - echo 'Ubuntu 18.04 x32 detected...ths only works on x64 system. [404]' >>/var/log/installLogs.txt - exit - fi - elif echo $OUTPUT | grep -q "Ubuntu 20.04"; then - if uname -m | grep -q 64; then - echo -e "\nDetecting Ubuntu 20.04 ...\n" - SERVER_OS="Ubuntu" - UBUNTU_20="True" - else - echo -e "\nUbuntu 20 x32 detected...ths only works on x64 system." - echo 'Ubuntu 20 x32 detected...ths only works on x64 system. [404]' >>/var/log/installLogs.txt - exit - fi - else - cat /etc/*release - echo -e "\nUnable to detect your OS...\n" - echo -e "\nCyberPanel is supported on Ubuntu 18.04 x86_64, Ubuntu 20.04 x86_64, CentOS 7.x, CentOS 8.x and CloudLinux 7.x...\n" - echo 'CyberPanel is supported on Ubuntu 18.04 x86_64, Ubuntu 20.04 x86_64, CentOS 7.x, CentOS 8.x and CloudLinux 7.x... [404]' >>/var/log/installLogs.txt - exit 1 - fi - -} - -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" - 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 installation command again." - exit - fi - - if [[ $(id -u) != 0 ]] >/dev/null; then - echo -e "\nYou must use root user to install CyberPanel...\n" - # echo -e "or run following command: (do NOT miss the quotes)" - # echo -e "\e[31msudo su -c \"sh <(curl https://cyberpanel.sh || wget -O - https://cyberpanel.sh)\"\e[39m" - exit 1 - else - echo -e "\nYou are runing as root...\n" - fi -} - -check_panel() { - if [ -d /usr/local/cpanel ]; then - echo -e "\ncPanel detected...exit...\n" - echo 'cPanel detected...exit... [404]' >>/var/log/installLogs.txt - exit 1 - fi - if [ -d /opt/plesk ]; then - echo -e "\nPlesk detected...exit...\n" - echo 'Plesk detected...exit... [404]' >>/var/log/installLogs.txt - exit 1 - fi -} - -check_process() { - if systemctl is-active --quiet httpd; then - systemctl disable httpd - systemctl stop httpd - systemctl mask httpd - echo -e "\nhttpd process detected, disabling...\n" - fi - if systemctl is-active --quiet apache2; then - systemctl disable apache2 - systemctl stop apache2 - systemctl mask apache2 - echo -e "\napache2 process detected, disabling...\n" - fi - if systemctl is-active --quiet named; then - systemctl stop named - systemctl disable named - systemctl mask named - echo -e "\nnamed process detected, disabling...\n" - fi - if systemctl is-active --quiet exim; then - systemctl stop exim - systemctl disable exim - systemctl mask exim - echo -e "\nexim process detected, disabling...\n" - fi -} - -show_help() { - echo -e "\nCyberPanel Installer Script Help\n" - echo -e "\nUsage: sh <(curl cyberpanel.sh) --argument" - echo -e "\n -v or --version: choose to install CyberPanel OpenLiteSpeed or CyberPanel Enterprise, available options are \e[31mols\e[39m and \e[31mSERIAL_NUMBER\e[39m, default ols" - echo -e "\n Please be aware, this serial number must be obtained from LiteSpeed Store." - echo -e "\n And if this serial number has been used before, it must be released/migrated in Store first, otherwise it will fail to start." - echo -e "\n -a or --addons: install addons: memcached, redis, PHP extension for memcached and redis" - echo -e "\n -p or --password: set password of new installation, empty for default 1234567, [r] or [random] for randomly generated 16 digital password, any other value besides [d] and [r(andom)] will be accept as password, default use 1234567." - echo -e "\n -m: set to minimal mode which will not install PowerDNS, Pure-FTPd and Postfix" - echo -e "\n Example:" - echo -e "\n sh <(curl cyberpanel.sh) -v ols -p r or ./cyberpanel.sh --version ols --password random" - echo -e "\n This will install CyberPanel OpenLiteSpeed and randomly generate the password." - echo -e "\n sh <(curl cyberpanel.sh) -v LICENSE_KEY -a -p my_pass_word" - echo -e "\n This will install LiteSpeed Enterise , replace LICENSE_KEY to actual license key and set password to my_pass_word\n" -} - -license_input() { - VERSION="ENT" - echo -e "\nPlease note that your server has \e[31m$TOTAL_RAM MB\e[39m RAM" - echo -e "If you are using \e[31mFree Start\e[39m license, It will not start due to \e[31m2GB RAM limit\e[39m.\n" - echo -e "If you do not have any license, you can also use trial license (if server has not used trial license before), type \e[31mTRIAL\e[39m\n" - - printf "%s" "Please input your serial number for LiteSpeed WebServer Enterprise:" - read LICENSE_KEY - if [ -z "$LICENSE_KEY" ]; then - echo -e "\nPlease provide license key\n" - exit - fi - - echo -e "The serial number you input is: \e[31m$LICENSE_KEY\e[39m" - printf "%s" "Please verify it is correct. [y/N]" - read TMP_YN - if [ -z "$TMP_YN" ]; then - echo -e "\nPlease type \e[31my\e[39m\n" - exit - fi - - KEY_SIZE=${#LICENSE_KEY} - TMP=$(echo $LICENSE_KEY | cut -c5) - TMP2=$(echo $LICENSE_KEY | cut -c10) - TMP3=$(echo $LICENSE_KEY | cut -c15) - - if [[ $TMP == "-" ]] && [[ $TMP2 == "-" ]] && [[ $TMP3 == "-" ]] && [[ $KEY_SIZE == "19" ]]; then - echo -e "\nLicense key set..." - elif [[ $LICENSE_KEY == "trial" ]] || [[ $LICENSE_KEY == "TRIAL" ]] || [[ $LICENSE_KEY == "Trial" ]]; then - echo -e "\nTrial license set..." - LICENSE_KEY="TRIAL" - else - echo -e "\nLicense key seems incorrect, please verify\n" - echo -e "\nIf you are copying/pasting, please make sure you didn't paste blank space...\n" - exit - fi - - echo -e "\nWould you like use Redis Mass Hosting?" - echo -e "Please type Yes or No (with capital \e[31mY\e[39m, default No):" - printf "%s" - read REDIS_HOSTING - -} - -interactive_mode() { - echo -e " CyberPanel Installer v$CP_VER1$CP_VER2 - - 1. Install CyberPanel. - - 2. Addons and Miscellaneous - - 3. Exit. - - " - read -p " Please enter the number[1-3]: " num - echo "" - case "$num" in - 1) - interactive_install - ;; - 2) - interactive_others - ;; - 3) - exit - ;; - *) - echo -e " Please enter the right number [1-3]\n" - exit - ;; - esac -} - -interactive_others() { - if [ ! -e "/etc/cyberpanel/machineIP" ]; then - echo -e "\nYou don't have CyberPanel installed...\n" - exit - fi - - echo -e " CyberPanel Addons v$CP_VER1$CP_VER2 - - 1. Install Memcached extension and backend - - 2. Install Redis extension and backend - - 3. Return to main page. - - 4. Exit - " - - echo && read -p "Please enter the number[1-4]: " num - case "$num" in - 1) - memcached_installation - exit - ;; - 2) - redis_installation - exit - ;; - 3) - interactive_mode - ;; - 4) - exit - ;; - *) - echo -e "${Error} please enter the right number [1-4]" - ;; - esac -} - -interactive_install() { - RAM=$(free -m | awk 'NR==2{printf "%s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }') - DISK=$(df -h | awk '$NF=="/"{printf "%d/%dGB (%s)\n", $3,$2,$5}') - #clear - echo -e " CyberPanel Installer v$CP_VER1$CP_VER2 - - RAM check : $RAM - - Disk check : $DISK (Minimal \e[31m10GB\e[39m free space) - - 1. Install CyberPanel with \e[31mOpenLiteSpeed\e[39m. - - 2. Install Cyberpanel with \e[31mLiteSpeed Enterprise\e[39m. - - 3. Exit. - - " - read -p " Please enter the number[1-3]: " num - echo "" - case "$num" in - 1) - VERSION="OLS" - ;; - 2) - license_input - ;; - 3) - exit - ;; - *) - echo -e " Please enter the right number [1-3]\n" - exit - ;; - esac - - echo -e "\nInstall Full service for CyberPanel? This will include PowerDNS, Postfix and Pure-FTPd." - echo -e "" - printf "%s" "Full installation [Y/n]: " - read TMP_YN - if [[ $(expr "x$TMP_YN" : 'x[Yy]') -gt 1 ]] || [[ $TMP_YN == "" ]]; then - echo -e "\nFull installation selected..." - POSTFIX_VARIABLE="ON" - POWERDNS_VARIABLE="ON" - PUREFTPD_VARIABLE="ON" - else - echo -e "" - printf "%s" "Install Postfix? [Y/n]: " - read TMP_YN - if [[ $TMP_YN =~ ^(no|n|N) ]]; then - POSTFIX_VARIABLE="OFF" - else - POSTFIX_VARIABLE="ON" - fi - echo -e "" - printf "%s" "Install PowerDNS? [Y/n]: " - read TMP_YN - if [[ $TMP_YN =~ ^(no|n|N) ]]; then - POWERDNS_VARIABLE="OFF" - else - POWERDNS_VARIABLE="ON" - fi - echo -e "" - printf "%s" "Install PureFTPd? [Y/n]: " - read TMP_YN - if [[ $TMP_YN =~ ^(no|n|N) ]]; then - PUREFTPD_VARIABLE="OFF" - else - PUREFTPD_VARIABLE="ON" - fi - fi - - ### Ask if you want to set up this CyberPanel with remote MySQL - - echo -e "\nDo you want to setup Remote MySQL? (This will skip installation of local MySQL)" - echo -e "" - printf "%s" "(Default = No) Remote MySQL [y/N]: " - read TMP_YN - if [[ $(expr "x$TMP_YN" : 'x[Yy]') -gt 1 ]]; then - echo -e "\nRemote MySQL selected..." - REMOTE_MYSQL='ON' - - echo -e "" - printf "%s" "Remote MySQL Hostname: " - read MYSQL_HOST - - echo -e "" - printf "%s" "Remote MySQL Database that contains meta information regarding MYSQL. (usually mysql): " - read MYSQL_DB - - echo -e "" - printf "%s" "Remote MySQL Username: " - read MYSQL_USER - - echo -e "" - printf "%s" "Remote MySQL Password: " - read -r -s -p "Password: " MYSQL_PASSWORD - - echo -e "" - printf "%s" "Remote MySQL Port: " - read MYSQL_PORT - - else - - echo -e "" - printf "%s" "Local MySQL selected.." - echo -e "" - - fi - - ### - - #above comment for future use - - #if [[ $DEV_ARG == "ON" ]] ; then - #echo -e "Press \e[31mEnter\e[39m to continue with stable version of CyberPanel, or" - #echo -e "\nPlease enter \e[31mbeta\e[39m and then press \e[31mEnter\e[39m to install CyberPanel with Python 3." - #echo -e "\nCentOS 8 will autoamtically proceed with Python 3 branch." - #printf "%s" "" - #read TMP_YN - - echo -e "\nPress \e[31mEnter\e[39m key to continue with latest version or Enter specific version such as: \e[31m1.9.4\e[39m , \e[31m2.0.1\e[39m , \e[31m2.0.2\e[39m ...etc" - printf "%s" "" - read TMP_YN - - DEV="ON" - 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" + if [[ $Set_SWAP -gt "2049" ]]; then + #limit it to 2GB as max size + Set_SWAP="2048" fi - else - echo -e "\nPlease input a valid format version number." - exit + fallocate --length ${Set_SWAP}MiB $SWAP_File + chmod 600 $SWAP_File + mkswap $SWAP_File + swapon $SWAP_File + echo -e "${SWAP_File} swap swap sw 0 0" | sudo tee -a /etc/fstab + sysctl vm.swappiness=10 + echo -e "vm.swappiness = 10" >> /etc/sysctl.conf + echo -e "\nSWAP set...\n" fi fi - #if [[ $TMP_YN == "beta" ]] ; then - # DEV="ON" - ## echo -e "\nPlease specify branch name" - ## printf "%s" "" - ## read TMP_YN - # BRANCH_NAME="p3" - # echo -e "Branch name set to $BRANCH_NAME" - #else - # DEV="OFF" - # - # if [[ $CENTOS_8 == "True" ]] ; then - # DEV="ON" - # BRANCH_NAME="p3" - # fi - #fi + if [[ "$Server_Provider" = "Tencent Cloud" ]] ; then + echo "$(host mirrors.tencentyun.com | awk '{print $4}') mirrors.tencentyun.com " >> /etc/hosts + fi + if [[ "$Server_Provider" = "Alibaba Cloud" ]] ; then + echo "$(host mirrors.cloud.aliyuncs.com | awk '{print $4}') mirrors.cloud.aliyuncs.com " >> /etc/hosts + fi + #add internal repo server to host file before systemd-resolved is disabled - #fi + if grep -i -q "systemd-resolve" /etc/resolv.conf ; then + systemctl stop systemd-resolved >/dev/null 2>&1 + systemctl disable systemd-resolved >/dev/null 2>&1 + systemctl mask systemd-resolved >/dev/null 2>&1 + fi - echo -e "\nPlease choose to use default admin password \e[31m1234567\e[39m, randomly generate one \e[31m(recommended)\e[39m or specify the admin password?" - printf "%s" "Choose [d]fault, [r]andom or [s]et password: [d/r/s] " - read TMP_YN + rm -f /etc/resolv.conf - if [[ $TMP_YN =~ ^(d|D| ) ]] || [[ -z $TMP_YN ]]; then - ADMIN_PASS="1234567" - echo -e "\nAdmin password will be set to $ADMIN_PASS\n" - elif [[ $TMP_YN =~ ^(r|R) ]]; then - ADMIN_PASS=$( - head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 - echo '' - ) - echo -e "\nAdmin password will be provided once installation is completed...\n" - elif [[ $TMP_YN =~ ^(s|S) ]]; then - CUSTOM_PASS="True" - echo -e "\nPlease enter your password:" - printf "%s" "" - read -r -s -p "Password: " TMP_YN - if [ -z "$TMP_YN" ]; then - echo -e "\nPlease do not use empty string...\n" - exit - fi - if [ ${#TMP_YN} -lt 8 ]; then - echo -e "\nPassword lenth less than 8 digital, please choose a more complicated password.\n" - exit - fi - TMP_YN1=$TMP_YN - printf "%s\n" "" - read -r -s -p "Confirm Password:" TMP_YN - if [ -z "$TMP_YN" ]; then - echo -e "\nPlease do not use empty string...\n" - exit - fi - TMP_YN2=$TMP_YN - if [ $TMP_YN1 = $TMP_YN2 ]; then - ADMIN_PASS=$TMP_YN1 - else - echo -e "\nRepeated password didn't match , please check...\n" - exit - fi + if [[ "$Server_Provider" = "Tencent Cloud" ]] ; then + echo -e "nameserver 183.60.83.19" > /etc/resolv.conf + echo -e "nameserver 183.60.82.98" >> /etc/resolv.conf + elif [[ "$Server_Provider" = "Alibaba Cloud" ]] ; then + echo -e "nameserver 100.100.2.136" > /etc/resolv.conf + echo -e "nameserver 100.100.2.138" >> /etc/resolv.conf else - ADMIN_PASS="1234567" - echo -e "\nAdmin password will be set to $ADMIN_PASS\n" + echo -e "nameserver 1.1.1.1" > /etc/resolv.conf + echo -e "nameserver 8.8.8.8" >> /etc/resolv.conf fi - echo -e "\nDo you wish to install Memcached extension and backend?" - printf "%s" "Please select [Y/n]: " - read TMP_YN - if [[ $TMP_YN =~ ^(no|n|N) ]]; then - MEMCACHED="OFF" - else - MEMCACHED="ON" - fi + systemctl restart systemd-networkd >/dev/null 2>&1 + sleep 3 + #take a break ,or installer will break - echo -e "\nDo you wish to install Redis extension and backend?" - printf "%s" "Please select [Y/n]: " - read TMP_YN - if [[ $TMP_YN =~ ^(no|n|N) ]]; then - REDIS="OFF" - else - REDIS="ON" - fi +cp /etc/resolv.conf /etc/resolv.conf-tmp - echo -e "\nWould you like to set up a WatchDog \e[31m(beta)\e[39m for Web service and Database service ?" - echo -e "The watchdog script will be automatically started up after installation and server reboot" - echo -e "If you want to kill the watchdog , run \e[31mwatchdog kill\e[39m" - echo -e "Please type Yes or no (with capital \e[31mY\e[39m, default Yes):" - printf "%s" - read TMP_YN - if [[ $TMP_YN == "Yes" ]] || [[ $TMP_YN == "" ]]; then - WATCHDOG="ON" - else - WATCHDOG="OFF" - fi +Line1="$(grep -n "f.write('nameserver 8.8.8.8')" installCyberPanel.py | head -n 1 | cut -d: -f1)" +sed -i "${Line1}i\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ subprocess.call\(command, shell=True)" installCyberPanel.py +sed -i "${Line1}i\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ command = 'cat /etc/resolv.conf-tmp > /etc/resolv.conf'" installCyberPanel.py } -main_install() { +License_Validation() { +Debug_Log2 "Validating LiteSpeed license..." +Current_Dir=$(pwd) - if [[ -e /usr/local/CyberCP ]]; then - echo -e "\n CyberPanel already installed, exiting..." - echo 'CyberPanel already installed, exiting... [404]' >>/var/log/installLogs.txt - exit +if [ -f /root/cyberpanel-tmp ]; then + rm -rf /root/cyberpanel-tmp +fi + +mkdir /root/cyberpanel-tmp +cd /root/cyberpanel-tmp || exit + +Retry_Command "wget https://cyberpanel.sh/www.litespeedtech.com/packages/${LSWS_Stable_Version:0:1}.0/lsws-$LSWS_Stable_Version-ent-x86_64-linux.tar.gz" +tar xzvf "lsws-$LSWS_Stable_Version-ent-x86_64-linux.tar.gz" >/dev/null +cd "/root/cyberpanel-tmp/lsws-$LSWS_Stable_Version/conf" || exit +if [[ "$License_Key" = "Trial" ]]; then + Retry_Command "wget -q https://cyberpanel.sh/license.litespeedtech.com/reseller/trial.key" + sed -i "s|writeSerial = open('lsws-5.4.2/serial.no', 'w')|command = 'wget -q --output-document=./lsws-$LSWS_Stable_Version/trial.key https://cyberpanel.sh/license.litespeedtech.com/reseller/trial.key'|g" "$Current_Dir/installCyberPanel.py" + sed -i 's|writeSerial.writelines(self.serial)|subprocess.call(command, shell=True)|g' "$Current_Dir/installCyberPanel.py" + sed -i 's|writeSerial.close()||g' "$Current_Dir/installCyberPanel.py" +else + echo "$License_Key" > serial.no +fi + +cd "/root/cyberpanel-tmp/lsws-$LSWS_Stable_Version/bin" || exit + +if [[ "$License_Key" = "Trial" ]]; then + License_Key="1111-2222-3333-4444" +else + ./lshttpd -r +fi + +if ./lshttpd -V |& grep "ERROR" || ./lshttpd -V |& grep "expire in 0 days" ; then + echo -e "\n\nIt apeears to have some issue with license , please check above result..." + Debug_Log2 "It appears to have some issue with LiteSpeed License, make sure you are using correct serial key. [404]" + exit +fi + +echo -e "\nLicense seems valid..." +cd "$Current_Dir" || exit +rm -rf /root/cyberpanel-tmp + #clean up the temp files +} + +Pre_Install_CN_Replacement() { +if [[ "$Server_OS" = "Ubuntu" ]] ; then + sed -i 's|wget http://rpms.litespeedtech.com/debian/|wget https://cyberpanel.sh/litespeed/|g' install.py + sed -i 's|https://repo.dovecot.org/|https://cyberpanel.sh/repo.dovecot.org/|g' install.py +fi + #replace litespeed repo on ubuntu 18/20 + +if [[ "$Server_OS" = "CentOS" ]] ; then + sed -i 's|rpm -ivh http://rpms.litespeedtech.com/centos/litespeed-repo-1.2-1.el7.noarch.rpm|curl -o /etc/yum.repos.d/litespeed.repo https://cyberpanel.sh/litespeed/litespeed_cn.repo|g' install.py + sed -i 's|rpm -Uvh http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el8.noarch.rpm|curl -o /etc/yum.repos.d/litespeed.repo https://cyberpanel.sh/litespeed/litespeed_cn.repo|g' install.py + sed -i 's|https://mirror.ghettoforge.org/distributions|https://cyberpanel.sh/mirror.ghettoforge.org/distributions|g' install.py + + if [[ "$Server_OS_Version" = "8" ]] ; then + sed -i 's|dnf --nogpg install -y https://mirror.ghettoforge.org/distributions/gf/el/8/gf/x86_64/gf-release-8-11.gf.el8.noarch.rpm|echo gf8|g' install.py + sed -i 's|dnf --nogpg install -y https://cyberpanel.sh/mirror.ghettoforge.org/distributions/gf/el/8/gf/x86_64/gf-release-8-11.gf.el8.noarch.rpm|echo gf8|g' install.py + + Retry_Command "dnf --nogpg install -y https://cyberpanel.sh/mirror.ghettoforge.org/distributions/gf/el/8/gf/x86_64/gf-release-8-11.gf.el8.noarch.rpm" + sed -i "s|mirrorlist=http://mirrorlist.ghettoforge.org/el/8/gf/\$basearch/mirrorlist|baseurl=https://cyberpanel.sh/mirror.ghettoforge.org/distributions/gf/el/8/gf/x86_64/|g" /etc/yum.repos.d/gf.repo + sed -i "s|mirrorlist=http://mirrorlist.ghettoforge.org/el/8/plus/\$basearch/mirrorlist|baseurl=https://cyberpanel.sh/mirror.ghettoforge.org/distributions/gf/el/8/plus/x86_64/|g" /etc/yum.repos.d/gf.repo + #get this set up beforehand. fi - special_change +fi - if [[ $VERSION == "ENT" ]]; then - echo -e "\nValidating the license..." - echo -e "\nThis may take a minute..." - echo -e "\nplease be patient...\n\n" - license_validation +sed -i "s|https://www.litespeedtech.com/|https://cyberpanel.sh/www.litespeedtech.com/|g" installCyberPanel.py +sed -i 's|composer.sh|composer_cn.sh|g' install.py +sed -i 's|./composer_cn.sh|COMPOSER_ALLOW_SUPERUSER=1 ./composer_cn.sh|g' install.py +sed -i 's|http://www.litespeedtech.com|https://cyberpanel.sh/www.litespeedtech.com|g' install.py +sed -i 's|https://www.rainloop.net/repository/webmail/rainloop-community-latest.zip|https://cyberpanel.sh/www.rainloop.net/repository/webmail/rainloop-community-latest.zip|g' install.py - SERIAL_NO="--ent ent --serial " - fi +sed -i "s|rep.cyberpanel.net|cyberpanel.sh/rep.cyberpanel.net|g" installCyberPanel.py +sed -i "s|rep.cyberpanel.net|cyberpanel.sh/rep.cyberpanel.net|g" install.py - sed -i 's|lsws-5.4.2|lsws-'$LSWS_STABLE_VER'|g' installCyberPanel.py - sed -i 's|lsws-5.3.5|lsws-'$LSWS_STABLE_VER'|g' installCyberPanel.py + +Debug_Log2 "Setting up URLs for CN server..." + + +sed -i 's|wget -O - https://get.acme.sh \| sh|echo acme|g' install.py +sed -i 's|/root/.acme.sh/acme.sh --upgrade --auto-upgrade|echo acme2|g' install.py + +Current_Dir=$(pwd) +Retry_Command "git clone https://gitee.com/neilpang/acme.sh.git" +cd acme.sh || exit +./acme.sh --install +cd "$Current_Dir" || exit +rm -rf acme.sh + +# shellcheck disable=SC2016 +sed -i 's|$PROJECT/archive/$BRANCH.tar.gz|https://cyberpanel.sh/codeload.github.com/acmesh-official/acme.sh/tar.gz/master|g' /root/.acme.sh/acme.sh + +Retry_Command "/root/.acme.sh/acme.sh --upgrade --auto-upgrade" +#install acme and upgrade it beforehand, to prevent gitee fail +} + +Main_Installation() { +Debug_Log2 "Start to main installation..." +if [[ -d /usr/local/CyberCP ]] ; then + echo -e "\n CyberPanel already installed, exiting..." + Debug_Log2 "CyberPanel already installed, exiting... [404]" + exit +fi + +if [[ $Server_Edition = "Enterprise" ]] ; then + echo -e "\nValidating the license..." + echo -e "\nThis may take a minute..." + echo -e "\nPlease be patient...\n" + + License_Validation + + sed -i "s|lsws-5.4.2|lsws-$LSWS_Stable_Version|g" installCyberPanel.py + sed -i "s|lsws-5.3.5|lsws-$LSWS_Stable_Version|g" installCyberPanel.py #this sed must be done after license validation - echo -e "Preparing..." - echo -e "Installation will start in 10 seconds, if you wish to stop please press CTRL + C" - sleep 10 - debug="1" - if [[ $debug == "0" ]]; then - echo "/usr/local/CyberPanel/bin/python install.py $SERVER_IP $SERIAL_NO $LICENSE_KEY --postfix $POSTFIX_VARIABLE --powerdns $POWERDNS_VARIABLE --ftp $PUREFTPD_VARIABLE" - exit - fi - if [[ $debug == "1" ]]; then - if [[ $REDIS_HOSTING == "Yes" ]]; then - if [[ $REMOTE_MYSQL == "ON" ]]; then - /usr/local/CyberPanel/bin/python install.py $SERVER_IP $SERIAL_NO $LICENSE_KEY --postfix $POSTFIX_VARIABLE --powerdns $POWERDNS_VARIABLE --ftp $PUREFTPD_VARIABLE --redis enable --remotemysql $REMOTE_MYSQL --mysqlhost $MYSQL_HOST --mysqldb $MYSQL_DB --mysqluser $MYSQL_USER --mysqlpassword $MYSQL_PASSWORD --mysqlport $MYSQL_PORT - else - /usr/local/CyberPanel/bin/python install.py $SERVER_IP $SERIAL_NO $LICENSE_KEY --postfix $POSTFIX_VARIABLE --powerdns $POWERDNS_VARIABLE --ftp $PUREFTPD_VARIABLE --redis enable --remotemysql $REMOTE_MYSQL - fi - else - if [[ $REMOTE_MYSQL == "ON" ]]; then - echo "/usr/local/CyberPanel/bin/python install.py $SERVER_IP $SERIAL_NO $LICENSE_KEY --postfix $POSTFIX_VARIABLE --powerdns $POWERDNS_VARIABLE --ftp $PUREFTPD_VARIABLE --remotemysql $REMOTE_MYSQL --mysqlhost $MYSQL_HOST --mysqluser $MYSQL_USER --mysqlpassword $MYSQL_PASSWORD --mysqlport $MYSQL_PORT" - /usr/local/CyberPanel/bin/python install.py $SERVER_IP $SERIAL_NO $LICENSE_KEY --postfix $POSTFIX_VARIABLE --powerdns $POWERDNS_VARIABLE --ftp $PUREFTPD_VARIABLE --remotemysql $REMOTE_MYSQL --mysqlhost $MYSQL_HOST --mysqldb $MYSQL_DB --mysqluser $MYSQL_USER --mysqlpassword $MYSQL_PASSWORD --mysqlport $MYSQL_PORT - else - /usr/local/CyberPanel/bin/python install.py $SERVER_IP $SERIAL_NO $LICENSE_KEY --postfix $POSTFIX_VARIABLE --powerdns $POWERDNS_VARIABLE --ftp $PUREFTPD_VARIABLE --remotemysql $REMOTE_MYSQL - fi - fi + Enterprise_Flag="--ent ent --serial " +fi - if grep "CyberPanel installation successfully completed" /var/log/installLogs.txt >/dev/null; then - echo -e "\nCyberPanel installation sucessfully completed..." - else - echo -e "Oops, something went wrong..." - echo 'Oops, something went wrong... [404]' >>/var/log/installLogs.txt - exit - fi +sed -i 's|git clone https://github.com/usmannasir/cyberpanel|echo downloaded|g' install.py +sed -i 's|mirror.cyberpanel.net|cyberpanel.sh|g' install.py - if [[ $MEMCACHED == "ON" ]]; then - memcached_installation - fi - if [[ $REDIS == "ON" ]]; then - redis_installation - fi - after_install - fi +if [[ $Server_Country = "CN" ]] ; then + Pre_Install_CN_Replacement +fi + +echo -e "Preparing...\n" + +Final_Flags=() +Final_Flags+=("$Server_IP") +Final_Flags+=(${Enterprise_Flag:+$Enterprise_Flag}) +Final_Flags+=(${License_Key:+$License_Key}) +Final_Flags+=(--postfix "${Postfix_Switch^^}") +Final_Flags+=(--powerdns "${PowerDNS_Switch^^}") +Final_Flags+=(--ftp "${PureFTPd_Switch^^}") + +if [[ "$Redis_Hosting" = "Yes" ]] ; then + Final_Flags+=(--redis enable) +fi + +if [[ "$Remote_MySQL" = "On" ]] ; then + Final_Flags+=(--remotemysql "${Remote_MySQL^^}") + Final_Flags+=(--mysqlhost "$MySQL_Host") + Final_Flags+=(--mysqldb "$MySQL_DB") + Final_Flags+=(--mysqluser "$MySQL_User") + Final_Flags+=(--mysqlpassword "$MySQL_Password") + Final_Flags+=(--mysqlport "$MySQL_Port") +else + Final_Flags+=(--remotemysql "${Remote_MySQL^^}") +fi + #form up the final agurment for install.py +if [[ "$Debug" = "On" ]] ; then + Debug_Log "Final_Flags" "${Final_Flags[@]}" +fi + +/usr/local/CyberPanel/bin/python install.py "${Final_Flags[@]}" + + +if grep "CyberPanel installation successfully completed" /var/log/installLogs.txt >/dev/null; then + echo -e "\nCyberPanel installation sucessfully completed...\n" + Debug_Log2 "Main installation completed..." +else + echo -e "Oops, something went wrong..." + Debug_Log2 "Oops, something went wrong... [404]" + exit +fi } -pip_virtualenv() { - if [[ $SERVER_OS == "Ubuntu" ]]; then - DEBIAN_FRONTEND=noninteractive apt install -y locales - locale-gen "en_US.UTF-8" - update-locale LC_ALL="en_US.UTF-8" - fi - - export LC_CTYPE=en_US.UTF-8 - export LC_ALL=en_US.UTF-8 - #need to set lang to address some pip module installation issue. - - if [[ $DEV == "ON" ]]; then - #install dev branch - wget https://raw.githubusercontent.com/usmannasir/cyberpanel/$BRANCH_NAME/requirments.txt -O /usr/local/requirments.txt - virtualenv -p /usr/bin/python3 /usr/local/CyberPanel - - if [[ $UBUNTU_20 == "False" ]]; then - source /usr/local/CyberPanel/bin/activate - pip install -r /usr/local/requirments.txt - check_return - else - . /usr/local/CyberPanel/bin/activate - pip install -r /usr/local/requirments.txt - check_return - fi - fi - - if [ -f requirements.txt ] && [ -d cyberpanel ]; then - rm -rf cyberpanel - rm -f requirements.txt - fi - - git clone https://${GIT_URL} - cd cyberpanel - git checkout $BRANCH_NAME - check_return - cd - - cp -r cyberpanel /usr/local/cyberpanel - cd cyberpanel/install - - curl https://cyberpanel.sh/?version +Post_Install_Addon_Mecached_LSMCD() { +if [[ $Server_OS = "CentOS" ]]; then + yum groupinstall "Development Tools" -y + yum install autoconf automake zlib-devel openssl-devel expat-devel pcre-devel libmemcached-devel cyrus-sasl* -y + wget -O lsmcd-master.zip https://cyberpanel.sh/codeload.github.com/litespeedtech/lsmcd/zip/master + unzip lsmcd-master.zip + Current_Dir=$(pwd) + cd "$Current_Dir/lsmcd-master" || exit + ./fixtimestamp.sh + ./configure CFLAGS=" -O3" CXXFLAGS=" -O3" + make + make install + systemctl enable lsmcd + systemctl start lsmcd + cd "$Current_Dir" || exit +else + DEBIAN_FRONTEND=noninteractive apt install build-essential zlib1g-dev libexpat1-dev openssl libssl-dev libsasl2-dev libpcre3-dev git -y + wget -O lsmcd-master.zip https://cyberpanel.sh/codeload.github.com/litespeedtech/lsmcd/zip/master + unzip lsmcd-master.zip + Current_Dir=$(pwd) + cd "$Current_Dir/lsmcd-master" || exit + ./fixtimestamp.sh + ./configure CFLAGS=" -O3" CXXFLAGS=" -O3" + make + make install + cd "$Current_Dir" || exit + systemctl enable lsmcd + systemctl start lsmcd +fi } -regenerate_cert() { - cat </root/cyberpanel/cert_conf +Post_Install_Addon_Memcached() { +if [[ $Server_OS = "CentOS" ]]; then + yum install -y lsphp??-memcached lsphp??-pecl-memcached + if [[ $Total_RAM -eq "2048" ]] || [[ $Total_RAM -gt "2048" ]]; then + Post_Install_Addon_Mecached_LSMCD + else + yum install -y memcached + sed -i 's|OPTIONS=""|OPTIONS="-l 127.0.0.1 -U 0"|g' /etc/sysconfig/memcached + #turn off UDP and bind to 127.0.0.1 only + systemctl enable memcached + systemctl start memcached + fi +fi +if [[ $Server_OS = "Ubuntu" ]]; then + DEBIAN_FRONTEND=noninteractive apt install -y "lsphp*-memcached" + + if [[ "$Total_RAM" -eq "2048" ]] || [[ "$Total_RAM" -gt "2048" ]]; then + Post_Install_Addon_Mecached_LSMCD + else + DEBIAN_FRONTEND=noninteractive apt install -y memcached + systemctl enable memcached + systemctl start memcached + fi +fi + +if pgrep "lsmcd" ; then + echo -e "\n\nLiteSpeed Memcached installed and running..." +fi + +if pgrep "memcached" ; then + echo -e "\n\nMemcached installed and running..." +fi +} + +Post_Install_Addon_Redis() { +if [[ "$Server_OS" = "CentOS" ]]; then + if [[ "$Server_OS_Version" = "8" ]]; then + yum install -y lsphp??-redis redis + else + yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm + yum-config-manager --disable remi + yum-config-manager --disable remi-safe + yum -y --enablerepo=remi install redis + fi +fi + +if [[ $Server_OS = "Ubuntu" ]]; then + DEBIAN_FRONTEND=noninteractive apt install -y "lsphp*-redis" redis +fi + +if ifconfig -a | grep inet6; then + echo -e "\nIPv6 detected...\n" +else + sed -i 's|bind 127.0.0.1 ::1|bind 127.0.0.1|g' /etc/redis/redis.conf + echo -e "\n no IPv6 detected..." +fi + +if [[ $Server_OS = "Ubuntu" ]]; then + systemctl stop redis-server + rm -f /var/run/redis/redis-server.pid + systemctl enable redis-server + systemctl start redis-server +else + systemctl enable redis + systemctl start redis +fi + +if pgrep "redis" ; then + echo -e "\n\nRedis installed and running..." +fi +} + +Post_Install_PHP_Session_Setup() { +echo -e "\nSetting up PHP session storage path...\n" +wget -O /root/php_session_script.sh "${Git_Content_URL}/stable/CPScripts/setup_php_sessions.sh" +chmod +x /root/php_session_script.sh +bash /root/php_session_script.sh +rm -f /root/php_session_script.sh +Debug_Log2 "Setting up PHP session conf..." +} + +Post_Install_PHP_TimezoneDB() { +Current_Dir="$(pwd)" +rm -f /usr/local/lsws/cyberpanel-tmp +mkdir /usr/local/lsws/cyberpanel-tmp +cd /usr/local/lsws/cyberpanel-tmp || exit +wget -O timezonedb.tgz https://cyberpanel.sh/pecl.php.net/get/timezonedb +tar xzvf timezonedb.tgz +cd timezonedb-* || exit + +if [[ "$Server_OS" = "Ubuntu" ]] ; then + DEBIAN_FRONTEND=noninteractive apt install libmagickwand-dev pkg-config build-essential -y + DEBIAN_FRONTEND=noninteractive apt install -y lsphp*-dev +else + yum remove -y lsphp??-mysql + yum install -y lsphp??-mysqlnd + yum install -y lsphp??-devel make gcc glibc-devel libmemcached-devel zlib-devel +fi + +for PHP_Version in /usr/local/lsws/lsphp?? ; + do + PHP_INI_Path=$(find "$PHP_Version" -name php.ini) + + if [[ "$Server_OS" = "CentOS" ]]; then + if [[ ! -d "${PHP_Version}/tmp" ]]; then + mkdir "${PHP_Version}/tmp" + fi + "${PHP_Version}"/bin/pecl channel-update pecl.php.net + "${PHP_Version}"/bin/pear config-set temp_dir "${PHP_Version}/tmp" + "${PHP_Version}"/bin/phpize + ./configure --with-php-config="${PHP_Version}"/bin/php-config + make + make install + echo "extension=timezonedb.so" > "${PHP_Version}/etc/php.d/20-timezone.ini" + make clean + sed -i 's|expose_php = On|expose_php = Off|g' "$PHP_INI_Path" + sed -i 's|mail.add_x_header = On|mail.add_x_header = Off|g' "$PHP_INI_Path" + else + "${PHP_Version}"/bin/phpize + ./configure --with-php-config="${PHP_Version}"/bin/php-config + make + make install + echo "extension=timezonedb.so" > "/usr/local/lsws/${PHP_Version: 16:7}/etc/php/${PHP_Version: 21:1}.${PHP_Version: 22:1}/mods-available/20-timezone.ini" + make clean + sed -i 's|expose_php = On|expose_php = Off|g' "$PHP_INI_Path" + sed -i 's|mail.add_x_header = On|mail.add_x_header = Off|g' "$PHP_INI_Path" + fi + done +rm -rf /usr/local/lsws/cyberpanel-tmp +cd "$Current_Dir" || exit +Debug_Log2 "Installing timezoneDB..." +} + +Post_Install_Regenerate_Webadmin_Console_Passwd() { +if [[ "$Server_Edition" = "OLS" ]]; then + PHP_Command="admin_php" +else + PHP_Command="admin_php5" +fi + +Webadmin_Pass=$( + head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 + echo '' + ) + +Encrypt_string=$(/usr/local/lsws/admin/fcgi-bin/${PHP_Command} /usr/local/lsws/admin/misc/htpasswd.php "${Webadmin_Pass}") +echo "" >/usr/local/lsws/admin/conf/htpasswd +echo "admin:$Encrypt_string" >/usr/local/lsws/admin/conf/htpasswd +echo "${Webadmin_Pass}" >/etc/cyberpanel/webadmin_passwd +chmod 600 /etc/cyberpanel/webadmin_passwd +} + +Post_Install_Setup_Watchdog() { +if [[ "$Watchdog" = "On" ]]; then + wget -O /etc/cyberpanel/watchdog.sh "${Git_Content_URL}/stable/CPScripts/watchdog.sh" + chmod 700 /etc/cyberpanel/watchdog.sh + ln -s /etc/cyberpanel/watchdog.sh /usr/local/bin/watchdog + #shellcheck disable=SC2009 + pid=$(ps aux | grep "watchdog lsws" | grep -v grep | awk '{print $2}') + if [[ $pid = "" ]]; then + nohup watchdog lsws >/dev/null 2>&1 & + fi + echo -e "Checking MariaDB ..." + #shellcheck disable=SC2009 + pid=$(ps aux | grep "watchdog mariadb" | grep -v grep | awk '{print $2}') + if [[ $pid = "" ]]; then + nohup watchdog mariadb >/dev/null 2>&1 & + fi + + if [[ "$Server_OS" = "CentOS" ]]; then + echo "nohup watchdog lsws > /dev/null 2>&1 & +nohup watchdog mariadb > /dev/null 2>&1 &" >>/etc/rc.d/rc.local + else + echo "nohup watchdog lsws > /dev/null 2>&1 & +nohup watchdog mariadb > /dev/null 2>&1 &" >>/etc/rc.local + fi + echo -e "\nSetting up WatchDog..." +fi +} + +Post_Install_Setup_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 +} + +Post_Install_Display_Final_Info() { +Elapsed_Time="$((Time_Count / 3600)) hrs $(((SECONDS / 60) % 60)) min $((Time_Count % 60)) sec" +echo "###################################################################" +echo " CyberPanel Successfully Installed " +echo " " +echo " Current Disk usage : $(df -h | awk '$NF=="/"{printf "%d/%dGB (%s)\n", $3,$2,$5}') " +echo " " +echo " Current RAM usage : $(free -m | awk 'NR==2{printf "%s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }') " +echo " " +echo " Installation time : $Elapsed_Time " +echo " " +echo " Visit: https://$Server_IP:8090 " +echo " Panel username: admin " +if [[ "$Custom_Pass" = "True" ]]; then +echo " Panel password: ***** " +else +echo " Panel password: $Admin_Pass " +fi +echo " WebAdmin console username: admin " +echo " WebAdmin console password: $Webadmin_Pass " +echo " " +echo -e " Run \e[31mcyberpanel help\e[39m to get FAQ info" +echo -e " Run \e[31mcyberpanel upgrade\e[39m to upgrade it to latest version." +echo -e " Run \e[31mcyberpanel utility\e[39m to access some handy tools ." +echo " " +echo " Website : https://www.cyberpanel.net " +echo " Forums : https://forums.cyberpanel.net " +echo " Wikipage: https://docs.cyberpanel.net " +echo " " +echo -e " Enjoy your accelerated Internet by " +echo -e " CyberPanel & $Word " +echo "###################################################################" + +if [[ "$Server_Provider" != "Undefined" ]]; then + echo -e "\033[0;32m$Server_Provider\033[39m detected..." + echo -e "This provider has a \e[31mnetwork-level firewall\033[39m" +else + echo -e "If your provider has a \e[31mnetwork-level firewall\033[39m" +fi +echo -e "Please make sure you have opened following port for both in/out:" +echo -e "\033[0;32mTCP: 8090\033[39m for CyberPanel" +echo -e "\033[0;32mTCP: 80\033[39m, \033[0;32mTCP: 443\033[39m and \033[0;32mUDP: 443\033[39m for webserver" +echo -e "\033[0;32mTCP: 21\033[39m and \033[0;32mTCP: 40110-40210\033[39m for FTP" +echo -e "\033[0;32mTCP: 25\033[39m, \033[0;32mTCP: 587\033[39m, \033[0;32mTCP: 465\033[39m, \033[0;32mTCP: 110\033[39m, \033[0;32mTCP: 143\033[39m and \033[0;32mTCP: 993\033[39m for mail service" +echo -e "\033[0;32mTCP: 53\033[39m and \033[0;32mUDP: 53\033[39m for DNS service" + +if ! timeout 3 telnet mx.zoho.com 25 | grep "Escape" >/dev/null 2>&1; then + echo -e "Your provider seems \e[31mblocked\033[39m port 25 , E-mail sending may \e[31mnot\033[39m work properly." +fi + +if [[ "$Silent" != "On" ]]; then + printf "%s" "Would you like to restart your server now? [y/N]: " + read -r Tmp_Input + + if [[ "${Tmp_Input^^}" = *Y* ]] ; then + reboot + fi +fi +Debug_Log2 "Completed [200]" +} + + +Post_Install_Regenerate_Cert() { +cat </root/cyberpanel/cert_conf [req] prompt=no distinguished_name=cyberpanel @@ -1255,472 +1603,223 @@ dnQualifier = CyberPanel [server_exts] extendedKeyUsage = 1.3.6.1.5.5.7.3.1 EOF - openssl req -x509 -config /root/cyberpanel/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 +openssl req -x509 -config /root/cyberpanel/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 - if [[ $VERSION == "OLS" ]]; 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 /root/cyberpanel/cert_conf -extensions 'server_exts' -nodes -days 820 -newkey rsa:2048 -keyout $key_path -out $cert_path - rm -f /root/cyberpanel/cert_conf +if [[ "$Server_Edition" = "OLS" ]]; 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 /root/cyberpanel/cert_conf -extensions 'server_exts' -nodes -days 820 -newkey rsa:2048 -keyout "$Key_Path" -out "$Cert_Path" +rm -f /root/cyberpanel/cert_conf } -after_install() { - echo 'Finalization..,80' >>/var/log/installLogs.txt - if [ ! -d "/var/lib/php" ]; then - mkdir /var/lib/php +Post_Install_Required_Components() { +Debug_Log2 "Finalization..,80" +virtualenv -p /usr/bin/python3 /usr/local/CyberCP + +if [[ "$Server_OS" = "Ubuntu" ]] && [[ "$Server_OS_Version" = "20" ]] ; then + # shellcheck disable=SC1091 + . /usr/local/CyberCP/bin/activate + Check_Return +else + # shellcheck disable=SC1091 + source /usr/local/CyberCP/bin/activate + Check_Return + +fi + +Retry_Command "pip install --default-timeout=3600 -r /usr/local/requirments.txt" + Check_Return "requirments.txt" "no_exit" + +chown -R cyberpanel:cyberpanel /usr/local/CyberCP/lib +chown -R cyberpanel:cyberpanel /usr/local/CyberCP/lib64 || true +} + +Pre_Install_Setup_Git_URL() { +if [[ $Server_Country != "CN" ]] ; then + Git_User="usmannasir" + Git_Content_URL="https://raw.githubusercontent.com/${Git_User}/cyberpanel" + Git_Clone_URL="https://github.com/${Git_User}/cyberpanel.git" +else + Git_User="qtwrk" + Git_Content_URL="https://gitee.com/${Git_User}/cyberpanel/raw" + Git_Clone_URL="https://gitee.com/${Git_User}/cyberpanel.git" +fi + +if [[ "$Debug" = "On" ]] ; then + Debug_Log "Git_URL" "$Git_Content_URL" +fi +} + +Post_Install_Tweak() { +if [[ -d /etc/pure-ftpd/conf ]]; then + echo "yes" >/etc/pure-ftpd/conf/ChrootEveryone + systemctl restart pure-ftpd-mysql +fi + +if [[ -f /etc/pure-ftpd/pure-ftpd.conf ]]; then + sed -i 's|NoAnonymous no|NoAnonymous yes|g' /etc/pure-ftpd/pure-ftpd.conf +fi + +sed -i "s|lsws-5.3.8|lsws-$LSWS_Stable_Version|g" /usr/local/CyberCP/serverStatus/serverStatusUtil.py +sed -i "s|lsws-5.4.2|lsws-$LSWS_Stable_Version|g" /usr/local/CyberCP/serverStatus/serverStatusUtil.py +sed -i "s|lsws-5.3.5|lsws-$LSWS_Stable_Version|g" /usr/local/CyberCP/serverStatus/serverStatusUtil.py + + +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 + +rm -rf /etc/profile.d/cyberpanel* +curl --silent -o /etc/profile.d/cyberpanel.sh https://cyberpanel.sh/?banner 2>/dev/null +chmod 700 /etc/profile.d/cyberpanel.sh +echo "$Admin_Pass" > /etc/cyberpanel/adminPass +/usr/local/CyberPanel/bin/python /usr/local/CyberCP/plogical/adminPass.py --password "$Admin_Pass" +mkdir -p /etc/opendkim + +echo '/usr/local/CyberPanel/bin/python /usr/local/CyberCP/plogical/adminPass.py --password $@' > /usr/bin/adminPass +echo "systemctl restart lscpd" >> /usr/bin/adminPass +chmod 700 /usr/bin/adminPass + +if [[ "$Server_OS" = "CentOS" ]] ; then +#all centos7/8 post change goes here + + 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 + sed -i 's|/usr/local/lsws/bin/lswsctrl restart|systemctl restart lsws|g' /var/spool/cron/root + + if [[ "$Server_OS_Version" = "7" ]] ; then + #all centos 7 specific post change goes here + : fi - if [ ! -d "/var/lib/php/session" ]; then - mkdir /var/lib/php/session + if [[ "$Server_OS_Version" = "8" ]] ; then + #all centos 8 specific post change goes here + : fi - chmod 1733 /var/lib/php/session +elif [[ "$Server_OS" = "Ubuntu" ]] ; then +#all ubuntu18/20 post change goes here - if grep "\[ERROR\] We are not able to run ./install.sh return code: 1. Fatal error, see /var/log/installLogs.txt for full details" /var/log/installLogs.txt >/dev/null; then - cd ${DIR}/cyberpanel/install/lsws-* - ./install.sh - echo -e "\n\n\nIt seems LiteSpeed Enterprise has failed to install, please check your license key is valid" - echo -e "\nIf this license key has been used before, you may need to go to store to release it first." - echo 'It seems LiteSpeed Enterprise has failed to install, please check your license key is valid. If this license key has been used before, you may need to go to store to release it first. [404]' >>/var/log/installLogs.txt - exit + sed -i 's|/usr/local/lsws/bin/lswsctrl restart|systemctl restart lsws|g' /var/spool/cron/crontabs/root + + if [[ ! -f /usr/sbin/ipset ]] ; then + ln -s /sbin/ipset /usr/sbin/ipset fi - if grep "CyberPanel installation successfully completed" /var/log/installLogs.txt >/dev/null; then - - if [[ $DEV == "ON" ]]; then - - if [[ $PROVIDER == "Alibaba Cloud" ]] && [[ $SERVER_OS == "Ubuntu" ]]; then - cat </root/.config/pip/pip.conf -[global] -index-url = https://pypi.python.org/simple/ -[install] -trusted-host=pypi.python.org -EOF - fi - - fi - - virtualenv -p /usr/bin/python3 /usr/local/CyberCP - - if [[ $UBUNTU_20 == "False" ]]; then - source /usr/local/CyberCP/bin/activate - check_return - pip install -r /usr/local/requirments.txt - check_return - else - . /usr/local/CyberCP/bin/activate - check_return - pip install -r /usr/local/requirments.txt - check_return - fi - ## Some permissions on libs - - chown -R cyberpanel:cyberpanel /usr/local/CyberCP/lib - chown -R cyberpanel:cyberpanel /usr/local/CyberCP/lib64 - systemctl restart lscpd - - for version in $(ls /usr/local/lsws | grep lsphp); do - php_ini=$(find /usr/local/lsws/$version/ -name php.ini) - version2=${version:5:2} - version2=$(awk "BEGIN { print "${version2}/10" }") - if [[ $version2 == "7" ]]; then - version2="7.0" - fi - if [[ $SERVER_OS == "CentOS" ]]; then - yum remove -y $version-mysql - yum install -y $version-mysqlnd - yum install -y $version-devel make gcc glibc-devel libmemcached-devel zlib-devel - if [[ ! -d /usr/local/lsws/$version/tmp ]]; then - mkdir /usr/local/lsws/$version/tmp - fi - /usr/local/lsws/${version}/bin/pecl channel-update pecl.php.net - /usr/local/lsws/${version}/bin/pear config-set temp_dir /usr/local/lsws/${version}/tmp - /usr/local/lsws/${version}/bin/pecl install timezonedb - echo "extension=timezonedb.so" >/usr/local/lsws/${version}/etc/php.d/20-timezone.ini - chmod 755 /usr/local/lsws/${version}/lib64/php/modules/timezonedb.so - sed -i 's|expose_php = On|expose_php = Off|g' $php_ini - sed -i 's|mail.add_x_header = On|mail.add_x_header = Off|g' $php_ini - sed -i 's|;session.save_path = "/tmp"|session.save_path = "/var/lib/php/session"|g' $php_ini - fi - - if [[ $SERVER_OS == "Ubuntu" ]]; then - if [[ ! -d /usr/local/lsws/cyberpanel-tmp ]]; then - if [[ -d /etc/pure-ftpd/conf ]]; then - echo "yes" >/etc/pure-ftpd/conf/ChrootEveryone - systemctl restart pure-ftpd-mysql - fi - DEBIAN_FRONTEND=noninteractive apt install libmagickwand-dev pkg-config build-essential -y - mkdir /usr/local/lsws/cyberpanel-tmp - cd /usr/local/lsws/cyberpanel-tmp - wget -O timezonedb.tgz https://pecl.php.net/get/timezonedb - tar xzvf timezonedb.tgz - cd timezonedb-* - fi - /usr/local/lsws/${version}/bin/phpize - ./configure --with-php-config=/usr/local/lsws/${version}/bin/php-config${version2} - make - make install - echo "extension=timezonedb.so" >/usr/local/lsws/${version}/etc/php/${version2}/mods-available/20-timezone.ini - make clean - fi - done - - rm -rf /etc/profile.d/cyberpanel* - curl --silent -o /etc/profile.d/cyberpanel.sh https://cyberpanel.sh/?banner 2>/dev/null - chmod +x /etc/profile.d/cyberpanel.sh - RAM2=$(free -m | awk 'NR==2{printf "%s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }') - DISK2=$(df -h | awk '$NF=="/"{printf "%d/%dGB (%s)\n", $3,$2,$5}') - ELAPSED="$((SECONDS / 3600)) hrs $(((SECONDS / 60) % 60)) min $((SECONDS % 60)) sec" - MYSQLPASSWD=$(cat /etc/cyberpanel/mysqlPassword) - echo "$ADMIN_PASS" >/etc/cyberpanel/adminPass - /usr/local/CyberPanel/bin/python /usr/local/CyberCP/plogical/adminPass.py --password $ADMIN_PASS - mkdir -p /etc/opendkim - - regenerate_cert - - systemctl restart lscpd - systemctl restart lsws - echo '/usr/local/CyberPanel/bin/python /usr/local/CyberCP/plogical/adminPass.py --password $@' >/usr/bin/adminPass - echo "systemctl restart lscpd" >>/usr/bin/adminPass - chmod 700 /usr/bin/adminPass - if [[ $VERSION == "OLS" ]]; then - WORD="OpenLiteSpeed" - # sed -i 's|maxConnections 10000|maxConnections 100000|g' /usr/local/lsws/conf/httpd_config.conf - # OLS_LATEST=$(curl https://openlitespeed.org/packages/release) - # wget https://openlitespeed.org/packages/openlitespeed-$OLS_LATEST.tgz - # tar xzvf openlitespeed-$OLS_LATEST.tgz - # cd openlitespeed - # ./install.sh - systemctl stop lsws - systemctl start lsws - # rm -f openlitespeed-$OLS_LATEST.tgz - # rm -rf openlitespeed - # cd .. - fi - if [[ $VERSION == "ENT" ]]; then - WORD="LiteSpeed Enterprise" - if [[ $SERVER_COUNTRY != "CN" ]]; then - /usr/local/lsws/admin/misc/lsup.sh -f -v $LSWS_STABLE_VER - fi - fi - - systemctl status lsws >/dev/null 2>&1 - if [[ $? == "0" ]]; then - echo "LSWS service is running..." - else - systemctl stop lsws - systemctl start lsws - fi - - webadmin_passwd - - watchdog_setup - - install_utility - - if [[ ! -f /usr/sbin/ipset ]] && [[ $SERVER_OS == "Ubuntu" ]]; then - ln -s /sbin/ipset /usr/sbin/ipset - fi - - if [[ ! -f /usr/local/lsws/lsphp74/lib64/php/modules/zip.so ]] && [[ $SERVER_OS == "CentOS" ]] && [[ $CENTOS_8 == "False" ]]; then - yum list installed libzip-devel - if [[ $? == "0" ]]; then - yum remove -y libzip-devel - fi - yum install -y https://$DOWNLOAD_SERVER/misc/libzip-0.11.2-6.el7.psychotic.x86_64.rpm - yum install -y https://$DOWNLOAD_SERVER/misc/libzip-devel-0.11.2-6.el7.psychotic.x86_64.rpm - /usr/local/lsws/lsphp74/bin/pecl install zip - 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 - fi - #fix the lsphp74-zip missing issue. - - if [[ $SERVER_OS == "CentOS" ]]; then - 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 - fi - #fix php.ini & issue - - if [[ $UBUNTU_20 == "True" ]]; then - cp /usr/local/lsws/lsphp73/bin/php /usr/bin - fi - - #clear - echo "###################################################################" - echo " CyberPanel Successfully Installed " - echo " " - echo " Current Disk usage : $DISK2 " - echo " " - echo " Current RAM usage : $RAM2 " - echo " " - echo " Installation time : $ELAPSED " - echo " " - echo " Visit: https://$SERVER_IP:8090 " - echo " Panel username: admin " - if [[ $CUSTOM_PASS == "True" ]]; then - echo " Panel password: ***** " - elif [[ $CUSTOM_PASS == "False" ]]; then - echo " Panel password: $ADMIN_PASS " - fi - echo " WebAdmin console username: admin " - echo " WebAdmin console password: $WEBADMIN_PASS " - echo " " - echo -e " Run \e[31mcyberpanel help\e[39m to get FAQ info" - echo -e " Run \e[31mcyberpanel upgrade\e[39m to upgrade it to latest version." - echo -e " Run \e[31mcyberpanel utility\e[39m to access some handy tools ." - echo " " - echo " Website : https://www.cyberpanel.net " - echo " Forums : https://forums.cyberpanel.net " - echo " Wikipage: https://docs.cyberpanel.net " - echo " " - echo -e " Enjoy your accelerated Internet by " - echo -e " CyberPanel & $WORD " - echo "###################################################################" - if [[ $PROVIDER != "undefined" ]]; then - echo -e "\033[0;32m$PROVIDER\033[39m detected..." - echo -e "This provider has a \e[31mnetwork-level firewall\033[39m" - else - echo -e "If your provider has a \e[31mnetwork-level firewall\033[39m" - fi - echo -e "Please make sure you have opened following port for both in/out:" - echo -e "\033[0;32mTCP: 8090\033[39m for CyberPanel" - echo -e "\033[0;32mTCP: 80\033[39m, \033[0;32mTCP: 443\033[39m and \033[0;32mUDP: 443\033[39m for webserver" - echo -e "\033[0;32mTCP: 21\033[39m and \033[0;32mTCP: 40110-40210\033[39m for FTP" - echo -e "\033[0;32mTCP: 25\033[39m, \033[0;32mTCP: 587\033[39m, \033[0;32mTCP: 465\033[39m, \033[0;32mTCP: 110\033[39m, \033[0;32mTCP: 143\033[39m and \033[0;32mTCP: 993\033[39m for mail service" - echo -e "\033[0;32mTCP: 53\033[39m and \033[0;32mUDP: 53\033[39m for DNS service" - - if ! timeout 3 telnet mx.zoho.com 25 | grep "Escape" >/dev/null 2>&1; then - echo -e "Your provider seems \e[31mblocked\033[39m port 25 , E-mail sending may \e[31mnot\033[39m work properly." - fi - - if [[ $SERVER_COUNTRY == CN ]]; then - if [[ $PROVIDER == "Tencent Cloud" ]]; then - if [[ $SERVER_OS == "Ubuntu" ]]; then - rm -f /etc/apt/sources.list - mv /etc/apt/sources.list-backup /etc/apt/sources.list - echo >"nameserver 127.0.0.53 -options edns0" /run/systemd/resolve/stub-resolv.conf - echo >"nameserver 127.0.0.53 -options edns0" /etc/resolv.conf - apt update - #revert the previous change on tencent cloud repo. - fi - fi - if [[ $VERSION == "ENT" ]]; then - sed -i 's|https://www.litespeedtech.com/packages/5.0/lsws-5.3.5-ent-x86_64-linux.tar.gz|https://cyberpanel.sh/packages/5.0/lsws-5.3.5-ent-x86_64-linux.tar.gz|g' /usr/local/CyberCP/install/installCyberPanel.py - sed -i 's|https://www.litespeedtech.com/packages/5.0/lsws-5.3.8-ent-x86_64-linux.tar.gz|https://cyberpanel.sh/packages/5.0/lsws-5.3.8-ent-x86_64-linux.tar.gz|g' /usr/local/CyberCP/serverStatus/serverStatusUtil.py - sed -i 's|https://www.litespeedtech.com/packages/5.0/lsws-5.3.8-ent-x86_64-linux.tar.gz|https://'$DOWNLOAD_SERVER'/litespeed/lsws-'$LSWS_STABLE_VER'-ent-x86_64-linux.tar.gz|g' /usr/local/CyberCP/serverStatus/serverStatusUtil.py - echo -e "If you have install LiteSpeed Enterprise, please run \e[31m/usr/local/lsws/admin/misc/lsup.sh\033[39m to update it to latest." - fi - fi - - sed -i 's|lsws-5.3.8|lsws-'$LSWS_STABLE_VER'|g' /usr/local/CyberCP/serverStatus/serverStatusUtil.py - sed -i 's|lsws-5.4.2|lsws-'$LSWS_STABLE_VER'|g' /usr/local/CyberCP/serverStatus/serverStatusUtil.py - sed -i 's|lsws-5.3.5|lsws-'$LSWS_STABLE_VER'|g' /usr/local/CyberCP/serverStatus/serverStatusUtil.py - - if [[ -f /etc/pure-ftpd/pure-ftpd.conf ]]; then - sed -i 's|NoAnonymous no|NoAnonymous yes|g' /etc/pure-ftpd/pure-ftpd.conf - fi - - if [[ $SILENT != "ON" ]]; then - printf "%s" "Would you like to restart your server now? [y/N]: " - read TMP_YN - - if [[ $TMP_YN == "N" ]] || [[ $TMP_YN == "n" ]] || [[ -z $TMP_YN ]]; then - : - else - reboot - exit - fi - - exit - fi - #replace URL for CN - - else - - echo "something went wrong..." - echo 'something went wrong... [404]' >>/var/log/installLogs.txt - - exit + if [[ "$Server_OS_Version" = "18" ]] ; then + #all ubuntu 18 specific post change goes here + : fi + if [[ "$Server_OS_Version" = "20" ]] ; then + #all ubuntu 20 specific post change goes here + cp /usr/local/lsws/lsphp73/bin/php /usr/bin + fi + +fi + + +if [[ "$Server_Edition" = "OLS" ]]; then + Word="OpenLiteSpeed" +else + Word="LiteSpeed Enterprise" + sed -i 's|Include /usr/local/lsws/conf/rules.conf||g' /usr/local/lsws/conf/modsec.conf +fi + +systemctl restart lscpd >/dev/null 2>&1 +/usr/local/lsws/bin/lswsctrl stop >/dev/null 2>&1 +systemctl stop lsws >/dev/null 2>&1 +systemctl start lsws >/dev/null 2>&1 +echo -e "\nFinalizing...\n" +echo -e "Cleaning up...\n" +rm -rf /root/cyberpanel +rm -f /tmp/cyberpanel_debug.log +rm -f /tmp/lsws_latest + +if [[ "$Server_Country" = "CN" ]] ; then +Post_Install_CN_Replacement +fi + } -argument_mode() { - DEV="ON" - #default to python3 branch. - KEY_SIZE=${#VERSION} - TMP=$(echo $VERSION | cut -c5) - TMP2=$(echo $VERSION | cut -c10) - TMP3=$(echo $VERSION | cut -c15) - if [[ $VERSION == "OLS" || $VERSION == "ols" ]]; then - VERSION="OLS" - echo -e "\nSet to OpenLiteSpeed..." - elif [[ $VERSION == "Trial" ]] || [[ $VERSION == "TRIAL" ]] || [[ $VERSION == "trial" ]]; then - VERSION="ENT" - LICENSE_KEY="TRIAL" - echo -e "\nLiteSpeed Enterprise trial license set..." - elif [[ $TMP == "-" ]] && [[ $TMP2 == "-" ]] && [[ $TMP3 == "-" ]] && [[ $KEY_SIZE == "19" ]]; then - LICENSE_KEY=$VERSION - VERSION="ENT" - echo -e "\nLiteSpeed Enterprise license key set..." - else - echo -e "\nCan not recognize the input value \e[31m$VERSION\e[39m " - echo -e "\nPlease verify the input value..." - echo -e "\nPlease run with \e[31m-h\e[39m or \e[31m--help\e[39m for more detail." - exit - fi - - if [[ $ADMIN_PASS == "d" ]]; then - ADMIN_PASS="1234567" - echo -e "\nSet to default password..." - echo -e "\nAdmin password will be set to \e[31m$ADMIN_PASS\e[39m" - elif [[ $ADMIN_PASS == "r" ]]; then - ADMIN_PASS=$( - head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 - echo '' - ) - echo -e "\nSet to random-generated password..." - echo -e "\nAdmin password will be set to \e[31m$ADMIN_PASS\e[39m" - echo $ADMIN_PASS - else - echo -e "\nAdmin password will be set to \e[31m$ADMIN_PASS\e[39m" - fi +Post_Install_CN_Replacement() { +sed -i 's|wp core download|wp core download https://cyberpanel.sh/wordpress.org/latest.tar.gz|g' /usr/local/CyberCP/plogical/applicationInstaller.py +sed -i 's|https://raw.githubusercontent.com/|https://cyberpanel.sh/raw.githubusercontent.com/|g' /usr/local/CyberCP/plogical/applicationInstaller.py +sed -i 's|wp plugin install litespeed-cache|wp plugin install https://cyberpanel.sh/downloads.wordpress.org/plugin/litespeed-cache.zip|g' /usr/local/CyberCP/plogical/applicationInstaller.py } -initialize() { - if [ $# -eq 0 ]; then - echo -e "\nInitializing...\n" - else - if [[ $1 == "help" ]]; then - show_help - exit - elif [[ $1 == "dev" ]]; then - DEV="ON" - DEV_ARG="ON" - SILENT="OFF" - elif [[ $1 == "default" ]]; then - echo -e "\nThis will start default installation...\n" - SILENT="ON" - POSTFIX_VARIABLE="ON" - POWERDNS_VARIABLE="ON" - PUREFTPD_VARIABLE="ON" - VERSION="OLS" - ADMIN_PASS="1234567" - MEMCACHED="ON" - REDIS="ON" - else - while [ ! -z "${1}" ]; do - case $1 in - -v | --version) - shift - if [ "${1}" = '' ]; then - show_help - exit - else - VERSION="${1}" - SILENT="ON" - fi - ;; - -p | --password) - shift - if [[ ${1} == '' ]]; then - ADMIN_PASS="1234567" - elif [[ ${1} == 'r' ]] || [[ $1 == 'random' ]]; then - ADMIN_PASS=$( - head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 - echo '' - ) - elif [[ ${1} == "d" ]]; then - ADMIN_PASS="1234567" - else - if [ ${#1} -lt 8 ]; then - echo -e "\nPassword lenth less than 8 digital, please choose a more complicated password.\n" - exit - fi - ADMIN_PASS="${1}" - fi - ;; - -a | --addons) - MEMCACHED="ON" - REDIS="ON" - ;; - -m | --minimal) - POSTFIX_VARIABLE="OFF" - POWERDNS_VARIABLE="OFF" - PUREFTPD_VARIABLE="OFF" - ;; - -h | --help) - show_help - exit - ;; - *) - echo "unknown argument..." - show_help - exit - ;; - esac - shift - done - fi - fi +echo -e "\nInitializing...\n" - SERVER_IP=$(curl --silent --max-time 10 -4 https://cyberpanel.sh/?ip) - if [[ $SERVER_IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo -e "Valid IP detected..." - else - echo -e "Can not detect IP, exit..." - exit - fi - SERVER_COUNTRY="unknow" - SERVER_COUNTRY=$(curl --silent --max-time 5 https://cyberpanel.sh/?country) - if [[ ${#SERVER_COUNTRY} == "2" ]] || [[ ${#SERVER_COUNTRY} == "6" ]]; then - echo -e "\nChecking server..." - else - echo -e "\nChecking server..." - SERVER_COUNTRY="unknow" - fi - #SERVER_COUNTRY="CN" - #test string - if [[ $SERVER_COUNTRY == "CN" ]]; then - DOWNLOAD_SERVER="cyberpanel.sh" - GIT_URL="gitee.com/qtwrk/cyberpanel" - GIT_CONTENT_URL="gitee.com/qtwrk/cyberpanel/raw" - else - DOWNLOAD_SERVER="cdn.cyberpanel.sh" - fi +if [[ "$*" = *"--debug"* ]] ; then + Debug="On" + rm -f /tmp/cyberpanel_debug.log + echo -e "$(date)" > /tmp/cyberpanel_debug.log +fi - echo 'Initialization completed..,2' >/var/log/installLogs.txt -} +Set_Default_Variables -begin_install() { - set_git_repos_and_branch - initialize "$@" - check_OS - check_virtualization - check_root - check_panel - check_process - check_provider - if [[ $SILENT == "ON" ]]; then - argument_mode - else - interactive_mode - fi - SECONDS=0 - install_required - openvz_change - pip_virtualenv - system_tweak - main_install - disable_repos -} +Check_Root -begin_install "$@" +Check_Server_IP "$@" -echo 'Completed [200]' >>/var/log/installLogs.txt \ No newline at end of file +Check_OS + +Check_Virualization + +Check_Panel + +Check_Porcess + +Check_Provider + +Check_Argument "$@" + +if [[ $Silent = "On" ]]; then + Argument_Mode +else + Interactive_Mode +fi + +Time_Count="0" + +Pre_Install_Setup_Repository + +Pre_Install_Setup_Git_URL + +Pre_Install_Required_Components + +Pre_Install_System_Tweak + +Main_Installation +#Python install in here + +if [[ "$Memcached" = "On" ]] ; then + Post_Install_Addon_Memcached +fi + +if [[ "$Redis" = "On" ]] ; then + Post_Install_Addon_Redis +fi + +Post_Install_Required_Components + +Post_Install_PHP_Session_Setup + +Post_Install_PHP_TimezoneDB + +Post_Install_Regenerate_Cert + +Post_Install_Regenerate_Webadmin_Console_Passwd + +Post_Install_Setup_Watchdog + +Post_Install_Setup_Utility + +Post_Install_Tweak + +Post_Install_Display_Final_Info \ No newline at end of file diff --git a/cyberpanel_upgrade.sh b/cyberpanel_upgrade.sh index c6112c55e..83a2bbd7a 100644 --- a/cyberpanel_upgrade.sh +++ b/cyberpanel_upgrade.sh @@ -1,39 +1,219 @@ #!/bin/bash -#CyberPanel Upgrade script +#set -e -o pipefail +#set -x +#set -u + +#CyberPanel installer script for CentOS 7.X, CentOS 8.X, CloudLinux 7.X, Ubuntu 18.04 and Ubuntu 20.04 +#For whoever may edit this script, please follow : +#Please use Pre_Install_xxx() and Post_Install_xxx() if you want to something respectively before or after the panel installation +#and update below accordingly +#Please use variable/functions name as MySomething or My_Something, and please try not to use too-short abbreviation :) +#Please use On/Off, True/False, Yes/No. + +Sudo_Test=$(set) +#for SUDO check + +Set_Default_Variables() { export LC_CTYPE=en_US.UTF-8 -SUDO_TEST=$(set) -SERVER_OS='Undefined' -OUTPUT=$(cat /etc/*release) -MYSQLCurrentVersion=$(systemctl status mysql) -MYSQLPassword=$(cat /etc/cyberpanel/mysqlPassword) -TEMP=$(curl --silent https://cyberpanel.net/version.txt) -BRANCH_NAME=v${TEMP:12:3}.${TEMP:25:1} -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) -UBUNTU_20="False" +echo -e "\nFetching latest data from CyberPanel server...\n" +echo -e "This may take few seconds..." -## +Server_Country="Unknow" +Server_OS="" +Server_OS_Version="" +Server_Provider='Undefined' -if [[ ${#SERVER_COUNTRY} == "2" ]] || [[ ${#SERVER_COUNTRY} == "6" ]]; then - echo -e "\nChecking server..." +Temp_Value=$(curl --silent --max-time 30 -4 https://cyberpanel.net/version.txt) +Panel_Version=${Temp_Value:12:3} +Panel_Build=${Temp_Value:25:1} + +Branch_Name="v${Panel_Version}.${Panel_Build}" +Base_Number="1.9.3" + +Git_User="" +Git_Content_URL="" +Git_Clone_URL="" + +MySQL_Version=$(mysql -V | grep -P '\d+.\d+.\d+' -o) +MySQL_Password=$(cat /etc/cyberpanel/mysqlPassword) + + +#LSWS_Latest_URL="https://cyberpanel.sh/update.litespeedtech.com/ws/latest.php" +#curl --silent --max-time 30 -4 -o /tmp/lsws_latest "$LSWS_Latest_URL" 2>/dev/null +#LSWS_Stable_Line=$(grep "LSWS_STABLE" /tmp/lsws_latest) +#LSWS_Stable_Version=$(expr "$LSWS_Stable_Line" : '.*LSWS_STABLE=\(.*\) BUILD .*') +#grab the LSWS latest stable version. + +Debug_Log2 "Starting Upgrade...1" + +rm -rf /root/cyberpanel_upgrade_tmp +mkdir -p /root/cyberpanel_upgrade_tmp +cd /root/cyberpanel_upgrade_tmp || exit +} + +Debug_Log() { +echo -e "\n${1}=${2}\n" >> /tmp/cyberpanel_debug_upgrade.log +} + +Debug_Log2() { +echo -e "\n${1}" >> /var/log/upgradeLogs.txt +} + +Check_Root() { +echo -e "\nChecking root privileges..." + if echo "$Sudo_Test" | grep SUDO >/dev/null; then + echo -e "\nYou are using SUDO , please run as root user...\n" + 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 installation command again." + exit + fi + + if [[ $(id -u) != 0 ]] >/dev/null; then + echo -e "\nYou must run on root user to install CyberPanel...\n" + echo -e "or run following command: (do NOT miss the quotes)" + echo -e "\e[31msudo su -c \"sh <(curl https://cyberpanel.sh || wget -O - https://cyberpanel.sh)\"\e[39m" + exit 1 + else + echo -e "\nYou are runing as root...\n" + fi +} + +Check_Server_IP() { +echo -e "Checking server location...\n" + +Server_Country=$(curl --silent --max-time 10 -4 https://cyberpanel.sh/?country) +if [[ ${#Server_Country} != "2" ]] ; then + Server_Country="Unknow" +fi + +if [[ "$Debug" = "On" ]] ; then + Debug_Log "Server_Country" "$Server_Country" +fi + +if [[ "$*" = *"--mirror"* ]] ; then + Server_Country="CN" + echo -e "Force to use mirror server due to --mirror argument...\n" +fi + +if [[ "$Server_Country" = *"CN"* ]] ; then + Server_Country="CN" + echo -e "Setting up to use mirror server...\n" +fi +} + +Check_OS() { +if [[ ! -f /etc/os-release ]] ; then + echo -e "Unable to detect the operating system...\n" + exit +fi + +if ! uname -m | grep -q 64 ; then + echo -e "x64 system is required...\n" + exit +fi + +if grep -q -E "CentOS Linux 7|CentOS Linux 8" /etc/os-release ; then + Server_OS="CentOS" +elif grep -q -E "CloudLinux 7|CloudLinux 8" /etc/os-release ; then + Server_OS="CloudLinux" +elif grep -q -E "Ubuntu 18.04|Ubuntu 20.04" /etc/os-release ; then + Server_OS="Ubuntu" else - echo -e "\nChecking server..." - SERVER_COUNTRY="unknow" + echo -e "Unable to detect your system..." + echo -e "\nCyberPanel is supported on Ubuntu 18.04 x86_64, Ubuntu 20.04 x86_64, CentOS 7.x, CentOS 8.x and CloudLinux 7.x...\n" + Debug_Log2 "CyberPanel is supported on Ubuntu 18.04 x86_64, Ubuntu 20.04 x86_64, CentOS 7.x, CentOS 8.x and CloudLinux 7.x... [404]" + exit fi -#SERVER_COUNTRY="CN" -#for test +Server_OS_Version=$(grep VERSION_ID /etc/os-release | awk -F[=,] '{print $2}' | tr -d \" | head -c2) +#to make 20.04 display as 20 -if [[ $SERVER_COUNTRY == "CN" ]]; then - GIT_URL="gitee.com/qtwrk/cyberpanel" - GIT_CONTENT_URL="gitee.com/qtwrk/cyberpanel/raw" +echo -e "System: $Server_OS $Server_OS_Version detected...\n" + +if [[ $Server_OS = "CloudLinux" ]] ; then + Server_OS_Version=$(grep VERSION_ID /etc/os-release | awk -F[=,] '{print $2}' | tr -d \" | cut -c1-1) + Server_OS="CentOS" + #CloudLinux gives version id like 7.8 , 7.9 , so cut it to show first number only + #then treat it as CentOS system. fi -regenerate_cert() { +if [[ "$Debug" = "On" ]] ; then + Debug_Log "Server_OS" "$Server_OS $Server_OS_Version" +fi + +} + +Check_Provider() { +if hash dmidecode >/dev/null 2>&1; then + if [[ "$(dmidecode -s bios-vendor)" = "Google" ]]; then + Server_Provider="Google Cloud Platform" + elif [[ "$(dmidecode -s bios-vendor)" = "DigitalOcean" ]]; then + Server_Provider="Digital Ocean" + elif [[ "$(dmidecode -s system-product-name | cut -c 1-7)" = "Alibaba" ]]; then + Server_Provider="Alibaba Cloud" + elif [[ "$(dmidecode -s system-manufacturer)" = "Microsoft Corporation" ]]; then + Server_Provider="Microsoft Azure" + elif [[ -d /usr/local/qcloud ]]; then + Server_Provider="Tencent Cloud" + else + Server_Provider="Undefined" + fi +else + Server_Provider='Undefined' +fi + +if [[ -f /sys/devices/virtual/dmi/id/product_uuid ]]; then + if [[ "$(cut -c 1-3 /sys/devices/virtual/dmi/id/product_uuid)" = 'EC2' ]] && [[ -d /home/ubuntu ]]; then + Server_Provider='Amazon Web Service' + fi +fi + +if [[ "$Debug" = "On" ]] ; then + Debug_Log "Server_Provider" "$Server_Provider" +fi +} + +Branch_Check() { +if [[ "$1" = *.*.* ]]; then + #check input if it's valid format as X.Y.Z + Output=$(awk -v num1="$Base_Number" -v num2="${1//[[:space:]]/}" ' + 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${1//[[:space:]]/}" + echo -e "\nSet branch name to $Branch_Name...\n" + fi +else + echo -e "\nPlease input a valid format version number." + exit +fi +} + +Check_Return() { + #check previous command result , 0 = ok , non-0 = something wrong. +# shellcheck disable=SC2181 +if [[ $? != "0" ]]; then + if [[ -n "$1" ]] ; then + echo -e "\n\n\n$1" + fi + echo -e "above command failed..." + Debug_Log2 "command failed, exiting. For more information read /var/log/installLogs.txt [404]" + if [[ "$2" = "no_exit" ]] ; then + echo -e"\nRetrying..." + else + exit + fi +fi +} +# check command success or not + +Regenerate_Cert() { cat </usr/local/CyberCP/cert_conf [req] prompt=no @@ -69,161 +249,112 @@ EOF 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 - } -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 +Retry_Command() { +# shellcheck disable=SC2034 +for i in {1..50}; +do + $1 && break || echo -e "\n$1 has failed for $i times\nWait for 3 seconds and try again...\n"; sleep 3; +done +} - if [[ $TMP_YN == "" ]]; then - BRANCH_NAME="v${TEMP:12:3}.${TEMP:25:1}" - echo -e "\nBranch name set to $BRANCH_NAME" +Check_Argument() { +if [[ "$*" = *"--branch "* ]] || [[ "$*" = *"-b "* ]]; then + Branch_Name=$(echo "$*" | sed -e "s/--branch //" -e "s/--mirror//" -e "s/-b //") + Branch_Check "$Branch_Name" +fi +} + +Pre_Upgrade_Setup_Git_URL() { + if [[ $Server_Country != "CN" ]] ; then + Git_User="usmannasir" + Git_Content_URL="https://raw.githubusercontent.com/${Git_User}/cyberpanel" + Git_Clone_URL="https://github.com/${Git_User}/cyberpanel.git" 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 + Git_User="qtwrk" + Git_Content_URL="https://gitee.com/${Git_User}/cyberpanel/raw" + Git_Clone_URL="https://gitee.com/${Git_User}/cyberpanel.git" + fi + + if [[ "$Debug" = "On" ]] ; then + Debug_Log "Git_URL" "$Git_Content_URL" fi } -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 -} +Pre_Upgrade_CentOS7_MySQL() { +if [[ "$MySQL_Version" = "10.1" ]]; then + cp /etc/my.cnf /etc/my.cnf.bak + mkdir /etc/cnfbackup + cp -R /etc/my.cnf.d/ /etc/cnfbackup/ -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" - 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." - exit - fi + yum remove MariaDB-server MariaDB-client galera -y + yum --enablerepo=mariadb -y install MariaDB-server MariaDB-client galera - 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 -} + cp -f /etc/my.cnf.bak /etc/my.cnf + rm -rf /etc/my.cnf.d/ + mv /etc/cnfbackup/my.cnf.d /etc/ -check_return() { - #check previous command result , 0 = ok , non-0 = something wrong. - if [[ $? -eq "0" ]]; then - : - else - echo -e "\ncommand failed, exiting..." - exit - fi -} + systemctl enable mysql + systemctl start mysql -input_branch + mysql_upgrade -uroot -p"$MySQL_Password" -check_root - -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" -elif echo $OUTPUT | grep -q "CloudLinux 7"; then - echo -e "\nDetecting CloudLinux 7.X...\n" - SERVER_OS="CentOS7" -elif echo $OUTPUT | grep -q "CentOS Linux 8"; then - rm -f /etc/yum.repos.d/CyberPanel.repo - dnf --nogpg install -y https://mirror.ghettoforge.org/distributions/gf/el/8/gf/x86_64/gf-release-8-11.gf.el8.noarch.rpm - echo -e "\nDetecting CentOS 8.X...\n" - SERVER_OS="CentOS8" - 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 - yum autoremove epel-release -y - dnf install epel-release -y -elif echo $OUTPUT | grep -q "CloudLinux 8"; then - rm -f /etc/yum.repos.d/CyberPanel.repo - dnf --nogpg install -y https://mirror.ghettoforge.org/distributions/gf/el/8/gf/x86_64/gf-release-8-11.gf.el8.noarch.rpm - echo -e "\nDetecting Cloudlinux 8.X...\n" - SERVER_OS="CentOS8" - 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 - yum autoremove epel-release -y - dnf install epel-release -y -elif echo $OUTPUT | grep -q "Ubuntu 18.04"; then - echo -e "\nDetecting Ubuntu 18.04...\n" - SERVER_OS="Ubuntu" -elif echo $OUTPUT | grep -q "Ubuntu 20.04"; then - echo -e "\nDetecting Ubuntu 20.04...\n" - SERVER_OS="Ubuntu" - UBUNTU_20="True" -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 +mysql -uroot -p"$MySQL_Password" -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '$MySQL_Password';flush privileges" +} +Pre_Upgrade_Setup_Repository() { +if [[ "$Server_OS" = "CentOS" ]] ; then rm -f /etc/yum.repos.d/CyberPanel.repo + rm -f /etc/yum.repos.d/litespeed.repo + if [[ "$Server_Country" = "CN" ]] ; then + curl -o /etc/yum.repos.d/litespeed.repo https://cyberpanel.sh/litespeed/litespeed_cn.repo + else + curl -o /etc/yum.repos.d/litespeed.repo https://cyberpanel.sh/litespeed/litespeed.repo + fi 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 + yum autoremove epel-release -y +#all pre-upgrade operation for CentOS both 7/8 - yum install epel-release -y - yum -y install yum-utils - yum -y groupinstall development + if [[ "$Server_OS_Version" = "7" ]] ; then + yum install epel-release -y + yum -y install yum-utils + yum -y groupinstall development + rm -f /etc/yum.repos.d/dovecot.repo + rm -f /etc/yum.repos.d/frank.repo + rm -f /etc/yum.repos.d/ius-archive.repo + rm -f /etc/yum.repos.d/ius.repo + rm -f /etc/yum.repos.d/ius-testing.repo + #rm -f /etc/yum.repos.d/lux.repo + rm -f /etc/yum.repos.d/powerdns-auth-* - ###### Setup Required Repos + rm -f /etc/yum.repos.d/MariaDB.repo + rm -f /etc/yum.repos.d/MariaDB.repo.rpmsave - rm -f /etc/yum.repos.d/dovecot.repo - rm -f /etc/yum.repos.d/frank.repo - rm -f /etc/yum.repos.d/ius-archive.repo - rm -f /etc/yum.repos.d/ius.repo - rm -f /etc/yum.repos.d/ius-testing.repo -# rm -f /etc/yum.repos.d/lux.repo + yum erase gf-* -y - ## Start with PDNS + rm -f /etc/yum.repos.d/gf.repo + rm -f /etc/yum.repos.d/gf.repo.rpmsave - rm -rf /etc/yum.repos.d/powerdns-auth-* + rm -f /etc/yum.repos.d/copart-restic-epel-7.repo.repo + rm -f /etc/yum.repos.d/copart-restic-epel-7.repo.rpmsave - yum install yum-plugin-priorities -y - curl -o /etc/yum.repos.d/powerdns-auth-43.repo https://repo.powerdns.com/repo-files/centos-auth-43.repo + rm -f /etc/yum.repos.d/ius-archive.repo + rm -f /etc/yum.repos.d/ius.repo + rm -f /etc/yum.repos.d/ius-testing.repo - ## MariaDB + yum clean all - rm -f /etc/yum.repos.d/MariaDB.repo - rm -f /etc/yum.repos.d/MariaDB.repo.rpmsave + curl -o /etc/yum.repos.d/powerdns-auth-43.repo https://cyberpanel.sh/repo.powerdns.com/repo-files/centos-auth-43.repo + Check_Return "yum repo" "no_exit" - cat << EOF > /etc/yum.repos.d/MariaDB.repo + cat << EOF > /etc/yum.repos.d/MariaDB.repo # MariaDB 10.5 CentOS repository list - created 2020-09-08 14:54 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] @@ -233,207 +364,288 @@ gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 EOF - ## Lets upgrade mariadb on spot + yum install yum-plugin-copr -y + yum copr enable copart/restic -y + rpm -ivh https://cyberpanel.sh/repo.ius.io/ius-release-el7.rpm - if echo $MYSQLCurrentVersion | grep -q "MariaDB 10.1"; then + if [[ "$Server_Country" = "CN" ]] ; then + sed -i 's|http://yum.mariadb.org|https://cyberpanel.sh/yum.mariadb.org|g' /etc/yum.repos.d/MariaDB.repo + sed -i 's|https://yum.mariadb.org/RPM-GPG-KEY-MariaDB|https://cyberpanel.sh/yum.mariadb.org/RPM-GPG-KEY-MariaDB|g' /etc/yum.repos.d/MariaDB.repo + # use MariaDB Mirror + sed -i 's|https://download.copr.fedorainfracloud.org|https://cyberpanel.sh/download.copr.fedorainfracloud.org|g' /etc/yum.repos.d/_copr_copart-restic.repo + sed -i 's|http://repo.iotti.biz|https://cyberpanel.sh/repo.iotti.biz|g' /etc/yum.repos.d/frank.repo + sed -i "s|mirrorlist=http://mirrorlist.ghettoforge.org/el/7/gf/\$basearch/mirrorlist|baseurl=https://cyberpanel.sh/mirror.ghettoforge.org/distributions/gf/el/7/gf/x86_64/|g" /etc/yum.repos.d/gf.repo + sed -i "s|mirrorlist=http://mirrorlist.ghettoforge.org/el/7/plus/\$basearch/mirrorlist|baseurl=https://cyberpanel.sh/mirror.ghettoforge.org/distributions/gf/el/7/plus/x86_64/|g" /etc/yum.repos.d/gf.repo + sed -i 's|https://repo.ius.io|https://cyberpanel.sh/repo.ius.io|g' /etc/yum.repos.d/ius.repo + sed -i 's|http://repo.iotti.biz|https://cyberpanel.sh/repo.iotti.biz|g' /etc/yum.repos.d/lux.repo + sed -i 's|http://repo.powerdns.com|https://cyberpanel.sh/repo.powerdns.com|g' /etc/yum.repos.d/powerdns-auth-43.repo + sed -i 's|https://repo.powerdns.com|https://cyberpanel.sh/repo.powerdns.com|g' /etc/yum.repos.d/powerdns-auth-43.repo + fi + yum install yum-plugin-priorities -y - cp /etc/my.cnf /etc/my.cnf.bak - mkdir /etc/cnfbackup - cp -R /etc/my.cnf.d/ /etc/cnfbackup/ + yum update -y - yum remove MariaDB-server MariaDB-client galera -y - yum --enablerepo=mariadb -y install MariaDB-server MariaDB-client galera + yum 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 bind-utils - cp -f /etc/my.cnf.bak /etc/my.cnf - rm -rf /etc/my.cnf.d/ - mv /etc/cnfbackup/my.cnf.d /etc/ + Pre_Upgrade_CentOS7_MySQL - systemctl enable mysql - systemctl start mysql - - mysql_upgrade -uroot -p$MYSQLPassword + #all pre-upgrade operation for CentOS 7 + elif [[ "$Server_OS_Version" = "8" ]] ; then + cat </etc/yum.repos.d/CentOS-PowerTools-CyberPanel.repo +[powertools-for-cyberpanel] +name=CentOS Linux \$releasever - PowerTools +mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=PowerTools&infra=\$infra +baseurl=http://mirror.centos.org/\$contentdir/\$releasever/PowerTools/\$basearch/os/ +gpgcheck=1 +enabled=1 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial +EOF + if [[ "$Server_Country" = "CN" ]] ; then + dnf --nogpg install -y https://cyberpanel.sh/mirror.ghettoforge.org/distributions/gf/el/8/gf/x86_64/gf-release-8-11.gf.el8.noarch.rpm + else + dnf --nogpg install -y https://mirror.ghettoforge.org/distributions/gf/el/8/gf/x86_64/gf-release-8-11.gf.el8.noarch.rpm fi - mysql -uroot -p$MYSQLPassword -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '$MYSQLPassword';flush privileges" + dnf install epel-release -y - - ## Ghetoo Repo for Postfix/Dovecot - - yum erase gf-* -y - - rm -f /etc/yum.repos.d/gf.repo - rm -f /etc/yum.repos.d/gf.repo.rpmsave - - yum --nogpg install https://mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el7.noarch.rpm -y - - ## Copr for restic - - rm -f /etc/yum.repos.d/copart-restic-epel-7.repo.repo - rm -f /etc/yum.repos.d/copart-restic-epel-7.repo.rpmsave - - yum install yum-plugin-copr -y - yum copr enable copart/restic -y - - ## IUS Repo for python 3 - - rm -f /etc/yum.repos.d/ius-archive.repo - rm -f /etc/yum.repos.d/ius.repo - rm -f /etc/yum.repos.d/ius-testing.repo - - yum install https://repo.ius.io/ius-release-el7.rpm -y - - ### - - yum clean all - yum update -y - - yum 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 - -elif [ $SERVER_OS = "CentOS8" ]; then - 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 - dnf --enablerepo=powertools install gpgme-devel -y - dnf --enablerepo=PowerTools install gpgme-devel -y + 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 bind-utils + dnf install gpgme-devel -y dnf install python3 -y -else + fi + #all pre-upgrade operation for CentOS 8 +elif [[ "$Server_OS" = "Ubutnu" ]] ; then + apt update -y DEBIAN_FRONTEND=noninteractive apt upgrade -y - 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 + 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 dnsutils 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==16.7.9 - check_return + if [[ "$Server_OS_Version" = "18" ]] ; then + : +#all pre-upgrade operation for Ubuntu 18 + elif [[ "$Server_OS_Version" = "20" ]] ; then + : + fi +#all pre-upgrade operation for Ubuntu 20 +fi +} + +Download_Requirement() { +for i in {1..50}; + do + wget -O /usr/local/requirments.txt "${Git_Content_URL}/${Branch_Name}/requirments.txt" + if grep -q "Django==" /usr/local/requirments.txt ; then + break + else + echo -e "\n Requirement list has failed to download for $i times..." + echo -e "Wait for 30 seconds and try again...\n" + sleep 30 + fi +done +#special made function for Gitee.com , for whatever reason , sometimes it fails to download this file +} + + + +Pre_Upgrade_Required_Components() { + +if [ "$Server_OS" = "Ubuntu" ]; then + pip3 install --default-timeout=3600 virtualenv==16.7.9 + Check_Return else - pip3.6 install virtualenv==16.7.9 - check_return + pip3.6 install --default-timeout=3600 virtualenv==16.7.9 + Check_Return fi if [[ -f /usr/local/CyberPanel/bin/python2 ]]; then echo -e "\nPython 2 dectected, doing resetup...\n" rm -rf /usr/local/CyberPanel/bin virtualenv -p /usr/bin/python3 --system-site-packages /usr/local/CyberPanel - check_return + Check_Return elif [[ -d /usr/local/CyberPanel/bin/ ]]; then echo -e "\nNo need to resetup virtualenv at /usr/local/CyberPanel...\n" else echo -e "\nNothing found, need fresh setup...\n" virtualenv -p /usr/bin/python3 --system-site-packages /usr/local/CyberPanel - check_return + Check_Return fi -rm -f requirments.txt -wget https://raw.githubusercontent.com/usmannasir/cyberpanel/$BRANCH_NAME/requirments.txt - -#if [[ $UBUNTU_20 == "False" ]]; then -# wget -O /usr/local/cyberpanel-pip.zip https://rep.cyberpanel.net/cyberpanel-pip-3.zip -#else -# wget -O /usr/local/cyberpanel-pip.zip https://rep.cyberpanel.net/ubuntu-pip-3.zip -#fi -# -#check_return -#rm -rf /usr/local/pip-packs/ -#rm -rf /usr/local/packages -# -#unzip /usr/local/cyberpanel-pip.zip -d /usr/local -#check_return +# shellcheck disable=SC1091 . /usr/local/CyberPanel/bin/activate -check_return -if [ $SERVER_OS = "Ubuntu" ]; then +Download_Requirement + +if [[ "$Server_OS" = "CentOS" ]] ; then + pip3.6 install --default-timeout=3600 virtualenv==16.7.9 + Check_Return + pip3.6 install --default-timeout=3600 --ignore-installed -r /usr/local/requirments.txt + Check_Return +elif [[ "$Server_OS" = "Ubuntu" ]] ; then + # shellcheck disable=SC1091 . /usr/local/CyberPanel/bin/activate - check_return - if [[ $UBUNTU_20 == "False" ]]; then - pip3 install --ignore-installed -r requirments.txt - else - pip3 install --ignore-installed -r requirments.txt - fi - check_return + Check_Return + pip3 install --default-timeout=3600 virtualenv==16.7.9 + Check_Return + pip3 install --default-timeout=3600 --ignore-installed -r /usr/local/requirments.txt + Check_Return +fi + +#virtualenv -p /usr/bin/python3 --system-site-packages /usr/local/CyberPanel +# Check_Return + +wget "${Git_Content_URL}/${Branch_Name}/plogical/upgrade.py" + +if [[ "$Server_Country" = "CN" ]] ; then + sed -i 's|git clone https://github.com/usmannasir/cyberpanel|echo git cloned|g' upgrade.py + + Retry_Command "git clone ${Git_Clone_URL}" + Check_Return "git clone ${Git_Clone_URL}" + + # shellcheck disable=SC2086 + sed -i 's|https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/install/litespeed/httpd_config.xml|'${Git_Content_URL}/${Branch_Name}'//install/litespeed/httpd_config.xml|g' upgrade.py + sed -i 's|https://cyberpanel.sh/composer.sh|https://gitee.com/qtwrk/cyberpanel/raw/stable/install/composer_cn.sh|g' upgrade.py +fi + +} + +Pre_Upgrade_Setup_Git_URL() { +if [[ $Server_Country != "CN" ]] ; then + Git_User="usmannasir" + Git_Content_URL="https://raw.githubusercontent.com/${Git_User}/cyberpanel" + Git_Clone_URL="https://github.com/${Git_User}/cyberpanel.git" else - #source /usr/local/CyberPanel/bin/activate - #check_return - pip3.6 install --ignore-installed -r requirments.txt - check_return + Git_User="qtwrk" + Git_Content_URL="https://gitee.com/${Git_User}/cyberpanel/raw" + Git_Clone_URL="https://gitee.com/${Git_User}/cyberpanel.git" fi -## Doing again to prevent an error - dont confuse later - -virtualenv -p /usr/bin/python3 --system-site-packages /usr/local/CyberPanel -check_return - -## - -rm -rf upgrade.py -wget https://$GIT_CONTENT_URL/${BRANCH_NAME}/plogical/upgrade.py - -if [[ $SERVER_COUNTRY == "CN" ]]; then - 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 - 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 - #sed -i $'s/0.2.4\' % (branch)/0.2.4\'/' upgrade.py - 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 +if [[ "$Debug" = "On" ]] ; then + Debug_Log "Git_URL" "$Git_Content_URL" fi +} -/usr/local/CyberPanel/bin/python upgrade.py $BRANCH_NAME -check_return +Pre_Upgrade_Branch_Input() { + 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 -r -t 10 Tmp_Input + if [[ $Tmp_Input = "" ]]; then + echo -e "Branch name set to $Branch_Name" + else + Branch_Check "$Tmp_Input" + fi +} + +Main_Upgrade() { +/usr/local/CyberPanel/bin/python upgrade.py "$Branch_Name" + Check_Return if [[ -f /usr/local/CyberCP/bin/python2 ]]; then rm -rf /usr/local/CyberCP/bin virtualenv -p /usr/bin/python3 /usr/local/CyberCP + Check_Return elif [[ -d /usr/local/CyberCP/bin/ ]]; then 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 + Check_Return fi -check_return +rm -f /usr/local/requirments.txt -rm -f requirments.txt -wget https://raw.githubusercontent.com/usmannasir/cyberpanel/$BRANCH_NAME/requirments.txt +Download_Requirement -if [ $SERVER_OS = "Ubuntu" ]; then +if [ "$Server_OS" = "Ubuntu" ]; then + # shellcheck disable=SC1091 . /usr/local/CyberCP/bin/activate - check_return - if [[ $UBUNTU_20 == "False" ]]; then - pip3 install --ignore-installed -r requirments.txt - else - pip3 install --ignore-installed -r requirments.txt - fi - check_return + Check_Return + pip3 install --default-timeout=3600 --ignore-installed -r /usr/local/requirments.txt + Check_Return else + # shellcheck disable=SC1091 source /usr/local/CyberCP/bin/activate - check_return - pip3.6 install --ignore-installed -r requirments.txt - check_return + Check_Return + pip3.6 install --default-timeout=3600 --ignore-installed -r /usr/local/requirments.txt + Check_Return fi -## - -rm -f wsgi-lsapi-1.4.tgz -rm -f wsgi-lsapi-1.5.tgz -rm -f wsgi-lsapi-1.6.tgz -rm -rf wsgi-lsapi-1.4 -rm -rf wsgi-lsapi-1.5 -rm -rf wsgi-lsapi-1.6 -wget http://www.litespeedtech.com/packages/lsapi/wsgi-lsapi-1.6.tgz -tar xf wsgi-lsapi-1.6.tgz -cd wsgi-lsapi-1.6 +wget https://cyberpanel.sh/www.litespeedtech.com/packages/lsapi/wsgi-lsapi-1.7.tgz +tar xf wsgi-lsapi-1.7.tgz +cd wsgi-lsapi-1.7 || exit /usr/local/CyberPanel/bin/python ./configure.py make +rm -f /usr/local/CyberCP/bin/lswsgi cp lswsgi /usr/local/CyberCP/bin/ +} + +Post_Upgrade_System_Tweak() { + if [[ "$Server_OS" = "CentOS" ]] ; then + + #for cenots 7/8 + if [[ "$Server_OS_Version" = "7" ]] ; then + 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 + if ! yum list installed lsphp74-devel ; then + yum install -y lsphp74-devel + fi + if [[ ! -f /usr/local/lsws/lsphp74/lib64/php/modules/zip.so ]] ; then + if yum list installed libzip-devel >/dev/null 2>&1 ; then + yum remove -y libzip-devel + fi + yum install -y https://cyberpanel.sh/misc/libzip-0.11.2-6.el7.psychotic.x86_64.rpm + yum install -y https://cyberpanel.sh/misc/libzip-devel-0.11.2-6.el7.psychotic.x86_64.rpm + 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 + if /usr/local/lsws/lsphp74/bin/pecl install zip ; then + 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 + else + echo -e "\nlsphp74-zip compilation failed..." + fi + #fix old legacy lsphp74-zip issue on centos 7 + fi + + + #for centos 7 + elif [[ "$Server_OS_Version" = "8" ]] ; then + : + #for centos 8 + fi + fi + + if [[ "$Server_OS" = "Ubuntu" ]] ; then + + if ! dpkg -l lsphp74-dev >/dev/null 2>&1 ; then + apt install -y lsphp74-dev + fi + + if [[ ! -f /usr/sbin/ipset ]] ; then + ln -s /sbin/ipset /usr/sbin/ipset + fi + + #for ubuntu 18/20 + if [[ "$Server_OS_Version" = "18" ]] ; then + : + #for ubuntu 18 + elif [[ "$Server_OS_Version" = "20" ]] ; then + : + #for ubuntu 20 + fi + fi + sed -i 's|python2|python|g' /usr/bin/adminPass chmod 700 /usr/bin/adminPass -if [[ ! -f /usr/sbin/ipset ]] && [[ $SERVER_OS == "Ubuntu" ]]; then - ln -s /sbin/ipset /usr/sbin/ipset -fi - if [[ -f /etc/cyberpanel/webadmin_passwd ]]; then chmod 600 /etc/cyberpanel/webadmin_passwd fi @@ -442,107 +654,94 @@ if [[ -f /etc/pure-ftpd/pure-ftpd.conf ]]; then sed -i 's|NoAnonymous no|NoAnonymous yes|g' /etc/pure-ftpd/pure-ftpd.conf fi -install_utility - -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 +Tmp_Output=$(timeout 3 openssl s_client -connect 127.0.0.1:8090 2>/dev/null) +if echo "$Tmp_Output" | grep -q "mail@example.com" ; 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 + Regenerate_Cert 8090 fi -if [[ $SERVER_OS == "CentOS7" ]]; then - 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 - - yum list installed lsphp74-devel - if [[ $? != "0" ]]; then - yum install -y lsphp74-devel - fi +Tmp_Output=$(timeout 3 openssl s_client -connect 127.0.0.1:7080 2>/dev/null) +if echo "$Tmp_Output" | grep -q "mail@example.com" ; then + Regenerate_Cert 7080 fi -if [[ $SERVER_OS == "Ubuntu" ]]; then - dpkg -l lsphp74-dev >/dev/null 2>&1 - if [[ $? != "0" ]]; then - apt install -y lsphp74-dev - fi +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 -if [[ ! -f /usr/local/lsws/lsphp74/lib64/php/modules/zip.so ]] && [[ $SERVER_OS == "CentOS7" ]]; then - yum list installed libzip-devel >/dev/null 2>&1 - if [[ $? == "0" ]]; then - yum remove -y libzip-devel - fi - - 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 - 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 - /usr/local/lsws/lsphp74/bin/pecl install zip - if [[ $? == 0 ]]; then - 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 - else - echo -e "\nlsphp74-zip compilation failed..." - fi -fi -#fix the lsphp74-zip missing issue. - -## -chown -R cyberpanel:cyberpanel /usr/local/CyberCP/lib -chown -R cyberpanel:cyberpanel /usr/local/CyberCP/lib64 -systemctl restart lscpd - -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 - if [[ -f /etc/cyberpanel/watchdog.sh ]] ; then - watchdog kill + watchdog kill rm -f /etc/cyberpanel/watchdog.sh rm -f /usr/local/bin/watchdog - wget -O /etc/cyberpanel/watchdog.sh https://$GIT_CONTENT_URL/$BRANCH_NAME/CPScripts/watchdog.sh + wget -O /etc/cyberpanel/watchdog.sh "${Git_Content_URL}/${Branch_Name}/CPScripts/watchdog.sh" chmod 700 /etc/cyberpanel/watchdog.sh ln -s /etc/cyberpanel/watchdog.sh /usr/local/bin/watchdog watchdog status fi -#update and restart watchdog -### Disable Centos Default Repos -disable_repos() { +rm -f /usr/local/composer.sh +rm -f /usr/local/requirments.txt - if [[ $SERVER_OS == "CentOS" ]]; then - sed -i 's|enabled=1|enabled=0|g' /etc/yum.repos.d/CentOS-Base.repo - sed -i 's|enabled=1|enabled=0|g' /etc/yum.repos.d/CentOS-Debuginfo.repo - sed -i 's|enabled=1|enabled=0|g' /etc/yum.repos.d/CentOS-Media.repo - sed -i 's|enabled=1|enabled=0|g' /etc/yum.repos.d/CentOS-Vault.repo - sed -i 's|enabled=1|enabled=0|g' /etc/yum.repos.d/CentOS-CR.repo - sed -i 's|enabled=1|enabled=0|g' /etc/yum.repos.d/CentOS-fasttrack.repo - sed -i 's|enabled=1|enabled=0|g' /etc/yum.repos.d/CentOS-Sources.repo - fi +chown -R cyberpanel:cyberpanel /usr/local/CyberCP/lib +chown -R cyberpanel:cyberpanel /usr/local/CyberCP/lib64 +systemctl restart lscpd } -disable_repos +Post_Install_Display_Final_Info() { +Panel_Port=$(cat /usr/local/lscp/conf/bind.conf) +if [[ $Panel_Port = "" ]] ; then + Panel_Port="8090" +fi -echo "###################################################################" -echo " CyberPanel Upgraded " -echo "###################################################################" +if curl -I -XGET -k "https://127.0.0.1:${Panel_Port#*:}" | grep -q "200 OK" ; then + echo "###################################################################" + echo " CyberPanel Upgraded " + echo "###################################################################" +else + echo -e "\nSeems something wrong with upgarde, please check...\n" +fi +rm -rf /root/cyberpanel_upgrade_tmp +} + +if [[ ! -d /etc/cyberpanel ]] ; then + echo -e "\n\nCan not detect CyberCP..." + exit +fi + +if [[ "$*" = *"--debug"* ]] ; then + Debug="On" + rm -f /tmp/cyberpanel_debug_upgrade.log + echo -e "$(date)" > /tmp/cyberpanel_debug_upgrade.log +fi + +Set_Default_Variables + +Check_Root + +Check_Server_IP "$@" + +Check_OS + +Check_Provider + +Check_Argument "$@" + +if [[ "$*" != *"--branch "* ]] && [[ "$*" != *"-b "* ]] ; then + Pre_Upgrade_Branch_Input +fi + +Pre_Upgrade_Setup_Repository + +Pre_Upgrade_Setup_Git_URL + +Pre_Upgrade_Required_Components + +Main_Upgrade + +Post_Upgrade_System_Tweak + +Post_Install_Display_Final_Info