2019-11-06 09:30:54 -05:00
|
|
|
#!/bin/bash
|
|
|
|
# Type of instance Base 19.2
|
|
|
|
|
|
|
|
# wpDeploy
|
|
|
|
# Nick Leffler
|
|
|
|
# 20190930 v1
|
|
|
|
|
|
|
|
##### EDIT HERE ####
|
2020-01-22 23:32:14 -05:00
|
|
|
# acme.sh location
|
|
|
|
acmebin="/root/.acme.sh/acme.sh"
|
2020-01-12 14:37:45 -05:00
|
|
|
|
2020-01-22 23:32:14 -05:00
|
|
|
# httpd server user
|
2020-01-12 14:37:45 -05:00
|
|
|
wwwUser="nginx"
|
2020-01-22 23:32:14 -05:00
|
|
|
|
2019-11-06 09:30:54 -05:00
|
|
|
#### DON"T TOUCH BELOW HERE ####
|
|
|
|
|
|
|
|
get_info () {
|
|
|
|
read -p "Enter Site Name: " siteName
|
|
|
|
read -p "Enter Site Title: " siteTitle
|
2020-01-22 23:32:14 -05:00
|
|
|
read -p "SSL [Y/n]: " siteProtoIn
|
|
|
|
read -p "Certbot ready?: cbReady
|
2019-11-06 09:30:54 -05:00
|
|
|
read -p "Enter Site URL: " siteURL
|
2020-01-12 14:50:24 -05:00
|
|
|
read -p "Enter WPAdmin email: " adminEmail
|
2019-11-06 09:30:54 -05:00
|
|
|
|
2020-01-22 23:32:14 -05:00
|
|
|
if [[ $siteProtoIn == "n" ]]; then
|
|
|
|
siteProto="http://"
|
|
|
|
ssl=0
|
2019-11-06 09:30:54 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
fullURL="${siteProto}${siteURL}"
|
|
|
|
}
|
|
|
|
|
|
|
|
genSSL () {
|
|
|
|
mkdir -p "/etc/nginx/ssl/${siteURL}/" || exit
|
|
|
|
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/${siteURL}/key -out /etc/nginx/ssl/${siteURL}/crt \
|
|
|
|
-subj "/C=TT/ST=TT/L=TT/O=TEMP/OU=TEMP/CN=$siteURL/emailAddress=TEMP"
|
2020-01-22 23:32:14 -05:00
|
|
|
|
|
|
|
sslCert="/etc/nginx/ssl/${siteURL}/crt"
|
|
|
|
sslKey="/etc/nginx/ssl/${siteURL}/key"
|
|
|
|
}
|
|
|
|
|
2020-01-22 23:36:09 -05:00
|
|
|
certbotSSL () {
|
2020-01-22 23:32:14 -05:00
|
|
|
"${acmebin}" --issue --dns dns_cf -d "${siteURL}" --reloadcmd "systemctl reload nginx" --force
|
|
|
|
|
|
|
|
sslCert="/root/.acme.sh/${siteURL}/fullchain.cer"
|
|
|
|
sslKey="/root/.acme.sh/${siteURL}/${siteURL}.key"
|
2019-11-06 09:30:54 -05:00
|
|
|
}
|
|
|
|
|
2019-11-06 09:46:12 -05:00
|
|
|
create_wp_db () {
|
2020-01-22 23:32:14 -05:00
|
|
|
siteNoP=$(echo "${siteURL}" | sed 's/\.//g')
|
|
|
|
# create wordpress user with passwd
|
|
|
|
wpasswd=$(openssl rand 39 -base64 | cut -c1-37)
|
|
|
|
wpapasswd=$(openssl rand 39 -base64 | cut -c1-37)
|
|
|
|
mysql -e "create database ${siteNoP}"
|
|
|
|
mysql -e "grant all on ${siteNoP}.* to ${siteNoP}@localhost identified by '${wpasswd}'"
|
2019-11-06 09:46:12 -05:00
|
|
|
}
|
|
|
|
|
2019-11-06 09:30:54 -05:00
|
|
|
vHostHTTP () {
|
|
|
|
siteFile="/etc/nginx/sites-available/${siteURL}"
|
|
|
|
# create nginx config for site
|
|
|
|
cat <<EOF > "${siteFile}"
|
|
|
|
server {
|
|
|
|
## Your website name goes here.
|
|
|
|
server_name "${siteURL}";
|
|
|
|
## Your only path reference.
|
|
|
|
root "${siteFP}";
|
|
|
|
## This should be in your http block and if it is, it's not needed here.
|
|
|
|
index index.php;
|
|
|
|
|
|
|
|
location = /favicon.ico {
|
|
|
|
log_not_found off;
|
|
|
|
access_log off;
|
|
|
|
}
|
|
|
|
|
|
|
|
location = /robots.txt {
|
|
|
|
allow all;
|
|
|
|
log_not_found off;
|
|
|
|
access_log off;
|
|
|
|
}
|
|
|
|
|
|
|
|
location ~ /\. {
|
|
|
|
access_log off;
|
|
|
|
log_not_found off;
|
|
|
|
deny all;
|
|
|
|
}
|
|
|
|
|
|
|
|
location ~* \\.(js|css|png|jpg|jpeg|gif|ico)$ {
|
|
|
|
expires max;
|
|
|
|
log_not_found off;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
location / {
|
|
|
|
# This is cool because no php is touched for static content.
|
|
|
|
# include the "?\$args" part so non-default permalinks doesn't break when using query string
|
|
|
|
try_files \$uri \$uri/ /index.php?\$args;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Pass PHP scripts to PHP-FPM
|
|
|
|
location ~* \\.php\$ {
|
|
|
|
fastcgi_index index.php;
|
|
|
|
fastcgi_intercept_errors on;
|
|
|
|
fastcgi_pass php;
|
|
|
|
#fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
|
|
|
|
include fastcgi_params;
|
|
|
|
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
|
|
|
|
fastcgi_param SCRIPT_NAME \$fastcgi_script_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
vHostHTTPS () {
|
|
|
|
# create nginx config for site
|
|
|
|
siteFile="/etc/nginx/sites-available/${siteURL}"
|
|
|
|
cat <<EOF > "${siteFile}"
|
|
|
|
server {
|
|
|
|
listen 80;
|
|
|
|
server_name "${siteURL}";
|
|
|
|
return 301 https://\$server_name\$request_uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
server {
|
|
|
|
listen 443 ssl;
|
|
|
|
## Your website name goes here.
|
|
|
|
server_name "${siteURL}";
|
|
|
|
## Your only path reference.
|
|
|
|
root "${siteFP}";
|
|
|
|
## This should be in your http block and if it is, it's not needed here.
|
|
|
|
index index.php;
|
|
|
|
|
|
|
|
location = /favicon.ico {
|
|
|
|
log_not_found off;
|
|
|
|
access_log off;
|
|
|
|
}
|
|
|
|
|
|
|
|
location = /robots.txt {
|
|
|
|
allow all;
|
|
|
|
log_not_found off;
|
|
|
|
access_log off;
|
|
|
|
}
|
|
|
|
|
|
|
|
location ~ /\. {
|
|
|
|
access_log off;
|
|
|
|
log_not_found off;
|
|
|
|
deny all;
|
|
|
|
}
|
|
|
|
|
|
|
|
location ~* \\.(js|css|png|jpg|jpeg|gif|ico)$ {
|
|
|
|
expires max;
|
|
|
|
log_not_found off;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
location / {
|
|
|
|
# This is cool because no php is touched for static content.
|
|
|
|
# include the "?\$args" part so non-default permalinks doesn't break when using query string
|
|
|
|
try_files \$uri \$uri/ /index.php?\$args;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Pass PHP scripts to PHP-FPM
|
|
|
|
location ~* \\.php\$ {
|
|
|
|
fastcgi_index index.php;
|
|
|
|
fastcgi_intercept_errors on;
|
|
|
|
fastcgi_pass php;
|
|
|
|
#fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
|
|
|
|
include fastcgi_params;
|
|
|
|
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
|
|
|
|
fastcgi_param SCRIPT_NAME \$fastcgi_script_name;
|
|
|
|
}
|
2020-01-22 23:32:14 -05:00
|
|
|
|
|
|
|
ssl_certificate "${sslCert}";
|
|
|
|
ssl_certificate_key "${sslKey}";
|
2019-11-06 09:30:54 -05:00
|
|
|
|
|
|
|
ssl_ciphers "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK";
|
|
|
|
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
|
|
|
|
ssl_prefer_server_ciphers on;
|
|
|
|
ssl_session_cache shared:SSL:10m;
|
|
|
|
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
|
|
|
|
add_header X-Content-Type-Options nosniff;
|
|
|
|
ssl_stapling on;
|
|
|
|
ssl_stapling_verify on;
|
|
|
|
resolver 8.8.8.8 4.2.2.1 valid=300s;
|
|
|
|
resolver_timeout 5s;
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
nginx-conf () {
|
|
|
|
if [[ "${ssl}" = 1 ]]; then
|
2020-01-22 23:40:40 -05:00
|
|
|
if [[ "${cbReady}" = 1 ]]; then
|
2020-01-22 23:36:09 -05:00
|
|
|
certbotSSL
|
|
|
|
else
|
|
|
|
genSSL
|
|
|
|
fi
|
2019-11-06 09:30:54 -05:00
|
|
|
vHostHTTPS
|
|
|
|
else
|
|
|
|
vHostHTTP
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
# #
|
|
|
|
# Starts HERE #
|
|
|
|
# #
|
|
|
|
########################################################################
|
|
|
|
|
|
|
|
# set defaults
|
2020-01-22 23:32:14 -05:00
|
|
|
siteProto="https://"
|
|
|
|
ssl=1
|
2019-11-06 09:30:54 -05:00
|
|
|
|
|
|
|
# get mdata
|
|
|
|
get_info
|
|
|
|
|
|
|
|
# Create variable from inputed ones
|
|
|
|
siteFP="/usr/share/nginx/html/${siteURL}/wordpress"
|
|
|
|
|
|
|
|
# do mysql stuff
|
|
|
|
create_wp_db
|
|
|
|
|
|
|
|
# create admin email
|
|
|
|
#adminEmail="admin@${siteURL}"
|
|
|
|
|
|
|
|
# Create site with wp-cli
|
|
|
|
mkdir -p "${siteFP}" || exit
|
|
|
|
cd "${siteFP}" || exit
|
2020-01-12 14:40:59 -05:00
|
|
|
chown -R "${wwwUser}":"${wwwUser}" "$(dirname ${siteFP})"
|
2020-01-12 14:39:38 -05:00
|
|
|
sudo -u "${wwwUser}" /usr/local/bin/wp core download
|
2020-01-12 14:49:43 -05:00
|
|
|
sudo -u "${wwwUser}" /usr/local/bin/wp config create --dbname="${siteNoP}" --dbuser="${siteNoP}" --dbpass="${wpasswd}" --path="${siteFP}"
|
2020-01-12 14:39:38 -05:00
|
|
|
sudo -u "${wwwUser}" /usr/local/bin/wp core install --url="${siteURL}" --title="${siteTitle}" --admin_user="wpm258159" --admin_password="${wpapasswd}" --admin_email="${adminEmail}" --path="${siteFP}" --skip-email
|
2020-01-12 14:37:45 -05:00
|
|
|
|
2019-11-06 09:30:54 -05:00
|
|
|
|
|
|
|
# Confiugre nginx and create config
|
|
|
|
nginx-conf
|
|
|
|
ln -s ${siteFile} /etc/nginx/sites-enabled/
|
|
|
|
nginx -t
|
|
|
|
read -p "Would you like to reload nginx to take new changes?: [y/n]" yy
|
2020-01-12 14:59:56 -05:00
|
|
|
if [ $yy == "y" ]; then
|
2019-11-06 09:30:54 -05:00
|
|
|
echo "reloading nginx"
|
|
|
|
systemctl reload nginx
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Echo errythang that matters
|
2020-01-12 14:58:54 -05:00
|
|
|
echo "The WP sql password is: ${wpasswd}"
|
2019-11-06 09:30:54 -05:00
|
|
|
echo "${siteName} is at ${siteProto}${siteURL} with the title ${siteTitle} and the admin email of ${adminEmail}"
|
|
|
|
echo "The wp-admin email/username is: ${adminEmail} and the password is: ${wpapasswd}"
|
|
|
|
echo "Thank you and have a great day"
|