Skip to content

Instantly share code, notes, and snippets.

@ericmil87
Last active March 23, 2022 02:32
Show Gist options
  • Save ericmil87/ff7285048252370838254cf73f6add03 to your computer and use it in GitHub Desktop.
Save ericmil87/ff7285048252370838254cf73f6add03 to your computer and use it in GitHub Desktop.
wordpress quick install bash script
#!/bin/bash -e
clear
echo "============================================"
echo "Instalador de Wordpress v1.1"
echo "============================================"
echo "Host do Banco de dados: "
read -e dbhost
echo "Nome do Banco de dados: "
read -e dbname
echo "Usúario do Banco de dados: "
read -e dbuser
echo "Senha do Banco de dados: "
read -s dbpass
echo "============================================"
echo "Vou validar o Banco de dados"
echo "============================================"
# mysql="mysql --host=$dbhost --user=$dbuser --password=$dbpass -s -N --execute="SELECT IF(EXISTS (SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$dbname'), 'Yes','No')";"
mysql='mysqlshow --host=$dbhost --user=$dbuser --password=$dbpass $dbname | grep -v Wildcard | grep -o $dbname'
echo $mysql
if [ "$mysql" == "$dbname" ]; then
echo "Esse banco de dados já existe, deseja usar ele? (y/n)"
read -e usethis
if [ "$usethis" == n ]; then
echo "Recomece para selecionar outro banco de dados."
echo "Precione qualquer tecla para sair..."
read -s exit
exit
fi
else
mysql='mysql --host=$dbhost --user=$dbuser --password=$dbpass --execute="CREATE DATABASE $dbname"'
echo "============================================"
echo "Banco de dados criado!"
echo "============================================"
fi
echo "Começar a instalação? (y/n)"
read -e run
if [ "$run" == n ] ; then
exit
else
echo "===================================================="
echo "O script está instalação o Wordpress, aguarde..."
echo "===================================================="
#Faz o download da bagaça
curl -O https://wordpress.org/latest.tar.gz
#dezipa
tar -zxvf latest.tar.gz
#vai pro dir do wordpress
cd wordpress
#copia pro diretório de cima
cp -rf . ..
#vai pro diretório de cima
cd ..
#exclui as coisas do diretório do wordpress
rm -R wordpress
#cria o wp config
cp wp-config-sample.php wp-config.php
#sobreescreve as configs do db
perl -pi -e "s/database_name_here/$dbname/g" wp-config.php
perl -pi -e "s/username_here/$dbuser/g" wp-config.php
perl -pi -e "s/password_here/$dbpass/g" wp-config.php
#define WP salts (WTF??)
perl -i -pe'
BEGIN {
@chars = ("a" .. "z", "A" .. "Z", 0 .. 9);
push @chars, split //, "!@#$%^&*()-_ []{}<>~\`+=,.;:/?|";
sub salt { join "", map $chars[ rand @chars ], 1 .. 64 }
}
s/chagasfe/salt()/ge
' wp-config.php
#cria as pastas de upload e da a permissão
mkdir wp-content/uploads
chmod 775 wp-content/uploads
#create .htaccess file
echo '
# BEGIN WordPress
# As diretrizes (linhas) entre "BEGIN WordPress" e "END WordPress" são
# geradas dinamicamente e só devem ser modificadas através de filtros do WordPress.
# Quaisquer alterações nas diretivas entre esses marcadores serão sobrescritas.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# Block the include-only files.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# Prevent viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
# Prevent viewing of wp-config.php file
# Prevent directory listings
Options All -Indexes
#prevent sensitive files
<FilesMatch "^.*(error_log|wp-config\.php|php.ini|\.[hH][tT][aApP].*)$">
Order deny,allow
Deny from all
</FilesMatch>
# END WordPress
' >> .htaccess
echo ".htaccess criado..\n Hardening wordpress"
#hardening wp
OWNER=admin # <-- wordpress owner
GROUP=admin # <-- wordpress group
ROOT=. # <-- wordpress root directory
# reset to safe defaults
find ${ROOT} -exec chown ${OWNER}:${GROUP} {} \;
find ${ROOT} -type d -exec chmod 755 {} \;
find ${ROOT} -type f -exec chmod 644 {} \;
# hardening wp-config and .htaccess
chgrp ${GROUP} ${ROOT}/wp-config.php
chmod 400 ${ROOT}/wp-config.php
chgrp ${GROUP} ${ROOT}/.htaccess
chmod 400 ${ROOT}/.htaccess
# allow wordpress to manage wp-content
find ${ROOT}/wp-content -exec chgrp ${GROUP} {} \;
find ${ROOT}/wp-content -type d -exec chmod 775 {} \;
find ${ROOT}/wp-content -type f -exec chmod 664 {} \;
echo "Limpando a bagunça..."
#exclui o zip
rm latest.tar.gz
#remove o script
rm wp-quick-install-inovaway.sh
echo "========================="
echo "Instalação completa!"
echo "========================="
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment