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.

1121 lines
32 KiB

#!/bin/bash
# Help Function
EngineHelp()
{
echo
echo "Usage: `basename $0` [OPTION] [ARGUMENT]..."
echo
echo "OPTION:"
12 years ago
echo " `basename $0` [system] [install|remove|purge] [nginx|php|mysql|postfix|--all]"
echo
echo " `basename $0` [site] [read] [all|active|sitename]"
12 years ago
echo " `basename $0` [site] [create] [sitename] [--with-wordpress]"
echo " `basename $0` [site] [update] [sitename] [singlesite] [w3total|wpsuper|fastcgi]"
12 years ago
echo " `basename $0` [site] [update] [sitename] [multisite] [subdomain|subdirectory] [basic|w3total|wpsuper|fastcgi]"
echo " `basename $0` [site] [delete] [sitename] [--database|--webroot|--all]"
12 years ago
echo
12 years ago
echo " `basename $0` [config] [set|get] [memory|timeout]"
echo
echo " `basename $0` [update] "
echo
echo "Exit status:"
echo " 0 if OK,"
echo " 100 sudo privilege required,"
echo " 101 command failed to execute,"
}
# Make Variables Available For Later Use
LOGDIR=/var/log/easyengine
MAINLOG=/var/log/easyengine/main.log
ERRORLOG=/var/log/easyengine/error.log
# Capture Errors
OwnError()
{
echo -e "[ `date` ] \033[31m $@ \e[0m" | tee -ai $ERRORLOG
exit 101
}
# GET Information Function
12 years ago
MYSQLINFO()
{
# Get The MySQL Username/Password
read -p "MySQL Host [localhost]: " MYSQLHOST
if [ -f ~/.my.cnf ]
then
MYSQLUSER=$(cat ~/.my.cnf | grep user | cut -d'=' -f2)
MYSQLPASS=$(cat ~/.my.cnf | grep pass | cut -d'=' -f2)
else
read -p "Enter The MySQL Username: " MYSQLUSER
# Turn Off Echo For Passwords
stty -echo
read -p "Enter The MySQL Password: " MYSQLPASS
stty echo
echo
fi
read -p "Enter The MySQL Database Name [$DOMAIN]: " WPDBNAME
# If Enter Is Pressed, Then Use localhost as MySQL Host
if [[ $MYSQLHOST = "" ]]
then
MYSQLHOST=localhost
#echo $MYSQLHOST
fi
# If Enter Is Pressed, Then Use $DOMAIN As Database Name
if [[ $WPDBNAME = "" ]]
then
WPDBNAME=$DOMAIN
#echo $WPDBNAME
fi
# Create Database
mysql -u $MYSQLUSER -p$MYSQLPASS -e "create database \`$WPDBNAME\`" \
12 years ago
|| OwnError "Unable To Create $WPDBNAME Database"
12 years ago
}
WEBUSERINFO()
{
# Nginx User
NGINXUSER=$(grep user /etc/nginx/nginx.conf | cut -d' ' -f2 | cut -d';' -f1) \
12 years ago
|| OwnError "Unable To Findout Nginx Username"
}
12 years ago
NGINXRELOAD()
{
# Test & Reload Nginx
echo -e "\033[34m Reloading Nginx Configuration, Please Wait... \e[0m"
12 years ago
nginx -t && service nginx reload || OwnError "Unable To Reload Nginx"
}
PHPSTART()
{
# Check PHP5-FPM IS Running
service php5-fpm status
if [ $? -ne 0 ]
then
echo -e "\033[34m Restarting PHP5-FPM, Please Wait... \e[0m"
service php5-fpm start || OwnError "Unable To Restart PHP5-FPM"
fi
}
# Easy Engine System Settings
if [ "$1" = "system" ]
then
# Easy Engine Install
if [ "$2" = "install" ]
then
if [ "$3" = "nginx" ]
then
# Install Python Software Properties
12 years ago
echo -e "\033[34m Installing Python Software Properties... \e[0m"
sudo apt-get -y install python-software-properties \
12 years ago
|| OwnError "Unable To Install Python Software Properties"
# Add Nginx Launchpad Repository
echo -e "\033[34m Adding Brianmercer Nginx Launchpad Repository... \e[0m"
sudo add-apt-repository ppa:brianmercer/nginx \
|| OwnError "Unable To Add Nginx Launchpad Repository"
# Fix GPG Key Problems
echo -e "\033[34m Checking GPG Keys For Brianmercer Nginx Repository... \e[0m"
sudo apt-get update > /dev/null 2> /tmp/keymissing \
|| OwnError "Unable To Fix GPG Keys For Brianmercer Nginx Repository "
for key in $(grep "NO_PUBKEY" /tmp/keymissing |sed "s/.*NO_PUBKEY //")
do
echo -e "\033[34m Processing key: $key \e[0m"
gpg --keyserver subkeys.pgp.net --recv $key && sudo gpg --export --armor $key | apt-key add -
done
# Update The APT Cache
echo -e "\033[34m Updating APT Cache... \e[0m"
sudo apt-get update || OwnError "Unable To Update APT Cache"
# Install Nginx
12 years ago
echo -e "\033[34m Installing Nginx... \e[0m"
sudo apt-get -y install nginx-custom || OwnError "Unable To Install Nginx"
# Display Success Message
echo -e "\033[34m Nginx Successfully Installed \e[0m"
elif [ "$3" = "php" ]
then
# Install Python Software Properties
12 years ago
echo -e "\033[34m Installing Python Software Properties... \e[0m"
sudo apt-get -y install python-software-properties \
12 years ago
|| OwnError "Unable To Install Python Software Properties"
# Add PHP Launchpad Repository
12 years ago
echo -e "\033[34m Adding PHP5 Launchpad Repository... \e[0m"
sudo add-apt-repository ppa:ondrej/php5 \
12 years ago
|| OwnError "Unable To Add PHP5 Launchpad Repository"
# Fix GPG Key Problems
echo -e "\033[34m Checking GPG Keys For Ondrej PHP5 Repository... \e[0m"
sudo apt-get update > /dev/null 2> /tmp/keymissing \
|| OwnError "Unable To Fix GPG Keys For Ondrej PHP5 Repository "
for key in $(grep "NO_PUBKEY" /tmp/keymissing |sed "s/.*NO_PUBKEY //")
do
echo -e "\033[34m Processing key: $key \e[0m"
gpg --keyserver subkeys.pgp.net --recv $key && sudo gpg --export --armor $key | apt-key add -
done
# Update The APT Cache
echo -e "\033[34m Updating APT Cache... \e[0m"
sudo apt-get update || OwnError "Unable To Update APT Cache"
# Install PHP5
12 years ago
echo -e "\033[34m Installing PHP5... \e[0m"
sudo apt-get -y install php5-common php5-mysql php5-xmlrpc \
php5-cgi php5-curl php5-gd php5-cli php5-fpm php-apc php-pear \
12 years ago
php5-dev php5-imap php5-mcrypt || OwnError "Unable To Install PHP5"
# Display Success Message
echo -e "\033[34m PHP5 Successfully Installed \e[0m"
elif [ "$3" = "mysql" ]
then
# Update The APT Cache
12 years ago
echo -e "\033[34m Updating APT Cache... \e[0m"
sudo apt-get update || OwnError "Unable To Update APT Cache"
# Install MySQL
12 years ago
echo -e "\033[34m Installing MySQL... \e[0m"
sudo apt-get -y install mysql-server mysqltuner \
|| OwnError "Unable To Install MySQL"
# Display Success Message
echo -e "\033[34m MySQL Successfully Installed \e[0m"
elif [ "$3" = "postfix" ]
then
# Update The APT Cache
12 years ago
echo -e "\033[34m Updating APT Cache... \e[0m"
sudo apt-get update || OwnError "Unable To Update APT Cache"
# Install Postfix
12 years ago
echo -e "\033[34m Installing Postfix... \e[0m"
sudo apt-get -y install postfix || OwnError "Unable To Install Postfix"
# Display Success Message
echo -e "\033[34m Postfix Successfully Installed \e[0m"
elif [ "$3" = "--all" ]
then
# Install Python Software Properties
12 years ago
echo -e "\033[34m Installing Python Software Properties... \e[0m"
sudo apt-get -y install python-software-properties \
12 years ago
|| OwnError "Unable To Install Python Software Properties"
# Add Nginx Launchpad Repository
echo -e "\033[34m Adding Brianmercer Nginx Launchpad Repository... \e[0m"
sudo add-apt-repository ppa:brianmercer/nginx \
|| OwnError "Unable To Add Nginx Launchpad Repository"
# Add PHP Launchpad Repository
12 years ago
echo -e "\033[34m Adding PHP5 Launchpad Repository... \e[0m"
sudo add-apt-repository ppa:ondrej/php5 \
12 years ago
|| OwnError "Unable To Add PHP5 Launchpad Repository"
# Fix GPG Key Problems
echo -e "\033[34m Checking GPG Keys For Brianmercer Nginx & Ondrej PHP5 Repository... \e[0m"
sudo apt-get update > /dev/null 2> /tmp/keymissing \
|| OwnError "Unable To Fix GPG Keys For Nginx & PHP5 Repository "
for key in $(grep "NO_PUBKEY" /tmp/keymissing |sed "s/.*NO_PUBKEY //")
do
echo -e "\033[34m Processing key: $key \e[0m"
gpg --keyserver subkeys.pgp.net --recv $key && sudo gpg --export --armor $key | apt-key add -
done
# Update The APT Cache
echo -e "\033[34m Updating APT Cache... \e[0m"
sudo apt-get update || OwnError "Unable To Update APT Cache"
# Install Nginx PHP5 MySQL Postfix
12 years ago
echo -e "\033[34m Installing Nginx PHP5 MySQL Postfix... \e[0m"
sudo apt-get -y install nginx-custom php5-common php5-mysql php5-xmlrpc \
php5-cgi php5-curl php5-gd php5-cli php5-fpm php-apc php-pear \
php5-dev php5-imap php5-mcrypt mysql-server mysqltuner postfix \
12 years ago
|| OwnError "Unable To Install Nginx PHP5 MySQL Postfix"
# Display Success Message
echo -e "\033[34m Nginx PHP5 MySQL Postfix Successfully Installed \e[0m"
else
EngineHelp
fi
# Easy Engine Remove
elif [ "$2" = "remove" ]
then
if [ "$3" = "nginx" ]
then
# Remove Nginx
12 years ago
echo -e "\033[34m Removing Nginx... \e[0m"
sudo apt-get -y remove nginx-custom || OwnError "Unable To Remove Nginx"
# Remove Unwanted Packages
echo -e "\033[34m Removing Unwanted Packages... \e[0m"
sudo apt-get -y autoremove
# Display Success Message
echo -e "\033[34m Nginx Successfully Removed \e[0m"
elif [ "$3" = "php" ]
then
# Remove PHP5
12 years ago
echo -e "\033[34m Removing PHP5... \e[0m"
sudo apt-get -y remove php5-common php5-mysql php5-xmlrpc \
php5-cgi php5-curl php5-gd php5-cli php5-fpm php-apc php-pear \
12 years ago
php5-dev php5-imap php5-mcrypt || OwnError "Unable To Remove PHP5"
# Remove Unwanted Packages
echo -e "\033[34m Removing Unwanted Packages... \e[0m"
sudo apt-get -y autoremove
# Display Success Message
echo -e "\033[34m PHP5 Successfully Removed \e[0m"
elif [ "$3" = "mysql" ]
then
# Remove MySQL
12 years ago
echo -e "\033[34m Removing MySQL... \e[0m"
sudo apt-get -y remove mysql-server mysqltuner \
12 years ago
|| OwnError "Unable To Remove MySQL"
# Remove Unwanted Packages
echo -e "\033[34m Removing Unwanted Packages... \e[0m"
sudo apt-get -y autoremove
# Display Success Message
echo -e "\033[34m MySQL Successfully Removed \e[0m"
elif [ "$3" = "postfix" ]
then
# Remove Postfix
12 years ago
echo -e "\033[34m Removing Postfix... \e[0m"
sudo apt-get -y remove postfix || OwnError "Unable To Remove Postfix"
# Remove Unwanted Packages
echo -e "\033[34m Removing Unwanted Packages... \e[0m"
sudo apt-get -y autoremove
# Display Success Message
echo -e "\033[34m Postfix Successfully Removed \e[0m"
elif [ "$3" = "--all" ]
then
# Remove All
12 years ago
echo -e "\033[34m Removing Nginx PHP5 MySQL Postfix... \e[0m"
sudo apt-get -y remove nginx-custom php5-common php5-mysql php5-xmlrpc \
php5-cgi php5-curl php5-gd php5-cli php5-fpm php-apc php-pear \
php5-dev php5-imap php5-mcrypt mysql-server mysqltuner postfix \
|| OwnError "Unable To Remove Nginx PHP5 MySQL Postfix"
# Remove Unwanted Packages
echo -e "\033[34m Removing Unwanted Packages... \e[0m"
sudo apt-get -y autoremove
# Display Success Message
echo -e "\033[34m Nginx PHP5 MySQL Postfix Successfully Removed \e[0m"
else
EngineHelp
fi
# Easy Engine Purge
elif [ "$2" = "purge" ]
then
if [ "$3" = "nginx" ]
then
# Purge Nginx
12 years ago
echo -e "\033[34m Purge Nginx... \e[0m"
sudo apt-get -y remove --purge nginx-custom || OwnError "Unable To Purge Nginx"
# Remove Unwanted Packages
echo -e "\033[34m Removing Unwanted Packages... \e[0m"
sudo apt-get -y autoremove
# Display Success Message
echo -e "\033[34m Nginx Successfully Purged \e[0m"
elif [ "$3" = "php" ]
then
# Purge PHP5
12 years ago
echo -e "\033[34m Purge PHP5... \e[0m"
sudo apt-get -y remove --purge php5-common php5-mysql php5-xmlrpc \
php5-cgi php5-curl php5-gd php5-cli php5-fpm php-apc php-pear \
12 years ago
php5-dev php5-imap php5-mcrypt || OwnError "Unable To Purge PHP5"
# Remove Unwanted Packages
echo -e "\033[34m Removing Unwanted Packages... \e[0m"
sudo apt-get -y autoremove
# Display Success Message
echo -e "\033[34m PHP5 Successfully Purged \e[0m"
elif [ "$3" = "mysql" ]
then
# Purge MySQL
12 years ago
echo -e "\033[34m Purge MySQL... \e[0m"
sudo apt-get -y remove --purge mysql-server mysqltuner \
12 years ago
|| OwnError "Unable To Purge MySQL"
# Remove Unwanted Packages
echo -e "\033[34m Removing Unwanted Packages... \e[0m"
sudo apt-get -y autoremove
# Display Success Message
echo -e "\033[34m MySQL Successfully Purged \e[0m"
elif [ "$3" = "postfix" ]
then
# Purge Postfix
12 years ago
echo -e "\033[34m Purge Postfix... \e[0m"
sudo apt-get -y remove --purge postfix || OwnError "Unable To Purge Postfix"
# Remove Unwanted Packages
echo -e "\033[34m Removing Unwanted Packages... \e[0m"
sudo apt-get -y autoremove
# Display Success Message
echo -e "\033[34m Postfix Successfully Purged \e[0m"
elif [ "$3" = "--all" ]
then
# Purge All
12 years ago
echo -e "\033[34m Purge Nginx PHP5 MySQL Postfix... \e[0m"
sudo apt-get -y remove --purge nginx-custom php5-common php5-mysql php5-xmlrpc \
php5-cgi php5-curl php5-gd php5-cli php5-fpm php-apc php-pear \
php5-dev php5-imap php5-mcrypt mysql-server mysqltuner postfix \
|| OwnError "Unable To Purge Nginx PHP5 MySQL Postfix"
# Remove Unwanted Packages
echo -e "\033[34m Removing Unwanted Packages... \e[0m"
sudo apt-get -y autoremove
# Display Success Message
echo -e "\033[34m Nginx PHP5 MySQL Postfix Successfully Purged \e[0m"
else
EngineHelp
fi
12 years ago
# Easy Engine Help
else
EngineHelp
fi
12 years ago
# Easy Engine Site Settings
elif [ "$1" = "site" ]
then
12 years ago
# Easy Engine Read
if [ "$2" = "read" ]
then
if [ "$3" = "all" ]
then
# Display The List Of All Sites
12 years ago
echo -e "\033[34m List Of All (sites-available) Websites \e[0m"
ls /etc/nginx/sites-available/ \
12 years ago
|| OwnError "Unable To Display The List Of Websites"
elif [ "$3" = "active" ]
then
# Display The List Of Active Sites
12 years ago
echo -e "\033[34m List Of Active (sites-enabled) Websites \e[0m"
ls /etc/nginx/sites-enabled/ \
12 years ago
|| OwnError "Unable To Display The List Of Active Websites"
elif [ "$3" != "all" ] && [ "$3" != "active" ] && [ -n "$3" ]
then
# Check The Website Is Exist
ls /etc/nginx/sites-available/$3 &> /dev/null \
12 years ago
|| OwnError "The $3 Is Not Found In Available Websites List"
if [ $? -eq 0 ]
then
# Display The Specific Site Configuration
12 years ago
echo -e "\033[34m Display The $3 Configuration Settings \e[0m"
cat /etc/nginx/sites-available/$3 \
12 years ago
|| OwnError "Unable To Display The $3 Configuration Settings"
fi
else
EngineHelp
fi
12 years ago
# Easy Engine Create
elif [ "$2" = "create" ]
then
if [ -n "$3" ]
then
# Remove http:// & www.
DOMAIN=$(echo $3 | sed "s'http://''" | sed "s'www.''")
# Creating Site
12 years ago
echo -e "\033[34m Creating $DOMAIN, Please Wait... \e[0m"
sed "s/example.com/$DOMAIN/g" \
/usr/share/easyengine/nginx/singlesite/basic.conf \
> /etc/nginx/sites-available/$DOMAIN \
12 years ago
|| OwnError "Unable To Create Configuration File For $DOMAIN"
# Creating Symbolic Link
12 years ago
echo -e "\033[34m Creating Symbolic Link \e[0m"
ln -s /etc/nginx/sites-available/$DOMAIN /etc/nginx/sites-enabled/ \
12 years ago
|| OwnError "Unable To Create Symbolic Link For $DOMAIN"
# Creating Htdocs & Logs Directory
12 years ago
echo -e "\033[34m Creating htdocs & logs Directory \e[0m"
(mkdir -p /var/www/$DOMAIN/htdocs; mkdir -p /var/www/$DOMAIN/logs) \
12 years ago
|| OwnError "Unable To Create htdocs & logs Directory"
# Creating Symbolic Links For Logs
12 years ago
echo -e "\033[34m Creating Symbolic Link For Logs \e[0m"
ln -s /var/log/nginx/$DOMAIN.access.log /var/www/$DOMAIN/logs/access.log \
&& ln -s /var/log/nginx/$DOMAIN.error.log /var/www/$DOMAIN/logs/error.log \
12 years ago
|| OwnError "Unable To Create Symbolic Link For $DOMAIN Logs"
if [ "$4" = "--with-wordpress" ]
then
# Download Latest Wordpress
12 years ago
echo -e "\033[34m Downloading WordPress \e[0m"
wget -cO /var/www/$DOMAIN/htdocs/latest.tar.gz \
http://wordpress.org/latest.tar.gz
# Extracting Wordpress
tar --strip-components=1 -zxf /var/www/$DOMAIN/htdocs/latest.tar.gz \
-C /var/www/$DOMAIN/htdocs/
# Removing Wordpress Archive
rm /var/www/$DOMAIN/htdocs/latest.tar.gz
12 years ago
# Call MYSQLINFO Function For MySQL Values
MYSQLINFO
# Modify wp-config.php & Move Outside The Webroot
cp -v /var/www/$DOMAIN/htdocs/wp-config-sample.php \
/var/www/$DOMAIN/wp-config.php
sed -i "s/database_name_here/$WPDBNAME/" \
/var/www/$DOMAIN/wp-config.php
sed -i "s/username_here/$MYSQLUSER/" \
/var/www/$DOMAIN/wp-config.php
sed -i "s/password_here/$MYSQLPASS/" \
/var/www/$DOMAIN/wp-config.php
sed -i "s/localhost/$MYSQLHOST/" \
/var/www/$DOMAIN/wp-config.php
printf '%s\n' "g/put your unique phrase here/d" \
a "$(curl -L https://api.wordpress.org/secret-key/1.1/salt/)" . w \
| ed -s /var/www/$DOMAIN/wp-config.php
fi
12 years ago
# Call WEBUSERINFO Function For Web User Details
WEBUSERINFO
# Change Ownership
echo -e "\033[34m Changing Ownership \e[0m"
#echo $NGINXUSER $DOMAIN
chown -R $NGINXUSER:$NGINXUSER /var/www/$DOMAIN/
# Reload Nginx Configuration
NGINXRELOAD
# Start PHP-FPM If Not Running
PHPSTART
# Display Success Message
12 years ago
echo -e "\033[34m http://$DOMAIN Domain Successfully Created \e[0m"
else
EngineHelp
fi
12 years ago
# Easy Engine Update
elif [ "$2" = "update" ]
then
if [ -n "$3" ]
then
# Remove http:// & www.
DOMAIN=$(echo $3 | sed "s'http://''" | sed "s'www.''")
# Make Backup Directory For Storing Older Nginx Configurations
if [ ! -d /etc/nginx/sites-available/backups/ ]
then
mkdir -p /etc/nginx/sites-available/backups/
fi
if [ "$4" = "singlesite" ]
then
if [ "$5" = "w3total" ]
then
# Taking Backup
mv /etc/nginx/sites-available/$DOMAIN \
/etc/nginx/sites-available/backups/$DOMAIN.$(date +%d%m%Y.%H%M%S)
# Updating Site
echo -e "\033[34m Updating $DOMAIN For W3TotalCache, Please Wait... \e[0m"
sed "s/example.com/$DOMAIN/g" \
/usr/share/easyengine/nginx/singlesite/w3-total-cache.conf \
> /etc/nginx/sites-available/$DOMAIN \
|| OwnError "Unable To Update Configuration File For $DOMAIN"
# Installing W3 Total Cache
cd /var/www/$DOMAIN/htdocs/
wp plugin install w3-total-cache || OwnError "Unable To Install W3 Total Cache Plugin"
# Activate W3 Total Cache
wp plugin activate w3-total-cache || OwnError "Unable To Activate W3 Total Cache Plugin"
# Call WEBUSERINFO Function For Web User Details
WEBUSERINFO
# Give Ownership To $NGINXUSER
chown -R $NGINXUSER:$NGINXUSER /var/www/$DOMAIN/
# Display W3 Total Cache URL For Settings
echo -e "\033[34m Please Configure W3 Total Cache Settings \e[0m"
echo -e "\033[34m W3 Total Cache: http://$DOMAIN/wp-admin/admin.php?page=w3tc_general \e[0m"
# Reload Nginx Configuration
NGINXRELOAD
# Display Success Message
echo -e "\033[34m Nginx Configuration For $DOMAIN Is Successfully Updated \e[0m"
elif [ "$5" = "wpsuper" ]
then
# Taking Backup
mv /etc/nginx/sites-available/$DOMAIN \
/etc/nginx/sites-available/backups/$DOMAIN.$(date +%d%m%Y.%H%M%S)
# Updating Site
echo -e "\033[34m Updating $DOMAIN For WPSuperCache, Please Wait... \e[0m"
sed "s/example.com/$DOMAIN/g" \
/usr/share/easyengine/nginx/singlesite/wp-super-cache.conf \
> /etc/nginx/sites-available/$DOMAIN \
|| OwnError "Unable To Update Configuration File For $DOMAIN"
# Installing WP Super Cache
cd /var/www/$DOMAIN/htdocs/
wp plugin install wp-super-cache || OwnError "Unable To Install WP Super Cache Plugin"
# Activate WP Super Cache
wp plugin activate wp-super-cache || OwnError "Unable To Activate WP Super Cache Plugin"
# Call WEBUSERINFO Function For Web User Details
WEBUSERINFO
# Give Ownership To $NGINXUSER
chown -R $NGINXUSER:$NGINXUSER /var/www/$DOMAIN/
# Display W3 Total Cache URL For Settings
echo -e "\033[34m Please Configure WP Super Cache Settings \e[0m"
echo -ne "\033[34m WP Super Cache:\e[0m"
echo -e "\033[34m http://$DOMAIN/wp-admin/options-general.php?page=wpsupercache \e[0m"
# Reload Nginx Configuration
NGINXRELOAD
# Display Success Message
echo -e "\033[34m Nginx Configuration For $DOMAIN Is Successfully Updated \e[0m"
12 years ago
elif [ "$5" = "fastcgi" ]
then
12 years ago
# Taking Backup
mv /etc/nginx/sites-available/$DOMAIN \
/etc/nginx/sites-available/backups/$DOMAIN.$(date +%d%m%Y.%H%M%S)
12 years ago
# Updating Site
echo -e "\033[34m Updating $DOMAIN For Fastcgi Cache, Please Wait... \e[0m"
sed "s/example.com/$DOMAIN/g" \
/usr/share/easyengine/nginx/singlesite/fastcgi-cache.conf \
> /etc/nginx/sites-available/$DOMAIN \
|| OwnError "Unable To Update Configuration File For $DOMAIN"
# Installing Nginx Helper
cd /var/www/$DOMAIN/htdocs/
wp plugin install nginx-helper || OwnError "Unable To Install Nginx Helper"
# Activate Nginx Helper
wp plugin activate nginx-helper || OwnError "Unable To Activate Nginx Helper Plugin"
# Call WEBUSERINFO Function For Web User Details
WEBUSERINFO
# Give Ownership To $NGINXUSER
chown -R $NGINXUSER:$NGINXUSER /var/www/$DOMAIN/
# Display W3 Total Cache URL For Settings
echo -e "\033[34m Please Configure Nginx Helper Settings \e[0m"
echo -e "\033[34m Nginx Helper: http://$DOMAIN/wp-admin/options-general.php?page=nginx \e[0m"
12 years ago
# Reload Nginx Configuration
NGINXRELOAD
# Display Success Message
echo -e "\033[34m Nginx Configuration For $DOMAIN Is Successfully Updated \e[0m"
else
EngineHelp
fi
elif [ "$4" = "multisite" ]
then
12 years ago
# Presetup For WordPress MU
sed -i "/WP_DEBUG/a \define('WP_ALLOW_MULTISITE', true);" /var/www/$DOMAIN/wp-config.php
sed -i "/WP_ALLOW_MULTISITE/a \define('WPMU_ACCEL_REDIRECT', true);" /var/www/$DOMAIN/wp-config.php
if [ "$5" = "subdomain" ]
then
# Configure Network Setup
12 years ago
echo -e "\033[34m Please Open Following URL & Click On Sub-Domains & Install \e[0m"
echo -e "\033[34m Configure Network Setup: http://$DOMAIN/wp-admin/network.php \e[0m"
echo -e "\033[34m Press Enter, Once You Setup Network: \e[0m"
read
12 years ago
# Add Rules In wp-config.php gile
sed -i "/WPMU_ACCEL_REDIRECT/a \define('MULTISITE', true);\n\
define('SUBDOMAIN_INSTALL', true);\n\
\$base = '/';\n\
12 years ago
define('DOMAIN_CURRENT_SITE', '$DOMAIN');\n\
define('PATH_CURRENT_SITE', '/');\n\
define('SITE_ID_CURRENT_SITE', 1);\n\
define('BLOG_ID_CURRENT_SITE', 1);\n" /var/www/$DOMAIN/wp-config.php
# Make Blogs.Dir
mkdir /var/www/$DOMAIN/htdocs/wp-content/blogs.dir
# Call WEBUSERINFO Function For Web User Details
WEBUSERINFO
12 years ago
# Give Ownership To WEBUSER
chown -R $NGINXUSER:$NGINXUSER /var/www/$DOMAIN/htdocs/wp-content/blogs.dir
if [ "$6" = "basic" ]
then
# Installing Nginx Helper
cd /var/www/$DOMAIN/htdocs/
wp plugin install nginx-helper || OwnError "Unable To Install Nginx Helper"
# Activate Nginx Helper
wp plugin activate nginx-helper || OwnError "Unable To Activate Nginx Helper Plugin"
# Call WEBUSERINFO Function For Web User Details
WEBUSERINFO
# Give Ownership To $NGINXUSER
chown -R $NGINXUSER:$NGINXUSER /var/www/$DOMAIN/
# Display W3 Total Cache URL For Settings
echo -e "\033[34m Please Configure Nginx Helper Settings \e[0m"
echo -e "\033[34m Please Open Following URL & Click Enable Map \e[0m"
echo -ne "\033[34m Nginx Helper:\e[0m"
echo -e "\033[34m http://$DOMAIN/wp-admin/options-general.php?page=nginx \e[0m"
echo -e "\033[34m Press Enter, Once You Setup Nginx Helper Plugin: \e[0m"
read
12 years ago
12 years ago
# Taking Backup
mv /etc/nginx/sites-available/$DOMAIN \
/etc/nginx/sites-available/backups/$DOMAIN.$(date +%d%m%Y.%H%M%S)
# Updating Site
echo -e "\033[34m Updating $DOMAIN For Basic WPMU, Please Wait... \e[0m"
sed "s/example.com/$DOMAIN/g" \
/usr/share/easyengine/nginx/multisite/subdomain/basic.conf \
> /etc/nginx/sites-available/$DOMAIN \
|| OwnError "Unable To Update Configuration File For $DOMAIN"
12 years ago
# Reload Nginx Configuration
NGINXRELOAD
# Display Success Message
echo -e "\033[34m Nginx Configuration For $DOMAIN Is Successfully Updated \e[0m"
12 years ago
elif [ "$6" = "w3total" ]
then
12 years ago
# Taking Backup
mv /etc/nginx/sites-available/$DOMAIN \
/etc/nginx/sites-available/backups/$DOMAIN.$(date +%d%m%Y.%H%M%S)
# Updating Site
echo -e "\033[34m Updating $DOMAIN For W3TotalCache, Please Wait... \e[0m"
sed "s/example.com/$DOMAIN/g" \
/usr/share/easyengine/nginx/multisite/subdomain/w3-total-cache.conf \
> /etc/nginx/sites-available/$DOMAIN \
|| OwnError "Unable To Update Configuration File For $DOMAIN"
# Reload Nginx Configuration
NGINXRELOAD
# Display Success Message
echo -e "\033[34m Nginx Configuration For $DOMAIN Is Successfully Updated \e[0m"
12 years ago
elif [ "$6" = "wpsuper" ]
then
# Taking Backup
mv /etc/nginx/sites-available/$DOMAIN \
/etc/nginx/sites-available/backups/$DOMAIN.$(date +%d%m%Y.%H%M%S)
# Updating Site
echo -e "\033[34m Updating $DOMAIN For WPSuperCache, Please Wait... \e[0m"
sed "s/example.com/$DOMAIN/g" \
/usr/share/easyengine/nginx/multisite/subdomain/wp-super-cache.conf \
> /etc/nginx/sites-available/$DOMAIN \
|| OwnError "Unable To Update Configuration File For $DOMAIN"
# Reload Nginx Configuration
NGINXRELOAD
# Display Success Message
echo -e "\033[34m Nginx Configuration For $DOMAIN Is Successfully Updated \e[0m"
12 years ago
elif [ "$6" = "fastcgi" ]
then
# Taking Backup
mv /etc/nginx/sites-available/$DOMAIN \
/etc/nginx/sites-available/backups/$DOMAIN.$(date +%d%m%Y.%H%M%S)
# Updating Site
echo -e "\033[34m Updating $DOMAIN For Fastcgi Cache, Please Wait... \e[0m"
sed "s/example.com/$DOMAIN/g" \
/usr/share/easyengine/nginx/multisite/subdomain/fastcgi-cache.conf \
> /etc/nginx/sites-available/$DOMAIN \
|| OwnError "Unable To Update Configuration File For $DOMAIN"
# Reload Nginx Configuration
NGINXRELOAD
# Display Success Message
echo -e "\033[34m Nginx Configuration For $DOMAIN Is Successfully Updated \e[0m"
else
12 years ago
EngineHelp
fi
12 years ago
elif [ "$5" = "subdirectory" ]
then
# Configure Network Setup
12 years ago
echo -e "\033[34m Please Open Following URL & Click On Sub-Directories & Install \e[0m"
echo -e "\033[34m Configure Network Setup: http://$DOMAIN/wp-admin/network.php \e[0m"
echo -e "\033[34m Press Enter, Once You Setup Network: \e[0m"
read
12 years ago
# Add Rules In wp-config.php gile
sed -i "/WPMU_ACCEL_REDIRECT/a \define('MULTISITE', true);\n\
define('SUBDOMAIN_INSTALL', false);\n\
\$base = '/';\n\
12 years ago
define('DOMAIN_CURRENT_SITE', '$DOMAIN');\n\
define('PATH_CURRENT_SITE', '/');\n\
define('SITE_ID_CURRENT_SITE', 1);\n\
define('BLOG_ID_CURRENT_SITE', 1);\n" /var/www/$DOMAIN/wp-config.php
# Make Blogs.Dir
mkdir /var/www/$DOMAIN/htdocs/wp-content/blogs.dir
# Call WEBUSERINFO Function For Web User Details
WEBUSERINFO
12 years ago
# Give Ownership To WEBUSER
chown -R $NGINXUSER:$NGINXUSER /var/www/$DOMAIN/htdocs/wp-content/blogs.dir
if [ "$6" = "basic" ]
then
# Taking Backup
mv /etc/nginx/sites-available/$DOMAIN \
/etc/nginx/sites-available/backups/$DOMAIN.$(date +%d%m%Y.%H%M%S)
# Updating Site
echo -e "\033[34m Updating $DOMAIN For Basic WPMU, Please Wait... \e[0m"
sed "s/example.com/$DOMAIN/g" \
/usr/share/easyengine/nginx/multisite/subdir/basic.conf \
> /etc/nginx/sites-available/$DOMAIN \
|| OwnError "Unable To Update Configuration File For $DOMAIN"
# Reload Nginx Configuration
NGINXRELOAD
# Display Success Message
echo -e "\033[34m Nginx Configuration For $DOMAIN Is Successfully Updated \e[0m"
12 years ago
elif [ "$6" = "w3total" ]
then
# Taking Backup
mv /etc/nginx/sites-available/$DOMAIN \
/etc/nginx/sites-available/backups/$DOMAIN.$(date +%d%m%Y.%H%M%S)
# Updating Site
echo -e "\033[34m Updating $DOMAIN For W3TotalCache, Please Wait... \e[0m"
sed "s/example.com/$DOMAIN/g" \
/usr/share/easyengine/nginx/multisite/subdir/w3-total-cache.conf \
> /etc/nginx/sites-available/$DOMAIN \
|| OwnError "Unable To Update Configuration File For $DOMAIN"
# Reload Nginx Configuration
NGINXRELOAD
# Display Success Message
echo -e "\033[34m Nginx Configuration For $DOMAIN Is Successfully Updated \e[0m"
12 years ago
elif [ "$6" = "wpsuper" ]
then
# Taking Backup
mv /etc/nginx/sites-available/$DOMAIN \
/etc/nginx/sites-available/backups/$DOMAIN.$(date +%d%m%Y.%H%M%S)
# Updating Site
echo -e "\033[34m Updating $DOMAIN For WPSuperCache, Please Wait... \e[0m"
sed "s/example.com/$DOMAIN/g" \
/usr/share/easyengine/nginx/multisite/subdir/wp-super-cache.conf \
> /etc/nginx/sites-available/$DOMAIN \
|| OwnError "Unable To Update Configuration File For $DOMAIN"
# Reload Nginx Configuration
NGINXRELOAD
# Display Success Message
echo -e "\033[34m Nginx Configuration For $DOMAIN Is Successfully Updated \e[0m"
12 years ago
elif [ "$6" = "fastcgi" ]
then
# Taking Backup
mv /etc/nginx/sites-available/$DOMAIN \
/etc/nginx/sites-available/backups/$DOMAIN.$(date +%d%m%Y.%H%M%S)
# Updating Site
echo -e "\033[34m Updating $DOMAIN For Fastcgi Cache, Please Wait... \e[0m"
sed "s/example.com/$DOMAIN/g" \
/usr/share/easyengine/nginx/multisite/subdir/fastcgi-cache.conf \
> /etc/nginx/sites-available/$DOMAIN \
|| OwnError "Unable To Update Configuration File For $DOMAIN"
# Reload Nginx Configuration
NGINXRELOAD
# Display Success Message
echo -e "\033[34m Nginx Configuration For $DOMAIN Is Successfully Updated \e[0m"
else
EngineHelp
fi
else
EngineHelp
fi
else
EngineHelp
fi
else
EngineHelp
fi
12 years ago
12 years ago
# Easy Engine Delete
elif [ "$2" = "delete" ]
then
if [ -n "$3" ]
then
# Remove http:// & www.
DOMAIN=$(echo $3 | sed "s'http://''" | sed "s'www.''")
# Delete Site
echo -e "\033[34m Deleting $DOMAIN, Please Wait... \e[0m"
rm /etc/nginx/sites-available/$DOMAIN /etc/nginx/sites-enabled/$DOMAIN
# Remove Symbolic Links For Logs Files
echo -e "\033[34m Remove Symbolic Link For $DOMAIN Logs... \e[0m"
rm /var/www/$DOMAIN/logs/{access,error}.log
if [ "$4" = "--database" ]
then
# Get The Database Details
MYSQLUSER=$(grep DB_USER /var/www/$DOMAIN/wp-config.php \
| cut -d"'" -f4)
MYSQLPASS=$(grep DB_PASSWORD /var/www/$DOMAIN/wp-config.php \
| cut -d"'" -f4)
WPDBNAME=$(grep DB_NAME /var/www/$DOMAIN/wp-config.php \
| cut -d"'" -f4)
# Remove Database
echo -e "\033[34m Removing Database $WPDBNAME... \e[0m"
mysql -u $MYSQLUSER -p$MYSQLPASS -e "drop database \`$WPDBNAME\`" \
|| OwnError "Unable To Drop $WPDBNAME Database"
elif [ "$4" = "--webroot" ]
then
# Remove Webroot For $DOMAIN
echo -e "\033[34m Removing /var/www/$DOMAIN Directory... \e[0m"
12 years ago
rm -rf /var/www/$DOMAIN/
elif [ "$4" = "--all" ]
then
# Get The Database Details
MYSQLUSER=$(grep DB_USER /var/www/$DOMAIN/wp-config.php \
| cut -d"'" -f4)
MYSQLPASS=$(grep DB_PASSWORD /var/www/$DOMAIN/wp-config.php \
| cut -d"'" -f4)
WPDBNAME=$(grep DB_NAME /var/www/$DOMAIN/wp-config.php \
| cut -d"'" -f4)
# Remove Database
echo -e "\033[34m Removing Database $WPDBNAME... \e[0m"
mysql -u $MYSQLUSER -p$MYSQLPASS -e "drop database \`$WPDBNAME\`" \
|| OwnError "Unable To Drop $WPDBNAME Database"
# Remove Webroot For $DOMAIN
echo -e "\033[34m Removing /var/www/$DOMAIN Directory... \e[0m"
rm -rf /var/www/$DOMAIN
12 years ago
else
EngineHelp
fi
# Reload Nginx Configuration
NGINXRELOAD
# Display Success Message
12 years ago
echo -e "\033[34m http://$DOMAIN Successfully Deleted \e[0m"
12 years ago
else
12 years ago
EngineHelp
fi
12 years ago
# Easy Engine Help
else
EngineHelp
12 years ago
fi
12 years ago
# Easy Engine Config Settings
elif [ "$1" = "config" ]
then
12 years ago
echo "Under Developments !!"
12 years ago
# Easy Engine Update
elif [ "$1" = "update" ]
then
echo -e "\033[34m Updating Easy Engine, Please wait... \e[0m"
#curl -L http://goo.gl/FvARq | sudo bash
curl -L rt.cx/ee | sudo bash
12 years ago
# Easy Engine Help
else
EngineHelp
fi