From 5f199ccc14092204fed085477573630adf488972 Mon Sep 17 00:00:00 2001 From: Mitesh Shah Date: Wed, 18 Jun 2014 14:58:59 +0530 Subject: [PATCH] ee site created --- .travis.yml | 7 +++ bin/easyengine | 93 +++++++++++++++++++++++++++++++++-- src/lib/ee_lib_git.sh | 27 ++++++++++ src/lib/ee_lib_git_commit.sh | 15 ------ src/lib/ee_lib_git_init.sh | 23 --------- src/lib/ee_lib_permissions.sh | 4 +- 6 files changed, 126 insertions(+), 43 deletions(-) create mode 100644 src/lib/ee_lib_git.sh delete mode 100644 src/lib/ee_lib_git_commit.sh delete mode 100644 src/lib/ee_lib_git_init.sh diff --git a/.travis.yml b/.travis.yml index 1157eecb..6b8eb4d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,3 +56,10 @@ script: - sudo bash ee info php - sudo bash ee info mysql - sudo bash ee info + +- sudo bash ee site create html.com +- sudo bash ee site create html2.com --html +- sudo bash ee site info html.com +- sudo bash ee site show html.com +- sudo bash ee site list +- sudo bash ee site list available diff --git a/bin/easyengine b/bin/easyengine index 5fcbb2bf..38d8dfb9 100644 --- a/bin/easyengine +++ b/bin/easyengine @@ -68,13 +68,13 @@ elif [ "$EE_FIRST" = "stack" ] || [ "$EE_FIRST" = "system" ]; then ee_lib_service php5-fpm restart # Initialize Git - ee_lib_git_init /etc/php5/ + ee_lib_git /etc/php5/ "Initialize Git" else # Restart NGINX/MySQL/Postfix ee_lib_service $EE_THIRD restart # Initialize Git - ee_lib_git_init /etc/$EE_THIRD/ + ee_lib_git /etc/$EE_THIRD/ "Initialize Git" fi fi @@ -111,7 +111,7 @@ elif [ "$EE_FIRST" = "stack" ] || [ "$EE_FIRST" = "system" ]; then ee_lib_service nginx php5-fpm mysql restart # Initialize Git - ee_lib_git_init /etc/nginx/ /etc/php5/ /etc/mysql/ /etc/postfix + ee_lib_git /etc/nginx/ /etc/php5/ /etc/mysql/ /etc/postfix "Initialize Git" # Install Adminer/phpMyAdmin/WP-CLI/Utils ee_ven_install_adminer @@ -174,6 +174,93 @@ elif [ "$EE_FIRST" = "stack" ] || [ "$EE_FIRST" = "system" ]; then 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 + 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 } diff --git a/src/lib/ee_lib_git.sh b/src/lib/ee_lib_git.sh new file mode 100644 index 00000000..477719b7 --- /dev/null +++ b/src/lib/ee_lib_git.sh @@ -0,0 +1,27 @@ +# Initialize Git + +function ee_lib_git() +{ + for ee_git_dir in $@; do + if [ $ee_git_dir != ${@: -1} ]; then + + # Change directory + cd $ee_git_dir || ee_lib_error "Unable to change directory $ee_git_dir, exit status = " $? + + # Check .git + if [ ! -d .git ]; then + ee_lib_echo "Initialize Git on ${ee_git_dir}..." + git init &>> $EE_COMMAND_LOG \ + || ee_lib_error "Unable to initialize Git on $ee_git_dir, exit status = " $? + fi + + # Check for untracked files + if [ $(git status -s | wc -l) -ne 0 ]; then + # Add files in Git version control + ee_lib_echo "Committing changes inside $EE_GIT_DIR, please wait..." + git add --all && git commit -am ${@: -1} &>> $EE_COMMAND_LOG \ + || ee_lib_error "Unable to Git commit on $ee_git_dir, exit status = " $? + fi + fi + done +} diff --git a/src/lib/ee_lib_git_commit.sh b/src/lib/ee_lib_git_commit.sh deleted file mode 100644 index ef445f5e..00000000 --- a/src/lib/ee_lib_git_commit.sh +++ /dev/null @@ -1,15 +0,0 @@ -# Record changes to the repository - -function ee_lib_git_commit() -{ - cd $EE_GIT_DIR \ - || ee_lib_error "Unable to change directory $EE_GIT_DIR, exit status = " $? - - if [ $(git status -s | wc -l) -ne 0 ]; then - ee_lib_echo "Committing changes inside $EE_GIT_DIR, please wait..." - - # Add newly created files && commit it - git add --all && git commit -am "$EE_GIT_MESSAGE" &>> $EE_COMMAND_LOG \ - || ee_lib_error "Unable to Git commit on $EE_GIT_DIR, exit status = " $? - fi -} diff --git a/src/lib/ee_lib_git_init.sh b/src/lib/ee_lib_git_init.sh deleted file mode 100644 index 0b8113b7..00000000 --- a/src/lib/ee_lib_git_init.sh +++ /dev/null @@ -1,23 +0,0 @@ -# Initialize Git - -function ee_lib_git_init() -{ - for ee_git_dir in $@; do - # Change directory - cd $ee_git_dir || ee_lib_error "Unable to change directory $ee_git_dir, exit status = " $? - - # Check .git - if [ ! -d .git ]; then - ee_lib_echo "Initialize Git on ${ee_git_dir}..." - git init &>> $EE_COMMAND_LOG \ - || ee_lib_error "Unable to initialize Git on $ee_git_dir, exit status = " $? - fi - - # Check for untracked files - if [ $(git status -s | wc -l) -ne 0 ]; then - # Add files in Git version control - git add --all && git commit -am "Initialize Git on $ee_git_dir" &>> $EE_COMMAND_LOG \ - || ee_lib_error "Unable to Git commit on $ee_git_dir, exit status = " $? - fi - done -} diff --git a/src/lib/ee_lib_permissions.sh b/src/lib/ee_lib_permissions.sh index 5a4704cb..0a6346c1 100644 --- a/src/lib/ee_lib_permissions.sh +++ b/src/lib/ee_lib_permissions.sh @@ -1,8 +1,8 @@ -# Set ownership of /var/www/$EE_DOMAIN to www-data:www-data +# Adjust permission function ee_lib_permissions() { - ee_lib_echo "Changing ownership of /var/www/$EE_DOMAIN..." + ee_lib_echo "Changing ownership of /var/www/$EE_DOMAIN, please wait..." chown -R $EE_PHP_USER:$EE_PHP_USER /var/www/$EE_DOMAIN/ \ || ee_lib_error "Unable to change ownership for $EE_DOMAIN, exit status = " $? }