From 448870d1bca8413769b3bd81aaf66c61c0db7052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristhian=20Mart=C3=ADnez=20Ochoa?= Date: Tue, 3 Apr 2018 20:44:59 -0500 Subject: [PATCH] mysql site unattended MySQL site now can run unattended and also acept default and custom data. --- lib/sites | 32 +++++++++++++++++++++----------- plugins/site | 21 ++++++++++++++------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/lib/sites b/lib/sites index abddf1a..5da391e 100644 --- a/lib/sites +++ b/lib/sites @@ -77,9 +77,9 @@ dbword_check() { wpinstall() { + [[ $domain == "-mysql" ]] && local dom="Webinoly_$(pwgen -s -1)" || local dom=${domain//./_} local ROOT_PASS=$( echo $(conf_read mysql-root) | openssl enc -d -a -salt ) local AUTOGENPASS_WPDB=`pwgen -s -1` - local dom=${domain//./_} local setupmysql="y" local setupwp="y" local dbhost="localhost" @@ -89,7 +89,7 @@ wpinstall() { local dbpref="wp_" # WP with Custom Data - if [[ $wp == 3 ]]; then + if [[ $wp == [35] ]]; then [[ $setmsqcustom == "false" ]] && setupmysql="n" [[ $setpwpcustom == "false" ]] && setupwp="n" @@ -102,6 +102,16 @@ wpinstall() { dbproot="$expasscustom" fi + # Print MySQL default data + if [[ $wp == 4 ]]; then + echo "${blu}" + echo "Host: $dbhost" + echo "Database Name: $dbname" + echo "Database User: $dbuser" + echo "Password: $dbpass" + echo "${end}" + fi + echo "${blu}" if [[ $wp == 1 ]]; then echo "Do you need to setup new MySQL database? [Y/n]" @@ -117,7 +127,7 @@ wpinstall() { fi # Just create DB, not install WP - [[ $wp == 0 ]] && setupwp="n" + [[ $wp == [045] ]] && setupwp="n" # Download WP (latest version) if [[ $wp == [123] ]]; then @@ -137,16 +147,16 @@ wpinstall() { done="1" # Ask DB data or suggest default values echo "" - [[ $wp == [23] ]] || read -p "Database Host [localhost]:" dbhost + [[ $wp == [2345] ]] || read -p "Database Host [localhost]:" dbhost dbhost=${dbhost:-localhost} - if [[ $dbhost == "localhost" && ( "$setupmysql" == y || "$setupmysql" == Y ) && $(conf_read mysql) != "true" ]]; then + if [[ $dbhost == "localhost" && $setupmysql == [yY] && $(conf_read mysql) != "true" ]]; then echo "${red} [ERROR] MySQL is not installed or localhost was not found!${blu}" done="0" continue 1; fi # Check if localhost or external DB - if [[ $dbhost != "localhost" && ( "$setupmysql" == y || "$setupmysql" == Y ) ]]; then + if [[ $dbhost != "localhost" && $setupmysql == [yY] ]]; then if [[ $(conf_read mysql-client) != "true" ]]; then echo "${gre}MySQL Client is not installed and we need it to stablish a connection with your external server." echo "Wait while we install MySQL Client... installing!!!${end}" @@ -155,7 +165,7 @@ wpinstall() { fi echo "${blu}" - if [[ $wp == 1 || ($wp == 3 && ( -z $dburoot || -z $dbproot )) ]]; then + if [[ $wp == 1 || ($wp == [35] && ( -z $dburoot || -z $dbproot )) ]]; then read -p "External DB root username [root]: " dburoot read -p "External DB root password: " dbproot echo "" @@ -169,7 +179,7 @@ wpinstall() { # ************* Ask for DB Name and validate data *************** # dom=$(dbword_check $dom) - [[ $wp == [23] ]] || read -p "Database Name [$dom]:" dbname + [[ $wp == [2345] ]] || read -p "Database Name [$dom]:" dbname dbname=${dbname:-$dom} # Check for duplicate database names, if already exists ask for another dbname to create the new db @@ -234,7 +244,7 @@ wpinstall() { fi # ************* Ask for DB User and validate data *************** # - [[ $wp == [23] ]] || read -p "Database User [$dom]:" dbuser + [[ $wp == [2345] ]] || read -p "Database User [$dom]:" dbuser dbuser=${dbuser:-$dom} # Check for duplicate database users, if already exists ask for another dbuser to create the new user @@ -298,10 +308,10 @@ wpinstall() { done fi - if [[ $wp != [23] ]]; then + if [[ $wp != [2345] ]]; then read -p "Database Password [$AUTOGENPASS_WPDB]:" dbpass # Not ask for wp_prefix when wp=0 (mysql only site) - [[ $wp == 0 ]] || read -p "Database Prefix [wp_]:" dbpref + [[ $wp == [045] ]] || read -p "Database Prefix [wp_]:" dbpref echo "${end}" # If empty, assign defalut values diff --git a/plugins/site b/plugins/site index 3b0ac6a..49ee4a7 100644 --- a/plugins/site +++ b/plugins/site @@ -31,7 +31,11 @@ fi # Extract value if exist -if [[ $type == "-parked="* || $type == "-proxy="* || $type == "-wp="* || $type == "-wpsubdir="* || $type == "-wpsubdom="* || $type == "-ssl-off="* ]]; then +if [[ $domain == "-mysql="* ]]; then + value=$(echo "${domain}" | cut -d'=' -f 2 -s) + domain=$(echo "${domain}" | cut -d'=' -f 1 -s) +fi +if [[ $type == "-parked="* || $type == "-proxy="* || $type == "-wp="* || $type == "-wpsubdir="* || $type == "-wpsubdom="* || $type == "-ssl-off="* || $type == "-mysql="* ]]; then value=$(echo "${type}" | cut -d'=' -f 2 -s) type=$(echo "${type}" | cut -d'=' -f 1 -s) fi @@ -58,20 +62,23 @@ fi [[ $cache == "-subdomain" && $value == "false" ]] && subdomflag="0" -# Evaluate if site to create is WP ( 0 = noWP, 1 = WP, 2 = WP with default values, 3 = WP with custom values ) +# Evaluate if site to create is WP ( 0 = noWP, 1 = WP, 2 = WP with default values, 3 = WP with custom values, 4 = MySQL with default values, 3 = MySQL with custom values ) wp="0" -if [[ $type == "-wp" || $type == "-wpsubdir" || $type == "-wpsubdom" ]]; then - wp="1" +if [[ $type == "-wp" || $type == "-wpsubdir" || $type == "-wpsubdom" || $type == "-mysql" || $domain == "-mysql" ]]; then + [[ $type == "-mysql" || $domain == "-mysql" ]] || wp="1" if [[ -n $value ]]; then if [[ $value == "default" ]]; then - wp="2" + [[ $type == "-mysql" || $domain == "-mysql" ]] && wp="4" || wp="2" else # -wp=[setupmysql,setupwp,dbhost,dbname,dbuser,dbpass,dbpref,extdbuser,extdbpass] custombegin=$(echo "${value}" | cut -c-1) customlast=$(echo "${value}" | rev | cut -c-1) wpdata=${value:1:-1} + # Because MySQL format not have this parameters at the beggining to match WP format. Insert it! + [[ $type == "-mysql" || $domain == "-mysql" ]] && wpdata=${wpdata/#/true,false,} + # Double coma is for lower case convertion setmsqcustom=$(echo "${wpdata,,}" | cut -d',' -f 1 -s) setpwpcustom=$(echo "${wpdata,,}" | cut -d',' -f 2 -s) @@ -84,8 +91,8 @@ if [[ $type == "-wp" || $type == "-wpsubdir" || $type == "-wpsubdom" ]]; then exusercustom=$(echo "${wpdata}" | cut -d',' -f 8 -s) expasscustom=$(echo "${wpdata}" | cut -d',' -f 9 -s) - if [[ $custombegin == "[" && $customlast == "]" && ((($setmsqcustom == "true" || $setpwpcustom == "true") && -n $dbhostcustom && -n $dbnamecustom && -n $dbusercustom && -n $dbpasscustom && -n $dbprefcustom) || ($setmsqcustom == "false" && $setpwpcustom == "false")) ]]; then - wp="3" + if [[ $custombegin == "[" && $customlast == "]" && ((($setmsqcustom == "true" || $setpwpcustom == "true") && -n $dbhostcustom && -n $dbnamecustom && -n $dbusercustom && -n $dbpasscustom && (-n $dbprefcustom || $type == "-mysql" || $domain == "-mysql")) || ($setmsqcustom == "false" && $setpwpcustom == "false")) ]]; then + [[ $type == "-mysql" || $domain == "-mysql" ]] && wp="5" || wp="3" fi fi fi