Skip to content

Instantly share code, notes, and snippets.

@richardsweeney
Last active December 16, 2015 05:09
Show Gist options
  • Save richardsweeney/5382003 to your computer and use it in GitHub Desktop.
Save richardsweeney/5382003 to your computer and use it in GitHub Desktop.
Install latest WordPress, setup database, get latest ölab starter theme, commit it all to gitlab, setup virtual host, makes you a coffee (ok not the last one)
#!/bin/bash
# Initializes a git repo & adds gitlab repo as origin.
# For this to work the directory contining the repo has
echo "Enter the directory/database directory name:"
read directory
basedir="/Users/richardsweeney/s/"
MYSQL=`which mysql`
SQLCREATE="CREATE DATABASE IF NOT EXISTS $directory;"
TEMP_FILE="out.tmp"
DB_NAME="$directory"
DB_USER="root"
DB_PASSWORD="root"
DB_HOST="localhost"
#See if the database exists
RESULT=`mysqlshow --user=root --password=root $directory| grep -v Wildcard | grep -o $directory`
if [ "$RESULT" == "$directory" ]; then
echo "A database with that name already exists"
else
"$MYSQL" -uroot --password=root -e "$SQLCREATE"
echo ''
echo '*********************************************************'
echo ''
echo "=> The database $directory has been successfully created"
echo ''
echo '*********************************************************'
echo ''
fi
#Create a directory if it doesn't exist
if [ -d "$basedir$directory" ]; then
echo ''
echo '*********************************************************'
echo ''
echo "WOAH! A directory named '$directory' already exists!"
echo 'This installer will now exit, please remove or rename the directory and re-run the installer.'
echo ''
echo '*********************************************************'
echo ''
exit 0
else
mkdir $basedir$directory && cd $basedir$directory && curl http://wordpress.org/latest.tar.gz | tar xvz && mv wordpress/* .
rm -R wordpress
rm license.txt
rm readme.html
echo ''
echo '*********************************************************'
echo ''
echo '=> Gotcha!'
echo ''
echo '*********************************************************'
echo ''
fi
echo ''
echo '*********************************************************'
echo ''
echo '=> Fetching .gitignore'
echo ''
echo '*********************************************************'
echo ''
git clone https://gist.github.com/5292478.git gitignore && mv gitignore/.gitignore . && sudo rm -R gitignore/
echo ''
echo '*********************************************************'
echo ''
echo '=> Configuring wp-config.php'
echo ''
echo '*********************************************************'
echo ''
# Setup wp-config.php
cp wp-config-sample.php wp-config.php
touch $TEMP_FILE
# Set database connection
DB_DEFINES=( 'DB_NAME' 'DB_USER' 'DB_PASSWORD' 'DB_HOST' )
for DB_PROPERTY in ${DB_DEFINES[@]} ;
do
OLD="define('$DB_PROPERTY', '.*')"
NEW="define('$DB_PROPERTY', '${!DB_PROPERTY}')" # Will probably need some pretty crazy escaping to allow for better passwords
sed "s/$OLD/$NEW/g" wp-config.php > $TEMP_FILE && mv $TEMP_FILE wp-config.php
done
#Fix permissions + owership
sudo chown -R richardsweeney:admin *
echo ''
echo '*********************************************************'
echo ''
echo '=> Wordpress has been succesfully installed and configured'
echo ''
echo '*********************************************************'
echo ''
echo "127.0.0.1 $directory.dev" >> /etc/hosts
cat >> /Applications/MAMP/conf/apache/httpd.conf <<EOL
<VirtualHost *>
ServerName ${directory}.dev
DocumentRoot "/Applications/MAMP/htdocs/${directory}"
</VirtualHost>
EOL
echo "Initialize git (yes or no)?"
read bool
if [ "$bool" == 'yes' ]; then
git init
git add .
git commit -m 'Initial commit';
echo "Add the gitlab repo name (eg reponame.git)"
read reponame
git remote add origin git@dev.o-lab.se:richard.sweeney/$reponame
git push -u origin master
echo ''
echo '*********************************************************'
echo ''
echo '=> Succesfully pushed to gitlab'
echo ''
echo '*********************************************************'
echo ''
fi
echo "Do you want to add the Örestad Linux starter theme 'for fun and profit®' (yes or no)?"
read olabTheme
if [ "$olabTheme" == 'yes' ]; then
git clone git@dev.o-lab.se:richard.sweeney/wordpress-base-theme.git $basedir$directory/wp-content/themes/$directory-theme
sudo rm -R $basedir$directory/wp-content/themes/$directory-theme/.git
git add .
git commit -m 'Added theme to git'
git push origin master
echo ''
echo '*********************************************************'
echo ''
echo '=> Starter theme added'
echo ''
echo '*********************************************************'
echo ''
fi
echo "Add stage as git remote (yes or no)?"
read stageBool
if [ "$stageBool" == 'yes' ]; then
echo "Enter the name of the remote directory on stage"
read stageDir
git remote add stage ssh://richards@stage.o-lab.se/stage/www/$stageDir
git push -u stage master
echo ''
echo '*********************************************************'
echo ''
echo '=> Succesfully added and pushed to stage'
echo ''
echo '*********************************************************'
echo ''
fi
# Restart Apache
/Applications/MAMP/bin/apache2/bin/apachectl graceful
# Open in sublime
subl $basedir$directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment