From 6111e4e52f516ac3d952a41377b7528655811b0b Mon Sep 17 00:00:00 2001 From: Mitesh Shah Date: Wed, 8 Oct 2014 13:36:08 +0530 Subject: [PATCH] Reuse code and comment codes --- bin/easyengine | 70 ++++++------------- src/lib/ee_lib_stack_packages.sh | 2 +- src/modules/site/ee_mod_site_packages.sh | 21 ++++++ .../site/update/ee_mod_update_cache.sh | 4 +- .../site/update/ee_mod_update_plugins.sh | 30 ++++++++ 5 files changed, 77 insertions(+), 50 deletions(-) create mode 100644 src/modules/site/ee_mod_site_packages.sh create mode 100644 src/modules/site/update/ee_mod_update_plugins.sh diff --git a/bin/easyengine b/bin/easyengine index b8a12e55..416f34b6 100644 --- a/bin/easyengine +++ b/bin/easyengine @@ -421,25 +421,8 @@ elif [ "$EE_FIRST" = "site" ]; then # Auto switch site options ee_mod_site_option - if [ "$EE_SITE_CREATE_OPTION" = "--html" ] || [ "$EE_SITE_CREATE_OPTION" = "--php" ] || [ "$EE_SITE_CREATE_OPTION" = "--mysql" ] || [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then - # Check & Install NGINX Packages - ee_lib_stack_packages nginx - fi - if [ "$EE_SITE_CREATE_OPTION" = "--php" ] || [ "$EE_SITE_CREATE_OPTION" = "--mysql" ] || [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then - # Check & Install PHP Packages - ee_lib_stack_packages php - fi - if [ "$EE_SITE_CREATE_OPTION" = "--mysql" ] || [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then - # Check & Install Percona MySQL Packages - ee_lib_stack_packages mysql - fi - - if [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then - # Install WP-CLI - ee_ven_install_wpcli - fi - # Check & Install Postfix Packages - ee_lib_stack_packages postfix + # Install required packages + ee_mod_site_packages # Lets create HTML|PHP|MySQL website if [ "$EE_SITE_CREATE_OPTION" = "--html" ] || [ "$EE_SITE_CREATE_OPTION" = "--php" ] || [ "$EE_SITE_CREATE_OPTION" = "--mysql" ]; then @@ -609,6 +592,7 @@ elif [ "$EE_FIRST" = "site" ]; then 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 @@ -625,44 +609,34 @@ elif [ "$EE_FIRST" = "site" ]; then fi # Install required packages - if [ "$EE_SITE_CREATE_OPTION" = "--html" ] || [ "$EE_SITE_CREATE_OPTION" = "--php" ] || [ "$EE_SITE_CREATE_OPTION" = "--mysql" ] || [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then - ee_lib_stack_packages nginx - fi - if [ "$EE_SITE_CREATE_OPTION" = "--php" ] || [ "$EE_SITE_CREATE_OPTION" = "--mysql" ] || [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then - ee_lib_stack_packages php - fi - if [ "$EE_SITE_CREATE_OPTION" = "--mysql" ] || [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then - ee_lib_stack_packages mysql - fi - - if [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then - ee_ven_install_wpcli - fi - ee_lib_stack_packages postfix + 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 - # Update NGINX ee_mod_update_domain fi + # Setup WordPress if [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ]; then ee_mod_setup_wordpress fi + # Setup WordPress Network if [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then ee_mod_setup_network fi + # Install WordPress plugins if [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ]; then - # Install WordPress plugins ee_mod_plugin_nginx_helper fi - ee_mod_update_cache + # Update cache plugins + ee_mod_update_plugins # Setup MySQL database if [[ "$EE_SITE_CREATE_OPTION" = "--mysql" && "$EE_SITE_CURRENT_OPTION" != "MYSQL" ]]; then @@ -689,16 +663,17 @@ elif [ "$EE_FIRST" = "site" ]; then || [[ "$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 + # Update NGINX configuration for $EE_DOMAIN ee_mod_update_domain else ee_lib_error "Site already, $EE_SITE_CREATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $? fi + # Setup WordPress Network if [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then ee_mod_setup_network fi - - ee_mod_update_cache + # Update cache plugins + ee_mod_update_plugins 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 @@ -706,13 +681,13 @@ elif [ "$EE_FIRST" = "site" ]; then || [[ "$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 + # Update NGINX configuration for $EE_DOMAIN ee_mod_update_domain else ee_lib_error "Site already, $EE_SITE_CREATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $? fi - - ee_mod_update_cache + # Update cache plugins + ee_mod_update_plugins 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 @@ -720,13 +695,13 @@ elif [ "$EE_FIRST" = "site" ]; then || [[ "$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 + # Update NGINX configuration for $EE_DOMAIN ee_mod_update_domain else ee_lib_error "Site already, $EE_SITE_CREATE_OPTION $EE_SITE_CACHE_OPTION, exit status =" $? fi - - ee_mod_update_cache + # Update cache plugins + ee_mod_update_plugins else ee_lib_error "Invalid update parameters, Use proper parameters, exit status =" $? @@ -747,7 +722,7 @@ elif [ "$EE_FIRST" = "site" ]; then # Display logs for websites ee_mod_site_log ${@:3} - #EasyEngine cd + # EasyEngine cd elif [ "$EE_SECOND" = "cd" ]; then # Check the website name is empty or not EE_DOMAIN_CHECK=$EE_THIRD @@ -885,10 +860,11 @@ elif [ "$EE_FIRST" = "secure" ]; then ee_lib_echo_escape "\t--ip\tUpdate whitelist IP address" fi -# Clean cache +# Clean NGINX FastCGI, Memcache, OPcache cache elif [ "$EE_FIRST" = "clean" ]; then ee_mod_clean ${@:2} +# Import MySQL slow log to Anememoter elif [ "$EE_FIRST" = "import-slow-log" ];then ee_lib_import_slow_log diff --git a/src/lib/ee_lib_stack_packages.sh b/src/lib/ee_lib_stack_packages.sh index a75f18b3..39d6eaa4 100644 --- a/src/lib/ee_lib_stack_packages.sh +++ b/src/lib/ee_lib_stack_packages.sh @@ -1,4 +1,4 @@ -# Check the specified package is installed or not +# Check & Install Packages function ee_lib_stack_packages() { diff --git a/src/modules/site/ee_mod_site_packages.sh b/src/modules/site/ee_mod_site_packages.sh new file mode 100644 index 00000000..edf448cf --- /dev/null +++ b/src/modules/site/ee_mod_site_packages.sh @@ -0,0 +1,21 @@ +# Install required packages + +if [ "$EE_SITE_CREATE_OPTION" = "--html" ] || [ "$EE_SITE_CREATE_OPTION" = "--php" ] || [ "$EE_SITE_CREATE_OPTION" = "--mysql" ] || [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then + # Check & Install NGINX Packages + ee_lib_stack_packages nginx +fi +if [ "$EE_SITE_CREATE_OPTION" = "--php" ] || [ "$EE_SITE_CREATE_OPTION" = "--mysql" ] || [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then + # Check & Install PHP Packages + ee_lib_stack_packages php +fi +if [ "$EE_SITE_CREATE_OPTION" = "--mysql" ] || [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then + # Check & Install Percona MySQL Packages + ee_lib_stack_packages mysql +fi + +if [ "$EE_SITE_CREATE_OPTION" = "--wp" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then + # Install WP-CLI + ee_ven_install_wpcli +fi +# Check & Install Postfix Packages +ee_lib_stack_packages postfix diff --git a/src/modules/site/update/ee_mod_update_cache.sh b/src/modules/site/update/ee_mod_update_cache.sh index d53ecdce..38eec6d7 100644 --- a/src/modules/site/update/ee_mod_update_cache.sh +++ b/src/modules/site/update/ee_mod_update_cache.sh @@ -1,6 +1,6 @@ -# Update Cache +# Update cache plugins -function ee_mod_update_cache() +function ee_mod_update_plugins() { cd /var/www/$EE_DOMAIN/htdocs/ diff --git a/src/modules/site/update/ee_mod_update_plugins.sh b/src/modules/site/update/ee_mod_update_plugins.sh new file mode 100644 index 00000000..38eec6d7 --- /dev/null +++ b/src/modules/site/update/ee_mod_update_plugins.sh @@ -0,0 +1,30 @@ +# Update cache plugins + +function ee_mod_update_plugins() +{ + cd /var/www/$EE_DOMAIN/htdocs/ + + if [ "$EE_SITE_CURRENT_OPTION" = "WPSINGLE W3 TOTAL CACHE" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSINGLE FAST CGI" ] \ + || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDIR W3 TOTAL CACHE" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDIR FAST CGI" ] \ + || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDOMAIN W3 TOTAL CACHE" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDOMAIN FAST CGI" ] && [ "$EE_SITE_CACHE_OPTION" = "--basic" ]; then + ee_lib_echo "Uninstalling W3 Total Cache plugin, please wait..." + wp plugin --allow-root uninstall w3-total-cache &>> $EE_COMMAND_LOG + fi + + if [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDOMAIN WP SUPER CACHE" ] || [ "$EE_SITE_CURRENT_OPTION" = "WPSINGLE WP SUPER CACHE" ] \ + || [ "$EE_SITE_CURRENT_OPTION" = "WPSUBDIR WP SUPER CACHE" ] && [ "$EE_SITE_CACHE_OPTION" = "--basic" ]; then + ee_lib_echo "Unnstalling WP Super Cache plugin, please wait..." + wp plugin --allow-root uninstall wp-super-cache &>> $EE_COMMAND_LOG + fi + + if [ "$EE_SITE_CURRENT_OPTION" != "WPSINGLE WP SUPER CACHE" ] && [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDIR WP SUPER CACHE" ] \ + && [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDOMAIN WP SUPER CACHE" ] && [ "$EE_SITE_CACHE_OPTION" = "--wpsc" ]; then + ee_mod_plugin_wpsc + fi + + if [ "$EE_SITE_CURRENT_OPTION" != "WPSINGLE W3 TOTAL CACHE" ] && [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDIR W3 TOTAL CACHE" ] \ + || [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDOMAIN W3 TOTAL CACHE" ] && [ "$EE_SITE_CURRENT_OPTION" != "WPSINGLE FAST CGI" ] || [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDIR FAST CGI" ] \ + || [ "$EE_SITE_CURRENT_OPTION" != "WPSUBDOMAIN FAST CGI" ] && [[ "$EE_SITE_CACHE_OPTION" = "--wpfc" || "$EE_SITE_CACHE_OPTION" = "--w3tc" ]]; then + ee_mod_plugin_w3tc + fi +}