Browse Source

Database and webroot setup

old-stable
Mitesh Shah 11 years ago
parent
commit
39c16e3266
  1. 2
      src/lib/ee_lib_symbolic_link.sh
  2. 3
      src/lib/ee_lib_variables.sh
  3. 11
      src/modules/site/create/ee_mod_domain_setup.sh
  4. 92
      src/modules/site/create/ee_mode_create_database.sh
  5. 7
      src/modules/system/install/ee_mod_install_mysql.sh

2
src/lib/ee_lib_symbolic_link.sh

@ -1,4 +1,4 @@
# Create symbolic link for site name
# Create symbolic link
function ee_lib_symbolic_link()
{

3
src/lib/ee_lib_variables.sh

@ -17,7 +17,7 @@ readonly EE_CONFIG_GET=$(echo "git config --file /etc/easyengine/ee.conf")
readonly EE_CONFIG_SET=$(echo "git config --file /etc/easyengine/ee.conf" --replace-all)
readonly EE_IP_ADDRESS=$($EE_CONFIG_GET system.ip-address | cut -d'=' -f2 | sed 's/ //g' | tr ',' '\n')
readonly EE_APT_GET=$($EE_CONFIG_GET system.apt-get-assume-yes | grep -i true &> /dev/null && echo apt-get -y || echo apt-get)
readonly EE_RANDOM=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 15 | head -n1)
# Distribution specific variable
if [ "$EE_LINUX_DISTRO" == "Ubuntu" ]; then
@ -40,7 +40,6 @@ else
fi
# Find out MySQL hostname
if [ -z $($EE_CONFIG_GET mysql.host) ]; then
readonly EE_MYSQL_HOST=localhost
else

11
src/modules/site/create/ee_mod_domain_setup.sh

@ -1,12 +1,11 @@
#Setup domain
# Domain setup
function ee_domain_setup()
function ee_mod_domain_setup()
{
#Check the NGINX configuration exist for $EE_DOMAIN
ls /etc/nginx/sites-available/$EE_DOMAIN &> $EE_ERROR_LOG
ls /etc/nginx/sites-available/$EE_DOMAIN &>> $EE_COMMAND_LOG
if [ $? -ne 0 ]; then
if [ $? -ne 0 ];then
# Creating website $EE_DOMAIN
# Creating $EE_DOMAIN
ee_lib_echo "Creating $EE_DOMAIN, please wait..."
sed "s/example.com/$EE_DOMAIN/g" \
/usr/share/easyengine/nginx/$EE_NGINX_CONF \

92
src/modules/site/create/ee_mode_create_database.sh

@ -1,46 +1,62 @@
# Create Database for WordPress site
# Database setup
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)
# Replace dot(.) with underscore(_) in EE_DOMAIN Name
ee_replace_dot=$(echo $EE_DOMAIN | tr '.' '_')
# Setup MySQL database
# Default database or custom database
if [ $($EE_CONFIG_GET mysql.db-name) == "true" ];then
read -p "Enter the MySQL database name [$ee_replace_dot]: " ee_database_name
read -p "Enter the MySQL database name [$ee_replace_dot]: " EE_DB_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"
# If mysql.db-name = false
# Then it never ask for MySQL database name in this case $EE_DB_NAME is empty
# If mysql.db-name = true
# User enter custom database name then $EE_DB_NAME is not empty & we used provided database name
# If user pressed enter then $EE_DB_NAME is empty
if [[ $EE_DB_NAME = "" ]]; then
EE_DB_NAME=$ee_replace_dot
fi
# Default database user or custom user
if [ $($EE_CONFIG_GET mysql.db-user) == "true" ]; then
read -p "Enter the MySQL database username [$ee_replace_dot]: " EE_DB_USER
read -sp "Enter the MySQL database password [$EE_RANDOM]: " EE_DB_PASS
fi
# If mysql.db-user = false
# Then it never ask for MySQL database user in this case $EE_DB_USER is empty
# If mysql.db-name = true
# User enter custom database user then $EE_DB_USER is not empty & we used provided database user
# If user pressed enter then $EE_DB_USER is empty
if [[ $EE_DB_USER = "" ]]; then
EE_DB_USER=$ee_replace_dot
fi
if [[ $EE_DB_PASS = "" ]]; then
EE_DB_PASS=$EE_RANDOM
fi
# Fix MySQL username ERROR 1470 (HY000)
if [[ $(echo -n $EE_DB_USER | wc -c) -gt 16 ]]; then
ee_lib_echo "Autofix MySQL username (ERROR 1470 (HY000)), please wait..."
local ee_random10=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n1)
EE_DB_USER=$(echo $EE_DB_USER | cut -c1-16 | sed "s/.\{10\}$/$ee_random10/")
fi
# Create MySQL database
echo -e "EE_DB_NAME = $EE_DB_NAME \nEE_DB_USER = $EE_DB_USER \nEE_DB_PASS = $EE_DB_PASS" &>> $EE_COMMAND_LOG
mysql -e "create database \`$EE_DB_NAME\`" \
|| ee_lib_error "Unable to create $EE_DB_NAME database, exit status = " $?
# Create MySQL User
mysql -e "create user '$EE_DB_USER'@'$EE_MYSQL_HOST' identified by '$EE_DB_PASS'" \
|| ee_lib_error "Unable to create $EE_DB_USER database, exit status = " $?
# Grant permission
mysql -e "grant all privileges on \`$EE_DB_NAME\`.* to '$EE_DB_USER'@'$EE_MYSQL_HOST'"
mysql -e "flush privileges"
}

7
src/modules/system/install/ee_mod_install_mysql.sh

@ -10,12 +10,11 @@ ee_mod_install_mysql()
if [ -n "$EE_PACKAGE_NAME" ]; then
# Setting up MySQL password
local ee_mysql_auto_pass=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 15 | head -n1)
debconf-set-selections <<< "mysql-server mysql-server/root_password password $ee_mysql_auto_pass"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $ee_mysql_auto_pass"
debconf-set-selections <<< "mysql-server mysql-server/root_password password $EE_RANDOM"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $EE_RANDOM"
# Generate ~/.my.cnf
echo -e "[client]\nuser=root\npassword=$ee_mysql_auto_pass" > ~/.my.cnf
echo -e "[client]\nuser=root\npassword=$EE_RANDOM" > ~/.my.cnf
fi

Loading…
Cancel
Save