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.
711 lines
25 KiB
711 lines
25 KiB
#!/bin/bash
|
|
|
|
# Include library
|
|
for ee_include in $(find /usr/local/lib/easyengine/ -iname "*.sh"); do
|
|
source $ee_include
|
|
done
|
|
|
|
# Main EasyEngine (ee) function to log all the outputs
|
|
EasyEngine()
|
|
{
|
|
|
|
# Arguments
|
|
EE_FIRST=$1
|
|
EE_SECOND=$2
|
|
EE_THIRD=$3
|
|
EE_FOURTH=$4
|
|
EE_FIFTH=$5
|
|
|
|
# Let's capture the EasyEngine arguments
|
|
ee_lib_echo "EasyEngine (ee) $EE_VERSION execution started [$(date)]" &>> $EE_COMMAND_LOG
|
|
ee_lib_echo "EasyEngine (ee) command: $0 $@" &>> $EE_COMMAND_LOG
|
|
|
|
|
|
# EasyEngine version
|
|
if [ "$EE_FIRST" = "version" ] || [ "$EE_FIRST" = "--version" ] || [ "$EE_FIRST" = "-v" ];then
|
|
# Display Easy Engine Version
|
|
echo "EasyEngine (ee) version: $EE_VERSION"
|
|
|
|
# EasyEngine help
|
|
elif [ "$EE_FIRST" = "help" ] || [ "$EE_FIRST" = "--help" ] || [ "$EE_FIRST" = "-h" ]; then
|
|
# Display man page
|
|
man ee
|
|
|
|
# Display information about NGINX|PHP|MySQL
|
|
elif [ "$EE_FIRST" = "info" ];then
|
|
if [ "$EE_SECOND" = "nginx" ] || [ "$EE_SECOND" = "php" ] || [ "$EE_SECOND" = "mysql" ]; then
|
|
ee_lib_${EE_SECOND}_info
|
|
else
|
|
ee_lib_nginx_info
|
|
ee_lib_php_info
|
|
ee_lib_mysql_info
|
|
fi
|
|
|
|
# EasyEngine stack/system
|
|
elif [ "$EE_FIRST" = "stack" ] || [ "$EE_FIRST" = "system" ]; then
|
|
# EasyEngine install
|
|
if [ "$EE_SECOND" = "install" ]; then
|
|
if [ "$EE_THIRD" = "nginx" ] || [ "$EE_THIRD" = "php" ] || [ "$EE_THIRD" = "mysql" ] || [ "$EE_THIRD" = "postfix" ] || [ "$EE_THIRD" = "adminer" ] || [ "$EE_THIRD" = "phpmyadmin" ] || [ "$EE_THIRD" = "wpcli" ] || [ "$EE_THIRD" = "utils" ]; then
|
|
if [ "$EE_THIRD" = "nginx" ] || [ "$EE_THIRD" = "php" ] || [ "$EE_THIRD" = "mysql" ]; then
|
|
# Setup NGINX/PHP repository
|
|
ee_mod_repo_$EE_THIRD
|
|
|
|
# Fix GnuPG key
|
|
ee_lib_gpg_key_fix
|
|
fi
|
|
|
|
if [ "$EE_THIRD" = "nginx" ] || [ "$EE_THIRD" = "php" ] || [ "$EE_THIRD" = "mysql" ] || [ "$EE_THIRD" = "postfix" ]; then
|
|
# Execute: apt-get update
|
|
ee_lib_apt_get_update
|
|
|
|
# Install NGINX/PHP/MySQL/Postfix package
|
|
ee_mod_install_$EE_THIRD
|
|
fi
|
|
|
|
if [ "$EE_THIRD" = "nginx" ] || [ "$EE_THIRD" = "php" ] || [ "$EE_THIRD" = "mysql" ]; then
|
|
# Setup NGINX/PHP/MySQL
|
|
ee_mod_setup_$EE_THIRD
|
|
fi
|
|
|
|
if [ "$EE_THIRD" = "nginx" ] || [ "$EE_THIRD" = "php" ] || [ "$EE_THIRD" = "mysql" ] || [ "$EE_THIRD" = "postfix" ]; then
|
|
# Restart php5-fpm
|
|
if [ "$EE_THIRD" = "php" ];then
|
|
ee_lib_service php5-fpm restart
|
|
|
|
# Initialize Git
|
|
ee_lib_git /etc/php5/ "Initialize Git"
|
|
else
|
|
# Restart NGINX/MySQL/Postfix
|
|
ee_lib_service $EE_THIRD restart
|
|
|
|
# Initialize Git
|
|
ee_lib_git /etc/$EE_THIRD/ "Initialize Git"
|
|
fi
|
|
fi
|
|
|
|
if [ "$EE_THIRD" = "adminer" ] || [ "$EE_THIRD" = "phpmyadmin" ] || [ "$EE_THIRD" = "wpcli" ] || [ "$EE_THIRD" = "utils" ];then
|
|
# Install Adminer/phpMyAdmin/WP-CLI/Utils
|
|
ee_ven_install_$EE_THIRD
|
|
fi
|
|
|
|
# Display success message
|
|
ee_lib_echo "$EE_THIRD successfully installed"
|
|
elif [ "$EE_THIRD" = "" ] || [ "$EE_THIRD" = "web" ] || [ "$EE_THIRD" = "all" ]; then
|
|
# Setup NGINX/PHP repository
|
|
ee_mod_repo_nginx
|
|
ee_mod_repo_php
|
|
|
|
# Fix GnuPG key
|
|
ee_lib_gpg_key_fix
|
|
|
|
# Execute: apt-get update
|
|
ee_lib_apt_get_update
|
|
|
|
# Install NGINX/PHP/MySQL/Postfix package
|
|
ee_mod_install_nginx
|
|
ee_mod_install_php
|
|
ee_mod_install_mysql
|
|
ee_mod_install_postfix
|
|
|
|
# Setup NGINX/PHP/MySQL
|
|
ee_mod_setup_nginx
|
|
ee_mod_setup_php
|
|
ee_mod_setup_mysql
|
|
|
|
# Restart NGINX/MySQL/Postfix
|
|
ee_lib_service nginx php5-fpm mysql restart
|
|
|
|
# Initialize Git
|
|
ee_lib_git /etc/nginx/ /etc/php5/ /etc/mysql/ /etc/postfix "Initialize Git"
|
|
|
|
# Install Adminer/phpMyAdmin/WP-CLI/Utils
|
|
ee_ven_install_adminer
|
|
ee_ven_install_phpmyadmin
|
|
ee_ven_install_wpcli
|
|
ee_ven_install_utils
|
|
|
|
# Display success message
|
|
if [ "$EE_THIRD" != "all" ];then
|
|
ee_lib_echo "Successfully installed web server packages"
|
|
ee_lib_echo "Create your first WordPress site powered by NGINX using:"
|
|
ee_lib_echo_info "ee site create example.com --wp"
|
|
fi
|
|
fi
|
|
# EasyEngine mail server setup
|
|
if [ "$EE_THIRD" = "mail" ] || [ "$EE_THIRD" = "all" ];then
|
|
|
|
# Check required Packages are installed or not
|
|
dpkg --get-selections | grep -v deinstall | grep nginx > /dev/null \
|
|
&& dpkg --get-selections | grep -v deinstall | grep php5-fpm > /dev/null \
|
|
&& mysqladmin ping &> /dev/null \
|
|
&& dpkg --get-selections | grep -v deinstall | grep postfix > /dev/null
|
|
if [ $? -ne 0 ];then
|
|
ee_lib_error "Failed to find NGINX PHP MySQL Postfix, exit status=" 1
|
|
fi
|
|
|
|
dpkg --get-selections | grep -v deinstall | grep dovecot-core > /dev/null
|
|
if [ $? -eq 0 ];then
|
|
ee_lib_error "Found installed Dovecot Packages server, exit status=" 1
|
|
fi
|
|
|
|
# Install Dovecot
|
|
ee_mod_install_dovecot
|
|
|
|
# Install mail scanner packages
|
|
ee_mod_install_mailscan
|
|
|
|
# Install ViMbAdmin
|
|
ee_ven_install_vimbadmin
|
|
|
|
# Install Roundcube
|
|
ee_ven_install_roundcube
|
|
|
|
# Configure PostFix
|
|
ee_mod_setup_postfix
|
|
|
|
# Configure Dovecot
|
|
ee_mod_setup_dovecot
|
|
|
|
# Setup Amavis
|
|
ee_mod_setup_mailscan
|
|
|
|
# Setup ViMbAdmin
|
|
ee_ven_setup_vimbadmin
|
|
|
|
# Setup Roundcube
|
|
ee_ven_setup_roundcube
|
|
|
|
# Setup Sieve Rules
|
|
ee_mod_setup_sieve
|
|
|
|
ee_lib_service nginx postfix dovecot amavis restart
|
|
|
|
ee_lib_git /etc/nginx /etc/postfix /etc/dovecot /etc/amavis "Initialize Git"
|
|
|
|
# Display message for mail server
|
|
ee_lib_echo_escape "Configure ViMbAdmin:\thttps://$(hostname -f):22222/vimbadmin"
|
|
ee_lib_echo_escape "Security Salt:\t\t${ee_security_salt}\n"
|
|
|
|
ee_lib_echo "Successfully installed mail server packages"
|
|
fi
|
|
|
|
# EasyEngine remove/purge
|
|
elif [ "$EE_SECOND" = "remove" ] || [ "$EE_SECOND" = "purge" ]; then
|
|
if [ "$EE_THIRD" = "nginx" ] || [ "$EE_THIRD" = "php" ] || [ "$EE_THIRD" = "mysql" ] || [ "$EE_THIRD" = "postfix" ] || [ "$EE_THIRD" = "adminer" ] || [ "$EE_THIRD" = "phpmyadmin" ] || [ "$EE_THIRD" = "wpcli" ] || [ "$EE_THIRD" = "utils" ]; then
|
|
|
|
# Remove/Purge NGINX/PHP/MySQL/Postfix package
|
|
if [ "$EE_THIRD" = "nginx" ] || [ "$EE_THIRD" = "php" ] || [ "$EE_THIRD" = "mysql" ] || [ "$EE_THIRD" = "postfix" ]; then
|
|
ee_mod_remove_$EE_THIRD
|
|
|
|
# Execute: apt-get autoremove
|
|
ee_lib_autoremove
|
|
fi
|
|
|
|
# Remove/Purge Adminer/phpMyAdmin/WP-CLI/Utils
|
|
if [ "$EE_THIRD" = "adminer" ] || [ "$EE_THIRD" = "phpmyadmin" ] || [ "$EE_THIRD" = "wpcli" ] || [ "$EE_THIRD" = "utils" ];then
|
|
ee_ven_remove_$EE_THIRD
|
|
fi
|
|
|
|
# Display success message
|
|
if [ "$EE_SECOND" = "remove" ];then
|
|
ee_lib_echo "$EE_THIRD successfully removed"
|
|
elif [ "$EE_SECOND" = "purge" ];then
|
|
ee_lib_echo "$EE_THIRD successfully purged"
|
|
fi
|
|
elif [ "$EE_THIRD" = "" ] || [ "$EE_THIRD" = "web" ] || [ "$EE_THIRD" = "all" ]; then
|
|
# Remove/Purge NGINX/PHP/MySQL/Postfix package
|
|
ee_mod_remove_nginx
|
|
ee_mod_remove_php
|
|
ee_mod_remove_mysql
|
|
ee_mod_remove_postfix
|
|
|
|
# Install Adminer/phpMyAdmin/WP-CLI/Utils
|
|
ee_ven_remove_adminer
|
|
ee_ven_remove_phpmyadmin
|
|
ee_ven_remove_wpcli
|
|
ee_ven_remove_utils
|
|
|
|
# Execute: apt-get autoremove
|
|
ee_lib_autoremove
|
|
|
|
# Display success message
|
|
if [ "$EE_SECOND" = "remove" ];then
|
|
ee_lib_echo "Successfully removed web packages"
|
|
elif [ "$EE_SECOND" = "purge" ];then
|
|
ee_lib_echo "Successfully purged web packages"
|
|
fi
|
|
fi
|
|
if [ "$EE_THIRD" = "all" ] || [ "$EE_THIRD" = "mail" ];then
|
|
# Remove Dovecot
|
|
ee_mod_remove_dovecot
|
|
|
|
# Remove Amavis
|
|
ee_mod_remove_mailscan
|
|
|
|
# Remove ViMbAdmin
|
|
ee_ven_remove_vimbadmin
|
|
|
|
# Remove Roundcube
|
|
ee_ven_remove_roundcube
|
|
|
|
# Execute: apt-get autoremove
|
|
ee_lib_autoremove
|
|
|
|
# Display success message
|
|
if [ "$EE_SECOND" = "remove" ];then
|
|
ee_lib_echo "Successfully removed mail server packages"
|
|
elif [ "$EE_SECOND" = "purge" ];then
|
|
ee_lib_echo "Successfully purged mail server packages"
|
|
fi
|
|
fi
|
|
|
|
elif [ "$EE_SECOND" = "status" ]; then
|
|
ee_mod_stack_status
|
|
elif [ "$EE_SECOND" = "start" ] || [ "$EE_SECOND" = "stop" ] || [ "$EE_SECOND" = "reload" ] || [ "$EE_SECOND" = "restart" ]; then
|
|
ee_lib_service nginx php5-fpm mysql postfix $EE_SECOND
|
|
else
|
|
ee_lib_echo "ee stack commands:"
|
|
ee_lib_echo_escape "\tinstall\tInstall NGINX, PHP5, MySQL, Postfix, Adminer, phpMyAdmin, WP-CLI and Utils"
|
|
ee_lib_echo_escape "\tremove\tRemove NGINX, PHP5, MySQL, Postfix, Adminer, phpMyAdmin, WP-CLI and Utils"
|
|
ee_lib_echo_escape "\tpurge\tPurge NGINX, PHP5, MySQL, Postfix, Adminer, phpMyAdmin, WP-CLI and Utils"
|
|
ee_lib_echo_escape "\tstatus\tDisplay system status information"
|
|
ee_lib_echo_escape "\tstart\tStart NGINX, PHP5, MySQL and Postfix service"
|
|
ee_lib_echo_escape "\tstop\tStop NGINX, PHP5, MySQL and Postfix service"
|
|
ee_lib_echo_escape "\treload\tReload NGINX, PHP5, MySQL and Postfix service"
|
|
ee_lib_echo_escape "\trestart\tRestart NGINX, PHP5, MySQL and Postfix service"
|
|
fi
|
|
|
|
|
|
# EasyEngine site
|
|
elif [ "$EE_FIRST" = "site" ]; then
|
|
if [ "$EE_SECOND" = "list" ]; then
|
|
if [ "$EE_THIRD" = "available" ];then
|
|
ee_lib_echo "List of sites-available websites:"
|
|
ls /etc/nginx/sites-available/ \
|
|
|| ee_lib_error "Unable to display list of sites-available websites, exit status = " $?
|
|
else
|
|
ee_lib_echo "List of sites-enabled websites:"
|
|
ls /etc/nginx/sites-enabled/ \
|
|
|| ee_lib_error "Unable to display list of sites-enabled websites, exit status = " $?
|
|
fi
|
|
elif [ "$EE_SECOND" = "info" ] || [ "$EE_SECOND" = "show" ]; then
|
|
# Check the website name is empty or not
|
|
EE_DOMAIN_CHECK=$EE_THIRD
|
|
ee_lib_check_domain
|
|
|
|
if [ "$EE_SECOND" = "info" ]; then
|
|
# Display information about website
|
|
ee_mod_site_info
|
|
elif [ "$EE_SECOND" = "show" ]; then
|
|
# 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 = " $?
|
|
|
|
# Display NGINX configuration for $EE_DOMAIN
|
|
if [ $? -eq 0 ]; then
|
|
ee_lib_echo "Display NGINX configuration for $EE_DOMAIN"
|
|
cat /etc/nginx/sites-available/$EE_DOMAIN \
|
|
|| ee_lib_error "Unable to display NGINX configuration for $EE_DOMAIN, exit status = " $?
|
|
fi
|
|
fi
|
|
elif [ "$EE_SECOND" = "enable" ]; then
|
|
# Check the website name is empty or not
|
|
EE_DOMAIN_CHECK=$EE_THIRD
|
|
ee_lib_check_domain
|
|
|
|
# Creating symbolic link
|
|
ee_lib_echo "Creating symbolic link for $EE_DOMAIN"
|
|
ee_lib_symbolic_link /etc/nginx/sites-available/$EE_DOMAIN /etc/nginx/sites-enabled/
|
|
|
|
# Execute: service nginx reload
|
|
ee_lib_service nginx reload
|
|
|
|
# Git commit
|
|
ee_lib_git /etc/nginx/ "Enable website: $EE_DOMAIN"
|
|
elif [ "$EE_SECOND" = "disable" ]; then
|
|
# Check the website name is empty or not
|
|
EE_DOMAIN_CHECK=$EE_THIRD
|
|
ee_lib_check_domain
|
|
|
|
# Remove symbolic link
|
|
ee_lib_echo "Removing symbolic link for $EE_DOMAIN"
|
|
rm /etc/nginx/sites-enabled/$EE_DOMAIN \
|
|
|| ee_lib_error "Unable to remove symbolic link for $EE_DOMAIN, exit status = " $?
|
|
|
|
# Execute: service nginx reload
|
|
ee_lib_service nginx reload
|
|
|
|
# Git commit
|
|
ee_lib_git /etc/nginx/ "Disable website: $EE_DOMAIN"
|
|
elif [ "$EE_SECOND" = "edit" ]; then
|
|
# Check the website name is empty or not
|
|
EE_DOMAIN_CHECK=$EE_THIRD
|
|
ee_lib_check_domain
|
|
|
|
# Edit the NGINX configuration for $EE_DOMAIN
|
|
ee_mod_site_edit $EE_FOURTH
|
|
|
|
if [ $(cd /etc/nginx; git status -s /etc/nginx/sites-available/$EE_DOMAIN | wc -l) -ne 0 ]; then
|
|
# Git commit
|
|
ee_lib_git /etc/nginx/ "Edit website: $EE_DOMAIN"
|
|
|
|
# Execute: service nginx reload
|
|
ee_lib_service nginx reload
|
|
fi
|
|
elif [ "$EE_SECOND" = "create" ]; then
|
|
# Configure variables
|
|
EE_DOMAIN_CHECK=$EE_THIRD
|
|
EE_SITE_CREATE_OPTION=$EE_FOURTH
|
|
EE_SITE_CACHE_OPTION=$EE_FIFTH
|
|
|
|
# Auto switch options
|
|
if [ "$EE_SITE_CREATE_OPTION" = "--basic" ] || [ "$EE_SITE_CREATE_OPTION" = "--w3tc" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsc" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpfc" ]; then
|
|
if [ "$EE_SITE_CACHE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CACHE_OPTION" = "--wpsubdirectory" ] || [ "$EE_SITE_CACHE_OPTION" = "--wpsubdom" ] || [ "$EE_SITE_CACHE_OPTION" = "--wpsubdomain" ]; then
|
|
EE_SITE_CREATE_OPTION=$EE_FIFTH
|
|
EE_SITE_CACHE_OPTION=$EE_FOURTH
|
|
else
|
|
EE_SITE_CREATE_OPTION=--wp
|
|
EE_SITE_CACHE_OPTION=$EE_FOURTH
|
|
fi
|
|
fi
|
|
# WordPresss subdirectory variables
|
|
if [ "$EE_SITE_CREATE_OPTION" = "--wpsubdir" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdirectory" ]; then
|
|
EE_SITE_CREATE_OPTION="--wpsubdir"
|
|
EE_NETWORK_ACTIVATE="--network"
|
|
fi
|
|
# WordPress sub-domain variables
|
|
if [ "$EE_SITE_CREATE_OPTION" = "--wpsubdom" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then
|
|
EE_SITE_CREATE_OPTION="--wpsubdomain"
|
|
EE_NETWORK_ACTIVATE="--network"
|
|
EE_WP_SUBDOMAIN="--subdomains"
|
|
fi
|
|
# Use default whenever possible
|
|
if [ "$EE_SITE_CREATE_OPTION" = "" ]; then
|
|
EE_SITE_CREATE_OPTION=--html
|
|
fi
|
|
# For WordPress sites if $EE_SITE_CACHE_OPTION is empty then used --basic as a $EE_SITE_CACHE_OPTION
|
|
if [ "$EE_SITE_CACHE_OPTION" = "" ] && [ "$EE_SITE_CREATE_OPTION" != "--html" ] && [ "$EE_SITE_CREATE_OPTION" != "--php" ] && [ "$EE_SITE_CREATE_OPTION" != "--mysql" ]; then
|
|
EE_SITE_CACHE_OPTION=--basic
|
|
fi
|
|
|
|
# Lets create HTML|PHP|MySQL website
|
|
if [ "$EE_SITE_CREATE_OPTION" = "--html" ] || [ "$EE_SITE_CREATE_OPTION" = "--php" ] || [ "$EE_SITE_CREATE_OPTION" = "--mysql" ]; then
|
|
# Configure variable
|
|
EE_NGINX_CONF=$(echo $EE_SITE_CREATE_OPTION | cut -c3-)/basic.conf
|
|
echo -e "EE_DOMAIN_CHECK = $EE_DOMAIN_CHECK \nEE_SITE_CREATE_OPTION = $EE_SITE_CREATE_OPTION \nEE_SITE_CACHE_OPTION = $EE_SITE_CACHE_OPTION \nEE_NETWORK_ACTIVATE = $EE_NETWORK_ACTIVATE \nEE_WP_SUBDOMAIN = $EE_WP_SUBDOMAIN \nEE_NGINX_CONF = $EE_NGINX_CONF" &>> $EE_COMMAND_LOG
|
|
|
|
# Setup NGINX
|
|
ee_lib_check_domain
|
|
ee_mod_setup_domain
|
|
|
|
# Setup MySQL database
|
|
if [ "$EE_SITE_CREATE_OPTION" = "--mysql" ]; then
|
|
ee_mod_setup_database
|
|
|
|
# Add Database Information On ee-config.php
|
|
echo -e "define('DB_NAME', '$EE_DB_NAME'); \ndefine('DB_USER', '$EE_DB_USER'); \ndefine('DB_PASSWORD', '$EE_DB_PASS'); \ndefine('DB_HOST', '$EE_MYSQL_HOST');" \
|
|
&>> /var/www/$EE_DOMAIN/ee-config.php
|
|
fi
|
|
|
|
# Adjust permission
|
|
ee_lib_permissions
|
|
|
|
# Git commit
|
|
ee_lib_git /etc/nginx/ "$EE_DOMAIN created with $EE_SITE_CREATE_OPTION $EE_SITE_CACHE_OPTION options"
|
|
|
|
# Display Success Message
|
|
ee_lib_echo_info "Successfully Created New Website: http://$EE_WWW_DOMAIN"
|
|
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
|
|
# Cross check WP-CLI installed or not
|
|
wp --allow-root --info &>> $EE_COMMAND_LOG \
|
|
|| ee_lib_error "WP-CLI not found, exit status = " $?
|
|
|
|
# Configure variable
|
|
EE_NGINX_CONF=$(echo $EE_SITE_CREATE_OPTION | cut -c3-)/$(echo $EE_SITE_CACHE_OPTION | cut -c3-).conf
|
|
echo -e "EE_DOMAIN_CHECK = $EE_DOMAIN_CHECK \nEE_SITE_CREATE_OPTION = $EE_SITE_CREATE_OPTION \nEE_SITE_CACHE_OPTION = $EE_SITE_CACHE_OPTION \nEE_NETWORK_ACTIVATE = $EE_NETWORK_ACTIVATE \nEE_WP_SUBDOMAIN = $EE_WP_SUBDOMAIN \nEE_NGINX_CONF = $EE_NGINX_CONF" &>> $EE_COMMAND_LOG
|
|
|
|
# Setup NGINX
|
|
ee_lib_check_domain
|
|
ee_mod_setup_domain
|
|
|
|
# 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
|
|
|
|
# Git commit
|
|
ee_lib_git /etc/nginx/ "$EE_DOMAIN created with $EE_SITE_CREATE_OPTION $EE_SITE_CACHE_OPTION options"
|
|
|
|
# Execute: service nginx reload
|
|
ee_lib_service nginx reload
|
|
|
|
# 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
|
|
|
|
# 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 Success Message
|
|
ee_lib_echo_info "Successfully created new website: http://$EE_WWW_DOMAIN"
|
|
fi
|
|
fi
|
|
elif [ "$EE_SECOND" = "delete" ]; then
|
|
# Check the website name is empty or not
|
|
EE_DELETE_ARGS=$EE_FOURTH
|
|
EE_DOMAIN_CHECK=$EE_THIRD
|
|
ee_lib_check_domain
|
|
|
|
# Check the $EE_DOMAIN exist or not
|
|
if [ ! -f /etc/nginx/sites-available/$EE_DOMAIN ]; then
|
|
ee_lib_error "$EE_DOMAIN not exist, exit status = " $?
|
|
fi
|
|
|
|
# Use default whenever possible
|
|
# ee site delete example.com
|
|
# ee site delete example.com --no-prompt
|
|
if [ "$EE_DELETE_ARGS" = "" ]; then
|
|
EE_DELETE_ARGS="--all"
|
|
elif [ "$EE_DELETE_ARGS" = "--no-prompt" ]; then
|
|
EE_DELETE_ARGS="--all"
|
|
EE_FIFTH="--no-prompt"
|
|
fi
|
|
|
|
if [ "$EE_DELETE_ARGS" = "--db" ]; then
|
|
# Delete MySQL database
|
|
ee_mod_delete_database $EE_FIFTH
|
|
elif [ "$EE_DELETE_ARGS" = "--files" ]; then
|
|
# Delete webroot
|
|
ee_mod_delete_webroot $EE_FIFTH
|
|
elif [ "$EE_DELETE_ARGS" = "--all" ]; then
|
|
# Delete MySQL database
|
|
ee_mod_delete_database $EE_FIFTH
|
|
|
|
# Delete webroot
|
|
ee_mod_delete_webroot $EE_FIFTH
|
|
|
|
# Delete NGINX configuration file
|
|
ee_mod_delete_nginxconf $EE_FIFTH
|
|
|
|
# Git commit
|
|
ee_lib_git /etc/nginx/ "Delete website: $EE_DOMAIN"
|
|
|
|
# Execute: service nginx reload
|
|
ee_lib_service nginx reload
|
|
fi
|
|
elif [ "$EE_SECOND" = "log" ]; then
|
|
# Display logs for websites
|
|
ee_mod_site_log ${@:3}
|
|
|
|
#EasyEngine cd
|
|
elif [ "$EE_SECOND" = "cd" ]; then
|
|
# Check the website name is empty or not
|
|
EE_DOMAIN_CHECK=$EE_THIRD
|
|
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 = " $?
|
|
|
|
# Change Directory to $EE_DOMAIN webroot
|
|
if [ $? -eq 0 ]; then
|
|
ee_site_cd
|
|
fi
|
|
|
|
else
|
|
ee_lib_echo "ee site commands:"
|
|
ee_lib_echo_escape "\tlist\tList NGINX enabled website"
|
|
ee_lib_echo_escape "\tinfo\tDisplay information about given website"
|
|
ee_lib_echo_escape "\tshow\tDisplay NGINX configuration for given website"
|
|
ee_lib_echo_escape "\tenable\tEnable website"
|
|
ee_lib_echo_escape "\tdisable\tDisable website"
|
|
ee_lib_echo_escape "\tedit\tEdit NGINX configuration for given website"
|
|
ee_lib_echo_escape "\tcreate\tCreate new HTML, PHP, MySQL or WordPress website"
|
|
ee_lib_echo_escape "\tdelete\tDelete existing website"
|
|
fi
|
|
|
|
# EasyEngine debug
|
|
elif [ "$EE_FIRST" = "debug" ]; then
|
|
# Default action
|
|
EE_DEBUG="--start"
|
|
|
|
# Auto arrange debug arguments
|
|
for ee_debug_args in $@; do
|
|
[ "$ee_debug_args" = "-i" ] && EE_DEBUG_INTERACTIVE=$ee_debug_args && echo EE_DEBUG_INTERACTIVE = $EE_DEBUG_INTERACTIVE &>> $EE_COMMAND_LOG
|
|
[ "$ee_debug_args" = "--stop" ] && EE_DEBUG=$ee_debug_args && echo EE_DEBUG = $EE_DEBUG &>> $EE_COMMAND_LOG
|
|
[ "$ee_debug_args" = "--nginx" ] && EE_DEBUG_NGINX=$ee_debug_args && echo EE_DEBUG_NGINX = $EE_DEBUG_NGINX &>> $EE_COMMAND_LOG
|
|
[ "$ee_debug_args" = "--rewrite" ] && EE_DEBUG_REWRITE=$ee_debug_args && echo EE_DEBUG_REWRITE = $EE_DEBUG_REWRITE &>> $EE_COMMAND_LOG
|
|
[ "$ee_debug_args" = "--php" ] && EE_DEBUG_PHP=$ee_debug_args && echo EE_DEBUG_PHP = $EE_DEBUG_PHP &>> $EE_COMMAND_LOG
|
|
[ "$ee_debug_args" = "--fpm" ] && EE_DEBUG_FPM=$ee_debug_args && echo EE_DEBUG_FPM = $EE_DEBUG_FPM &>> $EE_COMMAND_LOG
|
|
[ "$ee_debug_args" = "--mysql" ] && EE_DEBUG_MYSQL=$ee_debug_args && echo EE_DEBUG_MYSQL = $EE_DEBUG_MYSQL &>> $EE_COMMAND_LOG
|
|
[ "$ee_debug_args" = "--wp" ] && EE_DEBUG_WP=$ee_debug_args && echo EE_DEBUG_WP = $EE_DEBUG_WP &>> $EE_COMMAND_LOG
|
|
if [ "$ee_debug_args" != "debug" ] && [ "$ee_debug_args" != "-i" ] && [ "$ee_debug_args" != "--start" ] && [ "$ee_debug_args" != "--stop" ] && [ "$ee_debug_args" != "--nginx" ] && [ "$ee_debug_args" != "--rewrite" ] && [ "$ee_debug_args" != "--php" ] && [ "$ee_debug_args" != "--fpm" ] && [ "$ee_debug_args" != "--mysql" ] && [ "$ee_debug_args" != "--wp" ]; then
|
|
ls /etc/nginx/sites-available/ | grep $ee_debug_args &>> $EE_COMMAND_LOG
|
|
if [ $? -eq 0 ]; then
|
|
EE_DOMAIN_CHECK=$ee_debug_args && echo EE_DOMAIN_CHECK = $EE_DOMAIN_CHECK &>> $EE_COMMAND_LOG
|
|
|
|
# Domain name find out
|
|
ee_lib_check_domain
|
|
echo EE_DOMAIN = $EE_DOMAIN &>> $EE_COMMAND_LOG
|
|
fi
|
|
fi
|
|
done
|
|
|
|
# The following code execute on
|
|
# ee debug
|
|
# ee debug -i
|
|
# ee debug --start
|
|
# ee debug --stop
|
|
# ee debug example.com
|
|
if [ -z "$EE_DEBUG_NGINX" ] && [ -z "$EE_DEBUG_REWRITE" ] && [ -z "$EE_DEBUG_PHP" ] && [ -z "$EE_DEBUG_FPM" ] && [ -z "$EE_DEBUG_MYSQL" ] && [ -z "$EE_DEBUG_WP" ]; then
|
|
EE_DEBUG_NGINX="--nginx" && echo EE_DEBUG_NGINX = $EE_DEBUG_NGINX &>> $EE_COMMAND_LOG
|
|
EE_DEBUG_REWRITE="--rewrite" && echo EE_DEBUG_REWRITE = $EE_DEBUG_REWRITE &>> $EE_COMMAND_LOG
|
|
EE_DEBUG_PHP="--php" && echo EE_DEBUG_PHP = $EE_DEBUG_PHP &>> $EE_COMMAND_LOG
|
|
EE_DEBUG_FPM="--fpm" && echo EE_DEBUG_FPM = $EE_DEBUG_FPM &>> $EE_COMMAND_LOG
|
|
EE_DEBUG_MYSQL="--mysql" && echo EE_DEBUG_MYSQL = $EE_DEBUG_MYSQL &>> $EE_COMMAND_LOG
|
|
|
|
if [ -n "$EE_DOMAIN" ]; then
|
|
EE_DEBUG_WP="--wp" && echo EE_DEBUG_WP = $EE_DEBUG_WP &>> $EE_COMMAND_LOG
|
|
fi
|
|
fi
|
|
|
|
# Actual debug function call
|
|
if [ "$EE_DEBUG_NGINX" = "--nginx" ]; then
|
|
# Debug NGINX
|
|
ee_mod_debug_nginx
|
|
fi
|
|
|
|
if [ "$EE_DEBUG_REWRITE" = "--rewrite" ]; then
|
|
# Debug NGINX rewrite rules
|
|
ee_mod_debug_rewrite
|
|
fi
|
|
|
|
if [ "$EE_DEBUG_PHP" = "--php" ]; then
|
|
# Debug PHP slow log and enable xdebug profiling
|
|
ee_mod_debug_php
|
|
fi
|
|
|
|
if [ "$EE_DEBUG_FPM" = "--fpm" ]; then
|
|
# Change PHP log_level from notice to debug
|
|
ee_mod_debug_fpm
|
|
fi
|
|
|
|
if [ "$EE_DEBUG_MYSQL" = "--mysql" ]; then
|
|
# Enable MySQL slow query
|
|
ee_mod_debug_mysql
|
|
fi
|
|
|
|
if [ "$EE_DEBUG_WP" = "--wp" ]; then
|
|
# Enable WordPress debug.log
|
|
ee_mod_debug_wp
|
|
fi
|
|
|
|
# Execute: service nginx reload
|
|
if [ "$EE_TRIGGER_NGINX" = "true" ]; then
|
|
ee_lib_service nginx reload
|
|
fi
|
|
|
|
if [ "$EE_TRIGGER_PHP" = "true" ]; then
|
|
ee_lib_service php5-fpm restart
|
|
fi
|
|
|
|
if [ "$EE_DEBUG_INTERACTIVE" = "-i" ]; then
|
|
# Debug stop on CTRL+C
|
|
trap "ee_mod_debug_stop" EXIT
|
|
|
|
if [ ! -z "$EE_DEBUG_MSG" ]; then
|
|
tail -f $EE_DEBUG_MSG
|
|
fi
|
|
elif [ "$EE_DEBUG_INTERACTIVE" != "-i" ] && [ "$EE_DEBUG" != "--stop" ]; then
|
|
if [ ! -z "$EE_DEBUG_MSG" ]; then
|
|
ee_lib_echo_info "tail -f $EE_DEBUG_MSG"
|
|
fi
|
|
fi
|
|
|
|
# EasyEngine secure
|
|
elif [ "$EE_FIRST" = "secure" ]; then
|
|
if [ "$EE_SECOND" = "--auth" ] || [ "$EE_SECOND" = "--port" ] || [ "$EE_SECOND" = "--ip" ]; then
|
|
ee_mod_secure_$(echo $EE_SECOND | sed 's/--//')
|
|
ee_lib_service nginx reload
|
|
else
|
|
ee_lib_echo "ee secure commands:"
|
|
ee_lib_echo_escape "\t--auth\tUpdate credential of HTTP authentication"
|
|
ee_lib_echo_escape "\t--port\tChange EasyEngine admin port 22222"
|
|
ee_lib_echo_escape "\t--ip\tUpdate whitelist IP address"
|
|
fi
|
|
|
|
# Clean cache
|
|
elif [ "$EE_FIRST" = "clean" ]; then
|
|
ee_mod_clean ${@:2}
|
|
|
|
|
|
# EasyEngine update
|
|
elif [ "$EE_FIRST" = "update" ]; then
|
|
ee_lib_echo "Please set/use following alias to update EasyEngine (ee)"
|
|
echo "alias eeupdate=\"wget -qO eeup http://rt.cx/eeup && sudo bash eeup\""
|
|
|
|
else
|
|
ee_lib_echo "EasyEngine (ee) commands:"
|
|
ee_lib_echo_escape "\tversion\tDisplay EasyEngine (ee) version"
|
|
ee_lib_echo_escape "\thelp\tDisplay EasyEngine (ee) man page"
|
|
ee_lib_echo_escape "\tinfo\tDisplay Information about NGINX, PHP5, MySQL"
|
|
ee_lib_echo_escape "\tstack\tInstall/Remove/Purge NGINX, PHP, MySQL, Postfix"
|
|
ee_lib_echo_escape "\tsite\tPerform various site specific operation"
|
|
ee_lib_echo_escape "\tdebug\tPerform various debugging operation"
|
|
ee_lib_echo_escape "\tsecure\tUpdate HTTP authentication and EasyEngine admin port"
|
|
ee_lib_echo_escape "\tupdate\tUpdate EasyEngine (ee) to latest version"
|
|
fi
|
|
|
|
}
|
|
|
|
EasyEngine $@ | tee -ai $EE_COMMAND_LOG
|
|
|