Skip to content

Instantly share code, notes, and snippets.

@jonatasrenan jonatasrenan/ forked from emirpprime/
Last active Aug 29, 2015

What would you like to do?
#!/bin/bash -e
echo "============================================"
echo "Script de Instalação Wordpress - Major labs"
echo "============================================"
echo "É necessário criar uma nova base de dados MySQL? (s/n)"
read -e setupmysql
if [ "$setupmysql" == s ] ; then
echo "MySQL Admin User: "
read -e mysqluser
echo "MySQL Admin Password: "
read -s mysqlpass
echo "MySQL Host (Pressione Enter para 'localhost'): "
read -e mysqlhost
echo "WP Database Name: "
read -e dbname
echo "WP Database User: "
read -e dbuser
echo "WP Database Password: "
read -s dbpass
echo "WP Database Table (Pressione Enter para 'wp_'): "
read -e dbtable
echo "Última chance - Tem certeza que quer instalar? (s/n)"
read -e run
if [ "$run" == s ] ; then
if [ "$setupmysql" == s ] ; then
echo "============================================"
echo "Configurando Base de Dados."
echo "============================================"
#login to MySQL, add database, add user and grant permissions
dbsetup="create database $dbname;GRANT ALL PRIVILEGES ON $dbname.* TO $dbuser@$mysqlhost IDENTIFIED BY '$dbpass';FLUSH PRIVILEGES;"
mysql -u $mysqluser -p$mysqlpass -e "$dbsetup"
if [ $? != "0" ]; then
echo "============================================"
echo "[Error]: Database creation failed. Aborting."
echo "============================================"
exit 1
echo "============================================"
echo "Instalando o Wordpress."
echo "============================================"
#download wordpress
echo "Downloading..."
curl -O
#unzip wordpress
echo "Unpacking..."
tar -zxf latest.tar.gz
#move /wordpress/* files to this dir
echo "Moving..."
mv wordpress/* ./
echo "Configuring..."
#create wp config
cp wp-config-sample.php wp-config.php
#set database details with perl find and replace
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
perl -pi -e "s/wp_/$dbtable/g" wp-config.php
#set WP salts
perl -i -pe'
@chars = ("a" .. "z", "A" .. "Z", 0 .. 9);
push @chars, split //, "!@#$%^&*()-_ []{}<>~\`+=,.;:/?|";
sub salt { join "", map $chars[ rand @chars ], 1 .. 64 }
s/put your unique phrase here/salt()/ge
' wp-config.php
#create uploads folder and set permissions
mkdir wp-content/uploads
chmod 775 wp-content/uploads
echo "Cleaning..."
#remove wordpress/ dir
rmdir wordpress
#remove zip file
rm latest.tar.gz
#remove bash script if it exists in this dir
[[ -f "$file" ]] && rm ""
echo "==============================="
echo "[Sucesso]: Instalação completa."
echo "==============================="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.