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.
 
 
 

444 lines
15 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"
# 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" ]; 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" = "" ]; 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
ee_lib_echo "Successfully installed all 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
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
# Execute: apt-get autoremove
ee_lib_autoremove
# 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" = "" ]; 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 all packages"
elif [ "$EE_SECOND" = "purge" ];then
ee_lib_echo "Successfully purged all packages"
fi
fi
elif [ "$EE_SECOND" = "status" ]; then
ee_mod_system_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
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-available/ \
|| 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
# 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 MySQL database
ee_mod_setup_database
# 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\tMemcache"
ee_lib_echo_escape "Object Cache:\t\tMemcache"
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
# 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
fi
fi
}
EasyEngine $@ | tee -ai $EE_COMMAND_LOG