You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

420 lines
17 KiB

#!/bin/bash
# Define variables
readonly EE_UPDATE_LOG=/var/log/easyengine/update.log
# Define echo function
# Blue color
function ee_lib_echo()
{
echo $(tput setaf 4)$@$(tput sgr0)
}
# White color
function ee_lib_echo_info()
{
echo $(tput setaf 7)$@$(tput sgr0)
}
# Red color
function ee_lib_echo_fail()
{
echo $(tput setaf 1)$@$(tput sgr0)
}
# Capture errors
function ee_lib_error()
{
echo "[ `date` ] $(tput setaf 1)$@$(tput sgr0)" | tee -ai $EE_ERROR_LOG
exit $2
}
# Initialize Git
function ee_lib_git()
{
for ee_git_dir in ${@:1:$(($#-1))}; do
# Change directory
cd $ee_git_dir || ee_lib_error "Unable to change directory $ee_git_dir, exit status = " $?
# Check .git
if [ ! -d .git ]; then
# ee_lib_echo "Initialize Git on ${ee_git_dir}"
git init &>> $EE_UPDATE_LOG \
|| ee_lib_error "Unable to initialize Git on $ee_git_dir, exit status = " $?
fi
# Check for untracked files
if [ $(git status -s | wc -l) -ne 0 ]; then
# Add files in Git version control
ee_lib_echo "Git commit on $ee_git_dir, please wait..."
git add --all && git commit -am "${@: -1}" &>> $EE_UPDATE_LOG \
|| ee_lib_error "Unable to Git commit on $ee_git_dir, exit status = " $?
fi
done
}
# Update EasyEngine (ee)
# EasyEngine version: 1.0.0
# EasyEngine (ee) version: 2.0.0
EE_CURRENT_VERSION=$(ee version | sed 's/(ee) //' | awk '{print $3}')
EE_LATEST_VERSION=$(curl -sL https://api.github.com/repos/rtCamp/easyengine/releases | grep tag_name | awk '{print($2)}' | cut -d'"' -f2 | cut -c2- | head -n1)
echo EE_CURRENT_VERSION = $EE_CURRENT_VERSION EE_LATEST_VERSION = $EE_LATEST_VERSION &>> $EE_UPDATE_LOG
if [[ $EE_CURRENT_VERSION < $EE_LATEST_VERSION ]]; then
read -p "Update EasyEngine to $EE_LATEST_VERSION (y/n): " EE_ANS
if [ "$EE_ANS" = "y" ] || [ "$EE_ANS" = "Y" ]; then
ee_lib_echo "EasyEngine (ee) update started [$(date)]" | tee -ai $EE_UPDATE_LOG
# Install required packages
if [ "$EE_LINUX_DISTRO" == "Ubuntu" ]; then
ee_lib_package_check graphviz python-software-properties software-properties-common
elif [ "$EE_LINUX_DISTRO" == "Debian" ]; then
ee_lib_package_check graphviz python-software-properties
fi
if [ ! -x /usr/bin/tee ] || [ ! -x /bin/ed ] || [ ! -x /usr/bin/bc ] || [ ! -x /usr/bin/wget ] || [ ! -x /usr/bin/curl ] || [ ! -x /bin/tar ] || [ ! -x /usr/bin/git ] || [ -n "$EE_PACKAGE_NAME" ]; then
ee_lib_echo "Installing required packages, please wait..." | tee -ai $EE_INSTALL_LOG
apt-get -y install coreutils ed bc wget curl tar git-core $EE_PACKAGE_NAME | tee -ai $EE_INSTALL_LOG\
|| ee_lib_error "Unable to install required packages, exit status = " $?
fi
# Git backup
ee_lib_git /etc/nginx/ /etc/php5/ /etc/mysql/ /etc/postfix "EasyEngine version $EE_CURRENT_VERSION"
# Remove old version of EasyEngine (ee)
rm -rf /tmp/easyengine &>> /dev/null
# Let's clone EasyEngine (ee)
ee_lib_echo "Cloning EasyEngine (ee) stable branch, please wait..." | tee -ai $EE_UPDATE_LOG
git clone -b stable https://github.com/rtCamp/easyengine.git /tmp/easyengine &>> $EE_UPDATE_LOG \
|| ee_lib_error "Unable to clone EasyEngine (ee) stable branch, exit status = " $?
# Setup EasyEngine (ee)
if [ ! -d /etc/easyengine ]; then
mkdir -p /etc/easyengine \
|| ee_lib_error "Unable to create /etc/easyengine directory, exit status = " $?
fi
if [ ! -d /usr/share/easyengine/ ]
then
mkdir -p /usr/share/easyengine/ \
|| ee_lib_error "Unable to create /usr/share/easyengine/ directory, exit status = " $?
fi
if [ ! -d /usr/local/lib/easyengine ]
then
mkdir -p /usr/local/lib/easyengine \
|| ee_lib_error "Unable to create /usr/local/lib/easyengine directory, exit status = " $?
fi
# Setup EasyEngine (ee)
# EasyEngine (ee) auto completion file
cp -av /tmp/easyengine/config/bash_completion.d/ee /etc/bash_completion.d/ &>> $EE_UPDATE_LOG \
|| ee_lib_error "Unable to copy EasyEngine (ee) auto completion file, exit status = " $?
# Templates
cp -a /tmp/easyengine/config/nginx /tmp/easyengine/templates/* /usr/share/easyengine/ &>> $EE_UPDATE_LOG \
|| ee_lib_error "Unable to copy NGINX sample files, exit status = " $?
# NGINX Setup
sed -i "s/X-Powered-By.*/X-Powered-By \"EasyEngine $EE_LATEST_VERSION\";/" /etc/nginx/nginx.conf
rsync -avz --exclude acl.conf /usr/share/easyengine/nginx/common/* /etc/nginx/common/ &>> $EE_UPDATE_LOG \
|| ee_lib_error "Unable to rsync NGINX common files, exit status = " $?
# EasyEngine (ee) library and modules
cp -av /tmp/easyengine/src/* /usr/local/lib/easyengine &>> $EE_UPDATE_LOG \
|| ee_lib_error "Unable to copy src files, exit status = " $?
# EasyEngine (ee) command
cp -av /tmp/easyengine/bin/easyengine /usr/local/sbin/ &>> $EE_UPDATE_LOG \
|| ee_lib_error "Unable to copy EasyEngine (ee) command, exit status = " $?
# Change permission of EasyEngine (ee) command
chmod 750 /usr/local/sbin/easyengine || ee_lib_error "Unable to change permission of EasyEngine (ee) command, exit status = " $?
# Create symbolic link
if [ ! -L /usr/local/sbin/ee ]; then
ln -s /usr/local/sbin/easyengine /usr/local/sbin/ee
fi
# EasyEngine (ee) man page
cp -av /tmp/easyengine/docs/man/ee.8 /usr/share/man/man8/ &>> $EE_UPDATE_LOG \
|| ee_lib_error "Unable to copy EasyEngine (ee) man page, exit status = " $?
if [[ $EE_CURRENT_VERSION < 2.0.0 ]]; then
# EasyEngine (ee) config file
cp -av /etc/easyengine/ee.conf /etc/easyengine/ee.bak &>> $EE_UPDATE_LOG
cp -av /tmp/easyengine/config/easyengine/ee.conf /etc/easyengine/ &>> $EE_UPDATE_LOG \
|| ee_lib_error "Unable to copy EasyEngine (ee) config file, exit status = " $?
# Lets re-used our functions
# Include library
for ee_include in $(find /usr/local/lib/easyengine/ -iname "*.sh"); do
source $ee_include
done
# Lets modify the $EE_COMMAND_LOG value
# So all the logs write in $EE_UPDATE_LOG
EE_COMMAND_LOG=$EE_UPDATE_LOG
# Install required packages
if [ "$EE_LINUX_DISTRO" == "Ubuntu" ]; then
ee_lib_package_check graphviz python-software-properties software-properties-common
elif [ "$EE_LINUX_DISTRO" == "Debian" ]; then
ee_lib_package_check graphviz python-software-properties
fi
if [ ! -x /usr/bin/tee ] || [ ! -x /bin/ed ] || [ ! -x /usr/bin/bc ] || [ ! -x /usr/bin/wget ] || [ ! -x /usr/bin/curl ] || [ ! -x /bin/tar ] || [ ! -x /usr/bin/git ] || [ -n "$EE_PACKAGE_NAME" ]; then
ee_lib_echo "Installing required packages, please wait..." | tee -ai $EE_UPDATE_LOG
apt-get -y install coreutils ed bc wget curl tar git-core $EE_PACKAGE_NAME | tee -ai $EE_UPDATE_LOG\
|| ee_lib_error "Unable to install required packages, exit status = " $?
fi
# Get old value from ee.bak file
ee_stack_ip=$(grep ip_address /etc/easyengine/ee.bak | cut -d'=' -f2)
ee_mysql_host=$(grep mysqlhost /etc/easyengine/ee.bak | cut -d'=' -f2)
ee_wp_user=$(grep wpadminuser /etc/easyengine/ee.bak | cut -d'=' -f2)
ee_wp_pass=$(grep wpadminpass /etc/easyengine/ee.bak | cut -d'=' -f2)
#ee_wp_email=$(grep wpadminemail /etc/easyengine/ee.bak | cut -d'=' -f2)
# Set localhost when no host found
if [ -z $ee_mysql_host ]; then
ee_mysql_host=localhost
fi
# Ask email address
ee_lib_echo "Update your email address, which is used to setup WordPress"
read -p "Enter email address: " ee_wp_email
# Update value in ee.conf file
$EE_CONFIG_SET stack.ip-address "$(echo -n $ee_stack_ip)" && \
$EE_CONFIG_SET mysql.host "$(echo -n $ee_mysql_host)" && \
$EE_CONFIG_SET wordpress.user "$(echo -n $ee_wp_user)" && \
$EE_CONFIG_SET wordpress.password "$(echo -n $ee_wp_pass)" && \
$EE_CONFIG_SET wordpress.email "$(echo -n $ee_wp_email)" \
|| ee_lib_error "Unable to update ee.conf file, exit status = " $?
# NGINX conf.d
cp -v /usr/share/easyengine/nginx/conf.d/fastcgi.conf /etc/nginx/conf.d/ &>> $EE_UPDATE_LOG \
|| ee_lib_error "Unable to copy fastcgi.conf file, exit status = " $?
cp -v /usr/share/easyengine/nginx/conf.d/upstream.conf /etc/nginx/conf.d/ &>> $EE_UPDATE_LOG \
|| ee_lib_error "Unable to copy upstream.conf file, exit status = " $?
# NGINX common
if [[ $EE_CURRENT_VERSION = 1.0.0 ]] || [[ $EE_CURRENT_VERSION = 1.0.1 ]] || [[ $EE_CURRENT_VERSION = 1.1.0 ]]; then
# Move allowed_ip.conf to acl.conf
(sed "/allow/,+2d" /usr/share/easyengine/nginx/common/acl.conf; grep -v ^# /etc/nginx/common/allowed_ip.conf ) > /etc/nginx/common/acl.conf
sed -i '/allow ;/d' /etc/nginx/common/acl.conf
# Update nginx.conf
# SSL settings
grep ssl_ /etc/nginx/nginx.conf &>> $EE_UPDATE_LOG
if [ $? -ne 0 ]; then
sed -i "/client_max_body_size/a \ \n\t# SSL Settings\n\tssl_session_cache shared:SSL:20m;\n\tssl_session_timeout 10m;\n\tssl_prefer_server_ciphers on;\n\tssl_ciphers HIGH:\!aNULL:\!MD5:\!kEDH;\n\n" /etc/nginx/nginx.conf
fi
# Log format
sed -i "s/log_format rt_cache.*/log_format rt_cache '\$remote_addr \$upstream_response_time \$upstream_cache_status [\$time_local] '/" /etc/nginx/nginx.conf
sed -i "s/.*\$body_bytes_sent'/\t\t'\$http_host \"\$request\" \$status \$body_bytes_sent '/" /etc/nginx/nginx.conf
# Update PHP session storage to Memcache
sed -i "/extension/a \session.save_handler = memcache\nsession.save_path = \"tcp://localhost:11211\"" /etc/php5/mods-available/memcache.ini
# Set easyengine:easyengine as default http authentication
if [ ! -f /etc/nginx/htpasswd-ee ]; then
printf "easyengine:$(openssl passwd -crypt easyengine 2> /dev/null)\n" > /etc/nginx/htpasswd-ee 2> /dev/null
fi
# Update EasyEngine current version
EE_CURRENT_VERSION="1.2.2"
fi
if [[ $EE_CURRENT_VERSION = 1.2.2 ]]; then
# Update NGINX configuration
sed -i "/worker_processes/a \worker_rlimit_nofile 100000;" /etc/nginx/nginx.conf
sed -i "s/# multi_accept/multi_accept/" /etc/nginx/nginx.conf
sed -i "s/keepalive_timeout.*/keepalive_timeout 30;/" /etc/nginx/nginx.conf
# Setup port 22222
cp -av /usr/share/easyengine/nginx/22222 /etc/nginx/sites-available/ &>> $EE_UPDATE_LOG
if [ "$EE_LINUX_DISTRO" == "Debian" ]; then
# Dotdeb nginx repository doesn't support spdy
sed -i "s/ spdy//;" /usr/share/easyengine/nginx/22222
fi
# Create a symbolic link for 22222
if [ ! -L /etc/nginx/sites-enabled/22222 ]; then
ln -s /etc/nginx/sites-available/22222 /etc/nginx/sites-enabled/
fi
# Setup logs for 22222
if [ ! -d /var/www/22222/logs ]; then
mkdir -p /var/www/22222/logs
ln -s /var/log/nginx/22222.access.log /var/www/22222/logs/access.log
ln -s /var/log/nginx/22222.error.log /var/www/22222/logs/error.log
fi
# Setup SSL
# Create SSL certificate directory
if [ ! -d /var/www/22222/cert ]; then
mkdir /var/www/22222/cert
fi
# Generate SSL key
ee_lib_echo "Generating SSL private key"
openssl genrsa -out /var/www/22222/cert/22222.key 2048 &>> $EE_UPDATE_LOG \
|| ee_lib_error "Unable to generate SSL private key for port 22222, exit status = " $?
ee_lib_echo "Generating a certificate signing request (CSR)"
openssl req -new -batch -subj /commonName=127.0.0.1/ -key /var/www/22222/cert/22222.key -out /var/www/22222/cert/22222.csr &>> $EE_UPDATE_LOG \
|| ee_lib_error "Unable to generate certificate signing request (CSR) for port 22222, exit status = " $?
ee_lib_echo "Removing pass phrase from SSL private key"
mv /var/www/22222/cert/22222.key /var/www/22222/cert/22222.key.org
openssl rsa -in /var/www/22222/cert/22222.key.org -out /var/www/22222/cert/22222.key &>> $EE_UPDATE_LOG \
|| ee_lib_error "Unable to remove pass phrase from SSL for port 22222, exit status = " $?
ee_lib_echo "Generating SSL certificate"
openssl x509 -req -days 3652 -in /var/www/22222/cert/22222.csr -signkey /var/www/22222/cert/22222.key -out /var/www/22222/cert/22222.crt &>> $EE_UPDATE_LOG \
|| ee_lib_error "Unable to generate SSL certificate for port 22222, exit status = " $?
# Update PHP configuration
dpkg -l | grep php5-fpm &>> $EE_UPDATE_LOG
if [ $? -eq 0 ]; then
ee_lib_echo "Installing php5-xdebug package, please wait..."
apt-get -y install php5-xdebug \
|| ee_lib_error "Unable to install php5-xdebug package, exit status = " $?
ee_lib_echo "Setting up PHP5, please wait..."
# Custom php5 log directory
if [ ! -d /var/log/php5/ ]; then
mkdir -p /var/log/php5/ \
|| ee_lib_error "Unable to create /var/log/PHP5/, exit status = " $?
fi
# Update timezone
local ee_time_zone=$(cat /etc/timezone | head -n1 | sed "s'/'\\\/'")
sed -i "s/;date.timezone.*/date.timezone = $ee_time_zone/" /etc/php5/fpm/php.ini
# Change php5-fpm error log location
sed -i "s'error_log.*'error_log = /var/log/php5/fpm.log'" /etc/php5/fpm/php-fpm.conf
# Separate php5-fpm for ee debug command
cp -v /etc/php5/fpm/pool.d/www.conf /etc/php5/fpm/pool.d/debug.conf
sed -i "s'\[www\]'[debug]'" /etc/php5/fpm/pool.d/debug.conf \
|| ee_lib_error "Unable to change debug pool name, exit status = " $?
sed -i "s'listen = 127.0.0.1:9000'listen = 127.0.0.1:9001'" /etc/php5/fpm/pool.d/debug.conf \
|| ee_lib_error "Unable to change listen = 127.0.0.1:9001 for debug pool, exit status = " $?
sed -i "s';slowlog.*'slowlog = /var/log/php5/slow.log'" /etc/php5/fpm/pool.d/debug.conf \
|| ee_lib_error "Unable to change slowlog settings for debug pool, exit status = " $?
sed -i "s';request_slowlog_timeout.*'request_slowlog_timeout = 10s'" /etc/php5/fpm/pool.d/debug.conf \
|| ee_lib_error "Unable to change request_slowlog_timeout for debug pool, exit status = " $?
echo -e "php_admin_value[xdebug.profiler_output_dir] = /tmp/ \nphp_admin_value[xdebug.profiler_output_name] = cachegrind.out.%p-%H-%R \nphp_admin_flag[xdebug.profiler_enable_trigger] = on \nphp_admin_flag[xdebug.profiler_enable] = off" | tee -ai /etc/php5/fpm/pool.d/debug.conf &>> $EE_UPDATE_LOG \
|| ee_lib_error "Unable to add xdebug settings for debug pool, exit status = " $?
fi
dpkg -l | grep mysql-server &>> $EE_UPDATE_LOG
if [ $? -eq 0 ]; then
ee_lib_echo "Installing percona-toolkit package, please wait..."
apt-get -y install percona-toolkit \
|| ee_lib_error "Unable to install percona-toolkit package, exit status = " $?
fi
# Install 22222 admin tools
ee_ven_install_utils
ee_ven_install_phpmyadmin
# Update EasyEngine current version
EE_CURRENT_VERSION="1.3.0"
fi
if [[ $EE_CURRENT_VERSION = 1.3.0 ]] || [[ $EE_CURRENT_VERSION = 1.3.1 ]] || [[ $EE_CURRENT_VERSION = 1.3.2 ]] || [[ $EE_CURRENT_VERSION = 1.3.3 ]]; then
grep "^pm = ondemand" /etc/php5/fpm/pool.d/www.conf &>> $EE_UPDATE_LOG
if [ $? -ne 0 ]; then
sed -i "s/pm = dynamic/pm = ondemand/" /etc/php5/fpm/pool.d/www.conf \
|| ee_lib_error "Unable to change process manager from dynamic to ondemand, exit status = " $?
fi
grep "^pm = ondemand" /etc/php5/fpm/pool.d/debug.conf &>> $EE_UPDATE_LOG
if [ $? -ne 0 ]; then
sed -i "s/pm = dynamic/pm = ondemand/" /etc/php5/fpm/pool.d/debug.conf \
|| ee_lib_error "Unable to change process manager from dynamic to ondemand on debug.conf, exit status = " $?
fi
# Update EasyEngine current version
EE_CURRENT_VERSION="1.3.4"
fi
if [[ $EE_CURRENT_VERSION = 1.3.4 ]] || [[ $EE_CURRENT_VERSION = 1.3.5 ]] || [[ $EE_CURRENT_VERSION = 1.3.6 ]] || [[ $EE_CURRENT_VERSION = 1.3.7 ]] || [[ $EE_CURRENT_VERSION = 1.3.8 ]]; then
# Update 22222 for fix #259
cp -av /usr/share/easyengine/nginx/22222 /etc/nginx/sites-available/ &>> $EE_UPDATE_LOG
if [ "$EE_LINUX_DISTRO" == "Debian" ]; then
# Dotdeb nginx repository doesn't support spdy
sed -i "s/ spdy//;" /usr/share/easyengine/nginx/22222
fi
# Update NGINX
if [ "$EE_LINUX_DISTRO" == "Ubuntu" ]; then
nginx -v 2>&1 | grep 1.6.0 &>> $EE_UPDATE_LOG
if [ $? -ne 0 ]; then
rm /etc/apt/sources.list.d/brianmercer-nginx*
# Add rtCamp nginx launchpad repository
ee_lib_echo "Adding rtCamp NGINX launchpad repository, please wait..."
add-apt-repository -y ppa:rtcamp/nginx &>> $EE_UPDATE_LOG \
|| ee_lib_error "Unable to add rtCamp NGINX launchpad repository, exit status = " $?
# Execute: apt-get update
ee_lib_apt_get_update
# Install NGINX
apt-get -o Dpkg::Options::="--force-confold" -y install nginx-custom \
|| ee_lib_error "Unable to install nginx-custom package, exit status = " $?
fi
fi
# Update EasyEngine current version
EE_CURRENT_VERSION="2.0.0"
fi
fi
if [[ $EE_CURRENT_VERSION < 2.0.1 ]]; then
# Lets re-used our functions
# Include library
for ee_include in $(find /usr/local/lib/easyengine/ -iname "*.sh"); do
source $ee_include
done
if [[ $EE_CURRENT_VERSION = 2.0.0 ]]; then
dpkg -l | grep php5-fpm &>> $EE_UPDATE_LOG
if [ $? -eq 0 ]; then
# WP-CLI change the installation method
rm -rf /usr/share/easyengine/wp-cli /usr/share/wp-cli /usr/bin/wp /etc/bash_completion.d/wp-completion.bash
# Install WP-CLI
ee_ven_install_wpcli
fi
fi
fi
# Restart service
ee_lib_service nginx php5-fpm restart
# Git backup
ee_lib_git /etc/nginx/ /etc/php5/ /etc/mysql/ /etc/postfix /etc/easyengine "EasyEngine version $EE_LATEST_VERSION"
# Enable EasyEngine (ee) auto completion
echo
ee_lib_echo "For EasyEngine (ee) auto completion, run the following command" | tee -ai $EE_UPDATE_LOG
ee_lib_echo_info "source /etc/bash_completion.d/ee" | tee -ai $EE_UPDATE_LOG
echo
ee_lib_echo "EasyEngine (ee) updated successfully"
fi
else
ee_lib_echo "Latest version ($EE_CURRENT_VERSION) already installed"
fi