Browse Source

Optimise ee site update code

bugfixes
Mitesh Shah 10 years ago
parent
commit
04a87d4a87
  1. 189
      bin/easyengine
  2. 35
      src/modules/site/create/ee_mod_plugin_settings.sh
  3. 17
      src/modules/site/create/ee_mod_setup_wordpress.sh
  4. 93
      src/modules/site/update/ee_mod_update_domain.sh
  5. 129
      src/modules/site/update/ee_mod_update_nginx.sh

189
bin/easyengine

@ -456,22 +456,6 @@ elif [ "$EE_FIRST" = "site" ]; then
# Setup WordPress
ee_mod_setup_wordpress
# Setup WordPress Network
if [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then
ee_mod_setup_network
fi
# Install WordPress plugins
ee_mod_plugin_nginx_helper
if [ "$EE_SITE_CACHE_OPTION" = "--wpsc" ]; then
ee_mod_plugin_wpsc
fi
if [ "$EE_SITE_CACHE_OPTION" = "--w3tc" ] || [ "$EE_SITE_CACHE_OPTION" = "--wpfc" ]; then
ee_mod_plugin_w3tc
fi
# Adjust permission
ee_lib_permissions
@ -493,38 +477,8 @@ elif [ "$EE_FIRST" = "site" ]; then
ee_lib_echo_info "WordPress Admin Password: $EE_WP_PASS"
echo
# Configure WordPress plugin settings
if [ "$EE_SITE_CACHE_OPTION" = "--wpsc" ]; then
if [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then
ee_lib_echo_escape "Configure WPSC:\t\thttp://$EE_DOMAIN/wp-admin/network/settings.php?page=wpsupercache"
else
ee_lib_echo_escape "Configure WPSC:\t\thttp://$EE_DOMAIN/wp-admin/options-general.php?page=wpsupercache"
fi
fi
if [ "$EE_SITE_CACHE_OPTION" = "--wpfc" ]; then
if [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then
ee_lib_echo_escape "Configure nginx-helper:\thttp://$EE_DOMAIN/wp-admin/network/settings.php?page=nginx"
else
ee_lib_echo_escape "Configure nginx-helper:\thttp://$EE_DOMAIN/wp-admin/options-general.php?page=nginx"
fi
fi
if [ "$EE_SITE_CACHE_OPTION" = "--w3tc" ] || [ "$EE_SITE_CACHE_OPTION" = "--wpfc" ]; then
if [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then
ee_lib_echo_escape "Configure W3TC:\t\thttp://$EE_DOMAIN/wp-admin/network/admin.php?page=w3tc_general"
else
ee_lib_echo_escape "Configure W3TC:\t\thttp://$EE_DOMAIN/wp-admin/admin.php?page=w3tc_general"
fi
if [ "$EE_SITE_CACHE_OPTION" = "--wpfc" ]; then
ee_lib_echo_escape "Page Cache:\t\tDisable"
elif [ "$EE_SITE_CACHE_OPTION" = "--w3tc" ]; then
ee_lib_echo_escape "Page Cache:\t\tDisk Enhanced"
fi
ee_lib_echo_escape "Database Cache:\t\tMemcached"
ee_lib_echo_escape "Object Cache:\t\tMemcached"
ee_lib_echo_escape "Browser Cache:\t\tDisable"
fi
# Display WordPress cache plugin settings
ee_mod_plugin_settings
# Display Success Message
ee_lib_echo_info "Successfully created new website: http://$EE_WWW_DOMAIN"
@ -582,67 +536,33 @@ elif [ "$EE_FIRST" = "site" ]; then
# Check the website name is empty or not
ee_lib_check_domain
# Check the website exist
ls /etc/nginx/sites-available/$EE_DOMAIN &> /dev/null \
|| ee_lib_error "The $EE_DOMAIN is not found in /etc/nginx/sites-available, exit status = " $?
# Update WordPress user password
if [ "$EE_SITE_CREATE_OPTION" = "--password" ]; then
ee_mod_site_update_password
else
# Auto switch site options
ee_mod_site_option
EE_SITE_CURRENT_OPTION=$(head -n1 /etc/nginx/sites-available/$EE_DOMAIN | grep "NGINX CONFIGURATION" | rev | cut -d' ' -f3,4,5,6,7 | rev | cut -d ' ' -f2,3,4,5)
if [ "$EE_SITE_CREATE_OPTION" = "--html" ] || [ "$EE_SITE_CREATE_OPTION" = "--php" ] || [ "$EE_SITE_CREATE_OPTION" = "--mysql" ]; then
EE_NGINX_CONF=$(echo $EE_SITE_CREATE_OPTION | cut -c3-)/basic.conf
elif [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then
if [ "$EE_SITE_CACHE_OPTION" = "--basic" ] || [ "$EE_SITE_CACHE_OPTION" = "--wpsc" ] || [ "$EE_SITE_CACHE_OPTION" = "--w3tc" ] || [ "$EE_SITE_CACHE_OPTION" = "--wpfc" ]; then
EE_NGINX_CONF=$(echo $EE_SITE_CREATE_OPTION | cut -c3-)/$(echo $EE_SITE_CACHE_OPTION | cut -c3-).conf
fi
fi
# Let's use variable name as per action
# EE_SITE_CREATE_OPTION=$EE_SITE_CREATE_OPTION
# Install required packages
ee_mod_site_packages
# Lets update HTML|PHP|MySQL website
if [ "$EE_SITE_CURRENT_OPTION" = "HTML" ] || [ "$EE_SITE_CURRENT_OPTION" = "PHP" ] || [ "$EE_SITE_CURRENT_OPTION" = "MYSQL" ]; then
# Update NGINX configuration for $EE_DOMAIN
if [[ "$EE_SITE_CREATE_OPTION" = "--php" && "$EE_SITE_CURRENT_OPTION" != "PHP" ]] || [[ "$EE_SITE_CREATE_OPTION" = "--mysql" && "$EE_SITE_CURRENT_OPTION" != "MYSQL" ]] \
|| [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ]; then
ee_mod_update_domain
else
ee_lib_error "$EE_DOMAIN already with $EE_SITE_CREATE_OPTION $EE_SITE_CACHE_OPTION options, exit status" $?
fi
# Check the website exist or not
ls /etc/nginx/sites-available/$EE_DOMAIN &> /dev/null \
|| ee_lib_error "The $EE_DOMAIN does not exist, exit status = " $?
# Setup WordPress
if [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ]; then
if [ "$EE_SITE_CURRENT_OPTION" = "MYSQL" ]; then
# Sets EE_DB_NAME, EE_DB_USER, EE_DB_PASS variables, so that same database can be used while updating MYSQL site to any WordPress site
EE_DB_NAME=$(grep DB_NAME $(grep root /etc/nginx/sites-available/$EE_DOMAIN | awk '{ print $2 }' | sed 's/;//g' | sed "s'htdocs'backup/htdocs/$EE_DATE/ee-config.php'" 2> /dev/null) | cut -d"'" -f4)
EE_DB_USER=$(grep DB_USER $(grep root /etc/nginx/sites-available/$EE_DOMAIN | awk '{ print $2 }' | sed 's/;//g' | sed "s'htdocs'backup/htdocs/$EE_DATE/ee-config.php'" 2> /dev/null) | cut -d"'" -f4)
EE_DB_PASS=$(grep DB_PASSWORD $(grep root /etc/nginx/sites-available/$EE_DOMAIN | awk '{ print $2 }' | sed 's/;//g' | sed "s'htdocs'backup/htdocs/$EE_DATE/ee-config.php'" 2> /dev/null) | cut -d"'" -f4)
fi
ee_mod_setup_wordpress
fi
# Find out information about current NGINX configuration
EE_SITE_CURRENT_OPTION=$(head -n1 /etc/nginx/sites-available/$EE_DOMAIN | grep "NGINX CONFIGURATION" | rev | cut -d' ' -f3,4,5,6,7 | rev | cut -d ' ' -f2,3,4,5)
# Setup WordPress Network
if [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then
ee_mod_setup_network
fi
# Lets update HTML|PHP website
#if [ "$EE_SITE_CURRENT_OPTION" = "HTML" ] || [ "$EE_SITE_CURRENT_OPTION" = "PHP" ]; then
if [[ "$EE_SITE_CURRENT_OPTION" = "HTML" && "$EE_SITE_CREATE_OPTION" != "--html" ]] || [[ "$EE_SITE_CURRENT_OPTION" = "PHP" && "$EE_SITE_CREATE_OPTION" != "--html" && "$EE_SITE_CREATE_OPTION" != "--php" ]]; then
# Let's take backup first
ee_mod_site_backup
# Install WordPress plugins
if [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ]; then
ee_mod_plugin_nginx_helper
fi
# Install required packages
ee_mod_site_packages
# Update cache plugins
ee_mod_update_plugins
# Let's start update
ee_mod_update_nginx
# Setup MySQL database
if [[ "$EE_SITE_CREATE_OPTION" = "--mysql" && "$EE_SITE_CURRENT_OPTION" != "MYSQL" ]]; then
if [ "$EE_SITE_CREATE_OPTION" = "--mysql" ]; then
ee_mod_setup_database
# Add Database Information On ee-config.php
@ -650,72 +570,16 @@ elif [ "$EE_FIRST" = "site" ]; then
&>> /var/www/$EE_DOMAIN/ee-config.php
fi
if [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ]; then
# Display WordPress credential
echo
ee_lib_echo_info "WordPress Admin Username: $EE_WP_USER"
ee_lib_echo_info "WordPress Admin Password: $EE_WP_PASS"
echo
fi
# Lets update WordPress Single sites
# WordPress Single sites can only be updated to multisites or with different cache options
elif [ "$EE_SITE_CURRENT_OPTION" = "WPSINGLE BASIC" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSINGLE W3 TOTAL CACHE" ] \
|| [ "$EE_SITE_CURRENT_OPTION" = "WPSINGLE FAST CGI" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSINGLE WP SUPER CACHE" ] \
&& [[ "$EE_SITE_CREATE_OPTION" = "--wp" || "$EE_SITE_CREATE_OPTION" = "--wpsubdir" || "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]]; then
# Setup WordPress
if [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then
# Setup WordPress
ee_mod_setup_wordpress
if [[ "$EE_SITE_CACHE_OPTION" = "--basic" && "$EE_SITE_CURRENT_OPTION" != "WPSINGLE BASIC" ]] \
|| [[ "$EE_SITE_CACHE_OPTION" = "--wpfc" && "$EE_SITE_CURRENT_OPTION" != "WPSINGLE FAST CGI" ]] \
|| [[ "$EE_SITE_CACHE_OPTION" = "--w3tc" && "$EE_SITE_CURRENT_OPTION" != "WPSINGLE W3 TOTAL CACHE" ]] \
|| [[ "$EE_SITE_CACHE_OPTION" = "--wpsc" && "$EE_SITE_CURRENT_OPTION" != "WPSINGLE WP SUPER CACHE" ]] \
|| [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ]; then
# Update NGINX configuration for $EE_DOMAIN
ee_mod_update_domain
else
ee_lib_error "$EE_DOMAIN already with $EE_SITE_CREATE_OPTION $EE_SITE_CACHE_OPTION options, exit status" $?
fi
# Setup WordPress Network
if [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then
ee_mod_setup_network
fi
# Update cache plugins
ee_mod_update_plugins
# Lets update WprdPress multi sites with subdirectory
# WordPress multi sites with subdirectory can only update cache
elif [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDIR BASIC" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDIR W3 TOTAL CACHE" ] \
|| [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDIR FAST CGI" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDIR WP SUPER CACHE" ] && [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ]; then
if [[ "$EE_SITE_CACHE_OPTION" = "--basic" && "$EE_SITE_CURRENT_OPTION" != "WPSUBDIR BASIC" ]] \
|| [[ "$EE_SITE_CACHE_OPTION" = "--wpfc" && "$EE_SITE_CURRENT_OPTION" != "WPSUBDIR FAST CGI" ]] \
|| [[ "$EE_SITE_CACHE_OPTION" = "--w3tc" && "$EE_SITE_CURRENT_OPTION" != "WPSUBDIR W3 TOTAL CACHE" ]] \
|| [[ "$EE_SITE_CACHE_OPTION" = "--wpsc" && "$EE_SITE_CURRENT_OPTION" != "WPSUBDIR WP SUPER CACHE" ]]; then
# Update NGINX configuration for $EE_DOMAIN
ee_mod_update_domain
else
ee_lib_error "$EE_DOMAIN already with $EE_SITE_CREATE_OPTION $EE_SITE_CACHE_OPTION options, exit status" $?
fi
# Update cache plugins
ee_mod_update_plugins
# Lets update WordPress multi sites with subdomain
# WordPress multi sites with subdomain can only update cache
elif [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDOMAIN BASIC" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDOMAIN W3 TOTAL CACHE" ] \
|| [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDOMAIN FAST CGI" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDOMAIN WP SUPER CACHE" ] && [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then
if [[ "$EE_SITE_CACHE_OPTION" = "--basic" && "$EE_SITE_CURRENT_OPTION" != "WPSUBDOMAIN BASIC" ]] \
|| [[ "$EE_SITE_CACHE_OPTION" = "--wpfc" && "$EE_SITE_CURRENT_OPTION" != "WPSUBDOMAIN FAST CGI" ]] \
|| [[ "$EE_SITE_CACHE_OPTION" = "--w3tc" && "$EE_SITE_CURRENT_OPTION" != "WPSUBDOMAIN W3 TOTAL CACHE" ]] \
|| [[ "$EE_SITE_CACHE_OPTION" = "--wpsc" && "$EE_SITE_CURRENT_OPTION" != "WPSUBDOMAIN WP SUPER CACHE" ]]; then
# Update NGINX configuration for $EE_DOMAIN
ee_mod_update_domain
else
ee_lib_error "$EE_DOMAIN already with $EE_SITE_CREATE_OPTION $EE_SITE_CACHE_OPTION options, exit status" $?
# Display WordPress cache plugin settings
ee_mod_plugin_settings
fi
# Update cache plugins
ee_mod_update_plugins
else
ee_lib_error "Invalid update option, exit status =" $?
fi
# Adjust permission
ee_lib_permissions
@ -727,7 +591,6 @@ elif [ "$EE_FIRST" = "site" ]; then
# Display Success Message
ee_lib_echo_info "Successfully Updated Website: http://$EE_WWW_DOMAIN"
fi
elif [ "$EE_SECOND" = "log" ]; then
# Display logs for websites
ee_mod_site_log ${@:3}

35
src/modules/site/create/ee_mod_plugin_settings.sh

@ -0,0 +1,35 @@
# Display WordPress cache plugin settings
function ee_mod_plugin_settings() {
if [ "$EE_SITE_CACHE_OPTION" = "--wpsc" ]; then
if [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then
ee_lib_echo_escape "Configure WPSC:\t\thttp://$EE_DOMAIN/wp-admin/network/settings.php?page=wpsupercache"
else
ee_lib_echo_escape "Configure WPSC:\t\thttp://$EE_DOMAIN/wp-admin/options-general.php?page=wpsupercache"
fi
fi
if [ "$EE_SITE_CACHE_OPTION" = "--wpfc" ]; then
if [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then
ee_lib_echo_escape "Configure nginx-helper:\thttp://$EE_DOMAIN/wp-admin/network/settings.php?page=nginx"
else
ee_lib_echo_escape "Configure nginx-helper:\thttp://$EE_DOMAIN/wp-admin/options-general.php?page=nginx"
fi
fi
if [ "$EE_SITE_CACHE_OPTION" = "--w3tc" ] || [ "$EE_SITE_CACHE_OPTION" = "--wpfc" ]; then
if [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then
ee_lib_echo_escape "Configure W3TC:\t\thttp://$EE_DOMAIN/wp-admin/network/admin.php?page=w3tc_general"
else
ee_lib_echo_escape "Configure W3TC:\t\thttp://$EE_DOMAIN/wp-admin/admin.php?page=w3tc_general"
fi
if [ "$EE_SITE_CACHE_OPTION" = "--wpfc" ]; then
ee_lib_echo_escape "Page Cache:\t\tDisable"
elif [ "$EE_SITE_CACHE_OPTION" = "--w3tc" ]; then
ee_lib_echo_escape "Page Cache:\t\tDisk Enhanced"
fi
ee_lib_echo_escape "Database Cache:\t\tMemcached"
ee_lib_echo_escape "Object Cache:\t\tMemcached"
ee_lib_echo_escape "Browser Cache:\t\tDisable"
fi
}

17
src/modules/site/create/ee_mod_setup_wordpress.sh

@ -121,4 +121,21 @@ function ee_mod_setup_wordpress()
ee_lib_echo "Updating WordPress permalink, please wait..."
wp rewrite structure --allow-root /%year%/%monthnum%/%day%/%postname%/ &>> $EE_COMMAND_LOG \
|| ee_lib_error "Unable to update WordPress permalink for $EE_DOMAIN, exit status = " $?
# Setup WordPress Network
if [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then
ee_mod_setup_network
fi
# Install WordPress plugins
ee_mod_plugin_nginx_helper
if [ "$EE_SITE_CACHE_OPTION" = "--wpsc" ]; then
ee_mod_plugin_wpsc
fi
if [ "$EE_SITE_CACHE_OPTION" = "--w3tc" ] || [ "$EE_SITE_CACHE_OPTION" = "--wpfc" ]; then
ee_mod_plugin_w3tc
fi
}

93
src/modules/site/update/ee_mod_update_domain.sh

@ -1,93 +0,0 @@
# Update NGINX configuration for $EE_DOMAIN
function ee_mod_update_domain()
{
# Git commit
ee_lib_git /etc/nginx/ "Before ee site update: $EE_DOMAIN running on $EE_SITE_CURRENT_OPTION"
# Backup NGINX configuration & Database & Webroot
ee_mod_site_backup
# Creating $EE_DOMAIN
ee_lib_echo "Updating $EE_DOMAIN, please wait..."
if [ -f /etc/nginx/sites-available/$EE_DOMAIN ]; then
EE_SITE_CURRENT_CONF=$(head -n1 /etc/nginx/sites-available/$EE_DOMAIN | grep "NGINX CONFIGURATION")
EE_SITE_UPDATE_CONF=$(head -n1 /usr/share/easyengine/nginx/$EE_NGINX_CONF | grep "NGINX CONFIGURATION")
EE_SITE_NGINX_CONF="/etc/nginx/sites-available/$EE_DOMAIN"
# Update Head Line of NGINX conf
sed -i "s'$EE_SITE_CURRENT_CONF'$EE_SITE_UPDATE_CONF'" $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
# Update Head Line of NGINX conf file
if [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ] \
&& [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDOMAIN BASIC" ] && [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDIR BASIC" ] \
&& [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDOMAIN WP SUPER CACHE" ] && [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDIR WP SUPER CACHE" ] \
&& [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDOMAIN FAST CGI" ] && [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDIR FAST CGI" ] \
&& [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDOMAIN W3 TOTAL CACHE" ] && [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDIR W3 TOTAL CACHE" ];then
sed -i "s'server_name $EE_DOMAIN www.$EE_DOMAIN;'server_name $EE_DOMAIN *.$EE_DOMAIN;'" $EE_SITE_NGINX_CONF && \
sed -i '/server_name.*;/i \\t# Uncomment the following line for domain mapping;\n\t# listen 80 default_server;\n' $EE_SITE_NGINX_CONF && \
sed -i '/server_name.*;/a \\n\t# Uncomment the following line for domain mapping \n\t#server_name_in_redirect off;' $EE_SITE_NGINX_CONF && \
sed -i '/include common\/locations.conf/i \\tinclude common\/wpsubdir.conf;' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
fi
# Update NGINX conf for HTML site
if [ "$EE_SITE_CURRENT_OPTION" = "HTML" ]; then
sed -i 's/access\.log/access.log rt_cache/' $EE_SITE_NGINX_CONF && \
sed -i '/index index.html index.htm;$/d' $EE_SITE_NGINX_CONF && \
sed -i '/location \/ {/,/}/c \\tindex index.php index.htm index.html;' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
if [ "$EE_SITE_CACHE_OPTION" = "--basic" ] || [[ "$EE_SITE_CREATE_OPTION" = "--php" || "$EE_SITE_CREATE_OPTION" = "--mysql" ]]; then
sed -i '/include common\/locations.conf/i \\tinclude common\/php.conf;' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--wpfc" ]; then
sed -i '/include common\/locations.conf/i \\tinclude common\/wpfc.conf;' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--wpsc" ]; then
sed -i '/include common\/locations.conf/i \\tinclude common\/wpsc.conf;' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--w3tc" ]; then
sed -i '/include common\/locations.conf/i \\tinclude common\/w3tc.conf;' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
fi
# Update NGINX conf from BASIC CACHE to WPFC|W3TC|WPSC CACHE
elif [ "$EE_SITE_CURRENT_OPTION" = "PHP" ] || [ "$EE_SITE_CURRENT_OPTION" = "MYSQL" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSINGLE BASIC" ] \
|| [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDIR BASIC" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDOMAIN BASIC" ]; then
if [ "$EE_SITE_CACHE_OPTION" = "--wpfc" ]; then
sed -i 's/include common\/php.conf/include common\/wpfc.conf/' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--wpsc" ]; then
sed -i 's/include common\/php.conf/include common\/wpsc.conf/' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--w3tc" ]; then
sed -i 's/include common\/php.conf/include common\/w3tc.conf/' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
fi
# Update NGINX conf from W3TC CACHE to BASIC|WPSC|WPFC CACHE
elif [ "$EE_SITE_CURRENT_OPTION" = "WPSINGLE W3 TOTAL CACHE" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDIR W3 TOTAL CACHE" ] \
|| [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDOMAIN W3 TOTAL CACHE" ]; then
if [ "$EE_SITE_CACHE_OPTION" = "--wpfc" ]; then
sed -i 's/include common\/w3tc.conf/include common\/wpfc.conf/' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--wpsc" ]; then
sed -i 's/include common\/w3tc.conf/include common\/wpsc.conf/' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--basic" ]; then
sed -i 's/include common\/w3tc.conf/include common\/php.conf/' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
fi
# Update NGINX conf from WPFC CACHE to BASIC|W3TC|WPSC CACHE
elif [ "$EE_SITE_CURRENT_OPTION" = "WPSINGLE FAST CGI" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDIR FAST CGI" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDOMAIN FAST CGI" ]; then
if [ "$EE_SITE_CACHE_OPTION" = "--basic" ]; then
sed -i 's/include common\/wpfc.conf/include common\/php.conf/' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--wpsc" ]; then
sed -i 's/include common\/wpfc.conf/include common\/wpsc.conf/' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--w3tc" ]; then
sed -i 's/include common\/wpfc.conf/include common\/w3tc.conf/' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
fi
# Update NGINX conf from WPSC CACHE to BASIC|W3TC|WPFC CACHE
elif [ "$EE_SITE_CURRENT_OPTION" = "WPSINGLE WP SUPER CACHE" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDIR WP SUPER CACHE" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDOMAIN WP SUPER CACHE" ]; then
if [ "$EE_SITE_CACHE_OPTION" = "--basic" ]; then
sed -i 's/include common\/wpsc.conf/include common\/php.conf/' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--wpfc" ]; then
sed -i 's/include common\/wpsc.conf/include common\/wpfc.conf/' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--w3tc" ]; then
sed -i 's/include common\/wpfc.conf/include common\/w3tc.conf/' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
fi
fi
# Update NGINX conf from HTML|PHP|MYSQL to wp|wpsubdir|wpsubdomain
if [[ "$EE_SITE_CREATE_OPTION" = "--wp" || "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" || "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ]] \
&& [[ "$EE_SITE_CURRENT_OPTION" = "HTML" || "$EE_SITE_CURRENT_OPTION" = "PHP" || "$EE_SITE_CURRENT_OPTION" = "MYSQL" ]]; then
sed -i '/include common\/locations.conf/i \\tinclude common\/wpcommon.conf;' $EE_SITE_NGINX_CONF || ee_lib_error "Unable to update nginx configuration to $EE_SITE_CREATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
fi
else
ee_lib_error "Unable to find $EE_DOMAIN NGINX configuration, exit status =" $?
fi
}

129
src/modules/site/update/ee_mod_update_nginx.sh

@ -0,0 +1,129 @@
# Update NGINX configuration for $EE_DOMAIN
function ee_mod_update_nginx()
{
# Find out information about current NGINX configuration
EE_SITE_CURRENT_OPTION=$(head -n1 /etc/nginx/sites-available/$EE_DOMAIN | grep "NGINX CONFIGURATION" | rev | cut -d' ' -f3,4,5,6,7 | rev | cut -d ' ' -f2,3,4,5)
# Git commit
ee_lib_git /etc/nginx/ "Before ee site update: $EE_DOMAIN running on $EE_SITE_CURRENT_OPTION"
# Update NGINX configuration
ee_lib_echo "Updating $EE_DOMAIN, please wait..."
if [ -f /etc/nginx/sites-available/$EE_DOMAIN ]; then
# Find out current NGINX configuration header
ee_nginx_current_header=$(head -n1 /etc/nginx/sites-available/$EE_DOMAIN | grep "NGINX CONFIGURATION")
# Update NGINX configuration header
if [ "$EE_SITE_UPDATE_OPTION" = "--html" ] || [ "$EE_SITE_UPDATE_OPTION" = "--php" ] || [ "$EE_SITE_UPDATE_OPTION" = "--mysql" ]; then
ee_nginx_conf=$(echo $EE_SITE_UPDATE_OPTION | cut -c3-)/basic.conf
elif [ "$EE_SITE_CACHE_OPTION" = "--basic" ] || [ "$EE_SITE_CACHE_OPTION" = "--wpsc" ] || [ "$EE_SITE_CACHE_OPTION" = "--w3tc" ] || [ "$EE_SITE_CACHE_OPTION" = "--wpfc" ]; then
ee_nginx_conf=$(echo $EE_SITE_UPDATE_OPTION | cut -c3-)/$(echo $EE_SITE_CACHE_OPTION | cut -c3-).conf
fi
ee_nginx_update_header=$(head -n1 /usr/share/easyengine/nginx/$ee_nginx_conf | grep "NGINX CONFIGURATION")
# Update Head Line of NGINX conf
sed -i "s'$ee_nginx_current_header'$ee_nginx_update_header'" /etc/nginx/sites-available/$EE_DOMAIN || ee_lib_error "Unable to update nginx configuration to $EE_SITE_UPDATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
# Update NGINX conf for HTML site
if [ "$EE_SITE_CURRENT_OPTION" = "HTML" ]; then
sed -i 's/access\.log/access.log rt_cache/' /etc/nginx/sites-available/$EE_DOMAIN && \
sed -i '/index index.html index.htm;$/d' /etc/nginx/sites-available/$EE_DOMAIN && \
sed -i '/location \/ {/,/}/c \\tindex index.php index.htm index.html;' /etc/nginx/sites-available/$EE_DOMAIN \
|| ee_lib_error "Unable to update NGINX configuration to $EE_SITE_UPDATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $?
# Update HTML to PHP MySQL --basic (--wp/--wpsubdir/--wpsubdomain) options
if [ "$EE_SITE_UPDATE_OPTION" = "--php" ] || [ "$EE_SITE_UPDATE_OPTION" = "--mysql" ] || [ "$EE_SITE_CACHE_OPTION" = "--basic" ] || ; then
sed -i '/include common\/locations.conf/i \\tinclude common\/php.conf;' /etc/nginx/sites-available/$EE_DOMAIN \
|| ee_lib_error "Unable to update NGINX configuration to $EE_SITE_UPDATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $?
# Update HTML to --wpsc (--wp/--wpsubdir/--wpsubdomain) options
elif [ "$EE_SITE_CACHE_OPTION" = "--wpsc" ]; then
sed -i '/include common\/locations.conf/i \\tinclude common\/wpsc.conf;' /etc/nginx/sites-available/$EE_DOMAIN \
|| ee_lib_error "Unable to update NGINX configuration to $EE_SITE_UPDATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $?
# Update HTML to --w3tc (--wp/--wpsubdir/--wpsubdomain) options
elif [ "$EE_SITE_CACHE_OPTION" = "--w3tc" ]; then
sed -i '/include common\/locations.conf/i \\tinclude common\/w3tc.conf;' /etc/nginx/sites-available/$EE_DOMAIN \
|| ee_lib_error "Unable to update NGINX configuration to $EE_SITE_UPDATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $?
# Update HTML to --wpfc (--wp/--wpsubdir/--wpsubdomain) options
elif [ "$EE_SITE_CACHE_OPTION" = "--wpfc" ]; then
sed -i '/include common\/locations.conf/i \\tinclude common\/wpfc.conf;' /etc/nginx/sites-available/$EE_DOMAIN \
|| ee_lib_error "Unable to update NGINX configuration to $EE_SITE_UPDATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $?
fi
# Update PHP MySQL --basic (--wp/--wpsubdir/--wpsubdomain) to --wpsc --w3tc --wpfc options
elif [ "$EE_SITE_CURRENT_OPTION" = "PHP" ] || [ "$EE_SITE_CURRENT_OPTION" = "MYSQL" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSINGLE BASIC" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDIR BASIC" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDOMAIN BASIC" ]; then
if [ "$EE_SITE_CACHE_OPTION" = "--wpsc" ]; then
sed -i 's/include common\/php.conf/include common\/wpsc.conf/' /etc/nginx/sites-available/$EE_DOMAIN \
|| ee_lib_error "Unable to update NGINX configuration to $EE_SITE_UPDATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--w3tc" ]; then
sed -i 's/include common\/php.conf/include common\/w3tc.conf/' /etc/nginx/sites-available/$EE_DOMAIN \
|| ee_lib_error "Unable to update NGINX configuration to $EE_SITE_UPDATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--wpfc" ]; then
sed -i 's/include common\/php.conf/include common\/wpfc.conf/' /etc/nginx/sites-available/$EE_DOMAIN \
|| ee_lib_error "Unable to update NGINX configuration to $EE_SITE_UPDATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $?
fi
# Update --wpsc (--wp/--wpsubdir/--wpsubdomain) to --basic --w3tc --wpfc options
elif [ "$EE_SITE_CURRENT_OPTION" = "WPSINGLE WP SUPER CACHE" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDIR WP SUPER CACHE" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDOMAIN WP SUPER CACHE" ]; then
if [ "$EE_SITE_CACHE_OPTION" = "--basic" ]; then
sed -i 's/include common\/wpsc.conf/include common\/php.conf/' /etc/nginx/sites-available/$EE_DOMAIN \
|| ee_lib_error "Unable to update NGINX configuration to $EE_SITE_UPDATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--w3tc" ]; then
sed -i 's/include common\/wpfc.conf/include common\/w3tc.conf/' /etc/nginx/sites-available/$EE_DOMAIN \
|| ee_lib_error "Unable to update NGINX configuration to $EE_SITE_UPDATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--wpfc" ]; then
sed -i 's/include common\/wpsc.conf/include common\/wpfc.conf/' /etc/nginx/sites-available/$EE_DOMAIN \
|| ee_lib_error "Unable to update NGINX configuration to $EE_SITE_UPDATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $?
# Update --w3tc (--wp/--wpsubdir/--wpsubdomain) to --basic --wpsc --wpfc options
elif [ "$EE_SITE_CURRENT_OPTION" = "WPSINGLE W3 TOTAL CACHE" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDIR W3 TOTAL CACHE" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDOMAIN W3 TOTAL CACHE" ]; then
if [ "$EE_SITE_CACHE_OPTION" = "--basic" ]; then
sed -i 's/include common\/w3tc.conf/include common\/php.conf/' /etc/nginx/sites-available/$EE_DOMAIN \
|| ee_lib_error "Unable to update NGINX configuration to $EE_SITE_UPDATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--wpsc" ]; then
sed -i 's/include common\/w3tc.conf/include common\/wpsc.conf/' /etc/nginx/sites-available/$EE_DOMAIN \
|| ee_lib_error "Unable to update NGINX configuration to $EE_SITE_UPDATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--wpfc" ]; then
sed -i 's/include common\/w3tc.conf/include common\/wpfc.conf/' /etc/nginx/sites-available/$EE_DOMAIN \
|| ee_lib_error "Unable to update NGINX configuration to $EE_SITE_UPDATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $?
fi
# Update --wpfc (--wp/--wpsubdir/--wpsubdomain) to --basic --wpsc --w3tc options
elif [ "$EE_SITE_CURRENT_OPTION" = "WPSINGLE FAST CGI" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDIR FAST CGI" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDOMAIN FAST CGI" ]; then
if [ "$EE_SITE_CACHE_OPTION" = "--basic" ]; then
sed -i 's/include common\/wpfc.conf/include common\/php.conf/' /etc/nginx/sites-available/$EE_DOMAIN \
|| ee_lib_error "Unable to update NGINX configuration to $EE_SITE_UPDATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--wpsc" ]; then
sed -i 's/include common\/wpfc.conf/include common\/wpsc.conf/' /etc/nginx/sites-available/$EE_DOMAIN \
|| ee_lib_error "Unable to update NGINX configuration to $EE_SITE_UPDATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $?
elif [ "$EE_SITE_CACHE_OPTION" = "--w3tc" ]; then
sed -i 's/include common\/wpfc.conf/include common\/w3tc.conf/' /etc/nginx/sites-available/$EE_DOMAIN \
|| ee_lib_error "Unable to update NGINX configuration to $EE_SITE_UPDATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $?
fi
fi
# Add WordPress common file wpcommon.conf for HTML PHP & MYSQL sites
if [[ "$EE_SITE_CURRENT_OPTION" = "HTML" || "$EE_SITE_CURRENT_OPTION" = "PHP" || "$EE_SITE_CURRENT_OPTION" = "MYSQL" ]] && \
[[ "$EE_SITE_UPDATE_OPTION" = "--wp" || "$EE_SITE_UPDATE_OPTION" = "--wpsubdomain" || "$EE_SITE_UPDATE_OPTION" = "--wpsubdir" ]]; then
sed -i '/include common\/locations.conf/i \\tinclude common\/wpcommon.conf;' /etc/nginx/sites-available/$EE_DOMAIN || ee_lib_error "Unable to update nginx configuration to $EE_SITE_UPDATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
fi
# Update server_name for HTML PHP MYSQL WP (single site) only
# Don't execute for WordPress Multisite
if [ "$EE_SITE_UPDATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_UPDATE_OPTION" = "--wpsubdomain" ] \
&& [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDIR BASIC" ] && [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDOMAIN BASIC" ] \
&& [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDIR WP SUPER CACHE" ] && [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDOMAIN WP SUPER CACHE" ] \
&& [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDIR W3 TOTAL CACHE" ] && [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDOMAIN W3 TOTAL CACHE" ] \
&& [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDIR FAST CGI" ] && [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDOMAIN FAST CGI" ]; then
sed -i "s'server_name $EE_DOMAIN www.$EE_DOMAIN;'server_name $EE_DOMAIN *.$EE_DOMAIN;'" /etc/nginx/sites-available/$EE_DOMAIN && \
sed -i '/server_name.*;/i \\t# Uncomment the following line for domain mapping;\n\t# listen 80 default_server;\n' /etc/nginx/sites-available/$EE_DOMAIN && \
sed -i '/server_name.*;/a \\n\t# Uncomment the following line for domain mapping \n\t#server_name_in_redirect off;' /etc/nginx/sites-available/$EE_DOMAIN && \
sed -i '/include common\/locations.conf/i \\tinclude common\/wpsubdir.conf;' /etc/nginx/sites-available/$EE_DOMAIN || ee_lib_error "Unable to update nginx configuration to $EE_SITE_UPDATE_OPTION, $EE_SITE_CACHE_OPTION for $EE_DOMAIN, exit status =" $?
fi
else
ee_lib_error "Unable to find $EE_DOMAIN NGINX configuration, exit status =" $?
fi
}
Loading…
Cancel
Save