LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > Spock's Brain
User Name
Password

Notices


Rate this Entry

Scripting a Wordpress rollout - Method I

Posted 11-27-2015 at 06:11 PM by Habitual
Updated 12-08-2015 at 12:54 PM by Habitual

We have 60 Wordpress sites to roll-out and I dislike tedious crap, so I scripted it.
# CentOS release 6.7 (Final)

Code:
#!/bin/bash
### 11/27/2015 07:03:58 PM
### jj/Habitual
### Wordpress files deployment
BASEDIR=/var/www/html

echo -n "Domain? " ; read DOMAIN

if [ -d $BASEDIR/$DOMAIN ] ; then
echo "directory exists, exiting..." ; exit 1
else
mkdir -pv "$BASEDIR"/"$DOMAIN"
fi

### /var/www/latest.zip exists ###
### checksum latest.zip needed ###
/usr/bin/unzip -o /var/www/latest.zip 
cp -pr wordpress/* "$BASEDIR"/"$DOMAIN"/
cp "$BASEDIR"/"$DOMAIN"/wp-config-sample.php  "$BASEDIR"/"$DOMAIN"/wp-config.php
chown apache:apache "$BASEDIR"/"$DOMAIN"/ -R


### MySQL Database Routine ###
### MySQL hates .com etc in db names, so clean-up $DOMAIN
MYSQLDOMAIN=$(echo $DOMAIN | sed 's/\./_/g')
mysql -e "create database IF NOT EXISTS $MYSQLDOMAIN;"
CONNECT_PASSWORD=$(date +s | sha256sum | base64 | head -c 12 ; echo)
mysql -e "grant select, insert, update, delete on $MYSQLDOMAIN.* to wp_installer@'localhost' identified by '$CONNECT_PASSWORD';flush privileges;"

### Add connection credentials ###
sed -i -e 's@database_name_here@'"$MYSQLDOMAIN"'@' $BASEDIR/$DOMAIN/wp-config.php
sed -i -e 's@username_here@wp_installer@' $BASEDIR/$DOMAIN/wp-config.php
sed -i -e 's@password_here@'"$CONNECT_PASSWORD"'@' $BASEDIR/$DOMAIN/wp-config.php

THIS_HOST=$(curl icanhazip.com)
echo "Done. Please navigate to http://$THIS_HOST/$DOMAIN"
#EOF
Running it:
Code:
./script.sh
Domain? <something.tld>
I may add arguments for the domain, I may not. OK, So I did. So there.

Enjoy the goodness.

Edit:Tue Dec 08, 2015 - 1:51:50 PM EST
Randomized CONNECT_USER over 'wp_installer' as multiple dbs with same connect user seemed to be an issue:
Code:
### 11/27/2015 07:03:58 PM
### jj/Habitual
### Wordpress files deployment
BASEDIR=/var/www/html

echo -n "Domain? " ; read DOMAIN

if [ -d $BASEDIR/$DOMAIN ] ; then
echo "directory exists, exiting..." ; exit 1
else
mkdir -pv "$BASEDIR"/"$DOMAIN"
fi

### /var/www/latest.zip exists ###
### checksum latest.zip needed ###
/usr/bin/unzip -o /var/www/latest.zip 
cp -pr wordpress/* "$BASEDIR"/"$DOMAIN"/
cp "$BASEDIR"/"$DOMAIN"/wp-config-sample.php  "$BASEDIR"/"$DOMAIN"/wp-config.php
chown apache:apache "$BASEDIR"/"$DOMAIN"/ -R


### MySQL Database Routine ###
### MySQL hates .com etc in db names, so clean-up $DOMAIN
MYSQLDOMAIN=$(echo $DOMAIN | sed 's/\./_/g')
mysql -e "create database IF NOT EXISTS $MYSQLDOMAIN;"
CONNECT_USER=$(date +s | sha256sum | base64 | head -c 8 ; echo)
CONNECT_PASSWORD=$(date +s | sha256sum | base64 | head -c 12 ; echo)
mysql -e "grant ALL on $MYSQLDOMAIN.* to $CONNECT_USER@'localhost' identified by '$CONNECT_PASSWORD';flush privileges;"

### Add connection credentials ###
sed -i -e 's@database_name_here@'"$MYSQLDOMAIN"'@' $BASEDIR/$DOMAIN/wp-config.php
sed -i -e 's@username_here@'"$CONNECT_USER"'@' $BASEDIR/$DOMAIN/wp-config.php
sed -i -e 's@password_here@'"$CONNECT_PASSWORD"'@' $BASEDIR/$DOMAIN/wp-config.php

THIS_HOST=$(curl icanhazip.com)
echo "Done. Please navigate to http://$THIS_HOST/$DOMAIN"
#EOF
Posted in Uncategorized
Views 3253 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 12:58 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration