gau1991
11 years ago
5 changed files with 113 additions and 0 deletions
@ -0,0 +1,19 @@ |
|||||
|
# Removes https://, http://, www from site name |
||||
|
|
||||
|
function ee_lib_prcoess_site_name() |
||||
|
{ |
||||
|
# Check EE_SITE_NAME is empty or not |
||||
|
if [ -z "$EE_SITE_NAME" ] |
||||
|
then |
||||
|
# Ask users to enter domain name |
||||
|
read -p "Enter domain name: " EE_SITE_NAME |
||||
|
# Remove http:// https:// & www. |
||||
|
EE_DOMAIN=$(echo $EE_SITE_NAME | tr 'A-Z' 'a-z' | sed "s'http://''" | sed "s'https://''" | sed "s'www.''" | sed "s'/''") |
||||
|
else |
||||
|
# Remove http:// https:// & www. |
||||
|
EE_DOMAIN=$(echo $EE_SITE_NAME | tr 'A-Z' 'a-z' | sed "s'http://''" | sed "s'https://''" | sed "s'www.''" | sed "s'/''") |
||||
|
fi |
||||
|
|
||||
|
# Remove http:// https:// for WordPress setup (www.example.com) |
||||
|
EE_WWWDOMAIN=$(echo $EE_SITE_NAME | tr 'A-Z' 'a-z' | sed "s'http://''" | sed "s'https://''" | sed "s'/''") |
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
# Create symbolic link for site name |
||||
|
|
||||
|
function ee_lib_symbolic_link() |
||||
|
{ |
||||
|
# Creating symbolic link |
||||
|
ee_lib_echo "Creating symbolic link, please wait..." |
||||
|
ln -sf $1 $2 \ |
||||
|
|| ee_lib_error "Unable to create symbolic link for $1 -> $2, exit status = " $? |
||||
|
} |
@ -0,0 +1,31 @@ |
|||||
|
#Setup domain |
||||
|
|
||||
|
function ee_domain_setup() |
||||
|
{ |
||||
|
#Check the NGINX configuration exist for $EE_DOMAIN |
||||
|
ls /etc/nginx/sites-available/$EE_DOMAIN &> $EE_ERROR_LOG |
||||
|
|
||||
|
if [ $? -ne 0 ];then |
||||
|
# Creating website $EE_DOMAIN |
||||
|
ee_lib_echo "Creating $EE_DOMAIN, please wait..." |
||||
|
sed "s/example.com/$EE_DOMAIN/g" \ |
||||
|
/usr/share/easyengine/nginx/$EE_NGINX_CONF \ |
||||
|
> /etc/nginx/sites-available/$EE_DOMAIN \ |
||||
|
|| ee_lib_error "Unable to create NGINX configuration file for $EE_DOMAIN, exit status = " $? |
||||
|
|
||||
|
# Creating symbolic link |
||||
|
ee_lib_symbolic_link /etc/nginx/sites-available/$EE_DOMAIN /etc/nginx/sites-enabled/ |
||||
|
|
||||
|
# Creating htdocs & logs directory |
||||
|
ee_lib_echo "Creating htdocs & logs directory" |
||||
|
mkdir -p /var/www/$EE_DOMAIN/htdocs && mkdir -p /var/www/$EE_DOMAIN/logs \ |
||||
|
|| ee_lib_error "Unable to create htdocs & logs directory, exit status = " $? |
||||
|
|
||||
|
# Creating symbolic links for logs |
||||
|
ee_lib_echo "Creating symbolic link for logs" |
||||
|
ee_lib_symbolic_link /var/log/nginx/$EE_DOMAIN.access.log /var/www/$EE_DOMAIN/logs/access.log |
||||
|
ee_lib_symbolic_link /var/log/nginx/$EE_DOMAIN.error.log /var/www/$EE_DOMAIN/logs/error.log |
||||
|
else |
||||
|
ee_lib_error "$EE_DOMAIN already exist, exit status = " $? |
||||
|
fi |
||||
|
} |
@ -0,0 +1,46 @@ |
|||||
|
# Create Database for WordPress site |
||||
|
|
||||
|
function ee_mod_create_database() |
||||
|
{ |
||||
|
local ee_replace_dot=$(echo $EE_DOMAIN | tr '.' '_') |
||||
|
# Check use default database user or custom database user |
||||
|
EE_WP_DB_RANDOM_PASSWORD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 15 | head -n1) |
||||
|
|
||||
|
# Setup MySQL database |
||||
|
if [ $($EE_CONFIG_GET mysql.db-name) == "true" ];then |
||||
|
read -p "Enter the MySQL database name [$ee_replace_dot]: " ee_database_name |
||||
|
fi |
||||
|
|
||||
|
if [ $ee_database_name = "" ]; then |
||||
|
ee_database_name=$ee_replace_dot |
||||
|
fi |
||||
|
|
||||
|
mysql -e "create database \`${ee_database_name}\`" \ |
||||
|
|| ee_lib_error "Unable to create $ee_database_name database" |
||||
|
|
||||
|
# Setup MySQL user |
||||
|
if [ $($EE_CONFIG_GET mysql.db-user) == "true" ];then |
||||
|
read -p "Enter the MySQL database username [$ee_replace_dot]: " ee_database_user |
||||
|
read -sp "Enter The MySQL Database Password [$EE_WP_DB_RANDOM_PASSWORD]: " EE_WP_DB_PASS |
||||
|
fi |
||||
|
elif |
||||
|
ee_database_user=$ee_replace_dot |
||||
|
# Fix MySQL USER ERROR 1470 (HY000) |
||||
|
EE_WP_DB_PASS=$EE_WP_DB_RANDOM_PASSWORD |
||||
|
fi |
||||
|
|
||||
|
local ee_mysql_user_16=$(echo -n $ee_database_user | wc -c) |
||||
|
|
||||
|
if [[ $ee_mysql_user_16 -gt 16 ]]; then |
||||
|
echo "MySQL database username $ee_database_user = $ee_mysql_user_16" &>> $EE_COMMAND_LOG |
||||
|
ee_lib_echo "Auto fix MySQL username to the 16 characters" |
||||
|
local ee_random_character=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n1) |
||||
|
ee_database_user=$(echo $ee_mysql_user_16 | cut -c1-16 | sed "s/.\{10\}$/$ee_random_character/") |
||||
|
fi |
||||
|
|
||||
|
# create separate user & grant permission |
||||
|
echo -e "ee_database_name = $ee_database_name \nWPDBUSER = $ee_database_user \nWPDBPASS = $EE_WP_DB_PASS" &>> $EE_COMMAND_LOG |
||||
|
mysql -e "create user '$ee_database_user'@'$MYSQLHOST' identified by '$EE_WP_DB_PASS'" |
||||
|
mysql -e "grant all privileges on \`$ee_database_name\`.* to '$ee_database_user'@'$MYSQLHOST'" |
||||
|
mysql -e "flush privileges" |
||||
|
} |
Loading…
Reference in new issue