Scripting a Wordpress rollout - Method I
We have 60 Wordpress sites to roll-out and I dislike tedious crap, so I scripted it.
# CentOS release 6.7 (Final)
Running it:
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:
# 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
Code:
./script.sh Domain? <something.tld>
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
Total Comments 0