Unattended WP installation

Unattended WP installation with default data.
This commit is contained in:
Cristhian Martínez Ochoa 2017-12-01 18:15:06 -07:00
parent 34a0912d25
commit ed9b5b2841
2 changed files with 48 additions and 34 deletions

View file

@ -20,21 +20,29 @@ nginx_helper_plugin() {
wpinstall() { wpinstall() {
local AUTOGENPASS_WPDB=`pwgen -s -1`
local dom=${domain//./_}
local setupmysql="y"
local setupwp="y"
local dbhost="localhost"
local dbname=$dom
local dbuser=$dom
local dbpass=$AUTOGENPASS_WPDB
local dbpref="wp_"
echo "${blu}" echo "${blu}"
echo "Do you need to setup new MySQL database? [Y/n]" if [[ $wp != [2] ]]; then
while read -r -n 1 -s setupmysql; do echo "Do you need to setup new MySQL database? [Y/n]"
local setupmysql=${setupmysql:-y} while read -r -n 1 -s setupmysql; do
if [[ $setupmysql = [YyNn] ]]; then setupmysql=${setupmysql:-y}
break [[ $setupmysql = [YyNn] ]] && break
fi done
done echo "Create WP-Config file automatically? [Y/n]"
echo "Create WP-Config file automatically? [Y/n]" while read -r -n 1 -s setupwp; do
while read -r -n 1 -s setupwp; do setupwp=${setupwp:-y}
local setupwp=${setupwp:-y} [[ $setupwp = [YyNn] ]] && break
if [[ $setupwp = [YyNn] ]]; then done
break fi
fi
done
# Download WP (latest version) # Download WP (latest version)
sudo wget --timeout=15 -qrO /var/www/$domain/htdocs/wp.tar.gz https://wordpress.org/latest.tar.gz sudo wget --timeout=15 -qrO /var/www/$domain/htdocs/wp.tar.gz https://wordpress.org/latest.tar.gz
@ -45,8 +53,6 @@ wpinstall() {
# Generate and auto-fill wp-config.php and also create database # Generate and auto-fill wp-config.php and also create database
if [[ "$setupmysql" == y || "$setupmysql" == Y || "$setupwp" == y || "$setupwp" == Y ]] ; then if [[ "$setupmysql" == y || "$setupmysql" == Y || "$setupwp" == y || "$setupwp" == Y ]] ; then
local AUTOGENPASS_WPDB=`pwgen -s -1`
local dom=${domain//./_}
local done="0" local done="0"
while [[ $done != "1" ]] while [[ $done != "1" ]]
@ -54,8 +60,8 @@ wpinstall() {
done="1" done="1"
# Ask DB data or suggest default values # Ask DB data or suggest default values
echo "" echo ""
read -p "Database Host [localhost]:" dbhost [[ $wp == [2] ]] || read -p "Database Host [localhost]:" dbhost
local dbhost=${dbhost:-localhost} dbhost=${dbhost:-localhost}
if [[ $dbhost == "localhost" && ( "$setupmysql" == y || "$setupmysql" == Y ) && $(conf_read mysql) != "true" ]]; then if [[ $dbhost == "localhost" && ( "$setupmysql" == y || "$setupmysql" == Y ) && $(conf_read mysql) != "true" ]]; then
echo "${red} [ERROR] MySQL is not installed or localhost was not found!${blu}" echo "${red} [ERROR] MySQL is not installed or localhost was not found!${blu}"
@ -81,8 +87,8 @@ wpinstall() {
local dbport=$(echo "$dbhost" | cut -f 2 -d ':') local dbport=$(echo "$dbhost" | cut -f 2 -d ':')
fi fi
read -p "Database Name [$dom]:" dbname [[ $wp == [2] ]] || read -p "Database Name [$dom]:" dbname
local dbname=${dbname:-$dom} dbname=${dbname:-$dom}
# Check for duplicate database names, if already exists ask for another dbname to create the new db # Check for duplicate database names, if already exists ask for another dbname to create the new db
if [[ "$setupmysql" == y || "$setupmysql" == Y ]]; then if [[ "$setupmysql" == y || "$setupmysql" == Y ]]; then
@ -135,16 +141,17 @@ wpinstall() {
fi fi
done done
fi fi
read -p "Database User [$dom]:" dbuser if [[ $wp != [2] ]]; then
read -p "Database Password [$AUTOGENPASS_WPDB]:" dbpass read -p "Database User [$dom]:" dbuser
read -p "Database Prefix [wp_]:" dbpref read -p "Database Password [$AUTOGENPASS_WPDB]:" dbpass
echo "${end}" read -p "Database Prefix [wp_]:" dbpref
echo "${end}"
# If empty, assign defalut values
local dbuser=${dbuser:-$dom} # If empty, assign defalut values
local dbpass=${dbpass:-$AUTOGENPASS_WPDB} dbuser=${dbuser:-$dom}
local dbpref=${dbpref:-wp_} dbpass=${dbpass:-$AUTOGENPASS_WPDB}
dbpref=${dbpref:-wp_}
fi
# DB Creation # DB Creation
if [[ "$setupmysql" == y || "$setupmysql" == Y ]] ; then if [[ "$setupmysql" == y || "$setupmysql" == Y ]] ; then
@ -263,7 +270,7 @@ deletesite() {
createsite() { createsite() {
if [[ "$wp" == "1" && $(conf_read php) != "true" ]]; then if [[ "$wp" == [12] && $(conf_read php) != "true" ]]; then
echo "${red}" echo "${red}"
echo " [ERROR] PHP must be installed before you can create a WP site!" echo " [ERROR] PHP must be installed before you can create a WP site!"
echo "${end}" echo "${end}"
@ -294,7 +301,7 @@ createsite() {
# Create data folder for new site # Create data folder for new site
if [[ ! -d /var/www/$domain/htdocs || ! -d /var/www/$domain ]]; then if [[ ! -d /var/www/$domain/htdocs || ! -d /var/www/$domain ]]; then
sudo mkdir -p /var/www/$domain/htdocs sudo mkdir -p /var/www/$domain/htdocs
if [[ "$wp" == "1" ]]; then if [[ "$wp" == [12] ]]; then
wpinstall wpinstall
fi fi
else else
@ -311,7 +318,7 @@ createsite() {
if [[ $wwwexist == n || $wwwexist == N ]]; then if [[ $wwwexist == n || $wwwexist == N ]]; then
sudo rm -rf /var/www/$domain/htdocs sudo rm -rf /var/www/$domain/htdocs
sudo mkdir -p /var/www/$domain/htdocs sudo mkdir -p /var/www/$domain/htdocs
if [[ "$wp" == "1" ]]; then if [[ "$wp" == [12] ]]; then
wpinstall wpinstall
fi fi
fi fi
@ -323,7 +330,7 @@ createsite() {
fi fi
# Activate FastCgi cache # Activate FastCgi cache
if [[ "$cache" == "-cache" && "$wp" == "1" ]]; then if [[ "$cache" == "-cache" && "$wp" == [12] ]]; then
sudo sed -i '/php.conf/c \ include common/wpfc.conf;' /etc/nginx/sites-available/$domain sudo sed -i '/php.conf/c \ include common/wpfc.conf;' /etc/nginx/sites-available/$domain
nginx_helper_plugin nginx_helper_plugin
fi fi

View file

@ -34,6 +34,13 @@ wp="0" # Evaluate if site to create is WP
if [[ "$type" == "-wp" || "$type" == "-wpsubdir" || "$type" == "-wpsubdom" ]]; then if [[ "$type" == "-wp" || "$type" == "-wpsubdir" || "$type" == "-wpsubdom" ]]; then
wp="1" wp="1"
fi fi
if [[ "$type" == "-wp="* || "$type" == "-wpsubdir="* || "$type" == "-wpsubdom="* ]]; then
wpunat=$(echo "${type}" | cut -d'=' -f 2 -s)
if [[ $wpunat == "default" ]]; then
wp="2"
type=$(echo "${type}" | cut -d'=' -f 1 -s)
fi
fi
# Cache validation # Cache validation
if [[ "$cache" == "-cache" && "$wp" == "0" ]]; then if [[ "$cache" == "-cache" && "$wp" == "0" ]]; then