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.

269 lines
8.9 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) 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"
11 years ago
# 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
11 years ago
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
11 years ago
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
11 years ago
ee_mod_install_$EE_THIRD
fi
if [ "$EE_THIRD" = "nginx" ] || [ "$EE_THIRD" = "php" ] || [ "$EE_THIRD" = "mysql" ]; then
# Setup NGINX/PHP/MySQL
11 years ago
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
11 years ago
ee_lib_git /etc/php5/ "Initialize Git"
11 years ago
else
# Restart NGINX/MySQL/Postfix
11 years ago
ee_lib_service $EE_THIRD restart
# Initialize Git
11 years ago
ee_lib_git /etc/$EE_THIRD/ "Initialize Git"
11 years ago
fi
fi
if [ "$EE_THIRD" = "adminer" ] || [ "$EE_THIRD" = "phpmyadmin" ] || [ "$EE_THIRD" = "wpcli" ] || [ "$EE_THIRD" = "utils" ];then
# Install Adminer/phpMyAdmin/WP-CLI/Utils
11 years ago
ee_ven_install_$EE_THIRD
fi
11 years ago
# Display success message
ee_lib_echo "$EE_THIRD successfully installed"
elif [ "$EE_THIRD" = "" ]; then
# Setup NGINX/PHP repository
11 years ago
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
11 years ago
ee_mod_install_nginx
ee_mod_install_php
ee_mod_install_mysql
ee_mod_install_postfix
# Setup NGINX/PHP/MySQL
11 years ago
ee_mod_setup_nginx
ee_mod_setup_php
ee_mod_setup_mysql
# # Restart NGINX/MySQL/Postfix
11 years ago
ee_lib_service nginx php5-fpm mysql restart
11 years ago
# Initialize Git
11 years ago
ee_lib_git /etc/nginx/ /etc/php5/ /etc/mysql/ /etc/postfix "Initialize Git"
# Install Adminer/phpMyAdmin/WP-CLI/Utils
11 years ago
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
11 years ago
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
11 years ago
# 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
11 years ago
fi
11 years ago
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
11 years ago
# 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
e_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" = "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_NETWORK_ACTIVATE="--network"
fi
# WordPress sub-domain variables
if [ "$EE_SITE_CREATE_OPTION" = "--wpsubdom" ] || [ "$EE_SITE_CREATE_OPTION" = "--wpsubdomain" ]; then
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 website
if [ "$EE_SITE_CREATE_OPTION" = "--html" ]; then
# Configure variable
EE_NGINX_CONF=html/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 HTML website
ee_lib_check_domain
ee_mod_setup_domain
# 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"
fi
fi
fi
}
EasyEngine $@ | tee -ai $EE_COMMAND_LOG