Skip to content

Instantly share code, notes, and snippets.

@saulmoralespa
Last active January 10, 2019 01:50
Show Gist options
  • Save saulmoralespa/e78b545e18da7f27b8fc1d28348178b2 to your computer and use it in GitHub Desktop.
Save saulmoralespa/e78b545e18da7f27b8fc1d28348178b2 to your computer and use it in GitHub Desktop.
#!/bin/bash
##change port nginx for 8080
#### For centos create directories
#sudo mkdir /etc/nginx/sites-available
#sudo mkdir /etc/nginx/sites-enabled
rutaRelation=/var/www/user/
echo "Dominio o subdominio a agregar (example.com), (sub.example.com):"
read domain
rutaToInstall="$rutaRelation$domain"
isDomain(){
regex='^([a-z.])+([.]{1})+([a-z])+$'
if [[ "$domain" =~ $regex ]]
then
return 0
else
message='Ingrese un nombre de dominio válido: "example.com sub.example.com"'
return 1
fi
}
notInstall(){
if [ -d "$rutaToInstall" ]
then
message="Ya existe una instalación para $domain"
return 1
else
return 0
fi
}
isAvailable(){
if [[ $rutaToInstall == *".com"* ]] ||
[[ $rutaToInstall == *".info"* ]] ||
[[ $rutaToInstall == *".net"* ]] ||
[[ $rutaToInstall == *".co"* ]] ||
[[ $rutaToInstall == *".mx"* ]]
then
return 0
else
message='Verifique por favor la extensión, intente con .com, .co, .net, .info, .mx'
return 1
fi
}
wpConfig()
{
uniqueKeys=$(wget https://api.wordpress.org/secret-key/1.1/salt/ -q -O -)
prefix=$(cat /dev/urandom | tr -dc 'a-z' | fold -w 3 | head -n 1)
echo "<?php
/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the
* installation. You don't have to use the web site, you can
* copy this file to "wp-config.php" and fill in the values.
*
* This file contains the following configurations:
*
* * MySQL settings
* * Secret keys
* * Database table prefix
* * ABSPATH
*
* @link https://codex.wordpress.org/Editing_wp-config.php
*
* @package WordPress
*/
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', '$nameDataBase');
/** MySQL database username */
define('DB_USER', '$nameUserDB');
/** MySQL database password */
define('DB_PASSWORD', '$passwodDB');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
/**#@+
* Authentication Unique Keys and Salts.
*
* Change these to different unique phrases!
* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
*
* @since 2.6.0
*/
$uniqueKeys
/**#@-*/
/**
* WordPress Database Table prefix.
*
* You can have multiple installations in one database if you give each
* a unique prefix. Only numbers, letters, and underscores please!
*/
$table_prefix = '$prefix_';
/**
* For developers: WordPress debugging mode.
*
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
*
* For information on other constants that can be used for debugging,
* visit the Codex.
*
* @link https://codex.wordpress.org/Debugging_in_WordPress
*/
define('WP_DEBUG', false);
/* That's all, stop editing! Happy blogging. */
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');"
}
configNginx(){
echo "server {
listen 8080;
root $rutaRelation$domain;
index index.php index.html index.htm;
server_name $domain www.$domain;
location / {
try_files \$uri \$uri/ /index.php?q=\$uri&\$args;
}
error_page 404 /404.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files \$uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}"
}
prepareInstall(){
echo "Comenzando instalación de wordpress......."
mkdir -p $rutaToInstall
cd $rutaToInstall
wget http://wordpress.org/latest.tar.gz
tar -zxf latest.tar.gz
mv wordpress/* ./
rm -rf latest.tar.gz
rm -rf wordpress
rm -rf wp-content/themes/twenty*
nameDomain=`echo $domain | cut -d \. -f 1`
nameDomain2=`echo $domain | cut -d \. -f 2`
nameDataBase=$nameDomain"_"$nameDomain2
nameUserDB=$nameDomain"_user"
passwodDB=$(openssl rand -base64 12)
echo "Creando base de datos......."
echo "CREATE DATABASE $nameDataBase" | mysql
echo "CREATE USER '$nameUserDB'@'localhost' IDENTIFIED BY '$passwodDB'" | mysql
echo "GRANT ALL PRIVILEGES ON * . * TO '$nameUserDB'@'localhost'" | mysql
echo "FLUSH PRIVILEGES" | mysql
wpConfig > wp-config.php
##change permissions
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
chown -R nginx:nginx $rutaToInstall
#echo "Agregando $domain al host......"
###https://www.tecmint.com/find-linux-server-public-ip-address/
#ipServer=$(wget -qO- http://ipecho.net/plain | xargs echo)
#echo "$ipServer $domain" >> /etc/hosts
echo "Configurando nginx para $domain......"
systemctl restart nginx
echo "Instalación completada, abra $domain en el navegador"
}
if isDomain && isAvailable $rutaToInstall && notInstall $rutaToInstall;
then
prepareInstall
else
echo $message
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment